qyliang/CodeNanoFix huggingface dataset:
Buggy code:
a = list(map(int,input().split()))
A = a[0]
B = a[1]
c = True
for x in range(10001):
    a = x * 0.08
    b = x * 0.1
    if A == round(a,2) and B == round(b,2):
        print(x)
        c = False
        break
if c:
    print(-1)

Fixed code:
a = list(map(int,input().split()))
A = a[0]
B = a[1]
c = True
for x in range(10001):
    a = x * 0.08
    b = x * 0.1
    if A == int(a) and B == int(b):
        print(x)
        c = False
        break
if c:
    print(-1)
Buggy code:
import math

A, B = map(int, input().split())

min_A = math.ceil(A * 100 / 8)
max_A = ((A + 1) * 100 / 8
min_B = math.ceil(B * 100 / 10)
max_B = (B + 1) * 100 / 10

if (min_A <= min_B and min_B < max_A):
    ans = min_B
elif (min_B <= min_A and min_A < max_B):
    ans = min_A
else:
    ans = -1

print(ans)


Fixed code:
import math

A, B = map(int, input().split())

min_A = math.ceil(A * 100 / 8)
max_A = (A + 1) * 100 / 8
min_B = math.ceil(B * 100 / 10)
max_B = (B + 1) * 100 / 10

if (min_A <= min_B and min_B < max_A):
    ans = min_B
elif (min_B <= min_A and min_A < max_B):
    ans = min_A
else:
    ans = -1

print(ans)
Buggy code:
a,b = map(int,input().split())
for x in range(100):
    if (int(x*0.08) == a) and (int(x*0.1) == b):
        print(x)
        break
else:
    print("-1")

Fixed code:
a,b = map(int,input().split())
for x in range(100000):
    if (int(x*0.08) == a) and (int(x*0.1) == b):
        print(x)
        break
else:
    print("-1")
Buggy code:
A, B = list(map(int, input().split()))

begin = int(min(A // 0.08, B // 0.10))
end = int(max((A + 1) // 0.08, (B + 1) // 0.10))

for n in range(begin, end+1):
  if int(n * 0.08) == A and int(n * 0.1) == B:
    print(n)
    break
    else:
      print(-1)


Fixed code:
A, B = list(map(int, input().split()))

begin = int(min(A // 0.08, B // 0.10))
end = int(max((A + 1) // 0.08, (B + 1) // 0.10))

for n in range(begin, end+1):
    if int(n * 0.08) == A and int(n * 0.1) == B:
        print(n)
        break
else:
    print(-1)
Buggy code:
[A, B] = list(map(int, input().split()))

ans = 0
for i in range(1250) :
    if int(i * 0.08) == A and int(i * 0.1) == B :
        ans = i
        break

if ans == 0 :
    ans = -1

print(ans)
print(A)


Fixed code:
[A, B] = list(map(int, input().split()))

ans = 0
for i in range(1250) :
    if int(i * 0.08) == A and int(i * 0.1) == B :
        ans = i
        break

if ans == 0 :
    ans = -1

print(ans)
Buggy code:
A, B=list(map(int,input().split()))

a = int(A*12.5)
b = B*10
ans = -1

if a < b:
    for i in range(a, b+2):
        if (int(i*0.1) == B) and (int(i*0.08) == A):
            ans = i

else:
    for i in range(b, a+2):
        if (int(i*0.1) == B) and (int(i*0.08) == A):
            ans = i

print(ans)


Fixed code:
A, B=list(map(int,input().split()))

a = int(A*12.5)
b = B*10
ans = -1

if a < b:
    for i in range(a, b+2):
        if (int(i*0.1) == B) and (int(i*0.08) == A):
            if ans == -1:
                ans = i

else:
    for i in range(b, a+2):
        if (int(i*0.1) == B) and (int(i*0.08) == A):
            if ans == -1:
                ans = i

print(ans)
Buggy code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve(inp):
    (A, B) = map(int, inp.readline().strip().split(' '))

    b1 = B * 11
    b2 = (B + 1) * 11
    for i in range(b1, b2 + 1):
        if int(i * 0.08) == A and int(i * 0.1) == B:
            return str(i)

    return "-1"


def main():
    import sys
    result = solve(sys.stdin)
    if result is not None and result != '':
        print(result)


if __name__ == '__main__':
    main()


Fixed code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve(inp):
    (A, B) = map(int, inp.readline().strip().split(' '))

    b1 = B * 10
    b2 = (B + 1) * 10
    for i in range(b1, b2 + 1):
        if int(i * 0.08) == A and int(i * 0.1) == B:
            return str(i)

    return "-1"


def main():
    import sys
    result = solve(sys.stdin)
    if result is not None and result != '':
        print(result)


if __name__ == '__main__':
    main()
Buggy code:
A, B = map(int, input().split())
for n in range(1, 2000):
    if n * 0.08 == A and n * 0.1 == B:
        print(n)
        break
else:
    print(-1)

Fixed code:
A, B = map(int, input().split())
for n in range(2000):
    if int(n * 0.08) == A and int(n * 0.1) == B:
        print(n)
        break
else:
    print(-1)
Buggy code:

A, B = map(int, input().split())

#maxA = A+0.99
#maxB = B+0.99

maxA = A+1
maxB = B+1

gAmin = A/8 * 100
gAmax = maxA/8 * 100

gBmin = B*10
gBmax = maxB * 10

#print(gAmin)
#print(gAmax)
#print(gBmin)
#print(gBmax)

if gAmax <= gBmin or gBmax <= gAmin:
    ans = -1
elif gAmin <= gBmin:
    ans = gBmin
else:
    ans = gAmin

if ans - int(ans) > 0:
    ans = int(ans) + 1

print(ans)


Fixed code:

A, B = map(int, input().split())

#maxA = A+0.99
#maxB = B+0.99

maxA = A+1
maxB = B+1

gAmin = A/8 * 100
gAmax = maxA/8 * 100

gBmin = B*10
gBmax = maxB * 10

#print(gAmin)
#print(gAmax)
#print(gBmin)
#print(gBmax)

if gAmax <= gBmin or gBmax <= gAmin:
    ans = -1
elif gAmin <= gBmin:
    ans = gBmin
else:
    ans = gAmin

if ans - int(ans) > 0:
    ans = int(ans) + 1

print(int(ans))
Buggy code:
A, B = map(int, input().split(' '))
for i in range(1, 1500):
    if i * 8 // 100 == A and i * 10 // 100 == B:
        print(i)
        break

Fixed code:
A, B = map(int, input().split(' '))
for i in range(1500):
    if i * 8 // 100 == A and i * 10 // 100 == B:
        print(i)
        break
else:
    print(-1)
Buggy code:
A, B = map(int, input().split(' '))
rst = -1
for i in range(1, 100000):
    if i * 8 // 100 == A & i * 10 // 100 == B:
        rst = i
        break
print(rst)

Fixed code:
A, B = map(int, input().split(' '))
rst = -1
for i in range(1, 100000):
    if i * 8 // 100 == A and i * 10 // 100 == B:
        rst = i
        break
print(rst)
Buggy code:
A,B=map(int,input().split())
A*=100
B*=100
for i in range(2000):
  t*=100
  if A==t*8 and B==t*10:
    print(i)
    break
else:
    print(-1)


Fixed code:
A,B=map(int,input().split())
for i in range(2000):
  if A==i*8//100 and B==i*10//100:
    print(i)
    break
else:
    print(-1)
Buggy code:
A, B = map(int, input().split())
for i in range(20000):
    if int(i*0.08) == A and (i * 0.1) == B:
        print(i)
        exit()
print(-1)

Fixed code:
A, B = map(int, input().split())
for i in range(20000):
    if int(i*0.08) == A and int(i * 0.1) == B:
        print(i)
        exit()
print(-1)
Buggy code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 20:20:19 2020

@author: Kanaru Sato
"""

a, b = list(map(int, input().split()))
l = []

if a//0.08 == a/0.08:
    i = int(a/0.08)
else:
    i = int(a/0.08)+1

while 0.08*i < a+1:
    l.append(i)
    i += 1

flag = 0

for candidate in l:
    if 0.1*candidate < b+1 and 0.1*candidate >= b:
        print(candidate)
        flag = 1
        break

if flag != 1:
    print(-1)

Fixed code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 20:20:19 2020

@author: Kanaru Sato
"""

a, b = list(map(int, input().split()))
l = []

i = -(-1*a//0.08)

while 0.08*i < a+1:
    l.append(i)
    i += 1

flag = 0

for candidate in l:
    if 0.1*candidate < b+1 and 0.1*candidate >= b:
        print(int(candidate))
        flag = 1
        break

if flag != 1:
    print(-1)
Buggy code:
a, b = map(int, input().split())
for i in range(1002):
    if i*0.08==a and i*0.1==b:
        print(i)
        exit()
print('-1')

Fixed code:
a, b = map(int, input().split())
for i in range(1002):
    if (i*0.08)//1==a and (i*0.1)//1==b:
        print(i)
        exit()
print('-1')
Buggy code:
a,b = map(int, input().split())
ok = True
for i in range(b*10+1):
  if int(i*0.08)==a and int(i*0.1)==b:
    print(i)
    ok = False
    break
if ok: print(-1)

Fixed code:
a,b = map(int, input().split())
ok = True
for i in range(1001):
  if int(i*0.08)==a and int(i*0.1)==b:
    print(i)
    ok = False
    break
if ok: print(-1)
Buggy code:
a,b=map(int,input().split())
x=0
for i in range(1300):
  if int(i*0.08) == a and int(i*0.10) == b:
    print(i)
    x=1
  if x == 0 and i == 1299:
    print("-1")


Fixed code:
a,b=map(int,input().split())
x=0
for i in range(2000):
  if x == 0 and int(i*0.08) == a and int(i*0.10) == b:
    print(i)
    x=1
  if x == 0 and i == 1299:
    print("-1")
Buggy code:
import math
a, b = map(int,input().split())
e = 10**-7
mi = max(math.ceil(a*12.5),b*10)
ma = min(int((a-1)+*12.5),b*10-1)
if mi > ma:
    print(-1)
else:
    print(mi)


Fixed code:
import math
a, b = map(int,input().split())
e = 10**-7
mi = max(math.ceil(a*12.5),b*10)
ma = min(int(math.ceil((a+1)*12.5)-1),(b+1)*10-1)
if mi > ma:
    print(-1)
else:
    print(mi)
Buggy code:
import math

A,B = map(int,input().split())


ARangemin = math.ceil(A * (100/8))
BRangemin = math.ceil(B * (100/10))

ARangemax = ARangemin
BRangemax = BRangemin
while int(ARangemax * 0.08) == A:
    ARangemax = ARangemax + 1
while int(BRangemax* 0.08) == B:
    BRangemax = BRangemax + 1
ARangemax = ARangemax -1
BRangemax = BRangemax -1

if ARangemax > BRangemin or ARangemin > BRangemax:
    if ARangemin < BRangemin:
        print(ARangemin)
    else:
        print(BRangemin)
else:
    print(-1)



Fixed code:
import math

A,B = map(int,input().split())


ARangemin = math.ceil(A * (100/8))
BRangemin = math.ceil(B * (100/10))

ARangemax = ARangemin
BRangemax = BRangemin
while int(ARangemax * 0.08) == A:
    ARangemax = ARangemax + 1
while int(BRangemax* 0.10) == B:
    BRangemax = BRangemax + 1
ARangemax = ARangemax -1
BRangemax = BRangemax -1

if ARangemax >= BRangemin or ARangemin >= BRangemax:
    if ARangemin >= BRangemax:
        print(-1)
    else:
        if ARangemin > BRangemin:
            print(ARangemin)
        else:
            print(BRangemin)
else:
    print(-1)
Buggy code:
A, B = map(int, input().split())
p = -1
for i in range(101):
  if (108 * i) // 100 == A and (11 * i) // 10 == B:
    p = i
    break
print(p)

Fixed code:
A, B = map(int, input().split())
p = -1
for i in range(100001):
  if (108 * i) // 100 - i == A and (11 * i) // 10 - i == B:
    p = i
    break
print(p)
Buggy code:
from collections import deque

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

q = deque()
rev = 0

for s in S:
  q.append(s)

for _ in range(Q):
  TFC = input()
  if len(TFC) == 1: # T == 1
    rev ^= 1
  else:
    T, F, C = (i for i in TFC.split())  
    if F == '1' and rev:
      q.append(C)
    else:
      q.appendleft(C)
      
ans = ''.join(q)

if reverse:
  print(ans[::-1])
else:
  print(ans)

Fixed code:
from collections import deque

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

q = deque()
rev = 0

for s in S:
  q.append(s)

for _ in range(Q):
  TFC = input()
  if len(TFC) == 1: # T == 1
    rev ^= 1
  else:
    T, F, C = (i for i in TFC.split())  
    if (F == '2' and not rev) or (F == '1' and rev):
      q.append(C)
    else:
      q.appendleft(C)
      
ans = ''.join(q)

if rev:
  print(ans[::-1])
else:
  print(ans)
Buggy code:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

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

Fixed code:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)
Buggy code:
s = input()
q = int(input())

from collections import deque

ss = deque(s)
flg = True

for i in range(q):
  t = input().split()
  if t[0] == '1':
    flg = !flg
  else:
    if t[1] == '2':
        ss.append(t[2]) if flg else ss.appendleft(t[2])
    else:
        ss.append(t[2]) if flg != True else ss.appendleft(t[2])



print("".join(ss)) if flg else print("".join(ss[::-1]))



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

from collections import deque

ss = deque(s)
flg = True

for i in range(q):
  t = input().split()
  if t[0] == '1':
    flg = not flg
  else:
    if t[1] == '2':
        ss.append(t[2]) if flg else ss.appendleft(t[2])
    else:
        ss.append(t[2]) if not flg else ss.appendleft(t[2])

ss = list(ss)

print("".join(ss)) if flg else print("".join(ss[::-1]))
Buggy code:

s = input()
q = int(input())
ht = 1
count = 0
for i in range(2, q):
    txt3 = input().split()
    if txt3[0] == '1':
        ht = 3 - ht
        count += 1
    else:
        if int(txt3[1]) == ht:
            s = txt3[2] + s
        else:
            s = s + txt3[2]
if count % 2 == 1:
    s = s[::-1]
print(s)


Fixed code:

s = input()
q = int(input())
ht = 1
head = ''
tail = ''
count = 0
for i in range(q):
    txt3 = input().split()
    if txt3[0] == '1':
        ht = 3 - ht
        count += 1
    else:
        if int(txt3[1]) == ht:
            head = txt3[2] + head
        else:
            tail = tail + txt3[2]
s = head + s + tail
if count % 2 == 1:
    s = s[::-1]
print(s)
Buggy code:
resolve()
def resolve():
    S = str(input())
    Q = int(input())

    rev_flag = 1
    head_str = ""
    tail_str = ""
    for _ in range(Q):
        query = input() # contains spaces
        if query[0] == "1":
            rev_flag *= -1
        else:
            h_or_t_flag = 1 if query[2] == "1" else -1
            h_or_t_flag *= rev_flag

            if h_or_t_flag == 1:
                head_str += query[4]
            else:
                tail_str += query[4]

    ans = head_str[::-1] + S + tail_str
    print(ans if rev_flag == 1 else ans[::-1])


Fixed code:
def resolve():
    S = str(input())
    Q = int(input())

    rev_flag = 1
    head_str = ""
    tail_str = ""
    for _ in range(Q):
        query = input() # contains spaces
        if query[0] == "1":
            rev_flag *= -1
        else:
            h_or_t_flag = 1 if query[2] == "1" else -1
            h_or_t_flag *= rev_flag

            if h_or_t_flag == 1:
                head_str += query[4]
            else:
                tail_str += query[4]

    ans = head_str[::-1] + S + tail_str
    print(ans if rev_flag == 1 else ans[::-1])
resolve()
Buggy code:
# -*- coding: utf-8 -*-
S = str(input())
Q = int(input())

rev_flag = 1
head_str = ""
tail_str = ""
for _ in range(Q):
    query = str(input())
    if query[0] == "1":
        rev_flag *= -1
    else:
        h_or_t_flag = 1 if query[1] == "1" else -1
        h_or_t_flag *= rev_flag
        
        if h_or_t_flag == 1:
            head_str += query[2]
        else:
            tail_str += query[2]

ans = head_str[::-1] + S + tail_str
print(ans if rev_flag == 1 else ans[::-1])

Fixed code:
# -*- coding: utf-8 -*-
S = str(input())
Q = int(input())

rev_flag = 1
head_str = ""
tail_str = ""
for _ in range(Q):
    query = str(input()) # contains spaces
    if query[0] == "1":
        rev_flag *= -1
    else:
        h_or_t_flag = 1 if query[2] == "1" else -1
        h_or_t_flag *= rev_flag
        
        if h_or_t_flag == 1:
            head_str += query[4]
        else:
            tail_str += query[4]

ans = head_str[::-1] + S + tail_str
print(ans if rev_flag == 1 else ans[::-1])
Buggy code:
from collections import deque

S = list(input())
Q = int(input())

d = deque(S)
head = "l"

for _ in range(Q):
    q = input()
    if len(q) == 1:
        if head == "l":
            head = "r"
        else:
            head = "l"
    else:
        T, F, C = q.split()
        if F == 1:
            if head == "l":
                d.appendleft(C)
            else:
                d.append(C)
        else:
            if head == "l":
                d.append(C)
            else:
                d.appendleft(C)

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

Fixed code:
from collections import deque

S = list(input())
Q = int(input())

d = deque(S)
head = "l"

for _ in range(Q):
    q = input()
    if len(q) == 1:
        if head == "l":
            head = "r"
        else:
            head = "l"
    else:
        T, F, C = q.split()
        if int(F) == 1:
            if head == "l":
                d.appendleft(C)
            else:
                d.append(C)
        else:
            if head == "l":
                d.append(C)
            else:
                d.appendleft(C)
if head == "l":
    print("".join(list(d)))
else:
    print("".join(list(d)[::-1]))
Buggy code:
from collections import deque

z=list(input())
Q=deque()
Q.append(z)
q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

Fixed code:
from collections import deque


Q=deque(list(input()))

q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))
Buggy code:
s=input()
q=int(input())
s=[]
r=[]
for i in S:
    s.append(i)
t=1
for i in range(q):
    qv=list(input().split())
    if qv[0]=='1':
        t^=1
    else:
        if int(qv[1])^t==0 or int(qv[1])^t==2:
            r.append(qv[2])
        else:
            s.append(qv[2])
            
if t==0:
    ss=s.copy()
    s=[]
    for j in range(len(ss)):
        s.append(ss[-1-j])
    ans=s
    ans.extend(r)
else:
    rr=r.copy()
    r=[]
    for j in range(len(rr)):
        r.append(rr[-1-j])
    ans=r
    ans.extend(s)
answer=''.join(ans)
print(answer)

Fixed code:
S=input()
q=int(input())
s=[]
r=[]
for i in S:
    s.append(i)
t=1
for i in range(q):
    qv=list(input().split())
    if qv[0]=='1':
        t^=1
    else:
        if int(qv[1])^t==0 or int(qv[1])^t==2:
            r.append(qv[2])
        else:
            s.append(qv[2])
            
if t==0:
    ss=s.copy()
    s=[]
    for j in range(len(ss)):
        s.append(ss[-1-j])
    ans=s
    ans.extend(r)
else:
    rr=r.copy()
    r=[]
    for j in range(len(rr)):
        r.append(rr[-1-j])
    ans=r
    ans.extend(s)
answer=''.join(ans)
print(answer)
Buggy code:
s=input()
q=int(input())

rev=1

sf=[]
sb=[]

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf.append(n[2])
    else:
      sb.append(n[2])

s=''.join(sf)+s+''.join(sb)

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


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

rev=1

sf=""
sb=s

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf+=n[2]
    else:
      sb+=n[2]

s=sf[::-1]+sb

if rev==1:
  print(s)
else:
  print(s[::-1])
Buggy code:
def main():
  from collections import deque
  s=deque(input())
  q=int(input())
  count=0
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      count+=1
    else:
      if count%2==0:
        if a[1]=='1':
           s.appendleft(a[2])
        else:
          s.append(a[2])
      else:
        if a[1]=='1':
          s.append(a[2])
        else:
          l=(a[2],s)
          s.appendleft(a[2])
  if count%2==1:
    s=s[::-1]
  print(''.join(s))
if __name__=='__main__':
  main()

Fixed code:
def main():
  from collections import deque
  s=deque(input())
  q=int(input())
  count=0
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      count+=1
    else:
      if count%2==0:
        if a[1]=='1':
           s.appendleft(a[2])
        else:
          s.append(a[2])
      else:
        if a[1]=='1':
          s.append(a[2])
        else:
          l=(a[2],s)
          s.appendleft(a[2])
  if count%2==1:
    s=list(s)[::-1]
  print(''.join(s))
if __name__=='__main__':
  main()
Buggy code:
S = input()
numQ = int(input())
lead = 1

for i in range(numQ):
  Q = input()
  if Q[0] == "1":
    lead *= -1
  else:
    if Q[2] == 1:
      if lead == 1:
        S = Q[4] + S
      else:
        S = S + Q[4]
    else:
      if lead == 1:
        S = S + Q[4]
      else:
        S = Q[4] + S
if lead == -1:
  S = S[::-1]

print(S)
      
      

Fixed code:
S = input()
numQ = int(input())
lead = 1
front = ""
rear = ""
for i in range(numQ):
  Q = input()
  if Q[0] == "1":
    lead *= -1
  else:
    if Q[2] == "1":
      if lead == 1:
        front = Q[4] + front
      else:
        rear = rear + Q[4]
    else:
      if lead == 1:
        rear = rear + Q[4]
      else:
        front = Q[4] + front
S = front + S + rear
if lead == -1:
  S = S[::-1]

print(S)
Buggy code:
import sys
from collections import deque
def main():
  S = input()
  Q = int(input())
  r = False
  ans = deque(S)
  for l in sys.stdin:
    TFC = l.split()
    if TFC[0]=="1": r = not r
    elif TFC[1]=="1":
      if r: ans.append(TFC[2])
      else: ans.appendleft(TFC[2])
    elif TFC[1]=="2":
      if r: ans.appendleft(TFC[2])
      else: ans.append(TFC[2])
  print("".join(S[::-1] if r else S))

if __name__ == "__main__":
  main()

Fixed code:
import sys
from collections import deque
def main():
  S = input()
  Q = int(input())
  r = False
  ans = deque(S)
  for l in sys.stdin:
    TFC = l.split()
    if TFC[0]=="1": r = not r
    elif TFC[1]=="1":
      if r: ans.append(TFC[2])
      else: ans.appendleft(TFC[2])
    elif TFC[1]=="2":
      if r: ans.appendleft(TFC[2])
      else: ans.append(TFC[2])
  print("".join(reversed(ans) if r else ans))

if __name__ == "__main__":
  main()
Buggy code:
s = input()
q = int(input())
appendix = [[], []]
reverse = False
for _ in range(q):
  query = input().split()
  if query[0] == '1':
    reverse ^= True
  else:
    f = bool(int(query[1]) - 1)
    appendix[int(f ^ reverse)].append(query[2])
print(''.join(appendix[int(reverse)][::-1]) + s + ''.join(appendix[int(not reverse)])

Fixed code:
s = input()
q = int(input())
appendix = [[], []]
reverse = False
for _ in range(q):
  query = input().split()
  if query[0] == '1':
    reverse ^= True
  else:
    f = bool(int(query[1]) - 1)
    appendix[int(f ^ reverse)].append(query[2])
if reverse:
  print(''.join(appendix[1][::-1]) + s[::-1] + ''.join(appendix[0]))
else:
  print(''.join(appendix[0][::-1]) + s + ''.join(appendix[1]))
Buggy code:
s=input()
n=int(input())
isreverse=False
top=''

for i in range(n):
    ss=input().split()
    if len(ss)==1:
        isreverse=not isreverse
    else:
        if ss[1]=="1":
            if isreverse: s+=ss[2]
            else: top+ss[2]
        else:
            if isreverse: top+=ss[2]
            else: s+=ss[2]
if isreverse:
    s=s[::-1]+top
else:
    s=top[::-1]+s


print(s)

Fixed code:
s=input()
n=int(input())
isreverse=False
top=''

for i in range(n):
    ss=input().split()
    if len(ss)==1:
        isreverse=not isreverse
    else:
        if ss[1]=="1":
            if isreverse: s+=ss[2]
            else: top+=ss[2]
        else:
            if isreverse: top+=ss[2]
            else: s+=ss[2]
if isreverse:
    s=s[::-1]+top
else:
    s=top[::-1]+s


print(s)