Buggy python submission (verdict: Time Limit Exceeded):

s = input()
q = int(input())
ht = 1
count = 0
for i in range(q):
    txt3 = input().split()
    if txt3[0] == '1':
        ht = 3 - ht
        count += 1
    else:
        if int(txt3[1]) == ht:
            s = txt3[2] + s
        else:
            s = s + txt3[2]
if count % 2 == 1:
    s = s[::-1]
print(s)


Fixed submission:

s = input()
q = int(input())
ht = 1
head = ''
tail = ''
count = 0
for i in range(q):
    txt3 = input().split()
    if txt3[0] == '1':
        ht = 3 - ht
        count += 1
    else:
        if int(txt3[1]) == ht:
            head = txt3[2] + head
        else:
            tail = tail + txt3[2]
s = head + s + tail
if count % 2 == 1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Runtime Error):
def ABC158D():
    s = input()
    q = int(input())
    for i in range(2, q):
        txt3 = input().split()
        print(f"txt3 = {txt3}")
        if txt3[0] == '1':
            s = s[::-1]
        else:
            if txt3[1] == '1':
                s = txt3[2] + s
            else:
                s = s + txt3[2]
    print(s)

ABC158D()


Fixed submission:

s = input()
q = int(input())
ht = 1
head = ''
tail = ''
count = 0
for i in range(q):
    txt3 = input().split()
    if txt3[0] == '1':
        ht = 3 - ht
        count += 1
    else:
        if int(txt3[1]) == ht:
            head = txt3[2] + head
        else:
            tail = tail + txt3[2]
s = head + s + tail
if count % 2 == 1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Runtime Error):
def ABC158D():
    txt2 = txt.split("\n")
    s = txt2[0]
    q = int(txt2[1])
    for i in range(2, len(txt2)):
        txt3 = txt2[i].split()
        if txt3[0] == '1':
            s = s[::-1]
        else:
            if txt3[1] == '1':
                s = txt3[2] + s
            else:
                s = s + txt3[2]
    print(s)

f = open("foot/bar.dat")
txt = f.read()
f.close()
ABC158D(txt)


Fixed submission:

s = input()
q = int(input())
ht = 1
head = ''
tail = ''
count = 0
for i in range(q):
    txt3 = input().split()
    if txt3[0] == '1':
        ht = 3 - ht
        count += 1
    else:
        if int(txt3[1]) == ht:
            head = txt3[2] + head
        else:
            tail = tail + txt3[2]
s = head + s + tail
if count % 2 == 1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Runtime Error):
def ABC158D():
    txt2 = txt.split("\n")
    s = txt2[0]
    q = int(txt2[1])
    for i in range(2, len(txt2)):
        txt3 = txt2[i].split()
        if txt3[0] == '1':
            s = s[::-1]
        else:
            if txt3[1] == '1':
                s = txt3[2] + s
            else:
                s = s + txt3[2]
    print(s)
                
ABC158D()


Fixed submission:

s = input()
q = int(input())
ht = 1
head = ''
tail = ''
count = 0
for i in range(q):
    txt3 = input().split()
    if txt3[0] == '1':
        ht = 3 - ht
        count += 1
    else:
        if int(txt3[1]) == ht:
            head = txt3[2] + head
        else:
            tail = tail + txt3[2]
s = head + s + tail
if count % 2 == 1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Runtime Error):
def ABC158D(txt):
    txt2 = txt.split("\n")
    s = txt2[0]
    q = int(txt2[1])
    for i in range(2, len(txt2)):
        txt3 = txt2[i].split()
        if txt3[0] == '1':
            s = s[::-1]
        else:
            if txt3[1] == '1':
                s = txt3[2] + s
            else:
                s = s + txt3[2]
    print(s)
                
ABC158D(txt)


Fixed submission:

s = input()
q = int(input())
ht = 1
head = ''
tail = ''
count = 0
for i in range(q):
    txt3 = input().split()
    if txt3[0] == '1':
        ht = 3 - ht
        count += 1
    else:
        if int(txt3[1]) == ht:
            head = txt3[2] + head
        else:
            tail = tail + txt3[2]
s = head + s + tail
if count % 2 == 1:
    s = s[::-1]
print(s)