Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())

r = False
for i in range(Q):
    x = input().split()
    
    if x[0] == "1":
        r = not r
        
    else:
        if x[1] == "1":
            if r == False :
                S.insert(0, x[2])
            else:
                S.append(x[2])
        else:
            if r == True :
                S.insert(0, x[2])
            else:
                S.append(x[2])
        
if r:
    print("".join(S[::-1]))
else:
    print("".join(S))

Fixed submission:
from collections import deque
S = list(input())
Q = int(input())

day = deque(S)

r = False
for i in range(Q):
    x = input().split()
    
    if x[0] == "1":
        r = not r
        
    else:
        if x[1] == "1":
            if r == False :
                day.appendleft(x[2])
            else:
                day.append(x[2])
        else:
            if r == True :
                day.appendleft(x[2])
            else:
                day.append(x[2])
                
day = list(day)
        
if r:
    print("".join(day[::-1]))
else:
    print("".join(day))

Buggy python submission (verdict: Runtime Error):
S = list(input())
Q = int(input())
 
r = False
for i in range(Q):
    x = input().split()
    
    if x[0] == "1":
        r = not r
        
    else:
        if x[1] == "1":
            if r == False :
                S.insert(0, x[2])
            else:
                S.append(x[2])
        else:
            if r == True :
                S.insert(0, x[2])
            else:
                S.append(x[2])
        
if r:
    print("".join(S[::-1]))
else:
    print("".join(S))
S = list(input())
Q = int(input())

r = False
for i in range(Q):
    x = input().split()
    
    if x[0] == "1":
        r = not r
        
    else:
        if x[1] == "1":
            if r == False :
                S.insert(0, x[2])
            else:
                S.append(x[2])
        else:
            if r == True :
                S.insert(0, x[2])
            else:
                S.append(x[2])
        
if r:
    print("".join(S[::-1]))
else:
    print("".join(S))

Fixed submission:
from collections import deque
S = list(input())
Q = int(input())

day = deque(S)

r = False
for i in range(Q):
    x = input().split()
    
    if x[0] == "1":
        r = not r
        
    else:
        if x[1] == "1":
            if r == False :
                day.appendleft(x[2])
            else:
                day.append(x[2])
        else:
            if r == True :
                day.appendleft(x[2])
            else:
                day.append(x[2])
                
day = list(day)
        
if r:
    print("".join(day[::-1]))
else:
    print("".join(day))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())

r = False
for i in range(Q):
    x = input().split()
    
    if x[0] == "1":
        r = not r
        
    else:
        if x[1] == "1":
            if r == False :
                S.insert(0, x[2])
            else:
                S.append(x[2])
        else:
            if r == True :
                S.insert(0, x[2])
            else:
                S.append(x[2])
        
if r:
    print("".join(S[::-1]))
else:
    print("".join(S))

Fixed submission:
from collections import deque
S = list(input())
Q = int(input())

day = deque(S)

r = False
for i in range(Q):
    x = input().split()
    
    if x[0] == "1":
        r = not r
        
    else:
        if x[1] == "1":
            if r == False :
                day.appendleft(x[2])
            else:
                day.append(x[2])
        else:
            if r == True :
                day.appendleft(x[2])
            else:
                day.append(x[2])
                
day = list(day)
        
if r:
    print("".join(day[::-1]))
else:
    print("".join(day))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

r = False
for i in range(Q):
    x = input().split()
    
    if x[0] == "1":
        r = not r
        
    else:
        if x[1] == "1":
            if r == False :
                S = x[2] + S
            else:
                S = S + x[2]
        else:
            if r == True :
                S = x[2] + S
            else:
                S = S + x[2]
        
if r:
    print(S[::-1])
else:
    print(S)

Fixed submission:
from collections import deque
S = list(input())
Q = int(input())

day = deque(S)

r = False
for i in range(Q):
    x = input().split()
    
    if x[0] == "1":
        r = not r
        
    else:
        if x[1] == "1":
            if r == False :
                day.appendleft(x[2])
            else:
                day.append(x[2])
        else:
            if r == True :
                day.appendleft(x[2])
            else:
                day.append(x[2])
                
day = list(day)
        
if r:
    print("".join(day[::-1]))
else:
    print("".join(day))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

r = False
for i in range(Q):
    x = input().split()
    
    if x[0] == "1":
        r = not r
        
    else:
        if x[1] == "1":
            if r == False :
                S = x[2] + S
            else:
                S = S + x[2]
        else:
            if r == True :
                S = x[2] + S
            else:
                S = S + x[2]
        
if r:
    print(S[::-1])
else:
    print(S)

Fixed submission:
from collections import deque
S = list(input())
Q = int(input())

day = deque(S)

r = False
for i in range(Q):
    x = input().split()
    
    if x[0] == "1":
        r = not r
        
    else:
        if x[1] == "1":
            if r == False :
                day.appendleft(x[2])
            else:
                day.append(x[2])
        else:
            if r == True :
                day.appendleft(x[2])
            else:
                day.append(x[2])
                
day = list(day)
        
if r:
    print("".join(day[::-1]))
else:
    print("".join(day))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

for i in range(Q):
    x = input().split()
    
    if x[0] == "1":
        S = S[::-1]
    else:
        if x[1] == "1":
            S = x[2] + S
        else:
            S = S + x[2]
            
print(S)

Fixed submission:
from collections import deque
S = list(input())
Q = int(input())

day = deque(S)

r = False
for i in range(Q):
    x = input().split()
    
    if x[0] == "1":
        r = not r
        
    else:
        if x[1] == "1":
            if r == False :
                day.appendleft(x[2])
            else:
                day.append(x[2])
        else:
            if r == True :
                day.appendleft(x[2])
            else:
                day.append(x[2])
                
day = list(day)
        
if r:
    print("".join(day[::-1]))
else:
    print("".join(day))