TnT/Multi_CodeNet4Repair huggingface dataset:
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):
# coding: utf-8

a, b = map(int, input().split())
# print(a,b)
# x=-1
# y=-1

xr=[]
yr=[]
for i in range(101):
    if i*0.08//1==a:
        # print("x:{}".format(i))
        x=i
        xr.append(x)
for i in range(101):
    if i *0.1//1==b:
        # print("y:{}".format(i))
        y=i
        yr.append(y)
flag=False

for i in xr:
    for j in yr:
        if i==j:
            print(i)
            flag=True
            break
    if flag:
        break
if not flag:
    print(-1)


# coding: utf-8

S = input()
Q = int(input())
# print("S:{}".format(S))
# print("Q:{}".format(Q))
query = []

for i in range(Q):
    query.append(input().split())

#     print(i)


#     if len(i) == 1:
#         S = S[::-1]
#     else:
#         if i[1]=="1":
#             S = i[2]+S
#         else:
#             S += i[2]
# print(S)
left = True
for i in query:
    if len(i) == 1:
        left = not left
        print(left)
    else:
        if i[1]=="1":
            if left:
                S = i[2]+S
            else:
                S += i[2]
        else:
            if left:
                S += i[2]
            else:
                S = i[2]+S
if left:
    print(S)
else:
    print(S[::-1])


# coding: utf-8

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

query = []

for i in range(Q):
    query.append(input().split())


bool = True
pre =''
suf =''

for i in query:
    if len(i) == 1:
        bool = not(bool)

    else:
        if i[1]=="1":
            if bool:
                pre = i[2]+pre
            else:
                suf += i[2]
        else:
            if bool:
                suf += i[2]
            else:
                pre = i[2]+pre

S = pre+ S +suf
print(S) if bool else print(S[::-1])


Verdicts: Runtime Error

Wrong Answer

Accepted
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 = deque(input())
Q = int(input())
reverse = 1


for i in range(Q):
    
    q = input()
    
    if (q == 1):
        reverse *= -1
    else:
        integer, judge, cha = q.split()
        
        if (judge == '1'):
            if (reverse == 1):
                S.appendleft(cha)
            else:
                S.append(cha)
        elif (judge == '2'):
            if (reverse == -1):
                S.append(cha)
            else:
                S.appendleft(cha)

if (reverse == -1):
    S.reverse()

print(''.join(list(S)))

from collections import deque

S = deque(input())
Q = int(input())
reverse = 1


for i in range(Q):
    
    q = input()
    
    if (q == '1'):
        reverse *= -1
    else:
        integer, judge, cha = q.split()
        
        if (judge == '1'):
            if (reverse == 1):
                S.appendleft(cha)
            else:
                S.append(cha)
        
        elif (judge == '2'):
            if (reverse == 1):
                S.append(cha)
            else:
                S.appendleft(cha)

if (reverse == -1):
    S.reverse()

print(''.join(list(S)))

Verdicts: Runtime Error

Accepted
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())
 = 0
ans = []
T = []

for i in range(Q):
  TS = input()
  if TS == "1":
    revcount += 1
  else:
    T.append(TS.rstrip().split(" "))
    T[len()-1][1] = str((int(T[len(T)-1][1]) + revcount % 2 + 1) % 2 + 1)
if revcount % 2 == 1:
  ans.append(S[::-1])
else:
  ans.append(S)
for i in range(len(T)):
  if (int(T[iinput()
Q = int(input())
revcount = 0
ans = []
T = []

for i in range(Q):
  TS = input()
  if TS == "1":
    revcount += 1
  else:
    T.append(TS.rstrip().split(" "))
    T[len(T)-1][1] = str((int(T[len(T)-1][1]) + revcount % 2 + 1) % 2 + 1)
if revcount % 2 == 1:
  ans.append(S[::-1])
else:
  ans.append(S)
            
for i in range(len(T)):
  if (int(T[i][1]) == 1 and revcount % 2 == 0) or (int(T[i][1]) == 2 and revcount % 2 == 1):
    ans.insert(0,T[i][2])
  else:
    ans.append(T[i][2])
ans2 = "".join(ans2  1]) == 1 and revcount % 2 == 0) or (int(T[i][1]) == 2 and revcount % 2 == 1)
    ans.insert(0,T[i][2])
  else:
    ans.append(T[i][2])
ans2 = "".join(ans)
print(ans2)
  


S = list(input())
mae = []
ato = []
rev = False
Q = int(input())
for i in range(Q):
    A = list(input().rstrip().split(" "))
    if int(A[0]) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        if (rev and int(A[1]) == 2 or not rev and int(A[1]) == 1):
            mae.append(A[2])
        else:
            ato.append(A[2])
if rev:
    ato.reverse()
    S.reverse()
    print("".join(ato) + "".join(S) + "".join(mae))
else:
    mae.reverse()
    print("".join(mae) + "".join(S) + "".join(ato))

Verdicts: Runtime Error

Accepted
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())
que=[list(map(str,input().split())) for i in range(q)]
count=0
for i in que:
  if i[0]=="1":
    count+=1
ans=[[],[]]
    
for i in que:
  if i[0]=="1":
    count-=1
  else:
    if i[1]=="1":
      ans[count%2].append(i[2])
    else:
      ans[(count+1)%2].append(i[2])
print("".join(ans[0])+s+"".join(ans[1]))

s=input()
q=int(input())
que=[]
count=0
left=[]
right=[]
for i in range(q):
  qu=list(map(str,input().split()))
  if qu[0]=="1":
    count+=1
  que.append(qu)
han=0
for i in range(q):
  if que[i][0]=="1":
    han+=1
  else:
    if que[i][1]=="1":  
      if (count-han)%2==0:
        left.append(que[i][2])
      else:
        right.append(que[i][2])
    elif que[i][1]=="2":  
      if (count-han)%2==0:
        left.append(que[i][2])
      else:
        right.append(que[i][2])
ls="".join(left[::-1])
lr="".join(right)
print(ls+s+lr)

s=input()
q=int(input())
que=[list(map(str,input().split())) for i in range(q)]
count=0
for i in que:
  if i[0]=="1":
    count+=1
ans=[[],[]]
ak=count
for i in que:
  if i[0]=="1":
    count-=1
  else:
    if i[1]=="1":
      ans[count%2].append(i[2])
    else:
      ans[(count+1)%2].append(i[2])
if ak%2==0:
  print("".join(reversed(ans[0]))+s+"".join(ans[1]))
else:
  print("".join(reversed(ans[0]))+"".join(reversed(list(s)))+"".join(ans[1]))

Verdicts: Wrong Answer

Wrong Answer

Accepted
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()
n = int(input())
query = [0]*n
rev = 0
for i in range(n):
    query[i] = list(map(str, input().split()))
    if query[i][0] == '1':
        rev = rev + 1

begin = deque()
end = deque()
pal = 0

for i in range(n):
    if int(query[i][0]) == 1:
        pal = (pal+1)%2
    else:
        if pal == 0:
            if int(query[i][1]) == 1:
                begin.appendleft(query[i][2])
            else:
                end.append(query[i][2])
        else:
            if int(query[i][1]) == 1:
                end.append(query[i][2])
            else:
                begin.appendleft(query[i][2])
#    print('--------'+str(i+1)+'th try-----')
#    print(begin)
#    print(end)
#    print('pal:'+str(pal))
print(s)

if rev%2 == 1:
    print(''.join(deque(reversed(end)))+s[::-1]+''.join(deque(reversed(begin))))
else:
    print(''.join(begin)+s+''.join(end))

s = input()
n = int(input())
query = [0]*n
rev = 0
for i in range(n):
    query[i] = list(map(str, input().split()))
    if query[i][0] == '1':
        rev = rev + 1

begin = []
end = []
pal = 0

for i in range(n):
    if int(query[i][0]) == 1:
        pal = (pal+1)%2
    else:
        if pal == 0:
            if int(query[i][1]) == 1:
                begin.append(query[i][2])
            else:
                end.append(query[i][2])
        else:
            if int(query[i][1]) == 1:
                end.append(query[i][2])
            else:
                begin.append(query[i][2])
#    print('--------'+str(i+1)+'th try-----')
#    print(begin)
#    print(end)
#    print('pal:'+str(pal))
#print(s)

if rev%2 == 1:
    print(''.join(end[::-1])+s[::-1]+''.join(begin))
else:
    print(''.join(begin[::-1])+s+''.join(end))

Verdicts: Wrong Answer

Accepted
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()

input_line = int(input())

flag0 = ""
flag1 = ""
flag = 0


for i in range(input_line):
    action = list(input())
    # print(flag0,flag1)
    # print(action)
    if action[0]=="1":
        if flag == 0:
            flag = 1
        else:
            flag = 0
    else:
        # print("check")
        if action[2] == "2":
            
            if flag == 0:
                flag0 = flag0 + action[4]
            elif flag ==1:
                flag1 = action[4] + flag1
        else:
            if flag == 0:
                flag0 = action[4] + flag0
            
            elif flag == 1:
                flag1 += action[4]
                
S = flag0 + S + flag1
if flag == 1:
    S = S[::-1]
print(S)

S =input()

input_line = int(input())

flag0 = ""
flag1 = ""

for i in range(input_line):
    action = list(input())
    
    flag = 0
    

    # print(flag0,flag1)
    # print(action)
    if action[0]=="1":
        if flag == 0:
            flag = 1
        else:
            flag = 0
    else:
        # print("check")
        if action[2] == "2":
            
            if flag == 0:
                flag1 = flag1 + action[4]
            elif flag ==1:
                flag0 = action[4]+flag0
        else:
            if flag == 1:
                flag1 += action[4]
            
            elif flag == 0:
                flag0 = action[4]+flag0

if flag == 1:
    S = S[::-1]
print(flag1)
S = flag1 + S + flag0
    
print(S)

S =input()

input_line = int(input())

flag0 = ""
flag1 = ""
flag = 0


for i in range(input_line):
    action = list(input())
    # print(flag0,flag1)
    # print(action)
    if action[0]=="1":
        if flag == 0:
            flag = 1
        else:
            flag = 0
    else:
        # print("check")
        if action[2] == "2":
            
            if flag == 0:
                flag1 = flag1 + action[4]
            elif flag ==1:
                flag0 = action[4] + flag0
        else:
            if flag == 0:
                flag0 = action[4] + flag0
            
            elif flag == 1:
                flag1 += action[4]
                
S = flag0 + S + flag1
if flag == 1:
    S = S[::-1]
print(S)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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())
for i in range(q):
  l=list(map(str,input().split()))
  if l[0]=="1":
    s=s[::-1]
  elif l[1]=="1":
    s=l[2]+s
  else:
    s=s+l[2]
print(s)

s=input()
q=int(input())
l = [list(input().split()) for i in range(q)]
c=0
for i in range(q):
  if l[i][0]=="1":
    c+=1
  elif c%2=0 and l[i][1]=="1":
    s=l[i][2]+s
  elif c%2=0:
    s=s+l[i][2]
  elif c%2=1 and l[i][1]=="1":
    s=s+l[i][2]
  else:
    s=l[i][2]+s
if c%2=1:
  s=s[::-1]
print(s)

from collections import deque
s=deque(list(input()))
q=int(input())
l = [list(input().split()) for i in range(q)]
c=0
for i in range(q):
  if l[i][0]=="1":
    c+=1
  elif c%2==0 and l[i][1]=="1":
    s.appendleft(l[i][2])
  elif c%2==0:
    s.append(l[i][2])
  elif c%2==1 and l[i][1]=="1":
    s.append(l[i][2])
  else:
    s.appendleft(l[i][2])
s=list(s)
if c%2==1:
  s=s[::-1]
print(*s, sep="")

Verdicts: Wrong Answer

Runtime Error

Accepted
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())
fb=True
forward=""
back=""

for i in range(Q):
    query=input()
    if(query=="1"):
        fb=False if(fb) else True
        print("query=1")
    else:
        query, F, C =query.split()
        if((F=="1")==fb):
            forward=C+forward
        else:
            back=back+C
        print("query=2")
print((forward+S+back)[::1 if(fb) else -1])

S=input()
Q=int(input())
fb=True
forward=""
back=""

for i in range(Q):
    query=input()
    if(query=="1"):
        fb=False if(fb) else True
    else:
        query, F, C =query.split()
        if((F=="1")==fb):
            forward=C+forward
        else:
            back=back+C
print((forward+S+back)[::1 if(fb) else -1])

Verdicts: Wrong Answer

Accepted
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):
string = input()
inp = []
n = int(input())
flag = 1
for i in range(n):
    j = input().split()
    if len(j) == 3 and j[1] == "1" and flag == 1:
        inp.insert(0,j[2])
    elif len(j) == 3 and j[1] == "2" and flag == 1:
        inp.append(j[2])
    elif len(j) == 3 and j[1] == "2" and flag == -1:
        inp.insert(0,j[2])
    elif len(j) == 3 and j[1] == "1" and flag == -1:
        inp.append(j[2])
    else:
        flag *= -1
if flag == -1:
    inp = inp[::-1]
s = ""
for j in inp:
    s = s + j
print(s)

s = input()
if('A' in s and 'B' in s):
    print('Yes')
else:
    print('No')

s=list(input())
q=int(input())
c=0
left=[]
right=[]
for i in range(q):
    s1=input()
    if s1[0]=='1':
        c+=1
    else:
        if s1[2] == '1':
            if c % 2 == 0:
                left.append(s1[4])
            else:
                right.append(s1[4])
        else:
            if c % 2 == 0:
                right.append(s1[4])
            else:
                left.append(s1[4])
left=left[::-1]
left.extend(s)
left.extend(right)
if c%2==0:
    print(''.join(left))
else:
    left=left[::-1]
    print(''.join(left))


Verdicts: Wrong Answer

Wrong Answer

Accepted
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 = deque(input())
Q = int(input())

flag = 1
for i in range(Q):
    qry = input().split()

    if qry[0] == '1':
        if flag:
            flag = 0
        else:
            flag = 1
    
    elif qry[0] == '2':
        if flag:
            if qry[1] == '1':
                S.append(qry[2])
            else:
                S.appendleft(qry[2])
        else:
            if qry[1] == '1':
                S.append(qry[2])
            else:
                S.appendleft(qry[2])

if flag:
    print(ans)
else:
    print(ans[::-1])

from collections import deque

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

flag = 1
for i in range(Q):
    qry = input().split()

    if qry[0] == '1':
        if flag:
            flag = 0
        else:
            flag = 1
    
    elif qry[0] == '2':
        if flag:
            if qry[1] == '1':
                S.appendleft(qry[2])
            else:
                S.append(qry[2])
        else:
            if qry[1] == '1':
                S.append(qry[2])
            else:
                S.appendleft(qry[2])

S = ''.join(S)

if flag:
    print(S)
else:
    print(S[::-1])

Verdicts: Runtime Error

Accepted
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()
que = deque()
que.append(S)
Q = int(input())
Front_flag = 1

for i in range(Q):
    Query = tuple(input().split())
    if len(Query) == 1:
        Front_flag = 1 - Front_flag
    else:
        a, b, c = Query
        if (Front_flag + int(b)) % 2 == 1:
            que.append(c)
        else:
            que.appendleft(c)
if not Front_flag:
    que.reverse()

for i in que:
    print(i, end='')

from collections import deque
S = input()
que = deque()
que.append(S)
Q = int(input())
Front_flag = 1

for i in range(Q):
    Query = tuple(input().split())
    if len(Query) == 1:
        Front_flag = 1 - Front_flag
    else:
        a, b, c = Query
        if (Front_flag + int(b)) % 2 == 1:
            que.append(c)
        else:
            que.appendleft(c)

ans = ''.join(que)
if Front_flag:
    print(ans)
else:
    print(ans[::-1])

Verdicts: Wrong Answer

Accepted
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):
# coding: utf-8
S = input().split()
Q = int(input())

def pop(left, right, rev, f, c):
    left_ = left
    if rev == 1:
        if f == '1':
            #left_ = [c] + left
            left.append(c)
        else:
            right.append(c)
    else:
        if f == '1':
            right.append(c)
        else:
            #left_ = [c] + left
            left.append(c)
    return left_, right


left, right = [], []
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        left, right = pop(left, right, rev, *que[1:])
print(''.join(left+S+right)[::rev])

# coding: utf-8
S = input().split()
Q = int(input())

def pop(left, right, rev, f, c):
    if rev == 1:
        if f == '1':
            left.append(c)
        else:
            right.append(c)
    else:
        if f == '1':
            right.append(c)
        else:
            left.append(c)
    return left, right


left, right = [], []
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        left, right = pop(left, right, rev, *que[1:])
print(''.join(left[::-1]+S+right)[::rev])

Verdicts: Wrong Answer

Accepted
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


def main():
    s = deque([list(input())])
    q = int(input())
    rev = False
    for _ in range(q):
        query = input().split()
        if query[0] == "1":
            if not rev:
                rev = True
            else:
                rev = False
        else:
            if query[1] == '1':
                pass
                if rev:
                    s.append(query[2])
                else:
                    s.appendleft(query[2])
            else:
                if rev:
                    s.appendleft(query[2])
                else:
                    s.append(query[2])
    if rev:
        s.reverse()
    print(*s, sep="")


if __name__ == "__main__":
    main()


from collections import deque


def main():
    s = deque(list(input()))
    q = int(input())
    rev = False
    for _ in range(q):
        query = input().split()
        if query[0] == "1":
            if not rev:
                rev = True
            else:
                rev = False
        else:
            if query[1] == '1':
                pass
                if rev:
                    s.append(query[2])
                else:
                    s.appendleft(query[2])
            else:
                if rev:
                    s.appendleft(query[2])
                else:
                    s.append(query[2])
    if rev:
        s.reverse()
    print(*s, sep="")


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
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=list(input())
q=int(input())
for i in range(q):
    query=input().split()
    print(query)
    if query==['1']:
        s.reverse()
    else:
        if query[1]=='1':
            s.insert(0,query[2])
        else:
            s.append(query[2])
print(''.join(s))


s=list(input())
q=int(input())
ans=0
mae=[]
ato=[]
for i in range(q):
    query=input().split()
    if query==['1']:
        ans+=1
    else:
        if query[1]=='1' and ans%2==0:
            mae.append(query[2])
        elif query[1]=='1' and ans%2==1:
            ato.append(query[2])
        elif query[1]=='2' and ans%2==0:
            ato.append(query[2])
        else:
            mae.append(query[2])
if ans%2==1:
    s.reverse()
    ato.reverse()
    s=ato+s+mae
else:
    mae.reverse()
    s=mae+s+ato
print(''.join(s))


Verdicts: Wrong Answer

Accepted
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 = deque(input())
q = int(input())
r = 0
z = 0
to = 0
for i in range(q):
    
    try:
        t,f,c = input().split()
        if (r + int(f)) % 2 == 1:
            s.appendleft(c)
    
        else:
            s.append(c)
        r = 0
        z = 1
    except:
        if z == 0:
            pass
        else:
            r += 1
        z = 1
        to += 1
    print(s)
if to % 2 == 1:
    s = reversed(s)
print("".join(s))

from collections import deque
s = deque(input())
q = int(input())
lis = [list(input().split()) for _ in range(q)]
rev = 0
z = 0

for i in lis:
    if i[0] == "2":
        if (rev + int(i[1])) % 2 == 1:
            s.appendleft(i[2])
        else:
            s.append(i[2])
        z = 1
    else:
        if z == 1:
            rev += 1
        
if rev % 2 == 1:
    s = reversed(s)
print("".join(s))
    

Verdicts: Runtime Error

Accepted
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())

cnt = 0
llst = []
rlst = []
for i in range(q):
  line = input()
  if line == '1':
    cnt += 1
  else:
    elems = line.split()
    if cnt % 2 == 0:
      
      if elems[1] == '1':
        llst.append(elems[2])
      else:
        rlst.append(elems[2])
    else:
      
      if elems[1] == '1':
        rlst.append(elems[2])
      else:
        llst = [elems[2]] + llst
        
if cnt % 2 == 0:
  res = ''.join(llst[::-1]) + s + ''.join(rlst)
  print(res)
else:
  res = ''.join(llst[::-1]) + s + ''.join(rlst)
  print(res[::-1])

s = input()
q = int(input())

cnt = 0
llst = []
rlst = []
for i in range(q):
  line = input()
  if line == '1':
    cnt += 1
  else:
    elems = line.split()
    if cnt % 2 == 0:
      
      if elems[1] == '1':
        llst.append(elems[2])
      else:
        rlst.append(elems[2])
    else:
      
      if elems[1] == '1':
        rlst.append(elems[2])
      else:
        llst.append(elems[2])
        
if cnt % 2 == 0:
  res = ''.join(llst[::-1]) + s + ''.join(rlst)
  print(res)
else:
  res = ''.join(llst[::-1]) + s + ''.join(rlst)
  print(res[::-1])

Verdicts: Wrong Answer

Accepted
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 = deque(input())
num = int(input())
for i in range(num):
  a = deque(input().split())
  start = int(a[0])
  if start == 2:
    ns = int(a[1])
    if ns == 1:
      s.appendleft(a[2])
      #s = a[2] + s
    else:
      
      s.append(a[2])
  else:
    s.reverse()
for i in range(len(s)):
  print(s[i], end='')

from collections import deque
s = deque(input())
num = int(input())
for i in range(num):
  a = deque(input().split())
  start = int(a[0])
  if start == 2:
    ns = int(a[1])
    if ns == 1:
      s.appendleft(a[2])
      #s = a[2] + s
    else:
      
      s.append(a[2])
  else:
    s = s[::-1]
for i in range(len(s)):
  print(s[i], end='')

from collections import deque
s = deque(input())
num = int(input())
cnt = 0
for i in range(num):
  a = input().split()

  if a[0] == '2':
    if (int(a[1])+cnt)%2==1:
      s.appendleft(a[2])
    else:
      s.append(a[2])
  else:
    cnt += 1
if cnt%2 == 1:    
	s.reverse()
print("".join(s))
  

Verdicts: Time Limit Exceeded

Runtime Error

Accepted
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())
flag = 0b0
for i in range(q) :
    t = input()
    if t == 1 :
        flag ^= 1
        continue
    if (int(t[2]) - flag) == 1 :
        s = t[4] + s
    else :
        s = s + t[4]
if flag == 0 :
    print(s)
else :
    print(s[::-1])

right = input()
flag = 1
left = ""
for i in range(int(input())):
    t = input()
    if t == "1":
        flag ^= 1
        continue
    t, f, c = t.split(" ")
    if not ((f=="1")^flag):
        left += c
    else:
        right += c
ans = left[::-1] + right
if not flag:
    ans = ans[::-1]
print(ans)

Verdicts: Runtime Error

Accepted
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 numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

s = sinput()
q = iinput()
cnt = 0
for i in range(q):
    try: t,f,c = sarr()
    except: cnt += 1; cnt %= 2; continue
    print("====", t,f,c)
    if cnt:
        if f == 1: s = s + c
        if f == 2: s = c + s
    else:
        if f == 1: s = c + s
        if f == 2: s = s + c
    print(s)

s = s[::-1] if cnt else s
print(s)


import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

s = col.deque(sinput().split())
q = iinput()
cnt = 0
for i in range(q):
    try: t,f,c = sarr()
    except: cnt += 1; cnt %= 2; continue
    if cnt: 
        if f == "1": s.append(c)
        if f == "2": s.appendleft(c)
    else: 
        if f == "1": s.appendleft(c)
        if f == "2": s.append(c)
    #print(s)

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



Verdicts: Runtime Error

Accepted
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())

Q = []
for i in range(q):
    Q.append(input())


print(s)
for operation in Q:
    if (operation[0] == '1'):
        s = s[::-1]
    else:
        if (operation[2] == '1'):

            s = operation[4] + s
        else:
            s += operation[4]


print(s)


s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
left= right = ""
for operation in qs:
    if operation[0] == '1':
        n = not n
    if operation[0] == '2':
        t , f, c = operation
        f = int(f)
        if n:
            f = 1 if f != 1 else 2
        if f == 1:
            left=c+left
        elif f == 2:
            right+=c
s = left+s+right
print(s[::-1] if n else s)

Verdicts: Wrong Answer

Accepted
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())
r = False
for i in range(q):
  t=list(input().split())
  if len(t) == 1:
    r = not(r)
  else:
    if t[1] == '1' and r = False
      s = t[2] + s
    elif t[1] == '2' and r = True:
      s = t[2] + s
    else:
      s = s + t[2]
print(s)

s = input()
q = int(input())
r = False
f = ''
b = '' #behind
for i in range(q):
  t=list(input().split())
  if len(t) == 1:
    r = not(r)
  else:
    if (t[1] == '1' and r == False):
      f += t[2]
    elif (t[1] == '2' and r == True):
      f += t[2]
    else:
      b += t[2]
s = f[::-1] + s + b
if r:
  print(s[::-1])
else:
  print(s)

Verdicts: Runtime Error

Accepted
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())
is_r = False
f_list = []
b_list = []

for i in range(q):
    q_i = input().split(' ')
    t_i = q_i[0]
    if t_i == '1':
        is_r = not is_r
    else:
        f_i = q_i[1]
        if (f_i == '1' and not is_r) or (f_i == '2' and is_r):
            f_list.append(q_i[2])
        else:
            b_list.append(q_i[2])

f_list = f_list[::-1]
f_list.append(s)
f_list.extend(b_list)
s = f_list.join('') if not is_r else f_list[::-1].join('')
print(s)

s = input()
q = int(input())
is_r = False
f_list = []
b_list = []

for i in range(q):
    q_i = input().split(' ')
    t_i = q_i[0]
    if t_i == '1':
        is_r = not is_r
    else:
        f_i = q_i[1]
        if (f_i == '1' and not is_r) or (f_i == '2' and is_r):
            f_list.append(q_i[2])
        else:
            b_list.append(q_i[2])

f_list = f_list[::-1]
f_list.append(s)
f_list.extend(b_list)
s = ''.join(f_list) if not is_r else ''.join(f_list)[::-1]
print(s)

Verdicts: Runtime Error

Accepted
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):
# coding: utf-8

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


rev = False
for _ in range(Q):
    line = input()

    if line[0] == "1":
        rev = not rev

    else:
        if line[2] == "1":
            if rev:
                S = "".join(S, line[4])
            else:
                S = "".join(line[4], S)
        else:
            if rev:
                S = "".join(line[4], S)
            else:
                S = "".join(S, line[4])

if rev:
    print(S[::-1])
else:
    print(S)


# coding: utf-8

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


heads = {}
tails = {}
h = 0
t = 0
rev = False
for _ in range(Q):
    line = input()

    if line[0] == "1":
        rev = not rev

    else:
        if line[2] == "1":
            if rev:
                # S = "".join([S, line[4]])
                tails[t] = line[4]
                t += 1
            else:
                # S = "".join([line[4], S])
                heads[h] = line[4]
                h += 1
        else:
            if rev:
                # S = "".join([line[4], S])
                heads[h] = line[4]
                h += 1
            else:
                # S = "".join([S, line[4]])
                tails[t] = line[4]
                t += 1

head = [None] * h
tail = [None] * t

for i in range(h):
    head[i] = heads[i]
head = head[::-1]

for i in range(t):
    tail[i] = tails[i]

head_joint = "".join(head)
tail_joint = "".join(tail)
joint = "".join([head_joint, S, tail_joint])

if rev:
    print(joint[::-1])
else:
    print(joint)


Verdicts: Runtime Error

Accepted
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

d=deque()
s=input()
d.append(s)
q=int(input())
flag=1
t = [input().split() for l in range(q)]
for i in range(q):
  if t[i][0]=='1':
    flag=flag*(-1)
  else:
    if t[i][1]=='1' and flag==1:
      s=t[i][2]+s
    elif t[i][1]=='1' and flag==-1:
      s=s+t[i][2]
    elif t[i][1]=='2' and flag==1:
      s=s+t[i][2]
    elif t[i][1]=='2' and flag==-1:
      s=t[i][2]+s
if flag==-1:
  new_s = ''.join(list(reversed(s)))
print(new_s)

from collections import deque

d=deque()
s=input()
for i in s:
  d.append(i)
q=int(input())
flag=1
t = [input().split() for l in range(q)]
for i in range(q):
  if t[i][0]=='1':
    flag=flag*(-1)
  else:
    if t[i][1]=='1' and flag==1:
      d.appendleft(t[i][2])
    elif t[i][1]=='1' and flag==-1:
      d.append(t[i][2])
    elif t[i][1]=='2' and flag==1:
      d.append(t[i][2])
    elif t[i][1]=='2' and flag==-1:
      d.appendleft(t[i][2])
if flag==-1:
  d.reverse()
d="".join(list(d))
print(d)


Verdicts: Runtime Error

Accepted
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 = list(input())
q = int(input())
for i in range(q):
    l = input().split()
    if len(l) == 1:
        s[0], s[-1] = s[-1], s[0]
    else:
        pos = int(l[1])
        c = l[2]
        if pos == 1:
            s.insert(1, c)
        else:
            s.append(c)
print("".join(s))


from collections import deque

s = list(input())
d = deque(s)
forward = True
q = int(input())
for i in range(q):
    l = input().split()
    if len(l) == 1:
        forward = not forward
    else:
        pos = int(l[1])
        c = l[2]
        if pos == 1:
            if forward:
                d.appendleft(c)
            else:
                d.append(c)
        else:
            if forward:
                d.append(c)
            else:
                d.appendleft(c)
print("".join(s))


from collections import deque

s = list(input())
d = deque(s)
forward = True
q = int(input())
for i in range(q):
    l = input().split()
    if len(l) == 1:
        forward = not forward
    else:
        pos = int(l[1])
        c = l[2]
        if pos == 1:
            if forward:
                d.appendleft(c)
            else:
                d.append(c)
        else:
            if forward:
                d.append(c)
            else:
                d.appendleft(c)

if forward == False:
    d.reverse()

print("".join(d))


Verdicts: Wrong Answer

Wrong Answer

Accepted