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())
Qvery = [0]*Q
for i in range(Q):
    Qvery[i] = list(map(str,input().split()))
frontback = 1
tail = ''
head = ''
for i in range(Q):
    if Qvery[i][0]=='1':
        frontback *= -1
        
    else:
        if Qvery[i][1]=='2':
            if frontback == 1:
                tail +=  str(Qvery[i][2])
            else:
                head = str(Qvery[i][2]) + head
        else:
            if frontback == 1:
                head = str(Qvery[i][2])+head
            else:
                tail += str(Qvery[i][2])
if frontback == -1:
    S = S[::-1]
    
print(head+S+tail)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    S = list(input())
    Q = int(input())
    for _ in range(Q):
        qry = input().split(' ')
        if len(qry) == 3:
            f = int(qry[1])
            c = qry[2]
            if f == 1:
                S.insert(0, c)
            if f == 2:
                S.append(c)
        if len(qry) == 1:
            tmp = S[0]
            S[0] = S[-1]
            S[-1] = tmp
    ans = ''
    for s in S:
        ans += s
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

poe=deque([])
S=input()
for i in range(len(S)):
    poe.append(S[i])
Q=int(input())
P=[]
cnt=0
ans=0
for i in range(Q):
    a=list(input().split())
    P.append(a)

for i in range(Q):
    if len(P[i])==1:
        cnt+=1
        ans+=1
    else:
        P[i][1]=int(P[i][1])+cnt
        if P[i][1]%2==1:
            poe.appendleft(P[i][2])
        else:
            poe.append(P[i][2])
        cnt=0

poe=list(poe)
if ans%2==1:
    poe=poe[::-1]
print(''.join(poe))

Submission status: Wrong Answer

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

flag = True
lS = ''
for _ in range(Q):
    query = input()
    if query[0] == '1':
        flag = not flag
    else:
        _, f, c = query.split()
        if (f == '1' and flag) or (f == '2' and not flag):
            lS += c
        else:
            S += c
if not flag:
    S = S + lS
else:
    S = lS[::-1] + S[::-1]
print(S)

Submission status: Wrong Answer

Solution code:


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
from collections import deque


def main():
    mod=10**9+7
    S=input()
    
    from collections import deque
    dq=deque()
    
    for c in S:
        dq.append(c)
        
    rev=0
    Q=I()
    for _ in range(Q):
        q=input().split()
        if q[0]=="1":
            rev=(rev+1)%2
        else:
            f=int(q[1])
            c=q[2]
            
            if (rev+f)%2==1:
                dq.append(c)
            else:
                dq.appendleft(c)
                
    ans=[]
    if rev:
        while dq:
            ans.append(dq.popleft())
    else:
        while dq:
            ans.append(dq.pop())
            
    print(''.join(map(str, ans)))
        

        

main()

Submission status: Wrong Answer

Solution code:
s = str(input())
q = int(input())
Q = []
rv = 0
for i in range(q):
    l = list(map(str, input().split()))
    t = int(l[0])
    if t == 1:
        rv += 1
    else:
        f, c = int(l[1]), l[2]
        Q.append((f, c))
rv = rv % 2
if rv == 1:
    s = s[::-1]
    for m in Q:
        f, c = m
        if f == '1':
            s = c+s
        else:
            s = s+c
else:
    for m in Q:
        f, c = m
        if f == '1':
            s = s+c
        else:
            s = c+s
print(s)

Submission status: Wrong Answer

Solution code:
import sys
S = input()
Q = int(input())
key = 1

for i in sys.stdin:
    if i[0] == '0':
        break

    if i[0] == '1':
        key = -key
    
    else:
        if i[2] == '1':
            key = -key
            S = S[::-1]
        
        S = S + i[4]


print(S[::key])

Submission status: Wrong Answer

Solution code:
import sys
S = input()
Q = int(input())
key = 1

for i in sys.stdin:
    if i[0] == '1':
        key = -key
    
    else:
        S = S + i[4]

        if i[2] == '1':
            key = -key

print(S[::key])

Submission status: Wrong Answer

Solution code:
S = input()

import collections as col
S = col.deque(list(S))

N = int(input())

reversi = 0

for i in range(N):
	L = list(map(str, input().split()))
	if len(L) == 1:
		reversi = reversi^1
	else:
		if reversi == 1:
			if L[1] == 1:
				S.append(L[2])
			else:
				S.appendleft(L[2])
		else:
			if L[1] == 2:
				S.append(L[2])
			else:
				S.appendleft(L[2])

S = list(S)
if reversi == 1:
	print(*S[::-1], sep="")
else:
	print(*S, sep="")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
print(query)
forward = 1
for i in range(Q):
    if query[i][0] == '1':
        forward *= -1
    else:
        if query[i][1] == '1':
            if forward == 1:
                S = query[i][2] + S
            else:
                S = S + query[i][2] 
        else:
            if forward == 1:
                S = S + query[i][2] 
            else:
                S = query[i][2] + S

if forward == -1:
    ans = ''
    for i in range(len(S)):
        ans += S[-i-1]
else:
    ans = S
print(ans)

Submission status: Wrong Answer

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

    reverse = 0
    head = ""
    tail = ""

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

    s = head[::-1] + s + tail
    if reverse % 2 == 1:
        s = s[::-1]

    print(s)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s=[i for i in input()]
q=int(input())
t=0
for i in range(q):
  qu=list(input().split())
  if qu[0]=='2':
    if qu[1]=='1' and t==0:
      s=[qu[2]]+s
    elif qu[1]=='1' and t==1:
      s=s+[qu[2]]
    elif qu[1]=='2' and t==0:
      s=s+[qu[2]]
    elif qu[1]=='2' and t==1:
      s=[qu[2]]+s
  else:
    if t==0:
      t=1
    else:
      t=0
print(*s,sep='')

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
head = ''
tail = ''
rev = 0

for _ in range(q):
    T = list(input().split())
    if T[0] == '1':
        rev += 1
    elif T[0] == '2':
        if rev%2 == 0:
            if T[1] == '1':
                head = T[2] + head
            else:
                tail += T[2]
        else:
            if T[1] == '1':
                tail += T[2]
            else:
                head = T[2] + head
    # print(head, s, tail, rev)

if rev%2 == 0:
    print(head+s+tail)
else:
    print(tail[::-1]+s+head[::-1])

Submission status: Wrong Answer

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
def main():
    s = input().split()
    q = int(input())
    query = []
    que = deque(s)
    f = 1
    for i in range(q):
        query.append(input().split(" "))
    for i in range(q):
        if query[i][0] == '1':
            f *= -1
        else:
            if f<0:
                if query[i][1] == '2':
                    que.appendleft(query[i][2])
                else:
                    que.append(query[i][2])
            else:
                if query[i][1] == '1':
                    que.appendleft(query[i][2])
                else:
                    que.append(query[i][2])
    if f<0:
        que.reverse()
    print("".join(que))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

def main():
    s = input().split()
    q = int(input())
    query = []
    f = 1
    for i in range(q):
        query.append(input().split(" "))
    for i in range(q):
        if query[i][0] == '1':
            f *= -1
        else:
            if f<0:
                if query[i][1] == '2':
                    s.insert(0, query[i][2])
                else:
                    s.append(query[i][2])
            else:
                if query[i][1] == '1':
                    s.insert(0, query[i][2])
                else:
                    s.append(query[i][2])
    if f<0:
        s.reverse()
    print("".join(s))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

def main():
    s = input().split()
    q = int(input())
    query = []
    for i in range(q):
        query.append(input().split(" "))
    for i in range(q):
        if query[i][0] == '1':
            s.reverse()
        else:
            if query[i][1] == '1':
                s.insert(0, query[i][2])
            else:
                s.append(query[i][2])
    print("".join(s))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

for i in range(Q):
    if query[i][0] == '1':
        if len(S) > 1:
            S = S[-1] + S[1:-1] + S[0]
        #print(S)
    else:
        if query[i][1] == '1':
            S = query[i][2] + S
        else:
            S = S + query[i][2]
print(S)

Submission status: Wrong Answer

Solution code:
S = input()
N = int(input())
flg = 0
L = []
for i in range(N):
    e = input().split()
    if e[0] == '1':
        flg += 1
        flg = flg%2
    else:
        L.append(((flg+int(e[1]))%2, e[2]))


for f, v in L:
    if (flg+f)%2 == 1:
        S = v + S
    else:
        S = S + v

print(S)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
rev = 1
for i in range(q):
  t = input()
  
  if t == '1':
    rev *= -1
  else:
    x,y,sr = t.split()
    if rev == 1 and y == '2':
      s = s + sr
    else:
      s = sr + s

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

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
rev = 1
for i in range(q):
  t = input()
  
  if t == '1':
    rev *= -1
  else:
    x,y,a = t.split()
    if rev == 1 and y == '2':
      s = s + a
    else:
      s = a + s
if rev == -1:
  s = s[::-1]
  
print(s)

Submission status: Wrong Answer

Solution code:
from sys import stdin
input=stdin.readline
s=input().rstrip()
t=s
q=int(input())
cnt=0
for i in range(q):
  qu=list(input().split())
  if qu[0]=='1':
    cnt+=1
  elif qu[0]=='2':
    if (int(qu[1])+cnt)%2==1:
      s=qu[2]+s
      t=t+qu[2]
    else:
      s=s+qu[2]
      t=qu[2]+t
if cnt%2==0:
  print(s)
else:
  print(t)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
s=input().rstrip()
q=int(input())
t=s
cnt=0
for i in range(q):
  qu=list(input().split())
  if qu[0]=='1':
    cnt+=1
  elif qu[0]=='2':
    if (int(qu[1])+cnt)%2==1:
      s=qu[2]+s
      t=t+qu[2]
    else:
      s=s+qu[2]
      t=qu[2]+t
if cnt%2==0:
  print(s)
else:
  print(t)

Submission status: Wrong Answer

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    s = s_list()
    q = i_input()
    rev = 0
    front = []
    back = []
    for _ in range(q):
        k = s_list()
        if k[0] == "1":
            rev += 1
        else:
            if rev%2==0: # 元と同じ状態
                if k[1] == "1":
                    front.append(k[2])
                else:
                    back.append(k[2])
            else: # 反転
                if k[1] == "1":
                    back.append(k[2])
                else:
                    front.append(k[2])
    if rev%2==0:
        front.reverse()
        print("".join(front)+"".join(s)+"".join(back))
    else:
        back.reverse()
        s.reverse()
        print("".join(back)+"".join(s)+"".join(front))


if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():

    s, q = input().split() , int(input())

    flag = 0
    query = []
    for _ in range(q):
        temp = input().split()
        if len(temp) == 1:
            flag += 1
        else:
            temp += [flag%2]
            query.append(temp)

    for q in query:
        if q[-1] == 0:
            if q[1] == "1":
                s = [q[2]] + s
            else:
                s += [q[2]]
        else:
            if q[1] == "1":
                s += [q[2]]
            else:
                s = [q[2]] + s

    if flag % 2 == 1:
        print("".join(s[::-1]))
    else:
        print("".join(s))

main()

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

L, R = [], []

for i in range(Q):
  if Query[i][0] == "1": L, R = R[::-1], L[::-1]
  else:
    if Query[i][1] == "1": L.insert(0, Query[i][2])
    else: R.append(Query[i][2])

L, R = "".join(L), "".join(R)

print(L + S + R)

Submission status: Wrong Answer

Solution code:

s = input()

q = int(input())
x = []
y = []

flag = 0

for i in range(q):
    li = list(input().split())
    if flag%2 == 0:
        if li[0] == "2":
            if li[1] =="1":
                x.append(li[2])
            else:
                y.append(li[2])
        else:
            s = s[::-1]
            flag += 1


    else:
        if li[0] == "2":
            if li[1] =="1":
                y.append(li[2])
            else:
                x.append(li[2])
        else:
            s = s[::-1]
            flag += 1

if flag//2 == 0:
    print("".join(x)+s+"".join(y))
else:
    print("".join(y)+s+"".join(x))

Submission status: Wrong Answer

Solution code:
S,Q=input(),int(input())
reverse=0
if len(S)==1:l,c,r='',S,''
elif len(S)%2:l,c,r='',S[len(S)//2],''
else:l,c,r=S[0],'',S[-1]
for i in range(Q):
    T=input().split()
    if T[0]=='1':reverse=0 if reverse else 1
    else:
        if T[1]=='1':
            if reverse:r=r+T[2]
            else:l=T[2]+l
        else:
            if reverse:l=T[2]+l
            else:r=r+T[2]
s=list(l+c+r);s.reverse()
print(''.join(s) if reverse else l+c+r)

Submission status: Wrong Answer

Solution code:
S=input()
Q=int(input())
reverse=0
if len(S)==1:l,c,r='',S,''
elif len(S)%2:l,c,r='',S[len(S)//2],''
else:l,c,r=S[0],'',S[-1]
for i in range(Q):
    T=input().split()
    if T[0]=='1':reverse=0 if reverse else 1
    else:
        if T[1]=='1':
            if reverse:r=r+T[2]
            else:l=l+T[2]
        else:
            if reverse:l=T[2]+l
            else:r=r+T[2]
print(r+c+l if reverse else l+c+r)

Submission status: Wrong Answer

Solution code:
S=input()
Q=int(input())
reverse=0
if len(S)==1:l,c,r='',S,''
elif len(S)%2:l,c,r='',S[len(S)//2],''
else:l,c,r=S[0],'',S[-1]
for i in range(Q):
    T=input().split()
    if T[0]=='1':reverse=0 if reverse else 1
    else:
        if T[1]=='1':
            if reverse:r=r+T[2]
            else:l=T[2]+l
        else:
            if reverse:l=T[2]+l
            else:r=r+T[2]
print(r+c+l if reverse else l+c+r)

Submission status: Wrong Answer

Solution code:
S=input()
if len(S)==1:l,c,r='','',S
elif len(S)==2:l,c,r=S[0],'',S[-1]
else:l,c,r=S[0],S[1:-1],S[-1]
Q=int(input())
for i in range(Q):
    T=input().split()
    if T[0]=='1':l,r=r,l
    else:
        if T[1]=='1':
            c=l+c
            l=T[2]
        else:
            c=c+r
            r=T[2]
print(l+c+r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

flag = 0
for _ in range(q):
  query = list(map(str, input().split()))
  if query[0] == "1": flag = 1 - flag
  else:
    if query[1] == "1":
      if flag == 0: s.appendleft(query[2])
      else: s.append(query[2])
    else:
      if flag == 0: s.append(query[2])
      else: s.appendleft(query[2])

if query[0] == "1" and flag == 1: s.reverse()
print(*s, sep="")

Submission status: Wrong Answer

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

flag = 0
for _ in range(q):
  query = list(map(str, input().split()))
  if query[0] == "1": flag = 1 - flag
  else:
    if query[1] == "1":
      if flag == 0: s.appendleft(query[2])
      else: s.append(query[2])
    else:
      if flag == 0: s.append(query[2])
      else: s.appendleft(query[2])

if query[0] == "1": s.reverse()
print(*s, sep="")

Submission status: Wrong Answer

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

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

c = 1
for _ in range(q):
    t = list(input().split())
    if t[0] == '1':
        c *= -1
    else:
        if (t[1] == '1' and c == -1) or (t[1] == '0' and c == 1):
            d.append(t[2])
        else:
            d.appendleft(t[2])

print(''.join(list(d)[::c]))

Submission status: Wrong Answer

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

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

c = 1
for _ in range(q):
    t = list(input().split())
    if t[0] == '1':
        c *= -1
    else:
        if (t[1] == '1' and c == -1) or (t[1] == 0 and c == 1):
            d.append(t[2])
        else:
            d.appendleft(t[2])

print(''.join(list(d)[::c]))

Submission status: Wrong Answer

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

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    S = SI()
    Q = NI()
    
    que = deque([S])
    
    reverse = False
    
    for q in range(Q):
        query = input()
        if query == "1":
            if reverse == False:
                reverse = True
            else:
                reverse = False
        else:
            x,y,z = map(str,query.split())
            if reverse == False:
                if y == "1":
                    que.appendleft(z)
                else:
                    que.append(z)
            else:
                if y == "1":
                    que.append(z)
                else:
                    que.appendleft(z)
    
    if reverse==True:
        print("".join(reversed(list(que))))
    else:
        print("".join(list(que)))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

flg = True
for q in Q:
    if q[0] == "1":
        flg = not flg
    else:
        F = int(q[1])
        if flg:
            F = str(3 - F)
        if F == "1":
            S = S + q[2]
        else:
            S = q[2] + S
            
if not flg:
    S = S[::-1]
print(S)

Submission status: Wrong Answer

Solution code:
s=input()
q=int(input())
que=[list(map(str,input().split())) for i in range(q)]
count=0
for i in que:
  if i[0]=="1":
    count+=1
ans=[[],[]]
    
for i in que:
  if i[0]=="1":
    count-=1
  else:
    if i[1]=="1":
      ans[count%2].append(i[2])
    else:
      ans[(count+1)%2].append(i[2])
print("".join(reversed(ans[0]))+s+"".join(ans[1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import deque
s = list(map(str,input().split()))
s = deque(s)
Q = int(input())
eo = 0
for query in range(Q):
  temp = list(map(str,input().split()))
  if temp[0] == "1":
    eo += 1 #反転したということになる
  else:
    if temp[1] == "1":
      if eo%2 == 0:
        s.appendleft(temp[2])
      else:
        s.append(temp[2])
    else:
      if eo%2 == 0:
        s.append(temp[2])
      else:
        s.appendleft(temp[2])
#print(s)
s = list(s)
if eo%2 == 0:
  ans = "".join(s)
else:
  s = s[::-1]
  ans = "".join(s)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    s=SI()
    turn=0
    q=I()
    ortop=[]
    orbot=[]
    for i in range(q):
        query=list(input().rstrip().split(" "))
        if query[0]=="1":
            turn=(turn+1)%2
        else:
            x=int(query[1])
            if (x+turn)%2==1:
                ortop.append(query[2])
            else:
                orbot.append(query[2])
    if turn%2==0:
        s1="".join(list(reversed(ortop)))
        #print(list(reversed(ortop)))
        #print(s)
        s2="".join(orbot)
        #print(orbot)
        print(s1+s+s2)
    else:
        s1="".join(list(reversed(orbot)))
        '''print(list(reversed(orbot)))
        print(s)
        print(ortop)'''
        s2="".join(ortop)
        print(s1+s+s2)
        
        
            
            
            
    

        
    
            
        

        
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
input = sys.stdin.readline
S = input()
input()
rev = 0
for line in readlines():
    q, *query, = line.split()
    if q == '1':
        rev ^= 1
    else:
        f, c = query
        if f == '1':
            if not rev:
                S = c+S
            else:
                S = S+c
        else:
            if not rev:
                S = S+c
            else:
                S = c+S

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

Submission status: Wrong Answer

Solution code:
s=list(input())
n=int(input())
Q=[]
for i in range(n) :
    Q.append(list(input().split()))

count=0
for q in Q :
    if q[0]=="1" :
        count+=1
    elif q[0]=="2" and count%2==0 :
        if q[1]=="1" :
            s.insert(0,q[2])
        else :
            s.insert(-1,q[2])
    else :
        if q[1]=="1" :
            s.insert(-1,q[2])
        else :
            s.insert(0,q[2])

ans="".join(s)
if count%2==0 :
    print(ans)
else :
    print(ans[::-1])

Submission status: Wrong Answer

Solution code:
from collections import deque

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

cnt=2

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    
  elif x[0]=='2':
    if (x[2]=='1' and cnt%2==0) or (x[2]=='2' and cnt%2==1):
      Q.appendleft(x[4])
      
    else:
      Q.append(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

cnt=0

for i in range(q):
  x=input()
  if x=='1':
    cnt+=1
    
  elif x[0]=='2':
    if (x[2]=='1' and cnt%2==0) or (x[2]=='2' and cnt%2==1):
      Q.appendleft(x[4])
      
    else:
      Q.append(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

cnt=0

for i in range(q):
  x=input()
  if x=='1':
    cnt+=1
    
  elif x[0]=='2':
    if (x[2]=='1' and cnt%2==0) or (x[2]=='2' and cnt%2==1):
      Q.appendleft(x[4])
      
    else:
      Q.append(x[4])
      
if cnt%2==1:
  Q.reverse()
  
Q=list(Q)
print(''.join(Q))