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: Runtime Error

Solution code:

S=input()
2
Q=int(input())
3
m=1
4
while Q>=1:
5
  tfc=list(input().split())
6
  if int(tfc[0])==1:
7
    m+=1
8
  elif int(tfc[0])==2:
9
    if (int(tfc[1])==1 and m%2==1) or (int(tfc[1])==2 and m%2==0):
10
      S=tfc[2]+S
11
    elif (int(tfc[1])==2 and m%2==1) or (int(tfc[1])==1 and m%2==0):
12
      S=S+tfc[2]
13
  Q-=1
14
if m%2==0:
15
  S= ''.join(list(reversed(S)))
16
print(S)

Submission status: Runtime Error

Solution code:
S=input()
Q=int(input())
m=1
n=2
while Q>=1:
  tfc=list(input().split())
  if int(tfc[0])==1:
    m,n=n,m
  elif int(tfc[0])==2:
    if (int(tfc[1])==1 and m==1) or (int(tfc[1])==2 and m==2):
      S=tfc[2]+S
    elif (int(tfc[1])==2) and m==1) or (int(tfc[1])==1 and m==2):
      S=S+tfc[2]
  Q-=1
if m==2:
  S=S[::-1]
print(S)

Submission status: Runtime Error

Solution code:
# 158-D
from collections import deque

s = deque()
s.append(input())
q = int(input())
is_not_reverse = True
for _ in range(q):
    command = [e for e in input().split()]
    if command[0] == '1':
        is_not_reverse = not is_not_reverse      
    elif command[1] == '1':
        if is_not_reverse:
            s.appendleft(command[2])
        else:
            s.append(command[2])
    elif command[1] == '2':
        if is_not_reverse:
            s.append(command[2])
        else:
            s.appendleft(command[2])
if is_not_reverse:
    print(''.join(s))
else:
    print(''.join(s[::-1]))

Submission status: Runtime Error

Solution code:
# 158-D ver2
s = input()
q = int(input())
pre = ''
last = ''
is_not_reverse = True
for _ in range(q):
    command = [e for e in input().split()]
    if command[0] == '1':
        is_not_reverse = not is_not_reverse      
    elif command[1] == '1':
        if is_not_reverse:
            pre = command[2] + pre
        else:
            last = last + [2]
    elif command[1] == '2':
        if is_not_reverse:
            last = last + command[2]
        else:
            pre = command[2] + pre
if is_not_reverse:
    print(pre+s+last)
else:
    print((pre+s+last)[::-1])

Submission status: Runtime Error

Solution code:
# 158-D ver2
s = input()
q = int(input())
pre = ''
last = ''
is_not_reverse = True
for _ in range(q):
    command = input().split()
    if command[0] == '1':
        is_not_reverse = not is_not_reverse      
    elif command[1] == '1':
        if is_not_reverse:
            pre = command[2] + pre
        else:
            last = last + [2]
    elif command[1] == '2':
        if is_not_reverse:
            last = last + command[2]
        else:
            pre = command[2] + pre
if is_not_reverse:
    print(pre+s+last)
else:
    print((pre+s+last)[::-1])

Submission status: Runtime Error

Solution code:
L = []
S = str(input())
Q = int(input())
Ql = [[] for _ in range(Q)] 

for i in range(len(S)):
    L.append(S[i])

for i in range(Q):
    A = input().split()
    Ql[i] = A

for i in range(Q):
    print(L)
    if Ql[i][0] == '1':
        L.reverse()
            
    elif Ql[i][0] == '2':
        if Ql[i][1] == '1':
            L.insert(0, Ql[i][2])
        else:
            L.append(Ql[i][2])

print(''.join(L))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
rflag = 0
s = [i for i in input()]
q = int(input())

for i in range(q):
    x = input().split()
    
    if(x[0] == '1'):
        rflag = rflag + 1
        # s = s[::-1]
    else:
        if((rflag % 2) == 0):
            rflag = 0
        else:
            s = s[::-1]
            rflag = 0
            
        s.insert(0,x[2]) if(x[1]=='1') else s.append(x[2])

s if((rflag % 2) == 0) else s = s[::-1]

print(''.join(s))

Submission status: Runtime Error

Solution code:
def sr(x):
    y = ''
    for i in range(len(x)-1,-1,-1):
        y = '%s%s' %(y,x[i])
        print(y)
    print(y)    
    return y

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

for i in range(q):
    x = input().split()
    
    if (x[0] == '1'):
        #s = s[::-1]
        s = sr(s)
    else:
        s = '%s%s'%(x[2],s) if (x[1] == '1') else '%s%s'%(s,x[2])

print(s)

Submission status: Runtime Error

Solution code:
s = input()
q = int(input())
t, f, c = [], [], ''
for i in range(q):
  t = int(input())
  if t == 1:
    s.reverse()
  else:
    f = int(input())
    c = input()
    if f == 1:
      s = c + s
    else:
      s = s + c
print(s)

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
    s = input()

    roops = int(input())

    #grid = [list(map(str,input().strip().split())) for i in range(roops)]
    j = 0
    for i in range(roops):
        a = list(map(str,input().strip().split()))
        if len(a)==1:
            j+=1
        else:
            if a[1]=="1":
                if j%2==0:
                    s = a[2]+s
                else:
                    s = s+a[2]
            else:
                if j%2==0:
                    s = s+a[2]
                else:
                    s = a[2]+s
    if j%2==0:
        print(s)
    else:
        print(''.join(list(reversed(s))))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import deque

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

if rev: ans = ''.join(s[::-1])
else: ans = ''.join(s)
print(ans)

Submission status: Runtime Error

Solution code:
# import bisect
# import heapq
# from copy import deepcopy
from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math

# n, k = map(int, input().split())
# a = list(map(int, input().split()))
s = deque(input())
q = int(input())
rev = False
for i in range(q):
    que = input()
    if que[0] == '1':
        rev = not rev
    else:
        que = list(que.split())
        if (int(que[1])==1 and not rev) or (int(que[1])==2 and rev):
            s.appendleft(que[2])
        else:
            s.append(que[2])

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

Submission status: Runtime Error

Solution code:
from collections import deque
S = list(input())
S = deque(S)
Q = int(input())
c = 0
for _ in range(Q):
    q = list(input().split())
    if int(q[0]) == 1:
        if c == 0:
            c = 1
        else:
            c = 0
    else:
        if c == 0:
            if int(q[1]) == 1:
                S.appendleft(q[2])
            else:
                S.append[q[2]]
        else:
            if int(q[1]) == 2:
                S.appendleft(q[2])
            else:
                S.append(q[2])
S = list(S)
if c == 0:
    print("".join(S))
else:
    S = S[::-1]
    print("".join(S))

Submission status: Runtime Error

Solution code:
from collections import deque

s = input().strip()
s = deque([*s])
q = int(input())

queries = [input().strip().split() for _ in range(q)]
is_reversed = False

for query in queries:
    t = query[0]
    if t == '1':
        is_reversed = not is_reversed
    else:
        f = query[1]
        c = query[2]
        if f == '1':
            if is_reversed:
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if is_reversed:
                s.appendleft(c)
            else:
                s.append(c)

str_list = list(s)
if is_reversed:
    str_list = reversed(str_list)

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

Submission status: Runtime Error

Solution code:
import math
S = input()
Q = int(input())
for n in range(Q):
    T,F,C = input()
    if T == "1":
        S = S[::-1]
    else:
        if F == "1":
            S = C + S
        else:
            S = S + C
print(S)

Submission status: Runtime Error

Solution code:
S,f=__import__('collections').deque(input()),0
for _ in range(int(input())):
	T=input()
	if'2'>T:f=1-f
	else:S.insert(0 if(T[2]<'2')^f else len(S),T[4])
if f:S.reverse()
print(*S,sep='')

Submission status: Runtime Error

Solution code:
S,f=__import__('collections').deque(input()),0
for _ in range(int(input())):
	T=input()
	if'2'>T:f=1-f
	else:S.insert(0if(T[2]<'2')^f else len(S),T[4])
if f:S.reverse()
print(*S,sep='')

Submission status: Runtime Error

Solution code:
from collections import deque

def main():
    S = list(input())
    Q = int(input())
    l = [list(input().split(' ')) for _ in range(Q)]

    d = deque(S)

    FLAG = False

    for li in l:
        if int(li[0]) == 1: # 前後反転
            if FLAG == True:
                FLAG = False
            else:
                FLAG = True
        
        elif int(li[0]) == 2: # 追加, li[1] == 1 => li[2]を先頭に，li[1] == 2 => li[2]を末尾
            if int(li[1]) == 1:
                if FLAG == True:
                    d.append(li[2])
                else:
                    d.appendleft(li[2])
            elif int(li[1]) == 2:
                if FLAG == True:
                    d.appendleft(li[2])
                else:
                    d.append(li[2])
                    
                # S.append(li[2])
        # print(S)
    if FLAG:
        d = d[::-1]
    print(''.join(d))


main()

Submission status: Runtime Error

Solution code:
import collections

def bfs(N):
    S = "abcdefghij"
    result = []
    deq = collections.deque(["a"])

    while deq:
        s = deq.popleft()
        if len(s) == N:
            result.append(s)
            continue
        else:
            for i in S[:len(set(s))+1]:
                deq.append(s + i)
    return result

N = int(input())
ans = bfs(N)
for a in ans:
    print(a)
exit()

Submission status: Runtime Error

Solution code:
#幅優先探索による全探索
from collections import deque

def bfs(N):
    S = "abcdefghij"
    result = []
    deq = deque(["a"])

    while deq:
        s = deq.popleft()
        if len(s) == N:
            result.append(s)
            continue
        else:
            for i in S[:len(set(s))+1]:
                deq.append(s + i)
    return result

N = int(input())
ans = bfs(N)
for a in ans:
    print(a)

Submission status: Runtime Error

Solution code:
#幅優先探索による全探索
from collections import deque

def bfs(N):
    S = "abcdefghij"
    result = []
    deq = deque(["a"])

    while deq:
        s = deq.popleft()
        if len(s) == N:
            result.append(s)
            continue
        else:
            for i in S[:len(set(s))+1]:
                deq.append(s + i)
    return result

N = int(input())
ans = bfs(N)
print('\n'.join(ans))

Submission status: Runtime Error

Solution code:
#幅優先探索による全探索
from collections import deque

def bfs(N):
    S = "abcdefghij"
    result = []
    deq = deque(["a"])

    while deq:
        s = deq.popleft()
        if len(s) == N:
            result.append(s + "\n")
            continue
        else:
            for i in S[:len(set(s))+1]:
                deq.append(s + i)
    return result

N = int(input())
ans = bfs(N)
print(''.join(ans))

Submission status: Runtime Error

Solution code:
S=list(input())
q=int(input())
for i in range(q):
  c=list(input().split())
  print(c)
  if c[0]=='1':
    S.reverse()
  elif c[0]=='2':
    if c[1]=='1':
      S.appendleft(c[2])
    elif c[1]=='2':
      S.append(c[2])
ans=''.join(S)
print(ans)

Submission status: Runtime Error

Solution code:
S=str(input())
S_list=list(S)

Q=int(input())

q=[]
right=[]
left=[]

rev=1

for i in range(Q):
    q.append(input().split())
    if q[i][0]=="1":
        rev=rev*(-1)
    elif q[i][0]=="2":
        if q[i][1]=="1":
            if rev==1:
                right.insert(0,q[i][2])
            else:
                left.append(q[i][2])
        elif q[i][1]=="2":
            if rev==1:
                left.append(q[i][2])
            else:
                right.insert(0,q[i][2])
if rev==1:
    S_list.append(left)
    S_list.insert(0,right)
else:
    S_list.reverse()
    S_list.append(left)
    S_list.insert(0,right)
    
S=''.join(S_list)
print(S)

Submission status: Runtime Error

Solution code:
S = input('')
Q = int(input(''))
rev_flag = 1
for i in range(Q):
    str = input('')
    if(str.count(' ') == 0 and str == '1'):
        rev_flag = -rev_flags
    elif(str[0] == '2' and ((str[2] == '1' and rev_flag == 1) or (str[2] == '2' and rev_flag == -1))):
        S = str[4] + S
    elif(str[0] == '2' and ((str[2] == '2' and rev_flag == 1) or (str[2] == '1' and rev_flag == -1))):
        S = S + str[4]
if rev_flag == 1:
    print(S)
elif rev_flag == -1:
    print(S[::-1])

Submission status: Runtime Error

Solution code:
from collections import deque

S = deque(input())
Q = int(input())
flip = False # True: left side is head
for i in range(Q):
  Query_i = list(map(str, input().split()))
  if Query_i[0]=='1':
    flip = not flip
  elif Query_i[1] == '1' and not flip:
    S.appendleft(Query_i[2])
  elif Query_i[1] == '1' and flip:
    S.append(Query_i[2])
  elif Query_i[1] == '2' and not flip:
    S.append(Query_i[2])
  elif Query_i[1] == '2' and flip:
    S.appendleft(Query_i[2])
if flip:
  S = S.reverse()
print(''.join(S))

Submission status: Runtime Error

Solution code:
S = input()
Q = int(input())
head = True # True: left side is head
for i in range(Q):
  Query_i = list(map(str, input().split()))
  if Query_i[0]=='1':
    head = not head
  elif Query_i[1] == '1' and head:
    S = Query_i[2] + S
  elif Query_i[1] == '1' and not head:
    S = S + Query_i[2]
  elif Query_i[1] == '2' and head:
    S = S + Query_i[2]
  else Query_i[1] == '2' and not head:
    S = Query_i[2] + S
  if not head:
    S = S[::-1]
print(S)

Submission status: Runtime Error

Solution code:
S = input()
Q = int(input())
for i in range(Q):
  Query_i = list(map(str, input().split()))
  if Query_i[0]=='1':
    S = S[::-1]
  elif Query_i[1] = '1':
    S = Query_i[2] + S
  else:
    S = S + Query_i[2]
print(S)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=input()
n=int(input())
front=""
back=""
reverse=False

for i in range(n):
  t=input().split()
  if t[0]=="1":
    reverse=not reverse
  else:
    if (t[1]=="1")and not reverse:
      front=front+t[2]
    elif (t[1]=="2")and reverse:
    else:
      back=back+t[2]
if reverse:
  print(back[::-1]+s+front)
else:
  print(front[::-1]+s+back)

Submission status: Runtime Error

Solution code:
n = int(input())

if n == 1:
    print('a')
    exit()

ans = []


def dfs(s, c):
    for i in range(ord('a'), ord(c) + 2):
        now = s + chr(i)
        if len(now) == n:
            ans.append(now)
        elif i > ord(c):
            dfs(now, chr(i))
        else:
            dfs(now, c)


dfs('a', 'a')

for c in ans:
    print(c)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    s = input()
    q = int(input())
    ans = s
    rev_count = 0
    leftList = []
    rightList =[]
    alist =[]

    for i in range(q):
        a = [i for i in input().split()]
        alist.append(a)
        if len(a) == 1:
            rev_count = rev_count +1

    if rev_count % 2 ==1:
        ans = ans[::-1]

    for i in alist:
        if len(i) == 3:
            rev_count = rev_count -1
        else:
            if int(i[1]) == 1:
                if rev_count % 2 == 1:
                    rightList.append(i[2])
                else:
                    leftList.append(i[2])

            else:
                if rev_count % 2 == 1:
                    leftList.append(i[2])
                else:
                    rightList.append(i[2])

    ans = leftList.join + ans+rightList.join

    print(ans)

Submission status: Runtime Error

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: Runtime Error

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
count = 0
for i in range(q):
  k = l[i][0]
  if(k == '1'):
    count += 1
  elif(k == '2'):
    c = count
    d = int(l[i][1])
    e = i[i][2]
    if((c + d) % 2 == 1):
      st = e + st
    elif((c + d) % 2 == 0):
      st = st + e

if(count % 2 == 1):
  st = st[::-1]
      
print(st)

Submission status: Runtime Error

Solution code:
    S = input()
    Q = int(input())
    reverse = False
    front = ""
    end = S
     
    for i in range(Q):
        inp = input()
        if inp[0] == "1":
            reverse = ~reverse
        else:
            _, F, C = inp.split()
            if (F == "1") ^ reverse:
                front =front+C
            else:
                end = end+C
     
     
    if reverse:
        print(end[::-1]+front)
    else:
        print(front[::-1]+end)

Submission status: Runtime Error

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: Runtime Error

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==bool(int(qq[1])-2):
            s.appendleft(qq[2])
        else:
            s.append(qq[2])

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

Submission status: Runtime Error

Solution code:
S = str(input())
n = int(input())
Q = [list(map(str, input().split())) for _ in range(n)]
cnt = 0
# for q in Q:
#     if q[0] == "1":
#         cnt += 1
# #         S.reverse()
#     elif q[0] == "2":
#         if (int(q[1])+cnt)%2 == 1:
#             S.insert(0,q[2])
#         else:
#             S.append(q[2])
for q in Q:
    if q[0] == "1":
        cnt += 1
    elif q[0] == "2":
        if (int(q[1])+cnt)%2 == 1:
            S = q[2] + S
        else:
            S = S + q[2]

if cnt%2==1:
    S.reverse()
print("".join(S))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from sys import stdin 
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline


S ,= input().split()
Q = int(input())



for _ in range(Q):
	ins = input().split()
	if len(ins) == 1:
		S = S[::-1]
	else:
		T, F, C = ins
		F = int(F) 
		if F == 1:
			S = str(C) + S

		else:
			S += str(C)


print (S)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

print(s)

Submission status: Runtime Error

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

Q = int(input())

A = np.array([S])

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

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

Submission status: Runtime Error

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

Q = int(input())

A = np.array([])
A = np.append(A,S)

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

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

Submission status: Runtime Error

Solution code:
def StrConv(S, T, F, C):
  ans = ''
  if T == '1':
    #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: Runtime Error

Solution code:
from collections import deque
S=deque(input())
Q=int(input())
F=0
for i in range(Q):
  N=list(input().split())
  if F==0:
    if N[0]=="1":
      F=1
    elif N[1]=="1":
      S.appendleft(N[2])
    else:
      S.append(N[2])
  elif F==1:
    if N[0]=="1":
      F=0
    elif N[1]=="1":
      S.append(N[2])
    else:
      S.appendleft(N[2])
if F==1:
  print("".join(S.reverse()))
else:
  print("".join(S))

Submission status: Runtime Error

Solution code:
from collections import deque
S=deque(input())
Q=int(input())
for i in range(Q):
  N=list(input().split())
  if N[0]=="1":
    S.reverse()
  elif N[1]="1":#先頭にC1
    S.appendleft(N[2])
  else:
    S.append(N[2])
print(S)

Submission status: Runtime Error

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

for i in range(q):
    x = input()
    if int(len(x)) == 1:
        a = int(x)
        if flg == False:
            flg = True
        else:
            flg = False
        print("G:",s)
    else:
        a, b, c = map(str, x.split()) 
        if flg == False and int(b) == 1:
            s = c + s
        elif flg == False and int(b) == 2:
            s = s + c
        elif flg == True and int(b) == 1:
            s = s + c
        else:
            s = c + s

if flg == True:
    s = s[::-1]
print(s)

Submission status: Runtime Error

Solution code:
s= list(input())
x=''
Q=int(input())
for i in range(Q):
	q,*l= input().split()
	#print(l)
	if int(q)==1:
		s=s[::-1]
	else:
		if(int(l[0])==1):
			s.insert(0,l[1])
		else:
			s.append(l[1])
	x=''.join(s)
	print(x)

Submission status: Runtime Error

Solution code:
from collections import deque

S = deque(input())
queryNum = input()
flip = False
for i in range(int(queryNum)):
	order = input()
	if order == '1':
		if flip:
			flip = False
		else:
			flip = True
	else:
		if order[2] == '1':
			if not flip:
				S.appendleft(order[4])
			elif flip:
				S.appendright(order[4])
		else:
			if not flip:
				S.appendright(order[4])
			elif flip:
				S.appendleft(order[4])
S = ''.join(S)
if flip:
	print(S[::-1])
else: 
	print(S)

Submission status: Runtime Error

Solution code:
from collections import deque

c = deque(input())
n = int(input())
head = 1

for _ in range(n):
  now = list(input().split())
  if now[0] == "1":
    head *= -1
  else:
    if now[1] == "1":
      if head == 1:
        c.appendleft(now[2])
      else:
        c.append(now[2])
    else:
      if head == 1:
        c.append(now[2])
      else:
        c.appendleft(now[2])
      
print("".join(c) if head == 1 else "".join(c[::-1]))

Submission status: Runtime Error

Solution code:
from typing import List


class Solution:

    def solve(self, S: str, Q: int, Query) -> int:

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

        if num_reverse % 2 == 1:
            S = S[::-1]

        return S


if __name__ == '__main__':

    # standard input
    S = input()
    Q = int(input())
    Query = []
    for _ in range(Q):
        Query.append(tuple(input().split()))

    # solve
    solution = Solution()
    print(solution.solve(S, Q, Query))

Submission status: Runtime Error

Solution code:
S = input()
queryNum = input()
for i in queryNum:
	order = input()
	if order == 1:
		S = S[::-1]
	else:
		if order[0] == 1:
			S = order[2] + S
		else:
			S = S + order[2]
print(S)

Submission status: Runtime Error

Solution code:
from collections import deque

S = input()
Q = int(input())
q = deque(S)
fg = False

for i in range(Q):
    que = list(map(str , input().split()))
    if que[0] == "1":
        fg = not fg
    elif (que[1] == "1" and fg == False) or (que[1] == "2" and fg == True) :
        q.appendleft(que[2])
    else:
        q.append(que[2])

if not fg:
    q.reverse()

print("".join(q))a

Submission status: Runtime Error

Solution code:
S = input()
Q = int(input())
fg = False
que2 = []
que2.append(S)

for _ in range(Q+1):
    que = list(map(str, input().split()))
    if que[0] == "1":
        que2.reverse()
    elif que[1] == "1":
        que2.insert(0,que[2])
    elif que[1] == "2":
        que2.append(que[2])
        
ans = "".join(que2)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque

S = input()
Q = int(input())
d = deque(S)
fg = False
for i in range(Q):
    que = list(map(str , input().split()))
    if que[0] == "1":
        fg = True
    elif (que[1] == "1" and fg == False) or (que[1] == "2" and fg == True) :
        q.appendleft(que[2])
    else:
        q.append(que[2])
if fg:
    q.reverse()
print("".join(q))

Submission status: Runtime Error

Solution code:
# coding: utf-8

str = list(input())
num = int(input())

for i in range(num):
    list = input().split()
    if list[0]=="1":
        str = str.reversed()
    if list[0]=="2":
        if list[1]=="1":
            str.insert(0, list[2])
        if list[1]=="2":
            str.append(list[2])
print("".join(str))

Submission status: Runtime Error

Solution code:
S = input()
Q = int(input())
if Q != 1:
    Qr = [list(input().split()) for i in range(Q)]
isForward = True
for i in range(Q):
    if Qr[i][0] == "1":
        isForward = not(isForward)
    elif (isForward and  Qr[i][1] == "1") or (not(isForward) and Qr[i][1] == "2"):
        S = Qr[i][2] + S
    else:
        S = S + Qr[i][2]
if not(isForward):
    S = S[::-1]
print(S)

Submission status: Runtime Error

Solution code:
from collections import deque
S=deque([input()])
q=int(input())
rev=False
for i in range(q):
   s=input()
   if s=="1":
      rev= not rev
   else:
      t,f,c=s.split()
      if (rev==False and f=="1") or (rev==True and f=="2"):
         S.appendleft(c)
      else:
         S.append(c)
if rev==False:
   print("".join(S))
else:
   print("".join(S[::-1]))

Submission status: Runtime Error

Solution code:
from collections import deque
 
S = input()
Q = int(input())
S = deque(S)
 
flg_reverse = False
 
for q in range(Q):
  _ = input()
  if _[0] == '1':
    flg_reverse = flg_reverse ^ True
  else:
    _T, _F, _C = _.split()
    ## リバース回数が奇数偶数のいずれかをチェック
    if _F == '1':
      if cnt_reverse % 2 == 0:
        S.appendleft(_C)
      else:
        S.append(_C)
    else:
      if cnt_reverse % 2 == 0:
        S.append(_C)
      else:
        S.appendleft(_C)
 
S = list(S)
# reverseの部分を対応
if flg_reverse:
  S.reverse()
 
print(''.join(S))

Submission status: Runtime Error

Solution code:
from collections import deque

s = deque(input())
q = int(input())
rev = 0 # revが0のとき先頭、1のとき後尾

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

    if len(t) == 1:
        rev ^= 1
    else:
        if rev == 1:
            if t[1] == '1':
                s.append(t[2])
            else:
                s.appendleft(t[2])
        else:
            if t[1] == '1':
                s.appendleft(t[2])
            else:
                s.append(t[2])

if rev == 1:
    s.reverse()

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

print()

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())

for num in range(12000):
    a_ = int(num * 0.08)
    b_ = int(num * 0.1)
    if a_ == a and b_ == b:
        print(num)
        break
else:
  print(-1)