N = int(input())
answer = []
stack = []
for _ in range(N):
cmd = input().split()
main_cmd = cmd[0]
if main_cmd == "push":
stack.append(int(cmd[1]))
elif main_cmd == "top":
if stack:
answer.append(stack[-1])
else:
answer.append(-1)
elif main_cmd == "size":
answer.append(len(stack))
elif main_cmd == "empty":
if stack:
answer.append(0)
else:
answer.append(1)
else:
if stack:
answer.append(stack.pop())
else:
answer.append(-1)
for elem in answer:
print(elem)