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:
from collections import deque
S = deque([i for i in input()])
Q = int(input())
#list = [['1', "0", "0"] for i in range(Q) ]
for i in range(Q):
    a = input()
    if a[0] == '2':
        #p, q, r = map(str, a.split())
        if a[2] == "1":
            S.appendleft(a[4])
        else:
            S.append(a[4])
    else:
        S[0], S[-1] = S[-1], S[0]
ans = ""
N = len(S)
for i in range(N):
    ans = ans + S.popleft()
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque([i for i in input()])
Q = int(input())
#list = [['1', "0", "0"] for i in range(Q) ]
flag = False
for i in range(Q):
    a = input()
    if a[0] == '2':
        p, q, r = map(str, a.split())
        if q == "1":
            S.appendleft(r)
        else:
            S.append(r)
    else:
        S[0], S[-1] = S[-1], S[0]
ans = ""
N = len(S)
for i in range(N):
    ans = ans + S.popleft()
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque([i for i in input()])
Q = int(input())
#list = [['1', "0", "0"] for i in range(Q) ]
for i in range(Q):
    a = input()
    if a[0] == '2':
        p, q, r = map(str, a.split())
        if q == "1":
            S.appendleft(r)
        else:
            S.append(r)
    else:
        tmp = S[0]
        S[0] = S[-1]
        S[-1] = tmp
ans = ""
N = len(S)
for i in range(N):
    ans = ans + S.popleft()
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque([i for i in input()])
Q = int(input())
list = [['1', "0", "0"] for i in range(Q) ]
for i in range(Q):
    a = input()
    if a[0] == '2':
        p, q, r = map(str, a.split())
        if q == "1":
            S.appendleft(r)
        else:
            S.append(r)
    else:
        tmp = S[0]
        S[0] = S[-1]
        S[-1] = tmp
ans = ""
N = len(S)
for i in range(N):
    ans = ans + S.popleft()
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque([i for i in input()])
Q = int(input())
list = [['1', "0", "0"] for i in range(Q) ]
for i in range(Q):
    a = input()
    if a[0] == '2':
        p, q, r = map(str, a.split())
        if q == "1":
            S.appendleft(r)
        else:
            S.append(r)
    else:
        tmp = S[0]
        S[0] = S[-1]
        S[-1] = tmp
ans = ""
for i in range(len(S)):
    ans = ans + S.popleft()
print(ans)

Submission status: Wrong Answer

Solution code:
ans=input()
q=int(input())
ls=[input()for _ in range(q)]
be=""
af=""

for i in range(q):
  if ls[i][0]=="1":
    if i>=1 and i!=q-1:
      if ls[i+1][0]=="1" or ls[i-1][0]=="1":
        continue
      
      else:
        ans=(be+ans+af)[::-1]
        be,af="",""
        
    else:
      if i==0 and ls[i+1][0]=="1":
        continue
        
      elif i==q-1 and ls[i-1][0]=="1":
        continue
        
      else:
        ans=(be+ans+af)[::-1]
        be,af="",""
      
  elif ls[i][2]=="1":
    be=ls[i][4]+be
    
  else:
    af+=ls[i][4]
    
print(be+ans+af if be!="" or af!="" else ans)

Submission status: Wrong Answer

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

rev = False
head = []
tail = []

for i in range(q):
    query = input()
    if query == "1":
        rev = not rev
    else:
        _, f, c = query.split()
        if (not rev and f == "1") or (rev and f == "2"):
            head.append(c)
        else:
            tail.append(c)

if not rev:
    res = head[::-1] + s + tail
else:
    res = tail[::-1] + s + head

print(*res, sep="")

Submission status: Wrong Answer

Solution code:
import math
S=input()
Q=int(input())
Rev=1
front=""
back=""
for i in range(Q):
    a=input()
    if a=="1":
        Rev=Rev*-1
    else:
        b,c,x=a.split()
        if (c=="1"and Rev==1) or (c=="2" and Rev==-1):
            front+=a[2]
        else:
            back+=a[2]
if Rev==1:
    S=S[::-1]
print(front[::-1]+S+back)

Submission status: Wrong Answer

Solution code:
import math
S=input()
Q=int(input())
Rev=1
front=""
back=""
for i in range(Q):
    a=input().split()
    if a[0]=="1":
        Rev=Rev*-1
        continue
    if (a[1]=="1"and Rev==1) or (a[1]=="2" and Rev==-1):
        front+=a[2]
    else:
        back+=a[2]
print(front)
if Rev==1:
    #str(front.reverse().extend(S).extend(back))
    print(front[::-1]+S+back)
    #str(front.reverse()+S+back)
else:
    print(back[::-1]+S[::-1]+front)

Submission status: Wrong Answer

Solution code:
from collections import deque
s=input()
q=int(input())
t=[input() for i in range(q)]

l=deque([s])
for i in range(q):
  if int(t[i][0])==1:
    l.reverse()
  else:
    if int(t[i][2])==1:
      l.appendleft(t[i][4]) 
    else:
      l.append(t[i][4])
print(''.join(l))

Submission status: Wrong Answer

Solution code:
s=input()
q=int(input())
t=[input() for i in range(q)]

l=[s]
for i in range(q):
  if int(t[i][0])==1:
    l.reverse()
  else:
    if int(t[i][2])==1:
      l.insert(0,t[i][4]) 
    else:
      l.extend(t[i][4])
print(''.join(l))

Submission status: Wrong Answer

Solution code:
import math
S=input()
Q=int(input())
Rev=1
front=""
back=""
for i in range(Q):
    a=input().split()
    if a[0]=="1":
        Rev=Rev*-1
        continue
    if a[1]=="1":
        if Rev==1:
            front=a[2]+front
        else:
            back=a[2]+back
    else:
        if Rev==1:
            back=back+a[2]
        else:
            front=front+a[2]

if Rev==1:
    #str(front.reverse().extend(S).extend(back))
    print(front[::-1]+S+back)
    #str(front.reverse()+S+back)
else:
    print(back[::-1]+S[::-1]+front)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
que = [0]*Q
count = 0
flag = True
flist = []
llist = []

for i in range(Q):
    que[i] = list(map(str, input().split()))
for i in que:
    if len(i) == 1:
        count += 1
        flag = not flag
    else:
        if i[1] == 1 and flag:
            flist.append(i[2])
        elif i[1] == 2 and not flag:
            flist.append(i[2])
        elif i[1] == 1 and not flag:
            llist.append(i[2])
        else:
            llist.append(i[2])

F = ''.join(flist)
L = ''.join(llist)

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

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
flip = False
head = ''
tail = ''
for _ in range(Q):
    q = input()
    if q == '1':
        flip = not flip
        head, tail = tail, head
    else:
        _, f, c = q.split()
        if f == '1':
            head += c
        else:
            tail += c
#if flip:
    #S = S[::-1]
print(head[::-1] + S + tail)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s  = input()
q  = int(input())
inv = 1
sfb = [0,"",""]
for i in range(q):
    ls = list(input().split())
    if ls[0] == "1":
        inv *=-1
    else:
        f,c = ls[1:]
        if f == "1":
            sfb[inv] +=c
        else:
            sfb[-inv] +=c

ans = sfb[1][::-1] + s + sfb[-1]
print(ans[::inv])

Submission status: Wrong Answer

Solution code:
ans=input()
q=int(input())
qu=[input()for _ in range(q)]

for i in range(q):
  
  if i<q-1:
    if qu[i][0]=="1":
      if qu[i+1]=="1" or qu[i-1]=="1":
        continue
        
      else:
        ans=ans[::-1]
    
    else:
      if qu[i][2]=="1":
        ans=qu[i][4]+ans
      else:
        ans=ans+qu[i][4]
        
  if i==q-1:
    if qu[i][0]=="1":
      if qu[i-1]=="1":
        break
        
      else:
        ans=ans[::-1]
      
    else:          
      if qu[i][2]=="1":
        ans=qu[i][4]+ans
          
      else:
        ans=ans+qu[i][4]
      
print(ans)

Submission status: Wrong Answer

Solution code:
import math
S=[input()]
Q=int(input())
Rev=1
front=[]
back=[]
for i in range(Q):
    Qu=input()
    if Qu=="1":
        Rev=Rev*-1
        continue
    A,B,moji=Qu.split()
    if B=="1":
        if Rev==1:
            front.append(moji)
        else:
            back.append(moji)
    else:
        if Rev==1:
            back.append(moji)
        else:
            front.append(moji)
    moji=""

if Rev==1:
    #str(front.reverse().extend(S).extend(back))

    front.reverse()
    front.extend(S)
    front.extend(back)
    print("".join(front))
    #str(front.reverse()+S+back)
else:
    back.reverse()
    S.reverse()
    back.extend(S)
    back.extend(front)
    print("".join(back))

Submission status: Wrong Answer

Solution code:
import math
S=[input()]
Q=int(input())
Rev=1
front=[]
back=[]
for i in range(Q):
    Qu=input()
    if Qu=="1":
        Rev=Rev*-1
        continue
    A,B,moji=Qu.split()
    if B=="1":
        if Rev==1:
            front.append(moji)
        else:
            back.append(moji)
    else:
        if Rev==1:
            back.append(moji)
        else:
            front.append(moji)
    moji=""

if Rev==1:
    #str(front.reverse().extend(S).extend(back))

    front.reverse()
    front.extend(S)
    front.extend(back)
    print("".join(front))
    #str(front.reverse()+S+back)
else:
    back.reverse()
    back.extend(S)
    back.extend(front)
    print("".join(back))

Submission status: Wrong Answer

Solution code:
import math
S=[input()]
Q=int(input())
Rev=1
front=[]
back=[]
for i in range(Q):
    Qu=input()
    if Qu=="1":
        Rev=Rev*-1
        continue
    A,B,moji=Qu.split()
    if B=="1":
        if Rev==1:
            front.append(moji)
        else:
            back.append(moji)
    else:
        if Rev==1:
            back.append(moji)
        else:
            front.append(moji)

if Rev==1:
    #str(front.reverse().extend(S).extend(back))

    front.reverse()
    front.extend(S)
    front.extend(back)
    print("".join(front))
    #str(front.reverse()+S+back)
else:
    back.reverse()
    back.extend(S)
    back.extend(front)
    print("".join(back))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = input()
q = int(input())
c = []
for i in range(q):
  que = input().split()
  c_append = c.append
  c_append(que)
  
for i in c:
  if i[0] == '1':
    s = s[::-1]
  else:
    if i[1] == '1':
      s = i[2] + s
    else:
      s = s + i[2]
print(s)

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    n = int(input())
    pre = ''
    suf = ''
    r = 1
    for _ in range(n):
        q = input().split()
        if len(q) == 1:
            r *= -1
            continue
        if r * int(q[1]) in (1, -2):
            pre = q[2] + pre
        else:
            suf += q[2]
    ans = pre + s + suf
    if r == -1:
        ans = s[::-1]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
from math import floor,ceil
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n').split(' ')]
def li3():return [int(i) for i in input().rstrip('\n')]


s = st()
q = val()
l = []

cou = 0

d = deque()
for i in s:d.append(i)


for j in range(q):
    l = li2()
    if len(l) == 1:cou = not cou
    else:
        if cou:
            a = 3 - int(l[1])
        else:a = int(l[1])
        if a == 1:
            d.append(l[-1])
        else:d.appendleft(l[-1])

s = ''.join(e for e in d)
if not cou:s = s[::-1]
print(s)

Submission status: Wrong Answer

Solution code:
li1=[]
li2=[]

def sousa(even,li):
    global li1,li2
    if even:
        if(li[1]=="1"):
            li1.insert(0,li[2])
        else:
            li2.append(li[2])
    else:
        if(li[1]=="1"):
            li2.append(li[2])
        else:
            li1.insert(0,li[2])

s = input()
q = int(input())
li = []
rev_list=[]
for i in range(q):
    li.append(input().split())
    if(li[i][0]=="1"):
        rev_list.append(int(i))

start_ind=0
even=False
if(len(rev_list)%2==0):
    even=True
for i in range(len(rev_list)):
    for j in range(start_ind,rev_list[i]):
        if even:
            sousa(True,li[j])
        else:
            sousa(False,li[j])
    start_ind=rev_list[i]+1
    if even:
        even=False
    else:
        even=True
    # print("str",start_ind)
    # print("rev",rev_list[i])

if(len(rev_list)!=0):
    for i in range(len(li)-rev_list[-1]-1):
        sousa(even,li[i+start_ind])
else:
    for i in range(len(li)):
        sousa(even,li[i])

print("".join(li1)+s+"".join(li2))

Submission status: Wrong Answer

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

    from collections import deque
    strings = deque([S])
    switch = 0
    for _ in range(Q):
        line = input()
        if line.startswith('1'):
            switch ^= 1
            continue
        _, n, char = line.split()
        if n == '1':
            if switch == 0:
                strings.append(char)
            else:
                strings.appendleft(char)
        else:
            if switch == 0:
                strings.appendleft(char)
            else:
                strings.append(char)

    if not switch:
        print(''.join(strings)[::-1])
    else:
        print(''.join(strings))
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    S = input()
    Q = int(input())
    strings = [S, S]

    switch = 0
    for _ in range(Q):
        line = input()
        if line.startswith('1'):
            switch ^= 1
            continue
        _, n, char = line.split()
        if n == '1':
            strings[switch] = char + strings[switch]
            strings[switch^1] = strings[switch^1] + char
        else:
            strings[switch] = strings[switch] + char
            strings[switch^1] = char + strings[switch^1]
    print(strings[switch])
resolve()

Submission status: Wrong Answer

Solution code:
S = input()
numQ = int(input())
lead = 1

for i in range(numQ):
  Q = input()
  if Q[0] == "1":
    lead *= -1
  else:
    if Q[2] == 1:
      if lead == 1:
        S = Q[4] + S
      else:
        S = S + Q[4]
    else:
      if lead == 1:
        S = S + Q[4]
      else:
        S = Q[4] + S
if lead == -1:
  S = S[::-1]

print(S)

Submission status: Wrong Answer

Solution code:
S = input()
numQ = int(input())
lead = 1

for i in range(numQ):
  Q = input()
  if Q[0] == "1":
    lead *= -1
  else:
    if Q[1] == 1:
      if lead == 1:
        S = Q[2] + S
      else:
        S = S + Q[2]
    else:
      if lead == 1:
        S = S + Q[2]
      else:
        S = Q[2] + S
if lead == -1:
  S = S[::-1]

print(S)

Submission status: Wrong Answer

Solution code:
S=input()
QN=int(input())
front=''
rear=''
rev=False

for i in range(QN):
    op=input()
    if op[0]=='1':
        rev=not(rev)
    else:
        if op[2]=='1':
            if rev:
                rear+=op[4]
            else:
                front+=op[4]
        else:
            if rev:
                front+=op[4]
            else:
                rear+=op[4]

if rev:
    print(rear[::-1]+S+front)
else:
    print(front[::-1]+S+rear)

Submission status: Wrong Answer

Solution code:
from collections import deque

S = input()
Q = int(input())
right, left = deque(), deque()
right_inv, left_inv, S_inv = False, False, False

for q in range(Q):
  T = input().split(" ")
  if len(T) == 1:
    # reverse
    S_inv = not S_inv
    right_inv = not right_inv
    left_inv = not left_inv
  else:
    # append
    F, C = int(T[1]), T[2]
    if F ^ S_inv:
      left.appendleft(C)
    else:
      right.append(C)

if S_inv:
  print(''.join(list(right)[::-1]), S[::-1], ''.join(list(left)[::-1]), sep='')
else:
  print(''.join(list(left)), S, ''.join(list(right)), sep='')

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque
    s = deque(input().split())
    q = int(input())
    rev = False
    for i in range(q):
        l = input().split()
        if l[0] == "2":
            flag = int(l[1])
            flag -= 1
            if rev: flag ^= 1
            if flag == 1:
                s.append(l[2])
            else:
                s.appendleft(l[2])
        else:
            rev = not rev
    if rev:
        s.reverse()
        print("".join(s))
    else:
        print("".join(s))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque
    s = list(input().split())
    left = deque()
    right = deque()
    q = int(input())
    rev = False
    for i in range(q):
        l = input().split()
        if int(l[0]) == 2:
            flag = int(l[1])
            flag -= 1
            if rev: flag = 1 - flag
            if flag == 1:
                right.append(l[2])
            else:
                left.appendleft(l[2])
        else:
            rev = False if rev else True
    left = list(left)
    right = list(right)
    if rev:
        print("".join(right[::-1]+s[::-1]+left[::-1]))
    else:
        print("".join(left+s+right))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque
    s = list(input().split())
    left = deque()
    right = deque()
    q = int(input())
    rev = False
    for i in range(q):
        l = input().split()
        if int(l[0]) == 2:
            flag = int(l[1])
            flag -= 1
            if rev: flag = 1 - flag
            if flag:
                right.append(l[2])
            else:
                left.appendleft(l[2])
        else:
            rev = False if rev else True
    left = list(left)
    right = list(right)
    if rev:
        print("".join(right[::-1]+s[::-1]+left[::-1]))
    else:
        print("".join(left+s+right))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque
    s = input().split()
    left = deque()
    right = deque()
    q = int(input())
    rev = False
    for i in range(q):
        l = input().split()
        if int(l[0]) == 2:
            if int(l[1]) == 1:
                if rev:
                    right.append(l[2])
                else: left.appendleft(l[2])
            else:
                if rev:
                    left.appendleft(l[2])
                else: right.append(l[2])
        else:
            rev = False if rev else True
    left = list(left)
    right = list(right)
    if rev:
        print("".join(right[::-1]+list(reversed(s))+left[::-1]))
    else:
        print("".join(left+list(s)+right))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque
    s = input().split()
    left = deque()
    right = deque()
    q = int(input())
    rev = False
    for i in range(q):
        l = input().split()
        if int(l[0]) == 2:
            if int(l[1]) == 1:
                if rev:
                    right.append(l[2])
                else: left.appendleft(l[2])
            else:
                if rev:
                    left.appendleft(l[2])
                else: right.append(l[2])
        else:
            rev = False if rev else True
    if rev:
        tmp_left = deque(reversed(left))
        tmp_right = deque(reversed(right))
        left = tmp_right
        right = tmp_left
        print("".join(list(left)+list(reversed(s))+list(right)))
    else:
        print("".join(list(left)+list(s)+list(right)))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

s=input()
n=int(input())
q=deque()
q.append(s)
f=0
for i in range(n):
    t=list(input().split())
    if int(t[0])==1:
        f+=1
    else:
        if f%2==0:
            if t[1]=='1' :
                q.appendleft(t[2])
            else:
                q.append(t[2])
        else:
            if t[2]=='2':
                q.appendleft(t[2])
            else:    
                q.append(t[2])
if f%2==1:
    q=reversed(q)

ans=''.join(q)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

s=input()
n=int(input())
q=deque()
q.append(s)
f=0
for i in range(n):
    t=list(input().split())
    if int(t[0])==1:
        f+=1
    else:
        if (int(t[1])==1 and f%2==0) or (int(t[1])==2 and f%2==1):
            q.appendleft(t[2])
        else:
            q.append(t[2])

if f%2==1:
    q=reversed(q)

ans=''.join(q)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
Right = ''
Left = ''
Q = int(input())
flag = 0
for i in range(Q):
    P = [a for a in input().split()]
    if len(P) == 1:
        flag = (flag + 1) % 2
    else:
        if flag == 0:
            if int(P[1]) == 2:
                Right += P[2]
            else:
                Left += P[2]
        else:
            if int(P[1]) == 1:
                Right += P[2]
            else:
                Left += P[2]

if flag == 0:
    S = Left[::-1] + S + Right
    print(S)
else:
    S = Right[::-1] + S + Left
    print(S)

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque
    s = input().split()
    left = deque()
    right = deque()
    q = int(input())
    cnt = 0
    for i in range(q):
        l = input().split()
        if int(l[0]) == 2:
            if int(l[1]) == 1:
                left.appendleft(l[2])
            else:
                right.append(l[2])
        else:
            cnt += 1
            tmp_left = deque(reversed(left))
            tmp_right = deque(reversed(right))
            left = tmp_right
            right = tmp_left
    if cnt % 2 == 0:
        print("".join(list(left)+list(s)+list(right)))
    else:
        print("".join(list(left)+list(reversed(s))+list(right)))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque
    import sys
    input = sys.stdin.readline
    s = deque(input().rstrip().split())
    q = int(input())
    for i in range(q):
        l = input().split()
        if int(l[0]) == 1:
            s.reverse()
        else:
            if int(l[1]) == 1:
                s.appendleft(l[2])
            else:
                s.append(l[2])
    print("".join(s))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

s=input()
n=int(input())
q=deque()
q.append(s)
for i in range(n):
    t=list(input().split())
    if t[0]=='1':
        l=reversed(list(q))
        q=deque(l)
    else:
        if t[1]=='1':
            q.appendleft(t[2])
        else:
            q.append(t[2])

print(''.join(q))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
revflag = 0
before = ""
after = ""

for i in query:
    if i[0] == '1':
        revflag = 1 - revflag
    else:
        if (revflag == 0 and i[1] == '1') or (revflag == 1 and i[1] == '2'):
            before += i[2]
        else:
            after += i[2]

if revflag == 0:
    print(before[::-1]+S+after)
else:
    print((after+S)[::-1]+before)

Submission status: Wrong Answer

Solution code:
a = input()
n = int(input())
rev = False
front = []
back = []
q = [input() for i in range(n)]
for i in q:
    if i == "1":
        rev = not rev
    else:
        i,f,c = i.split()
        if rev == False:
            if f == "1":
                front.append(c)
            else:
                back.append(c)
        else:
            if f == "1":
                back.append(c)
            else:
                front.append(c)
if rev == False:
    print("".join(list(reversed(front))+[a]+back))
else:
    print("".join(list(reversed([a]+back))+front))

Submission status: Wrong Answer

Solution code:
a = input()
n = int(input())
rev = False
front = []
back = []
q = [input() for i in range(n)]
for i in q:
    if i == "1":
        rev = not rev
    else:
        i,f,c = i.split()
        if rev == False:
            if f == "1":
                front.append(c)
            else:
                back.append(c)
        else:
            if f == "1":
                back.append(c)
            else:
                front.append(c)
if rev == False:
    print("".join(list(reversed(front))+[a]+back))
else:
    print("".join(list(reversed(back))+[a]+front))

Submission status: Wrong Answer

Solution code:
from collections import deque

S=list(input())
Q=int(input())
cnt=0
for i in range(Q):
    a=list(map(str,input().split()))

    if a[0]=='1':
        cnt+=1
        cnt%=2
    else:
        if (cnt+int(a[1]))%2==0:
            S.insert(0,a[2])
        else:
            S.append(a[2])
            
S.reverse()
S="".join(S)
print(S)

Submission status: Wrong Answer

Solution code:
S=list(input())
Q=int(input())
cnt=0
for i in range(Q):
    a=list(map(str,input().split()))
    if a[0]=='1':
        cnt+=1
    elif a[0]=='2':
        if a[1]=='1':
            if cnt%2==0:
                S.insert(0,a[2])
            else:
                S.append(a[2])
        elif a[1]=='2':
            if cnt%2==0:
                S.append(a[2])
            else:
                S.insert(0,a[2])

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

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque(list(input()))
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if (int(b[0]) + f) % 2 == 0 :
      S.append(b[1])
    else:
      S.appendleft(b[1])
for i in range(len(S)):
  if f % 2 == 1:
    print (S[-i-1], end="")
  else:
    print (*S, sep="")

Submission status: Wrong Answer

Solution code:
S=input()
Q=int(input())
A= [input().split() for i in range(Q)]

from collections import deque
ans = deque()
tmp=0
ans.append(S)

for li in A:
    if li[0]=='1':
        tmp=(tmp+1)%2
    else:
        if (tmp+int(li[1]))%2 == 1:
            ans.appendleft(li[2])
        else:
            ans.append(li[2])
if tmp == 0:
    re=map(str, list(ans))
    print(''.join(re))
else:
    re=map(str, list(ans)[::-1])
    print(''.join(re))

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque(input().split())
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if (int(b[0]) + f) % 2 == 0 :
      S.appendleft(b[1])
    else:
      S.append(b[1])
for i in range(len(S)):
  if f % 2 == 0:
    print (S[-i-1], end="")
  else:
    print (S[i], end="")

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque(input().split())
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if (int(b[0]) + f) % 2 == 0 :
      S.appendleft(b[1])
    else:
      S.append(b[1])
if f % 2 == 0:
  for i in range(len(S)):
    print (S[-i-1], end="")
    print ()
else:
  print (*S, sep="")

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque(input().split())
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if (int(b[0]) + f) % 2 == 0 :
      S.appendleft(b[1])
    else:
      S.append(b[1])
if f % 2 == 0:
  for i in range(len(S)):
    print (S[-i-1], end="")
else:
  print (*S, sep="")

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque(input().split())
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if int(b[0]) + f % 2 ==0 :
      S.leftappend(b[1])
    else:
      S.append(b[1])
if f % 2 == 0:
  for i in range(len(S)):
    print (S[-i-1], end="")
else:
  print (*S, sep="")

Submission status: Wrong Answer

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

s=input()
q=int(input())
for i in range(q):
  l=list(map(str,input().split()))
  if l[0]=="1":
    s=s[::-1]
  elif l[1]=="1":
    s=l[2]+s
  else:
    s=s+l[2]
print(s)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if int(b[0]) + f % 2 ==0 :
      S = b[1] + S
    else:
      S += b[1]
print (S if f % 2 == 1 else S[::-1])

Submission status: Wrong Answer

Solution code:
import collections


class Formatter:
    def __init__(self, s):
        self._d = collections.deque(s)
        self._reversed = False

    def reverse(self):
        self._reversed = not self._reversed

    def append(self, s):
        if self._reversed:
            self._d.appendleft(s)
        else:
            self._d.append(s)

    def appendleft(self, s):
        if self._reversed:
            self.append(s)
        else:
            self._d.appendleft(s)

    def __iter__(self):
        if self._reversed:
            return reversed(self._d)
        else:
            return iter(self._d)


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

d = Formatter(S)

for _ in range(Q):
    Qi = input()
    if Qi == "1":
        d.reverse()
    else:
        T, F, C = Qi.split()
        if F == "1":
            d.appendleft(C)
        else:
            d.append(C)

print("".join(d))