Problem:


Score : 400 points

Problem Statement

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.

Constraints

1 \leq |S| \leq 10^5

S consists of lowercase English letters.

1 \leq Q \leq 2 \times 10^5

T_i = 1 or 2.

F_i = 1 or 2, if provided.

C_i is a lowercase English letter, if provided.

Input

Input is given from Standard Input in the following format:

S
Q
Query_1
:
Query_Q

In the 3-rd through the (Q+2)-th lines, Query_i is one of the following:

1

which means T_i = 1, and:

2 F_i C_i

which means T_i = 2.

Output

Print the resulting string.

Sample Input 1

a
4
2 1 p
1
2 2 c
1

Sample Output 1

cpa

There will be Q = 4 operations. Initially, S is a.

Operation 1: Add p at the beginning of S. S becomes pa.

Operation 2: Reverse S. S becomes ap.

Operation 3: Add c at the end of S. S becomes apc.

Operation 4: Reverse S. S becomes cpa.

Thus, the resulting string is cpa.

Sample Input 2

a
6
2 2 a
2 1 b
1
2 2 c
1
1

Sample Output 2

aabc

There will be Q = 6 operations. Initially, S is a.

Operation 1: S becomes aa.

Operation 2: S becomes baa.

Operation 3: S becomes aab.

Operation 4: S becomes aabc.

Operation 5: S becomes cbaa.

Operation 6: S becomes aabc.

Thus, the resulting string is aabc.

Sample Input 3

y
1
2 1 x

Sample Output 3

xy



Sample input:
a
4
2 1 p
1
2 2 c
1


Sample output:
cpa

Submission status: Wrong Answer

Solution code:
S = str(input())
Q = int(input())

topFlg = True

for _ in range(Q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        topFlg = not (topFlg)
    else:
        if query[1] == "1":
            S = query[2] + S if topFlg else S + query[2]
        else:
            S = S + query[2] if topFlg else query[2] + S

# if not topFlg:
#     S = S[::-1]

print(S)

Submission status: Wrong Answer

Solution code:
s = input()
#sc = s[::-1]
n = int(input())
l = [list(input().split()) for i in range(n)]

for i in range(n):
    if l[i][0] == '1':
        save = s
        #s = sc
        #sc = save
    elif l[i][1] == '1':
        s = l[i][2] + s
        #sc += l[i][2]
    else:
        s += l[i][2]
        #sc = l[i][2] + sc

print(s)

Submission status: Wrong Answer

Solution code:
s = list(input())
qn = int(input())
q = []
rev = False

for i in range(qn):
    qi = input().split()
    if i == 0:
        ordqi = (-1, -1, -1)
    else:
        ordqi = q[-1]
    if len(qi) == 1:
        rev = not rev
    else:
        if rev:
            qi[1] = str((not (int(qi[1])-1)) + 1)
        if ordqi[0] == 2:
            if int(ordqi[1]) == int(qi[1]):
                q.pop()
                qi[2] += ordqi[2]
        q.append((int(qi[0]), int(qi[1]), qi[2]))
for i in range(len(q)):
    if q[i][1] == 1:
        s = [q[i][2]] + s
    else:
        s.append(q[i][2])
if rev:
    print("".join(s)[::-1])
else:
    print("".join(s))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
ARR = []
TOTAL1 = 0

import sys
sys.setrecursionlimit(20000000)

for i in range(Q):
    arr = input().split(" ")

    if int(arr[0]) == 1:
        TOTAL1 = TOTAL1 + 1
    ARR.append(arr)

def calculate(s,q,arr,total1):

    current1Sums = 0

    for ar in arr:
        if int(ar[0]) == 1:
            current1Sums = current1Sums + 1

        if int(ar[0]) == 2:
            nokoru1Sums = total1 - current1Sums

            if int(ar[1]) == 1:
                if nokoru1Sums % 2 == 0:
                    s = ar[2] + s
                else:
                    s = s + ar[2]
            else:
                if nokoru1Sums % 2 == 0:
                    s = s + ar[2]
                else:
                    s = ar[2] + s

    print(s)



calculate(S,Q,ARR,TOTAL1)

Submission status: Wrong Answer

Solution code:
S = list(input())
Q = int(input())
L = [input().split() for _ in range(Q)]

def syori(item):
    global S
    if item[0] == '1':
        S.reverse()
    else:
        # Ti = 2 の時
        if item[1] == '1':
            S = [item[2]] + S
        else:
            S = S + [item[2]]

# L を圧縮しないとTimeOverになる

# ['1'] ['1'] は元に戻るので、削除
a = []
for i in range(len(L)-1):
    if (L[i][0] == '1') and (L[i+1][0] == '1'):
        a = a + [i]
# print(a)
a.reverse()
for i in a:
    L.pop(i+1)
    L.pop(i)

#['1'] ,['2', '1', 'b'], ['1']　等のパターンは['2', '2', 'b'] と同じ
count = 0
for i in range(len(L)-3,-1,-1):
    
    if count > 0:
        # i のカウンタを２回すすめる（エラー回避）
        count -= 1
        continue

    if (L[i][0] == '1') and (L[i+1][0] == '2') and (L[i+2][0] == '1'):
        count = 2
        if L[i+1][1] == '1':
            L[i+1][1] = '2'
        else:
            L[i+1][1] = '1'
        L.pop(i+2)
        L.pop(i)


for item in L:
    syori(item)
# print(L)
print(''.join(S))

Submission status: Wrong Answer

Solution code:
import numpy as np 

S = str(input())

Q = int(input())

q = np.ones(Q,dtype = object)


flag=0
for i in range(Q):
    q[i] = [i for i in input().split()]

for i in range(Q):
    if q[i][0] == '1':
        flag+=1
    else:
        
        if q[i][1] == '1':
            if flag%2==0:
                S = S+str(q[i][2])
            else:
                S = str(q[i][2])+S
        elif q[i][1] == '2':
            if flag%2==1:
                S = S+str(q[i][2])
            else:
                S = str(q[i][2])+S
if flag%2==1:
    pass
else:
    S=S[::-1]
                
print(S)

Submission status: Wrong Answer

Solution code:
ans = input()
q = int(input())

for i in range(q):
    nyuryoku = input().split()
    if nyuryoku[0] == '2':
        if nyuryoku[1] == '1':
            ans = nyuryoku[2] + ans
        else:
            ans += nyuryoku[2]
    else:
        sento = ans[0]
        matsubi = ans[len(ans)-1]
        ans = ans[1:]
        ans = ans[0:len(ans)-1]
        ans = matsubi + ans + sento
        
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
Q = int(input())

for i in range(Q):
    command = list(input().split())
    if command[0] == "1":
        S[0], S[-1] = S[-1], S[0]
    elif command[0] == "2":
        if command[1] == "1":
            S.insert(0, command[2])
        elif command[1] == "2":
            S.append(command[2])
    #print(i+1, S)
print("".join(S))

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():
    S = list(stdin.readline().rstrip())
    Q = int(input())
    rev = 0
    forward = []
    backward = []

    for _ in range(Q):
        q = stdin.readline()
        if q[0] == "1":
            rev = (rev+1)%2
        else:
            if q[2] == "1":
                if rev == 0:
                    forward.append(q[4])
                else:
                    backward.append(q[4])
            else:
                if rev ==0:
                    backward.append(q[4])
                else:
                    forward.append(q[4])

    if rev == 0:
        ans = "".join(forward[::-1] + S + backward)
    else:
        ans = "".join(backward[::-1] + S + forward)
    
    print(ans)
    """
    S = stdin.readline().rstrip() 
    Q = int(input())
    rev = 0
    for _ in range(Q):
        q = stdin.readline()

        if q[0] == "1":
            rev = (rev+1)%2
        else:
            if q[2] == "1":
                if rev == 0:
                    S = "{}{}".format(q[4], S)
                else:
                    S = "{}{}".format(S, q[4])
            else:
                if rev ==0:
                    S = "{}{}".format(S, q[4])
                else:
                    S = "{}{}".format(q[4], S)
    if rev == 1:
        print(S[::-1])
    else:
        print(S)
    """
main()

Submission status: Wrong Answer

Solution code:

#import numpy as np
s = input()
n = int(input())
#qt = np.ones((n),dtype=np.int32)
#qf = np.zeros((n),dtype=np.int64)
#qc = [''] * n

mode = False
#mode = True : f1->s=c+s,f2->s=s+c
#mode = False : f1->s=s+c,f2->s=c+s

front = ''
back = ''
for i in range(n):
    qs = input()
    if len(qs) == 1:
        mode = not mode
        #s = s[::-1]
        #pass
    else:
        #qt[i] = 2
        #qf[i] = int(qs[1:-2])
        #qc[i] = qs[-1]
        if mode:
            if int(qs[2]) == 1:
                front += qs[4]
                #s = qs[4] + s
            else:
                back += qs[4]
                #s = s + qs[4]
        else:
            if int(qs[2]) == 1:
                back += qs[4]
                #s = s + qs[4]
            else:
                front += qs[4]
                #s = qs[4] + s
        
#print(mode,front,back)
if mode:
    print(front + s[::-1] + back)
else:
    print(back[::-1] + s + front)

#s = front + s + back[::-1]

#for i in range(n):
#    print(qt[i],qf[i],qc[i])

#print(s)

Submission status: Wrong Answer

Solution code:

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

tmplist = []
T = 0
for i in range(Q):
    Quary = list(input().split())
    if len(Quary) == 1:
        T = T+1
    else:
        if T%2 == 0:
            if Quary[1] == 1:
                S.insert(0,Quary[2])
            else:
                S.append(Quary[2])
        else:
            if Quary[1] == 2:
                S.insert(0,Quary[2])
            else:
                S.append(Quary[2])

if T%2 == 0:
    S.reverse()

print(''.join(S))

Submission status: Wrong Answer

Solution code:
letter = [input()]
Q= int(input())

reversed = False
for i in range(Q):
    query = input().split()
    if len(query)==1:
        reversed = not bool(reversed)
    else:
        if int(query[1])==1: #まえに追加
            if reversed == False:
                letter.insert(0,query[2])
            else:
                letter.append(query[2])
        else:
            if reversed == False:
                letter.append(query[2])
            else:
                letter.insert(0,query[2])
if reversed==True:
    letter.reverse()
print(''.join(letter))

Submission status: Wrong Answer

Solution code:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

S= one_str()

Q = one_int()

Qs = [ input() for i in range(Q)]
def ss(S, Qs):
    is_not_ac=False
    head = ""
    tail = ""
    for temp in Qs:
#         temp = input()
        if len(temp)>=2:
            T, F, C = temp.split()
            if F=="1":
                if is_not_ac:
                    tail += C
                else:
                    head += C
            else:
                if is_not_ac:
                    head += C
                else:
                    tail += C
        else:        
            is_not_ac = not is_not_ac
    if is_not_ac:
        return tail[::-1] + S + head
    else:
        return head[::-1] + S + tail


print(ss(S,Qs))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
Query = [input() for i in range(Q)]
inf_string = [""] * Q
inf_numbers = [0] * Q
#反転回数のトータルを記録
total_numbers = 0
# 0->先頭, 1->末尾
#inf_first_position = [0] * Q
index = 0

for i in range(Q-1,-1,-1):
    # Ti = 1の時 反転する
    if len(Query[i]) == 1:
        total_numbers += 1
    else:
        # 先頭に追加
        if Query[i][2] == "1":
            inf_string[index] = Query[i][4]
            inf_numbers[index] = total_numbers
        # 末尾に追加
        else:
            inf_string[index] = Query[i][4]
            inf_numbers[index] = total_numbers + 1
        index += 1

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

for i in range(index-1,-1,-1):
    if inf_numbers[i] % 2 == 0:
        S = inf_string[i] + S
    else:
        S = S + inf_string[i]
print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = deque()
s.append(input())
q = int(input())

reverse_status = False

for i in range(q):
  query = list(map(format, input().split()))
  if int(query[0]) == 1:
    if reverse_status:
      reverse_status = False
    else:
      reverse_status = True
  else:
    if int(query[1]) == 1:
      if reverse_status:
        s.append(query[2])
      else:
        s.appendleft(query[2])
    else:
      if reverse_status:
        s.appendleft(query[2])
      else:
        s.append(query[2])

if reverse_status:
  print(''.join(reversed(s)))
else:
  print(''.join(s))

Submission status: Wrong Answer

Solution code:
import sys
S = input()
Q = int(input())
r = False
for l in sys.stdin:
  TFC = l.split()
  if TFC[0]=="1": r = not r
  elif TFC[1]=="1": S = S+TFC[2] if r else TFC[2]+S
  elif TFC[1]=="2": S = TFC[2]+S if r else S+TFC[2]
print(reversed(S) if r else S)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

input = sys.stdin.readline

s = list(input())

n = int(input())

for ii in range(n):
    q = input()
#     print("".join(s))
    if q[0] == "1":
        s = s[::-1]
    else:
        t, f, c = q.split()
        if f == "1":
            s.insert(0, c)
        else:
            s.append(c)
print("".join(s))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
Query = [input().split() for i in range(Q)]
cnt = 0
rev_cnt = []
for q in Query:
    if q[0] == '1':
        cnt += 1
    rev_cnt.append(cnt)


if rev_cnt[-1] % 2 == 0:
    ans = S
else:
    ans = S[::-1]

i = 0
for q in Query:
    if q[0] == '1':
        continue

    if (rev_cnt[-1] - rev_cnt[i]) % 2 == 0:
        tmp = q[2]
        if q[1] == '1':
            ans = tmp + ans
        else:
            ans = ans + tmp
    else:
        tmp = q[2][::-1]
        if q[1] == '1':
            ans = ans + tmp
        else:
            ans = tmp + ans

    i += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
Que = [list(map(str,input().split())) for i in range(Q)]

from collections import deque

S = list(S)
S = deque(S)
count = 0

for i in range(Q):
    if Que[i][0] == '1':
        count += 1
    elif Que[i][0] == '2':
        if Que[i][1] == '1':
            S.append(Que[i][2])
        elif Que[i][1] == '2':
            S.append(Que[i][2])
            

if count%2 != 0:
    print("".join(S))
else:
    S.reverse()
    print("".join(S))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

d = deque(['S'])

#d = ['S']

rev = 0

for i in range(q):
    if query[i][0] == '2':
        if query[i][1] == '1':
            d.appendleft(query[i][2])
        else:
            d.append(query[i][2])
    else:
        d.reverse()
        rev += 1

ans = deque()
"""
if rev % 2 == 1:
    s = ''.join(list(reversed(s)))
"""
while len(d):
    tmp = d.popleft()
    if tmp == 'S':
        ans.append(s)
    else:
        ans.append(tmp)

print(*ans,sep='')

Submission status: Wrong Answer

Solution code:
s = input()
try:
    while True:
        query = input()
        if len(query) == 1:
            s = s[::-1]
            continue

        s = query[-1] + s if query[2] == "1" else s + query[-1]
except:
    pass
print(s)

Submission status: Wrong Answer

Solution code:
S = input().split()
Q = int(input())
for q in range(1, Q + 1):
    inp = input().split(" ")
    if (int(inp[0]) == 1):
        S = S[::-1]
    else:
        if (int(inp[1]) == 1):
            S.insert(0, inp[2])
        elif (int(inp[1]) == 2):
            S.append(inp[2])
ans = "".join(S)
print(ans)

Submission status: Wrong Answer

Solution code:

#import numpy as np
s = input()
n = int(input())
#qt = np.ones((n),dtype=np.int32)
#qf = np.zeros((n),dtype=np.int64)
#qc = [''] * n

mode = False
#mode = True : f1->s=c+s,f2->s=s+c
#mode = False : f1->s=s+c,f2->s=c+s

front = ''
back = ''
for i in range(n):
    qs = input()
    if len(qs) == 1:
        mode = not mode
        #s = s[::-1]
        #pass
    else:
        #qt[i] = 2
        #qf[i] = int(qs[1:-2])
        #qc[i] = qs[-1]
        if mode:
            if int(qs[2]) == 1:
                front += qs[4]
                #s = qs[4] + s
            else:
                back += qs[4]
                #s = s + qs[4]
        else:
            if int(qs[2]) == 1:
                back += qs[4]
                #s = s + qs[4]
            else:
                front += qs[4]
                #s = qs[4] + s
        
#print(mode,front,back)
if mode:
    print(front + s + back)
else:
    print(back[::-1] + s[::-1] + front)

#s = front + s + back[::-1]

#for i in range(n):
#    print(qt[i],qf[i],qc[i])

#print(s)

Submission status: Wrong Answer

Solution code:
S = input() 
Q = int(input())
rlist, llist = [], []
flag, cnt = 0, 0

def trans(f):
    if f == 1:
        f = 0
    elif f == 0:
        f = 1
    return f

for i in range(Q):
    lists = input().split()
    if lists[0] == "1":
        flag = trans(flag)
    else:
        if lists[1] == "2":
            rlist.append(lists[2])
        else:
            llist.append(lists[2])
print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque
s=deque(list(input().split()))
ans=""
q=int(input())

for i in range(q):
  ques=list(input().split())
  if ques[0]=="1":
    s.reverse()
    #print("1",s)
  else:
    if ques[1]=="1":
      s.appendleft(ques[2])
      #print("2",s)
    else:
      s.append(ques[2])
      #print("22",s)
for i in s:
  ans+=i
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline
S = input()
Q = int(input())
s = [S[0]]
A = []
count = 0
for i in range(Q):
  A += [input().split()]
for i in range(Q):
  if int(A[i][0]) == 2:
    if count % 2 == 1:
      s = s[::-1]
    count = 0
    if int(A[i][1]) == 1:
      s = [A[i][2]] + s
    else:
      s = s + [A[i][2]]
  else:
    count += 1
    if i == Q-1:
      if count % 2 == 1:
        s = s[::-1]
 
 
result = ''.join(s)
print(result)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())

qlist = [input() for _ in range(Q)]
tmp = 0
qslist = []
for q in qlist:
    if q == '1':
        tmp += 1
    else:
        t, f, c = q.split()
        if tmp != 0:
            qslist.append(str(tmp))
            tmp = 0
        qslist.append(f+c)
if tmp != 0:
    qslist.append(str(tmp))
plist = []
alist = []
rsum = 0
rflag = False
for q in qslist[::-1]:    
    if len(q) == 2:
        if not rflag:
            if q.startswith('1'):
                plist.append(q[1])
            else:
                alist.append(q[1])
        else:
            if q.startswith('1'):
                alist.append(q[1])
            else:
                plist.append(q[1])
    else:
        rsum += int(q)
        rflag = rsum % 2 != 0
if rflag:
    S = S[::-1]
print("".join(plist)+S+"".join(alist[::-1]))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())

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

for i in range(Q):                
  if len(Q_list[i]) == 1:
    if len(S) >= 2:
      S_list = list(S)
      S_list[0], S_list[-1] = S_list[-1], S_list[0]
      S = "".join(S_list)
  
  else:
    F = Q_list[i][1]
    C = Q_list[i][2]
    
    if int(F) == 1:
      S = C + S
    else:
      S = S + C
      
print(S)

Submission status: Wrong Answer

Solution code:
word = input()
words = [word]
number = int(input())
for i in range(number):
    a = input().split(" ")
    if a[0] == "1":
        words[0], words[-1] = words[-1], words[0]
    else:
        if a[1] == "1":
            words.insert(0, a[2])
        else:
            words.append(a[2])
for j in words:
    print(j,end="")

Submission status: Wrong Answer

Solution code:
def rev_f(string , i):
    if i[2] == '2':
        string = string + i[4]

    if i[2] == '1':
        string = i[4] + string
    return string



def rev_s(string , i):
    if i[2] == '1':
        string = string + i[4]

    if i[2] == '2':
        string = i[4] + string
    return string




string = input()
num = int(input())
q_list = []
reverse_num = 0
reverse = True
reverese_s = False
for i in range(num):
    a = input()
    if len(a) == 1:
        reverse_num += 1
    q_list.append(a)
    
if reverse_num %2 == 0:
    reverse = False
    
if reverse == False:    
    
    for i in q_list:
        if i == '1':
            if reverese_s:
                reverese_s = False
            else:
                reverese_s = True
        else:
            if reverese_s == False:
                string = rev_f(string,i)

            if reverese_s ==True:
                string = rev_s(string,i)
        
    
if reverse == True:    
    
    
    for i in q_list:
        if i == '1':
            if reverese_s:
                reverese_s = False
            else:
                reverese_s = True
        else:
            if reverese_s == False:
                string = rev_s(string,i)

            if reverese_s ==True:
                string = rev_f(string,i)

print(string)

Submission status: Wrong Answer

Solution code:
s = str(input())
n = int(input())
num = [str(input()).split() for _ in range(n)]

count=0
ans = s
for i in num:
    if int(i[0]) == 1:
        ans=ans[count+1:]+s+ans[:count]
        count=len(ans[count:])-1

    else:
        if int(i[1]) == 1:
            count=+1
            ans=i[2]+ans
        else:
            ans+=i[2]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque(input())
Q = int(input())
sousa = []
for i in range(Q):
  sousa.append(input().split())

for j in range(Q):
  rev = 0
  if sousa[j][0] == '1':
    rev += 1
  else:
    if rev%2 == 1:
      S.reverse()
    if sousa[j][1] == '1':
      S.appendleft(sousa[j][2])
    else:
      S.append(sousa[j][2])
Ans = ''.join(list(S))
print(Ans)

Submission status: Wrong Answer

Solution code:
import math

s = input()
q = int(input())
reverse_flag = 0

for i in range(q):
  query = input().split(" ")
  if(len(query) == 1):
    reverse_flag += 1
  else:
    if((reverse_flag + int(query[1]) % 2 == 0)):
      s = s + query[2]
    else:
      s = query[2] + s

if(reverse_flag % 2 == 1): print(s[::-1])
else: print(s)

Submission status: Wrong Answer

Solution code:
S=[]
a=input()
S.append(a)
Q=int(input())
s=0
for i in range(Q):
    q=list(input().split())
    if int(q[0])==1:
        if s==0:
            s=1
        else:
            s=0
    else:
        T=int(q[1])
        if s==0:
            if T==2:
                S.append(q[2])
            else:
                S.insert(0,q[2])
        else:
            if T==1:
                S.append(q[2])
            else:
                S.insert(0,q[2])
if s==1:
    S.reverse()
S="".join(S)
print(S)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
from collections import deque

def solve():
    d = deque(list(input().split()))
    Q = int(input())

    is_reverse = False # 反転中か？

    for _ in range(Q):
        query = input()
        if query == "1":
            is_reverse = not is_reverse
        else:
            t, f, c = query.split()
            if f == "1":
                if is_reverse:
                    # 末尾にcを追加
                    d.append(c)
                else:
                    # 先頭にcを追加
                    d.appendleft(c)
            else:
                if is_reverse:
                    # 先頭に追加
                    d.appendleft(c)
                else:
                    # 末尾に追加
                    d.append(c)

    if is_reverse:
        d.reverse()
        for moji in d:
            print(moji, end="")
    else:
        for moji in d:
            print(moji, end="")
    print()


def solve2():
    S = list(input().split())
    Q = int(input())
    M = 2*10**5+10
    data = [None]*M
    data.extend(S)
    data.extend([None]*M)
    left, right = M-1, M+len(S)

    is_reverse = False

    for _ in range(Q):
        query = input()
        if query == "1":
            is_reverse = not is_reverse
        else:
            t, f, c = query.split()
            if f == "1":
                if is_reverse:
                    # 末尾にcを追加
                    data[right] = c
                    right += 1
                else:
                    # 先頭にcを追加
                    data[left] = c
                    left -= 1
            else:
                if is_reverse:
                    # 先頭に追加
                    data[left] = c
                    left -= 1
                else:
                    # 末尾に追加
                    data[right] = c
                    right += 1

    # 出力
    ans = ""
    if is_reverse:
        for i in range(right-1, left, -1):
            ans += data[i]
            # print(data[i], end="")
    else:
        for i in range(left+1, right):
            ans += data[i]
            # print(data[i], end="")
    # print()
    print(ans)


if __name__ == "__main__":
    solve2()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
S = input()[0:1]
Q = int(input())

mode = 1

for i in range(Q):
  TFC = list(map(str, input().split()))
  if "1" in TFC[0]:
    mode *= -1
    continue
  if mode == 1:
    if "1" in TFC[1]:
      S = ''.join([TFC[2],S])
    else:
      S = ''.join([S,TFC[2]])
  else:
    if "1" in TFC[1]:
      S = ''.join([S,TFC[2]])
    else:
      S = ''.join([TFC[2],S])

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import collections
#input = sys.stdin.buffer.readline

def inn(func=int):
    return list(map(func,input().split()))

def ins():
    return input().split()

s = ins()
q = inn()[0]
d = collections.deque(s)
for i in range(q):
    que = ins()
    if que[0] == "1":
        d.reverse()
    else:
        if que[1] == "1":
            d.appendleft(que[2])
        else:
            d.append(que[2])
print("".join(list(d)))

Submission status: Wrong Answer

Solution code:
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))
# print(l)
t_str=deque(s)
gyaku_fig=False
for ll in l:
    if ll[0]=='1':
        if gyaku_fig==False:
            gyaku_fig=True
        elif gyaku_fig==True:
            gyaku_fig=False
    elif ll[0]=='2':
        if gyaku_fig==True:
            if ll[1]=='1':
                t_str.appendleft(ll[2])
                # t_str=list(ll[2])+t_str
            elif ll[1]=='2':
                t_str.append(ll[2])
                # t_str+=list(ll[2])
        elif gyaku_fig==False:
            if ll[1]=='2':
                t_str.appendleft(ll[2])
                # t_str=list(ll[2])+t_str
            elif ll[1]=='1':
                t_str.append(ll[2])
                # t_str+=list(ll[2])
t_str=list(t_str)
if gyaku_fig==True:
    ans=''.join(t_str)
    print(ans)
else:
    t_str=t_str[::-1]
    ans=''.join(t_str)
    print(ans)
# t_str=s
# gyaku_fig=False
# for ll in l:
#     if ll[0]=='1':
#         if gyaku_fig==False:
#             gyaku_fig=True
#         elif gyaku_fig==True:
#             gyaku_fig=False
#     elif ll[0]=='2':
#         if gyaku_fig==True:
#             if ll[1]=='1':
#                 t_str=ll[2]+t_str
#             elif ll[1]=='2':
#                 t_str+=ll[2]
#         elif gyaku_fig==False:
#             if ll[1]=='2':
#                 t_str=ll[2]+t_str
#             elif ll[1]=='1':
#                 t_str+=ll[2]        
# if gyaku_fig==True:
#     print(t_str)
# else:
#     print(t_str[::-1])

Submission status: Wrong Answer

Solution code:
import math

s=input()
S=[]
S.append(s)
q=input()
Q=int(q)

#print(S,Q)

for i in range(Q):
  qu = input()
  #print(qu)
  T = int(qu[0])
  
  if T == 1:
    S.reverse()
  else:
    F = int(qu[2])
    if F == 1:
      S.insert(0,qu[4])
    else:
      S.append(qu[4])
     
L="".join(S)
print(L)

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
l=[]
r=[]
cnt=0
for i in range(n):
    e=list(map(str,input().split()))
    q=int(e[0])
    if len(e)!=1:
        f=int(e[1])
        c=e[2]
    if q==2:
        if f==1 or (f==2 and cnt%2!=0):
            s=c+s
        else:
            s=s+c
    else:
        cnt+=1
if cnt%2==0:
    print(s)
else:
    print(s[::-1])

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline


S = input()
Q = int(input())
h = 0

for i in range(Q):
    A = input()
    print(A)
    if A[0] == '1' and len(S)!=1:
        h = h + 1
    else:
        if h % 2 == 0:
            if A[2] == '1':
                S = A[4]+S
            else:
                S = S+A[4]
        else:
            if A[2] == '1':
                S = S+A[4]
            else:
                S = A[4]+S

if h % 2 == 0:
    print(S)
else:
    print(S[::-1])

Submission status: Wrong Answer

Solution code:

#import numpy as np
s = input()
n = int(input())
#qt = np.ones((n),dtype=np.int32)
#qf = np.zeros((n),dtype=np.int64)
#qc = [''] * n

mode = False
#mode = True : f1->s=c+s,f2->s=s+c
#mode = False : f1->s=s+c,f2->s=c+s

front = ''
back = ''
for i in range(n):
    qs = input()
    if len(qs) == 1:
        mode = not mode
        #s = s[::-1]
        #pass
    else:
        #qt[i] = 2
        #qf[i] = int(qs[1:-2])
        #qc[i] = qs[-1]
        if mode:
            if int(qs[2]) == 1:
                front += qs[4]
                #s = qs[4] + s
            else:
                back += qs[4]
                #s = s + qs[4]
        else:
            if int(qs[2]) == 1:
                back += qs[4]
                #s = s + qs[4]
            else:
                front += qs[4]
                #s = qs[4] + s
        
#print(mode,front,back)
if mode:
    print(front + s + back)
else:
    print(back[::-1] + s + front)

#s = front + s + back[::-1]

#for i in range(n):
#    print(qt[i],qf[i],qc[i])

#print(s)

Submission status: Wrong Answer

Solution code:
S = list(str(input()))
N = int(input())

top = []
end = []


order = []
state = True

for n in range(N):
    order = input().split()
    if order[0] == '2':
        if (order[1] == '1') == state:
            top.append(order[2])
        else:
            end.append(order[2])
    elif state:
        state = False
    else:
        state = True


if state:
    S = ''.join(S)
    top = ''.join(top[::-1])
    end = ''.join(end)
    out = top + S + end
else:
    S = ''.join(S)
    top = ''.join(top)
    end = ''.join(end[::-1])
    out = end + S + top

print(out)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())

cnt=0
for i in range(Q):
  T = input().split()
  if T[0] == '1':
    if i >0:
    	cnt += 1
  elif T[0] == '2':
    #normal
    if cnt % 2 == 0:
      if T[1] == '1':
        S = T[2] + S 
      elif T[1] == '2':
        S = S + T[2]      
    #reverse
    elif cnt % 2 == 1:
      if T[1] == '1':
        S = S + T[2] 
      elif T[1] == '2':
        S = T[2] + S
print(cnt)        
if cnt % 2 == 1:
  S = S[::-1]
print(S)