Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
rev = False
for i in range(q):
    inp = input()
    if inp[0] == "1":
        if rev:
            rev = False
        else:
            rev = True
    elif inp[2] == "1":
        a = inp[4]
        if rev:
            s.append(a)
        else:
            s.insert(0, a)
    else:
        a = inp[4]
        if rev:
            s.insert(0, a)
        else:
            s.append(a)
if rev:
    s.reverse()
print("".join(s))

Fixed submission:
s = list(input())
q = int(input())
l1 = []
l2 = []
rev = False
for i in range(q):
    inp = input()
    if inp[0] == "1":
        if rev:
            rev = False
        else:
            rev = True
    elif inp[2] == "1":
        a = inp[4]
        if rev:
            l2.append(a)
        else:
            l1.append(a)
    else:
        a = inp[4]
        if rev:
            l1.append(a)
        else:
            l2.append(a)
l1.reverse()
ans = l1 + s + l2
if rev:
    ans.reverse()
print("".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
rev = False
for i in range(q):
    inp = input().split()
    if len(inp) == 1:
        if rev:
            rev = False
        else:
            rev = True
    elif inp[1] == "1":
        a = inp[2]
        if rev:
            s.append(a)
        else:
                s.insert(0, a)
    else:
        a = inp[2]
        if rev:
            s.insert(0, a)
        else:
            s.append(a)
if rev:
    s.reverse()
print("".join(s))

Fixed submission:
s = list(input())
q = int(input())
l1 = []
l2 = []
rev = False
for i in range(q):
    inp = input()
    if inp[0] == "1":
        if rev:
            rev = False
        else:
            rev = True
    elif inp[2] == "1":
        a = inp[4]
        if rev:
            l2.append(a)
        else:
            l1.append(a)
    else:
        a = inp[4]
        if rev:
            l1.append(a)
        else:
            l2.append(a)
l1.reverse()
ans = l1 + s + l2
if rev:
    ans.reverse()
print("".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
rev = False
for i in range(q):
    inp = input().split()
    if len(inp) == 1:
        if rev:
            rev = False
        else:
            rev = True
    elif inp[1] == "1":
        a = inp[2]
        if rev:
            s.append(a)
        else:
                s.insert(0, a)
    else:
        a = inp[2]
        if rev:
            s.insert(0, a)
        else:
            s.append(a)
if rev:
    s.reverse()
print("".join(s))

Fixed submission:
s = list(input())
q = int(input())
l1 = []
l2 = []
rev = False
for i in range(q):
    inp = input()
    if inp[0] == "1":
        if rev:
            rev = False
        else:
            rev = True
    elif inp[2] == "1":
        a = inp[4]
        if rev:
            l2.append(a)
        else:
            l1.append(a)
    else:
        a = inp[4]
        if rev:
            l1.append(a)
        else:
            l2.append(a)
l1.reverse()
ans = l1 + s + l2
if rev:
    ans.reverse()
print("".join(ans))

Buggy python submission (verdict: Runtime Error):
s = list(input())
q = int(input())
rev = False
for i in range(q):
    print(input().split())
    if len(input()) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        if input()[2] == "1":
            a = input()[5]
            if rev:
                s.append(a)
            else:
                s.insert(0, a)
        else:
            a = input()[5]
            if rev:
                s.insert(0, a)
            else:
                s.append(a)
if rev:
    s.reverse()
print("".join(s))

Fixed submission:
s = list(input())
q = int(input())
l1 = []
l2 = []
rev = False
for i in range(q):
    inp = input()
    if inp[0] == "1":
        if rev:
            rev = False
        else:
            rev = True
    elif inp[2] == "1":
        a = inp[4]
        if rev:
            l2.append(a)
        else:
            l1.append(a)
    else:
        a = inp[4]
        if rev:
            l1.append(a)
        else:
            l2.append(a)
l1.reverse()
ans = l1 + s + l2
if rev:
    ans.reverse()
print("".join(ans))