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 = input()
q = int(input())

is_s0_head = True
tail = len(S)-1

queue = deque(S)

for _ in range(q):
    # print(S)
    Q = list(input().split())
    if Q[0] == "1":
        is_s0_head = not is_s0_head
    else:
        if Q[1] == "1":
            if is_s0_head:
                queue.appendleft(Q[2])
            else:
                queue.append(Q[2])
        else:
            if is_s0_head:
                queue.append(Q[2])
            else:
                queue.appendleft(Q[2])

if is_s0_head:
    print("".join(list(S)))
else:
    print("".join(list(S)[::-1]))

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque
S=list(stdin.readline().strip().split())
N=list(map(int,stdin.readline().strip().split()))[0]

d = deque(S)
rev=False
for i in range(N):

    Q = list(stdin.readline().strip().split())
    if Q[0]=='1' :
        if rev==False:rev=True
        else:rev=False

    if Q[0]=='2':
        if Q[1]=='1':
            if rev==False:d.appendleft(Q[2])
            else:d.append(Q[2])
        if Q[1]=='2':
            if rev == False:
                d.append(Q[2])
            else:
                d.appendleft(Q[2])
if rev==False:[print(x,end="") for x in d]
else:[print(d[x],end="") for x in range(len(d)-1,-1,-1)]

Submission status: Wrong Answer

Solution code:
s = str(input())
q = int(input())
inv = False
for i in range(q):
    a = input()
    if a == '1':
        inv = ~inv
        continue
    a = a.split()
    if (a[1] == '1')^inv:
        s = a[2] + s
    else:
        s += a[2]
if inv:
    print(s[::-1])
else:
    print(s)

Submission status: Wrong Answer

Solution code:
s = str(input())
q = int(input())
inv = False
for i in range(q):
    a = list(input().split())
    if a[0] == '1':
        inv = ~inv
    if a[0] == '2':
        if (a[1] == '1')^inv:
            s = a[2] + s
        else:
            s += a[2]
if inv:
    print(s[::-1])
else:
    print(s)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque
S=list(stdin.readline().strip().split())
N=list(map(int,stdin.readline().strip().split()))[0]

d = deque(S)
sentou=0
for i in range(N):

    Q = list(stdin.readline().strip().split())
    if Q[0]=='1' :
        sentou+=1

    if Q[0]=='2':
        if Q[1]=='1':
            if sentou%2==0:d.appendleft(Q[2])
            else:d.append(Q[2])
        if Q[1]=='2':
            if sentou % 2 == 0:
                d.append(Q[2])
            else:
                d.appendleft(Q[2])
if sentou%2==0:[print(x,end="") for x in d]
else:[print(d[x],end="") for x in range(len(d)-1,-1,-1)]

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
inv = False
for i in range(q):
    a = list(input().split())
    if a[0] == '1':
        inv = ~inv
    if a[0] == '2':
        if (a[1] == '1')^inv:
            s = a[2] + s
        else:
            s += a[2]
if inv:
    print(s[::-1])
else:
    print(s)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque
S=list(stdin.readline().strip().split())
N=list(map(int,stdin.readline().strip().split()))[0]

d = deque(S)
for i in range(N):
    zen = deque()
    kou = deque()
    Q = list(stdin.readline().strip().split())
    if Q[0]=='1' and len(d)>=2:
        while(len(d)>=2):
            zen.appendleft(d.pop())
            kou.appendleft(d.popleft())
        d.extendleft(zen)
        d.extend(kou)
    if Q[0]=='2':
        if Q[1]=='1':
            d.appendleft(Q[2])
        if Q[1]=='2':
            d.append(Q[2])

[print(x,end="") for x in d]

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque
S=list(stdin.readline().strip().split())
N=list(map(int,stdin.readline().strip().split()))[0]

d = deque(S)
for i in range(N):
    zen = []
    kou = []
    Q = list(stdin.readline().strip().split())
    if Q[0]=='1' and len(d)>=2:
        while(len(d)>=2):
            zen.append(d.pop())
            kou.append(d.popleft())
        d.extendleft(zen)
        d.extend(kou)
    if Q[0]=='2':
        if Q[1]=='1':
            d.appendleft(Q[2])
        if Q[1]=='2':
            d.append(Q[2])

[print(x,end="") for x in d]

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque
S=list(stdin.readline().strip().split())
N=list(map(int,stdin.readline().strip().split()))[0]

d = deque(S)
for i in range(N):
    Q = list(stdin.readline().strip().split())
    if Q[0]=='1' and len(d)>=2:
        vari_b=d.pop()
        vari_f=d.popleft()
        d.appendleft(vari_b)
        d.append(vari_f)
    if Q[0]=='2':
        if Q[1]=='1':
            d.appendleft(Q[2])
        if Q[1]=='2':
            d.append(Q[2])
[print(x,end="") for x in d]

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque
S=list(stdin.readline().strip().split())
N=list(map(int,stdin.readline().strip().split()))[0]

d = deque(S)
for i in range(N):
    Q = list(stdin.readline().strip().split())
    if Q[0]=='1':
        vari_b=d.pop()
        vari_f=d.popleft()
        d.appendleft(vari_b)
        d.append(vari_f)
    if Q[0]=='2':
        if Q[1]=='1':
            d.appendleft(Q[2])
        if Q[1]=='2':
            d.append(Q[2])
[print(x,end="") for x in d]

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque
S=list(stdin.readline().strip().split())
N=list(map(int,stdin.readline().strip().split()))[0]

d = deque(S)
for i in range(N):
    Q = list(stdin.readline().strip().split())
    if Q[0]=='1':
        vari_b=d.pop()
        vari_f=d.popleft()
        d.appendleft(vari_b)
        d.append(vari_f)
    if Q[0]=='2':
        if Q[1]=='1':
            d.appendleft(Q[2])
        if Q[1]=='2':
            d.append(Q[2])
print(*d)

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    q = int(input())
    r = 1
    front = ""
    back = ""
    for _ in range(q):
        n, *fc = input().split()
        if n == "1":
            r *= -1
        else:
            f, c = fc
            f = 1 if f == "1" else -1
            if f*r == 1:
                front += c
            else:
                back += c
    print(front[::-1]+s[::r]+back)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	S = input()
	Q = int(input())
	cnt = 0
	s_start = ""
	s_end = ""
	for i in range(Q):
		q = list(input().split())
		if q[0] == "1":
			cnt += 1
		else:
			if q[1] == "1":
				if cnt % 2 == 0:
					s_start += q[2]
				else:
					s_end += q[2]
			else:
				if cnt % 2 == 0:
					s_end += q[2]
				else:
					s_start += q[2]

	if cnt % 2 == 0:
		ans = s_start[::-1] + S + s_end

	else:
		ans = s_end[::-1] + S + s_start

	print(ans)

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

cnt = 0
llst = []
rlst = []
for i in range(q):
  line = input()
  if line == '1':
    cnt += 1
  else:
    elems = line.split()
    if cnt % 2 == 0:
      # 指示通り追加
      if elems[1] == '1':
        llst.append(elems[2])
      else:
        rlst.append(elems[2])
    else:
      # 指示の向きと逆に追加
      if elems[1] == '1':
        rlst.append(elems[2])
      else:
        llst = [elems[2]] + llst
        
if cnt % 2 == 0:
  res = ''.join(llst[::-1]) + s + ''.join(rlst)
  print(res)
else:
  res = ''.join(llst[::-1]) + s + ''.join(rlst)
  print(res[::-1])

Submission status: Wrong Answer

Solution code:
S=input()
Q=int(input())
head=""
tail=""
rev=False

for _ in range(Q):
    q = input().split()
    if len(q)==1:
        rev != rev
    else:
        if rev ^ (q[1]=="1"):
            head+=q[2]
        else:
            tail+=q[2]
if rev:
    print(tail[::-1]+S[::-1]+head)
else:
    print(head[::-1]+S+tail)

Submission status: Wrong Answer

Solution code:
S=input()
rev=False
head=""
tail=""
for _ in range(int(input())):
    l = input().split()
    if len(l)==1:
        rev = not rev
    else:
        if rev^(l[1]=="1"):
            tail+=l[2]
        else:
            head+=l[2]
if not rev:
    print("".join(map(str,reversed(head[::-1]+S+tail))))
else:
    print(head[::-1]+S+tail)

Submission status: Wrong Answer

Solution code:
S=input()
rev=False
head=""
tail=""
for _ in range(int(input())):
    l = input().split()
    if len(l)==1:
        rev = not rev
    else:
        if rev^(l[1]=="1"):
            tail+=l[2]
        else:
            head+=l[2]
if not rev:
    print("".join(map(str,reversed(head+S+tail))))
else:
    print(head+S+tail)

Submission status: Wrong Answer

Solution code:
from collections import deque
d = deque([input()])
flag = True  # 逆順になっている->False
for i in range(int(input())):
  query = input().split()
  if query[0] == '1':
    flag = not flag
  if query[0] == '2':
    if query[1] == '1':
      if flag:
        d.appendleft(query[2])
      if not flag:
        d.append(query[2])
    if query[1] == '2':
      if flag:
        d.append(query[2])
      if not flag:
        d.appendleft(query[2])
if flag:
  for i in d:
    print(i, end='')
if not flag:
  for i in reversed(d):
    print(i, end='')

Submission status: Wrong Answer

Solution code:
S = list(input())
Q = int(input())
front = []
back = []
ifZyun = True

for _ in range(Q):
    query = input()
    if query == "1":
        ifZyun = not ifZyun
    else:
        query = list(query)
        F = query[2]
        C = query[4]
        if (F == "1" and ifZyun) or (F == "2" and not ifZyun):
            front.append(C)
        else:
            back.append(C)

if not ifZyun:
    S = S[::-1]
    print("".join(back + S + front))
else:
    front = front[::-1]
    print("".join(front + S + back))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
QUE = []
start_index = None
end_index = None
for i in range(Q):
    query = input()
    if query == "1" and start_index == None:
        start_index = i
    elif query == "1":
        end_index = i
    else:
        if start_index == None:
            QUE.append(query)
        else:
            if end_index == None:
                QUE.append("1")
            else:
                for _ in range(end_index - start_index + 1):
                    QUE.append("1")
            QUE.append(query)
            start_index = None
            end_index = None

for query in QUE:
    if query == "1":
        S = S[::-1]
    else:
        query = list(query)
        F = query[2]
        C = query[4]
        if F == "1":
            # 先頭に追加
            S = C + S
        else:
            # 末尾に追加
            S = S + C

print(S)

Submission status: Wrong Answer

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

for i in range(q):
    a=list(input().split())
    if a[0]=='1':
        rev*=-1
    else:
        if a[1]=='1':
            rev=-1
            s.append(a[2])
        else:
            rev=1
            s.append(a[2])
  
if rev<0:
    s=s[::-1]
print(''.join(s))

Submission status: Wrong Answer

Solution code:
from collections import deque

def swap(d, query):
    if(query[0] == 1):
        d.reverse()
    else:
        if(query[1] == 1):
            d.appendleft(query[2])
        else:
            d.append(query[2])

def main():
    S = [c for c in input().rstrip()]
    Q = int(input().rstrip())
    query = []
    for i in range(Q):
        q = input().rstrip().split(' ')
        if(q[0] == '1'):
            query.append((1, -1, -1))
        else:
            query.append((2, int(q[1]), q[2]))
    d = deque(S)
    
    for q in query:
        swap(d, q)
    print(d)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
q = int(input())
flag = True
p = ''
m = ''
for i in range(q):
    qfc = input()
    if qfc[0] == '1':
        if flag:
            flag = False
        else:
            flag = True
    else:
        if qfc[2] == '1':
            if flag:
                p += qfc[4]
            else:
                m += qfc[4]
        else:
            if flag:
                m += qfc[4]
            else:
                p += qfc[4]
if flag:
    print(p[::-1] + s + m)
else:
    print(m[::-1] + s + p)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
q = int(input())
flag = True
p = ''
m = ''
for i in range(q):
    qfc = input()
    if qfc[0] == '1':
        if flag:
            flag = False
        else:
            flag = True
    else:
        if qfc[2] == '1':
            if flag:
                p += qfc[4]
            else:
                m += qfc[4]
        else:
            if flag:
                m += qfc[4]
            else:
                p += qfc[4]
if flag:
    print(p[::-1] + s + m)
else:
    print(m + s + p)

Submission status: Wrong Answer

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

flip = False

for q in range(0, Q):
    qi = list(input().split())

    if len(qi) == 1:
        # S = S[::-1]
        flip = not flip
    else: # len(qi) == 3
        Fi, Ci = int(qi[1]), qi[2]

        # Fi == 1, front ^ flip == False
        # Fi == 0, end ^ flip == True
        if Fi^flip: # front
            S = Ci + S
        else: # Fi == 2, end
            S = S + Ci

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

Submission status: Wrong Answer

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

a=0
for i in range(q):
  t=input()
  if t=='1':
    a=a^1
  else:
    t, f, c = map(str, t.split())
    f=int(f)
    if f^a==0:
      s=s+c
    else:
      s=c+s
if a==1:
  s=s[::-1]
print(s)

Submission status: Wrong Answer

Solution code:
def main():
    S = list(str(input()))
    Q = int(input())
    SS = [list(input(_).split()) for _ in range(Q)]  # [[abc],[def],[ghi]]
    J = True
    for s in SS:
        if len(s) == 1 and int(s[0]) == 1:
            J = not J
        elif int(s[1]) == 1:
            if J: S = list(s[2]) + S
            elif not J: S = S + list(s[2])
        elif int(s[1]) == 2:
            if not J: S = list(s[2]) + S
            elif J: S = S + list(s[2])

    ans = ""
    if J:
       for i in S:
           ans += i
    else:
        for i in S[::-1]:
            ans +=i
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
def main():
    S = list(str(input()))
    Q = int(input())
    SS = [list(input(_).split()) for _ in range(Q)]  # [[abc],[def],[ghi]]
    for s in SS:
        if len(s) == 1 and int(s[0]) == 1:
            S.reverse()
        elif int(s[1]) == 1:
            S = list(s[2]) + S
        elif int(s[1]) == 2:
            S.append(s[2])

    ans = ""
    for i in S:
        ans += i
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
from collections import deque
S = list(input())
Q = int(input())

dq1 = deque(S)
dq2 = deque(S)
isReversed = False

for _ in range(Q):
    l = input().split()
    if l[0] == "1":
        isReversed = not isReversed
    else:
        s = l[2]
        if l[1]=="1":
            if isReversed:
                dq1.append(s)
                dq2.appendleft(s)
            else:
                dq1.appendleft(s)
                dq2.append(s)
        else:
            if isReversed:
                dq1.appendleft(s)
                dq2.append(s)
            else:
                dq1.append(s)
                dq2.appendleft(s)

q = dq2 if isReversed else dq1
print("".join(q))

Submission status: Wrong Answer

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

head = []
tail = []
flip = 0

for i in range(q):
	query = input().split()
	if query[0] == '1':
		flip ^= 1
	else:
		f = query[1]
		c = query[2]
		# if (f ^ flip) == 0:
		if f == '1' or flip == 1:
			head.append(c)
		else:
			tail.append(c)

if flip:
	head, tail = tail, head
	s = s[::-1]

head = ''.join(head)
tail = ''.join(tail)

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

Submission status: Wrong Answer

Solution code:
import math
from collections import deque
def ma(): return map(str,input().split())

#input
s=input()
q=int(input())
#print(deque(s))
s_now=deque()
s_now.append(s)
s_state=1
for _ in range(q):
    t=list(ma())
    t_len=len(t)
    if t_len==1:
        s_state*=-1
    else:
        t_edit=3-2*int(t[1])
        if t_edit==s_state:
            s_now.appendleft(t[2])
        else:
            s_now.append(t[2])

if s_state == 1:
    print("".join(s_now))
else:
    s_last=list(s_now)
    print("".join(s_last[::-1]))

Submission status: Wrong Answer

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

n = len(s)
rev = False

for i in range(q):
    t = input()
    if len(t) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        q2, f, c = t.split()
        if int(f) == 1 or (int(f) == 2 and rev):
            s = c + s
            n += 1
        else:
            s = s + c
            n += 1

if rev:
    s = "".join(list(reversed(s)))

print(s)

Submission status: Wrong Answer

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

for i in range(q):
    t = input()
    if len(t) == 1:
        tmp = s[0]
        s[0] = s[-1]
        s[-1] = tmp
    else:
        q2, f, c = t.split()
        if int(f) == 1:
            s = [c] + s
        else:
            s.append(c)

print("".join(s))

Submission status: Wrong Answer

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

for i in range(q):
    t = input()
    if len(t) == 1:
        tmp = list(s)
        tmp[0] = s[-1]
        tmp[-1] = s[0]
        s = "".join(tmp)
    else:
        q2, f, c = t.split()
        if int(f) == 1:
            s = c + s
        else:
            s = s + c

print(s)

Submission status: Wrong Answer

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

# Trueのとき元の並びといっしょ　Falseのとき逆順
direction = True
s_r = ""
s_l = ""

for i in range(Q):
    line = input().strip().split()
    if line[0] == "1":
        direction = not(direction)

    else:
        if line[1] == "1":
            if direction:
                s_l += line[2]
            else:
                s_r += line[2]
        else:
            if direction:
                s_r += line[2]
            else:
                s_l += line[2]

if direction:
    for i in range(len(s_l)-1,-1,-1):
        print(s_l[i],end="")

    print(S,end="")
    print(s_r)
else:
    for i in range(len(s_r)-1,-1,-1):
        print(s_r[i],end="")
    print(S,end="")
    print(s_l)

Submission status: Wrong Answer

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

x = []
y = []
cnt = 0

for i in range(q):
    a = list(input().split())
    if a[0] == "1":
        x, y = y, x
        cnt += 1
    else:
        if a[1] == "1":
            x.append(a[2])
        else:
            y.append(a[2])

if cnt % 2 == 1:
    s = s[::-1]

print(''.join(x[::-1]) + s + ''.join(y))

print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque(input().split())
Q = int(input())
not_reversed = True
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        not_reversed = not not_reversed 
        continue
    
    else:
        if not_reversed:
            if query[1] == "1":
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if query[1] == "2":
                S.appendleft(query[2])
            else:
                S.append(query[2])

if not_reversed == False:
    print("".join(map(str, list(S)[::-1])))
else:
    print("".join(map(str, S)))

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque(input().split())
Q = int(input())
not_reversed = True
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        not_reversed = not not_reversed 
        continue
    
    else:
        if not_reversed:
            if query[1] == "1":
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if query[1] == "1":
                S.appendleft(query[2])
            else:
                S.append(query[2])

if not_reversed == False:
    print("".join(map(str, list(S)[::-1])))
else:
    print("".join(map(str, S)))

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque(input().split())
Q = int(input())
not_reversed = True
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        not_reversed = not not_reversed 
        continue
    
    else:
        if not_reversed:
            if query[1] == "1":
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if query[1] == "1":
                S.append(query[2])
            else:
                S.appendleft(query[2])

if not_reversed == False:
    print("".join(map(str, list(S)[::-1])))
else:
    print("".join(map(str, S)))

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque(input().split())
Q = int(input())
not_reversed = True
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        not_reversed = not not_reversed 
        continue
    
    else:
        if not_reversed:
            if query[1] == "1":
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if query[1] == "1":
                S.append(query[2])
            else:
                S.appendleft(query[2])

if not_reversed == False:
    print("".join(map(str, list(S)[::-1])))
else:
    print(S)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
q_list = []
for i in range(q):
    q_ = list(input().split())
    q_list.append(q_)

print(q_list)
for j in q_list:
    if len(j)==1:
        s = s[::-1]
    else:
        if j[1] == '1':
            s = j[2] + s
        else:
            s = s + j[2]

print(s)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
q_list = []
for i in range(q):
    q_ = list(input().split())
    q_list.append(q_)

for j in q_list:
    if len(j) == 1:
        s = s[::-1]
    else:
        if j[1] == 1:
            s = j[2] + s
        else:
            s = s + j[2]

print(s)

Submission status: Wrong Answer

Solution code:
def main():
    ans = [input()]
    n = int(input())
    vec = 1
    for i in range(n):
        q = input()
        if q == "1":
            vec *= -1
        else:
            _,o,s = q.split()
            if ((o == "1") and (vec == 1)) or ((o == "2") and (vec == -1)):
                ans.insert(0, s)
            else:
                ans.append(s)
    if vec == -1:
        ans = reversed(ans)
    ans = ''.join(ans)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

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

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

d = deque([S])

vector = True
for q in qs:
    if q[0] == "1":
        vector = not vector
    else:
        if q[1] == "1":
            if vector:
                d.appendleft(q[2])
            else:
                 d.append(q[2])
        else:
            if vector:
                d.append(q[2])
            else:
                 d.appendleft(q[2])

if not vector:
    d.reverse()

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

Submission status: Wrong Answer

Solution code:
def main():
    ans = [input()]
    n = int(input())
    vec = 1
    for i in range(n):
        q = input()
        if q == "1":
            vec *= -1
        else:
            _,o,s = q.split()
            if ((o == "1") and (vec == 1)) or ((o == "2") and (vec == -1)):
                ans.insert(0,s)
            else:
                ans.append(s)
    if vec == -1:
        ans.reverse()
    print(''.join(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

def main():
    ans = [input()]
    n = int(input())
    vec = 1
    for i in range(n):
        q = sys.stdin.readline().rstrip()
        if q == "1":
            vec *= -1
        else:
            if ((q[2] == "1") and (vec == 1)) or ((q[2] == "2") and (vec == -1)):
                ans.insert(0,q[4])
            else:
                ans.append(q[4])
    if vec == -1:
        ans.reverse()
    print(''.join(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
char_S = list(S)
Q = int(input())
for i in range(Q):
    query = input().split()
    if query[0] == "1":
        char_S.reverse()
    else:
        if query[1] == "1":
            char_S.insert(0,query[2])
        else:
            char_S.insert(len(char_S),query[2])
print(char_S)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

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

d = deque([S])

def addLeft(vector, char):
    d.appendleft(char)
    return d

def addRight(vector, char):    
    d.append(char)
    return d

vector = True
for q in qs:
    if q[0] == "1":
        vector = not vector
    else:
        if not vector:
            q[1] = str(3 - int(q[1]))
        if q[1] == "1":
            d = addLeft(vector, q[2])
        else:
            d = addRight(vector, q[2])


if not vector:
    d.reverse()

ans = ''.join(list(d))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

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

d = deque([S])

def changeVector(vector):
    if vector:
        return False
    return True

def addLeft(vector, char):
    if vector:
        d.appendleft(char)
        return d
    d.append(char)
    return d

def addRight(vector, char):
    if vector:
        d.append(char)
        return d
    d.appendleft(char)
    return d

vector = True
for q in qs:
    if q[0] == "1":
        vector = changeVector(vector)
    else:
        if q[1] == "1":
            d = addLeft(vector, q[2])
        else:
            d = addRight(vector, q[2])

d.reverse()

ans = ''.join(list(d))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

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

d = deque([S])

def changeVector(vector):
    if vector:
        return False
    return True

def addLeft(vector, char):
    if vector:
        d.appendleft(char)
        return d
    d.append(char)
    return d

def addRight(vector, char):
    if vector:
        d.append(char)
        return d
    d.appendleft(char)
    return d

vector = True
for q in qs:
    if q[0] == "1":
        vector = changeVector(vector)
    else:
        if q[1] == "1":
            d = addLeft(vector, q[2])
        else:
            d = addRight(vector, q[2])

if not vector:
    d.reverse()

ans = ''.join(list(d))
print(ans)

Submission status: Wrong Answer

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

def main():
    ans = input()
    n = int(input())
    vec = 1
    for i in range(n):
        q = input().split()
        if q[0] == "1":
            vec *= -1
        else:
            if ((q[1] == "1") and (vec == 1)) or ((q[1] == "2") and (vec == -1)):
                ans = q[2] + ans
            else:
                ans += q[2]
    if vec == -1:
        ans = ans[::-1]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def main():
    ans = input()
    n = int(input())
    vec = 1
    for i in range(n):
        q = input()
        if q[0] == "1":
            vec *= -1
        else:
            if ((q[1] == "1") and (vec == 1)) or ((q[1] == "2") and (vec == -1)):
                ans = q[2] + ans
            else:
                ans += q[2]
    if vec == -1:
        ans = ans[::-1]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def main():
    ans = input()
    n = int(input())
    vec = 1
    for i in range(n):
        q = input()
        if q[0] == "1":
            vec *= -1
        else:
            if ((q[1] == "1") and (vec == 1)) or ((q[1] == "2") and (vec == -1)):
                ans = q[2] + ans
            else:
                ans += q[2]
    if vec == -1:
        ans = ans[::-1]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
import copy
s = input()
q_ = int(input())
query = [input().split() for _ in range(q_)]
l = deque([s])
flag = 0

for q in query:
    if q[0] == '1':
        flag += 1
    elif q[0] == '2':
        if (int(q[1]) + flag) % 2 == 1:
            l.appendleft(q[2])
        else:
            l.append(q[2])
if flag % 2 == 1:
    l.reverse()
print(''.join(l))

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    S = input()
    Q = int(input())

    reverse = False;

    for i in range(Q):
        query = input()
        if query[0] == '1':
            reverse = not reverse
        else:
            if query[2] == '1':
                if reverse == False:
                    S = query[4] + S
                else:
                    S = S + query[4]
            else:
                if reverse == False:
                    S = S + query[4]
                else:
                    S = query[4] + S

    if reverse == False:
        print(S)
    else:
        l = len(S)
        for i in range(l-1,-1,-1):
            print(S[i],end='')
        print()

main()