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):
S = input()
Q = int(input())
que2 = []
que2.append(S)
rv_flag= 0
for _ in range(Q):
    que = list(map(str, input().split()))
    if que[0] == "1":
        rv_flag = rv_flag + 1
    elif que[1] == "1":
        que2.insert(0,que[2])
    elif que[1] == "2":
        que2.append(que[2])
if rv_flag % 2 == 1:
    que2.reverse()
ans = "".join(que2)
print(ans)

from collections import deque

S = input()
Q = int(input())
L = ""
R = ""
flag = 0

for i in range(Q):
    q = list(map(str , input().split()))
    if q[0] == "1":
        if flag == 0:
            flag = 1
        else:
            flag = 0
    else:
        if q[1] == "1":
            if flag == 0:
                L.append(q[2])
            else:
                R.append(q[2])
        else:
            if flag == 0:
                R.appned(q[2])
            else:
                L.append(q[2])
K = L[::-1] + R

if flag == 0:
    print("".join(K))
else:
    print("".join(K[::-1]))

S = input()
Q = int(input())
fg = False
que2 = []
que2.append(S)

for _ in range(Q):
    que = list(map(str, input().split()))
    if que[0] == "1":
        fg = not fg
    elif (que[1] == "1" and fg == False) or (que[1] == "2" and fg == True) :
        que2.insert(0,que[2])
    else:
        que2.append(que[2])
        
if fg == True:
  que2.reverse()

from collections import deque

S = input()
Q = int(input())
d = deque(S)
fg = False
for i in range(Q):
    que = list(map(str , input().split()))
    if que[0] == "1":
        fg = True
    elif (que[1] == "1" and fg == False) or (que[1] == "2" and fg == True) :
        q.appendleft(que[2])
    else:
        q.append(que[2])
if fg:
    q.reverse()
print("".join(q))


S = input()
Q = int(input())
fg = False
que2 = []
que2.append(S)

for _ in range(Q+1):
    que = list(map(str, input().split()))
    if que[0] == "1":
        que2.reverse()
    elif que[1] == "1":
        que2.insert(0,que[2])
    elif que[1] == "2":
        que2.append(que[2])
        
ans = "".join(que2)
print(ans)


from collections import deque

S = input()
Q = int(input())
q = deque(S)
fg = False

for i in range(Q):
    que = list(map(str , input().split()))
    if que[0] == "1":
        fg = not fg
    elif (que[1] == "1" and fg == False) or (que[1] == "2" and fg == True) :
        q.appendleft(que[2])
    else:
        q.append(que[2])

if not fg:
    q.reverse()

print("".join(q))a



from collections import deque

S = input()
Q = int(input())
q = deque(S)
fg = False
for i in range(Q):
    que = list(map(str , input().split()))
    if que[0] == "1":
        fg = True
    elif (que[1] == "1" and fg == False) or (que[1] == "2" and fg == True) :
        q.appendleft(que[2])
    else:
        q.append(que[2])
if fg:
    q.reverse()
print("".join(q))


S = input()
Q = int(input())
que2 = []
que2.append(S)

for _ in range(Q):
    que = list(map(str, input().split()))
    if que[0] == "1":
        que2.reverse()
    elif que[1] == "1":
        que2.insert(0,que[2])
    elif que[1] == "2":
        que2.apend(que[2])
print(que2)

from collections import deque

S = input()
Q = int(input())
q = deque(S)
fg = False
for i in range(Q):
    que = list(map(str , input().split()))
    if que[0] == "1":
        fg = not fg
    elif (que[1] == "1" and fg == False) or (que[1] == "2" and fg == True) :
        q.appendleft(que[2])
    else:
        q.append(que[2])
if fg:
    q.reverse()
print("".join(q))



Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Accepted