728x90
import sys
n=int(sys.stdin.readline())
list=[]
answer=[]
for _ in range(n):
list=sys.stdin.readline().split()
if list[0]=='push':
answer.append(list[1])
elif list[0]=='pop':
if len(answer)==0:
print(-1)
else:
print(answer.pop(0))
elif list[0]=='size':
print(len(answer))
elif list[0]=='empty':
if len(answer)==0:
print(1)
else:
print(0)
elif list[0]=='front':
if len(answer)==0:
print(-1)
else:
print(answer[0])
elif list[0]=='back':
if len(answer)==0:
print(-1)
else:
print(answer[-1])
728x90