-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path47.py
More file actions
62 lines (49 loc) · 1.52 KB
/
Copy path47.py
File metadata and controls
62 lines (49 loc) · 1.52 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import sys
from queue import Queue, PriorityQueue, LifoQueue
def FILE_IO():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
def solve():
stack = LifoQueue()
queue = Queue()
pqueue = PriorityQueue()
while (True):
try:
n = int(input())
except EOFError:
break
stack.queue.clear()
queue.queue.clear()
pqueue.queue.clear()
isStack, isQueue, isPQueue = 1, 1, 1
for _ in range(n):
a, b = map(int, input().split())
if a == 1:
stack.put(b)
queue.put(b)
pqueue.put(-b)
else:
if queue.empty():
isStack, isQueue, isPQueue = 0, 0, 0
else:
xstack = stack.get()
xqueue = queue.get()
xpqueue = -pqueue.get()
if xstack != b:
isStack = 0
if xqueue != b:
isQueue = 0
if xpqueue != b:
isPQueue = 0
if isStack + isQueue + isPQueue == 0:
print('impossible')
elif isStack + isQueue + isPQueue > 1:
print('not sure')
elif isStack:
print('stack')
elif isQueue:
print('queue')
elif isPQueue:
print('priority queue')
# FILE_IO()
solve()