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

forward = [] 
backend = [] 
reverse = 0 

for i in range(Q):
    
        s = input()
        if s.count(" ") == 0:
            reverse += 1
        else:
            s2 = s.split(" ")
            if s2[1] == '1':
                if reverse % 2 == 0:
                    forward.append(s2[2])
                else:
                    backend.append(s2[2])
            else:
                if reverse % 2 == 0:
                    backend.append(s2[2])
                else:
                    forward.append(s2[2])


if reverse % 2 == 0:
    for i in forward[::-1]:
        print(i,end="")
    
    print(S,end="")

    for i in backend:
        print(i,end="")
else:
    for i in backend[::-1]:
        print(i,end="")
    
    print(S,end="")

    for i in forward:
        print(i,end="")

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

forward = []
backend = []
reverse = 0

for i in range(Q):
        s = input()
        s1 = list(s)

        if s1[0] == '1':
            reverse += 1
        else:
            if s1[2] == '1':
                if reverse % 2 == 0:
                    forward.append(s1[4])
                else:
                    backend.append(s1[4])
            else:
                if reverse % 2 == 0:
                    backend.append(s1[4])
                else:
                    forward.append(s1[4])

if reverse % 2 == 0:
    for i in forward[::-1]:
        print(i, end="")
    
    print(S,end="")

    for i in backend:
        print(i,end="")

    print()
else:
    for i in backend[::-1]:
        print(i,end="")
    
    for i in list(S)[::-1]:
        print(i,end="")

    for i in forward:
        print(i,end="")

    print()

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_reverse = 0
for i in range(q):
  query = input()
  
  if query[0] == '1':
    cnt_reverse += 1
  elif (query[2] == '1' and cnt_reverse % 2==0) or (query[2] == '1' and cnt_reverse % 2==1):
    s = query[4] + s
  else:
    s  = s + query[4]
if cnt_reverse%2==1:
  s = s[::-1]
print(s)

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

cnt_reverse = False
left = ''
for i in range(q):
  query = input()
  
  if query[0] == '1':
    cnt_reverse = not cnt_reverse
  elif (query[2] == '1' and not cnt_reverse) or (query[2] == '2' and cnt_reverse):
    left = left + query[4]

  else:
    s  = s + query[4]
s = left[::-1] + s
if cnt_reverse:
  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):
from sys import stdin
 
def main():
    S = list(stdin.readline().rstrip())
    Q = int(input())
    rev = 0
    head = []
    tail = []
 
    for _ in range(Q):
        q = stdin.readline()
        if q[0] == "1":
            rev = (rev+1)%2
        else:
            if q[2] == "1":
                if rev == 0:
                    head.append(q[4])
                else:
                    tail.append(q[4])
            else:
                if rev ==0:
                    tail.append(q[4])
                else:
                    head.append(q[4])
 
    if rev == 0:
        ans = "".join(head[::-1] + S + tail)
    else:
        ans = "".join(tail[::-1] + S[::-1] + head)
    
    print(ans)

s = input()
nq = int(input())
flg = 0
front = []
back = []
for i in range(nq):
    q = input()
    if len(q) == 1:
        #flg += 1
        flg = (flg+1)%2
    else:
        if flg == 0:
            if q[2] == '1':
                #front = [q[-1]] + front
                front.append(q[-1])
            else:
                #back = back + [q[-1]]
                back.append(q[-1])
        else:
            if q[2] == '1':
                #back = back + [q[-1]]
                back.append(q[-1])
            else:
                #front = [q[-1]] + front
                front.append(q[-1])
                
s = ''.join(front) + s + ''.join(back)
if flg % 2 == 1:
    s = s[::-1]
print(s)

s = input()
nq = int(input())
flg = 0
front = []
back = []
for i in range(nq):
    q = input()
    if len(q) == 1:
        #flg += 1
        flg = (flg+1)%2
    else:
        if flg == 0:
            if q[2] == '1':
                #front = [q[-1]] + front
                front.append(q[-1])
            else:
                #back = back + [q[-1]]
                back.append(q[-1])
        else:
            if q[2] == '1':
                #back = back + [q[-1]]
                back.append(q[-1])
            else:
                #front = [q[-1]] + front
                front.append(q[-1])
                

if flg % 2 == 1:
    s = ''.join(back)[::-1] + s[::-1] + ''.join(front)
else:
    s = ''.join(front)[::-1] + s + ''.join(back)
print(s)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Takahashi has a string S consisting of lowercase English letters.  Starting with this string, he will produce a new one in the procedure given as follows.  The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following:    * If T_i = 1: reverse the string S.    * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.      * If F_i = 1 : Add C_i to the beginning of the string S.     * If F_i = 2 : Add C_i to the end of the string S.  Help Takahashi by finding the final string that results from the procedure.

Submission attempts (in order):
from collections import deque

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

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

d = deque([S])

def changeVector(vector):
    if vector:
        return False
    return True

def addLeft(vector, char):
    if vector:
        d.appendleft(char)
        return d
    d.append(char)
    return d

def addRight(vector, char):
    if vector:
        d.append(char)
        return d
    d.appendleft(char)
    return d

vector = True
for q in qs:
    if q[0] == "1":
        vector = changeVector(vector)
    else:
        if q[1] == "1":
            d = addLeft(vector, q[2])
        else:
            d = addRight(vector, q[2])

d.reverse()

ans = ''.join(list(d))
print(ans)


from collections import deque

d = deque(input())
Q = int(input())

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

vector = True
for q in qs:
    if q[0] == "1":
        vector = not vector
    else:
        if q[1] == "1":
            if vector:
                d.appendleft(q[2])
            else:
                 d.append(q[2])
        else:
            if vector:
                d.append(q[2])
            else:
                 d.appendleft(q[2])

if not vector:
    d.reverse()

ans = ''.join(d)
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()
N = int(input())
S = []
for _ in range(N):
    S.append(input().split())

order = 1
for res in S:
    print(res)
    print(order)
    if res[0] == "1":
        order = order * - 1
    elif res[1] == "1":
        if order == 1:
            s = res[2]+s
        else:
            s = s+res[2]
    else:
        if order == 1:
            s = s+res[2]
        else:
            s = res[2]+s

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

from collections import deque
s = input().split()
sd = deque()
for i in s:
    sd.append(i)
N = int(input())
S = []
order = 1
for _ in range(N):
    res = input().split()
    if res[0] == "1":
        order = order * - 1
    elif res[1] == "1":
        if order == 1:
            sd.appendleft(res[2])
        else:
            sd.append(res[2])
    else:
        if order == 1:
            sd.append(res[2])
        else:
            sd.appendleft(res[2])

sd_str="".join(list(sd))
if order == -1:
    print(sd_str[::-1])
else:
    print(sd_str)

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
read = sys.stdin.read
readlines = sys.stdin.readlines
input = sys.stdin.readline
S = input()
input()
rev = 0
for line in readlines():
    q, *query, = line.split()
    if q == '1':
        rev ^= 1
    else:
        f, c = query
        if f == '1':
            if not rev:
                S = c+S
            else:
                S = S+c
        else:
            if not rev:
                S = S+c
            else:
                S = c+S

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


from collections import deque
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
input = sys.stdin.readline
S = list(input().rstrip())
S = deque(S)
input()
rev = 0
for line in readlines():
    q, *query, = line.split()
    if q == '1':
        rev ^= 1
    else:
        f, c = query
        if f == '1':
            if not rev:
                S.appendleft(c)
            else:
                S.append(c)
        else:
            if not rev:
                S.append(c)
            else:
                S.appendleft(c)

print(''.join(S) if not rev else ''.join(S)[::-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())
Switch = False
Query = []

import collections
dq = collections.deque(S)

for i in range(Q):
    s = input()
    if s[0] == '1':
        if Switch:
            Switch = False
        else:
            Switch = True
    if s[0] == '2':
        if s[2] == '1' and Switch==False:
            dq.appendleft(s[4])
#             S = s[4]+S
        elif s[2]=='1' and Switch==True:
            dq.append(s[4])
#             S = S+s[4]
        elif s[2] == '2' and Switch==False:
            dq.append(s[4])
#             S = S+s[4]
        else:
#             S = s[4]+S
            dq.appendleft(s[4])

if Switch == False:
    print('',join(dq))
else:
    print(''.join(dq)[::-1])

S = input()
Q = int(input())
Switch = False
Query = []

import collections
dq = collections.deque(S)

for i in range(Q):
    s = input()
    if s[0] == '1':
        if Switch:
            Switch = False
        else:
            Switch = True
    if s[0] == '2':
        if s[2] == '1' and Switch==False:
            dq.appendleft(s[4])
#             S = s[4]+S
        elif s[2]=='1' and Switch==True:
            dq.append(s[4])
#             S = S+s[4]
        elif s[2] == '2' and Switch==False:
            dq.append(s[4])
#             S = S+s[4]
        else:
#             S = s[4]+S
            dq.appendleft(s[4])

if Switch == False:
    print(''.join(dq))
else:
    print(''.join(dq)[::-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):
S = [input()]
q = int(input().strip())

for i in range(q):
  query = input()
  if query[0] == "1":
    S.reverse()
  elif query[0] == "2":
    query = query.strip().split(" ")
    if query[1] == "1":
      S.insert(query[2])
    else:
      S.append(query[2])

print("".join(S))

from collections import deque

S = deque(input())
q = int(input().strip())


rev_count = 0
for i in range(q):
  query = input()
  if query[0] == "1":
    rev_count += 1
  elif query[0] == "2":
    query = query.strip().split(" ")
    if rev_count & 1 == 1:
      if query[1] == "1":
        S.append(query[2])
      else:
        S.appendleft(query[2])
    else:
      if query[1] == "1":
        S.appendleft(query[2])
      else:
        S.append(query[2])

if rev_count & 1 == 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):
from collections import deque
S = deque([input()])

dic = 1
Q = int(input())
for i in range(0,Q):
    Query = input()
    if Query == '1':
        dic = 1*(-1)
    else:
        T, F, C = Query.split()
        if (F*dic == 2) or (F*dic == -1):
            S.append(C)
        else:
            S.appendleft(C)
print(''.join(list(S)[::dic]))

from collections import deque
S = deque([str for str in input()])
dic = 1
Q = int(input())
for i in range(0,Q):
    Query = input()
    if Query == '1':
        dic = dic*(-1)
    else:
        T, F, C = Query.split()
        if (int(F)*dic == 2) or (int(F)*dic == -1):
            S.append(C)
        else:
            S.appendleft(C)
print(''.join(list(S)[::dic]))

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():
    from collections import deque
    S=input()
    Q=int(input())
    A=[input().split() for _ in range(Q)]
    d=deque(S)
    for x in A:
        if x[0]=="1":
            d.reverse()
        else:
            if x[1]=="1":
                d.appendleft(x[2])
            else:
                d.append(x[2])

    print("".join(d))    

    print(-1)    
if __name__ == '__main__':
    main()



def main():
    from collections import deque
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    S=input()
    Q=int(input())
    A=[input().split() for _ in range(Q)]
    d=deque(S)
    
    d_left=d.appendleft
    d_right=d.append
    j=["1","2"]
    k=0
    j_re=j.reverse
    for x in A:
        if x[0]=="1":
            j_re()
            k+=1
        else:
            if x[1]==j[0]:
                d_left(x[2])
            else:
                d_right(x[2])
    if k%2==1:
        d.reverse()
    print("".join(d))    

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 = input()
    Q = int(input())
     
    # print(S, Q)
     
    queries = []
    for i in range(Q):
        query = input()
        queries.append(query)
     
    from collections import deque
    slist = deque()
	slist.append(S)
    for query in queries:
        if query == "1":
            isReversed = not isReversed
        else:
            t, f, c = query.split()
            if f == '1':
                if isReversed:
                    slist.append(c)
                else:
                    slist.appendleft(c)
            else:
                if isReversed:
                    slist.appendleft(c)
                else:
                    slist.append(c)
     
    if isReversed:
        slist.reverse()
    print("".join(slist))


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

# print(S, Q)

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

from collections import deque
slist = deque()
slist.append(S)
isReversed = False
for query in queries:
    if query == "1":
        isReversed = not isReversed
    else:
        t, f, c = query.split()
        if f=="1"
            if isReversed:
                slist.append(c)
            else:
                slist.appendleft(c)
        else:
            if isReversed:
                slist.appendleft(c)
            else:
                slist.append(c)
if isReversed:
    slist.reverse()

print("".join(slist))



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

# print(S, Q)

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

from collections import deque
slist = deque(list(S))
isReversed = False
for query in queries:
    if query == "1":
        isReversed = not isReversed
    else:
        t, f, c = query.split()
        if f == '1':
            if isReversed:
                slist.append(c)
            else:
                slist.appendleft(c)
        else:
            if isReversed:
                slist.appendleft(c)
            else:
                slist.append(c)

if isReversed:
    slist.reverse()
print("".join(slist))


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):
if __name__ == '__main__':
    d = input()
    n = int(input())
    for _ in range(n):
        q = input()
        d = d[::-1] if q[0] == ('1') else d = q[-1]+d if q[:3] == ("2 1") else d=d+q[-1]      
    print(d)

if __name__ == '__main__':
    d = input()
    n = int(input())
    qs = [input() for e in range(n)]
    s = []
    e = []
    r = False
    for q in qs:
        if q == '1':
            r = not(r)
        elif q.startswith("2 1"):
            e.append(q[-1]) if r else s.append(q[-1])
        else:
            s.append(q[-1]) if r else e.append(q[-1])
    print("".join(e[::-1]) + d[::-1] + "".join(s) if r else "".join(s[::-1]) + d + "".join(e))

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 = list(input().split() for _ in range(Q))

count = 0
L, R = "", ""

for i in range(Q):
  if Query[i][0] == "1": count += 1
  else:
    if Query[i][1] == "1":
      if count % 2 == 0: L = Query[i][2] + L
      else: R += Query[i][2]
    else:
      if count % 2 == 0: R += Query[i][2]
      else: L = Query[i][2] + L
  print(L + S + R)

if count % 2 == 0: print(L + S + R)
else: print(R[::-1] + S[::-1] + L[::-1])

from queue import deque
S = input()
Q = int(input())
Query = list(input().split() for _ in range(Q))

count = 0
L, R = deque(), deque()

for i in range(Q):
  if Query[i][0] == "1": count += 1
  else:
    if Query[i][1] == "1":
      if count % 2 == 0: L.appendleft(Query[i][2])
      else: R.append(Query[i][2])
    else:
      if count % 2 == 0: R.append(Query[i][2])
      else: L.appendleft(Query[i][2])
L, R = "".join(L), "".join(R)
if count % 2 == 0: print(L + S + R)
else: print(R[::-1] + S[::-1] + L[::-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():
    from collections import deque
    S = deque(input().split())
    Q = int(input())

    q_list = [input().split() for _ in range(Q)]

    flag = True
    for q in q_list:
        if len(q) == 1:
            t = q[0]
        else:
            t, f, c = q

        if t == '1':
            flag = not flag
        else:
            if (f == '1') ^ flag:
                S.appendleft(c)
            else:
                S.append(c)
        # print(q)
        # print("".join(S))
    print("".join(S))


if __name__ == '__main__':
    main()


def main():

    S = input().split()
    s = S
    Q = int(input())
    s_ind = 0

    q_list = [input().split() for _ in range(Q)]
    for q in q_list:
        if len(q) == 1:
            t = q[0]
        else:
            t, f, c = q

        if t == '1' or t == 1:
            front = S[:s_ind]
            end = S[s_ind+1:]
            s_ind = len(S)-s_ind
            end.append(s)
            end.extend(front)
            S = end
        else:
            if f == '1' or f == 1:
                S.insert(0, c)
                s_ind += 1
            else:
                S.append(c)

    print("".join(S))


if __name__ == '__main__':
    main()


def main():
    from collections import deque
    S = deque(input())
    Q = int(input())

    q_list = [input().split() for _ in range(Q)]

    flag = False
    for q in q_list:
        if len(q) == 1:
            t = q[0]
        else:
            t, f, c = q

        if t == '1':
            flag = not flag
        else:
            if (f == '1') ^ flag:
                S.appendleft(c)
            else:
                S.append(c)
    if flag:
        print("".join(S))


if __name__ == '__main__':
    main()


def main():
    from collections import deque
    S = deque(input())
    Q = int(input())

    q_list = [input().split() for _ in range(Q)]

    flag = False
    for q in q_list:
        if len(q) == 1:
            t = q[0]
        else:
            t, f, c = q

        if t == '1':
            flag = not flag
        else:
            if (f == '1') ^ flag:
                S.appendleft(c)
            else:
                S.append(c)
    if flag:
        S.reverse()
    print("".join(S))


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

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 = list(input())
print(S)
Q = int(input())

for _ in range(Q):
  q = list(input())
  if len(q) == 1:
    r = S[0]
    l = S[-1]
    S[0] = l
    S[-1] = r
  else:
    if q[2] == "1": S.insert(0, q[4])
    else: S.append(q[4])

print("".join(S)) 

from collections import deque
S = deque(input())
Q = int(input())
q = [input().split() for _ in range(Q)]
flag = True
for x in q:
    if x[0] == "1":
        if flag: flag = False
        else: flag = True
    else:
        if x[1] == "1":
            if flag: S.appendleft(x[2])
            else: S.append(x[2])
        else:
            if flag: S.append(x[2])
            else: S.appendleft(x[2])
s = list(S)
if not flag: s = s[::-1]
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):
s = input()
q = int(input())

flag_swap = False
for i in range(q):
  query = list(input().split())
  if query[0] == "1":
    flag_swap = not flag_swap
  else:
    if (query[1] == "1" and not flag_swap) or (query[1] == "2" and flag_swap):
      s = query[2] + s
    else:
      s += query[2]

idx = range(len(s))
if flag_swap:
  idx = reversed(idx)
for i in idx:
  print(s[i], end="")
  
      
      

s = input()
q = int(input())
left = ""
right = ""
flag_swap = False
for i in range(q):
  query = list(input().split())
  if query[0] == "1":
    flag_swap = not flag_swap
  else:
    if (query[1] == "1" and not flag_swap) or (query[1] == "2" and flag_swap):
      left += query[2]
    else:
      right += query[2]

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

Verdicts: Time Limit Exceeded

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())
query = [0 for _ in range(q)]
w = True
for i in range(q):
    query[i] = list(map(str,input().split()))
for i in range(q):
    if(query[i][0] == "1"):
        w = not(w)
    else:
        mem = query[i][2]
        if(query[i][1] == "1"):
            if(w):
                s = s + mem
            else:
                s = mem + s
        else:
            if(w):
                s = mem + s
            else:
                s = s + mem
print(s)

from collections import deque
s = str(input())
q = int(input())
s = deque(s)
query = []
w = True
for i in range(q):
    query = list(map(str,input().split()))
    if(query[0] == "1"):
        w = not(w)
    else:
        mem = query[2]
        if(query[1] == "1"):
            if(w):
                s.appendleft(mem)
            else:
                s.append(mem)
        else:
            if(w):
                s.append(mem)
            else:
                s.appendleft(mem)
if(w):
    print("".join(s))
else:
    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):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = input()
    Q = int(input())

    reverse = False
    header = []
    footer = []
    for _ in range(Q):
        query = input()
        if query[0] == '1':
            reverse = not reverse
        else:
            _, f, c = query.split()
            if reverse:
                if f == '1':
                    footer = [c] + footer
                else:
                    header.append(c)
            else:
                if f == '1':
                    header.append(c)
                else:
                    footer = [c] + footer
    if reverse:
        print("".join(footer + list(S)[::-1] + header))
    else:
        print("".join(header) + S + "".join(footer))

if __name__ == '__main__':
    main()

import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = input()
    Q = int(input())

    reverse = False
    header = [''] * Q
    footer = [''] * Q
    for i in range(Q):
        query = input()
        if query[0] == '1':
            reverse = not reverse
        else:
            _, f, c = query.split()
            isHead = f == '1'
            if reverse:
                isHead = not isHead
            if isHead:
                header[i] = c
            else:
                footer[i] = c

    if reverse:
        print("".join(footer[::-1] + list(S)[::-1] + header))
    else:
        print("".join(header[::-1]) + S + "".join(footer))

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())
n = int(input())
import numpy as np

s = np.array(s)

L = []
for i in range(n):
    flag = False
    L = (list(map(str,input())))
    #print(L)
    if len(L) >1:
        if int(L[2]) == 1:
            if flag:
                s = np.append(s,L[4])
            else:
                s = np.append(L[4],s)
        elif int(L[2]) == 2:
            if flag:
                s = np.append(L[4],s)
            else:
                s = np.append(s,L[4])
    
    elif len(L) ==1:
        flag = True
if flag:
    s = s[::-1]
print("".join(s))

rom collections import deque
s = input()
n = int(input())
s = deque(s)
cnt = 0
def ap(s,a,b):
    if flag ==True:
        if a == "1":
            s.appendleft(b)
        elif a == "2":
            s.append(b)
    if flag == False:
        if a == "1": 
            s.append(b)
        elif a == "2":
            s.appendleft(b)
flag = True
for i in range(n):
    L = list(input())
    if L[0] == "1":
        flag = False
        cnt +=1
    elif L[0] == "2":
        ap(s,L[2],L[4])
        flag = True
#print(flag,cnt,s)
if cnt %2 == 1:
    s.reverse()
print("".join(s))

s = list(input())
n = int(input())
import numpy as np

s = np.array(s)

L = []
for i in range(n):
    L = (list(map(str,input())))
    #print(L)
    if len(L) >1:
        if int(L[2]) == 1:
            #print(s)
            s = np.append(L[4],s)
        elif int(L[2]) == 2:
            s = np.append(s,L[4])
    
    elif len(L) ==1:
        s = np.rot90(s, 2)
        
print("".join(s))

from collections import deque
s = input()
s = deque(s)
n = int(input())
cnt = False
for i in range(n):
  L = input()
  if len(L) == 1:
    cnt  ^=1 
  else:
    a,b,c = L.split()
    if cnt:
      if b == "1":
        s.append(c)
      else:
        s.appendleft(c)
    else:
      if b == "1":
        s.appendleft(c)
      else:
        s.append(c)
if cnt:
    s = reversed(s)
    print("".join(s))
else:
    print("".join(s))

Verdicts: Wrong Answer

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())
que = [0] * q
t = []
f = []
c = []
for i in range(q):
    que[i] = list(map(str,input().split()))
    if(len(que[i])==3):
        t.append(que[i][0])
        f.append(que[i][1])
        c.append(que[i][2])
    else:
        t.append(que[i][0])
count = 0
for i in range(q):
    if t[i] == '1':
        s = s[::-1]
        print(t[i-1])
    else:
        if f[count] == '1':
            s = c[count] + s
            count += 1
        else:
            s += c[count]
            count += 1
print(s)

from collections import deque
s = input()
sque = deque(s)
q = int(input())
que = [0] * q
flg = False
for i in range(q):
    que[i] = (list(map(str,input().split())))
    if(len(que[i])==3):
        if que[i][1] == '1':
            if flg:
                sque.append(que[i][2])
            else:
                sque.appendleft(que[i][2])
        else:
            if flg:
                sque.appendleft(que[i][2])
            else:
                sque.append(que[i][2])
    else:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    sque.reverse()
    print("".join(list(sque)))
else:
    print("".join(list(sque)))

Verdicts: Wrong Answer

Accepted
Problem: Takahashi has a string S consisting of lowercase English letters.  Starting with this string, he will produce a new one in the procedure given as follows.  The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following:    * If T_i = 1: reverse the string S.    * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.      * If F_i = 1 : Add C_i to the beginning of the string S.     * If F_i = 2 : Add C_i to the end of the string S.  Help Takahashi by finding the final string that results from the procedure.

Submission attempts (in order):
# -*- coding: utf-8 -*-
from collenctions import deque

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

querys = []
op1_cnt = 0
op2_cnt = 0
prefix = deque()
suffix = deque()
for i in range(Q):
    query = input()
    if len(query) == 1:
        op1_cnt += 1

        if op2_cnt != 0:
            prefix.extend(S)
            prefix.extend(suffix)
            S = ''.join(prefix)
            prefix.clear()
            suffix.clear()
            op2_cnt = 0

    else:
        op2_cnt += 1

        if op1_cnt % 2 != 0:
            S = S[::-1]

        op1_cnt = 0

        t, F, C = query.split()
        if F == "1":
            prefix.appendleft(C)
        else:
            suffix.append(C)

if op1_cnt % 2 != 0:
    S = S[::-1]

if op2_cnt != 0:
    prefix.extend(S)
    prefix.extend(suffix)
    S = ''.join(prefix)


print(S)


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

reverse = 0
head = []
tail = []
for i in range(Q):
    query = input()
    if len(query) == 1:
        reverse = (reverse + 1) % 2

    else:
        t, F, C = query.split()
        if reverse == 0:
            if F == "1":
                head.append(C)
            else:
                tail.append(C)
        else:
            if F == "1":
                tail.append(C)
            else:
                head.append(C)

if reverse == 0:
    S = ''.join(head[::-1] + list(S) + tail)
else:
    S = ''.join(tail[::-1] + list(S[::-1]) + head)


print(S)


Verdicts: Runtime Error

Accepted
Problem: Takahashi has a string S consisting of lowercase English letters.  Starting with this string, he will produce a new one in the procedure given as follows.  The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following:    * If T_i = 1: reverse the string S.    * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.      * If F_i = 1 : Add C_i to the beginning of the string S.     * If F_i = 2 : Add C_i to the end of the string S.  Help Takahashi by finding the final string that results from the procedure.

Submission attempts (in order):
S=input()
Q=int(input())
l=list(input().split() for i in range(Q))
for j in l:
  if j[0]=="1":
    S=S[::-1]
  else:
    if j[1]=="1":
      S=S+j[2]
    else:
      S=j[2]+S

print(S)
      

from collections import deque
S=deque(list(input()))
Q=int(input())
l=list(input().split() for i in range(Q))
a=0
for j in l:
  if j[0]=="1":
      a+=1
  else:
    if j[1]=="1":
        if a %2==0:
            S.appendleft(j[2])
        else:
            S.append(j[2])
    else:
        if a %2==1:
            S.appendleft(j[2])
        else:
            S.append(j[2])
        
if a%2==0:
    print("".join(S))
else:
    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 solve2(s):
    ans = 0
    for i, c in enumerate(s): 
        if c in '02468':
            ans += i + 1 
                        
                        
                        
    return ans


def solve5(s): 
    ans = 0
    for i, c in enumerate(s):
        if c in '05':
            ans += i + 1
    return ans


def solve_other(s, p):
    ans = 0
    last_mod=0
    mods = [0]*p
    mods[0] = 1 
    digit = 1
    for i in range(n-1,-1,-1): 
        last_mod = (last_mod + int(s[i])*digit)%p 
        ans += mods[last_mod] 
        mods[last_mod] += 1 
        digit *=10 
    return ans


n, p = list(map(int, input().split()))
s = input()
if p == 2:
    print(solve2(s))
elif p == 5:
    print(solve5(s))
else:
    print(solve_other(s, p))

from collections import deque
s=deque(list(input()))
q=int(input())
direction=0 

for i in range(q):
    query=input()
    if query[0]=='1':
        direction=direction^1
    elif query[0]=='2':
        i,f,c=query.split()
        if f=='1' and direction==0:
            s.appendleft(c)
        elif f=='1' and direction==1:
            s.append(c)
        elif f=='2' and direction==0:
            s.append(c)
        elif f=='2' and direction==1:
            s.appendleft(c)


if direction==0:
    print(''.join(s))
else:
    s=''.join(s)
    s=s[::-1]
    print(s)


Verdicts: Runtime Error

Accepted
Problem: Takahashi has a string S consisting of lowercase English letters.  Starting with this string, he will produce a new one in the procedure given as follows.  The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following:    * If T_i = 1: reverse the string S.    * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.      * If F_i = 1 : Add C_i to the beginning of the string S.     * If F_i = 2 : Add C_i to the end of the string S.  Help Takahashi by finding the final string that results from the procedure.

Submission attempts (in order):
S = input()
Q = int(input())
reverse = False
front = ""
end = ""

for i in range(Q):
    inp = input()
    if inp[0] == "1":
        reverse = ~reverse
    else:
        _, F, C = inp.split()
        if (F == "1" and reverse == False) or (F == "2" and reverse == True):
            front = front+C
        else:
            end = end+C

if reverse:
    print(end[::-1]+S[::-1]+front)
else:
    print(front[::-1]+S+end)


    S = input()
    Q = int(input())
    reverse = False
    front = ""
    end = S
     
    for i in range(Q):
        inp = input()
        if inp[0] == "1":
            reverse = ~reverse
        else:
            _, F, C = inp.split()
            if (F == "1") ^ reverse:
                front =front+C
            else:
                end = end+C
     
     
    if reverse:
        print(end[::-1]+front)
    else:
        print(front[::-1]+end)

S = input()
Q = int(input())
reverse = False
front = ""
end = ""

for i in range(Q):
    print(end[::-1]+S[::-1]+front)
    inp = input()
    if inp[0] == "1":
        reverse = ~reverse
    else:
        _, F, C = inp.split()
        if (F == "1" and reverse == False) or (F == "2" and reverse == True):
            front = front+C
        else:
            end = end+C

if reverse:
    print(end[::-1]+S[::-1]+front)
else:
    print(front[::-1]+S+end)


S = input()
Q = int(input())
reverse = False
front = ""
end = ""
 
for i in range(Q):
    inp = input()
    if inp[0] == "1":
        reverse = not reverse
    else:
        _, F, C = inp.split()
        if (F == "1") ^ reverse:
            front = front+C
        else:
            end = end+C
 
if reverse:
    print(end[::-1]+S[::-1]+front)
else:
    print(front[::-1]+S+end)

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Accepted