Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input = sys.stdin.readline


a = list(input())
a.pop(-1)

Q = int(input())
count = 0
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        count += 1
        # a.reverse()
    else:
        if count % 2 == 0:
            if q[1] == "1":
                # a.insert(0, q[2])
                b = deque(a)
                b.appendleft(q[2])
                a = list(b)
            else:
                a.append(q[2])
        else:
            if q[1] == "1":
                a.append(q[2])
            else:
                # a.insert(0, q[2])
                b = deque(a)
                b.appendleft(q[2])
                a = list(b)

if count % 2 != 0:
    a.reverse()
print("".join(a))


Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(4100000)


def main():
    a = deque(input())
    a.pop()

    a_append = a.append
    a_appendleft = a.appendleft

    Q = int(input())
    count = 0
    for _ in range(Q):
        q = list(input().split())
        if q[0] == "1":
            count += 1
        else:
            if count % 2 == 0:
                if q[1] == "1":
                    a_appendleft(q[2])
                else:
                    a_append(q[2])
            else:
                if q[1] == "1":
                    a_append(q[2])
                else:
                    a_appendleft(q[2])

    b = list(a)
    if count % 2 != 0:
        b.reverse()
    print("".join(b))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input = sys.stdin.readline


a = list(input())
a.pop(-1)

Q = int(input())
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        a.reverse()
    else:
        if q[1] == "1":
            # a.insert(0, q[2])
            b = deque(a)
            b.appendleft(q[2])
            a = list(b)
        else:
            a.append(q[2])
print("".join(a))


Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(4100000)


def main():
    a = deque(input())
    a.pop()

    a_append = a.append
    a_appendleft = a.appendleft

    Q = int(input())
    count = 0
    for _ in range(Q):
        q = list(input().split())
        if q[0] == "1":
            count += 1
        else:
            if count % 2 == 0:
                if q[1] == "1":
                    a_appendleft(q[2])
                else:
                    a_append(q[2])
            else:
                if q[1] == "1":
                    a_append(q[2])
                else:
                    a_appendleft(q[2])

    b = list(a)
    if count % 2 != 0:
        b.reverse()
    print("".join(b))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

a = list(input())
a.pop(-1)

Q = int(input())
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        a.reverse()
    else:
        if q[1] == "1":
            a.insert(0, q[2])
        else:
            a.append(q[2])
print("".join(a))


Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(4100000)


def main():
    a = deque(input())
    a.pop()

    a_append = a.append
    a_appendleft = a.appendleft

    Q = int(input())
    count = 0
    for _ in range(Q):
        q = list(input().split())
        if q[0] == "1":
            count += 1
        else:
            if count % 2 == 0:
                if q[1] == "1":
                    a_appendleft(q[2])
                else:
                    a_append(q[2])
            else:
                if q[1] == "1":
                    a_append(q[2])
                else:
                    a_appendleft(q[2])

    b = list(a)
    if count % 2 != 0:
        b.reverse()
    print("".join(b))


if __name__ == '__main__':
    main()