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):
from collections import deque
s=input()
Q=int(input())

ans=deque()
ans.append(s)
rev=False

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            ans.appendleft(query[2])
        else:
            ans.append(query[2])

if not rev:
    for i in range(len(ans)):
        print(i,end="")
else:
    for i in range(len(ans)-1,-1,-1):
        print(ans[i],end="")

s=[input()]
Q=int(input())

rev=-1
for i in range(Q):
    que=input().split()
    if que[0]=="1":
        rev*=-1
    else:
        if que[1]=="1":
            if rev>0:
                s.append(que[2])
            else:
                s=[que[2]]+s
        else:
            if rev<0:
                s.append(que[2])
            else:
                s=[que[2]]+s
if rev<0:
    print(*s)
else:
    print(*s[::-1])

from collections import deque
s=input()
Q=int(input())

ans=deque()
ans.append(s)
rev=False

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            ans.appendleft(query[2])
        else:
            ans.append(query[2])

if not rev:
    for si in ans:
        print(si,end="")
else:
    for i in range(len(ans),0,-1):
        print(ans[i],end="")

s=[input()]
Q=int(input())

rev=-1
for i in range(Q):
    que=input().split()
    if que[0]=="1":
        rev*=-1
    else:
        if que[1]=="1":
            if rev>0:
                s.append(que[2])
            else:
                s=[que[2]]+s
        else:
            if rev<0:
                s.append(que[2])
            else:
                s=[que[2]]+s
if rev<0:
    for si in s:
        print(si,end="")
else:
    for i in range(len(s),0,-1):
        print(s[i],end="")

from collections import deque
S=input()
Q=int(input())

ans=deque()
for s in S:
    ans.append(s)
rev=False

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            ans.appendleft(query[2])
        else:
            ans.append(query[2])
    # print(ans)
if not rev:
    for i in range(len(ans)):
        print(ans[i],end="")
else:
    for i in range(len(ans)-1,-1,-1):
        print(ans[i],end="")

from collections import deque
s=input()
Q=int(input())

ans=deque()
ans.append(s)
rev=False

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            ans.appendleft(query[2])
        else:
            ans.append(query[2])

if not rev:
    for si in ans:
        print(si,end="")
else:
    for i in range(len(ans)-1,-1,-1):
        print(ans[i],end="")


from collections import deque
s=input()
Q=int(input())

ans=deque()
ans.append(s)
rev=False

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            ans.appendleft(query[2])
        else:
            ans.append(query[2])

if not rev:
    for i in range(len(ans)):
        print(ans[i],end="")
else:
    for i in range(len(ans)-1,-1,-1):
        print(ans[i],end="")

S=input()
Q=int(input())


# for s in S:


rev=False
front=""
last=""
# ans+=S

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
        # print(rev)
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            
            front="".join([query[2],front])
        else:
            
            last="".join([last,query[2]])

# if rev:

# # ans=""

#     ans+=deq[i]

if not rev:
    print(front+S+last)
else:
    print(last[::-1]+S[::-1]+front[::-1])

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Time Limit Exceeded

Wrong Answer

Wrong Answer

Accepted