Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    q = int(input())
    rev = 0
    for i in range(q):
        Q = input().split()
        if Q[0]=="1":
            rev = (rev+1)%2
        else:
            if Q[1]=='1':
                if rev==0:
                    s = Q[2]+s
                else:
                    s = s+Q[2]
            else:
                if rev==0:
                    s = s+Q[2]
                else:
                    s = Q[2]+s
    if rev==0:
        print(s)
    else:
        print(s[::-1])

if __name__ == "__main__":
    main()

Fixed submission:
s = input()
q = int(input())

t = 0
l = ''
r = ''
for i in range(q):
    query = input()
    if query == '1':
        if t == 1:
            t = 0
        else:
            t = 1
    else:
        if query[2] == '1':
            if t == 0:
                l = query[4:]+l
            else:
                r = r+query[4]
        else:
            if t == 0:
                r = r+query[4]
            else:
                l = query[4] + l
s = l+s+r
if t == 1:
    print(s[::-1])
else:
    print(s)

Buggy python submission (verdict: Runtime Error):
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$ 

Fixed submission:
s = input()
q = int(input())

t = 0
l = ''
r = ''
for i in range(q):
    query = input()
    if query == '1':
        if t == 1:
            t = 0
        else:
            t = 1
    else:
        if query[2] == '1':
            if t == 0:
                l = query[4:]+l
            else:
                r = r+query[4]
        else:
            if t == 0:
                r = r+query[4]
            else:
                l = query[4] + l
s = l+s+r
if t == 1:
    print(s[::-1])
else:
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

t = 0
for i in range(q):
    query = input()
    if query == '1':
        if t == 1:
            t = 0
        else:
            t = 1
    else:
        if query[2] == '1':
            if t == 0:
                s = query[4]+s
            else:
                s = s+query[4]
        else:
            if t == 0:
                s = s+query[4]
            else:
                s = query[4] + s

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

Fixed submission:
s = input()
q = int(input())

t = 0
l = ''
r = ''
for i in range(q):
    query = input()
    if query == '1':
        if t == 1:
            t = 0
        else:
            t = 1
    else:
        if query[2] == '1':
            if t == 0:
                l = query[4:]+l
            else:
                r = r+query[4]
        else:
            if t == 0:
                r = r+query[4]
            else:
                l = query[4] + l
s = l+s+r
if t == 1:
    print(s[::-1])
else:
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

t = 0
for i in range(q):
    query = input()
    if query == '1':
        if t == 1:
            t = 0
        else:
            t = 1
    else:
        if query[2] == '1':
            if t == 0:
                s = query[4:]+s
            else:
                s = s+query[4:][::-1]
        else:
            if t == 0:
                s = s+query[4:]
            else:
                s = query[4:][::-1] + s

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

Fixed submission:
s = input()
q = int(input())

t = 0
l = ''
r = ''
for i in range(q):
    query = input()
    if query == '1':
        if t == 1:
            t = 0
        else:
            t = 1
    else:
        if query[2] == '1':
            if t == 0:
                l = query[4:]+l
            else:
                r = r+query[4]
        else:
            if t == 0:
                r = r+query[4]
            else:
                l = query[4] + l
s = l+s+r
if t == 1:
    print(s[::-1])
else:
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

for i in range(q):
    query = input()
    if query[0] == '1':
        s = s[::-1]
    else:
        if query[2] == '1':
            s = query[4]+s
        else:
            s = s+query[4]
print(s)

Fixed submission:
s = input()
q = int(input())

t = 0
l = ''
r = ''
for i in range(q):
    query = input()
    if query == '1':
        if t == 1:
            t = 0
        else:
            t = 1
    else:
        if query[2] == '1':
            if t == 0:
                l = query[4:]+l
            else:
                r = r+query[4]
        else:
            if t == 0:
                r = r+query[4]
            else:
                l = query[4] + l
s = l+s+r
if t == 1:
    print(s[::-1])
else:
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

for i in range(q):
    query = input()
    if query[0] == '1':
        s = list(s)
        s.reverse()
        s = ''.join(s)
    else:
        if query[2] == '1':
            s = query[4]+s
        else:
            s = s+query[4]
print(s)

Fixed submission:
s = input()
q = int(input())

t = 0
l = ''
r = ''
for i in range(q):
    query = input()
    if query == '1':
        if t == 1:
            t = 0
        else:
            t = 1
    else:
        if query[2] == '1':
            if t == 0:
                l = query[4:]+l
            else:
                r = r+query[4]
        else:
            if t == 0:
                r = r+query[4]
            else:
                l = query[4] + l
s = l+s+r
if t == 1:
    print(s[::-1])
else:
    print(s)