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:
# -*- coding: utf-8 -*-
s = str(input())
q = int(input())  
st = s
sth = s
sth2 = ""
stm = ""
stm2 = ""
count = 0
for i in range(q):
  k = input().split()
  if(k[0] == '1'):
    count = (count + 1) % 2
  else:
    c = count - 2
    d = int(k[1]) 
    e = k[2]
    if(c + d != 0):
      sth = e + sth
      if(len(sth) > 500):
        sth2 = sth
        sth = ""
    else:
      stm = stm + e
      if(len(stm) > 500):
        stm2 = stm
        stm = ""
      

st = sth + sth2 + stm2 + stm
if(count == 1):
  st = st[::-1]
  
print(st)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = str(input())
q = int(input())  
st = s
sth = s
stm = ""
count = 0
for i in range(q):
  k = input().split()
  if(k[0] == '1'):
    count = (count + 1) % 2
  else:
    c = count - 2
    d = int(k[1]) 
    e = k[2]
    if(c + d != 0):
      sth = e + sth
    else:
      stm = stm + e

if(count % 2 == 1):
  sth = sth[::-1]
  stm = stm[::-1]

  
st = sth + stm
print(st)

Submission status: Wrong Answer

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

flug=0
ans=deque(list(s))

for i in range(q):
    t=list(input().split())
    
    if t[0]=="1":
        flug+=1
    else:
        if (flug%2==0 and t[1]==2) or (flug%2==1 and t[1]==1):
            ans.append(t[2])
        else:
            ans.appendleft(t[2])

ans="".join(map(str,ans))

if flug%2==1:
    ans=ans[::-1]
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = str(input())
q = int(input())
l = []
for i in range(q):
  qy = input().split()
  l.append(qy)
  
st = s
head = st[0]
tail = st[0]
body = ""
for i in range(q):
  count = len(st)
  if(l[i][0] == '1'):
    st = st[::-1]
    head = st[0]
    tail = st[count - 1]
    body = body[::-1]
    if(count == 1):
      st = s
  if(l[i][0] == '2'):
    if(l[i][1] == '1'):
      d = head
      head = l[i][2]
      if(count != 1):
        body = d + body
      elif(count == 1):
        st = head + d  
    elif(l[i][1] == '2'):
      d = tail
      tail = l[i][2]
      if(count != 1):
        body = body + d
      elif(count == 1):
        st = d + tail
  if(count != 1):
    st = head + body + tail
      
      
print(st)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = str(input())
q = int(input())
l = []
for i in range(q):
  qy = input().split()
  l.append(qy)
  
st = s
head = st[0]
tail = st[0]
body = ""
for i in range(q):
  count = len(st)
  if(l[i][0] == '1'):
    c = head
    head = tail
    tail = c
    if(count == 1):
      st = s
  if(l[i][0] == '2'):
    if(l[i][1] == '1'):
      d = head
      head = l[i][2]
      if(count != 1):
        body = d + body
      elif(count == 1):
        st = head + d  
    elif(l[i][1] == '2'):
      d = tail
      tail = l[i][2]
      if(count != 1):
        body = body + d
      elif(count == 1):
        st = d + tail
  if(count != 1):
    st = head + body + tail
      
      
print(st)

Submission status: Wrong Answer

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

r=False
d=deque(list(input()))
for i in range(int(input())):
  Q=input().split()
  if Q[0]=='1':
    r=not r
  else:
    if (Q[1]=='1' and not r) or (Q[1]=='2' and r):
      d.appendleft(Q[2])
    else:
      d.append(Q[2])

if r:
  d.reverse()

print("".join(list(d)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = str(input())
q = int(input())
l = []
for i in range(q):
  qy = input().split()
  l.append(qy)
  
st = s
for i in range(q):
  if(l[i][0] == '1'):
    if(len(st) != 1):
      length = len(st)
      head = st[0]
      tail = st[length - 1]
      hcount = st.count(head)
      tcount = st.count(tail)
      st = st[::-1]
      st = st.replace(tail,head,1)
      st = st[::-1]
      st = st.replace(head,tail,1)
  if(l[i][0] == '2'):
    if(l[i][1] == '1'):
      c = l[i][2]
      st = c + st
    if(l[i][1] == '2'):
      c = l[i][2]
      st = st + c
    
print(st)

Submission status: Wrong Answer

Solution code:
# standard input
S = input()
Q = int(input())
Query = []
num_reverse = 0

L = []
R = []

rev = False

for _ in range(Q):

    q = tuple(map(str, input().split()))

    if q[0] == '1':
        rev = (not rev)

    else:
        if (rev and q[1] == '1') or (not rev and q[1] == '2'):
            R.append(q[2])
        else:
            L.append(q[2])

if rev:
    print(''.join(reversed(R)) + S[::-1] + ''.join(L))
else:
    print(''.join(reversed(L)) + S[::-1] + ''.join(R))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

d = deque(['S'])

#d = ['S']

rev = False

for i in range(q):
    if query[i][0] == '2':
        if query[i][1] == '1':
            d.appendleft(query[i][2])
        else:
            d.append(query[i][2])
    else:
        d.reverse()
        rev = not rev
exit()
#ans = deque()

if rev % 2 == 1:
    #s = ''.join(list(reversed(s)))
    s = s[::-1]

while len(d):
    tmp = d.popleft()
    if tmp == 'S':
        #ans.append(s)
        print(s,end='')
    else:
        print(tmp,end='')
        #ans.append(tmp)

#print(*ans,sep='')

Submission status: Wrong Answer

Solution code:
# standard input
S = input()
Q = int(input())
Query = []
num_reverse = 0

S_r = ''.join(reversed(S))

for _ in range(Q):

    q = tuple(map(str, input().split()))

    if int(q[0]) == 1:
        num_reverse += 1

    else:
        if (num_reverse + int(q[1])) % 2 == 0:
            S = S + q[2]
            S_r = q[2] + S_r
        else:
            S = q[2] + S
            S_r = S + q[2]

if num_reverse % 2 == 1:
    print(S_r)
else:
    print(S)

Submission status: Wrong Answer

Solution code:
S=input()
Q=int(input())
fb=True
forward=""
back=""

for i in range(Q):
    query=input()
    if(query=="1"):
        fb=False if(fb) else True
        print("query=1")
    else:
        query, F, C =query.split()
        if((F=="1")==fb):
            forward=C+forward
        else:
            back=back+C
        print("query=2")
print((forward+S+back)[::1 if(fb) else -1])

Submission status: Wrong Answer

Solution code:
import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

prev_cmd = 0
for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
	  if( prev_cmd == 1):
            prev_cmd = 0
          else:
            prev_cmd = 1
        if( str[0] == '2'):
	  if( prev_cmd == 1):
	    s = s[::-1]
          if( str[2] == '1'):
	    s = str[4] + s
          if( str[2] == '2'):
	    s = s + str[4]

if( prev_cmd == 1):
  s = s[::-1]

print s
sys.stdout.flush()

Submission status: Wrong Answer

Solution code:
import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

print s
for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
		s = s[::-1]
        if( str[0] == '2'):
          if( str[2] == '1'):
	    s = str[4] + s
          if( str[2] == '2'):
	    s = s + str[4]

print s
sys.stdout.flush()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
l = ''
r = ''
countReverse = 0
for operation in range(q):
    t = input().split()
    if int(t[0]) == 1 and (len(l) > 0 or len(r) > 0):
        countReverse += 1
    if int(t[0]) == 2:
        if int(t[1]) == 1:
            if countReverse % 2 == 0:
                l = t[2] + l
            else:
                r = r + t[2]
        else:
            if countReverse % 2 == 0:
                r = r + t[2]
            else:
                l = t[2] + l
if countReverse % 2 == 0:
    s = l + s + r
else:
    l = l[::-1]
    r = r[::-1]
    s = r + s + l
print(s)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
l = ''
r = ''
countReverse = 0
for operation in range(q):
    t = input().split()
    if int(t[0]) == 1:
        countReverse += 1
    elif int(t[1]) == 1:
        if countReverse % 2 == 0:
            l = t[2] + l
        else:
            r = r + t[2]
    else:
        if countReverse % 2 == 0:
            r = r + t[2]
        else:
            l = t[2] + l
if countReverse % 2 == 0:
    s = l + s + r
else:
    l = l[::-1]
    r = r[::-1]
    s = r + s + l
print(s)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
S=[input()]
S=deque(S)
Q=int(sys.stdin.readline())
flag=0
for i in range(Q):
	qu=tuple(input().split())
	if qu[0]=='1':
		if flag==0:
			flag+=1
		else:
			flag=0
	else:
		if qu[1]=='1' and flag==0:
			S.appendleft(qu[2])
		elif qu[1]=='1' and flag==1:
			S.append(qu[2])
		elif qu[1]=='2' and flag==0:
			S.append(qu[2])
		elif qu[1]=='2' and flag==1:
			S.appendleft(qu[2])
if flag==1:
	S=list(S)
	S.reverse()
print(''.join(S))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
S=[input()]
S=deque(S)
Q=int(sys.stdin.readline())
flag=0
for i in range(Q):
	qu=tuple(input().split())
	if qu[0]=='1':
		if flag==0:
			flag+=1
		else:
			flag=0
	else:
		if qu[1]=='1' and flag==0:
			S.appendleft(qu[2])
		elif qu[1]=='1' and flag==1:
			S.append(qu[2])
		elif qu[1]=='2' and flag==0:
			S.append(qu[2])
		elif qu[1]=='2' and flag==1:
			S.appendleft(qu[2])
if flag==1:
	S.reverse()
print(''.join(S))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
def main():
	S=[input()]
	S=deque(S)
	Q=int(sys.stdin.readline())
	flag=0
	for i in range(Q):
		qu=tuple(input().split())
		if qu[0]=='1':
			if flag==0:
				flag+=1
			else:
				flag=0
		else:
			if qu[1]=='1' and flag==0:
				S.appendleft(qu[2])
			elif qu[1]=='1' and flag==1:
				S.append(qu[2])
			elif qu[1]=='2' and flag==0:
				S.append(qu[2])
			elif qu[1]=='2' and flag==1:
				S.appendleft(qu[2])
	if flag==1:
		S.reverse()
	print(''.join(S))
if __name__=='__main__':
	main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
def main():
	S=[input()]
	S=deque(S)
	Q=int(sys.stdin.readline())
	flag=0
	for i in range(Q):
		qu=tuple(input().split())
		if qu[0]=='1':
			if flag==0:
				flag+=1
			else:
				flag=0
		else:
			if qu[1]=='1' and flag==0:
				S.appendleft(qu[2])
			elif qu[1]=='1' and flag==1:
				S.append(qu[2])
			elif qu[1]=='2' and flag==0:
				S.append(qu[2])
			else:
				S.appendleft(qu[2])
	if flag==1:
		S.reverse()
	print(''.join(S))
if __name__=='__main__':
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=[input()]
q=int(input())
turn=True
l=""
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn and int(qq[1])-2:
            l+=qq[2]
        else:
            s.append(qq[2])

text=l[::-1]+"".join(s)
print(text if turn else text[::-1])

Submission status: Wrong Answer

Solution code:
s=[input()]
q=int(input())
turn=True
l=""
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn and int(qq[1])-2:
            l+=qq[2]
        else:
            s.append(qq[2])

text=l+"".join(s)
print(text if turn else text[::-1])

Submission status: Wrong Answer

Solution code:
s=[input()]
q=int(input())
turn=True
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn and int(qq[1])-2:
            s.insert(0,qq[2])
        else:
            s.append(qq[2])
text="".join(s)
print(text if turn else text[::-1])

Submission status: Wrong Answer

Solution code:
S = [input()]
Q = int(input())
# 前後反転スイッチ
w = True
for i in range(Q):
    # 入力
    I = list(input().split())
    
    # Ti == 1
    if int(I[0]) == 1:
        w = not w
    # Ti == 2
    else:
        if w:
            # Fi = 1
            if int(I[1]) == 1:
                S.insert(0,I[2])
            # Fi = 2
            else:
                S.append(I[2])
        else:
            # Fi = 1
            if int(I[1]) == 1:
                S.append(I[2])
            # Fi = 2
            else:
                S.insert(0,I[2])
    #print(w,S)
    
if not w:
    S = S[::-1]
print(''.join(S))

Submission status: Wrong Answer

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

def main():
    s = input()
    q = int(input())
    is_rev = False
    l = ''
    r = ''
    for _ in range(0, q):
        query = input()
        if len(query) == 1:
            is_rev = not is_rev
        else:
            query = query.split(' ')
            query = [int(query[0]), int(query[1]), query[2]]
            if (query[1] == 1 and is_rev) or (query[1] == 2 and not is_rev):
#                s = s + query[2]
                r += query[2]
            else:
#                s = query[2] + s
                l += query[2]
    if is_rev:
        print(r[::-1] + s + l)
    else:
        print(l[::-1] + s + r)

main()

Submission status: Wrong Answer

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

r_flg = False
for query in Q:
  if query == "1":
    r_flg = not r_flg
  else:
    _, f, c = query.split()
    f_flg = (f == "1")
    end = (r_flg ^ f_flg)
    if end:
      S = S + c
    else:
      S = c + S

if not r_flg:
  S = S[::-1]
  
print(S)

Submission status: Wrong Answer

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

me = 1#1:sei  -1:gyaku
for i in range(q):
    t = input().split()
    if t[0] == '1':
        me *= -1
            
    else:
        if t[1]=='1':
            if me == 1:
                s.insert(0,t[2])
            else:
                s.append(t[2])
        else:
            if me == 1:
                s.append(t[2])
            else:
                s.insert(0,t[2])

if me == 1:
    print(''.join(s))
else:
    for i in range((len(s)-1),-1,-1):
        print(s[i],end='')

Submission status: Wrong Answer

Solution code:
#パラメータの取得
S = input()
Q = int(input())
cnt = 0   #反転回数カウンタ
head = ''
tail = ''

#処理実体処理
for i in range(Q):
  tmp = str(input())
  #Q各行の値を、T, F, Cに基づいて処理
  if tmp[0] == '1':
    cnt += 1
  else:
    T, F, C = tmp.split(' ')
    if cnt % 2 == 1:
      if F == '1':
        tail = tail + C
      else:
        head = C + head
    else:
      if F == '1':
        head = C + head
      else:
        tail = tail + C
    #cnt = 0
  #print('head=',head)
  #print('tail=',tail)

print('cnt=',cnt)
if cnt % 2 == 0:
  ans = head + S + tail
else:
  ans = tail[::-1] + S[::-1] + head[::-1]
print(ans)

Submission status: Wrong Answer

Solution code:
#パラメータの取得
S = input()
Q = int(input())
cnt = 0   #反転回数カウンタ
head = ''
tail = ''
last = ''

#最初の1件処理
tmp = str(input())
if tmp[0] == '1':
  #cnt += 1
  S = S[::-1]
else:
  T, F, C = tmp.split(' ')
  if F == '1':
    S = C + S
  else:
    S = S + C
last = "2" #tmp[0]

#処理実体処理
for i in range(Q-1):
  tmp = str(input())
  #Q各行の値を、T, F, Cに基づいて処理
  if tmp[0] == '1':
    cnt += 1
  else:
    T, F, C = tmp.split(' ')
    if last == '1':
      if F == '1':
        tail = tail + C
      else:
        head = C + head
    else:
      if F == '1':
        head = C + head
      else:
        tail = tail + C
  last = tmp[0]
  #print('head=', head)
  #print('tail=', tail)
#文字列結合処理
if cnt % 2 == 0:
  ans = head + S + tail
else:
  ans = tail[::-1] + S[::-1] + head[::-1]
print(ans)

Submission status: Wrong Answer

Solution code:
#パラメータの取得
S = input()
Q = int(input())
cnt = 0   #反転回数カウンタ
head = ''
tail = ''
last = ''

#最初の1件処理
tmp = str(input())
if tmp[0] == '1':
  #cnt += 1
  S = S[::-1]
else:
  T, F, C = tmp.split(' ')
  if F == '1':
    head = C + head
  else:
    tail = tail + C
last = "2" #tmp[0]

#処理実体処理
for i in range(Q-1):
  tmp = str(input())
  #Q各行の値を、T, F, Cに基づいて処理
  if tmp[0] == '1':
    cnt += 1
  else:
    T, F, C = tmp.split(' ')
    if last == '1':
      if F == '1':
        tail = tail + C
      else:
        head = C + head
    else:
      if F == '1':
        head = C + head
      else:
        tail = tail + C
  last = tmp[0]
  #print('head=', head)
  #print('tail=', tail)
#文字列結合処理
if cnt % 2 == 0:
  ans = head + S + tail
else:
  ans = tail[::-1] + S[::-1] + head[::-1]
print(ans)

Submission status: Wrong Answer

Solution code:
#パラメータの取得
S = input()
Q = int(input())
cnt = 0   #反転回数カウンタ
head = ''
tail = ''
last = ''

#最初の1件処理
tmp = str(input())
if tmp[0] == '1':
  cnt += 1
else:
  T, F, C = tmp.split(' ')
  if F == '1':
    head = C + head
  else:
    tail = tail + C
last = tmp[0]

#処理実体処理
for i in range(Q-1):
  tmp = str(input())
  #Q各行の値を、T, F, Cに基づいて処理
  if tmp[0] == '1':
    cnt += 1
  else:
    T, F, C = tmp.split(' ')
    if last == '1':
      if F == '1':
        tail = tail + C
      else:
        head = C + head
    else:
      if F == '1':
        head = C + head
      else:
        tail = tail + C
  last = tmp[0]

#文字列結合処理
if cnt % 2 == 0:
  ans = head + S + tail
else:
  ans = tail[::-1] + S[::-1] + head[::-1]
print(ans)

Submission status: Wrong Answer

Solution code:
#パラメータの取得
S = input()
Q = int(input())
cnt = 0   #反転回数カウンタ
head = ''
tail = ''
last = ''

#最初の1件処理
tmp = str(input())
if tmp[0] == '1':
  cnt += 1
else:
  T, F, C = tmp.split(' ')
  if F == '1':
    head = C + head
  else:
    tail = tail + C
last = tmp[0]

#処理実体処理
for i in range(Q-1):
  tmp = str(input())
  #Q各行の値を、T, F, Cに基づいて処理
  if tmp[0] == '1':
    cnt += 1
  else:
    T, F, C = tmp.split(' ')
    if last == '1':
      if F == '1':
        tail = tail + C
      else:
        head = C + head
    else:
      if F == '1':
        head = C + head
      else:
        tail = tail + C
  last = tmp[0]

#文字列結合処理
if cnt % 2 == 0:
  ans = head + S + tail
else:
  ans = tail + S[::-1] + head
print(ans)

Submission status: Wrong Answer

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

for n in range(q):
  query = input()
  # add new alphabet
  if (len(query) > 1):
    f, c = query[2], query[4]
    if (f == 1):
      s = c + s
    else:
      s = s + c
	# reverse
  else:
    s = s[::-1]
    
print(s)

Submission status: Wrong Answer

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

rev = -1 # -1: False, 1: True
for n in range(q):
  query = input()
  # add new alphabet
  if (len(query) > 1):
    f, c = query[2], query[4]
    # reverse
    if (rev == 1):
      if (f == 1):
        s = s + c
      else:
        s = c + s
    else:
      if (f == 1):
        s = c + s
      else:
        s = s + c
	# reverse
  else:
    rev *= -1
    
if (rev == -1):
  print(s)
else:
  print(s[::-1])

Submission status: Wrong Answer

Solution code:
moji = input()
n = int(input())
count = 0
count_all = 0
for i in range(n):
  query = input().split()
  if len(query) == 1:
    count += 1
    count_all += 1
  else:
    if (query[1] == "1" and count % 2 == 0) or (query[1] == "2" and count % 2 == 1) :
      moji = query[2] + moji
    else:
      moji = moji + query[2]
    count = 0
if count_all % 2 == 1:
	moji = moji[::-1]
print(moji)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
a = [s]

for i in range(q):
    so = input()
    if so == '1':
        a[0], a[-1] = a[-1], a[0]
    else:
        d, f, c = so.split()
        if f == '1':
            a.insert(0, c)
        else:
            a.append(c)


print(''.join(a))

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
a = [s]

for i in range(q):
    so = input()
    if so == '1':
        a[0], a[-1] = a[-1], a[0]
    else:
        d, f, c = so.split()
        if f == '1':
            a.insert(0, c)
        else:
            a.insert(-1, c)


print(''.join(a))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
revese_flag = 0
int_list = []
last_list = []
for i in range(Q):
    inp = input()
    if inp[0] == "1":
        revese_flag = revese_flag ^ 1
    elif inp[2] == "1":
        #import IPython;IPython.embed()
        if revese_flag:
            last_list.append(inp[4])
        else:
            int_list.append(inp[4])
    else:
        if revese_flag:
            int_list.append(inp[4])
        else:
            last_list.append(inp[4])
    #print("step is ", i)
    #print("input is ", inp)
    #if revese_flag:
    #    print(S[::-1])
    #else:
    #    print(S)
int_list.reverse()
int_list.append(S)
int_list.extend(last_list)
if revese_flag:
    int_list.reverse()
    print("".join(int_list))
    #print(S[::-1])
else:
    print("".join(int_list))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
revese_flag = 0
int_list = []
last_list = []
for i in range(Q):
    inp = input()
    if inp[0] == "1":
        revese_flag = revese_flag ^ 1
    elif inp[2] == "1":
        #import IPython;IPython.embed()
        if revese_flag:
            last_list.append(inp[4])
        else:
            int_list.append(inp[4])
    else:
        if revese_flag:
            int_list.append(inp[4])
        else:
            last_list.append(inp[4])
    #print("step is ", i)
    #print("input is ", inp)
    #if revese_flag:
    #    print(S[::-1])
    #else:
    #    print(S)
if revese_flag:
    last_list.reverse()
    last_list.append(S)
    last_list.extend(int_list)
    print("".join(last_list))
    #print(S[::-1])
else:
    int_list.reverse()
    int_list.append(S)
    int_list.extend(last_list)
    print("".join(int_list))

Submission status: Wrong Answer

Solution code:
from collections import deque

S = input()
Q = int(input())
query = [input().split() for _ in range(Q)]

ans = deque(list(S))
flag = 1

for q in range(Q):
    if len(query[q]) == 1:
        flag = 1 - flag
    else:
        if query[q][1] == '1':
            if flag:
                ans.append(query[q][2])
            else:
                ans.appendleft(query[q][2])
        else:
            if not flag:
                ans.append(query[q][2])
            else:
                ans.appendleft(query[q][2])

if not flag:
    print(''.join(ans))
else:
    print(''.join(ans)[::-1])

Submission status: Wrong Answer

Solution code:
Sr = list(input())
Sl = []
Q = int(input())


for i in range(Q):
    s = list(input().split())
    if len(s) == 1:
        Sr,Sl = Sl,Sr
    else:
        if s[1] == '1':
            Sl.append(s[2])
        else:
            Sr.append(s[2])

print('%s' % (''.join(Sl) + ''.join(Sr)))

Submission status: Wrong Answer

Solution code:
Sr = list(input())
Sl = []
Q = int(input())


for i in range(Q):
    s = list(input().split())
    if len(s) == 1:
        Sr,Sl = Sl,Sr
    else:
        if s[1] == '1':
            Sl.insert(0,s[2])
        else:
            Sr.append(s[2])

print('%s' % (''.join(Sl) + ''.join(Sr)))

Submission status: Wrong Answer

Solution code:
from collections import deque

d = deque(input())

print(d)

q = int(input())

headflag = 0

for i in range(q):
    s = input()
    if len(s) == 1:
        if headflag == 0:
            headflag = 1
        else:
            headflag = 0
    else:
        l = list(s)
        if headflag == 0:
            if l[2] == '1':
                d.appendleft(l[4])
            else:
                d.append(l[4])
        else:
            if l[2] == '2':
                d.appendleft(l[4])
            else:
                d.append(l[4])

dl = len(d)

if headflag == 0:
    for i in range(len(d)):
        print(d[i], end='')
else:
    for i in range(len(d)):
        print(d[dl-1-i], end='')

print()

Submission status: Wrong Answer

Solution code:
S = input()

Q = int(input())

A = [S]

for i in range(Q):
    s = input().split()
    if len(s) == 1:
        A = A[::-1]
    else:
        if s[1] == '1':
            A.insert(0,s[2])
        else:
            A.append(s[2])

print('%s' % ''.join(A))

Submission status: Wrong Answer

Solution code:
import numpy as np
S = input()

Q = int(input())

A = [S]

for i in range(Q):
    s = input().split()
    if len(s) == 1:
        A = A[::-1]
    else:
        if s[1] == '1':
            A.insert(0,s[2])
        else:
            A.insert(-1,s[2])

print('%s' % ''.join(A))

Submission status: Wrong Answer

Solution code:
from collections import deque

d = deque()

l = list(input())

for i in range(len(l)):
    d.append(l[i])

q = int(input())

for i in range(q):
    s = input()
    if len(s) == 1:
        if len(d) != 1:
            t = d.pop()
            h = d.popleft()
            d.append(h)
            d.appendleft(t)
    else:
        l = list(s)
        if l[2] == '1':
            d.appendleft(l[4])
        else:
            d.append(l[4])

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

print()

Submission status: Wrong Answer

Solution code:
from collections import deque

d = deque()

l = list(input())
print(l)

for i in range(len(l)):
    d.append(l[i])

q = int(input())

for i in range(q):
    s = input()
    if len(s) == 1:
        if len(d) != 1:
            t = d.pop()
            h = d.popleft()
            d.append(h)
            d.appendleft(t)
    else:
        l = list(s)
        if l[2] == '1':
            d.appendleft(l[4])
        else:
            d.append(l[4])

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

print()

Submission status: Wrong Answer

Solution code:
from collections import deque

d = deque()

d.append(input())

q = int(input())

for i in range(q):
    s = input()
    if len(s) == 1:
        t = d.pop()
        h = d.popleft()
        d.append(h)
        d.appendleft(t)
    else:
        l = list(s)
        if l[2] == '1':
            d.appendleft(l[4])
        else:
            d.append(l[4])

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

print()

Submission status: Wrong Answer

Solution code:
def StrConv(S, T, F, C):
  ans = ''
  if T == '1':
    pass
    #ans = S[::-1]
  else:
    if F == '1':
      ans = C + S
    else:
      ans = S + C
  return ans
  
#パラメータの取得
S = input()
Q = int(input())
dumy = '|' #仮の文字列くみ上げ変数
cnt = 0   #反転回数カウンタ

#処理実体処理
for i in range(Q):
  tmp = str(input())
  #Q各行の値を、T, F, Cに基づいて処理
  if tmp[0] == '1':
    T = tmp[0]
    F = '-'
    C = '-'
    cnt += 1
  else:
    T, F, C = tmp.split(' ')
  #変換処理本体
  dumy = StrConv(dumy, T, F, C)

#文字列結合処理
if (cnt % 2) == 0:
  ans = dumy[0:dumy.find('|')] + S + dumy[dumy.find('|')+1:]
else:
  ans = dumy[0:dumy.find('|')] + S[::-1] + dumy[dumy.find('|')+1:]
print(ans)

Submission status: Wrong Answer

Solution code:
S =input()

input_line = int(input())

flag0 = ""
flag1 = ""
flag = 0


for i in range(input_line):
    action = list(input())
    # print(flag0,flag1)
    # print(action)
    if action[0]=="1":
        if flag == 0:
            flag = 1
        else:
            flag = 0
    else:
        # print("check")
        if action[2] == "2":
            
            if flag == 0:
                flag0 = flag0 + action[4]
            elif flag ==1:
                flag1 = action[4] + flag1
        else:
            if flag == 0:
                flag0 = action[4] + flag0
            
            elif flag == 1:
                flag1 += action[4]
                
S = flag0 + S + flag1
if flag == 1:
    S = S[::-1]
print(S)

Submission status: Wrong Answer

Solution code:
S =input()

input_line = int(input())

flag0 = ""
flag1 = ""

for i in range(input_line):
    action = list(input())
    
    flag = 0
    

    # print(flag0,flag1)
    # print(action)
    if action[0]=="1":
        if flag == 0:
            flag = 1
        else:
            flag = 0
    else:
        # print("check")
        if action[2] == "2":
            
            if flag == 1:
                flag0 = flag1 + action[4]
            elif flag ==0:
                flag1 = action[4]+flag1
        else:
            if flag == 1:
                flag0 += action[4]
            
            elif flag == 0:
                flag1 = action[4]+flag1

if flag == 1:
    S = S[::-1]
S = flag1 + S + flag0
    
print(S)

Submission status: Wrong Answer

Solution code:
S =input()

input_line = int(input())

flag0 = ""
flag1 = ""

for i in range(input_line):
    action = list(input())
    
    flag = 0
    

    # print(flag0,flag1)
    # print(action)
    if action[0]=="1":
        if flag == 0:
            flag = 1
        else:
            flag = 0
    else:
        # print("check")
        if action[2] == "2":
            
            if flag == 1:
                flag1 = flag1 + action[4]
            elif flag ==0:
                flag0 = action[4]+flag0
        else:
            if flag == 1:
                flag1 += action[4]
            
            elif flag == 0:
                flag0 = action[4]+flag0

if flag == 1:
    S = S[::-1]
S = flag0 + S + flag1
    
print(S)