Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines

s = readline().rstrip()
q = readline()
queries = readlines()
s = deque(s)
tot_1 = 0
for i in queries:
    if i[0] == '1':
        tot_1 += 1
        continue
    c = i[4]
    if (tot_1 + int(i[2])) % 2 == 0:
        s.append(c)
    else:
        s.appendleft(c)
ans = "".join(queue) if tot_1 % 2 == 0 else "".join(reversed(queue))
print(ans)

Fixed submission:
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines

s = readline().rstrip()
q = readline()
queries = readlines()
s = deque(s)
tot_1 = 0
for i in queries:
    if i[0] == '1':
        tot_1 += 1
        continue
    c = i[4]
    if (tot_1 + int(i[2])) % 2 == 0:
        s.append(c)
    else:
        s.appendleft(c)
ans = "".join(s) if tot_1 % 2 == 0 else "".join(reversed(s))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines

s = readline().rstrip()
q = readline()
queries = readlines()
tot_1 = 0
for i in queries:
    if i[0] == '1':
        tot_1 += 1
        continue
    if (tot_1 + int(i[2])) % 2 == 0:
        s = s + i[4]
    else:
        s = i[4] + s
if tot_1 % 2 == 1:
    s = s[::-1]
print(s)


Fixed submission:
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines

s = readline().rstrip()
q = readline()
queries = readlines()
s = deque(s)
tot_1 = 0
for i in queries:
    if i[0] == '1':
        tot_1 += 1
        continue
    c = i[4]
    if (tot_1 + int(i[2])) % 2 == 0:
        s.append(c)
    else:
        s.appendleft(c)
ans = "".join(s) if tot_1 % 2 == 0 else "".join(reversed(s))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines

s = readline().rstrip()
q = readline()
queries = readlines()
tot_1 = 0
for i in queries:
    if i[0] == '1':
        tot_1 += 1
    else:
        if (tot_1 + int(i[2])) % 2 == 0:
            s = s + i[4]
        else:
            s = i[4] + s
if tot_1 % 2 == 1:
    s = s[::-1]
print(s)

Fixed submission:
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines

s = readline().rstrip()
q = readline()
queries = readlines()
s = deque(s)
tot_1 = 0
for i in queries:
    if i[0] == '1':
        tot_1 += 1
        continue
    c = i[4]
    if (tot_1 + int(i[2])) % 2 == 0:
        s.append(c)
    else:
        s.appendleft(c)
ans = "".join(s) if tot_1 % 2 == 0 else "".join(reversed(s))
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines

s = readline().rstrip()
queries = readlines()
tot_1 = 0
for i in queries:
    if i[0] == '1':
        tot_1 += 1
    else:
        if (tot_1 + int(i[2])) % 2 == 0:
            s = s + i[4]
        else:
            s = i[4] + s
if tot_1 % 2 == 1:
    s = s[::-1]
print(s)

Fixed submission:
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines

s = readline().rstrip()
q = readline()
queries = readlines()
s = deque(s)
tot_1 = 0
for i in queries:
    if i[0] == '1':
        tot_1 += 1
        continue
    c = i[4]
    if (tot_1 + int(i[2])) % 2 == 0:
        s.append(c)
    else:
        s.appendleft(c)
ans = "".join(s) if tot_1 % 2 == 0 else "".join(reversed(s))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
tot_1 = 0
for i in range(q):
    l = list(input().split())
    if l[0] == '1':
        tot_1 += 1
    elif l[0] == '2':
        if (tot_1 + int(l[1])) % 2 == 0:
            s = s + l[2]
        else:
            s = l[2] + s
if tot_1 % 2 == 1:
    s = s[::-1]
print(s)


Fixed submission:
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines

s = readline().rstrip()
q = readline()
queries = readlines()
s = deque(s)
tot_1 = 0
for i in queries:
    if i[0] == '1':
        tot_1 += 1
        continue
    c = i[4]
    if (tot_1 + int(i[2])) % 2 == 0:
        s.append(c)
    else:
        s.appendleft(c)
ans = "".join(s) if tot_1 % 2 == 0 else "".join(reversed(s))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
q = int(input())
for i in range(q):
    l = list(map(str, input().split()))
    if l[0] == '1':
        s = s[::-1]
    elif l[0] == '2' and l[1] == '1':
        s = l[2] + s
    elif l[0] == '2' and l[1] == '2':
        s = s + l[2]
print(s)

Fixed submission:
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines

s = readline().rstrip()
q = readline()
queries = readlines()
s = deque(s)
tot_1 = 0
for i in queries:
    if i[0] == '1':
        tot_1 += 1
        continue
    c = i[4]
    if (tot_1 + int(i[2])) % 2 == 0:
        s.append(c)
    else:
        s.appendleft(c)
ans = "".join(s) if tot_1 % 2 == 0 else "".join(reversed(s))
print(ans)