Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    Q = int(input())
    revFlag = False
    for i in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            if revFlag:
                revFlag = False
            else:
                revFlag = True
        else:
            if tmp[1] == "1":
                if revFlag:
                    S += tmp[2]
                else:
                    S = tmp[2] + S
            else:
                if revFlag:
                    S = tmp[2] + S
                else:
                    S += tmp[2]
    if revFlag:
        S = list(S)
        S.reverse()
        print("".join(S))
    else:
        print(S)


if __name__ == '__main__':
    main()

Fixed submission:
from collections import deque

def main():
    S = deque(input())
    Q = int(input())
    revFlag = False
    for i in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            if revFlag:
                revFlag = False
            else:
                revFlag = True
        else:
            if tmp[1] == "1":
                if revFlag:
                    S.append(tmp[2])
                else:
                    S.appendleft(tmp[2])
            else:
                if revFlag:
                    S.appendleft(tmp[2])
                else:
                    S.append(tmp[2])
    if revFlag:
        S = list(S)
        S.reverse()
        print("".join(S))
    else:
        S = list(S)
        print("".join(S))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    Q = int(input())
    revFlag = False
    for i in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            if revFlag:
                revFlag = False
            else:
                revFlag = True
        else:
            if tmp[1] == "1":
                if revFlag:
                    tl = [S,tmp[2]]
                    S = "".join(tl)
                else:
                    tl = [tmp[2],S]
                    S = "".join(tl)
            else:
                if revFlag:
                    tl = [tmp[2],S]
                    S = "".join(tl)
                else:
                    tl = [S,tmp[2]]
                    S = "".join(tl)
    if revFlag:
        print(S[::-1])
    else:
        print(S)


if __name__ == '__main__':
    main()

Fixed submission:
from collections import deque

def main():
    S = deque(input())
    Q = int(input())
    revFlag = False
    for i in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            if revFlag:
                revFlag = False
            else:
                revFlag = True
        else:
            if tmp[1] == "1":
                if revFlag:
                    S.append(tmp[2])
                else:
                    S.appendleft(tmp[2])
            else:
                if revFlag:
                    S.appendleft(tmp[2])
                else:
                    S.append(tmp[2])
    if revFlag:
        S = list(S)
        S.reverse()
        print("".join(S))
    else:
        S = list(S)
        print("".join(S))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    Q = int(input())
    revFlag = False
    for i in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            if revFlag:
                revFlag = False
            else:
                revFlag = True
        else:
            if tmp[1] == "1":
                if revFlag:
                    S += tmp[2]
                else:
                    S = tmp[2] + S
            else:
                if revFlag:
                    S = tmp[2] + S
                else:
                    S += tmp[2]
    if revFlag:
        print(S[::-1])
    else:
        print(S)


if __name__ == '__main__':
    main()

Fixed submission:
from collections import deque

def main():
    S = deque(input())
    Q = int(input())
    revFlag = False
    for i in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            if revFlag:
                revFlag = False
            else:
                revFlag = True
        else:
            if tmp[1] == "1":
                if revFlag:
                    S.append(tmp[2])
                else:
                    S.appendleft(tmp[2])
            else:
                if revFlag:
                    S.appendleft(tmp[2])
                else:
                    S.append(tmp[2])
    if revFlag:
        S = list(S)
        S.reverse()
        print("".join(S))
    else:
        S = list(S)
        print("".join(S))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    Q = int(input())
    query = []
    revFlag = False
    for i in range(Q):
        query.append(list(input().split()))
    for i in range(Q):
        if query[i][0] == "1":
            if revFlag:
                revFlag = False
            else:
                revFlag = True
        else:
            if query[i][1] == "1":
                if revFlag:
                    S += query[i][2]
                else:
                    S = query[i][2] + S
            else:
                if revFlag:
                    S = query[i][2] + S
                else:
                    S += query[i][2]
    if revFlag:
        print(S[::-1])
    else:
        print(S)


if __name__ == '__main__':
    main()

Fixed submission:
from collections import deque

def main():
    S = deque(input())
    Q = int(input())
    revFlag = False
    for i in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            if revFlag:
                revFlag = False
            else:
                revFlag = True
        else:
            if tmp[1] == "1":
                if revFlag:
                    S.append(tmp[2])
                else:
                    S.appendleft(tmp[2])
            else:
                if revFlag:
                    S.appendleft(tmp[2])
                else:
                    S.append(tmp[2])
    if revFlag:
        S = list(S)
        S.reverse()
        print("".join(S))
    else:
        S = list(S)
        print("".join(S))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    Q = int(input())
    query = []
    revFlag = False
    for i in range(Q):
        query.append(list(input().split()))
    for i in range(Q):
        if query[i][0] == "1":
            if revFlag:
                revFlag = False
            else:
                revFlag = True
        else:
            if query[i][1] == "1":
                if revFlag:
                    S += query[i][2]
                else:
                    S = query[i][2] + S
            else:
                if revFlag:
                    S = query[i][2] + S
                else:
                    S += query[i][2]
    if revFlag:
        print(S[::-1])
    else:
        print(S)


if __name__ == '__main__':
    main()

Fixed submission:
from collections import deque

def main():
    S = deque(input())
    Q = int(input())
    revFlag = False
    for i in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            if revFlag:
                revFlag = False
            else:
                revFlag = True
        else:
            if tmp[1] == "1":
                if revFlag:
                    S.append(tmp[2])
                else:
                    S.appendleft(tmp[2])
            else:
                if revFlag:
                    S.appendleft(tmp[2])
                else:
                    S.append(tmp[2])
    if revFlag:
        S = list(S)
        S.reverse()
        print("".join(S))
    else:
        S = list(S)
        print("".join(S))


if __name__ == '__main__':
    main()