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()
Q = int(input())
Q_list = list()
for i in range(Q):
    Q_list.append(input().split())
 
from collections import deque
def operate(i):
    global count, str_list
    if Q_list[i][0] == '1':
        count += 1
    else:
        if count % 2 == 0:
            if Q_list[i][1] == '1':
                str_list.appendleft(Q_list[i][2])
            else:
                str_list.append(Q_list[i][2])
        else:
            if Q_list[i][1] == '1':
                str_list.append(Q_list[i][2])
            else:
                str_list.appendleft(Q_list[i][2])
 
check = 0
for i in range(Q):
    if Q_list[i][0] == '1':
        check += 1
 
if check % 2 == 1:
    S_list = list(reversed(S_list))
 
str_list = deque()
str_list.append(S)
count = check%2
for i in range(Q):
    operate(i)
print(''.join(str_list))

Submission status: Runtime Error

Solution code:
from collections import deque
S = deque(input())
Q = int(input())
rev = 0
for i in range(Q):
  query = input()
  if query == "1": rev = 1 - rev 
  elif int(query[2]) + rev == 2: S.append(query[4])
  else:S.insert(0,query[4])
if rev == 1: S.reverse()  
print("".join(S))

Submission status: Runtime Error

Solution code:
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11^CTraceback (most recent call last):
  File "/Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py", line 48, in <module>
    main(ptvsdArgs)
  File "/Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 432, in main
    run()
  File "/Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 316, in run_file
    runpy.run_path(target, run_name='__main__')
  File "/Users/kenmurata/anaconda3/lib/python3.7/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/Users/kenmurata/anaconda3/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/Users/kenmurata/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/kenmurata/practice/AtCoder/test.py", line 10, in <module>
    print(j)
KeyboardInterrupt
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 63018 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
^CTraceback (most recent call last):
  File "/Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py", line 48, in <module>
    main(ptvsdArgs)
  File "/Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 432, in main
    run()
  File "/Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 316, in run_file
    runpy.run_path(target, run_name='__main__')
  File "/Users/kenmurata/anaconda3/lib/python3.7/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/Users/kenmurata/anaconda3/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/Users/kenmurata/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/kenmurata/practice/AtCoder/test.py", line 10, in <module>
    if int(s[j:j+nagasa]) == tansaku:
KeyboardInterrupt
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 63781 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cpa
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 51171 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cpa
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 51236 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cbaa
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 51386 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cbaa
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 51967 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cbaa
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 52232 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
0
0
0
1
1
0
cbaa
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 52636 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
0
0
0
1
1
0
aabc
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 52680 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
aabc
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 52735 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
xy
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 55393 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
xy
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 55498 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
aacb
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 55580 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
pca
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 56916 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cap
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 57679 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cap
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 58073 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
c p
cap
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 58448 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
 cp
acp
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 59236 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
 cp
acp
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 59555 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
 c
ac
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 62327 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cp 
a
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 62438 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cpa
cpa
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 62627 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
aabc
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 62684 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
xy
(base) bash-3.2$

Submission status: Runtime Error

Solution code:
S = list(input())
Q = int(input())
S_r = []
S_l = []

n = 0

for i in range(Q):
  q = list(input().split())
  if int(q[0]) == 1:
    n += 1
  else:
      if int(q[1]) == 1:
        S_l.append(q[2])
        S_r = S
        n += 1
        break
      else:
        S_r.append(q[2])
        S_l = S
        n += 1
        break

  if i == Q-1:
    if not S_r and not S_l
      print(''.join(S))
    elif not S_r
      print(''.join(S_l[::-1]), end="")
      print(''.join(S))
    elif not S_l
      print(''.join(S), end="")
      print(''.join(S_r))

for i in range(Q - n):
  q = list(input().split())
  if int(q[0]) == 1:
    temp = S_r[-1]
    S_r[-1] = S_l[-1]
    S_l[-1] = temp
  else:
    if int(q[1]) == 1:
      S_l.append(q[2])
    else:
      S_r.append(q[2])

print(''.join(S_l[::-1]), end="")
print(''.join(S_r))

Submission status: Runtime Error

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

for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        if not len(L) == 1:
            L.reverse()
    else:	
        if a[1] == '1':
            L.append(a[2])
        else:
            L.insert(0, a[2])
x = "".join(L.reverse)
print()

Submission status: Runtime Error

Solution code:
S=input()
n=int(input())
l = [list(input()) for _ in range(n)]
z=1
for i in range(n):
    if l[i][0]=='1':
        #new_S = S[::-1]
        #S=new_S
        z=z*(-1)
    else:
        a=l[i][4]
        if l[i][2]=='1'and z==1:
            #S='' . join([a,S])
            S=a.append(S)
        elif l[i][2]=='2'and z==1:
            #S='' . join([S,a])
            S.append(a)
        elif  l[i][2]=='1'and z==-1:
            #S='' . join([S,a])
            S.append(a)
        else:
            #S='' . join([a,S])
            a=a.append(S)
if z==1:
  print(S)
else:
  print(S[::-1])

Submission status: Runtime Error

Solution code:
N = input()
Q = int(input())
Qs = []
for _ in range(Q):
    Qs.append(list(map(str, input().split())) ) 
k=0
for q in Qs:
    if q[0] == '1':
        k+=1
    else:
        if (k%2 ==0　& q[1] == '1') or (k%2==1 & q[1] == '2'):
            N = q[2] + N
        else:
            N = N + q[2]

if k%2==1:
    ans = ''.join(list(reversed(N)))
    print(ans)
else:
    print(N)

Submission status: Runtime Error

Solution code:
s = [input()]
q = int(input())
for i in range(q):
    inp = input().split()
    if len(inp) == 1:
        s = s[::-1]
        print(s)
    else:
        if int(inp[1])==1:
            s.insert(0,inp[2])
        else:
            s.append(inp[2])
        print(s)
print(''.join(s))

Submission status: Runtime Error

Solution code:
import numpy as np

S=input()
Q=int(input())
Qs=np.zeros((Q,2))
qs=['']*Q
a=[]
for i in range(Q):
    a=input().split()
    #print(a)
    if int(a[0])==2:
        Qs[i][0]=int(a[0])
        Qs[i][1]=int(a[1])
        qs[i]=a[2] 
        #print("here")   
    else:
        Qs[i][0]=int(a[0])

que=[S]
for i in range(Q):
    if Qs[i][0]==1:
        tmp=que[0]
        que[0]=que[len(que)-1]
        que[len(que)-1]=tmp
    else:
        if Qs[i][1]==1:
            #que=qs[i]+que
            que.insert(0,qs[i])
        else:
            #que=que+qs[i]
            que.append(qs[i])
        
c=''
print(que)
for i in range(len(qs)+1):
    c=c+que[i]
print(c)

Submission status: Runtime Error

Solution code:

if __name__ == "__main__":
    S = input()
    Q = int(input())
    S = []
    C = []
    for i in range(Q):
        Qu = input().split()
        if Qu[0] == "1":
            S[::-1]
        elif Qu[0] == "2":
            if Qu[1] == "1":
                S = Qu[2] + S[0]
            elif Qu[1] == "2":
                S = S + Qu[2]
    print(S)

Submission status: Runtime Error

Solution code:


if __name__ == "__main__":
    S = input()
    Q = int(input())
    S = []
    C = []
    for i in range(Q):
        Qu = input().split()
        if Qu[0] == "1":
            S[::-1]
        elif Qu[0] == "2":
            if Qu[1] == "1":
                S = Qu[2] + S[0]
            elif Qu[1] == "2":
                S = S + Qu[2]
    print(S)

Submission status: Runtime Error

Solution code:
from collections import deque
def main():
    S = input().split()
    Q = int(input())
    ir = False
    ans = deque(S)
    for _ in range(Q):
        Query = input()
        if Query == '1':
            ir = not ir
        else:
            Query = Query.split()
            if (Query[1] == '1' and (not ir)) or (Query[1] == '2' and ir):
                ans.appendleft(Query[2])
            else:
                ans.append(Query[2])

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

main()

Submission status: Runtime Error

Solution code:
import math,sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
li = lambda:list(map(int,input().split()))

def case():
    s=input().strip()
    d=deque()
    for i in s:
        d.append(s)
    q=int(input())
    c=0
    for i in range(q):
        a=list(map(str,input().split()))
        if(a[0]=="1"):
            c+=1
        else:
            if(c%2=="0"):
                if(a[1]=="1"):
                    d.appendleft(a[2])
                else:
                    d.append(a[2])
            else:
                if(a[1]=="1"):
                    d.append(a[2])
                else:
                    d.appendleft(a[2])
    s=[]
    for i in d:ok
        s.append(i)
    s="".join(map(str,s))
    if(c%2==0):
        print(s)
    else:
        print(s[::-1])


for _ in range(1):
    case()

Submission status: Runtime Error

Solution code:
import sys
import math
def inp():return sys.stdin.readline().replace("\n","")
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def strl():return [str(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
s = l()
n = i()
f = 0
r =""
for i in range(n):
    a = strl()
    if len(a) == 1:
        f = 1
    else:
        if a[1] == "1" and f ==0:
            f = 1
        elif a[1] == "1" and f == 1:
            f = 0
        else:
            if f == 0:
                f = 1
            else:
                f = 0
if f == 0:
    s = a[2] +s
else:
    s = s +a[2]
print(r)

Submission status: Runtime Error

Solution code:
import sys
from collections import deque

s = deque([sys.stdin.readline().rstrip()])
q = int(input())
cnt = 0
for i in range(q):
    query = sys.stdin.readline().split()
    if query[0] == '1':
        cnt = (cnt + 1)%2
    else:
        if (int(query[1]) + cnt)%2 == 1:
            s.appendleft(query[2])
        else:
            s.append(query[2])

if cnt:
    s = "".join(s)
print(s[::-1])

Submission status: Runtime Error

Solution code:
S = input()
Q = int(input())
Q_list = list()
for i in range(Q):
    Q_list.append(input().split())
  
from collections import deque
def operate(i):
    global count, str_list
    if Q_list[i][0] == '1':
        count += 1
    else:
        if count % 2 == 0:
            if Q_list[i][1] == '1':
                str_list.appendleft(Q_list[i][2])
            else:
                str_list.append(Q_list[i][2])
        else:
            if Q_list[i][1] == '1':
                str_list.append(Q_list[i][2])
            else:
                str_list.appendleft(Q_list[i][2])

check = 0
for i in range(Q):
    if Q_list[i][0] == '1':
        check += 1

if check % 2 == 1:
    S_list = list(reversed(S_list))

str_list = deque()
str_list.append(S)
count = 0
for i in range(Q):
    operate(i)
print(''.join(str_list))

Submission status: Runtime Error

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

for i in range(q):
  t = input().split()
  if t[0] == '1':
    ss = ss[::-1]
  else:
    if t[1] == '2':
      ss.append(t[2])
    else:
      ss.insert(0,t[2]

print("".join(ss))

Submission status: Runtime Error

Solution code:
from collections import deque
S = input()
Q = int(input())
R = 1
Top = deque()
Bot = deque()
for _ in range(Q):
  inp = input()
  if inp[0]=='1':
    R *= -1
  else:
    o, f, c = inp.split()
    if f=='1' and R==-1 or f=='2' and R==1:
      Bot.append(c)
    else:
      Top.appendleft(c)
Top.append(S)
if not len(Bot)==0:
  Top = [*Top]+[*Bot]
S = ''.join(Top)
S = S if R==1 else S[::-1]
print(S)

Submission status: Runtime Error

Solution code:
def main():
    S = list(input().split())
    Q = int(input())

    for i in range(Q):
        QList = list(input().split())
    
        if QList[0] == '1':
            S = S[::-1]
        else:
            if QList[1] == '1':
                S = QList[2].join(S)
            else:
                S = S.join(QList[2])
    print(S)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
from collections import deque

s = deque([sys.stdin.readline().rstrip()])
q = int(input())
cnt = 0
for i in range(q):
    query = sys.stdin.readline().split()
    if query[0] == '1':
        cnt = (cnt + 1)%2
    else:
        if (int(query[1]) + cnt)%2 == 1:
            s.appendleft(query[2])
        else:
            s.append(query[2])

if cnt:
    s = "".join(s)
print(s.reverse())

Submission status: Runtime Error

Solution code:
S = input().split()
Q = int(input())
switch = 1
for i in range(Q):
    a =input().split()
    if int(a[0])==1:
        switch *=-1
    else:
        if (int(a[1])==1 and switch ==1) or (int(a[1])==2 and switch ==-1):
            S.insert(0,a[2])
        else:
            S.append(a[2])
if switch ==1:
    print(S)
else switch ==-1:
    print(S.reverse())

Submission status: Runtime Error

Solution code:
def main():
    S=[input()]
    for i in range(int(input())):
        T = input()
        if T == '1':
            S = S[::-1]
        else:
            ta = T.split()
            F = int(ta[1])
            C = ta[2]
            if F == 1:
                S.insert(0, C)
            else:
                S.appendC)

    print(''.join(S))

main()

Submission status: Runtime Error

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

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

for i in range(Q):
  if A[i] == ("1"):
    S = ''.join(list(reversed(S)))
  else:
    if A[i][1] == "1":
      S = A[i][2] + "S"
    else:
      S = "S" + A[i][2] 
      
print(S)

Submission status: Runtime Error

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

for i in range(q):
  li= map(str,input().split())
  if li[0]=='1':
    isOrdered = not isOrdered
  else:
    if li[1]=='1':
      s = s+li[2] if isOrdered else li[2]+s
    else:
      s = li[2]+s if isOrderd else s+li[2]
     
print(s if isOrdered else s[::-1])

Submission status: Runtime Error

Solution code:
s = input()
q = int(input())
cnt = 0
for i in range(q):
    t_f_c = list(input().split())
    #反転する=先末逆転
    if t_f_c[0] == "1":
        cnt  += 1
    #反転しない
    elif t_f_c[0] == "2":
        if cnt % 2 == 0:
            if t_f_c[1] == "1":
                s = t_f_c[2] + s
            elif t_f_c[1] == "2":
                s = s + t_f_c[2]
        elif cnt % 2 == 1:
            if t_f_c[1] == "1":
                s = s + t_f_c[2]
            elif t_f_c[1] == "2":
                s = t_f_c[2] + s
if cnt % 2 == 0:
    print(s)
elif cnt % 2 == 1:
    print("".join((list(s)).reverse()))

Submission status: Runtime Error

Solution code:
def resolve():
    from collections import deque
    d=deque()
    s=list(input())
    d.extend(s)
    #print(d)
    q=int(input())
    Q=[list(map(str,input().split())) for i in range(q)]

    #print(Q)
    for i in range(q):
        if int(Q[i][0])==1:
            if i!=q-1 and int(Q[i+1][0])==2 and int(Q[i+1][1])==1:
                d.append(int(Q[i+1][2]))
                d.reverse()
                i=i+1
            else:
                d.reverse()
            #print(s)
        elif int(Q[i][0])==2:
            if int(Q[i][1])==1:
                d.appendleft(Q[i][2])
                #print(s)
            else:
                d.append(Q[i][2])
                #print(s)
    print(''.join(list(d)))






resolve()

Submission status: Runtime Error

Solution code:
s=input()
q=int(input())
total_t=1
result=[s]
for i in range(q):
  t=input()
  if t=="1":
    total_t=total_t*(-1)
  else:
    f=(t.split())[1]
    c=(t.split())[2]
    if (f=='1' and total_t==1) or (f=='2' and total_t==-1):
      result.appendleft(c)
    else:
      result.append(c)
if total_t==-1:
  result.reverse()
r=''.join(result)
print(r)

Submission status: Runtime Error

Solution code:
def main():
    S = list(input())
N = int(input())
t = [0] * N
f = [0] * N
c = [0] * N
for i in range(N):
    li = list(input().split())
    
    if li[0] == '1':
        S = S[::-1]
    else:
        if li[1] == '1':
            S[0:0] = li[2]
        elif li[1] == '2':
            S.extend(li[2])
        
print(''.join(S))
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math,sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
li = lambda:list(map(int,input().split()))

def case():
    s=input().strip()
    d=deque()
    for i in s:
        d.append(s)
    q=int(input())
    c=0
    for i in range(q):
        a=list(map(str,input().split()))
        if(a[0]=="1"):
            c+=1
        else:
            if(c%2=="0"):
                if(a[1]==1):
                    d.appendleft(a[2])
                else:
                    d.append(a[2])
            else:
                if(a[1]==1):
                    d.append(a[2])
                else:
                    d.appendleft(a[2])
    s=[]
    for i in d:
        s.append(i)
    s="".join(map(str,s))
    if(c%2==0):
        print(s)
    else:
        print(s[::-1])


for _ in range(1):
    case()

Submission status: Runtime Error

Solution code:
def q1(s):
    #reverse
    return s[::-1]
def q2(s,f,char):
    if int(f) == 1:
        s = char + s
    else:
        s= s + char
    return s


s = input()
q = int(input())
for i in range(q):
    query = input().split()
    if len(query)==1:
        s=q1(s)
    else:
        s=q2(s,query[1],query[2])
    print(s)

Submission status: Runtime Error

Solution code:
s = input()
q = int(input())
count = 0
for i in range(q):
    t = int(input())
    if t == 2:
        f = int(input())
        c = input()
        if f == 1:
            st = c + s
            s = st
        else:
            st = s + c
            s = st
    else:
        st = (s[::-1])
        s = st
print(s)

Submission status: Runtime Error

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

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

ans = S
flag = True

for i in range(Q):
    if query[i][0] == '1':
        if flag:
            flag = False
        else:
            flag = True
        continue
    elif query[i][0] == '2':
        f = query[i][1]
        c = query[i][2].rstrip()
        if f == '1' and flag:
            ans = c + ans
        elif f == '1' and not flag:
            ans = ans + c
        elif f == '2' and flag:
            ans = ans + c
        elif f == '2' and not flag:
            ans = c + ans
if flag:
    print(ans)
else:
    print(''.join(list(ans).reverse()))