Start: Jul, 10, 2019 08:30:00
2019年度暑期短学期达标测试补考
End: Jul, 10, 2019 11:30:00
Time elapsed:
Time remaining:

Problem_ID: I
Result: Accepted
Time: 50ms
Memory: 25320kB
Author: 2017210311034
In contest: 1284

lst=[]
n,m=map(int,input().split())
for i in range(m):
    s=input()
    lst1=[x for x in s.split()]
    if lst1[0]=='pushLeft' and len(lst)<n:
        lst=[lst1[1]]+lst
        print("Pushed in left: "+lst1[1])
    elif lst1[0]=='pushRight' and len(lst)<n:
        lst.append(lst1[1])
        print("Pushed in right: "+lst1[1])
    elif (lst1[0]=='pushLeft' or lst1[0]=='pushRight') and len(lst)==n:
        print("The queue is full")
    elif lst1[0]=='popLeft' and len(lst)>0:
        t=lst.pop(0)
        print('Popped from left: '+t)
    elif lst1[0]=='popRight' and len(lst)>0:
        t=lst.pop()
        print('Popped from right: '+t)
    elif (lst1[0]=='popLeft' or lst1[0]=='popRight') and len(lst)==0:
        print('The queue is empty')