Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
is_r = False
f_list = []
b_list = []

for i in range(q):
    q_i = input().split(' ')
    t_i = q_i[0]
    if t_i == '1':
        is_r = not is_r
    else:
        f_i = q_i[1]
        if (f_i == '1' and not is_r) or (f_i == '2' and is_r):
            f_list.insert(0, q_i[2])
        else:
            b_list.append(q_i[2])

f_list.append(s)
f_list.extend(b_list)
s = ''.join(f_list) if not is_r else ''.join(f_list)[::-1]
print(s)

Fixed submission:
s = input()
q = int(input())
is_r = False
f_list = []
b_list = []

for i in range(q):
    q_i = input().split(' ')
    t_i = q_i[0]
    if t_i == '1':
        is_r = not is_r
    else:
        f_i = q_i[1]
        if (f_i == '1' and not is_r) or (f_i == '2' and is_r):
            f_list.append(q_i[2])
        else:
            b_list.append(q_i[2])

f_list = f_list[::-1]
f_list.append(s)
f_list.extend(b_list)
s = ''.join(f_list) if not is_r else ''.join(f_list)[::-1]
print(s)

Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())
is_r = False
f_list = []
b_list = []

for i in range(q):
    q_i = input().split(' ')
    t_i = q_i[0]
    if t_i == '1':
        is_r = not is_r
    else:
        f_i = q_i[1]
        if (f_i == '1' and not is_r) or (f_i == '2' and is_r):
            f_list.append(q_i[2])
        else:
            b_list.append(q_i[2])

f_list = f_list[::-1]
f_list.append(s)
f_list.extend(b_list)
s = f_list.join('') if not is_r else f_list[::-1].join('')
print(s)

Fixed submission:
s = input()
q = int(input())
is_r = False
f_list = []
b_list = []

for i in range(q):
    q_i = input().split(' ')
    t_i = q_i[0]
    if t_i == '1':
        is_r = not is_r
    else:
        f_i = q_i[1]
        if (f_i == '1' and not is_r) or (f_i == '2' and is_r):
            f_list.append(q_i[2])
        else:
            b_list.append(q_i[2])

f_list = f_list[::-1]
f_list.append(s)
f_list.extend(b_list)
s = ''.join(f_list) if not is_r else ''.join(f_list)[::-1]
print(s)

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

for i in range(q):
    q_i = input().split(' ')
    t_i = q_i[0]
    if t_i == '1':
        is_r = not is_r
    else:
        f_i = q_i[1]
        if (f_i == '1' and not is_r) or (f_i == '2' and is_r):
            s = q_i[2] + s
        else:
            s = s + q_i[2]

s = s if not is_r else s[::-1]
print(s)

Fixed submission:
s = input()
q = int(input())
is_r = False
f_list = []
b_list = []

for i in range(q):
    q_i = input().split(' ')
    t_i = q_i[0]
    if t_i == '1':
        is_r = not is_r
    else:
        f_i = q_i[1]
        if (f_i == '1' and not is_r) or (f_i == '2' and is_r):
            f_list.append(q_i[2])
        else:
            b_list.append(q_i[2])

f_list = f_list[::-1]
f_list.append(s)
f_list.extend(b_list)
s = ''.join(f_list) if not is_r else ''.join(f_list)[::-1]
print(s)

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

for i in range(q):
    q_i = input().split(' ')
    t_i = q_i[0]
    if t_i == '1':
        s = s[::-1]
    else:
        f_i = q_i[1]
        if f_i == '1':
            s = q_i[2] + s
        else:
            s = s + q_i[2]

print(s)

Fixed submission:
s = input()
q = int(input())
is_r = False
f_list = []
b_list = []

for i in range(q):
    q_i = input().split(' ')
    t_i = q_i[0]
    if t_i == '1':
        is_r = not is_r
    else:
        f_i = q_i[1]
        if (f_i == '1' and not is_r) or (f_i == '2' and is_r):
            f_list.append(q_i[2])
        else:
            b_list.append(q_i[2])

f_list = f_list[::-1]
f_list.append(s)
f_list.extend(b_list)
s = ''.join(f_list) if not is_r else ''.join(f_list)[::-1]
print(s)