https://www.acmicpc.net/problem/10828
class Stack:
def __init__(self):
self.si = 0
self.stack = []
def push(self,num):
self.stack.append(num)
self.si += 1
def pop(self):
if self.si == 0:
return -1
else:
ans = self.stack[self.si - 1]
del self.stack[self.si - 1]
self.si -= 1
return ans
def size(self):
return self.si
def empty(self):
if self.si == 0:
return 1
else:
return 0
def top(self):
if self.si == 0:
return -1
else:
return self.stack[-1]
n=int(input())
t=Stack()
an=[]
count=0
for i in range(n):
arr = input().split()
st = arr[0]
if st == "push":
t.push(arr[1])
elif st == "pop":
an.append(t.pop())
count+=1
elif st == "size":
an.append(t.size())
count+=1
elif st == "empty":
an.append(t.empty())
count+=1
elif st == "top":
an.append(t.top())
count+=1
for i in range(count):
print(an[i])