Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    ans = [input()]
    n = int(input())
    vec = 1
    for i in range(n):
        q = sys.stdin.readline().rstrip()
        if q == "1":
            vec *= -1
        else:
            if ((q[2] == "1") and (vec == 1)) or ((q[2] == "2") and (vec == -1)):
                ans.insert(0, q[4])
            else:
                ans.append(q[4])
    ans = ''.join(ans)
    if vec == -1:
        ans = ans[::-1]
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
from collections import deque

def main():
    ans = deque(input())
    n = int(input())
    vec = 1
    for i in range(n):
        q = input()
        if q == "1":
            vec *= -1
        else:
            _,o,s = q.split()
            if ((o == "1") and (vec == 1)) or ((o == "2") and (vec == -1)):
                ans.appendleft(s)
            else:
                ans.append(s)
    if vec == -1:
        ans.reverse()
    ans = ''.join(ans)
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    ans = input()
    n = int(input())
    vec = 1
    for i in range(n):
        q = sys.stdin.readline().rstrip()
        if q == "1":
            vec *= -1
        else:
            if ((q[2] == "1") and (vec == 1)) or ((q[2] == "2") and (vec == -1)):
                ans = q[4] + ans
            else:
                ans += q[4]
    if vec == -1:
        ans = ans[::-1]
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
from collections import deque

def main():
    ans = deque(input())
    n = int(input())
    vec = 1
    for i in range(n):
        q = input()
        if q == "1":
            vec *= -1
        else:
            _,o,s = q.split()
            if ((o == "1") and (vec == 1)) or ((o == "2") and (vec == -1)):
                ans.appendleft(s)
            else:
                ans.append(s)
    if vec == -1:
        ans.reverse()
    ans = ''.join(ans)
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
ans = input()
n = int(input())
vec = 1
for i in range(n):
    query = input()
    if query == "1":
        vec *= -1
    else:
        _,option,str = query.split()
        if ((option == "1") and (vec == 1)) or ((option == "2") and (vec == -1)):
            ans = str + ans
        else:
            ans += str
if vec == -1:
    ans = ans[::-1]
print(ans)

Fixed submission:
from collections import deque

def main():
    ans = deque(input())
    n = int(input())
    vec = 1
    for i in range(n):
        q = input()
        if q == "1":
            vec *= -1
        else:
            _,o,s = q.split()
            if ((o == "1") and (vec == 1)) or ((o == "2") and (vec == -1)):
                ans.appendleft(s)
            else:
                ans.append(s)
    if vec == -1:
        ans.reverse()
    ans = ''.join(ans)
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
ans = input()
n = int(input())
for i in range(n):
    query = input()
    if query == "1":
        ans = ''.join(reversed(list(ans)))
    else:
        _,option,str = query.split()
        if option == "1":
            ans = str + ans
        else:
            ans += str
print(ans)

Fixed submission:
from collections import deque

def main():
    ans = deque(input())
    n = int(input())
    vec = 1
    for i in range(n):
        q = input()
        if q == "1":
            vec *= -1
        else:
            _,o,s = q.split()
            if ((o == "1") and (vec == 1)) or ((o == "2") and (vec == -1)):
                ans.appendleft(s)
            else:
                ans.append(s)
    if vec == -1:
        ans.reverse()
    ans = ''.join(ans)
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
ans = input()
n = int(input())
for i in range(n):
    query = input()
    if query == "1":
        ans = ''.join(list(ans).reverse())
    else:
        _,option,str = query.split()
        if option == "1":
            ans = str + ans
        else:
            ans += str
print(ans)

Fixed submission:
from collections import deque

def main():
    ans = deque(input())
    n = int(input())
    vec = 1
    for i in range(n):
        q = input()
        if q == "1":
            vec *= -1
        else:
            _,o,s = q.split()
            if ((o == "1") and (vec == 1)) or ((o == "2") and (vec == -1)):
                ans.appendleft(s)
            else:
                ans.append(s)
    if vec == -1:
        ans.reverse()
    ans = ''.join(ans)
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
ans = input()
n = int(input())
for i in range(n):
    query = input()
    if query == "1":
        ans = ans[::-1]
    else:
        _,option,str = query.split()
        if option == "1":
            ans = str + ans
        else:
            ans += str
print(ans)

Fixed submission:
from collections import deque

def main():
    ans = deque(input())
    n = int(input())
    vec = 1
    for i in range(n):
        q = input()
        if q == "1":
            vec *= -1
        else:
            _,o,s = q.split()
            if ((o == "1") and (vec == 1)) or ((o == "2") and (vec == -1)):
                ans.appendleft(s)
            else:
                ans.append(s)
    if vec == -1:
        ans.reverse()
    ans = ''.join(ans)
    print(ans)

if __name__ == '__main__':
    main()