qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    def df(c, d):
        res = c // d
        if res * d > c: res -= 1
        return res

    q = int(input())
    L = [list(map(int, input().split())) for _ in range(q)]
    for a, b in L:
        if (a, b) == (1, 1):
            print(0)
            continue
        c = a * b - 1
        rc = int(c ** 0.5)
        rc -= 1
        while (rc + 1) ** 2 < c:
            rc += 1
        ans = rc * 2
        if rc * (rc + 1) > c:
            ans -= 1
        ab = set([a, b])
        for k in ab:
            ans -= 1
            if k > rc:
                y = df(c, k)
                if y == 0:
                    ans += 1
                else:
                    x = df(c, y)
                    if x != k or (df(c, k) == df(c, k - 1)):
                        ans += 1
        print(ans)

main()


Fixed code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    def df(c, d):
        res = c // d
        if res * d > c: res -= 1
        return res

    q = int(input())
    L = [list(map(int, input().split())) for _ in range(q)]
    for a, b in L:
        if (a, b) == (1, 1):
            print(0)
            continue
        c = a * b - 1
        rc = int(c ** 0.5)
        rc -= 1
        while (rc + 1) ** 2 <= c:
            rc += 1
        ans = rc * 2
        if rc * (rc + 1) > c:
            ans -= 1
        ab = [a, b]
        for k in ab:
            ans -= 1
            if k > rc:
                y = df(c, k)
                if y == 0:
                    ans += 1
                else:
                    x = df(c, y)
                    if x != k or (df(c, k) == df(c, k - 1)):
                        ans += 1
        print(ans)

main()
Buggy code:
import math

Q = int(input())
for _ in range(Q):
    A, B = map(int, input().split())
    if A > B:
        A, B = B, A
    C1 = math.floor((A*B-1) ** (1/2))
    if C1 == 0:
        print(0)
        continue
    C2 = (A*B-1) // C1
    print((A-1) + (C2 + C1 - A-1))


Fixed code:
import math

Q = int(input())
for _ in range(Q):
    A, B = map(int, input().split())
    if A > B:
        A, B = B, A
    C1 = math.floor(math.sqrt(A) * math.sqrt(B))
    if C1 ** 2 >= A*B:
        C1 -= 1
    if C1 == 0:
        print(0)
        continue
    C2 = (A*B-1) // C1
    ans = C1 * 2
    if C1 == C2:
        ans -= 1
    if C1 >= A:
        ans -= 1
    print(ans)
Buggy code:
t= int(input())
for i in range(t):
    k=input().split()
    a=int(k[0])
    b=int(k[1])
	c=a*b
    d=int(c**.5)
    print(2*d-1-((d*d)==c)-(c==d*d and a!=b))

Fixed code:
t= int(input())
for i in range(t):
    k=input().split()
    a=int(k[0])
    b=int(k[1])
    c=a*b
    d=int(c**.5)
    print(2*d-1-((d*(d+1))>=c)-(c==d*d and a!=b))
Buggy code:
Q = int(input())
L = []
for i in range(Q):
    L.append([int(x) for x in input().split()])
    
for i in range(Q):
    a = min(L[i])
    b = max(L[i])
    if a == b:
        ans = 2*a-2
    elif a+1 == b:
        ans = 2*a-1
    else:
        c = int((a*b)**0.5)
        if c**2 == a*b:
            c -= 1
        if c*(c+1) >= a*b:
            ans = 2*c-2
        else:
            ans = 2*c-1
    print(ans)

Fixed code:
Q = int(input())
L = []
for i in range(Q):
    L.append([int(x) for x in input().split()])
    
for i in range(Q):
    a = min(L[i])
    b = max(L[i])
    if a == b:
        ans = 2*a-2
    elif a+1 == b:
        ans = 2*a-2
    else:
        c = int((a*b)**0.5)
        if c**2 == a*b:
            c -= 1
        if c*(c+1) >= a*b:
            ans = 2*c-2
        else:
            ans = 2*c-1
    print(ans)
Buggy code:
a,*t=map(int,open(0).read().split())
for a,b in zip(*[iter(t)]*2):
  c=a*b
  d=int(c**.5)
  print(2*d-1-(d*(d)>=c)-(c==d*d and a!=b))

Fixed code:
a,*t=map(int,open(0).read().split())
for a,b in zip(*[iter(t)]*2):
  c=a*b
  d=int(c**.5)
  print(2*d-1-(d*(d+1)>=c)-(c==d*d and a!=b))
Buggy code:
import math

Q = int(input())

AB = []
for _ in range(Q) :
    a, b = map(int, input().split())
    AB.append((a, b))

for a, b in AB :
    if a == b :
        print(2 * a - 2)
    elif (a + 1) == b :
        print(2 * a - 2)
    else :
        C = int(math.sqrt(a * b))
        if C * (C + 1) >= a * b :
            print(2 * C - 2)
        else :
            print(2 * C - 1)


Fixed code:
import math

Q = int(input())

AB = []
for _ in range(Q) :
    a, b = map(int, input().split())
    if a > b :
        a, b = b, a
    AB.append((a, b))

for a, b in AB :
    if a == b :
        print(2 * a - 2)
        continue

    C = int(math.sqrt(a * b))
    if C * C == a * b :
        C -= 1

    if C * (C + 1) >= a * b :
        print(2 * C - 2)
    else :
        print(2 * C - 1)
Buggy code:
import math

q = int(input())
a = [0] * q
b = [0] * q

for i in range(0, q):
    a[i], b[i] = [int(i) for i in input().split(" ")]
    
def sqrt_int(n):
    s = math.floor(n**(1/2)) - 1
    while s * s < n:
        s += 1
    return s - 1

def div_int(p, q):
    r = math.floor(p / q) - 1
    while q * r < p:
        r += 1
    return r - 1

for i in range(0, q):
    mi = min(a[i], b[i])
    mx = max(a[i], b[i])
    p = mi * mx - 1
    s = sqrt_int(p)
    c = 2 * (s - 1)
    if s == 0:
        print(0)
        continue
    if mi <= s - 1:
        c -= 1
    r = div_int(p, s)
    if r > s:
        if s == mi:
            c += 1
        else:
            c += 2
    elif r == s and s != mi:
        c += 1
    print(c)

Fixed code:
import math

q = int(input())
a = [0] * q
b = [0] * q

for i in range(0, q):
    a[i], b[i] = [int(i) for i in input().split(" ")]
    
def sqrt_int(n):
    s = math.floor(n**(1/2)) - 1
    while s * s <= n:
        s += 1
    return s - 1

for i in range(0, q):
    mi = min(a[i], b[i])
    mx = max(a[i], b[i])
    p = mi * mx - 1
    s = math.floor(p**(1/2))
    c = 2 * (s - 1)
    if s == 0:
        print(0)
        continue
    if mi <= s - 1:
        c -= 1
    r = p // s
    if r > s:
        if s == mi:
            c += 1
        else:
            c += 2
    elif r == s and s != mi:
        c += 1
    print(c)
Buggy code:
import math

n = int(input())
for _ in range(n):
  a,b = input().split(" ")
  a,b = sorted([int(a), int(b)])
  c = math.ceil((a*b)**0.5)-1
  print(2*c-(a!=b)-(c*(c+1)>=b*b))

Fixed code:
import math

n = int(input())
for _ in range(n):
  a,b = input().split(" ")
  a,b = sorted([int(a), int(b)])
  c = math.ceil((a*b)**0.5)-1
  print(2*c-(a!=b)-(c*(c+1)>=a*b))
Buggy code:
Q = int(input())
Ri = [list(map(int, input().split())) for _ in range(Q)]

for r in Ri:
    a = r[0]
    b = r[1]
    if a > b:
        t = b
        b = a
        a = t
    max_score = a * b

    if a == b:
        print(2 * a - 1)
    elif a + 1 == b:
        print(2 * a - 2)
    else:
        r = max_score ** 0.5
        rn = int(r)
        print(2 * rn - 2)

Fixed code:
Q = int(input())
Ri = [list(map(int, input().split())) for _ in range(Q)]

for r in Ri:
    a = r[0]
    b = r[1]
    if a > b:
        t = b
        b = a
        a = t
    max_score = a * b

    if a == b:
        print(2 * a - 2)
    elif a + 1 == b:
        print(2 * a - 2)
    else:
        r = max_score ** 0.5
        rn = int(r)
        if rn == r:
            rn -= 1
        if rn * (rn + 1) >= max_score:
            print(2 * rn - 2)
        else:
            print(2 * rn - 1)
Buggy code:
#import random

q=int(input())
A=[]
for i in range(q):
    A.append(list(map(int,input().split())))
    A[i].sort()

#A=[]
#q=10000
#for i in range(q):
#    A.append([random.randint(1,1000000)]*2)
#    A.sort()
#print(A)

for i in range(q):
    a=A[i][0]
    b=A[i][1]
    if a==b :
        ans1=2*(a-1)
    elif a+1==b :
        ans1=2*a-2
    else :
        c=int((a*b-1)**0.5)+2
        while c*c>=a*b :
            c-=1
        #print("c "+str(c))
        if c*(c+1)>=a*b :
            ans1=2*c-2
        else :
            ans1=2*c-1

print(ans1)


Fixed code:
#import random

q=int(input())
A=[]
for i in range(q):
    A.append(list(map(int,input().split())))
    A[i].sort()

#A=[]
#q=10000
#for i in range(q):
#    A.append([random.randint(1,1000000)]*2)
#    A.sort()
#print(A)

for i in range(q):
    a=A[i][0]
    b=A[i][1]
    if a==b :
        ans1=2*(a-1)
    elif a+1==b :
        ans1=2*a-2
    else :
        c=int((a*b-1)**0.5)+2
        while c*c>=a*b :
            c-=1
        #print("c "+str(c))
        if c*(c+1)>=a*b :
            ans1=2*c-2
        else :
            ans1=2*c-1

    print(ans1)
Buggy code:
import math
def near_sqrt(a,b):
  c = a * b
  d = math.floor(math.sqrt(c))
  if d*(d+1) <= c:
    return d
  else:
    return (d-1)
  
q = int(input())
for i in range(q):
  a,b = map(int, input().split())
  c = near_sqrt(a,b)
  if (a*b)%(c+1) == 0:
    print(math.floor((a*b)/(c+1))+c-2)
  else:
    print(math.floor((a*b)/(c+1))+c-1)

Fixed code:
import math
def near_sqrt(a,b):
  c = a * b
  d = math.floor(math.sqrt(c))
  if d*(d+1) < c:
    return d
  else:
    return (d-1)
  
q = int(input())
for i in range(q):
  a,b = map(int, input().split())
  c = near_sqrt(a,b)
  d = (a*b)%(c+1)
  if d == 0 and a!=b:
    print(math.floor((a*b)/(c+1))+c-2)
  else:
    print(math.floor((a*b)/(c+1))+c-1)
Buggy code:
import math
Q = int(input())
for i in range(Q):
  a, b = map(int, input().split())
  sqrt = int(math.sqrt(a * b))
  sub = 0 if math.sqrt(a * b) - sqrt > 0 else 1
  sqrt2 = sqrt + 1 if sqrt * (sqrt + 1) < a * b else sqrt
  add = min(max(sqrt2 - min(a, b) - 1, 0), max(max(a, b) - sqrt - 1, 0))
  print(min(a, b) - 1 + sqrt + add - sub)

Fixed code:
import math
Q = int(input())
for i in range(Q):
  a, b = map(int, input().split())
  sqrt = int(math.sqrt(a * b))
  sqrt2 = sqrt + 1 if sqrt * (sqrt + 1) < a * b else sqrt
  sub = 1 if sqrt == max(a, b) or sqrt2 == min(a, b) or sqrt * sqrt2 == a * b else 0
  add = min(max(sqrt2 - min(a, b) - 1, 0), max(max(a, b) - sqrt - 1, 0))
  print(min(a, b) - 1 + sqrt + add - sub)
Buggy code:
Q = int(input())
AB = [sorted(list(map(int,input().split()))) for i in range(Q)]

for A,B in AB:
    x = math.sqrt(A*B)
    y = int(x)
    if x!=y:
        if y*(y+1)<A*B:
            print(y*2-1)
        else:
            print(y*2-2)
    else:
        if A==B:
            print(y*2-2)
        else:
            print(y*2-3)

Fixed code:
import math

Q=int(input())
AB=[sorted(list(map(int,input().split()))) for i in range(Q)]

for A,B in AB:
    x=math.sqrt(A*B)
    y=int(x)
    if x!=y:
        y=int(x)
        if y*(y+1)<A*B:
            print(y*2-1)
        else:
            print(y*2-2)
    else:
        if A==B:
            print(y*2-2)
        else:
            print(y*2-3)
Buggy code:
from math import sqrt, floor
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if b-a < 2:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = floor(sqrt(a*b) - 1)
        else:
            c  = floor(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)

Fixed code:
from math import sqrt
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if a == b or a == b-1:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = int(sqrt(a*b) - 1)
        else:
            c  = int(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)
Buggy code:
def f(a,b):
  if a>b:a,b=b,a
  if a==b or a+1==b:
    return 2*a-2
  else:
    c=int((a*b)**(1/2))
    if c*(c+1)>=a*b:
      return 2*c-2
    else:
      return 2*c-1

q=int(input())
for _ in range(q):
  a,b=map(int,input().split())
  print(f(a,b))

Fixed code:
def f(a,b):
  if a>b:a,b=b,a
  if a==b or a+1==b:
    return 2*a-2
  else:
    c=int((a*b)**(1/2))
    if c**2==a*b:c-=1
    if c*(c+1)>=a*b:
      return 2*c-2
    else:
      return 2*c-1

q=int(input())
for _ in range(q):
  a,b=map(int,input().split())
  print(f(a,b))
Buggy code:
Q=int(input())
score=[map(int,input().split()) for _ in range(Q)]
import math
for i in range(Q):
    max_num=int(math.sqrt(score[i][0]*score[i][1]))
    if score[i][0]*score[i][1]==max_num:
        print(2*max_num-3)
    elif score[i][0]*score[i][1]>max_num*(max_num+1):
        print(2*max_num-1)
    elif score[i][0]==score[i][1]:
        print(2*max_num-2)
    else:
        print(2*max_num-2)


Fixed code:
Q=int(input())
score=[list(map(int,input().split())) for _ in range(Q)]
import math
for i in range(Q):
    max_num=int(math.sqrt(score[i][0]*score[i][1]))

    if score[i][0]==score[i][1]:
        print(2*max_num-2)
    elif score[i][0]*score[i][1]==max_num**2:
        print(2*max_num-3)
    elif score[i][0]*score[i][1]>max_num*(max_num+1):
        print(2*max_num-1)
    else:
        print(2*max_num-2)
Buggy code:
Q = int(input())
ans = []
for q in range(Q):
    A, B = map(int, input().split())
    M = int((A*B)**0.5)
    tmp = 2*M - 2
    tmp -= (A < M) or (B < M)
    if A != B and A*B != M*M:
        if M*(M+1) < A*B:
            tmp += 2
        elif M*M < A*B:
            tmp += 1
    ans.append(str(tmp))

print("\n".join(ans))

Fixed code:
Q = int(input())
ans = []
for q in range(Q):
    A, B = map(int, input().split())
    M = int((A*B)**0.5)
    if M*(M + 1) < A*B: 
        ans.append(2*M - 1)
    elif A*B == M*M and A != B: 
        ans.append(2*M - 3)
    else: 
        ans.append(2*M - 2)

print("\n".join(map(str, ans)))
Buggy code:
import math

def worst_case(A, B):
    c = min(A, B)
    d = max(A, B)
    if c == d or c + 1 == d:
        return 2 * (c - 1)
    root = int(math.sqrt(A * B))
    return 2 * (root - 1) + 1 if root * (root + 1) < A * B else 2 * (root - 1)

Q = int(input())
A = []
B = []
for i in range(Q):
    line = input().split()
    A.append(int(line[0]))
    B.append(int(line[1]))

for i in range(Q):
    print(worst_case(A[i], B[i]))

Fixed code:
import math

def worst_case(A, B):
    c = min(A, B)
    d = max(A, B)
    if c == d or c + 1 == d:
        return 2 * (c - 1)
    root = int(math.sqrt(A * B))
    if root ** 2 == A * B:
        root -= 1
    return 2 * (root - 1) + 1 if root * (root + 1) < A * B else 2 * (root - 1)

Q = int(input())
A = []
B = []
for i in range(Q):
    line = input().split()
    A.append(int(line[0]))
    B.append(int(line[1]))

for i in range(Q):
    print(worst_case(A[i], B[i]))
Buggy code:
import math
q = int(input())
a = [list(map(int, input().split())) for i in range(q)]

for i in range(q):
    ans = 0
    AB = a[i][0]*a[i][1]
    if a[i][0]<=a[i][1]:
        A, B = a[i][0], a[i][1]
    else:
        A, B = a[i][1], a[i][0]
    x = int(math.sqrt(AB))
    if A==B:
        ans=2*A-2
    elif A+1==B:
        ans= 2*A-2
    elif x*(x+1)>=AB:
        ans = 2*x-2
    else:
        ans = 2*x-1
    print(ans)

Fixed code:
import math
q = int(input())
a = [list(map(int, input().split())) for i in range(q)]

for i in range(q):
    ans = 0
    AB = a[i][0]*a[i][1]
    if a[i][0]<=a[i][1]:
        A, B = a[i][0], a[i][1]
    else:
        A, B = a[i][1], a[i][0]
    x = int(math.sqrt(AB-1))
    while x*x>=AB:
        x-=1
    if A==B:
        ans=2*A-2
    elif A+1==B:
        ans= 2*A-2
    elif x*(x+1)>=AB:
        ans = 2*x-2
    else:
        ans = 2*x-1
    print(ans)
Buggy code:
import math
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    c=int(math.sqrt(a*b))
    if c<2 :
        print('0')
    elif (math.sqrt(a*b)==c and a!=b:
        print(2*c-3)
    elif c*(c+1)<a*b:
        print(2*c-1)
    else:
        print(2*c-2)

Fixed code:
import math
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    c=int(math.sqrt(a*b))
    if c*(c+1)<a*b: print(2*c-1)
    elif a*b==c*c and a!=b:  print(2*c-3)
    else:  print(2*c-2)
Buggy code:
import math

q = int(input())
a = []
b = []
for i in range(q):
  c = [int(i) for i in input().split()]
  a += [c[0]]
  b += [c[1]]

for i in range(q):
  prod = a[i] * b[i]
  sqrt = int(math.sqrt(prod))
  cnt = 2 * sqrt

  if a[i] == b[i]:
    cnt -= 2
  else:
    if sqrt * sqrt == prod:
      cnt -= 2
    elif prod // sqrt == sqrt:
      cnt -= 1
    cnt -= 1
  
  print(cnt)

Fixed code:
import math

q = int(input())
a = []
b = []
for i in range(q):
  c = [int(i) for i in input().split()]
  a += [c[0]]
  b += [c[1]]

for i in range(q):
  prod = a[i] * b[i]
  sqrt = int(math.sqrt(prod))
  cnt = 2 * sqrt

  if a[i] == b[i]:
    cnt -= 2
  else:
    if sqrt * sqrt == prod:
      cnt -= 2
    elif prod // sqrt == sqrt:
      cnt -= 1
    elif prod // sqrt == sqrt + 1 and prod // sqrt * sqrt == prod:
      cnt -= 1
    cnt -= 1
  
  print(cnt)
Buggy code:
import math

N = int(input().strip())
grid = []
for i in range(N):
  array = list(map(int, input().strip().split(' ')))
  grid.append(array)

for i in grid:
  i.sort()
  a,b = [i[0],i[1]]
  if(a == b or a+1 == b):
    print(2*a-2)
  else:
    c = int(math.sqrt(a*b))
    if(c*c < a*b):
      print(2*c-1)
    else:
      print(2*c-2)


Fixed code:
import math

N = int(input().strip())
grid = []
for i in range(N):
	array = list(map(int, input().strip().split(' ')))
	grid.append(array)

for i in grid:
	i.sort()
	a,b = [i[0],i[1]]
	if(a == b or a+1 == b):
		print(2*a-2)
	else:
		c = int(math.sqrt(a*b))
		if c**2 == a*b:
			c-=1
		if(c*(c+1)>=a*b):
			print(2*c-2)
		else:
			print(2*c-1)
Buggy code:
Q = int(input())

while Q:
    Q -= 1
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = (M * m) ** 0.5
    if last % 1 != 0:
        last = int(last)
    else:
        last -= 1
        last = int(last)
    if last * (last * 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)


Fixed code:
Q = int(input())

while Q:
    Q -= 1
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = int((M * m) ** 0.5)
    if last == (M * m) ** 0.5:
        last -= 1
    if last * (last + 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)
Buggy code:
from math import sqrt, floor
q = int(input())
for _ in range(q):
    a, b = map(int, input().split(" "))
    if a == b:
        print(2 * a - 2)
    elif max(a, b) - min(a, b) == 1:
        print(2 * min(a, b) - 2)
    else:
        c = floor(sqrt(a * b - 1))
        if c * (c + 1) >= a + b:
            print(2 * floor(sqrt(a * b)) - 2)
        else:
            print(2 * floor(sqrt(a * b)) - 1)


Fixed code:
from math import sqrt, floor
q = int(input())
for _ in range(q):
    a, b = map(int, input().split(" "))
    if a == b:
        print(2 * a - 2)
    elif max(a, b) - min(a, b) == 1:
        print(2 * min(a, b) - 2)
    else:
        c = floor(sqrt(a * b))
        if c == sqrt(a*b):
            c -= 1
        if c * (c + 1) >= a * b:
            print(2 * c - 2)
        else:
            print(2 * c - 1)
Buggy code:
import math

q = int(input())
a = []
for i in range(q):
    a.append(list(map(int, input().split())))
for i in range(q):
    b = 2 * int(math.sqrt(a[i][0] * a[i][1])) - 1
    while True:
        status = True
        if b % 2 == 0:
            if (b // 2 + (a[i][0] <= b // 2)) * (b // 2 + 2 - (a[i][1] >= b//2 + 2)) < a[i][0] * a[i][1] and (b // 2 + 1 + (a[i][0] <= b // 2 + 1)) * (b // 2 + 1 - (a[i][1] >= b // 2 + 1)) < a[i][0] * a[i][1]:
                b = b + 1
            else:
                break
        else:
            if ((b - 1) // 2 + (a[i][0] <= (b - 1) // 2)) * ((b + 5) // 2 - (a[i][1] >= (b + 5) // 2)) < a[i][0] * a[i][1] and ((b + 1) // 2 + (a[i][0] <= (b + 1) // 2)) * ((b + 3) // 2 - (a[i][1] >= (b + 3) // 2)) < a[i][0] * a[i][1] and ((b + 3) // 2 + (a[i][0] <= (b + 3) // 2)) * ((b + 1) // 2 - (a[i][1] >= (b + 1) // 2)) < a[i][0] * a[i][1]:
                b = b + 1
            else:
                break
    print(b - 1)

Fixed code:
import math

q = int(input())
a = []
for i in range(q):
    a.append(list(map(int, input().split())))
for i in range(q):
    b = max(2 * int(math.sqrt(a[i][0] * a[i][1])) - 3, 0)
    while True:
        status = True
        if b % 2 == 0:
            if (b // 2 + (a[i][0] <= b // 2)) * (b // 2 + 2 - (a[i][1] >= b//2 + 2)) < a[i][0] * a[i][1] and (b // 2 + 1 + (a[i][0] <= b // 2 + 1)) * (b // 2 + 1 - (a[i][1] >= b // 2 + 1)) < a[i][0] * a[i][1]:
                b = b + 1
            else:
                break
        else:
            if ((b - 1) // 2 + (a[i][0] <= (b - 1) // 2)) * ((b + 5) // 2 - (a[i][1] >= (b + 5) // 2)) < a[i][0] * a[i][1] and ((b + 1) // 2 + (a[i][0] <= (b + 1) // 2)) * ((b + 3) // 2 - (a[i][1] >= (b + 3) // 2)) < a[i][0] * a[i][1] and ((b + 3) // 2 + (a[i][0] <= (b + 3) // 2)) * ((b + 1) // 2 - (a[i][1] >= (b + 1) // 2)) < a[i][0] * a[i][1]:
                b = b + 1
            else:
                break
    print(b - 1)
Buggy code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"

import string
s = v()

if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

lis =list(string.ascii_lowercase)
nlis = [0]*26

for i in s:
    t = lis.index(i)
    nlis[t] += 1

if sum(nlis) != 26:
    for i in range(26):
        if nlis[i] == 0:
            print(s+lis[i])
            break
else:
    for i in range(25, -1, -1):
        for j in lis:
            if s[i] < j and j not in s[:i]:
                print(s[:i] + j)
                exit()
print(lis)

Fixed code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"

import string
s = v()

if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

lis =list(string.ascii_lowercase)
nlis = [0]*26

for i in s:
    t = lis.index(i)
    nlis[t] += 1

if sum(nlis) != 26:
    for i in range(26):
        if nlis[i] == 0:
            print(s+lis[i])
            break
else:
    for i in range(25, -1, -1):
        for j in lis:
            if s[i] < j and j not in s[:i]:
                print(s[:i] + j)
                exit()
Buggy code:
s=input()
if len(s)==26:
	d=[]
	for i in range(26):
		if list(s[-i-1:][::-1])!=sorted(s[-i-1:]):
			for j in range(i+1):
				d.append(s[-j-1])
			d.sort()
			if d[0]==s[-i-1]:
				k=d[1]
				print(2/0)
			else:
				k=d[0]
			print(s[:-i-1]+k)
			exit()
	print(-1)
	exit()
d=[0]*26
for i in range(len(s)):
	d[ord(s[i])-ord("a")]+=1
for i in range(26):
	if d[i]==0:
		x=chr(ord("a")+i)
		break
print(s+x)

Fixed code:
s=input()
if len(s)==26:
	d=[]
	for i in range(26):
		if list(s[-i-1:][::-1])!=sorted(s[-i-1:]):
			for j in range(i+1):
				d.append(s[-j-1])
			d.sort()
			if d[0]==s[-i-1]:
				k=d[1]
			else:
				for j in range(len(d)):
					if d[j]>s[-i-1]:
						k=d[j]
						break
			print(s[:-i-1]+k)
			exit()
	print(-1)
	exit()
d=[0]*26
for i in range(len(s)):
	d[ord(s[i])-ord("a")]+=1
for i in range(26):
	if d[i]==0:
		x=chr(ord("a")+i)
		break
print(s+x)