Problem: Takahashi has a string S consisting of lowercase English letters.  Starting with this string, he will produce a new one in the procedure given as follows.  The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following:    * If T_i = 1: reverse the string S.    * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.      * If F_i = 1 : Add C_i to the beginning of the string S.     * If F_i = 2 : Add C_i to the end of the string S.  Help Takahashi by finding the final string that results from the procedure.

Submission attempts (in order):
import sys
input = sys.stdin.readline

s = input()
q = int(input())
par = 0
pre = ""
pos = ""

for i in range(q):
  t = input().split()
  if t[0] == "1":
    par += 1
  elif (par + int(t[1]))%2 == 1:
    pre = t[2] + pre
  else:
    pos = pos + t[2]
    
ans = pre + s + pos

if par%2 == 0:
  print(ans)
else:
  print(ans[::-1])

import sys
input = sys.stdin.readline

S = input()
Q = int(input())
A = [(input().split("")) for _ in range(Q)]

for i in range(Q):
  if A[i] == ["1"]:
    S = ''.join(list(reversed(S)))
  else:
    if A[i][1] == "1":
      S = S + A[i][2]
    else:
      S = A[i][2] + S
      
print(S)
    


import sys
input = sys.stdin.readline

S = input()
Q = int(input())
A = [(input().split()) for _ in range(Q)]

for i in range(Q):
  if A[i] == ["1"]:
    S = ''.join(list(reversed(S)))
  else:
    if A[i][1] == "1":
      S = S + A[i][2]
    else:
      S = A[i][2] + S
      
print(S)
    


import sys
input = sys.stdin.readline

S = input()
Q = int(input())
A = [(input().split("")) for _ in range(Q)]

for i in range(Q):
  if A[i] == ("1"):
    S = ''.join(list(reversed(S)))
  else:
    if A[i][1] == "1":
      S = A[i][2] + "S"
    else:
      S = "S" + A[i][2] 
      
print(S)

import sys
input = sys.stdin.readline

S = input()
Q = int(input())
A = [(input().split("")) for _ in range(Q)]

for i in range(Q):
  if A[i] == ["1"]:
    S = ''.join(list(reversed(S)))
  else:
    if A[i][1] == "1":
      S = A[i][2] + S
    else:
      S = S + A[i][2] 
      
print(S)
    


import sys
input = sys.stdin.readline

S = str(input())
Q = int(input())
A = [[input().split("")] for _ in range(Q)]

for i in range(Q):
  if A[i] == ["1"]:
    S = ''.join(list(reversed(S)))
  else:
    if A[i][1] == "1":
      S = A[i][2] + str(S)
    else:
      S = str(S) + A[i][2] 
      
print(S)
    


import sys
input = sys.stdin.readline

S = input()
Q = int(input())
A = [[input().split()] for _ in range(Q)]

for i in range(Q):
  if A[i] == ["1"]:
    S = ''.join(list(reversed(S)))
  else:
    if A[i][1] == "1":
      S = S + A[i][2]
    else:
      S = A[i][2] + S
      
print(S)
    


import sys
input = sys.stdin.readline

S = input()
Q = int(input())
A = [(input().split()) for _ in range(Q)]

for i in range(Q):
  if A[i] == ["1"]:
    S = ''.join(list(reversed(S)))
  else:
    if A[i][1] ==1:
      S = S + A[i][2]
    else:
      S = A[i][2] + S
      
print(S)
    

s = input()
q = int(input())
par = 0
pre = ""
pos = ""

for i in range(q):
  t = input().split()
  if t[0] == "1":
    par += 1
  elif (par + int(t[1]))%2 == 1:
    pre = t[2] + pre
  else:
    pos = pos + t[2]
    
ans = pre + s + pos

if par%2 == 0:
  print(ans)
else:
  print(ans[::-1])


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted