Buggy python submission (verdict: Time Limit Exceeded):


s = input()
q = int(input())



for i in range(q):
    inp = input()
    if inp[0] == "1":
        s = s[::-1]
    elif inp[2] == "1":
        s = inp[4] + s
    else:
        s = s + inp[4]


print(s)


Fixed submission:
from collections import deque

#inp = list(map(lambda x: int(x), input().split()))
#n,k = map(lambda x: int(x), input().split())
#p_n = list(map(lambda x:int(x),input().split()))


s = deque(input())
q = int(input())


cnt = 0
for i in range(q):
    inp = input().split()
    if inp[0] == "1":
        cnt += 1
    else:
        if inp[1] == "1":
            if cnt % 2 == 0:
                s.appendleft(inp[2])
            else:
                s.append(inp[2])
        else:
            if cnt % 2 == 0:
                s.append(inp[2])
            else:
                s.appendleft(inp[2])

ans = list(s)

if cnt % 2 == 1:
    ans = ans[::-1]

print(''.join(ans))

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



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


print(s)



Fixed submission:
from collections import deque

#inp = list(map(lambda x: int(x), input().split()))
#n,k = map(lambda x: int(x), input().split())
#p_n = list(map(lambda x:int(x),input().split()))


s = deque(input())
q = int(input())


cnt = 0
for i in range(q):
    inp = input().split()
    if inp[0] == "1":
        cnt += 1
    else:
        if inp[1] == "1":
            if cnt % 2 == 0:
                s.appendleft(inp[2])
            else:
                s.append(inp[2])
        else:
            if cnt % 2 == 0:
                s.append(inp[2])
            else:
                s.appendleft(inp[2])

ans = list(s)

if cnt % 2 == 1:
    ans = ans[::-1]

print(''.join(ans))

Buggy python submission (verdict: Time Limit Exceeded):

s = input()
q = int(input())

def rev(s):
    return "".join(list(reversed(s)))



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


print(s)


Fixed submission:
from collections import deque

#inp = list(map(lambda x: int(x), input().split()))
#n,k = map(lambda x: int(x), input().split())
#p_n = list(map(lambda x:int(x),input().split()))


s = deque(input())
q = int(input())


cnt = 0
for i in range(q):
    inp = input().split()
    if inp[0] == "1":
        cnt += 1
    else:
        if inp[1] == "1":
            if cnt % 2 == 0:
                s.appendleft(inp[2])
            else:
                s.append(inp[2])
        else:
            if cnt % 2 == 0:
                s.append(inp[2])
            else:
                s.appendleft(inp[2])

ans = list(s)

if cnt % 2 == 1:
    ans = ans[::-1]

print(''.join(ans))

Buggy python submission (verdict: Time Limit Exceeded):

s = input()
q = int(input())
#query = []
#for i in range(q):
 #   query.append(input())

def rev(s):
    return "".join(list(reversed(s)))



for i in range(q):
    inp = input().split()
    if inp[0] == "1":
        s = rev(s)
    elif inp[1] == "1":
        s = inp[2] + s
    else:
        s = s + inp[2]


print(s)

Fixed submission:
from collections import deque

#inp = list(map(lambda x: int(x), input().split()))
#n,k = map(lambda x: int(x), input().split())
#p_n = list(map(lambda x:int(x),input().split()))


s = deque(input())
q = int(input())


cnt = 0
for i in range(q):
    inp = input().split()
    if inp[0] == "1":
        cnt += 1
    else:
        if inp[1] == "1":
            if cnt % 2 == 0:
                s.appendleft(inp[2])
            else:
                s.append(inp[2])
        else:
            if cnt % 2 == 0:
                s.append(inp[2])
            else:
                s.appendleft(inp[2])

ans = list(s)

if cnt % 2 == 1:
    ans = ans[::-1]

print(''.join(ans))