Buggy python submission (verdict: Runtime Error):
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
reverse = False
back = []
head = []

for idx, value in enumerate(Query):
    if value[0] == "1":
        reverse ^= True
        head, back = back, head
    else:
        if value[1] == "1":
            back = back + [value[2]]
        else:
            head = head + [value[2]]
if reverse == False:
    print( "".join(head.reverse()) + "".join(Slist) + "".join(back) )

else:
    print( ''.join(reversed(head)) + "".join(Slist[::-1]) + "".join(back))

Fixed submission:
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
reverse = False
back = []
head = []

for idx, value in enumerate(Query):
    if value[0] == "1":
        reverse ^= True
        head, back = back, head
    else:
        if value[1] == "1":
            head += [value[2]]
        else:
            back += [value[2]]

if reverse == False:
    head.reverse()
    print("".join(head + Slist + back))
else:
    head.reverse()
    print("".join(head + Slist[::-1] + back))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
cnt = 0
back = []
head = []

for idx, value in enumerate(Query):
    if int(value[0]) == 1:
        cnt +=1
    else:
        if int(value[1]) == 1:
            if cnt % 2 != 0:
                back = back + [value[2]]
            else:
                head = [value[2]] + head
        else:
            if cnt % 2 != 0:
                head = [value[2]] + head
            else:
                back = back + [value[2]]
if cnt % 2 == 0:
    print("".join(head + Slist + back))
else:
    Slist.reverse()
    head.reverse()
    back.reverse()
    print("".join(back + Slist + head))
    
# head Slist last

Fixed submission:
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
reverse = False
back = []
head = []

for idx, value in enumerate(Query):
    if value[0] == "1":
        reverse ^= True
        head, back = back, head
    else:
        if value[1] == "1":
            head += [value[2]]
        else:
            back += [value[2]]

if reverse == False:
    head.reverse()
    print("".join(head + Slist + back))
else:
    head.reverse()
    print("".join(head + Slist[::-1] + back))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
cnt = 0
last = []
head = []
for i in range(Qlen):
    if int(Query[i][0]) == 1:
        cnt +=1
    else:
        if int(Query[i][1]) == 1: #頭につける
            if cnt % 2 != 0:   #逆さ
                last = last + [Query[i][2]]
            else:
                head = [Query[i][2]] + head
        else: #けつにつける
            if cnt % 2 != 0:
                head = [Query[i][2]] + head
            else:
                last = last + [Query[i][2]]
if cnt % 2 == 0:
    print("".join(head + Slist + last))
else:
    Slist = Slist[::-1]
    head = head[::-1]
    last = last[::-1]
    print("".join(last + Slist + head))
    
# head Slist last

Fixed submission:
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
reverse = False
back = []
head = []

for idx, value in enumerate(Query):
    if value[0] == "1":
        reverse ^= True
        head, back = back, head
    else:
        if value[1] == "1":
            head += [value[2]]
        else:
            back += [value[2]]

if reverse == False:
    head.reverse()
    print("".join(head + Slist + back))
else:
    head.reverse()
    print("".join(head + Slist[::-1] + back))

Buggy python submission (verdict: Runtime Error):
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
cnt = 0
last = []
head = []
for i in range(Qlen):
    if int(Query[i][0]) == 1:
        cnt +=1
    else:
        if int(Query[i][1]) == 1: #頭につける
            if cnt % 2 != 0:   #逆さ
                last = last + [Query[i][2]]
            else:
                head = [Query[i][2]] + head
        else: #けつにつける
            if cnt % 2 != 0:
                head = [Query[i][2]] + head
            else:
                last = last + [Query[i][2]]
if cnt % 2 == 0:
    print(head + "".join(Slist) + last)
else:
    Slist = Slist[::-1]
    head = head[::-1]
    last = last[::-1]
    print("".join(last + Slist + head))
    
# head Slist last

Fixed submission:
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
reverse = False
back = []
head = []

for idx, value in enumerate(Query):
    if value[0] == "1":
        reverse ^= True
        head, back = back, head
    else:
        if value[1] == "1":
            head += [value[2]]
        else:
            back += [value[2]]

if reverse == False:
    head.reverse()
    print("".join(head + Slist + back))
else:
    head.reverse()
    print("".join(head + Slist[::-1] + back))

Buggy python submission (verdict: Runtime Error):
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
cnt = 0
last = []
head = []
for i in range(Qlen):
    if int(Query[i][0]) == 1:
        cnt +=1
    else:
        if int(Query[i][1]) == 1: #頭につける
            if cnt % 2 != 0:   #逆さ
                last = last + [Query[i][2]]
            else:
                head = [Query[i][2]] + head
        else: #けつにつける
            if cnt % 2 != 0:
                head = [Query[i][2]] + head
            else:
                last = last + [Query[i][2]]
if cnt % 2 == 0:
    print(head + "".join(Slist) + last)
else:
    Slist = Slist[::-1]
    head = head[::-1]
    last = last[::-1]
    print("".join(last + Slist + head))
    
# head Slist last

Fixed submission:
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
reverse = False
back = []
head = []

for idx, value in enumerate(Query):
    if value[0] == "1":
        reverse ^= True
        head, back = back, head
    else:
        if value[1] == "1":
            head += [value[2]]
        else:
            back += [value[2]]

if reverse == False:
    head.reverse()
    print("".join(head + Slist + back))
else:
    head.reverse()
    print("".join(head + Slist[::-1] + back))

Buggy python submission (verdict: Runtime Error):
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
cnt = 0
last = []
head = []
for i in range(Qlen):
    if int(Query[i][0]) == 1:
        cnt +=1
    else:
        if int(Query[i][1]) == 1: #頭につける
            if cnt % 2 != 0:   #逆さ
                last = last + [Query[i][2]]
            else:
                head = [Query[i][2]] + head
        else: #けつにつける
            if cnt % 2 != 0:
                head = [Query[i][2]] + head
            else:
                last = last + [Query[i][2]]
if cnt % 2 == 0:
    print(head + "".join(Slist) + last)
else:
    Slist = Slist[::-1]
    head = head[::-1]
    last = last[::-1]
    print("".join(last + Slist + head))
    
# head Slist last

Fixed submission:
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
reverse = False
back = []
head = []

for idx, value in enumerate(Query):
    if value[0] == "1":
        reverse ^= True
        head, back = back, head
    else:
        if value[1] == "1":
            head += [value[2]]
        else:
            back += [value[2]]

if reverse == False:
    head.reverse()
    print("".join(head + Slist + back))
else:
    head.reverse()
    print("".join(head + Slist[::-1] + back))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
cnt = 0
for i in range(Qlen):
    if int(Query[i][0]) == 1:
        cnt +=1
    else:
        if int(Query[i][1]) == 1:
            if cnt % 2 != 0:   
                Slist = Slist + [Query[i][2]]
            else:
                Slist = [Query[i][2]] + Slist
        else:
            if cnt % 2 != 0:
                Slist = [Query[i][2]] + Slist
            else:
                Slist = Slist + [Query[i][2]]
if cnt % 2 == 0:
    print("".join(Slist))
else:
    Slist = Slist[::-1]
    print("".join(Slist))

Fixed submission:
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
reverse = False
back = []
head = []

for idx, value in enumerate(Query):
    if value[0] == "1":
        reverse ^= True
        head, back = back, head
    else:
        if value[1] == "1":
            head += [value[2]]
        else:
            back += [value[2]]

if reverse == False:
    head.reverse()
    print("".join(head + Slist + back))
else:
    head.reverse()
    print("".join(head + Slist[::-1] + back))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
for i in range(Qlen):
    if int(Query[i][0]) == 1:
        Slist= Slist[::-1]
    else:
        if int(Query[i][1]) == 1:
            Slist = [Query[i][2]] + Slist
        else:
            Slist = Slist + [Query[i][2]]
print("".join(Slist))

Fixed submission:
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
reverse = False
back = []
head = []

for idx, value in enumerate(Query):
    if value[0] == "1":
        reverse ^= True
        head, back = back, head
    else:
        if value[1] == "1":
            head += [value[2]]
        else:
            back += [value[2]]

if reverse == False:
    head.reverse()
    print("".join(head + Slist + back))
else:
    head.reverse()
    print("".join(head + Slist[::-1] + back))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
for idx, value in enumerate(Query):
    if int(value[0]) == 1:
        Slist= Slist[::-1]
    else:
        if int(value[1]) == 1:
            Slist = [value[2]] + Slist
        else:
            Slist.append(value[2])
print("".join(Slist))

Fixed submission:
S = input()
Slist = [S[i] for i in range(len(S))]
Q = int(input())
Query = [list(input().split()) for i in range(Q)]
Qlen = len(Query)
reverse = False
back = []
head = []

for idx, value in enumerate(Query):
    if value[0] == "1":
        reverse ^= True
        head, back = back, head
    else:
        if value[1] == "1":
            head += [value[2]]
        else:
            back += [value[2]]

if reverse == False:
    head.reverse()
    print("".join(head + Slist + back))
else:
    head.reverse()
    print("".join(head + Slist[::-1] + back))