Buggy python submission (verdict: Time Limit Exceeded):
import sys
S = input()
Q = int(input())
# queries = list(list(input().split()) for _ in range(Q))  # 後でroop回し直すのは2度手間

reverse = 0
# for query in queries:
for query in sys.stdin:
    if query[0] == '1':  # len(query)は改行記号の有無で変わるのでダメ
        reverse = 1 - reverse

    else:
        _, f, c = query.split()
        is_append_left = (reverse + int(f)) % 2
        if is_append_left:
            S = c + S
        else:
            S += c

if reverse:  # reverse処理は重い．実際，最後の一回で良い．
    S = S[::-1]

print(S)

Fixed submission:
import sys
from collections import deque
S = deque(input())
Q = int(input())
# queries = list(list(input().split()) for _ in range(Q))  # 後でroop回し直すのは2度手間

reverse = 0
# for query in queries:
for query in sys.stdin:
    if query[0] == '1':  # len(query)は改行記号の有無で変わるのでダメ
        reverse = 1 - reverse

    else:
        _, f, c = query.split()
        is_append_left = (reverse + int(f)) % 2
        if is_append_left:
            S.appendleft(c)  # listだとO(n)だが，dequeではO(1)
        else:
            S.append(c)

if reverse:  # reverse処理は重い．実際，最後の一回で良い．
    S.reverse()

print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
queries = list(list(input().split()) for _ in range(Q))

reverse = 0
for query in queries:
    if len(query) == 1:
        reverse = 1 - reverse

    else:
        is_append_left = (reverse + int(query[1])) % 2
        if is_append_left:
            S = query[2] + S
        else:
            S += query[2]

if reverse:  # reverse処理は重い．実際，最後の一回で良い．
    S = S[::-1]

print(S)


Fixed submission:
import sys
from collections import deque
S = deque(input())
Q = int(input())
# queries = list(list(input().split()) for _ in range(Q))  # 後でroop回し直すのは2度手間

reverse = 0
# for query in queries:
for query in sys.stdin:
    if query[0] == '1':  # len(query)は改行記号の有無で変わるのでダメ
        reverse = 1 - reverse

    else:
        _, f, c = query.split()
        is_append_left = (reverse + int(f)) % 2
        if is_append_left:
            S.appendleft(c)  # listだとO(n)だが，dequeではO(1)
        else:
            S.append(c)

if reverse:  # reverse処理は重い．実際，最後の一回で良い．
    S.reverse()

print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
queries = list(list(input().split()) for _ in range(Q))

reverse = 0
for query in queries:
    if len(query) == 1:
        reverse = 1 - reverse

    else:
        is_append_left = (reverse + int(query[1])) % 2
        if is_append_left:
            S = query[2] + S
        else:
            S += query[2]

if reverse:  # reverse処理は重い．実際，最後の一回で良い．
    S = S[::-1]

print(S)

Fixed submission:
import sys
from collections import deque
S = deque(input())
Q = int(input())
# queries = list(list(input().split()) for _ in range(Q))  # 後でroop回し直すのは2度手間

reverse = 0
# for query in queries:
for query in sys.stdin:
    if query[0] == '1':  # len(query)は改行記号の有無で変わるのでダメ
        reverse = 1 - reverse

    else:
        _, f, c = query.split()
        is_append_left = (reverse + int(f)) % 2
        if is_append_left:
            S.appendleft(c)  # listだとO(n)だが，dequeではO(1)
        else:
            S.append(c)

if reverse:  # reverse処理は重い．実際，最後の一回で良い．
    S.reverse()

print(''.join(S))

Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input().split())

division = N // (A + B)
count = division * A

count += N - division * (A + B) if A > N - division * (A + B) else A
print(count)

Fixed submission:
import sys
from collections import deque
S = deque(input())
Q = int(input())
# queries = list(list(input().split()) for _ in range(Q))  # 後でroop回し直すのは2度手間

reverse = 0
# for query in queries:
for query in sys.stdin:
    if query[0] == '1':  # len(query)は改行記号の有無で変わるのでダメ
        reverse = 1 - reverse

    else:
        _, f, c = query.split()
        is_append_left = (reverse + int(f)) % 2
        if is_append_left:
            S.appendleft(c)  # listだとO(n)だが，dequeではO(1)
        else:
            S.append(c)

if reverse:  # reverse処理は重い．実際，最後の一回で良い．
    S.reverse()

print(''.join(S))