import sys
# 명령어 개수
n = int(input())
# 함수들
def functions(queue, cmd):
cmd = cmd.split()
command = cmd[0]
l_size = len(queue)
if command == 'push':
queue.append(int(cmd[1]))
elif command == 'pop':
if l_size == 0: print(-1)
else: print(queue.pop(0))
elif command == 'size':
print(l_size)
elif command == 'empty':
if l_size == 0: print(1)
else: print(0)
elif command == 'front':
if l_size != 0: print(queue[0])
else: print(-1)
elif command == 'back':
if l_size != 0: print(queue[-1])
else: print(-1)
# 입력 받기
queue = []
for i in range(n):
com = sys.stdin.readline()
functions(queue, com)
이상한 점 : sys.stdin.readline()를 쓰지 않으면 시간 초과로 풀리지 않는다. 왜 이렇게 만들어 놓았는지 솔직히 잘 모르겠다.