Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- de = collections.deque()
- f1 = open("output.txt", "w")
- with open("input.txt") as f:
- for i in range(1):
- x = f.readline()
- x = int(x)
- q = 0
- for j in range(x):
- q += 1
- for k in range(q):
- a = f.readline().split()
- if a == 1 or a == 2:
- a, b = f.readline().split()
- if a == 1:
- de.appendleft(b)
- elif a == 2:
- de.append(b)
- elif a == 3:
- b = str(b)
- f1.write(b + " ")
- b = int(b)
- de.popleft()
- elif a == 4:
- b = str(b)
- f1.write(b + " ")
- b = int(b)
- de.pop()
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement