https://www.acmicpc.net/problem/10845
from collections import deque
import sys
n = int(sys.stdin.readline())
queue = deque()
for _ in range(n):
command = sys.stdin.readline()
if 'push' in command:
target = int(command.split()[1])
queue.append(target)
elif 'pop' in command:
if len(queue) == 0:
print(-1)
else:
print(queue.popleft())
elif 'size' in command:
print(len(queue))
elif 'empty' in command:
if len(queue) == 0:
print(1)
else:
print(0)
elif 'front' in command:
if len(queue) == 0:
print(-1)
else:
print(queue[0])
elif 'back' in command:
if len(queue) == 0:
print(-1)
else:
print(queue[-1])
시간 초과가 떠서 input 받을 때 input() 대신 sys.stdin.readline() 으로 바꾸니 해결되었다!