Buggy python submission (verdict: Time Limit Exceeded):

s=input()
q=int(input())
queries = []
rev = [0]*q
flag=0
for i in range(q):
    query = list( input().split() )
    queries.append( query )
    if query==["1"]:
        flag+=1
    rev[i]=flag

n_rev = flag
left=""
right=""
for r,query in zip(rev,queries):
    if query!=["1"]:
        q1 = query[1]
        q2 = query[2]
        if (r+n_rev)%2==0:
            if q1=="1":
                left=q2+left
            else:
                right=right+q2
        else:
            if q1=="1":
                right=right+q2
            else:
                left=q2+left 
#     print(i,left,s,right)
if n_rev%2==1:
    s=s[::-1]
print("".join([left,s,right]) )

Fixed submission:

s=input()
q=int(input())
queries = []
rev = [0]*q
flag=0
for i in range(q):
    query = list( input().split() )
    queries.append( query )
    if query==["1"]:
        flag+=1
    rev[i]=flag

n_rev = flag
from collections import deque
left=deque([])
right=deque([])
for r,query in zip(rev,queries):
    if query!=["1"]:
        q1 = query[1]
        q2 = query[2]
        if (r+n_rev)%2==0:
            if q1=="1":
                left.appendleft(q2)
            else:
                right.append(q2)
        else:
            if q1=="1":
                right.append(q2)
            else:
                left.appendleft(q2) 
#     print(i,left,s,right)
if n_rev%2==1:
    s=s[::-1]
print("".join(["".join(left),s,"".join(right)]) )

Buggy python submission (verdict: Time Limit Exceeded):

s=input()
q=int(input())
queries = []
rev = [0]*q
flag=0
for i in range(q):
    query = list( input().split() )
    queries.append( query )
    if query==["1"]:
        flag+=1
    rev[i]=flag

n_rev = queries.count(["1"])
left=""
right=""
for i,query in enumerate(queries):
    if query!=["1"]:
        q1 = query[1]
        q2 = query[2]
        if (rev[i]+n_rev)%2==0:
            if q1=="1":
                left=q2+left
            else:
                right=right+q2
        else:
            if q1=="1":
                right=right+q2
            else:
                left=q2+left 
#     print(i,left,s,right)
if n_rev%2==1:
    s=s[::-1]
print("".join([left,s,right]) )

Fixed submission:

s=input()
q=int(input())
queries = []
rev = [0]*q
flag=0
for i in range(q):
    query = list( input().split() )
    queries.append( query )
    if query==["1"]:
        flag+=1
    rev[i]=flag

n_rev = flag
from collections import deque
left=deque([])
right=deque([])
for r,query in zip(rev,queries):
    if query!=["1"]:
        q1 = query[1]
        q2 = query[2]
        if (r+n_rev)%2==0:
            if q1=="1":
                left.appendleft(q2)
            else:
                right.append(q2)
        else:
            if q1=="1":
                right.append(q2)
            else:
                left.appendleft(q2) 
#     print(i,left,s,right)
if n_rev%2==1:
    s=s[::-1]
print("".join(["".join(left),s,"".join(right)]) )

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
queries = []
rev = [0]*q
flag=0
for i in range(q):
    query = list( input().split() )
    queries.append( query )
    if query==["1"]:
        flag+=1
    rev[i]=flag

n_rev = queries.count(["1"])
rev = [rr+n_rev for rr in rev]
left=""
right=""
for i,query in enumerate(queries):
    if query!=["1"]:
        if rev[i]%2==0:
            if query[1]=="1":
                left=query[2]+left
            else:
                right=right+query[2]
        else:
            if query[1]=="1":
                right=right+query[2]
            else:
                left=query[2]+left 
#     print(i,left,s,right)
if n_rev%2==1:
    s=s[::-1]
print(left+s+right)

Fixed submission:

s=input()
q=int(input())
queries = []
rev = [0]*q
flag=0
for i in range(q):
    query = list( input().split() )
    queries.append( query )
    if query==["1"]:
        flag+=1
    rev[i]=flag

n_rev = flag
from collections import deque
left=deque([])
right=deque([])
for r,query in zip(rev,queries):
    if query!=["1"]:
        q1 = query[1]
        q2 = query[2]
        if (r+n_rev)%2==0:
            if q1=="1":
                left.appendleft(q2)
            else:
                right.append(q2)
        else:
            if q1=="1":
                right.append(q2)
            else:
                left.appendleft(q2) 
#     print(i,left,s,right)
if n_rev%2==1:
    s=s[::-1]
print("".join(["".join(left),s,"".join(right)]) )

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())

for _ in range(q):
    query = list( input().split() )
    if query[0]=="1":
        s = s[::-1]
    else:
        if query[1]=="1":
            s=query[2]+s
        else:
            s=s+query[2]
print(s)

Fixed submission:

s=input()
q=int(input())
queries = []
rev = [0]*q
flag=0
for i in range(q):
    query = list( input().split() )
    queries.append( query )
    if query==["1"]:
        flag+=1
    rev[i]=flag

n_rev = flag
from collections import deque
left=deque([])
right=deque([])
for r,query in zip(rev,queries):
    if query!=["1"]:
        q1 = query[1]
        q2 = query[2]
        if (r+n_rev)%2==0:
            if q1=="1":
                left.appendleft(q2)
            else:
                right.append(q2)
        else:
            if q1=="1":
                right.append(q2)
            else:
                left.appendleft(q2) 
#     print(i,left,s,right)
if n_rev%2==1:
    s=s[::-1]
print("".join(["".join(left),s,"".join(right)]) )

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())

for i in range(q):
    query = list( input().split() )
    if query[0]=="1":
        s = s[::-1]
    else:
        if query[1]=="1":
            s=query[2]+s
        else:
            s=s+query[2]
print(s)

Fixed submission:

s=input()
q=int(input())
queries = []
rev = [0]*q
flag=0
for i in range(q):
    query = list( input().split() )
    queries.append( query )
    if query==["1"]:
        flag+=1
    rev[i]=flag

n_rev = flag
from collections import deque
left=deque([])
right=deque([])
for r,query in zip(rev,queries):
    if query!=["1"]:
        q1 = query[1]
        q2 = query[2]
        if (r+n_rev)%2==0:
            if q1=="1":
                left.appendleft(q2)
            else:
                right.append(q2)
        else:
            if q1=="1":
                right.append(q2)
            else:
                left.appendleft(q2) 
#     print(i,left,s,right)
if n_rev%2==1:
    s=s[::-1]
print("".join(["".join(left),s,"".join(right)]) )