-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10866_덱.py
36 lines (35 loc) · 870 Bytes
/
10866_덱.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from collections import deque
import sys
def input(): return sys.stdin.readline().strip()
N = int(input())
arr = deque()
for _ in range(N):
query = input().split()
if query[0] == "push_front":
arr.appendleft(int(query[1]))
elif query[0] == "push_back":
arr.append(int(query[1]))
elif query[0] == "pop_front":
if arr:
print(arr.popleft())
else:
print(-1)
elif query[0] == "pop_back":
if arr:
print(arr.pop())
else:
print(-1)
elif query[0] == "size":
print(len(arr))
elif query[0] == "empty":
print(0 if arr else 1)
elif query[0] == "front":
if arr:
print(arr[0])
else:
print(-1)
elif query[0] == "back":
if arr:
print(arr[-1])
else:
print(-1)