Problem p02756 (python)

Fixed submission:
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''

t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)

for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.append(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=list(front_str)+list(t_str)+list(end_str)

if cnt%2==0:
    ans=''.join(ans)
else:
    ans=ans[::-1]
    ans=''.join(ans)
print(ans)

Buggy submission (verdict: Runtime Error):
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''

t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)

for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.appendleft(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=front_str+t_str+end_str
ans=list(ans)

if cnt%2==0:
    ans=''.join(ans)
else:
    ans=ans[::-1]
    ans=''.join(ans)
print(ans)

Buggy submission (verdict: Runtime Error):
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''
t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)
for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.appendleft(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=front_str+t_str+end_str
ans=list(ans)

if cnt%2==0:
    ans=''.join(ans)
else:
    ans=ans[::-1]
    ans=''.join(ans)
print(ans)

Buggy submission (verdict: Runtime Error):
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''
t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)
for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.appendleft(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=front_str+t_str+end_str
ans=list(ans)

if cnt%2==0:
    ans=''.join(ans)
else:
    ans=ans[::-1]
    ans=''.join(ans)
print(ans)