Buggy python submission (verdict: Runtime Error):
rom collections import deque

s = input()
q = int(input())

t = deque(s)

reverse = False
for _ in range(q):
   query = input()
   if query[0] == '1':
      reverse = not reverse
   elif query[0] == '2':
      _, f, c = query.split()
      if f == '1':
         if reverse:
            t.append(c)
         else:
            t.appendleft(c)
      elif f == '2':
         if reverse:
            t.appendleft(c)
         else:
            t.append(c)

result = ''.join(t)
if reverse:
   result = result[::-1]
print(result)


Fixed submission:
from collections import deque

s = input()
q = int(input())

t = deque(s)

reverse = False
for _ in range(q):
   query = input()
   if query[0] == '1':
      reverse = not reverse
   elif query[0] == '2':
      _, f, c = query.split()
      if f == '1':
         if reverse:
            t.append(c)
         else:
            t.appendleft(c)
      elif f == '2':
         if reverse:
            t.appendleft(c)
         else:
            t.append(c)

result = ''.join(t)
if reverse:
   result = result[::-1]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

rev_s = 0
for i in range(q):
   tmp = list(input().split())
   if len(tmp) == 1:
      rev_s += 1
   else:
      f, c = int(tmp[1]), tmp[2]
      x = rev_s % 2
      if (x == 0 and f == 1) or (x == 1 and f == 2):
         l = [c, s]
      else:
         l = [s, c]
      s = ''.join(l)

if rev_s % 2 == 1:
   print(s[::-1])
else:
   print(s)


Fixed submission:
from collections import deque

s = input()
q = int(input())

t = deque(s)

reverse = False
for _ in range(q):
   query = input()
   if query[0] == '1':
      reverse = not reverse
   elif query[0] == '2':
      _, f, c = query.split()
      if f == '1':
         if reverse:
            t.append(c)
         else:
            t.appendleft(c)
      elif f == '2':
         if reverse:
            t.appendleft(c)
         else:
            t.append(c)

result = ''.join(t)
if reverse:
   result = result[::-1]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

rev_s = False
for i in range(q):
   tmp = list(input().split())
   if len(tmp) == 1:
      if rev_s == True:
         rev_s = False
      else:
         rev_s = True
   else:
      f, c = int(tmp[1]), tmp[2]
      if (rev_s == False and f == 1) or (rev_s == True and f == 2):
         s = c + s
      else:
         s = s + c

if rev_s == True:
   print(s[::-1])
else:
   print(s)


Fixed submission:
from collections import deque

s = input()
q = int(input())

t = deque(s)

reverse = False
for _ in range(q):
   query = input()
   if query[0] == '1':
      reverse = not reverse
   elif query[0] == '2':
      _, f, c = query.split()
      if f == '1':
         if reverse:
            t.append(c)
         else:
            t.appendleft(c)
      elif f == '2':
         if reverse:
            t.appendleft(c)
         else:
            t.append(c)

result = ''.join(t)
if reverse:
   result = result[::-1]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

rev_s = False
for i in range(q):
   tmp = list(input().split())
   if len(tmp) == 1:
      if rev_s == True:
         rev_s = False
      else:
         rev_s = True
   else:
      f, c = int(tmp[1]), tmp[2]
      if rev_s == False:
         if f == 1:
            s = c + s
         else:
            s = s + c
      else:
         if f == 1:
            s = s + c
         else:
            s = c + s

if rev_s == True:
   print(s[::-1])
else:
   print(s)


Fixed submission:
from collections import deque

s = input()
q = int(input())

t = deque(s)

reverse = False
for _ in range(q):
   query = input()
   if query[0] == '1':
      reverse = not reverse
   elif query[0] == '2':
      _, f, c = query.split()
      if f == '1':
         if reverse:
            t.append(c)
         else:
            t.appendleft(c)
      elif f == '2':
         if reverse:
            t.appendleft(c)
         else:
            t.append(c)

result = ''.join(t)
if reverse:
   result = result[::-1]
print(result)