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):
S = input()
Q = int(input())
QUE = []
start_index = None
end_index = None
for i in range(Q):
    query = input()
    if query == "1" and start_index == None:
        start_index = i
    elif query == "1":
        end_index = i
    else:
        if start_index == None:
            QUE.append(query)
        else:
            if end_index == None:
                QUE.append("1")
            else:
                for _ in range(end_index - start_index + 1):
                    QUE.append("1")
            QUE.append(query)
            start_index = None
            end_index = None

for query in QUE:
    if query == "1":
        S = S[::-1]
    else:
        query = list(query)
        F = query[2]
        C = query[4]
        if F == "1":
            
            S = C + S
        else:
            
            S = S + C

print(S)


S = list(input())
Q = int(input())
front = []
back = []
ifZyun = True

for _ in range(Q):
    query = input()
    if query == "1":
        ifZyun = not ifZyun
    else:
        query = list(query)
        F = query[2]
        C = query[4]
        if (F == "1" and ifZyun) or (F == "2" and not ifZyun):
            front.append(C)
        else:
            back.append(C)

if not ifZyun:
    S = S[::-1]
    print("".join(back[::-1] + S + front))
else:
    front = front[::-1]
    print("".join(front + S + back))


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
input = sys.stdin.readline
s = input()
q = int(input())
c = []
for i in range(q):
  que = input().split()
  c_append = c.append
  c_append(que)
  
for i in c:
  if i[0] == '1':
    s = s[::-1]
  else:
    if i[1] == '1':
      s = i[2] + s
    else:
      s = s + i[2]
print(s)

def main():
  import sys
  input = sys.stdin.readline
  from collections import deque
  s = list(input())
  s = s[:-1]
  s = deque(s)
  q = int(input())
  c = [[i for i in input().split()] for j in range(q)]
  cnt = 1
  for i in c:
    if i[0] == '1':
      cnt *= -1
    else:
      if (i[1] == '1' and cnt == 1) or (i[1] == '2' and cnt == -1):
        s.appendleft(i[2])
      else:
        s.append(i[2])
  if cnt == 1:
    print(''.join(s))
  else:
    print(''.join(s)[::-1])
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())
s0 = []
s1 = []
for _ in range(q):
    ql = list(input().split())
    if ql[0] == '1':
        s0[-1:], s1[-1:] = s1[-1:], s0[-1:]
    else:
        if ql[1] == '1':
            s0 += ql[2]
        else:
            s1 += ql[2]

ans = s0 + s + s1
print(*ans, sep='')

s = input()
q = int(input())
head = ''
tail = ''
rev = 0

for _ in range(q):
    T = list(input().split())
    if T[0] == '1':
        head, tail = tail, head
        rev += 1
    else:
        if T[1] == '1':
            head += T[2]
        else:
            tail += T[2]

if rev%2 == 0:
    print(head[::-1]+s+tail)
else:
    print(head[::-1]+s[::-1]+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):
s = input()
q = int(input())
exchange = 0

for _ in range(q):
  query = input()
  if query == '1':
    excnange += 1
  else:
    t, f, c = query.split()
    if f == '1':
      s = c + s
    else:
      s = s + c
      
if exchange % 2 == 0:
  print(s)
else:
  print(s[::-1])


import sys
input = sys.stdin.readline

s = input().strip()
q = int(input())
query = [list(input().strip().split()) for _ in range(q)]

left = ''
right = ''
t = False
for ls in query:
    if len(ls) == 1:
        t = not t
    else:
        two, f, c = ls
        if f == '1':
            if t:
                right += c
            else:
                left += c
        else:
            if t:
                left += c
            else:
                right += c

if t:
    print(right[::-1] + s[::-1] + left)
else:
    print(left[::-1] + s + right)
    

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()
N = int(input())
Q = [input().split() for _ in range(N)]
start = ''
end = ''


direct = 0
for i in range(N):
  if Q[i][0] =='1':
    direct^=1
  else:
    if direct == int(Q[i][1])-1:
      start += Q[i][2]
      print('start',start)
    else:
      end += Q[i][2]
      print('end',end)
      
ans = start[::-1]+S+end
print(ans) if direct == 0 else print(ans[::-1])

S = input()
N = int(input())
Q = [input().split() for _ in range(N)]
start = ''
end = ''


direct = 0
for i in range(N):
  if Q[i][0] =='1':
    direct^=1
  else:
    if direct == int(Q[i][1])-1:
      start += Q[i][2]
    else:
      end += Q[i][2]
      
ans = start[::-1]+S+end
print(ans) if direct == 0 else print(ans[::-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):
def main():
  w = input()
  s = collections.deque(w)
  n = int(input())
  
  reverse_count = 0
  for i in range(n):
    t = list(input_list_str())
    if len(t) == 1:
      reverse_count = 1 - reverse_count
      continue
    q, f, c = t
    if int(f) == 1:
      s.append(c)
    else:
      s.appendleft(c)
  if reverse_count == 1:
    s.reverse()
  print(''.join(s))
  exit()
  a = pre_s + s + after_s
  if reverse_count % 2 != 0:
    a = a[::-1]
  print(a)
    
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
import collections
from functools import reduce
main()

def main():
  w = input()
  s = collections.deque(w)
  n = int(input())
  
  order = True
  for _ in range(n):
    q = list(input_list_str())
    if len(q) == 1:
      order = False if order else True
      continue
    t, f, c = q
    if int(f) == 1:
      if order:
        s.appendleft(c)
      else:
        s.append(c)
    else:
      if order:
        s.append(c)
      else:
        s.appendleft(c)
  if order is False:
    s.reverse()
  print(''.join(s))

    
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
import collections
from functools import reduce
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 = str(input())
Q = int(input())
flip = 0
for i in range(Q):
  j = input()
  if len(j) == 1:
    flip += 1
    continue
  else:
    if flip % 2 == 0:
      if j[2] == '1':
        S = j[4] + S
        continue
      elif j[2] == '2':
        S = S + j[4]
        continue
    elif flip % 2 == '1':
      if j[2] == 1:
        S = S + j[4]
        continue
      elif j[2] == '2':
        S = j[4] + S
        continue
if flip % 2 == 1:
  S = S[::-1]
print(S)

S = str(input())
Q = int(input())
flip = 0
front,back = '',''
for i in range(Q):
  j = input()
  if len(j) == 1:
    flip += 1
    continue
  else:
    if j[2] == '1' and flip % 2 == 0:
      front = j[4] + front
      continue
    elif j[2] == '2' and flip % 2 == 0:
      back = back + j[4]
      continue
    elif j[2] == '1' and flip % 2 ==1:
      back= back + j[4]
      continue
    elif j[2] == '2' and flip % 2 ==1:
      front = j[4] + front
      continue
S = front + S + back
if flip % 2 == 1:
  S = S[::-1]
print(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())
back = 1
for i in range(q):
    query = input().split()
    if query[0] == '1':
        back *= -1
    else:
        if query[1] == '1':
            if back == 1:
                s = query[2] + s
            else:
                s = s + (query[2]
        else:
            if back == 1:
                s = s + query[2]
            else:
                s = query[2] + s
if back == -1:
    s = s[-1::-1]
print(s)

import collections
s = input()
q = int(input())
back = 1
t = collections.deque()
for ss in s:
    t.append(ss)
for i in range(q):
    query = input().split()
    if query[0] == '1':
        back *= -1
    else:
        if query[1] == '1':
            if back == 1:
                t.appendleft(query[2])
            else:
                t.append(query[2])
        else:
            if back == 1:
                t.append(query[2])
            else:
                t.appendleft(query[2])
ans = ''
if back == -1:
    for i in range(len(t)):
        ans += t.pop()
else:
    for i in range(len(t)):
        ans += t.popleft()
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):
s = input()
q = int(input())

query = [[x for x in input().split()] for i in range(q)]

T2query = []
cnt=0
for i in range(q-1,-1,-1):
    if(query[i][0]=='1'):
        cnt+=1
        continue
    if(cnt%2!=0):
        if(query[i][1]=='1'):
            query[i][1]='2'
        else:
            query[i][1]='1'  
    T2query.append(query[i])
print(cnt)
if(cnt%2!=0):
    s = s[::-1]


for _,i,word in reversed(T2query):
    
    if(i=='1'):
        s = word + s
    else:
        s = s + word

print(s)

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

query = [[x for x in input().split()] for i in range(q)]

T2query = []
begin = []
end = []
cnt=0
for i in range(q-1,-1,-1):
    if(query[i][0]=='1'):
        cnt+=1
        continue
    if(cnt%2==1):
        if(query[i][1]=='1'):
            end.append(query[i][2])
        else:
            begin.append(query[i][2])
    else:
        if(query[i][1]=='1'):
            begin.append(query[i][2])
        else:
            end.append(query[i][2])
wb = ''.join(begin)
we = ''.join(end)
we = we[::-1] 

if(cnt%2!=0):
    s = s[::-1]

s = wb + s + we

print(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())
reverse = 0
for i in range(Q):
  Query = list(input().split())
  if Query[0] == "1":
    reverse = (reverse + 1) % 2
  if Query[0] == "2":
    f = int(Query[1])
    c = query[2]
    if (f + reverse) % 2 == 1:
      S = c + S
    else:
      S = S + c

if reverse == 0:
  print(S)
else:
  print(S[::-1])

from collections import deque
S = deque(input())
Q = int(input())
reverse = 0
for i in range(Q):
  Query = list(input().split())
  if Query[0] == "1":
    reverse = (reverse + 1) % 2
  if Query[0] == "2":
    f = int(Query[1])
    c = Query[2]
    if (f + reverse) % 2 == 1:
      S.appendleft(c)
    else:
      S.append(c)

S = "".join(list(S))
 
if reverse == 0:
  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):
#!/usr/bin/env python3
s = input()
Q = int(input())
q = [input().split() for _ in range(Q)]
reverse = 0
start = ""
end = ""
for i in q:
    if i[0] == "1":
        reverse ^= 1
    else:
        if int(i[1]) + reverse >> 0 ^ 0:
            end += i[2]
        else:
            start += i[2]
print(start[::-1] + s[::1 - reverse * 2] + end)


#!/usr/bin/env python3
s = input()
Q = int(input())
q = [input().split() for _ in range(Q)]
reverse = 0
start = ""
end = ""
for i in q:
    if i[0] == "1":
        reverse ^= 1
    else:
        if int(i[1]) + reverse >> 0 ^ 0:
            end += i[2]
        else:
            start += i[2]
s = start[::-1] + s + end
print(s[::1 - reverse * 2])


#!/usr/bin/env python3
s = input()
Q = int(input())
q = [input().split() for _ in range(Q)]
reverse = 0
start = ""
end = ""
for i in q:
    if i[0] == "1":
        reverse ^= 1
    else:
        if (int(i[1]) + reverse) % 2:
            start += i[2]
        else:
            end += i[2]
s = start[::-1] + s + end
print(s[::1 - reverse * 2])


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):
S = list(input())
Q = int(input())
is_reversed = False
append_first = []
my_first = append_first.append
append_end = []
my_end = append_end.append

for i in range(Q):
  q = list(input())
  if q[0] == '1':
    is_reversed = True if is_reversed == False else False
  else:
    if q[2] == '1' and is_reversed:
      append_end.append(q[4])
    elif q[2] == '1': 
      append_first.append(q[4])
    elif is_reversed:
      append_first.append(q[4])   
    else:
      append_end.append(q[4])
      
append_first.extend(S) 
append_first.extend(append_end)

if is_reversed:
  append_first.reverse()
print(''.join(append_first))

S = list(input())
Q = int(input())
is_reversed = False
append_first = []
my_first = append_first.append
append_end = []
my_end = append_end.append

for i in range(Q):
  q = list(input())
  if q[0] == '1':
    is_reversed = True if is_reversed == False else False
  else:
    if q[2] == '1' and is_reversed:
      append_end.append(q[4])
    elif q[2] == '1': 
      append_first.append(q[4])
    elif is_reversed:
      append_first.append(q[4])   
    else:
      append_end.append(q[4])
      
append_first.reverse()
append_first.extend(S) 
append_first.extend(append_end)

if is_reversed:
  append_first.reverse()
print(''.join(append_first))

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
input=sys.stdin.readline
from collections import deque
s=deque([input()])
q=int(input())

for _ in range(q):
	t=input()
	if t[0]=="1":
		s.reverse()
	else:
		t,f,c=t.split()
		if f=="1":
			s.appendleft(c)
		else:
			s.append(c)
print(*s,sep="")


from collections import deque

s=deque(input())
n=int(input())
r=False
for i in range(n):
    q=input()
    if q[0]=="1":
        r= not r
    else:
        t,f,c=map(str,q.split())
        if f=="1":
            if r==False:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if r==True:
                s.appendleft(c)
            else:
                s.append(c)
s=list(s)
if r==True:
    s=s[::-1]
print(*s,sep="")

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
input = sys.stdin.readline
from collections import deque

s = deque(input())
reverse = 0
q = int(input())

for _ in range(q):
  query = input()
  if query == '1':
    reverse = 1 - reverse
  else:
    _,f,c = query.split()
    if f == '1':
      if reverse:
        s.appendleft(c)
      else:
        s.append(c)
    else:
      if reverse:
        s.append(c)
      else:
        s.appendleft(c)
if not  reverse:
  s.reverse()

print(''.join(s))

from collections import deque

s = deque(input())
reverse = 0
q = int(input())

for _ in range(q):
  query = input()
  if query == '1':
    reverse = 1 - reverse
  else:
    _,f,c = query.split()
    if f == '1':
      if reverse:
        s.append(c)
      else:
        s.appendleft(c)
    else:
      if reverse:
        s.appendleft(c)
      else:
        s.append(c)
        
  
if reverse:
  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

def main():
    s = input()
    n = int(input())
    li = [input().split() for i in range(n)]
    a = 0 

    for x in li:
        if x[0] == "1":
            if a == 0:
                a = 1
            else:
                a = 0
        else:
            if (x[1] == "1" and a == 0) or (x[1] == "2" and a == 1):
                s = x[2] + s
            else:
                s = s + x[2]

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

if __name__ == '__main__':
    main()

ans = input()
q = int(input())
top = 0
first = str()
last = str()

for i in range(q):
    li =input().split()
    if li[0] =="1":
        top = (top+1)%2
    else:
        if li[1] == "1":
            if top ==0:
                first += li[2]
            else:
                last += li[2]
        else:
            if top ==1:
                first += li[2]
            else:
                last += li[2]

if top == 0:
    ans = first[::-1] + ans + last
else:
    ans = last[::-1] + ans[::-1] + first

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

#Que = [list(map(str, input().split())) for _ in range(Q)]

for i in range(Q):
    flag, F, C = map(str, input().split())

    if flag == '1':
        S = S[::-1]

    if flag == '2':
        if F == '1':
            S = C + S
        if F == '2':
            S = S + C


print(S)

from  collections import deque

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

#Que = [list(map(str, input().split())) for _ in range(Q)]

deque_S = deque(S)
re_flag = 1
for i in range(Q):
    que = str(input())

    if len(que) == 1:
        #S = S[::-1]
        re_flag *= -1

    else:
        if que[2] == '1':
            if re_flag == 1:
                
                deque_S.appendleft(que[4:])
            else:
                
                deque_S.append(que[-1:3:-1])
        if que[2] == '2':
            if re_flag == 1:
                
                deque_S.append(que[4:])
            else:
                
                deque_S.appendleft(que[-1:3:-1])

ans = ''
if re_flag == 1:
    ans = ''.join(deque_S)
else:
    ans = ''.join(deque_S)[::-1]
#print(deque_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
s = deque(input())
print(s)
Q = int(input())

reverse = False
for i in range(Q):
    q = input()
    if q == "1":
        reverse = False if reverse else True
    else:
        t, f, c = q.split(" ")
        if f == "1":
            if reverse:
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if reverse:
                s.appendleft(c)
            else:
                s.append(c)
ans = ''.join(s)
if reverse:
    print(ans[::-1])
else:
    print(ans)


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

reverse = False
for i in range(Q):
    q = input()
    if q == "1":
        reverse = False if reverse else True
    else:
        t, f, c = q.split(" ")
        if f == "1":
            if reverse:
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if reverse:
                s.appendleft(c)
            else:
                s.append(c)
ans = ''.join(s)
if reverse:
    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):
S=str(input())
S_list=list(S)

Q=int(input())

q=[]
right=[]
left=[]

rev=1

for i in range(Q):
    q.append(input().split())
    if q[i][0]=="1":
        rev=rev*(-1)
    elif q[i][0]=="2":
        if q[i][1]=="1":
            if rev==1:
                right.insert(0,q[i][2])
            else:
                left.append(q[i][2])
        elif q[i][1]=="2":
            if rev==1:
                left.append(q[i][2])
            else:
                right.insert(0,q[i][2])
if rev==1:
    S_list.append(left)
    S_list.insert(0,right)
else:
    S_list.reverse()
    S_list.append(left)
    S_list.insert(0,right)
    
S=''.join(S_list)
print(S)

S=str(input())
S_list=list(S)

Q=int(input())

q=[]
right=[]
left=[]

rev=1

for i in range(Q):
    q.append(input().split())
    if q[i][0]=="1":
        rev=rev*(-1)
    elif q[i][0]=="2":
        if q[i][1]=="1":
            if rev==1:
                right.insert(0,q[i][2])
            else:
                left.append(q[i][2])
        elif q[i][1]=="2":
            if rev==1:
                left.append(q[i][2])
            else:
                right.insert(0,q[i][2])
print(right,left)

if rev==1:
    S_list=right+S_list+left
else:
    S_list=right+S_list+left
    S_list.reverse()

S=''.join(S_list)
print(S)

S=str(input())
S_list=list(S)

Q=int(input())

q=[]
right=[]
left=[]

rev=1

for i in range(Q):
    q.append(input().split())
    if q[i][0]=="1":
        rev=rev*(-1)
    elif q[i][0]=="2":
        if q[i][1]=="1":
            if rev==1:
                right.append(q[i][2])
            else:
                left.append(q[i][2])
        elif q[i][1]=="2":
            if rev==1:
                left.append(q[i][2])
            else:
                right.append(q[i][2])
right.reverse()
if rev==1:
    S_list=right+S_list+left
else:
    S_list=right+S_list+left
    S_list.reverse()

S=''.join(S_list)
print(S)

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):
s = input()
q = int(input())
jun = 1
f = t = ""
for _ in range(q):
  
  tmp = input()
  if len(tmp)==1:
    jun = 1 if jun==0 else 0 
  else:
    _,f,c = tmp.split()
    if jun+int(f) ==2:
      f = c+f
    else:
      t += c
if jun==1:
  print(f+s+t)
else:
  print((f+s+t)[::-1])
      
    


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

jun = 1
for _ in range(q):
  
  tmp = input()
  if len(tmp)==1:
    jun = int(jun*(-1/2)+1/2)
  else:
    _,f,c = tmp.split()
    f = int(f)
    if jun+f ==2:
      s = c+s
    else:
      s += c
if jun==1:
  print(s)
else:
  print(s[::-1])
      
    

s = input()
q = int(input())
jun = 1
f = "";t = ""
for _ in range(q):
  
  tmp = input()
  if len(tmp)==1:
    jun = 1 if jun==0 else 0 
  else:
    _,ff,c = tmp.split()
    if jun+int(ff) ==2:
      f = c+f
    else:
      t += c
if jun==1:
  print(f+s+t)
else:
  print((f+s+t)[::-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):

import sys
input = sys.stdin.readline
S = input()
Q = int(input())
FQ_dic =tuple()
rev =0
for i in range(Q):
    FQ_dic =tuple(input().split())

    if      FQ_dic[0] =="1": 
                rev +=1
    else:                   
        if      FQ_dic[1]=="1":     
            if rev %2 ==0:
                    S = FQ_dic[2] + S
            else:
                    S = S +FQ_dic[2] 
        else: 
            if rev %2 ==0:
                    S = S + FQ_dic[2]
            else:        
                    S = FQ_dic[2] + S
if rev %2 ==0:
    print(S)
else:
    print(S[::-1])


import sys
input = sys.stdin.readline
S = input()
Q = int(input())
FQ_dic =tuple()
rev =0
for i in range(Q):
    FQ_dic =tuple(input().split())

    if      FQ_dic[0] =="1": 
                rev +=1
    else:                   
        if      FQ_dic[1]=="1":     
            if rev %2 ==0:
                    S = FQ_dic[2] + S
            else:
                    S = S +FQ_dic[2] 
        else: 
            if rev %2 ==0:
                    S = S + FQ_dic[2]
            else:        
                    S = FQ_dic[2] + S
if rev %2 ==0:
    print(S)
else:
    print(S[::-1])




from collections import deque
import sys
input = sys.stdin.readline
S = input().strip()
Q = int(input())
FQ_dic={}
for i in range(Q):
    FQ_dic[i] =input().split()

rev =0 
dq =deque(S)
for i in range(Q):
    if FQ_dic[i][0] =="1":
        rev +=1
    else:
        a,b,c =FQ_dic[i]
        if rev %2 ==0 and b =="1"  :
            dq.appendleft(c)
        elif rev %2 ==0 and b =="2":
            dq.append(c)
        elif rev %2 ==1 and b =="1":
            dq.append(c)
        elif rev %2 ==1 and b =="2":
            dq.appendleft(c)
if rev %2 ==1:
    dq.reverse()
ans ="".join(dq)
print(ans)

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
import sys

S = input()
Q = int(input())
q = deque([S])
reverse = False

for i in range(Q):
    X = sys.stdin.readline().split()
    if X[0] == "1":
        if reverse:
            reverse = False
        else:
            reverse = True
    elif X[0] == "2":
        if reverse:
            print(reverse)
            X[1] = str(3-int(X[1]))
        if X[1] == "1":
            q.appendleft(X[2])
        else:
            q.append(X[2])
        print(reverse, X[1], q)

if reverse: q.reverse()

for i in range(len(q)):
    print(q[i],end="")
print()

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  string s;
  cin >> s;
  string t;
  int q;
  cin >> q;
  rep(qi,q){
    int ty;
    cin >> ty;
    if (ty == 1){
      swap(s,t);
    }else{
      int f; char c;
      cin >> f >> c;
      if (f == 1){
	t += c;
      }else{
	s+=c;
      }}
  }
  reverse(t.begin(), t.end());
  t += s;
  cout << t << endl;
  return 0;
}

from collections import deque

S = input()
Q = int(input())
q = deque([S])
reverse = -1

for i in range(Q):
    print(reverse)
    X = input().split()
    if X[0] == "1":
        reverse *= -1
    # if X[1] == "1":
    elif X[1] == "1":
        if reverse == -1:
            q.appendleft(X[2])
        else:
            q.append(X[2])
    elif X[1] == "2":
        if reverse == -1:
            q.append(X[2])
        else:
            q.appendleft(X[2])
    print(reverse, q)
if reverse == 1: q.reverse()

for i in range(len(q)):
    print(q[i],end="")
print()
        


from collections import deque

q = deque(input())
Q = int(input())
reverse = -1

for i in range(Q):
    X = input().split()
    if X[0] == "1":
        reverse *= -1
    # if X[1] == "1":
    elif X[1] == "1":
        if reverse == -1:
            q.appendleft(X[2])
        else:
            q.append(X[2])
    elif X[1] == "2":
        if reverse == -1:
            q.append(X[2])
        else:
            q.appendleft(X[2])


if reverse == -1:
    print(''.join(q))
else:
    print(''.join(list(q)[::-1]))

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())
x = 0
p = ''
q = ''
for i in range(Q):
    A = list(input().split())
    if A[0] == '1':
        x += 1
    elif x%2 ==0:
        if A[1] == '1':
            p = A[2] + p
        else:
            q = q + A[2]
    else:
        if A[1] == '1':
            q = q + A[2] 
        else:
            p = A[2] + p
if x%2 == 1:
    S = ''.join(reversed(list(S)))
print(S)

S = input()
Q = int(input())
x = 0
p = ''
q = ''
for i in range(Q):
    A = list(input().split())
    if A[0] == '1':
        x += 1
    elif x%2 ==0:
        if A[1] == '1':
            p = A[2] + p
        else:
            q = q + A[2]
    else:
        if A[1] == '1':
            q = q + A[2] 
        else:
            p = A[2] + p
S = p + S + q
if x%2 == 1:
    S = ''.join(reversed(list(S)))
print(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):
import sys
input = sys.stdin.readline

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

if __name__=="__main__":
    sol()

import sys
input = sys.stdin.readline

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

if __name__=="__main__":
    sol()


import sys
input = sys.stdin.readline

def sol():
    s=input().rstrip()
    q=int(input())
    x=0
    a,b="",""
    for i in range(q):
        l=tuple([i for i in input().split()])
        if l[0]=="1":
            x=(x+1)%2
        elif l[1]=="1":
            if x==0: a=l[2]+a
            else: b=b+l[2]
        elif l[1]=="2":
            if x==0: b=b+l[2]
            else: a=l[2]+a
    s=a+s+b
    print(s if x==0 else s[::-1])

if __name__=="__main__":
    sol()


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

T = 0
for _ in range(Q):
    Query = list(input().split())
    if len(Query) == 1:
        T ^= 1
    elif T == 0:
        m = Query[2]
        if Query[1] == '1':
            S.append(m)
        else:
            S.appendleft(m)
    else:
        m = Query[2]
        if Query[1] == '2':
            S.append(m)
        else:
            S.appendleft(m)

if T==1:
    S.reverse()

print(''.join(S))




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

T = 0
l = []
r = []
for _ in range(Q):
    Query = list(input().split())
    if len(Query) == 1:
        T ^= 1
    elif T == 0:
        s = Query[2]
        if Query[1] == '1':
            l.append(s)
        else:
            r.append(s)
    else:
        s = Query[2]
        if Query[1] == '1':
            r.append(s)
        else:
            l.append(s)

if T == 1:
    r.reverse()
    ans = ''.join(r) + S[::-1] + ''.join(l)
else:
    l.reverse()
    ans = ''.join(l) + S + ''.join(r)

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):
def main():
  s,q,*r = [list(k.split()) for k in open(0)]
  s=s[0]
  p = False
  for x in r:
    if len(x)==1:
      p = True
      continue
    if (p == False and x[1]=='1') or (p == True and x[1]=='2'):
      s = x[2] + s
    else:
      s = s + x[2]
    
  print("".join(s) if p==False else "".join(s)[::-1])
  
if __name__=='__main__':
  main()

def main():
  s = list( input() )
  q = int(input())
  r = [list(input().split()) for _ in range(q)]
  p = False
  for x in r:
    if len(x)==1:
      p = True
      continue
    if (p == False and x[1]=='1') or (p == True and x[1]=='2'):
      s = [x[2]] + s
    else:
      s = s + [x[2]]
    
  print("".join(s) if p==False else "".join(s[::-1]))
  
if __name__=='__main__':
  main()

def main():
  from collections import deque
  
  s,q,*r = [list(k.split()) for k in open(0)]
  que = deque(s[0])
  p = False
  for x in r:
    if len(x)==1:
      p = not p
      continue
    if (p==False and x[1]=='1') or (p==True and x[1]=='2'):
        que.appendleft(x[2])
    else:
        que.append(x[2])
  print("".join(que) if p==False else "".join(que)[::-1])
  
if __name__=='__main__':
  main()

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):
    qi=list(input().split())
    if qi[0]=="1":
        s=s[::-1]
    else:
        f,c=qi[1],qi[2]
        if f=="1":
            s=c+s
        else:
            s=s+c
print(s)

from collections import deque
s=deque(input())
q=int(input())
rev=0
for i in range(q):
    p=list(map(str,input().split()))
    if p[0]=="1":
        rev^=1
    else:
        z,f,c=p
        if f=="1":
            if rev:
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if rev:
                s.appendleft(c)
            else:
                s.append(c)
if rev:
    s=list(s)[::-1]
else:
    s=list(s)
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():
    import sys
    input = sys.stdin.readline
    s = input()
    q =int(input())
    ten = 0
    r = []
    l = []
    for _ in range(q):
        ls = tuple(map(str, input().split()))
        if len(ls)==1:
            ten +=1
        else:
            if ls[1] =='1':
                if ten%2 ==0:
                    l.append(ls[2])
                else:
                    r.append(ls[2])
            else:
                if ten%2 ==1:
                    l.append(ls[2])
                else:
                    r.append(ls[2])
    s = ''.join(reversed(l))+s+''.join(r)
    if ten%2 ==1:
        s = s[::-1]
    print(s)
if __name__ == '__main__':
    main()

def main():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip())
    q =int(input())
    ten = 0
    r = []
    l = []
    la = l.append
    ra =r.append
    for _ in range(q):
        ls = tuple(map(str, sys.stdin.readline().split()))
        if len(ls)==1:
            ten +=1
        else:
            if ls[1] =='1':
                if ten%2 ==0:
                    la(ls[2])
                else:
                    ra(ls[2])
            else:
                if ten%2 ==1:
                    la(ls[2])
                else:
                    ra(ls[2])
    s = ''.join(reversed(l))+s+''.join(r)
    if ten%2 ==1:
        s = s[::-1]
    print(s)
if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted