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())
querry = [list(map(str, input().split())) for i in range(Q)]
A_S = ''
S_A = ''
for i in range(Q):
    if querry[i][0] == '1':
        S = S[::-1]
        A_S = A_S[::-1]
        S_A = S_A[::-1]
    elif querry[i][0] == '2':
        if querry[i][1] == '1':
            A_S += querry[i][2] 
        elif querry[i][1] == '2':
            S_A += querry[i][2]

print(A_S + S + S_A)

Submission status: Wrong Answer

Solution code:
S = list(input())
N = int(input())
X = []
for i in range(N):
    X.append(input())

T = []
for i in range(N):
    if len(X[i]) == 1:
        S.reverse()
        T.reverse()
        if T:
            S.extend(T)
            T.clear()
    else:
        Y = list(X[i].split())
        if int(Y[1]) == 1:
            T.append(Y[2])
        else:
            S.append(Y[2])

if T:
    T.extend(S)
    print(''.join(T))
else:
    print(''.join(S))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

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

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


print(S)

Submission status: Wrong Answer

Solution code:
s = str(input())
q = int(input())
hanten_flg = False
command_list= [input() for i in range(0,q)]
for i in command_list:
    commands = i.split()
    if(commands[0] == '1'):
        if(hanten_flg == True):
            hanten_flg = False
        if(hanten_flg == False):
            hanten_flg = True
    else:
        if(hanten_flg == True):
            s = s[::-1]
        if(commands[1] == '1'):
            s = commands[2] + s
        else:
            s = s + commands[2]
print(s)

Submission status: Wrong Answer

Solution code:
S = [input()]
Q = int(input())
querys = [input() for _ in range(Q)]
is_reverse = False

for q in querys:
    query = q.split()
    if len(query) == 1:
        is_reverse = not is_reverse
        continue
    _, f, c = query
    if is_reverse:
        
        if f == "1":
            S = S + [c]
        elif f == "2":
            S = [c] + S
    else:
        if f == "1":
            S = [c] + S
        elif f == "2":
            S = S + [c]
if is_reverse:
    print("".join(S[::-1]))
else:
    print("".join(S))

Submission status: Wrong Answer

Solution code:
from collections import deque

S = input()
Q = int(input())
ans = deque()
ans.append(S)
reverse = False

for _ in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse = not reverse
    else:
        F, C = query[1:]
        if (F == "1" and not reverse) or (F == "2" and reverse):
            ans.appendleft(C)
        else:
            ans.append(C)

if reverse:
    print("".join(reversed(ans)))
else:
    print("".join(ans))

Submission status: Wrong Answer

Solution code:
from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=deque(S)
reverse=False
for i,q in enumerate(query):
  if len(q)==1:
    reverse=not reverse
  else:
    _,f,c=q
    if (f=='1') ^ reverse:
      ans.append(c)
    else:
      ans.appendleft(c)
print(*ans,sep='')

Submission status: Wrong Answer

Solution code:
def main():
    S=[input()]
    for i in range(int(input())):
        T = input()
        if T == '1':
            S = S[::-1]
        else:
            ta = T.split()
            F = int(ta[1])
            C = ta[2]
            if F == 1:
                S.insert(0, C)
            else:
                S.append(C)

    print(''.join(S))

main()

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
flag = True
head, tail = "", ""

for i in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    flag = not flag
  else:
    if int(query[1]) == 1:
      if flag:
        head+=query[2]
      else:
        tail+=query[2]
    else:
      if flag:
        tail+=query[2]
      else:
        head+=query[2]

if flag:
  print(head[::-1] + s + tail)
else:
  print(tail[::-1] + s + head)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
inv = 0
a = []
for i in range(1, q+1):
    try:
        t, f, c = input().split()
    except ValueError:
        t = '1'
    if t == '1':
        inv += 1
    else:
        a.append([f, c, inv])

if inv % 2 == 1:
    s = s[::-1]
for i in range(len(a)):
    if (int(a[i][0])%2) * (int(a[i][2])%2) %2 == 1:
        s = s + a[i][1]
    else:
        s = a[i][1] + s
if (inv-a[0][2])%2 ==1:
    s = s[::-1]
print(s)

Submission status: Wrong Answer

Solution code:
S = str(input())
Q = int(input())
querry = [list(map(str, input().split())) for i in range(Q)]
A_S = ''
S_A = ''
for i in range(Q):
    if querry[i][0] == '1':
        S = S[::-1]
    elif querry[i][0] == '2':
        if querry[i][1] == '1':
            A_S += querry[i][2] 
        elif querry[i][1] == '2':
            S_A += querry[i][2]

print(A_S + S + S_A)

Submission status: Wrong Answer

Solution code:
def main():
  s=input()
  q=int(input())
  turn = 1

  for _ in [0]*q:
      query = input()
      try:
          t = int(query)
          turn = 3 - turn
      except ValueError:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              s = s + c
          else:
              s = c + s
  if turn == 2:
      print(s)
  else:
      print(s[::-1])
main()

Submission status: Wrong Answer

Solution code:
S = input().strip()
Q = int(input())
is_reverse = False
A = ""
B = ""
for i in range(Q):
  query = [j for j in input().strip().split()]
  T = int(query[0])
  if T == 1:
    is_reverse = not is_reverse
  else:
    F, C = int(query[1]), query[2]
    if F == 1:
      if not is_reverse:
        A = A + C
      else:
        B = B + C
    else:
      if not is_reverse:
        B = C + B
      else:
        A = C + A

if not is_reverse:
  print(A + S + B)
else:
  print(B[::-1] + S[::-1] + A[::-1])

Submission status: Wrong Answer

Solution code:
from sys import stdin

s = stdin.readline().rstrip().split()
q = int(stdin.readline().rstrip())

left = 1
for i in range(q):
    line = stdin.readline().rstrip().split()
    if len(line) == 1:
        left *= -1
    else:
        if ((line[1] == '1') and (left == 1)) or ((line[1] == '2') and (left == -1)):
            s.append(line[2])
        else:
            s.insert(0, line[2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S=input()
Q=int(input())
count=0
for i in range(Q):
	K=input().split()
	if K[0]=="1":
		if i==Q-1:
			S=S[::-1]
		else:
			count+=1
	if K[0]=="2":
		if K[1]=="1":
			if count%2==0:
				S=K[2]+S
			else:
				S=S+K[2]
		elif K[1]=="2":
			if count%2==0:
				S=S+K[2]
			else:
				S=K[2]+S
print(S)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
qlst = []
for i in range(Q):
    qlst.append(input().split())
start = S
end = ''
for i in range(Q):
    if qlst[i][0] == '1':
        start, end = end, start
    else:
        if qlst[i][1] == '1':
            start += qlst[i][2]
        else:
            end += qlst[i][2]

print(start[::-1] + end)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

hanten = 0
saki = ""
ato = ""

for i in range(Q):
    q = input().split()
    
    if q[0] == "1":
        hanten += 1
    else:
        if hanten % 2 == 0:
            if q[1] == "1":
                saki += q[2]
            else:
                ato += q[2]
        else:
            if q[1] == "1":
                ato += q[2]
            else:
                saki += q[2]

if hanten % 2 == 0:
    for i in range(len(saki)):
        print(saki[-i-1], end="")
    print(S, end="")
    print(ato)
else:
    for i in range(len(ato)):
        print(ato[-i-1], end="")
    print(S, end="")
    print(saki)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
    s = ns()
    Q = ni()

    T1 = 0
    FrontS = ""
    BackS = ""
    for _ in range(Q):
        T = stdin.readline().split()
        if T[0] == "1":
            T1 += 1
        else:
            if T1 % 2 == 0:
                if T[1] == "1":
                    FrontS = T[2] + FrontS
                else:
                    BackS += T[2]
            else:
                if T[1] == "1":
                    BackS = T[2] + BackS
                else:
                    FrontS = T[2] + FrontS
    
    if T1 % 2 == 0:
        print(FrontS + s + BackS)
    else:
        print((BackS + s + FrontS)[::-1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = str(input())
n = int(input())
q_list = [list(map(str, input().strip().split())) for i in range(n)]

rev = 0
for_s = ''
rev_s = ''

for q in q_list:
    if q[0] == '1':
        rev = 1 - rev
    elif q[1] == '1':
        if rev == 0:
            rev_s += q[2]
        else:
            for_s += q[2]
    else:
        if rev == 0:
            for_s += q[2]
        else:
            rev_s += q[2]
out = ''
if rev == 0:
    out = rev_s[::-1] + s + for_s
else:
    out = for_s[::-1] + s + rev_s
print(out)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

S=raw_input()
Q=input()
Query=[ sys.stdin.readline().split() for _ in range(Q) ]

s1=deque()
s2=deque()
judge={}
judge["front"]="s1"
judge["end"]="s2"

cnt=0
for x in Query:
    if x[0]=="1":
        n=x[0]
        cnt+=1
    elif x[0]=="2":
        n,f,c=x[0],x[1],x[2]
    if n=="1":
        judge["front"],judge["end"]=judge["end"],judge["front"]
    elif n=="2":
        if f=="1":
            if judge["front"]=="s1":
                s1.appendleft(c)
            elif judge["front"]=="s2":
                s2.appendleft(c)
        elif f=="2":
            if judge["end"]=="s1":
                s1.append(c)
            if judge["end"]=="s2":
                s2.append(c)

str1=""
for x in s1:
    str1+=x
str2=""
for x in s2:
    str2+=x

if cnt%2==0:
    print str1[::-1]+S+str2
elif cnt%2==1:
    print str2+S[::-1]+str1

Submission status: Wrong Answer

Solution code:

s = input()
q = int(input())
flag = False
head = ""
tail = ""
for i in range(q):
    query = input()
    if query[0] == "1":
        flag = not flag
    else:
        [t, f, c] = query.split()
        f = True if f == "1" else False
        if flag == f:
            head = c + head
        else:
            tail += c
s = head + s + tail
if not flag:
    s = s[::-1]
print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque
S=input()
S_list=deque()
for k in range(len(S)):
    S_list.append(S[k])
Q=int(input())
kouho=[input().split() for i in range(Q)]
"""for i in range(Q):
    kari=input().split()
    kouho.append(kari)"""
hanten=[]
count=0
flag="sonomama"
for j in range(Q):
    if kouho[j][0]=="1":
        flag="hantai"
        count+=1
    else:
        if flag=="sonomama":
            if kouho[j][1]=="1":
                S_list.appendleft(kouho[j][2])
            else:
                S_list.append(kouho[j][2])
        else:
            if kouho[j][1]!="1":
                S_list.appendleft(kouho[j][2])
            else:
                S_list.append(kouho[j][2])
for k in range(count):
    S_list.reverse()
print(*S_list,sep="")

Submission status: Wrong Answer

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

rev = 0

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev += 1
    else:
        if (t[1] == "1" and rev % 2 == 0) or (t[1] == "2" and rev % 2 != 0):
            s.appendleft(t[2])
        else:
            s.append(t[2])

if rev % 2 == 0:
    print(*list(s),sep="")
else:
    print(*reversed(list(s)), sep="")

Submission status: Wrong Answer

Solution code:
def main2(s,x,q):
    res = s
    rev = 1 #-1なら反転中
    lstA = []
    lstB = []
    for op in q:
        if int(op[0]) == 1:
            rev = rev * -1
        elif int(op[1])*rev == 1 or int(op[1])*rev == -2:
            lstA.append(op[2])
        elif int(op[1])*rev == -1 or int(op[1])*rev == 2:
            lstB.append(op[2])
    if rev == 1:
        res = "".join(lstA[::-1])+res+"".join(lstB)
    else :
        res = "".join(lstB[::-1])+res+"".join(lstA)
    return res

s = input()
x = int(input())
q = [input().split() for _ in range(x)]
print(main2(s,x,q))

Submission status: Wrong Answer

Solution code:
init = input()
num = int(input())

_strings = [''] * (num * 2 + 1)
_strings[num] = init

isReverse = False

queue = []

fi = num - 1
li = num + 1

i = 0
while i < num:
    query = input().split()
    type = int(query[0])

    if type == 1:
        # _strings.reverse()
        isReverse = not isReverse
    else:
        mode = int(query[1])

        if (mode == 1 and not isReverse) or (mode == 2 and isReverse):
            _strings[fi] = str(query[2])
            fi -= 1
            # _strings.insert(0, str(query[2]))
        else:
            _strings[li] = str(query[2])
            li += 1
            # _strings.append(str(query[2]))
    i += 1

if isReverse:
    _strings.reverse()

print(''.join(_strings))

Submission status: Wrong Answer

Solution code:
def main():

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

    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:
            S.reverse()
        else:
            if f == '1' or f == 1:
                S.insert(0, c)
            else:
                S.append(c)

    # S = str(input().split())
    # 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':
    #             S += c
    #         else:

    print("".join(S))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

for i in range(Q):
    query = input()
    is_forward = True

    if query == '1':
        is_forward = not is_forward
    else:
        T, F, C = query.split()
        if is_forward:
            if F == '1':
                S.insert(0, C)
            else:
                S.append(C)
        else:
            if F == '1':
                S.append(C)
            else:
                S.insert(0, C)

print(''.join(S))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():

    input = stdin.readline

    S = input()[:-1]
    Q = int(input())
    
    query = [0] * Q
    ans_list = [S]

    reverse_flag = False

    for i in range(Q):
        query = input().split()
        if(query[0] == '1'):
            reverse_flag = not reverse_flag
        else:
            if(query[1] == '1') and (reverse_flag is False):
                ans_list.insert(0,query[2])
            elif(query[1] == '2') and (reverse_flag is True):
                ans_list.insert(0,query[2])
            else:
                ans_list.append(query[2])
    
    if(reverse_flag is not True):
        print(''.join(ans_list))
    else:
        print(''.join(ans_list[::-1]))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
import copy
S = list(input())
S = deque(S)
Q = int(input())
qlis = []
cnt = 0
judge = 0
for _ in range(Q):
    qlis.append(input().split())

for i in range(Q):
    if len(S) >= 3:
        judge = 1
        break
    if len(qlis[i]) == 1:
        S.reverse()
    else:
        if int(qlis[i][1]) == 2:
            S.append(qlis[i][2])
        else:
            S.appendleft(qlis[i][2])

    cnt += 1

if judge == 1:
    SS = copy.deepcopy(S)
    saigo = SS.pop()
    saisyo = SS.popleft()
    kotei = SS
    reverse_kotei = copy.deepcopy(kotei)
    reverse_kotei.rotate(1)
    appendlist = [saisyo,saigo]
    append_rev = [0,0]
    mae_usiro = [0,1]
    cnt_rev = 0

    for i in range(cnt,Q):
        if int(qlis[i][0]) == 1:
            cnt_rev += 1
        else:
            if int(qlis[i][1]) == 2:
                mae_usiro.append(1)
                appendlist.append(qlis[i][2])
                append_rev.append(cnt_rev)
            else:
                mae_usiro.append(0)
                appendlist.append(qlis[i][2])
                append_rev.append(cnt_rev)

    if cnt_rev % 2 == 1:
        kotei = reverse_kotei

    if kotei:
        kotei = deque(kotei)



    for j in range(len(mae_usiro)):
        if (cnt_rev - append_rev[j] + mae_usiro[j]) %2 == 1:
            kotei.append(appendlist[j])
        else:
            kotei.appendleft(appendlist[j])
            
if judge==1:
    kotei = list(kotei)
    answer = "".join(kotei)
    print(answer)
else:
    answer = "".join(S)
    print(answer)

Submission status: Wrong Answer

Solution code:
from collections import deque

S = input().rstrip('\r\n')
S_list = deque(S)
reverse_flg = False

Q = int(input())
for _ in range(Q):
    query = input().rstrip('\r\n')
    t, f, c = '', '', ''
    if len(query) == 1:
        t = query
    else:
        t, f, c = query.split(' ')
    if t == '1':
        reverse_flg = not reverse_flg
    else:
        if f == '1':
            S_list.appendleft(c)
        else:
            S_list.append(c)
if reverse_flg:
    S_list.reverse()
print(''.join(S_list))

Submission status: Wrong Answer

Solution code:
from collections import deque
S = list(input().split())
q = int(input())
d = deque(S)
rev_cnt = 0
for ind in range(q):
    cur_list = list(input().split())
    #print(cur_list)
    if int(cur_list[0]) == 1:
        rev_cnt += 1
    else:
        f = int(cur_list[1])
        c = cur_list[2]
        if (rev_cnt + f) % 2 == 0:
            d.append(c)
        else:
            d.appendleft(c)         
S = list(d)
if rev_cnt %2 == 1:
    S.reverse()
print("".join(S))

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

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

Que = [0]* Q
for i in range(Q):
    Que[i] = list(map(str, input().split()))

answer = copy.copy(S)
check = 1
for i in range(Q):
    T = Que[i][0]
    if int(T) == 1:
        check *= -1
    else:
        F = Que[i][1]
        if (int(F) == 1 and check == 1) or (int(F) == 2 and check == -1):
            answer = ''.join([Que[i][2], answer])
        else:
            answer = ''.join([answer, Que[i][2]])
print(answer)

Submission status: Wrong Answer

Solution code:
S = str(input())
Q = int(input())
Qy = list([input().split() for _ in range(Q)])
ans = [S]
for i in Qy:
    if i[0] == '1':
        ans.reverse()
    elif i[0] == '2':
        if i[1] == '1':
            ans.insert(0,i[2])
        else:
            ans.append(i[2])
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
uerys = [list(input().split()) for i in range(Q)]
count = 0
SList = list(S)

for uery in uerys:
    if uery[0] == '1':
        count += 1
    
    if uery[0] == '2' and count % 2 == 0:
        if uery[1] == '1':
            SList.append(uery[2])
        else:
            SList.insert(0, uery[2])
    elif uery[0] == '2' and count % 2 == 1:
        if uery[1] == '1':
            SList.insert(0, uery[2])
        else:
            SList.append(uery[2])

if count % 2 == 0:
    print(''.join(SList))
else:
    print(''.join(SList[::-1]))

Submission status: Wrong Answer

Solution code:
from collections import deque

S = input()
Q = int(input())
ans = deque()
ans.append(S)
reverse = False

for _ in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse = not reverse
    if query[0] == "2":
        F, C = query[1:]
        if F == "1":
            if reverse:
                ans.append(C)
            else:
                ans.appendleft(C)
        else:
            if reverse:
                ans.appendleft(C)
            else:
                ans.append(C)

if reverse:
    ans.reverse()

print("".join(ans))

Submission status: Wrong Answer

Solution code:
S = list(input())
Q = int(input())
x = 1
y = 1
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
        y *= -1
    elif a == "2":
        c, d = b
        if c == "2":
            x *= -1 
        if x == 1:
            S.insert(0, d)
        elif x == -1:
            S.append(d)
if y == -1:
    S = S[::-1]
print(*S, sep="")

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    q = int(input())

    is_true = True

    s_list = [s]

    for _ in range(q):
        input_list = list(input().split())
        if input_list[0] == '1':
            if is_true:
                is_true = False
            else:
                is_true = True
            continue
        if input_list[1] == '1':
            if is_true:
                s_list.insert(0, input_list[2])
            else:
                s_list.append(input_list[2])

        else:
            if is_true:
                s_list.append(input_list[2])
            else:
                s_list.insert(0, input_list[2])
            
    if not is_true:
        s_list.reverse()

    print(''.join(s_list))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
raw_input = input()
S = list(raw_input)


Q_n = int(input())
Q=[]

for x in range(Q_n):
    x = input()
    tmp = x.split()
    q = tmp[0]

    if q == "1":
        S_len = len(S)
        if len(S) > 1:
            S_dash = S_len - 1
            tmp_2 = S[S_dash]
            S[S_dash]=S[0]
            S[0]=tmp_2
        else:
            S = S
        
    else:
        f = tmp[1]
        c = tmp[2]
        if f == "1":
            S.insert(0,c)
        else:
            S.append(c)

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

S = input().split()
Q = int(input())
QUERY = sys.stdin.readlines()

state = 0
q = deque()
for s in S:
    q.append(s)

for i in range(Q):
    query = QUERY[i]
    if query[0] == '1':
        state ^= 1
    else:
        _, F, C = query.split()
        if (state + int(F)) % 2:
            q.appendleft(C)
        else:
            q.append(C)

ans = []
if state == 0:
    while q:
        ans.append(q.popleft())
else:
    while q:
        ans.append(q.pop())

print(*ans, sep='')

Submission status: Wrong Answer

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

query = [input() for _ in range(q)]
count = 0

#memo = [[]for _ in range(10**5)]
right = ""
left = ""
for qu in query:
    if len(qu.split()) == 1:
        count += 1
        right, left = left, right
        continue
    num, f, c = qu.split()
    num = int(num)

    if f == 1:
        left += c
        
    else:
        right += c

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

Submission status: Wrong Answer

Solution code:
s=input()
q=int(input())
count=0
header=''
for i in range(q):
    query=list(map(str,input().split()))
    query[0]=int(query[0])
    if query[0]==1:
        count+=1
    else:
        query[1]=int(query[1])
        if count%2==0:
            if query[1]==1:
                s=query[2]+s
            else:
                header+=query[2]
        else:
            if query[1]==1:
                header+=query[2]
            else:
                s=query[2]+s
if count%2==1:
    s=s[::-1]
    header=header[::-1]
    s=s+header
print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()
q = int(input())
op = [input().split() for _ in range(q)]


ans = deque()
ans.append(s)

end_flag = 1

for i in op:
    if len(ans) <= 1:
        if i[0] == "1":
            continue
        if i[0] == "2":
            if i[1] == "1" and end_flag:
                ans.appendleft(i[2])
            elif i[1] == "2" and end_flag:
                ans.append(i[2])
            elif i[1] == "1" and not end_flag:
                ans.append(i[2])
            elif i[1] == "2" and not end_flag:
                ans.appendleft(i[2])
    elif len(ans) > 1:
        if i[0] == "1":
            if end_flag == 1:
                end_flag = 0
            elif end_flag == 0:
                end_flag = 1
        if i[0] == "2":
            if i[1] == "1" and end_flag == 1:
                ans.appendleft(i[2])
            elif i[1] == "2" and end_flag == 1:
                ans.append(i[2])
            elif i[1] == "1" and end_flag == 0:
                ans.append(i[2])
            elif i[1] == "2" and end_flag == 0:
                ans.appendleft(i[2])

if end_flag == 1:
    print("".join(ans))
elif end_flag == 0:
    ans.reverse()
    print("".join(ans))

Submission status: Wrong Answer

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

r = 0
sort = 0
for i in range(q):
  List=list(input().split())
  if len(List) > 1 :
    if List[1] == '1' and r == 0 :
      s = List[2] + s 
    elif List[1] == '1' and r == 1 :
      s = s + List[2] 
    elif List[1] == '2' and r == 0 :
      s = s + List[2] 
    elif List[1] == '2' and r == 1 :
      s = List[2] + s 
    r = 0
  else:
    
    if r == 1 :
      r=0
      sort += 1
    elif len(s) > 1 and r == 0:
      r=1
      sort += 1



ans = ''
if sort % 2 ==1:
  for j in range(len(s)):
    ans += s[len(s)-j-1:len(s)-j]
else:
  ans = s

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
 
for k in range(Q):
    q =  [ i for i in input().split(' ')]
    if q[0] == '1':
        if not len(S) == 1:
            head = S[0]
            tail = S[-1]
            S = tail + S[1:-1] + head
    else:
        if q[1] == '1':
            S = q[2] + S
        else:
            S = S + q[2]
print(S)

Submission status: Wrong Answer

Solution code:

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
        # print("reverse", S)
        # S = S[::-1]
    else:
        t, f, c = query.split()
        # print(t, f, c)
        d = f=="1"
        if isReversed: d = not d
        if d:
            # S = "".join([c, S])
            slist.appendleft(c)
        else:
            # print("append c to tail of ", S)
            # S = S + c
            # S = "".join([S, c])
            slist.append(c)
# slist = list(slist)
if isReversed:
    slist.reverse()

print("".join(slist))
# print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

ans = deque(s)

for i in range(q):
    now = query[i]
    if now == ['1']:
        if len(ans) != 1:
            l = ans.popleft()
            r = ans.pop()
            ans.append(l)
            ans.appendleft(r)
        else:
            continue
    else:
        f = now[1]
        c = now[2]
        if f == '1':
            ans.appendleft(c)
        elif f == '2':
            ans.append(c)

print(''.join(ans))

Submission status: Wrong Answer

Solution code:
s=list(input())
q=int(input())
t = []
for _ in range(q):
    t.append(input())
for i in range(0,q):
    if t[i][0]=="1":
        s.reverse()
    elif t[i][4]=="1":
        s.insert(0,t[i][4])
    else:
        s.append(t[i][4])
print("".join(s))