N=int(input())
stack = []
for _ in range(N):
a= input().split()
if a[0] == '1':
stack.append(a[1])
elif a[0] == '2':
if stack == []:
print(-1)
else:
print(stack.pop())
elif a[0] == '3':
print(len(stack))
elif a[0] == '4':
if stack == []:
print(1)
else:
print(0)
elif a[0] == '5':
if stack !=[]:
print(stack[-1])
else:
print(-1)
To embed this project on your website, copy the following code and paste it into your website's HTML: