Buggy python submission (verdict: Runtime Error):
from collections import deque
s=deque(list(input().split()))
ans=""
q=int(input())
flag=True
for i in range(q):
  ques=list(input().split())
  if ques[0]=="1":
    flag=not flag
    #print("1",s)
  else:
    if ques[1]=="1":
      if flag:
        s.appendleft(ques[2])
        #print("2",s)
      else:
        s.append(ques[2])
    else:
      if flag:
        s.append(ques[2])
      else:
        s.appendleft(ques[2])
      #print("22",s)
if flag==False:
    s = list(s).reverse()
print("".join(map(str, s)))

Fixed submission:
from collections import deque

S = input()
Q = int(input())
ans = deque(S)
revcnt = 0
for i in range(Q):
    data = list(input().split())
    if data[0] == '1':
        revcnt += 1
        continue

    if data[1] == '1':
        if revcnt % 2 == 0:
            ans.appendleft(data[2])
        else:
            ans.append(data[2])
    else:
        if revcnt % 2 == 0:
            ans.append(data[2])
        else:
            ans.appendleft(data[2])

if revcnt % 2 != 0:
    print(''.join(reversed(list(ans))))
else:
    print(''.join(list(ans)))

Buggy python submission (verdict: Runtime Error):
s=input()
q=int(input())
dp=["" for i in range(q+1)]
dp[0]=s
flag=0
for i in range(q):
  ques=list(input().split())
  if ques[0]=="1":
    dp[i+1]=dp[i]
    flag+=1
  else:
    if ques[1]=="1":
      if flag%2==0:
        dp[i+1]=ques[2]+dp[i]
      else:
        dp[i+1]=dp[i]+ques[2]
    else:
      if flag%2==0:
        dp[i+1]=dp[i]+ques[2]
      else:
        dp[i+1]=ques[2]+dp[i]
if flag%2==1:
  ans=dp[q][::-1]
else:
  ans=dp[q]
print(ans)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
ans = deque(S)
revcnt = 0
for i in range(Q):
    data = list(input().split())
    if data[0] == '1':
        revcnt += 1
        continue

    if data[1] == '1':
        if revcnt % 2 == 0:
            ans.appendleft(data[2])
        else:
            ans.append(data[2])
    else:
        if revcnt % 2 == 0:
            ans.append(data[2])
        else:
            ans.appendleft(data[2])

if revcnt % 2 != 0:
    print(''.join(reversed(list(ans))))
else:
    print(''.join(list(ans)))

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
dp=["" for i in range(q+1)]
dp[0]=s
flag=0
for i in range(q):
  ques=list(input().split())
  if ques[0]=="1":
    dp[i+1]=dp[i]
    flag+=1
  else:
    if ques[1]=="1":
      if flag%2==0:
        dp[i+1]=ques[2]+dp[i]
      else:
        dp[i+1]=dp[i]+ques[2]
    else:
      if flag%2==0:
        dp[i+1]=dp[i]+ques[2]
      else:
        dp[i+1]=ques[2]+dp[i]
if flag%2==1:
  ans=dp[q][::-1]
else:
  ans=dp[q]
print(ans)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
ans = deque(S)
revcnt = 0
for i in range(Q):
    data = list(input().split())
    if data[0] == '1':
        revcnt += 1
        continue

    if data[1] == '1':
        if revcnt % 2 == 0:
            ans.appendleft(data[2])
        else:
            ans.append(data[2])
    else:
        if revcnt % 2 == 0:
            ans.append(data[2])
        else:
            ans.appendleft(data[2])

if revcnt % 2 != 0:
    print(''.join(reversed(list(ans))))
else:
    print(''.join(list(ans)))

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
ans=""
q=int(input())
switch=0

for i in range(q):
  ques=list(input().split())
  if ques[0]=="1":
    switch+=1
    #print("1",s)
  else:
    if ques[1]=="1":
      if switch%2==0:
        s=ques[2]+s
        #print("2",s)
      else:
        s=s+ques[2]
    else:
      if switch%2==0:
        s=s+ques[2]
      else:
        s=ques[2]+s
        #print("22",s)
if switch%2==1:
  ans=s[::-1]
else:
  ans=s
print(ans)


Fixed submission:
from collections import deque

S = input()
Q = int(input())
ans = deque(S)
revcnt = 0
for i in range(Q):
    data = list(input().split())
    if data[0] == '1':
        revcnt += 1
        continue

    if data[1] == '1':
        if revcnt % 2 == 0:
            ans.appendleft(data[2])
        else:
            ans.append(data[2])
    else:
        if revcnt % 2 == 0:
            ans.append(data[2])
        else:
            ans.appendleft(data[2])

if revcnt % 2 != 0:
    print(''.join(reversed(list(ans))))
else:
    print(''.join(list(ans)))