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:
left = input()
right = ""
q = int(input())
flag = 0b0
for i in range(q) :
    t = input()
    if t == "1" :
        flag ^= 1
        continue
    t, f, c = t.split(" ")
    f = int(f)
    left += c*((flag+f)%2)
    right += c*((flag+f+1)%2)
if flag == 0 :
    print(left[::-1] + right)
else :
    print(right[::-1]+left)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
flag = 0b0
for i in range(q) :
    t = input()
    if t == "1" :
        flag ^= 1
        continue
    s = t[4]*((flag+int(t[2])%2)) + s + t[4]*((flag+int(t[2])+1)%2)
if flag == 0 :
    print(s)
else :
    print(s[::-1])

Submission status: Wrong Answer

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

rev = 0
front = ""
back = ""

for i in range(q):
    t = input().split()

    # T_1 = 1の時
    if len(t) == 1:
        rev += 1

    # T_1 = 2の時
    else:
        # 反転するときは入れ替える
        if rev%2 == 1:
            front,back = back,front

        # 文字を追加
        if  t[1] == '1':
            front = t[2] + front
        else:
            back = back + t[2]

        rev = 0

# 反転するとき
if rev%2 == 1:
    print(back[::-1] + s[::-1] + front[::-1])
else:
    print(front + s + back)

Submission status: Wrong Answer

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

rev = 0
front = ""
back = ""

for i in range(q):
    t = input().split()

    # T_1 = 1の時
    if len(t) == 1:
        rev += 1

    # T_1 = 2の時
    else:
        # 反転するときは入れ替える
        if rev%2 == 1:
            front,back = back,front

        # 文字を追加
        if  t[1] == '1':
            front = t[2] + front
        else:
            back = back + t[2]

        rev = 0

# 反転するとき
if rev%2 == 1:
    print(back[::-1] + s[::-1] + front[::-1])
else:
    print(front + s + back)
    
            

'''

words = [] #言葉
words.append(s) 
cnt = [0]*q #反転する回数
i = 0
j = 0

while i != q:
    t = input().split()

    if int(t[0]) == 1 and i == 0:
        cnt[j] += 1

        while i != q:
            t = input().split()

            if int(t[0]) == 1:
                cnt[j] += 1
                i += 1
            else:
                j += 1
                
                if int(t[1]) == 2:
                    cnt[j] += 1

                words.append(t[2])
                    
                i += 1
                break
            
    else:
        j += 1
                
        if int(t[1]) == 2:
        cnt[j] += 1

        words.append(t[2])
                    
        i += 1
                
if cnt % 2 == 1:
    list = list[::-1] 

for i in range(len(list)):
    print(list[i],end='')

print()

'''

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3 ## -*- python -*-

def main():
    s = list(input())
    q = int(input())
    for i in range(q):
        d = input()
        if d[0] == "1":
            s.reverse()
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                s.insert(1, c)
            else: # f == 2
                s.append(c)

    print(''.join(s))

main()

Submission status: Wrong Answer

Solution code:
s = []
s.append(input())
num = int(input())
change_flag = 1
for i in range(num):
    a = input().split(" ")
    if(a[0] == "1"):
        change_flag *= -1
    else:
        if((a[1] == "1" and change_flag == 1) or (a[1] == "2" and change_flag == -1)):
            s.insert(0, a[2])
        else:
            s.append(a[2])

if(change_flag == -1):
    s = s[::-1]
for i in s:
    print(i, end="")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3 ## -*- python -*-

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

for i in range(q):
    d = input()
    if d[:1] == "1":
        if not s[0] == s[-1]:
            s = s[::-1]
    else: # 2
        dd = d.split()
        f = int(dd[1])
        c = dd[2]
        if f == 1:
            s = c + s
        else: # f == 2
            s = s + c

print(s)

Submission status: Wrong Answer

Solution code:
S = input()
N = int(input())
direct = 0
for i in range(N):
  X = input().split()
  if len(X) != 1:
    if (X[1] == "1" and direct == 0) or (X[1] == "2" and direct == 1):
      S = X[2] + S
    else:
      S = S + X[2]
    direct = 1 - direct
print(S) if direct == 0 else print(S[::-1])

Submission status: Wrong Answer

Solution code:
S = input()
N = int(input())
direct = 0
for i in range(N):
  X = input().split()
  if len(X) != 1:
    if (X[1] == "1" and direct == 0) or (X[1] == "2" and direct == 1):
      S = X[2] + S
    else:
      S = S + X[2]
    direct = 1 - direct
print(S)

Submission status: Wrong Answer

Solution code:
S = input()
N = int(input())
for i in range(N):
  X = input().split()
  NS = S
  if len(X) == 1 and len(S) != 1:
    NS = S[-1] + S[1:-1] + S[0]
  else:
    if X[1] == "1":
      NS = X[2] + S
    else:
      NS = S + X[2]
  S = NS
print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque
d = deque()
s = input()
d.append(s)
q = int(input())
for i in range(q):
    tfc = input().split()
    if int(tfc[0]) == 1:
        d.reverse()
#         print('reverse:', d)
    else:
        if int(tfc[1]) == 1:
            d.appendleft(tfc[2])
#             print('appendleft:', d)
        else:
            d.append(tfc[2])
#             print('append:', d)
print(''.join(d))

Submission status: Wrong Answer

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

rev=1

sf=s
sb=""

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf+=n[2]
    else:
      sb+=n[2]

s=sf[::-1]+sb

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

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

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

Submission status: Wrong Answer

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

rev=1

sf=[]
sb=[]

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf.append(n[2])
    else:
      sb.append(n[2])

s=''.join(sf)+s+''.join(sb)

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

Submission status: Wrong Answer

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

lr = 'left'

def reverse_list(lr):
    if lr == 'right':
        return 'left'
    else:
        return 'right'

def moji_tuika(S, f, c, lr):
    if f == 1 and lr == 'left':
        S.insert(0,c)
    elif f == 1 and lr == 'right':
        S.append(c)
    elif f == 2 and lr == 'left':
        S.append(c)
    else:
        S.insert(0,c)
    return S

q = []
for i in range(Q):
    temp = input().split()
    if len(temp) == 1:
        q.append(1)
    else:
        q.append(temp)

S = list(S)
print(S)
for i in q:

    if type(i) == int:
        lr = reverse_list(lr)
    elif int(i[0]) == 2:
        #print(i[2])
        #print(S)
        S = moji_tuika(S,int(i[1]),i[2],lr)
    #print(S)
if lr == 'right':
    S.reverse()

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

Submission status: Wrong Answer

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

def reverse_list(S):
    S = list(S)
    return ''.join(S)

def moji_tuika(S, f, c):
    if f == 1:
        return c + S
    else:
        return S + c

q = []
for i in range(Q):
    temp = input().split()
    if len(temp) == 1:
        q.append(1)
    else:
        t = int(temp[0])
        f = int(temp[1])
        c = temp[2]
        q.append((t,f,c))

for i in q:
    if type(i) == int:
        S = reverse_list(S)
    elif i[0] == 2:
        S = moji_tuika(S,i[1],i[2])

print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque
d = deque()
length = 0
for x in input():
    d.append(x)
    length += 1
Q = int(input())
f = 0
for _ in range(Q):
    l = list(input().split())
    if l[0] == '1':
        f ^= 1
    else:
        length += 1
        if f == '0': 
            if l[1] == '0': d.append(l[2])
            else: d.appendleft(l[2])
        else:
            if l[1] == '0': d.appendleft(l[2])
            else: d.append(l[2])
ans = ''
for x in range(length):
    ans += d.pop()
if f:
    print(ans[::-1])    
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
q = int(input())
sw = 1
for i in range(q):
  e = list(map(str, input().split()))
  t = int(e[0])

  if t == 1:
    sw = sw * -1
  elif t == 2:
    f = int(e[1])
    if (sw == 1 and f == 1) or (sw == -1 and f == 2):
      S = e[2] + S
    elif (sw == -1 and f == 1) or (sw == 1 and f == 2):
      S = S + e[2]


print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = list(input())
q = int(input())
c = 0
d = deque(s)

for i in range(q):
    x = list(input().split())
    if x[0] == "1":
        c += 1
        d.reverse()
    else:
        if x[1] == "1":
            if c%2 == 0:
                d.appendleft(x[2])
            else:
                d.append(x[2])
        else:
            if c%2 == 1:
                d.append(x[2])
            else:
                d.appendleft(x[2])

print("".join(d))

Submission status: Wrong Answer

Solution code:
from collections import deque

S = input()
Q = int(input())
P = [input().split() for i in range(Q)]

for i in range(Q):    
  if P[i][0] == '2' and P[i][1] == '2':
    S += P[i][2]
  elif P[i][0] == '2' and P[i][1] == '1':
    S = P[i][2] + S
    
print(S[::-1])

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
flg = 0
senntou = ''
ushiro = ''
for i in range(Q):
    A = list(input().split())
    if int(A[0]) == 1 and flg == 0:
        flg = 1
        continue
    elif int(A[0]) == 1 and flg == 1:
        flg = 0
        continue
    if (int(A[1]) == 1 and flg == 0) or (int(A[1]) == 2 and flg == 1):
        senntou = A[2] + senntou
    else:
        ushiro = ushiro + A[2]
if flg == 0:
    print(senntou + S + ushiro)
if flg == 1:
    print(ushiro[::-1] + S + senntou[::-1])

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
flg = 0
senntou = ''
ushiro = ''
for i in range(Q):
    A = list(input().split())
    if int(A[0]) == 1 and flg == 0:
        flg = 1
        continue
    elif int(A[0]) == 1 and flg == 1:
        flg = 0
        continue
    if int(A[1]) == 1:
        if flg == 0:
            senntou += A[2]
        else:
            ushiro += A[2]
    else:
        if flg == 0:
            ushiro += A[2]
        else:
            senntou += A[2]
if flg == 0:
    print(senntou[::-1] + S + ushiro)
if flg == 1:
    print(ushiro[::-1] + S + senntou)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
flg = 0
acchi = ''
kocchi = ''
for i in range(Q):
    A = list(input().split())
    if int(A[0]) == 1 and flg == 0:
        flg = 1
        continue
    elif int(A[0]) == 1 and flg == 1:
        flg = 0
        continue
    if int(A[0]) == 2:
        if int(A[1]) == 1:
            if flg == 0:
                acchi += A[2]
            else:
                kocchi += A[2]
        else:
            if flg == 0:
                kocchi += A[2]
            else:
                acchi += A[2]
if flg == 0:
    acchi = acchi[::-1]
    print(acchi+S+kocchi)
if flg == 1:
    kocchi = kocchi[::-1]
    print(kocchi+S+acchi)

Submission status: Wrong Answer

Solution code:
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
if(w):
    print(s[::-1])
else:
    print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import deque

s=input()
q=int(input())
count=0 #何回反転があるか
ss=deque(s)
flag=True #通常状態
for i in range(q):
    info=input()
    if info[0]=="1":
        count+=1
        flag=False
    else:
        _,f,c=info.split()
        if flag:
            if f=="1":
                ss.appendleft(c)
            else:
                ss.append(c)
        else: #反転状態
            if f=="1":
                ss.append(c)
            else:
                ss.appendleft(c)
ans="".join(ss)
print(ans if count%2==0 else ans[::-1])

Submission status: Wrong Answer

Solution code:
s=input();q=int(input());r,a=0,[[],[]]
for _ in range(q):
  t=input()
  if t=='1':r=-(-~r%2)
  else:a[~-r+int(t[2])].append(t[4])
print(''.join(reversed(a[~-r+1]))+s+''.join(a[~-r+2]))

Submission status: Wrong Answer

Solution code:
a = str(input())
itr_num = int(input())
test =[]
status =1 
R=""
L=""

##type of valiable##
for i in range(itr_num):
  in_val =input().split()  
  test.append(in_val)

for i in test:
  if len(i)==1:
    status = status *(-1)
  else:
    if i[1] =="1":
      if status ==1:
        L += str(i[2])
      else:
        R += str(i[2])
    if i[1] =="2":
      if status ==1:
        R += str(i[2])
      else:
        L += str(i[2])

out = R[::-1]+a+L
print(out)

Submission status: Wrong Answer

Solution code:
#D
from collections import deque
Str = str(input())
Q = int(input())
S = deque(list(Str))
#S.append(list(Str))
#上の方法ではダメ
A = 0
B = []
C = []

for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        if A%2==0:
            if len(B)>1:
                B.reverse()
                S.extendleft(B)
                B = []
            elif len(B) == 1:
                S.extendleft(B)
                B = []
            if len(C) > 0:
                S.extend(C)
                C = []
        else:
            if len(C)>1:
                C.reverse()
                S.extendleft(C)
                C = []
            elif len(C) == 1:
                S.extendleft(C)
                C = []
            if len(B) > 0:
                S.extend(B)
                B = []
        A += 1
    elif a[1] == '1':
        B.append(a[2])
    else:
        C.append(a[2])

if a[0] != '1':
    if A%2==0:
        if len(B)>1:
            B.reverse()
            S.extendleft(B)
            B = []
        elif len(B) == 1:
            S.extendleft(B)
            B = []
        if len(C) > 0:
            S.extend(C)
            C = []
    else:
        if len(C)>1:
            C.reverse()
            S.extendleft(C)
            C = []
        elif len(C) == 1:
            S.extendleft(C)
            C = []
        if len(B) > 0:
            S.extend(B)
            B = []

if A%2 != 0:
    S.reverse()
print(''.join(S))

Submission status: Wrong Answer

Solution code:
a = str(input())
itr_num = int(input())
test =[]
status =1 

##type of valiable##
for i in range(itr_num):
  in_val =input().split()  
  test.append(in_val)

for i in test:
  if len(i)==1:
    status = status *(-1)
  elif len(i)==3 and i[1] ==1 and status ==1:
    a = str(i[2])+a
  elif len(i)==3 and i[1] ==1 and status !=1:
    a = a+str(i[2])
  elif len(i)==3 and i[1] ==2 and status ==1:
    a = a+str(i[2])
  elif len(i)==3 and i[1] ==2 and status !=1:
    a = str(i[2])+a

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

Submission status: Wrong Answer

Solution code:
#D
from collections import deque
Str = str(input())
Q = int(input())
S = deque(list(Str))
#S.append(list(Str))
#上の方法ではダメ
A = 0
B = []
C = []

for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        if A%2==0:
            if len(B)>1:
                B.reverse()
                S.extendleft(B)
                B = []
            elif len(B) == 1:
                S.extendleft(B)
                B = []
            if len(C) > 0:
                S.extend(C)
                C = []
        else:
            if len(C)>1:
                C.reverse()
                S.extendleft(C)
                C = []
            elif len(C) == 1:
                S.extendleft(C)
                C = []
            if len(B) > 0:
                S.extend(B)
                B = []
        A += 1
    elif a[1] == '1':
        B.append(a[2])
    else:
        C.append(a[2])

if a[0] != '1':
    if A%2==0:
        if len(B)>1:
            B.reverse()
            S.extendleft(B)
            B = []
        elif len(B) == 1:
            S.extendleft(B)
            B = []
        if len(C) > 0:
            S.extend(C)
            C = []
    else:
        if len(C)>1:
            C.reverse()
            S.extendleft(C)
            C = []
        elif len(C) == 1:
            S.extendleft(C)
            C = []
        if len(B) > 0:
            S.extend(B)
            B = []

if A%2 != 0:
    print(S)
    S.reverse()
    print(S)
print(''.join(S))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#D
from collections import deque
Str = str(input())
Q = int(input())
S = deque()
S.append(Str)
A = 0
B = []
C = []

for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        if A%2==0:
            if len(B)>1:

                S.extendleft(B)
                B = []
            elif len(B) == 1:
                S.extendleft(B)
                B = []
            if len(C) > 0:
                S.extend(C)
                C = []
        else:
            if len(C)>1:
 
                S.extendleft(C)
                C = []
            elif len(C) == 1:
                S.extendleft(C)
                C = []
            if len(B) > 0:
                S.extend(B)
                B = []
        A += 1
    elif a[1] == '1':
        B.append(a[2])
    else:
        C.append(a[2])

if a[0] != '1':
    if A%2==0:
        if len(B)>1:

            S.extendleft(B)
            B = []
        elif len(B) == 1:
            S.extendleft(B)
            B = []
        if len(C) > 0:
            S.extend(C)
            C = []
    else:
        if len(C)>1:

            S.extendleft(C)
            C = []
        elif len(C) == 1:
            S.extendleft(C)
            C = []
        if len(B) > 0:
            S.extend(B)
            B = []

if A%2 != 0:
    S.reverse()
print(''.join(S))

Submission status: Wrong Answer

Solution code:
#D
from collections import deque
Str = str(input())
Q = int(input())
S = deque()
S.append(Str)
A = 0
B = []
C = []

for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        if A%2==0:
            if len(B)>1:
                B.reverse()
                S.extendleft(B)
                B = []
            elif len(B) == 1:
                S.extendleft(B)
                B = []
            if len(C) > 0:
                S.extend(C)
                C = []
        else:
            if len(C)>1:
                C.reverse()
                S.extendleft(C)
                C = []
            elif len(C) == 1:
                S.extendleft(C)
                C = []
            if len(B) > 0:
                S.extend(B)
                B = []
        A += 1
    elif a[1] == '1':
        B.append(a[2])
    else:
        C.append(a[2])

if a[0] != '1':
    if A%2==0:
        if len(B)>1:
            B.reverse()
            S.extendleft(B)
            B = []
        elif len(B) == 1:
            S.extendleft(B)
            B = []
        if len(C) > 0:
            S.extend(C)
            C = []
    else:
        if len(C)>1:
            C.reverse()
            S.extendleft(C)
            C = []
        elif len(C) == 1:
            S.extendleft(C)
            C = []
        if len(B) > 0:
            S.extend(B)
            B = []

if A%2 != 0:
    S.reverse()
print(''.join(S))

Submission status: Wrong Answer

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

S = deque(input())
Q = int(input())
lst = deque()

for i in range(Q):
    tmp = list(input().split())
    lst.append(tmp)

reverse = 0
c = 1
for i in range(Q):

    if int(lst[i][0]) == 1:
        reverse += 1
        c += 1
    
    if int(lst[i][0]) == 2:
        if c%2 == 1:
            if int(lst[i][1]) == 1:
                S.appendleft(lst[i][2])
            else:
                S.append(lst[i][2])
        else:
            if int(lst[i][1]) == 2:
                S.appendleft(lst[i][2])
            else:
                S.append(lst[i][2])

if reverse%2 == 1:
    S.reverse()

ans = "".join(S)
print(ans)

Submission status: Wrong Answer

Solution code:
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") ^ reverse:
            S = C + S
        else:
            S = S + C


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

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()

q = int(input())
s = deque(s, maxlen=len(s) + q)
r = False
for _ in range(q):
    cmd = input()
    if cmd[0] == '1':
        r = not r
    else:
        cmd, f, c = cmd.split()
        if (f == '1' and not r) and (f=='2' and r):
            s.append(c)
        else:
            s.appendleft(c)
if r:
    s.reverse()
print(''.join(s))

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()

q = int(input())
s = deque(s, maxlen=len(s) + q)
r = False
for _ in range(q):
    cmd = input()
    if cmd[0] == '1':
        r = not r
    else:
        cmd, f, c = cmd.split()
        if (f == '2' and not r) and (f=='1' and r):
            s.append(c)
        else:
            s.appendleft(c)
if r:
    s.reverse()
print(''.join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
q = int(input())
l = []
r = False
for _ in range(q):
    cmd = input()
    if cmd[0] == '1':
        s.reverse()
        r = not r
    else:
        cmd, f, c = cmd.split()
        if (f == '1' and not r) and (f=='2' and r):
            s.append(c)
        else:
            l.append(c)
if r:

    print(''.join(s) + ''.join(l))
else:
    l.reverse()
    print(''.join(l) + ''.join(s))

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
d = deque()
num = 0
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1 :
            num += 1
        else:
            if num %2 == 1:
                d.reverse()
            num = 0   
            f = int(data[1])
            c = data[2]
            if f == 1:
                d.appendleft(c)
            else:
                d.append(c)

s = list(d)
s = "".join(s)



print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
d = deque()
num = 0
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1:
            tmp = d.pop()
            d[len(d)-1] = d[0]
            d[0] = tmp
        else:
            f = int(data[1])
            c = data[2]
            if f == 1:
                d.appendleft(c)
            else:
                d.append(c)

s = list(d)
s = "".join(s)



print(s)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
for i in range(q):
    t = input().split(' ')
    if t[0] == '1':
        s = s[-1] + s[1:-1] + s[0]
    else:
        if t[1] == '1':
            s = t[2] + s
        else:
            s = s + t[2]
print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

que = deque()

for s in S:
    que.append(s)

for _ in range(Q):
    query = input().split()

    if query[0] == "1":
        r = que.pop()
        l = que.popleft()
        que.append(l)
        que.appendleft(r)
    else:
        if query[1] == "1":
            que.appendleft(query[2])
        else:
            que.append(query[2])


print("".join(list(que)))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
cnt = 0
s = S
t = ''
for i in range(len(S)):
  t += S[-i]
for _ in range(Q):
  q = input()
  if q[0] == '1':
    cnt += 1
  if q[0] == '2':
    _, f, c = q.split()
    if cnt % 2 == 0:
      if f == '1':
        s = c + s
        t = t + c
      if f == '2':
        s = s + c
        t = c + t
    else:
      if f == '1':
        s = s + c
        t = c + t
      if f == '2':
        s = c + s
        t = t + c
if cnt % 2 == 0:
  print(s)
else:
  print(t)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
cnt = 0
s = S
for _ in range(Q):
  q = input()
  if q[0] == '1':
    cnt += 1
  if q[0] == '2':
    _, f, c = q.split()
    if cnt % 2 == 0:
      if f == '1':
        s = c + s
      if f == '2':
        s = s + c
    else:
      if f == '1':
        s = s + c
      if f == '2':
        s = c + s
if cnt % 2 == 0:
  print(s)
else:
  ans = ''
  for i in range(len(s)):
    ans += s[-i]
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
from collections import deque

s=input()
Q=deque([])
for c in s:
    Q.append(c)
q=int(input())
rev=1
for _ in range(q):
    opt=list(input().split())
    if(opt[0]=="1"):
        rev=1-rev
    else:
        f=int(opt[1])
        if(rev==1):
            f=3-f
        if(f==1):
            Q.appendleft(opt[2])
        else:
            Q.append(opt[2])
if(rev==1):
    Q.reverse()
print("".join(map(str,Q)))

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
d1 = deque()
d2 = deque()
d3 = deque()
num = 0
for i in s:
    d2.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1:
            if len(d2) != 1:
                num += 1
        else:
            f = int(data[1])
            c = data[2]
            if f == 1:
                d1.append(c)
            else:
                d3.append(c)
if num % 2 == 1:
    d1.reverse()
    d2.reverse()
    d3.reverse()
s1 = list(d1)
s1 = "".join(s1)
s2 = list(d2)
s2 = "".join(s2)
s3 = list(d3)
s3 = "".join(s3)


print(s3+s2+s1)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
from collections import deque

s=input()
Q=deque([])
for c in s:
    Q.append(c)
q=int(input())
rev=1
for _ in range(q):
    opt=list(input().split())
    if(opt[0]=="1"):
        rev^=1
    else:
        f=int(opt[1])
        if(rev==1):
            f=3-f
        if(f==1):
            Q.appendleft(opt[2])
        else:
            Q.append(opt[2])
if(rev==1):
    Q.reverse()
for ch in Q:
    print(ch,end="")

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
d = deque()
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1:
            if len(d) != 1:
                tmp1 = d.pop()
                tmp2 = d.popleft()
                d.appendleft(tmp1)
                d.append(tmp2)
        else:
            f = int(data[1])
            c = data[2]
            if f == 1:
                d.appendleft(c)
            else:
                d.append(c)
d.reverse()
s = list(d)
s = "".join(s)
print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
d = deque()
for i in s:
  d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1:
            if len(d) != 1:
                tmp1 = d.pop()
                tmp2 = d.popleft()
                d.appendleft(tmp1)
                d.append(tmp2)
        else:
            f = int(data[1])
            c = data[2]
            if f == 1:
                d.appendleft(c)
            else:
                d.append(c)
            
s = list(d)
s = "".join(s)
print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
d = deque()
d.append(s)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1:
            if len(d) != 1:
                tmp1 = d.pop()
                tmp2 = d.popleft()
                d.appendleft(tmp1)
                d.append(tmp2)
        else:
            f = int(data[1])
            c = data[2]
            if f == 1:
                d.appendleft(c)
            else:
                d.append(c)
            
s = list(d)
s = "".join(s)
print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
d = deque()
d.append(s)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1:
            if len(s) != 1:
                tmp1 = d.pop()
                tmp2 = d.popleft()
                d.appendleft(tmp2)
                d.append(tmp1)
        else:
            f = int(data[1])
            c = data[2]
            if f == 1:
                d.appendleft(c)
            else:
                d.append(c)
            
s = list(d)
s = "".join(s)
print(s)