Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())
ans_list1 = []
ans_list2 = []
flag = 1
for i in range(q):
    i = input().split()
    if i[0]=="1":
        flag *= -1
    else:
        if i[1]=='1':
            if flag==1:
                ans_list1.append(i[2])
            else:
                ans_list2.append(i[2])
        else:
            if flag==1:
                ans_list2.append(i[2])
            else:
                ans_list1.append(i[2])
    
    if flag==1:
        print(''.join(ans_list1[::-1]) + s +''.join(ans_list2))
    else:
        print(''.join(ans_list2[::-1]) + s[::-1] +''.join(ans_list1))

if flag==1:
    print(''.join(ans_list1[::-1]) + s +''.join(ans_list2))
else:
    print(''.join(ans_list2[::-1]) + s[::-1] +''.join(ans_list1))

Fixed submission:
s = input()
q = int(input())
ans_list1 = []
ans_list2 = []
flag = 1
for i in range(q):
    i = input().split()
    if i[0]=="1":
        flag *= -1
    else:
        if i[1]=='1':
            if flag==1:
                ans_list1.append(i[2])
            else:
                ans_list2.append(i[2])
        else:
            if flag==1:
                ans_list2.append(i[2])
            else:
                ans_list1.append(i[2])

if flag==1:
    print(''.join(ans_list1[::-1]) + s +''.join(ans_list2))
else:
    print(''.join(ans_list2[::-1]) + s[::-1] +''.join(ans_list1))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
q_lists = [input().split() for _ in range(q)]
for i in q_lists:
    if len(i)==1:
        s = s[::-1]
    else:
        f = i[1]
        c = i[2]
        if f=='1':
            s = s[::-1]
            s.append(c)
            s = s[::-1]
        else:
            s.append(c)
        
print(''.join(s))        

Fixed submission:
s = input()
q = int(input())
ans_list1 = []
ans_list2 = []
flag = 1
for i in range(q):
    i = input().split()
    if i[0]=="1":
        flag *= -1
    else:
        if i[1]=='1':
            if flag==1:
                ans_list1.append(i[2])
            else:
                ans_list2.append(i[2])
        else:
            if flag==1:
                ans_list2.append(i[2])
            else:
                ans_list1.append(i[2])

if flag==1:
    print(''.join(ans_list1[::-1]) + s +''.join(ans_list2))
else:
    print(''.join(ans_list2[::-1]) + s[::-1] +''.join(ans_list1))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
q_lists = [input().split() for _ in range(q)]
hanten = 0
for i in q_lists:
    if len(i)==1:
        hanten += 1
    else:
        f = i[1]
        c = i[2]
        if hanten%2==0:
            if f=='1':
                s =[c] + s
            else:
                s.append(c)
        else:
            if f=="1":
                s.append(c)
            else:
                s = [c] + s
print(''.join(s) if hanten%2==0 else ''.join(s[::-1]))        

Fixed submission:
s = input()
q = int(input())
ans_list1 = []
ans_list2 = []
flag = 1
for i in range(q):
    i = input().split()
    if i[0]=="1":
        flag *= -1
    else:
        if i[1]=='1':
            if flag==1:
                ans_list1.append(i[2])
            else:
                ans_list2.append(i[2])
        else:
            if flag==1:
                ans_list2.append(i[2])
            else:
                ans_list1.append(i[2])

if flag==1:
    print(''.join(ans_list1[::-1]) + s +''.join(ans_list2))
else:
    print(''.join(ans_list2[::-1]) + s[::-1] +''.join(ans_list1))

Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())
q_lists = [input().split() for _ in range(q)]
hanten = 0
for i in q_lists:
    if len(i)==1:
        hanten += 1
    else:
        f = i[1]
        c = i[2]
        if hanten%2==0:
            if f=='1':
                s = c + s
            else:
                s.append(c)
        else:
            if f=="1":
                s.append(c)
            else:
                s = c + s
print(s if hanten%2==0 else s[::-1])        

Fixed submission:
s = input()
q = int(input())
ans_list1 = []
ans_list2 = []
flag = 1
for i in range(q):
    i = input().split()
    if i[0]=="1":
        flag *= -1
    else:
        if i[1]=='1':
            if flag==1:
                ans_list1.append(i[2])
            else:
                ans_list2.append(i[2])
        else:
            if flag==1:
                ans_list2.append(i[2])
            else:
                ans_list1.append(i[2])

if flag==1:
    print(''.join(ans_list1[::-1]) + s +''.join(ans_list2))
else:
    print(''.join(ans_list2[::-1]) + s[::-1] +''.join(ans_list1))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
q_lists = [input().split() for _ in range(q)]
hanten = 0
for i in q_lists:
    if len(i)==1:
        hanten += 1
    else:
        f = i[1]
        c = i[2]
        if hanten%2==0:
            if f=='1':
                s = c + s
            else:
                s = s + c
        else:
            if f=="1":
                s = s + c
            else:
                s = c + s
print(s if hanten%2==0 else s[::-1])        

Fixed submission:
s = input()
q = int(input())
ans_list1 = []
ans_list2 = []
flag = 1
for i in range(q):
    i = input().split()
    if i[0]=="1":
        flag *= -1
    else:
        if i[1]=='1':
            if flag==1:
                ans_list1.append(i[2])
            else:
                ans_list2.append(i[2])
        else:
            if flag==1:
                ans_list2.append(i[2])
            else:
                ans_list1.append(i[2])

if flag==1:
    print(''.join(ans_list1[::-1]) + s +''.join(ans_list2))
else:
    print(''.join(ans_list2[::-1]) + s[::-1] +''.join(ans_list1))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
q_lists = [input().split() for _ in range(q)]
for i in q_lists:
    if len(i)==1:
        s = s[::-1]
    else:
        f = i[1]
        c = i[2]
        if f=='1':
            s = c + s
        else:
            s = s + c
print(s)        

Fixed submission:
s = input()
q = int(input())
ans_list1 = []
ans_list2 = []
flag = 1
for i in range(q):
    i = input().split()
    if i[0]=="1":
        flag *= -1
    else:
        if i[1]=='1':
            if flag==1:
                ans_list1.append(i[2])
            else:
                ans_list2.append(i[2])
        else:
            if flag==1:
                ans_list2.append(i[2])
            else:
                ans_list1.append(i[2])

if flag==1:
    print(''.join(ans_list1[::-1]) + s +''.join(ans_list2))
else:
    print(''.join(ans_list2[::-1]) + s[::-1] +''.join(ans_list1))

Buggy python submission (verdict: Runtime Error):
s = [input()]
q = int(input())
for i in range(q):
    inp = input().split()
    if len(inp) == 1:
        s = s[::-1]
        print(s)
    else:
        if int(inp[1])==1:
            s.insert(0,inp[2])
        else:
            s.append(inp[2])
        print(s)
print(''.join(s))

Fixed submission:
s = input()
q = int(input())
ans_list1 = []
ans_list2 = []
flag = 1
for i in range(q):
    i = input().split()
    if i[0]=="1":
        flag *= -1
    else:
        if i[1]=='1':
            if flag==1:
                ans_list1.append(i[2])
            else:
                ans_list2.append(i[2])
        else:
            if flag==1:
                ans_list2.append(i[2])
            else:
                ans_list1.append(i[2])

if flag==1:
    print(''.join(ans_list1[::-1]) + s +''.join(ans_list2))
else:
    print(''.join(ans_list2[::-1]) + s[::-1] +''.join(ans_list1))