Buggy python submission (verdict: Time Limit Exceeded):

s=input()
q=int(input())
p=0
for i in range(q):
    l=list(map(str,input().split()))
    if l[0]=="1":
        p=(p+1)%2
    else:
        if p==0:
            if l[1]=="1":
                s=l[2]+s
            else:
                s=s+l[2]
        else:
            if l[1]=="1":
                s+=l[2]
            else:
                s=l[2]+s

if p==0:
    print(s)
else:
    print(s[::-1])


Fixed submission:

s=input()
q=int(input())
p=0
a=""
b=""
for i in range(q):
    l=list(map(str,input().split()))
    if l[0]=="1":
        p=(p+1)%2
    else:
        if p==0:
            if l[1]=="1":
                a+=l[2]
            else:
                b+=l[2]
        else:
            if l[1]=="1":
                b+=l[2]
            else:
                a+=l[2]
if p==1:
    print(b[::-1]+s[::-1]+a)
else:
    print(a[::-1]+s+b)

Buggy python submission (verdict: Time Limit Exceeded):

s=input()
q=int(input())
p=0
for i in range(q):
    l=list(map(str,input().split()))
    if l[0]=="1":
        p=(p+1)%2
    else:
        if p==0:
            if l[1]=="1":
                s=l[2]+s
            else:
                s=s+l[2]
        else:
            if l[1]=="1":
                s+=l[2]
            else:
                s=l[2]+s

if p==0:
    print(s)
else:
    print(s[::-1])


Fixed submission:

s=input()
q=int(input())
p=0
a=""
b=""
for i in range(q):
    l=list(map(str,input().split()))
    if l[0]=="1":
        p=(p+1)%2
    else:
        if p==0:
            if l[1]=="1":
                a+=l[2]
            else:
                b+=l[2]
        else:
            if l[1]=="1":
                b+=l[2]
            else:
                a+=l[2]
if p==1:
    print(b[::-1]+s[::-1]+a)
else:
    print(a[::-1]+s+b)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
s=input()
ss=[]
for i in range(len(s)):
    ss.append(s[i])

    
arr=np.array(ss)

q=int(input())
for i in range(q):
    l=list(map(str,input().split()))
    if l[0]=="1":
        arr=arr[::-1]
        
    else:
        if l[1]=="1":
            arr=arr[::-1]
            arr=np.append(arr,l[2])
            arr=arr[::-1]
        if l[1]=="2":
            arr=np.append(arr,[l[2]])
        

a=arr.tolist()
for i in a:
    print(i,end="")

Fixed submission:

s=input()
q=int(input())
p=0
a=""
b=""
for i in range(q):
    l=list(map(str,input().split()))
    if l[0]=="1":
        p=(p+1)%2
    else:
        if p==0:
            if l[1]=="1":
                a+=l[2]
            else:
                b+=l[2]
        else:
            if l[1]=="1":
                b+=l[2]
            else:
                a+=l[2]
if p==1:
    print(b[::-1]+s[::-1]+a)
else:
    print(a[::-1]+s+b)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
s=input()

ss=[]
for i in range(len(s)):
    ss.append(s[i])
arr=np.array(ss)

q=int(input())
for i in range(q):
    l=list(map(str,input().split()))
    if l[0]=="1":
        arr=arr[::-1]
        
    else:
        if l[1]=="1":
            arr=arr[::-1]
            arr=np.hstack((arr,l[2]))
            arr=arr[::-1]
        if l[1]=="2":
            arr=np.hstack((arr,[l[2]]))
        

a=arr.tolist()
for i in a:
    print(i,end="")

Fixed submission:

s=input()
q=int(input())
p=0
a=""
b=""
for i in range(q):
    l=list(map(str,input().split()))
    if l[0]=="1":
        p=(p+1)%2
    else:
        if p==0:
            if l[1]=="1":
                a+=l[2]
            else:
                b+=l[2]
        else:
            if l[1]=="1":
                b+=l[2]
            else:
                a+=l[2]
if p==1:
    print(b[::-1]+s[::-1]+a)
else:
    print(a[::-1]+s+b)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
s=input()

ss=[]
for i in range(len(s)):
    ss.append(s[i])
arr=np.array(ss)

q=int(input())
for i in range(q):
    l=list(map(str,input().split()))
    if l[0]=="1":
        arr=arr[::-1]
        
    else:
        if l[1]=="1":
            arr=np.hstack((l[2],arr))
        if l[1]=="2":
            arr=np.hstack((arr,[l[2]]))
        

a=arr.tolist()
for i in a:
    print(i,end="")

Fixed submission:

s=input()
q=int(input())
p=0
a=""
b=""
for i in range(q):
    l=list(map(str,input().split()))
    if l[0]=="1":
        p=(p+1)%2
    else:
        if p==0:
            if l[1]=="1":
                a+=l[2]
            else:
                b+=l[2]
        else:
            if l[1]=="1":
                b+=l[2]
            else:
                a+=l[2]
if p==1:
    print(b[::-1]+s[::-1]+a)
else:
    print(a[::-1]+s+b)