Buggy python submission (verdict: Time Limit Exceeded):
def op2(f, c, r):
  if r == 0:
    if f == "1":
      slist.insert(0, c)
    elif f == "2":
      slist.append(c)

  if r == 1:
    if f == "2":
      slist.insert(0, c)
    elif f == "1":
      slist.append(c)

S = input()
Q = int(input())
v = [list(input().split()) for i in range(Q)]
rev = 0
slist = [S]

for val in v:
  if val[0] == "1":
    if rev == 0:
      rev = 1
    elif rev == 1:
      rev = 0
  elif val[0] == "2":
    op2(val[1], val[2], rev)

ans = "".join(slist)

if rev == 0:
  print(ans)
else:
  print(ans[::-1])


Fixed submission:
def op2(f, c, r):
  if r == 0:
    if f == "1":
      left.append(c)
    elif f == "2":
      right.append(c)

  if r == 1:
    if f == "1":
      right.append(c)
    elif f == "2":
      left.append(c)

S = input()
Q = int(input())
v = [list(input().split()) for i in range(Q)]
rev = 0
left = []
right = []

for val in v:
  if val[0] == "1":
    if rev == 0:
      rev = 1
    elif rev == 1:
      rev = 0
  elif val[0] == "2":
    op2(val[1], val[2], rev)

nleft = left[::-1]
ans = "".join(nleft + [S] + right)

if rev == 0:
  print(ans)
else:
  print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
def op2(f, c, r):
  if r == 0:
    if f == "1":
      slist.insert(0, c)
    elif f == "2":
      slist.append(c)

  if r == 1:
    if f == "2":
      slist.insert(0, c)
    elif f == "1":
      slist.append(c)

S = input()
Q = int(input())
v = [list(input().split()) for i in range(Q)]
rev = 0
slist = [S]

for val in v:
  if val[0] == "1":
    if rev == 0:
      rev = 1
    elif rev == 1:
      rev = 0
  elif val[0] == "2":
    S = op2(val[1], val[2], rev)

ans = "".join(slist)

if rev == 0:
  print(ans)
else:
  print(ans[::-1])

Fixed submission:
def op2(f, c, r):
  if r == 0:
    if f == "1":
      left.append(c)
    elif f == "2":
      right.append(c)

  if r == 1:
    if f == "1":
      right.append(c)
    elif f == "2":
      left.append(c)

S = input()
Q = int(input())
v = [list(input().split()) for i in range(Q)]
rev = 0
left = []
right = []

for val in v:
  if val[0] == "1":
    if rev == 0:
      rev = 1
    elif rev == 1:
      rev = 0
  elif val[0] == "2":
    op2(val[1], val[2], rev)

nleft = left[::-1]
ans = "".join(nleft + [S] + right)

if rev == 0:
  print(ans)
else:
  print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
def op2(f, c, r, s):
  if r == 0:
    if f == "1":
      return (c + s)
    elif f == "2":
      return (s + c)

  if r == 1:
    if f == "2":
      return (c + s)
    elif f == "1":
      return (s + c)

S = input()
Q = int(input())
v = [list(input().split()) for i in range(Q)]
rev = 0

for val in v:
  if val[0] == "1":
    if rev == 0:
      rev = 1
    elif rev == 1:
      rev = 0
  elif val[0] == "2":
    S = op2(val[1], val[2], rev, S)
    
if rev == 0:
  print(S)
else:
  print(S[::-1])

Fixed submission:
def op2(f, c, r):
  if r == 0:
    if f == "1":
      left.append(c)
    elif f == "2":
      right.append(c)

  if r == 1:
    if f == "1":
      right.append(c)
    elif f == "2":
      left.append(c)

S = input()
Q = int(input())
v = [list(input().split()) for i in range(Q)]
rev = 0
left = []
right = []

for val in v:
  if val[0] == "1":
    if rev == 0:
      rev = 1
    elif rev == 1:
      rev = 0
  elif val[0] == "2":
    op2(val[1], val[2], rev)

nleft = left[::-1]
ans = "".join(nleft + [S] + right)

if rev == 0:
  print(ans)
else:
  print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
def op2(f, c):
  if r == 0:
    if f == "1":
      return (c + S)
    elif f == "2":
      return (S + c)

  if r == 1:
    if f == "2":
      return (c + S)
    elif f == "1":
      return (S + c)

S = input()
Q = int(input())
v = [list(input().split()) for i in range(Q)]
r = 0

for val in v:
  if val[0] == "1":
    if r == 0:
      r = 1
    elif r == 1:
      r = 0
  elif val[0] == "2":
    S = op2(val[1], val[2])
    
if r == 0:
  print(S)
else:
  print(S[::-1])

Fixed submission:
def op2(f, c, r):
  if r == 0:
    if f == "1":
      left.append(c)
    elif f == "2":
      right.append(c)

  if r == 1:
    if f == "1":
      right.append(c)
    elif f == "2":
      left.append(c)

S = input()
Q = int(input())
v = [list(input().split()) for i in range(Q)]
rev = 0
left = []
right = []

for val in v:
  if val[0] == "1":
    if rev == 0:
      rev = 1
    elif rev == 1:
      rev = 0
  elif val[0] == "2":
    op2(val[1], val[2], rev)

nleft = left[::-1]
ans = "".join(nleft + [S] + right)

if rev == 0:
  print(ans)
else:
  print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
def op2(f, c):
  if r == 0:
    if f == "1":
      return (c + S)
    elif f == "2":
      return (S + c)

  if r == 1:
    if f == "2":
      return (c + S)
    elif f == "1":
      return (S + c)

S = input()
Q = int(input())
v = [list(input().split()) for i in range(Q)]
r = 0

for val in v:
  if val[0] == "1":
    if r == 0:
      r = 1
    elif r == 1:
      r = 0
  elif val[0] == "2":
    S = op2(val[1], val[2])
    
if r == 0:
  print(S)
else:
  print(S[::-1])

Fixed submission:
def op2(f, c, r):
  if r == 0:
    if f == "1":
      left.append(c)
    elif f == "2":
      right.append(c)

  if r == 1:
    if f == "1":
      right.append(c)
    elif f == "2":
      left.append(c)

S = input()
Q = int(input())
v = [list(input().split()) for i in range(Q)]
rev = 0
left = []
right = []

for val in v:
  if val[0] == "1":
    if rev == 0:
      rev = 1
    elif rev == 1:
      rev = 0
  elif val[0] == "2":
    op2(val[1], val[2], rev)

nleft = left[::-1]
ans = "".join(nleft + [S] + right)

if rev == 0:
  print(ans)
else:
  print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
def op1():
  new = S[::-1]
  return new

def op2(f, c):
  if f == "1":
    return (c + S)
  elif f == "2":
    return (S + c) 
  

S = input()
Q = int(input())
v = [list(input().split()) for i in range(Q)]

for val in v:
  if val[0] == "1":
    S = op1()
  elif val[0] == "2":
    S = op2(val[1], val[2])
    
print(S)

Fixed submission:
def op2(f, c, r):
  if r == 0:
    if f == "1":
      left.append(c)
    elif f == "2":
      right.append(c)

  if r == 1:
    if f == "1":
      right.append(c)
    elif f == "2":
      left.append(c)

S = input()
Q = int(input())
v = [list(input().split()) for i in range(Q)]
rev = 0
left = []
right = []

for val in v:
  if val[0] == "1":
    if rev == 0:
      rev = 1
    elif rev == 1:
      rev = 0
  elif val[0] == "2":
    op2(val[1], val[2], rev)

nleft = left[::-1]
ans = "".join(nleft + [S] + right)

if rev == 0:
  print(ans)
else:
  print(ans[::-1])