Buggy python submission (verdict: Time Limit Exceeded):


s = input()
q = int(input())

def addflont(s,c):
    text = "".join([c,s])
    return text
def addback(s,c):
    text = "".join([s,c])
    return text

reverse = 0

for i in range(q):
    t = input()
    if t[0]=="1":
        reverse = reverse^1
    if t[0]=="2":
        if t[2]=="1":
            if reverse==0:
                s = addflont(s,t[4])
            else:
                s = addback(s,t[4])
        elif t[2]=="2":
            if reverse==0:
                s = addback(s,t[4])
            else:
                s = addflont(s,t[4])

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


Fixed submission:


s = input()
q = int(input())

def addflont(s,c):
    text = "".join([c,s])
    return text
def addback(s,c):
    text = "".join([s,c])
    return text

reverse = 0
r = "";u = ""
for i in range(q):
    t = input()
    if t[0]=="1":
        reverse = reverse^1
    if t[0]=="2":
        if t[2]=="1":
            if reverse==0:
                r = addflont(r,t[4])
            else:
                u = addback(u,t[4])
        elif t[2]=="2":
            if reverse==0:
                u = addback(u,t[4])
            else:
                r = addflont(r,t[4])

s = r + s + u
if reverse==1:
    print(s[::-1])
else:
    print(s)

Buggy python submission (verdict: Runtime Error):


s = input()
q = int(input())

def addflont(s,c):
    return c+s
def addback(s,c):
    return s+c

reverse = 0

for i in range(q):
    t = input()
    if t[0]=="1":
        reverse = reverse^1
    if t[0]=="2":
        if t[2]=="1":
            if reverse==0:
                s = c+s
            else:
                s = s+c
        elif t[2]=="2":
            if reverse==0:
                s = s+c
            else:
                s = c+s

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


Fixed submission:


s = input()
q = int(input())

def addflont(s,c):
    text = "".join([c,s])
    return text
def addback(s,c):
    text = "".join([s,c])
    return text

reverse = 0
r = "";u = ""
for i in range(q):
    t = input()
    if t[0]=="1":
        reverse = reverse^1
    if t[0]=="2":
        if t[2]=="1":
            if reverse==0:
                r = addflont(r,t[4])
            else:
                u = addback(u,t[4])
        elif t[2]=="2":
            if reverse==0:
                u = addback(u,t[4])
            else:
                r = addflont(r,t[4])

s = r + s + u
if reverse==1:
    print(s[::-1])
else:
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):


s = input()
q = int(input())

def addflont(s,c):
    return c+s
def addback(s,c):
    return s+c

reverse = 0

for i in range(q):
    t = input()
    if t[0]=="1":
        reverse = reverse^1
    if t[0]=="2":
        if t[2]=="1":
            if reverse==0:
                s = addflont(s,t[4])
            else:
                s = addback(s,t[4])
        elif t[2]=="2":
            if reverse==0:
                s = addback(s,t[4])
            else:
                s = addflont(s,t[4])

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


Fixed submission:


s = input()
q = int(input())

def addflont(s,c):
    text = "".join([c,s])
    return text
def addback(s,c):
    text = "".join([s,c])
    return text

reverse = 0
r = "";u = ""
for i in range(q):
    t = input()
    if t[0]=="1":
        reverse = reverse^1
    if t[0]=="2":
        if t[2]=="1":
            if reverse==0:
                r = addflont(r,t[4])
            else:
                u = addback(u,t[4])
        elif t[2]=="2":
            if reverse==0:
                u = addback(u,t[4])
            else:
                r = addflont(r,t[4])

s = r + s + u
if reverse==1:
    print(s[::-1])
else:
    print(s)

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

def addflont(s,c):
    return c+s
def addback(s,c):
    return s+c

reverse = 0

for i in range(q):
    t = input()
    if t[0]=="1":
        reverse += 1
    if t[0]=="2":
        if t[2]=="1":
            if reverse%2==0:
                s = addflont(s,t[4])
            else:
                s = addback(s,t[4])
        elif t[2]=="2":
            if reverse%2==0:
                s = addback(s,t[4])
            else:
                s = addflont(s,t[4])

if reverse%2==1:
    print(s[::-1])
else:
    print(s)


Fixed submission:


s = input()
q = int(input())

def addflont(s,c):
    text = "".join([c,s])
    return text
def addback(s,c):
    text = "".join([s,c])
    return text

reverse = 0
r = "";u = ""
for i in range(q):
    t = input()
    if t[0]=="1":
        reverse = reverse^1
    if t[0]=="2":
        if t[2]=="1":
            if reverse==0:
                r = addflont(r,t[4])
            else:
                u = addback(u,t[4])
        elif t[2]=="2":
            if reverse==0:
                u = addback(u,t[4])
            else:
                r = addflont(r,t[4])

s = r + s + u
if reverse==1:
    print(s[::-1])
else:
    print(s)

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

def addflont(s,c):
    return c+s
def addback(s,c):
    return s+c

reverse = 0

for i in range(q):
    t = [str(i) for i in input().split()]

    if t[0]=="1":
        reverse += 1
    if t[0]=="2":
        if t[1]=="1":
            if reverse%2==0:
                s = addflont(s,t[2])
            else:
                s = addback(s,t[2])
        elif t[1]=="2":
            if reverse%2==0:
                s = addback(s,t[2])
            else:
                s = addflont(s,t[2])

if reverse%2==1:
    print(s[::-1])
else:
    print(s)


Fixed submission:


s = input()
q = int(input())

def addflont(s,c):
    text = "".join([c,s])
    return text
def addback(s,c):
    text = "".join([s,c])
    return text

reverse = 0
r = "";u = ""
for i in range(q):
    t = input()
    if t[0]=="1":
        reverse = reverse^1
    if t[0]=="2":
        if t[2]=="1":
            if reverse==0:
                r = addflont(r,t[4])
            else:
                u = addback(u,t[4])
        elif t[2]=="2":
            if reverse==0:
                u = addback(u,t[4])
            else:
                r = addflont(r,t[4])

s = r + s + u
if reverse==1:
    print(s[::-1])
else:
    print(s)

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

def addflont(s,c):
    return c+s
def addback(s,c):
    return s+c

reverse = 0

for i in range(q):
    t = list(map(str,input().split()))
    if t[0]=="1":
        reverse += 1
    if t[0]=="2":
        if t[1]=="1":
            if reverse%2==0:
                s = addflont(s,t[2])
            else:
                s = addback(s,t[2])
        elif t[1]=="2":
            if reverse%2==0:
                s = addback(s,t[2])
            else:
                s = addflont(s,t[2])

if reverse%2==1:
    print(s[::-1])
else:
    print(s)


Fixed submission:


s = input()
q = int(input())

def addflont(s,c):
    text = "".join([c,s])
    return text
def addback(s,c):
    text = "".join([s,c])
    return text

reverse = 0
r = "";u = ""
for i in range(q):
    t = input()
    if t[0]=="1":
        reverse = reverse^1
    if t[0]=="2":
        if t[2]=="1":
            if reverse==0:
                r = addflont(r,t[4])
            else:
                u = addback(u,t[4])
        elif t[2]=="2":
            if reverse==0:
                u = addback(u,t[4])
            else:
                r = addflont(r,t[4])

s = r + s + u
if reverse==1:
    print(s[::-1])
else:
    print(s)