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):
from collections import deque
S=input()
s=deque(S)
Q=int(input())
Que=[list(map(str, input().split())) for _ in range(Q)]
#print(Que)
for i in range(Q):
    if Que[i][0]=="1":
        s=s[::-1]
    elif Que[i][0]=="2":
        if Que[i][1]=="2":
            s.append(Que[i][2])
        elif Que[i][1]=="1":
            s.appendleft(Que[i][2])
ans="".join(s)
print(ans)


from collections import deque
S=input()
s=deque(S)
Q=int(input())
Que=[list(map(str, input().split())) for _ in range(Q)]
#print(Que)
a=0
for i in range(Q):
    if Que[i][0]=="1":
        a+=1
    elif Que[i][0]=="2":
        if a%2==0:
            if Que[i][1]=="2":
                s.append(Que[i][2])
            elif Que[i][1]=="1":
                s.appendleft(Que[i][2])
        else:
            if Que[i][1]=="1":
                s.append(Que[i][2])
            elif Que[i][1]=="2":
                s.appendleft(Que[i][2])
s=list(s)
if a%2==1:
    s=s[::-1]
ans="".join(s)
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):
from collections import deque

z=list(input())
Q=deque()
Q.append((z))
q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

from collections import deque

z=list(input())
Q=deque()
Q.append(z)
q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

from collections import deque

z=list(input())
Q=deque()
for i in z:
  Q.append(i)
q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

Verdicts: Runtime Error

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):
def string():
    s = input()
    q = int(input())
    l = ''
    r = ''
    re = False
    while q > 0:
        t = list(input().strip().split())
        if t[0] == 1:
            re = not re
        else:
            if re:
                if t[1] == 2:
                    l = t[2] + l
                else:
                    r = r + t[2]
            else:
                if t[1] == 2:
                    l = t[2] + l
                else:
                    r = r + t[2]
        q -= 1
    s = l + s + r
    if re:
        s = s[::-1]
    print(s)
string()

S = input()
Q = int(input())
flip = 0
head = []
tail = []
for i in range(Q):
  Query = input().split()
  if len(Query) == 3:
    T,F,C = Query
    F = int(F)-1
    if F^flip == 1:
      tail.append(C)
    else:
      head.append(C)
  else:
    flip ^= 1
if flip:
  head, tail = tail, head
  S = S[::-1]
head = ''.join(head[::-1])
tail = ''.join(tail)
print(head+S+tail)

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()
q = int(input())

is_s0_head = True
tail = len(S)-1

queue = deque(S)

for _ in range(q):
    # print(S)
    Q = list(input().split())
    if Q[0] == "1":
        is_s0_head = not is_s0_head
    else:
        if Q[1] == "1":
            if is_s0_head:
                queue.appendleft(Q[2])
            else:
                queue.append(Q[2])
        else:
            if is_s0_head:
                queue.append(Q[2])
            else:
                queue.appendleft(Q[2])

if is_s0_head:
    print("".join(list(S)))
else:
    print("".join(list(S)[::-1]))


from collections import deque

S = input()
q = int(input())

is_s0_head = True
tail = len(S)-1

queue = deque(S)

for _ in range(q):
    
    Q = list(input().split())
    if Q[0] == "1":
        is_s0_head = not is_s0_head
    else:
        if Q[1] == "1":
            if is_s0_head:
                queue.appendleft(Q[2])
            else:
                queue.append(Q[2])
        else:
            if is_s0_head:
                queue.append(Q[2])
            else:
                queue.appendleft(Q[2])

if is_s0_head:
    print("".join(list(queue)))
else:
    print("".join(list(queue)[::-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):

S = input()
Q = int(input())
f = True
head = []
tail = []
for i in range(Q):
    query = input().split(' ')
    if len(query) == 1:
        f = not f
    else:
        if (query[1] == '1' and f) or (query[1] == '0' and not f):
            head.append(query[2])
        else:
            tail.append(query[2])

S = ''.join(head)+S+''.join(tail)
if not f:
    S = S[::-1]
print(S)

# start = time.time()
# elapsed_time = time.time() - start
# print("elapsed_time:{0}".format(elapsed_time) + "[sec]")



S = input()
Q = int(input())
f = True
for i in range(Q):
    query = input().split(' ')
    if len(query) == 1:
        f = not f
    else:
        if (query[1] == '1' and f) or (query[1] == '0' and not f):
            S = query[2]+S
        else:
            S = S+query[2]

print(S)

# start = time.time()
# elapsed_time = time.time() - start
# print("elapsed_time:{0}".format(elapsed_time) + "[sec]")



S = input()
Q = int(input())
f = True
head = []
tail = []
for i in range(Q):
    query = input().split(' ')
    if len(query) == 1:
        f = not f
    else:
        if (query[1] == '1' and f) or (query[1] == '2' and not f):
            head.append(query[2])
        else:
            tail.append(query[2])

S = ''.join(head)[::-1]+S+''.join(tail)
if not f:
    S = S[::-1]
print(S)

# start = time.time()
# elapsed_time = time.time() - start
# print("elapsed_time:{0}".format(elapsed_time) + "[sec]")


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(list(input()))
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if (int(b[0]) + f) % 2 == 0 :
      S.append(b[1])
    else:
      S.appendleft(b[1])
for i in range(len(S)):
  if f % 2 == 1:
    print (S[-i-1], end="")
  else:
    print (*S, sep="")


from collections import deque
S = deque(input().split())
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if (int(b[0]) + f) % 2 == 0 :
      S.appendleft(b[1])
    else:
      S.append(b[1])
for i in range(len(S)):
  if f % 2 == 0:
    print (S[-i-1], end="")
  else:
    print (S[i], end="")

from collections import deque
S = deque(input().split())
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if (int(b[0]) + f) % 2 == 0 :
      S.appendleft(b[1])
    else:
      S.append(b[1])
if f % 2 == 0:
  for i in range(len(S)):
    print (S[-i-1], end="")
    print ()
else:
  print (*S, sep="")


from collections import deque
S = deque(input().split())
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if (int(b[0]) + f) % 2 == 0 :
      S.appendleft(b[1])
    else:
      S.append(b[1])
if f % 2 == 0:
  for i in range(len(S)):
    print (S[-i-1], end="")
else:
  print (*S, sep="")

from collections import deque
S = deque(input().split())
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if int(b[0]) + f % 2 ==0 :
      S.leftappend(b[1])
    else:
      S.append(b[1])
if f % 2 == 0:
  for i in range(len(S)):
    print (S[-i-1], end="")
else:
  print (*S, sep="")

from collections import deque
S = deque(list(input()))
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if (int(b[0]) + f) % 2 == 1 :
      S.appendleft(b[1])
    else:
      S.append(b[1])
D = list(S)
print ("".join(D) if f % 2 == 0 else "".join(D[::-1]))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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 = list(input())
s = deque(s)
n = int(input())
cnt = 0
for i in range(n):
    q = list(map(str,input().split()))
    if q[0] == '1':
        cnt += 1
    else:
        if cnt % 2 == 0:
            if q[1] == '1':
                s.appendleft(q[2])
            else:
                s.append(q[2])
        else:
            if q[1] == '1':
                s.append(q[2])
            else:
                s.appendleft(q[2])
    print(q)
if cnt % 2 != 0:
    s.reverse()
print(''.join(list(s)))


from collections import deque
s = list(input())
s = deque(s)
n = int(input())
cnt = 0
for i in range(n):
    q = list(map(str,input().split()))
    if q[0] == '1':
        cnt += 1
    else:
        if cnt % 2 == 0:
            if q[1] == '1':
                s.appendleft(q[2])
            else:
                s.append(q[2])
        else:
            if q[1] == '1':
                s.append(q[2])
            else:
                s.appendleft(q[2])
    #print(q)
if cnt % 2 != 0:
    s.reverse()
print(''.join(list(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())

cnt = 0
for _ in range(q):
    i = input().split()
    t = int(i[0])

    if t == 1:
        cnt += 1
    else:
        f = int(i[1])
        c = i[2]
        if (cnt % 2 == 0 and f == 1) or (cnt % 2 == 1 and f == 2):
            # s.insert(0, i[2])
            s.append(i[2])
        else:
            s.append(i[2])
print(''.join(s) if cnt % 2 == 0 else ''.join(s[::-1]))

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

cnt = 0
for _ in range(q):
    i = input().split()
    t = int(i[0])

    if t == 1:
        cnt += 1
    else:
        f = int(i[1])
        c = i[2]
        if (cnt % 2 == 0 and f == 1) or (cnt % 2 == 1 and f == 2):
            s.appendleft(i[2])
        else:
            s.append(i[2])

if cnt % 2 == 1:
    s.reverse()
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):
def main(s,end,start,perse):
    start.reverse()
    start.append(''.join(s))
    start.append(''.join(end))
    print(start)
    print(''.join(start))
def conv(s):
    a = []
    for i in range(len(s)):
        a.append(s[i])
    return a
perse = 1
start = []
end = []
  
s = input()
q = int(input())
for i in range(q):
    query = input().split()
    query[0] = int(query[0])
    if query[0] == 1:
        perse = -perse
    else:
        query[1] = int(query[1])
        if (int(query[1])*2-3)*perse == 1:
            end.append(query[2])
        else:
            start.append(query[2])
s =  conv(s)
if perse == -1:
    start.reverse()
    s.reverse()
    end.reverse()
main(s,end,start,perse)

def main(s,end,start,perse):
    start.reverse()
    start.append(''.join(s))
    start.append(''.join(end))
    if perse == -1:
        start.reverse()
    print(''.join(start))
def conv(s):
    a = []
    for i in range(len(s)):
        a.append(s[i])
    return a
perse = 1
start = []
end = []
  
s = input()
q = int(input())
for i in range(q):
    query = input().split()
    query[0] = int(query[0])
    if query[0] == 1:
        perse = -perse
    else:
        query[1] = int(query[1])
        if (int(query[1])*2-3)*perse == 1:
            end.append(query[2])
        else:
            start.append(query[2])
s =  conv(s)
if perse == -1:
    s.reverse()
    end.reverse()
main(s,end,start,perse)

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())
for _ in range(q):
    query = input().split()
    if query[0] == '1':
        s = s[::-1]
    else:
        if query[1] == '1':
            s = query[2] + s
        else:
            s = s + query[2]
    print(s)


from collections import deque

is_reverse = False
s = deque(input())
q = int(input())
for _ in range(q):
    query = input().split()
    if query[0] == '1':
        is_reverse = not is_reverse
    else:
        if (not is_reverse and query[1] == '1') or (is_reverse and query[1] == '2'):
            s.appendleft(query[2])
        else:
            s.append(query[2])
print(''.join(s)[::-1]) if is_reverse else 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):
def do(s, query, isReverse):
    if(query[0] == "1"):
        return s, isReverse * -1
    else:
        if(query[1] == "1"):
            if(isReverse == 1):
                return "".join([s, query[2]]), isReverse
            else:
                return "".join([query[2], s]), isReverse
        else:
            if(isReverse == 1):
                return "".join([query[2], s]), isReverse
            else:
                return "".join([s, query[2]]), isReverse

s = input()
q = int(input())
isReverse = -1
for i in range(q):
    query = input().split()
    #s, isReverse = do(s, query, isReverse)
if(isReverse == -1):
    print(s)
else:
    print(s[::-1])

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

ans = [" " for n in range(2*q + 1)]
ans[q] = s
frontIndex = q - 1
endIndex = q + 1
isReverse = -1

for i in range(q):
    query = input().split()
    if(query[0] == "1"):
        isReverse *= -1
    else:
        if(query[1] == "1"):
            if(isReverse == 1):
                ans[endIndex] = query[2]  
                endIndex += 1
            else:
                ans[frontIndex] = query[2]
                frontIndex -= 1
        else:
            if(isReverse == 1):
                ans[frontIndex] = query[2] 
                frontIndex -= 1
            else:
                ans[endIndex] = query[2]
                endIndex += 1
ans = "".join(ans).strip()
if(isReverse == -1):
    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):
import sys
s = str(input())
Q = int(input())
q = sys.stdin.readlines()
for i in q:
  if i[0] == 1:
    s = alpha[::-1]
  elif i[1] == 1:
    s.appendleft(i[2])
  else:
    s.append(i[2])
print(s)

from collections import deque
import sys
s = deque(list(input()))
Q = int(input())
cnt = 0

for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    cnt = (cnt+1) % 2
  elif q[1] == '1':
    if cnt == 0:
      s.appendleft(q[2])
    else:
      s.append(q[2])
  else:
    if cnt == 0:
      s.append(q[2])
    else:
      s.appendleft(q[2])

if cnt == 1:
  s.reverse()
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):
import sys
input = sys.stdin.readline

S = input().strip()
Q = int(input())

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        S.reverse()
    elif q[0] == '2':
        if q[1] == '1':
            S = '{}{}'.format(q[2], S)
        elif q[1] == '2':
            S = '{}{}'.format(S, q[2])

print(S)


import sys
from collections import deque
input = sys.stdin.readline

S = deque(input().strip())
Q = int(input())
flag = 0

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        flag = 1 if not flag else 0
    elif q[0] == '2':
        if q[1] == '1':
            S.appendleft(q[2]) if not flag else S.append(q[2])
        elif q[1] == '2':
            S.append(q[2]) if not flag else S.appendleft(q[2])

print(''.join(S)) if not flag else print(''.join(reversed(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())
for _ in range(q):
    l = input()
    if ipt == "1":
        s = s[::-1]
    else:
        t, f, c = l.split()
        if f == "1":
            st = c + st
        else:
            st += c
print(st)

def input(): return sys.stdin.readline().strip()
st = input()
q = int(input())
for i in range(q):
    ipt = input()
    if ipt == "1":
        st = st[::-1]
    else:
        _, f, c = input().split()
        if f == "1":
            st = st + c
        else:
            st = c + st
print(st)


s, _, q = open(0)
g = ""
for q in q:
  p, f, c = q.split()
  if p == "1":
    g, s = s, g
  else:
    if f == "1":
      g += c
    else:
      s += c
print(g[::-1] + s)

#!/usr/bin/env python3
s, _, *q = open(0)
g = ""
s = s.strip()
for q in q:
  q = q.strip().split()
  if q[0] == "1":
    g, s = s, g
  else:
    if q[1] == "1":
      g += q[2]
    else:
      s += q[2]
print(g[::-1] + s)

Verdicts: Runtime Error

Runtime Error

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())
head=""
tail=""
rev=False

for _ in range(Q):
    q = input().split()
    if len(q)==1:
        rev != rev
    else:
        if rev ^ (q[1]=="1"):
            head+=q[2]
        else:
            tail+=q[2]
if rev:
    print(tail[::-1]+S[::-1]+head)
else:
    print(head[::-1]+S+tail)


S=input()
Q=int(input())
head=""
tail=""
rev=False

for _ in range(Q):
    q = input().split()
    if len(q)==1:
        rev = not rev
    else:
        if rev ^ (q[1]=="1"):
            head+=q[2]
        else:
            tail+=q[2]
if rev:
    print(tail[::-1]+S[::-1]+head)
else:
    print(head[::-1]+S+tail)


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=str(input())
c=0
n=1
q=int(input())
for i in range(q):
    a=input().strip()
    a=list(a)
    #print(a)
    if int(a[0])==1:
        #print("DFGHJ")
        c=+1
        n+=1
    if c%2==1:
        if int(a[0])==2:
            #print(a[2])
            s=list(s)
            if int(a[2])==2:
                s=deque(s)
                #print(s)
                s.appendleft(str(a[4]))
                #print(s)
                s=list(s)
                #print("DFGH",s)
            else:
                s.append(str(a[4]))
            s=''.join(s)
            #print(s)  
            for i in range(n%2):
                s=s[::-1]
            n=0
    else:    
        if int(a[0])==2:
        #print(a[2])
            s=list(s)
            if int(a[2])==1:
                s=deque(s)
                #print(s)
                s.appendleft(str(a[4]))
                #print(s)
                s=list(s)
                #print("DFGH",s)
            else:
                
                s.append(str(a[4]))
            s=''.join(s)
            #print(s) 
            for i in range(n%2):
                s=s[::-1]
            n=0

print(s)


from collections import deque
s=str(input())

front = ""
back = ""

now_swap = 0
q=int(input())
for i in range(q):
    a = input().strip()
    a = list(a)
    
    if a[0] == "1":
        if now_swap == 0:
           now_swap = 1
        else: #now_step == 1:
            now_swap = 0
    else:
        if now_swap == 1:
            if a[2] == "1":
               # print("back")
                back+=a[4]

            else: #a[1]==2:
               ## print("f 2")
                front = a[4] + front

        else: #now_step == 0:
            if a[2] == "1":
                front = a[4] + front

            else: #a[1]==2:
                
                back+=a[4]
ans= front + s + back
#print(front,a,back)
if now_swap == 1:
    
    print(ans[::-1])
else:
    print(ans)




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()
num = int(input())
data = [input().split(' ') for i in range(kai)]

for i in range(num):
    if(data[i][0] == '1'):
        if(len(string) == 2):
            string = string[1] + string[0]
        elif(len(string) >= 3):
            string = string[-1] + string[1:-1] + string[0]
        
    else:
        if(data[i][1] == '1'):
            string = data[i][2] + string
        else:
            string = string + data[i][2]

print(string)


string = input()
kai = int(input())
data = [input().split(' ') for i in range(kai)]
key = 0  #0 start

for i in range(kai):
    if(data[i][0] == '1'):
        key = 1
    elif(data[i][1] == '1'):
        string = data[i][2] + string
    else:
        string = string + data[i][2]
if(key == 0):
    print(string)
else:
    print(string[::-1])


string = input()
kai = int(input())
data = [input().split(' ') for i in range(kai)]
key = 0  #0 start
former = []
latter = []

for i in range(kai):
    if(data[i][0] == '1'):
        key = (key + 1) % 2
    elif((int(data[i][1]) + key) % 2 == 1):
        former.append(data[i][2])
    else:
        latter.append(data[i][2])

string = ''.join(former[::-1]) + string + ''.join(latter)
if(key == 0):
    print(string)
else:
    print(string[::-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):
import sys
from collections import deque
input = sys.stdin.readline

reverse = 0
S = deque(list(input()))
q = int(input())

for _ in range(q):
    query = input()
    if query[0] == '1':
        reverse = 1 - reverse
        continue

    _, f, c = query.split()
    f = int(f)
    action = (reverse + f) % 2
    if action:
        S.appendleft(c)
    else:
        S.append(c)

if reverse:
    S.reverse()
    
print(''.join(S))


import sys
from collections import deque


reverse = 0
S = deque(list(input()))
q = int(input())

for query in sys.stdin:
    if query[0] == '1':
        reverse = 1 - reverse
        continue

    _, f, c = query.split()
    f = int(f)
    action = (reverse + f) % 2
    if action:
        S.appendleft(c)
    else:
        S.append(c)

if reverse:
    S.reverse()

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):
str = input()
times = int(input())
revers = 0
head = ""
tail = ""
for i in range(times):
    com = input().split()
    if com[0] == "1":
        if revers == 0:
            revers = 1:
        else :
            revers = 0
        
    else :
        if com[1] == "1":
            if revers == 0:
                head = com[2]+head
            else :
                tail = tail + com[2]
        else : 
            if revers == 1:
                head = com[2]+head
            else :
                tail = tail + com[2]          
str = head + str + tail
if revers == 1:
    str = str[::-1]
                
print(str)

str = input()
times = int(input())
revers = 0
head = ""
tail = ""
for i in range(times):
    com = input().split()
    if com[0] == "1":
        if revers == 0:
            revers = 1
        else :
            revers = 0
        
    else :
        if com[1] == "1":
            if revers == 0:
                head = com[2]+head
            else :
                tail = tail + com[2]
        else : 
            if revers == 1:
                head = com[2]+head
            else :
                tail = tail + com[2]          
str = head + str + tail
if revers == 1:
    str = str[::-1]
                
print(str)

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
S = input()

Q = int(input())

A = [S]

for i in range(Q):
    s = input().split()
    if len(s) == 1:
        A = A[::-1]
    else:
        if s[1] == '1':
            A.insert(0,s[2])
        else:
            A.insert(-1,s[2])

print('%s' % ''.join(A))



Sr = list(input())
Sl = []
Q = int(input())


for i in range(Q):
    s = list(input().split())
    if len(s) == 1:
        Sr,Sl = Sl,Sr
    else:
        if s[1] == '1':
            Sl.insert(0,s[2])
        else:
            Sr.append(s[2])

print('%s' % (''.join(Sl) + ''.join(Sr)))



import numpy as np
S = input()

Q = int(input())

A = [S]

for i in range(Q):
    s = input().split()
    if len(s) == 1:
        A = A[::-1]
    else:
        if s[1] == '1':
            A.insert(0,s[2])
        else:
            A.insert(-1,s[2])

print('%s' % ''.join(A))



Sr = list(input())
Sl = []
Q = int(input())


for i in range(Q):
    s = list(input().split())
    if len(s) == 1:
        Sr,Sl = Sl,Sr
    else:
        if s[1] == '1':
            Sl.append(s[2])
        else:
            Sr.append(s[2])

print('%s' % (''.join(Sl) + ''.join(Sr)))



Sr = list(input())
Sl = []
Q = int(input())


for i in range(Q):
    s = list(input().split())
    if len(s) == 1:
        Sr,Sl = Sl,Sr
    elif s[1] == '1':
        Sl.append(s[2])
    else:
        Sr.append(s[2])
Sl.reverse()
print('%s' % (''.join(Sl) + ''.join(Sr)))



Verdicts: Wrong Answer

Wrong Answer

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):
S = list(input())
Q = int(input())
query = [input().split() for i in range(Q)]
print(query)
for i in query:
    if i[0] == '1':
        S = list(reversed(S))
    elif i[0]=='2' and i[1]=='1':
        S.insert(0, i[2])
    elif i[0]=='2' and i[1]=='2':
        S.append(i[2])
print(''.join(S))


S = list(input())
Q = int(input())
query = [input().split() for i in range(Q)]
print(query)
for i in query:
    # print(i)
    if i[0] == '1':
        
        S = list(reversed(S))
        print(S)
    elif i[0]=='2' and i[1]=='1':
        S.insert(0, i[2])
        print(S)
    elif i[0]=='2' and i[1]=='2':
        S.append(i[2])
        print(S)
print(''.join(S))


from collections import deque

S = list(input())
S = deque(S)
Q = int(input())
reverse = 1
query = [input().split() for i in range(Q)]
for i in query:
    if len(i) == 1:
        reverse *= -1
    elif (i[1]=='1' and reverse == 1) or (i[1]=='2' and reverse==-1):
        S.appendleft(i[2])
    else:
        S.append(i[2])
if reverse == -1:
   S.reverse() 
print(''.join(list(S)))

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):
import sys
input = sys.stdin.readline
s  = input()
q  = int(input())
inv = 1
sfb = [0,"",""]
for i in range(q):
    ls = list(input().split())
    if ls[0] == "1":
        inv *=-1
    else:
        f,c = ls[1:]
        if f == "1":
            sfb[inv] +=c
        else:
            sfb[-inv] +=c

ans = sfb[1][::-1] + s + sfb[-1]
print(ans[::inv])


def main():
    s  = input()
    q  = int(input())
    inv = 1
    sfb = [0,"",""]
    for i in range(q):
        ls = list(input().split())
        if ls[0] == "1":
            inv *=-1
        else:
            f,c = ls[1:]
            if f == "1":
                sfb[inv] +=c
            else:
                sfb[-inv] +=c

    ans = sfb[1][::-1] + s + sfb[-1]
    print(ans[::inv])
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):
from collections import deque
S=input()
N=int(input())
Q=[input() for i in range(N)]
T=deque(S)
for i in range(N):
    if Q[i][0]=="2":
        if Q[i][2]=="1":
            T.appendleft(Q[i][4])
            S=list(T)
        if Q[i][2]=="2":
            T.append(Q[i][4])
            S=list(T)
    if Q[i][0]=="1":
        S=list(T)
        S=S[::-1]
        T=deque(S)
print(str(S))

from collections import deque
S=input()
N=int(input())
Q=[input() for i in range(N)]
T=deque(S)
cnt=0
for i in range(N):
    if Q[i][0]=="1":
        cnt+=1
    if cnt%2==0:
        if Q[i][0]=="2":
            if Q[i][2]=="1":
                T.appendleft(Q[i][4])
            if Q[i][2]=="2":
                T.append(Q[i][4])
    if cnt%2==1:
        if Q[i][0]=="2":
            if Q[i][2]=="1":
                T.append(Q[i][4])
            if Q[i][2]=="2":
                T.appendleft(Q[i][4])
if cnt%2==1:
    T.reverse()
print(''.join(T))

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

cnt = [0]*(q+5)
arr=[]
l=0
r=0

for i in range(q):
    t=input().split()
    if t[0]=='1':
        r+=1
        cnt[0]+=1 
        cnt[l]-=1 
    else:
        arr.append([t[2],int(t[1])])
        l+=1 
if r%2==1:
    s=s[::-1]
sm=0
for i in range(len(arr)):
    sm+=cnt[i]
    if sm%2==1:
        if arr[i][1]==1:arr[i][1]=2
        elif arr[i][1]==2:arr[i][1]=1 
ans1=""
ans2=""
for i in range(len(arr)):
    if arr[i][1]==1:
        ans1+=arr[i][0]

    else:ans2+=arr[i][0]
print("%s%s%s"%(ans1,s,ans2))        
        
    
    
    
    

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

cnt = [0]*(q+5)
arr=[]
l=0
r=0

for i in range(q):
    t=input().split()
    if t[0]=='1':
        r+=1
        cnt[0]+=1 
        cnt[l]-=1 
    else:
        arr.append([t[2],int(t[1])])
        l+=1 
if r%2==1:
    s=s[::-1]
sm=0
for i in range(len(arr)):
    sm+=cnt[i]
    if sm%2==1:
        if arr[i][1]==1:arr[i][1]=2
        elif arr[i][1]==2:arr[i][1]=1 
ans1=""
ans2=""
for i in range(len(arr)):
    if arr[i][1]==1:
        ans1+=arr[i][0]

    else:ans2+=arr[i][0]
print("%s%s%s"%(ans1[::-1],s,ans2))        
        
    
    
    
    

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 sys import stdin
def main():
    readline = stdin.readline
    S=readline()
    Q=int(readline())
    Queries=[readline().split() for i in range(Q)]

    for i in Queries:
        if i[0]=='1':
            S=S[::-1]
        else:
            if i[1]=='1':
                S=i[2]+S
            else:
                S=S+i[2]
    print(S)
main()

S=input()
Q=int(input())
Q=[input().split() for i in range(Q)]
Forward=[]
Backward=[]
count=0
for i in Q:
    if i[0]=='1':
        count+=1
    else:
        if (int(i[1])+count)%2==1:
            Forward.append(i[2])
        else:
            Backward.append(i[2])  
if count%2==0:
    ans = (''.join(Forward))[::-1]+S+(''.join(Backward))
else:
    ans = (''.join(Backward)[::-1]+S[::-1]+(''.join(Forward)))
print(ans)

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())
Q = [list(map(str, input().split())) for i in range(q)]

ans = ['' for in range(10 ** 5 * 3 + 2)]

for i in range(len(s)):
  ans[10 ** 5 + i + 1] = s[i]

reverse_num = 0
tmp1 = 0
tmp2 = 0
for i in range(q):
  if int(Q[i][0]) == 1:
    reverse_num += 1
  else:
    if int(Q[i][1]) == 1:
      if reverse_num % 2 == 0:
        ans[10 ** 5 - tmp1] = Q[i][2]
        tmp1 += 1
      else:
        ans[10 ** 5 + len(s) + tmp2] = Q[i][2]
        tmp2 += 1
    else:
      if reverse_num % 2 != 0:
        ans[10 ** 5 - tmp1] = Q[i][2]
        tmp1 += 1
      else:
        ans[10 ** 5 + len(s) + tmp2] = Q[i][2]
        tmp2 += 1
      
res = ''
for i in range(len(ans)):
  if ans[i] != '':
    res += ans[i]
    
print(ans)


s = input()
q = int(input())
Q = [list(map(str, input().split())) for i in range(q)]

ans = ['' for i in range(10 ** 5 * 3 + 2)]

for i in range(len(s)):
  ans[10 ** 5 + i + 1] = s[i]

reverse_num = 0
tmp1 = 0
tmp2 = 0
for i in range(q):
  if int(Q[i][0]) == 1:
    reverse_num += 1
  else:
    if int(Q[i][1]) == 1:
      if reverse_num % 2 == 0:
        ans[10 ** 5 - tmp1] = Q[i][2]
        tmp1 += 1
      else:
        ans[10 ** 5 + len(s) + tmp2] = Q[i][2]
        tmp2 += 1
    else:
      if reverse_num % 2 != 0:
        ans[10 ** 5 - tmp1] = Q[i][2]
        tmp1 += 1
      else:
        ans[10 ** 5 + len(s) + tmp2] = Q[i][2]
        tmp2 += 1
      
res = ''
for i in range(len(ans)):
  if ans[i] != '':
    res += ans[i]
    
print(ans)


from collections import deque

s = input()
q = int(input())
Q = [list(map(str, input().split())) for i in range(q)]

ans = deque(s)

reverse_num = 0
for i in range(q):
  if int(Q[i][0]) == 1:
    reverse_num += 1
  else:
    if int(Q[i][1]) == 1:
      if reverse_num % 2 == 0:
        ans.appendleft(Q[i][2])
      else:
        ans.append(Q[i][2])
    else:
      if reverse_num % 2 != 0:
        ans.appendleft(Q[i][2])
      else:
        ans.append(Q[i][2])

res = ''
if reverse_num % 2 == 0: 
  for i in range(len(ans)):
    res += ans.popleft()
  print(res)
else:
  for i in range(len(ans)):
    res += ans.pop()
  print(res)


Verdicts: Runtime Error

Wrong Answer

Accepted