Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

sign = 1
head = ""
tail = ""
for i in range(Q):
    Q = [i for i in input().split()]
    if Q[0] == "1":
        sign *= -1
    else:
        if Q[1] == "1" and sign == 1:
            head = Q[2] + head
        elif Q[1] == "1" and sign == -1:
            tail = tail + Q[2]
        elif Q[1] == "2" and sign == 1:
            tail = tail + Q[2]
        elif Q[1] == "2" and sign == -1:
            head = Q[2] + head

if sign==1:
    print(head + S + tail)
elif sign==-1:
    S = (head + S + tail)[::-1]
    print(S)


Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

sign = 1
head = ""
tail = ""
for i in range(Q):
    Q = input().split()
    if Q[0] == "1":
        sign *= -1
    else:
        if int(Q[1]) * sign == 1:
            S.appendleft(Q[2])
        elif int(Q[1]) * sign == -1:
            S.append(Q[2])
        elif int(Q[1]) * sign == 2:
            S.append(Q[2])
        elif int(Q[1]) * sign == -2:
            S.appendleft(Q[2])

if sign==1:
    print("".join(S))
elif sign==-1:
    S.reverse()
    print("".join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

for i in range(Q):
    Q = [i for i in input().split()]
    if Q[0] == "1":
        S = S[::-1]
    else:
        if Q[1] == "1":
            S = Q[2] + S
        elif Q[1] == "2":
            S = S + Q[2]

print(S)

Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

sign = 1
head = ""
tail = ""
for i in range(Q):
    Q = input().split()
    if Q[0] == "1":
        sign *= -1
    else:
        if int(Q[1]) * sign == 1:
            S.appendleft(Q[2])
        elif int(Q[1]) * sign == -1:
            S.append(Q[2])
        elif int(Q[1]) * sign == 2:
            S.append(Q[2])
        elif int(Q[1]) * sign == -2:
            S.appendleft(Q[2])

if sign==1:
    print("".join(S))
elif sign==-1:
    S.reverse()
    print("".join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())

for i in range(Q):
    Q = [i for i in input().split()]
    if Q[0] == "1":
        S = S[::-1]
    else:
        if Q[1] == "1":
            S.insert(0,Q[2])
        elif Q[1] == "2":
            S.append(Q[2])

print("".join(S))


Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

sign = 1
head = ""
tail = ""
for i in range(Q):
    Q = input().split()
    if Q[0] == "1":
        sign *= -1
    else:
        if int(Q[1]) * sign == 1:
            S.appendleft(Q[2])
        elif int(Q[1]) * sign == -1:
            S.append(Q[2])
        elif int(Q[1]) * sign == 2:
            S.append(Q[2])
        elif int(Q[1]) * sign == -2:
            S.appendleft(Q[2])

if sign==1:
    print("".join(S))
elif sign==-1:
    S.reverse()
    print("".join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())

for i in range(Q):
    Q = [i for i in input().split()]
    if Q[0] == "1":
        S = S[::-1]
    else:
        if Q[1] == "1":
            S.insert(0,Q[2])
        elif Q[1] == "2":
            S.append(Q[2])

print("".join(S))


Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

sign = 1
head = ""
tail = ""
for i in range(Q):
    Q = input().split()
    if Q[0] == "1":
        sign *= -1
    else:
        if int(Q[1]) * sign == 1:
            S.appendleft(Q[2])
        elif int(Q[1]) * sign == -1:
            S.append(Q[2])
        elif int(Q[1]) * sign == 2:
            S.append(Q[2])
        elif int(Q[1]) * sign == -2:
            S.appendleft(Q[2])

if sign==1:
    print("".join(S))
elif sign==-1:
    S.reverse()
    print("".join(S))

Buggy python submission (verdict: Runtime Error):
import math

A,B = [int(i) for i in input().split()]
emax = (A + 1) / 0.08
emin = math.ceil(A / 0.08)
tmax = (B + 1) / 0.1
tmin = B / 0.1

print(emax,emin)
print(tmax,tmin)

if emin < tmax and emin >= tmin:
    print(emin)
elif tmin < emax and tmin >= emin:
    print(int(tmin))
else:
    print(-1)


Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

sign = 1
head = ""
tail = ""
for i in range(Q):
    Q = input().split()
    if Q[0] == "1":
        sign *= -1
    else:
        if int(Q[1]) * sign == 1:
            S.appendleft(Q[2])
        elif int(Q[1]) * sign == -1:
            S.append(Q[2])
        elif int(Q[1]) * sign == 2:
            S.append(Q[2])
        elif int(Q[1]) * sign == -2:
            S.appendleft(Q[2])

if sign==1:
    print("".join(S))
elif sign==-1:
    S.reverse()
    print("".join(S))