Buggy python submission (verdict: Runtime Error):
x = input()
s = []
n = int(input())
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
    
a = ""
b = ""
c = 0
for i in range(n):
    if s[i][0] == "1":
        c += 1
        c = c%2
    else:
        if c == 0:
            if s[i][1] == "1":
                a = s[i][2] + a
            else:
                b = b + s[i][2]
        else:
            if s[i][1] == "1":
                b = b + s[i][2]
            else:
                a = s[i][2] + a
if c == 0:
    print(a + x + b)
else:
    print(reverse(b) + x + reverse(a))

Fixed submission:
x = input()
s = []
n = int(input())
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
    
a = ""
b = ""
c = 0
for i in range(n):
    if s[i][0] == "1":
        c += 1
        c = c%2
    else:
        if c == 0:
            if s[i][1] == "1":
                a = s[i][2] + a
            else:
                b = b + s[i][2]
        else:
            if s[i][1] == "1":
                b = b + s[i][2]
            else:
                a = s[i][2] + a
if c == 0:
    print(a + x + b)
else:
    print(''.join(list(reversed(b))) + ''.join(list(reversed(x))) + ''.join(list(reversed(a))))

Buggy python submission (verdict: Runtime Error):
x = input()
s = []
n = int(input())
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
    
a = ""
b = ""
c = 0
for i in range(n):
    if s[i][0] == "1":
        c += 1
        c = c%2
    else:
        if c == 0:
            if s[i][1] == "1":
                a = s[i][2] + a
            else:
                b.append(s[i][2])
        else:
            if s[i][1] == "1":
                b.append(s[i][2])
            else:
                a = s[i][2] + a
if c == 0:
    print(a + x + b)
else:
    print(b + x + a)

Fixed submission:
x = input()
s = []
n = int(input())
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
    
a = ""
b = ""
c = 0
for i in range(n):
    if s[i][0] == "1":
        c += 1
        c = c%2
    else:
        if c == 0:
            if s[i][1] == "1":
                a = s[i][2] + a
            else:
                b = b + s[i][2]
        else:
            if s[i][1] == "1":
                b = b + s[i][2]
            else:
                a = s[i][2] + a
if c == 0:
    print(a + x + b)
else:
    print(''.join(list(reversed(b))) + ''.join(list(reversed(x))) + ''.join(list(reversed(a))))

Buggy python submission (verdict: Runtime Error):
from collections import deque
d = deque()
S = input()
d.append(S)
s = []
n = int(input())
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)

for i in range(N):
    if s[i][0] == "1":
        d.reverse()
    else:
        if s[i][1] == "1":
            d.extendleft(s[i][2])
        else:
            d.extend(s[i][2])

print("".join(list(d)))

Fixed submission:
x = input()
s = []
n = int(input())
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
    
a = ""
b = ""
c = 0
for i in range(n):
    if s[i][0] == "1":
        c += 1
        c = c%2
    else:
        if c == 0:
            if s[i][1] == "1":
                a = s[i][2] + a
            else:
                b = b + s[i][2]
        else:
            if s[i][1] == "1":
                b = b + s[i][2]
            else:
                a = s[i][2] + a
if c == 0:
    print(a + x + b)
else:
    print(''.join(list(reversed(b))) + ''.join(list(reversed(x))) + ''.join(list(reversed(a))))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
S = list(input())
S.pop(-1)
n = int(input())
s = []
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
for i in range(n):
    if s[i][0] == "1":
        S.reverse()
    else:
        if s[i][1] == "1":
            S.insert(0,s[i][2])
        else:
            S.append(s[i][2])
print("".join(S))

Fixed submission:
x = input()
s = []
n = int(input())
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
    
a = ""
b = ""
c = 0
for i in range(n):
    if s[i][0] == "1":
        c += 1
        c = c%2
    else:
        if c == 0:
            if s[i][1] == "1":
                a = s[i][2] + a
            else:
                b = b + s[i][2]
        else:
            if s[i][1] == "1":
                b = b + s[i][2]
            else:
                a = s[i][2] + a
if c == 0:
    print(a + x + b)
else:
    print(''.join(list(reversed(b))) + ''.join(list(reversed(x))) + ''.join(list(reversed(a))))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
n = int(input())
s = []
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
for i in range(n):
    if s[i][0] == "1":
        S.reverse()
    else:
        if s[i][1] == "1":
            S.insert(0,s[i][2])
        else:
            S.append(s[i][2])

print("".join(S))

Fixed submission:
x = input()
s = []
n = int(input())
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
    
a = ""
b = ""
c = 0
for i in range(n):
    if s[i][0] == "1":
        c += 1
        c = c%2
    else:
        if c == 0:
            if s[i][1] == "1":
                a = s[i][2] + a
            else:
                b = b + s[i][2]
        else:
            if s[i][1] == "1":
                b = b + s[i][2]
            else:
                a = s[i][2] + a
if c == 0:
    print(a + x + b)
else:
    print(''.join(list(reversed(b))) + ''.join(list(reversed(x))) + ''.join(list(reversed(a))))