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())
turn=True
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn and int(qq[1])-2:
            s.insert(0,qq[2])
        else:
            s.append(qq[2])
text="".join(s)
print(text if turn else text[::-1])

ad=[[],[]]
add=[[],[]]
count=0
s=input()
q=int(input())
for i in range(q):
    t=input().split()
    if t[0]=='1':
        count+=1
        ad[0].reverse()
        ad[1].reverse()
        add=[add[0]+ad[1],add[1]+ad[0]]
        ad=[[],[]]
    elif t[1]=='1':
        ad[0].insert(0,t[2])
    else:
        ad[1].append(t[2])


if count%2==0:
    print(''.join(add[0]+ad[0])+s+''.join(add[1]+ad[1]))
else:
    print(''.join(add[0]+ad[0])+s[::-1]+''.join(add[1]+ad[1]))

ad=[[],[]]
add=[[],[]]
count=0
s=input()
q=int(input())
for i in range(q):
    t=input().split()
    if t[0]=='1':
        count+=1
        ad[0].reverse()
        ad[1].reverse()
        add=[add[0]+=ad[1],add[1]+=ad[0]]
        ad=[[],[]]
    elif t[1]=='1':
        ad[0].insert(0,t[2])
    else:
        ad[1].append(t[2])


if count%2==0:
    print(''.join(add[0]+ad[0])+s+''.join(add[1]+ad[1]))
else:
    print(''.join(add[0]+ad[0])+s[::-1]+''.join(add[1]+ad[1]))

s=[input()]
q=int(input())
turn=True
l=""
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn and int(qq[1])-2:
            l+=qq[2]
        else:
            s.append(qq[2])

text=l+"".join(s)
print(text if turn else text[::-1])

ad=[[],[]]
count=0
s=input()
q=int(input())
for i in range(q):
    t=input().split()
    if t[0]=='1':
        count+=1
        ad[1].reverse()
        ad[0].reverse()
        ad=[ad[1],ad[0]]
    elif t[1]=='1':
        ad[0].insert(0,t[2])
    else:
        ad[1].append(t[2])

if count%2==0:
    print(''.join(ad[0],s,ad[1]))
else:
    print(''.join(ad[0]),end='')
    for i in range(len(s)):
        print(s[-(i+1)],end='')
    print(''.join(ad[1]))

s=[input()]
q=int(input())
turn=True

for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn==bool(int(qq[1])-2):
            s.appendleft(qq[2])
        else:
            s.append(qq[2])

text="".join(s)
print(text if turn else text[::-1])

s=[input()]
q=int(input())
turn=True
for i in ragne(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn==not (int(qq[1])-1]):
            s.insert(0,qq[2])
        else:
            s.append(qq[2])
text="".join(s)
print(text if turn else text[::-1])

s=[input()]
q=int(input())
turn=True
l=""
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn and int(qq[1])-2:
            l+=qq[2]
        else:
            s.append(qq[2])

text=l[::-1]+"".join(s)
print(text if turn else text[::-1])

from collections import deque
s=deque(input())
q=int(input())
turn=True
 
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn==bool(int(qq[1])-2):
            s.appendleft(qq[2])
        else:
            s.append(qq[2])
 

text="".join(s)
print(text if turn else text[::-1])

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted