Buggy python submission (verdict: Runtime Error):
def main():
  from collections import deque
  s=input()
  q=int(input())
  turn = 2
  d=deque(s)

  for _ in [0]*q:
      query = input()
      if query[0] == "1":
          t = int(query)
          turn = 3 - turn
      else:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              d.append(c)
          else:
              d.appendleft(c)
  if turn == 2:
      print("".join(d))
  else:
      print("".join(d[::-1]))
main()


Fixed submission:
def main():
  from collections import deque
  s=input()
  q=int(input())
  turn = 2
  d=deque(s)

  for _ in [0]*q:
      query = input()
      if query[0] == "1":
          t = int(query)
          turn = 3 - turn
      else:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              d.append(c)
          else:
              d.appendleft(c)
  if turn == 2:
      print("".join(d))
  else:
      print("".join(list(d)[::-1]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s=input()
  q=int(input())
  turn = 2
  tmp=[]
  for i in s:
      tmp.append(i)
  for _ in [0]*q:
      query = input()
      if query[0] == "1":
          t = int(query)
          turn = 3 - turn
      else:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              tmp.append(c)
          else:
              tmp = [c] + tmp
  if turn == 2:
      print("".join(tmp))
  else:
      print("".join(tmp[::-1]))
main()


Fixed submission:
def main():
  from collections import deque
  s=input()
  q=int(input())
  turn = 2
  d=deque(s)

  for _ in [0]*q:
      query = input()
      if query[0] == "1":
          t = int(query)
          turn = 3 - turn
      else:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              d.append(c)
          else:
              d.appendleft(c)
  if turn == 2:
      print("".join(d))
  else:
      print("".join(list(d)[::-1]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s=input()
  q=int(input())
  turn = 2
  tmp=[]
  for i in s:
      tmp.append(i)
  for _ in [0]*q:
      query = input()
      try:
          t = int(query)
          turn = 3 - turn
      except ValueError:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              tmp.append(c)
          else:
              tmp = [c] + tmp
  if turn == 2:
      print("".join(tmp))
  else:
      print("".join(tmp[::-1]))
main()

Fixed submission:
def main():
  from collections import deque
  s=input()
  q=int(input())
  turn = 2
  d=deque(s)

  for _ in [0]*q:
      query = input()
      if query[0] == "1":
          t = int(query)
          turn = 3 - turn
      else:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              d.append(c)
          else:
              d.appendleft(c)
  if turn == 2:
      print("".join(d))
  else:
      print("".join(list(d)[::-1]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s=input()
  q=int(input())
  turn = 2

  for _ in [0]*q:
      query = input()
      try:
          t = int(query)
          turn = 3 - turn
      except ValueError:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              s = s + c
          else:
              s = c + s
  if turn == 2:
      print(s)
  else:
      print(s[::-1])
main()

Fixed submission:
def main():
  from collections import deque
  s=input()
  q=int(input())
  turn = 2
  d=deque(s)

  for _ in [0]*q:
      query = input()
      if query[0] == "1":
          t = int(query)
          turn = 3 - turn
      else:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              d.append(c)
          else:
              d.appendleft(c)
  if turn == 2:
      print("".join(d))
  else:
      print("".join(list(d)[::-1]))
main()

Buggy python submission (verdict: Runtime Error):


#E 
n,p=map(int,input().split())
s=input()



#D
def main():
  s=input()
  q=int(input())
  turn = 2

  for _ in [0]*q:
      query = input()
      try:
          t = int(query)
          turn = 3 - turn
      except ValueError:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              s = s + c
          else:
              s = c + s
  if turn == 2:
      print(s)
  else:
      print(s[::-1])
main()

Fixed submission:
def main():
  from collections import deque
  s=input()
  q=int(input())
  turn = 2
  d=deque(s)

  for _ in [0]*q:
      query = input()
      if query[0] == "1":
          t = int(query)
          turn = 3 - turn
      else:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              d.append(c)
          else:
              d.appendleft(c)
  if turn == 2:
      print("".join(d))
  else:
      print("".join(list(d)[::-1]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s=input()
  q=int(input())
  tmp=[]
  for i in s:
      tmp.append(i)

  for _ in [0]*q:
      query = input()
      try:
          t = int(query)
          tmp = tmp[::-1]
      except ValueError:
          t,f,c = map(str,query.split())
          if f == "1":
              tmp = [c] + tmp
          if f == "2":
              tmp.append(c)
  print(''.join(tmp))
main()

Fixed submission:
def main():
  from collections import deque
  s=input()
  q=int(input())
  turn = 2
  d=deque(s)

  for _ in [0]*q:
      query = input()
      if query[0] == "1":
          t = int(query)
          turn = 3 - turn
      else:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              d.append(c)
          else:
              d.appendleft(c)
  if turn == 2:
      print("".join(d))
  else:
      print("".join(list(d)[::-1]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s=input()
  q=int(input())
  for _ in [0]*q:
      query = input()
      try:
          t = int(query)
          s = s[::-1]
      except ValueError:
          t,f,c = map(str,query.split())
          if f == "1":
              s = c + s
          if f == "2":
              s = s + c
  print(s)
main()

Fixed submission:
def main():
  from collections import deque
  s=input()
  q=int(input())
  turn = 2
  d=deque(s)

  for _ in [0]*q:
      query = input()
      if query[0] == "1":
          t = int(query)
          turn = 3 - turn
      else:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              d.append(c)
          else:
              d.appendleft(c)
  if turn == 2:
      print("".join(d))
  else:
      print("".join(list(d)[::-1]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
for _ in range(q):
    query = input()
    try:
        t = int(query)
        s = s[::-1]
    except ValueError:
        t,f,c = map(str,query.split())
        if f == "1":
            s = c + s
        if f == "2":
            s = s + c
print(s)

Fixed submission:
def main():
  from collections import deque
  s=input()
  q=int(input())
  turn = 2
  d=deque(s)

  for _ in [0]*q:
      query = input()
      if query[0] == "1":
          t = int(query)
          turn = 3 - turn
      else:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              d.append(c)
          else:
              d.appendleft(c)
  if turn == 2:
      print("".join(d))
  else:
      print("".join(list(d)[::-1]))
main()