qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n = int(input())

def divisor(n: int) -> list:
    list_of_divisor = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            list_of_divisor.append(i)
            if i != n//i:
                list_of_divisor.append(n//i)
    list_of_divisor.sort()
    return list_of_divisor

li = divisor(n)
num = len(li)
if num % 2 == 0:
    # print(li[num//2-1], li[num//2])
    if li[num//2-1] == 1:
        print(li[num//2]-1)
    else:
        print((li[num//2-1]-1)*(li[num//2]-1))
else:
    print(li[num//2]**2)

Fixed code:
n = int(input())

def divisor(n: int) -> list:
    list_of_divisor = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            list_of_divisor.append(i)
            if i != n//i:
                list_of_divisor.append(n//i)
    list_of_divisor.sort()
    return list_of_divisor

li = divisor(n)
num = len(li)
if num % 2 == 0:
    # print(li[num//2-1], li[num//2])
    if li[num//2-1] == 1:
        print(li[num//2]-1)
    else:
        print((li[num//2-1]-1)+(li[num//2]-1))
else:
    print((li[num//2]-1)*2)
Buggy code:
import numpy as np
n=int(input())
ans = n-1
for i in range(int(np.sqrt(n))+1):
  if n % i == 0:
    ans = min(ans, i + n/i -2)
print(ans)

Fixed code:
import numpy as np
n=int(input())
ans = n-1
for i in range(1,int(np.sqrt(n))+1):
  if n % i == 0:
    ans = min(ans, i + n/i -2)
print(int(ans))
Buggy code:
N=int(input())
can=[]
for i in range(1,N**0.5+1):
  if N%i==0:
    can.append(N-1+N//i-1)
    

print(min(can))

Fixed code:
N=int(input())
can=[]
for i in range(1,int(N**0.5)+1):
  if N%i==0:
    can.append(i-1+N//i-1)
    

print(min(can))
Buggy code:
data=int(input())
sum=10**6

for i in range(10**6):
  a=i+1
  if data%a==0:
    b=data/a
    if a+b<sum:
      sum=a+b
print(sum-2)

Fixed code:
data=int(input())
sum=10**12
 
for i in range(10**6):
  a=i+1
  if data%a==0:
    b=data//a
    if a+b<sum:
      sum=a+b
      
print(sum-2)
Buggy code:
n = int(input())

ans = 10**12
for i in range(1, int(ns**0.5)+1):
    print(n%i)
    if n%i==0:
        ans = min(ans, i+n//i)
print(ans-2)

Fixed code:
n = int(input())
ans = 10 ** 12
for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
        tmp = i + (n // i) - 2
        ans = min(ans, tmp)
print(ans)
Buggy code:
import math

N = int(input())

a = pow(10,12)

is_not_prime = False
for k in range(2, int(math.sqrt(N)) + 1):
    if N % k == 0:
        is_not_prime = True
        break
if is_not_prime:
    for i in range(1, int(math.sqrt(N)) + 1):
        print(i)
        j = N/i
        if j.is_integer():

            if (i+int(j)) < a:
                a = i+int(j)
        if j < 2:
            break

    print(a - 2)
else:
    print(N - 1)

Fixed code:
import math

N = int(input())

a = pow(10,12)

is_not_prime = False
#for k in range(2, int(math.sqrt(N)) + 1):
#    if N % k == 0:
#        is_not_prime = True
#        break
#if is_not_prime:
for i in range(1, int(math.sqrt(N))+1):
    #print(i)
    j = N/i
    if j.is_integer():

        if (i+int(j)) < a:
            a = i+int(j)
    #if j < 2:
    #    break

print(a - 2)
#else:
#    print(N - 1)
Buggy code:
import math

n= int(input())
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

res  = []
if is_prime(n):
    res = n - 1
else:
    for t in range(1, int(math.sqrt(n)) + 1):
        if n % t == 0:
                res.append(n//t + t - 2)


print(min(res))


Fixed code:
import math

n= int(input())
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

res  = []
if is_prime(n):
    res.append(n - 1)
else:
    for t in range(1, int(math.sqrt(n)) + 1):
        if n % t == 0:
                res.append(n//t + t - 2)


print(min(res))
Buggy code:
import sys
import math

N = int(input())
sqrt = math.sqrt(N)

ls = []
for i in range(1, int(sqrt) + 1):
  if N % i == 0:
    ls.append((i, int(N/i)))

print(ls)

print(min(a[0] + a[1] -2 for a in ls))


Fixed code:
import sys
import math

N = int(input())
sqrt = math.sqrt(N)

ls = []
for i in range(1, int(sqrt) + 1):
  if N % i == 0:
    ls.append((i, int(N/i)))


print(min(a[0] + a[1] -2 for a in ls))
Buggy code:
import math
N=int(input())
a=int(math.sqrt(N))
while a>0:
  if N%a==0:
    print(a+N%a-2)
    break
  a-=1


Fixed code:
import math
N=int(input())
a=int(math.sqrt(N))
while a>0:
  if N%a==0:
    print(a+N//a-2)
    break
  a-=1
Buggy code:
import numpy as np
n = int(input())
MIN = n
for x in range(1,int(np.sqrt(n))):
    if n % x == 0:
        MIN = min([MIN,x + n/x - 2])
    print(x)
    x += 1
print(int(MIN))

Fixed code:
import numpy as np
n = int(input())
MIN = n
for x in range(1,int(np.sqrt(n)+1)):
    if n % x == 0:
        MIN = min([MIN,x + n/x - 2])
print(int(MIN))
Buggy code:
dN = int(input())
yaku = 1

import math

    



if N % 2 == 0:
	yaku = 2
	
for i in range(3,int(math.sqrt(N))+1 ,1):
	if N % i == 0:
		yaku = i
		
		
yaku2 = int(N/yaku)

print(int(yaku2+yaku - 2))


Fixed code:
N = int(input())
yaku = 1
import math

if N % 2 == 0:
	yaku = 2
	
for i in range(3,int(math.sqrt(N))+1 ,1):
	if N % i == 0:
		yaku = i
		
		
yaku2 = int(N/yaku)

print(int(yaku2+yaku - 2))
Buggy code:
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    N = int(input())
    min_s = 10 ** 12

    for i in range(1, int(math.sqrt(N))):
        if N % i == 0:
            if min_s > i+(N/i):
                min_s = i + (N/i)

    print(min_s - 2)


if __name__ == '__main__':
    main()

Fixed code:

import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    N = int(input())
    min_s = 10 ** 12

    for i in range(1, int(math.sqrt(N))+1):
        if N % i == 0:
            if min_s > i+(N/i):
                min_s = i + (N/i)

    print(int(min_s - 2))


if __name__ == '__main__':
    main()
Buggy code:
#%%
n = int(input())

x = int(n**0.5)
x += 1
for i in range(x, 1, -1):
    if n%i == 0:
        a = i
        b = n//i
        break
#print(a, b)

print(a+b-2)

Fixed code:
#%%
n = int(input())
a = 10**15


x = int(n**0.5)
x += 1
for i in range(x, 1, -1):
    if n%i == 0:
        a = i
        b = n//i
        break
#print(a, b)

if a == 10**15:
    print(n-1)
else:
    print(a+b-2)
Buggy code:
N = int(input())
a = int(N**0.5)
ans = 10**6
for x in range(0,a+1):
    b = N / x
    if b == int(b):
        if a + b - 2 < ans:
            ans = a+b-2
print(ans)

Fixed code:
N = int(input())
a = int(N**0.5)
ans = 10 ** 12
for x in range(1,a+1):
    b = N / x
    if b == int(b):
        if x + b - 2 < ans:
            ans = x+b-2
print(int(ans))
Buggy code:
n = int(input())
factor = []

for i in range(1,int(n**1/2)+1):
    if n%i == 0:
        factor.append(i + n//i -2)

factor.sort()
print(factor[0])

Fixed code:
n = int(input())
factor = []

for i in range(1,int(n**0.5)+1):
    if n%i == 0:
        factor.append(i + n//i)

factor.sort()
print(factor[0]-2)
Buggy code:
import math

N = int(input())

A = int(math.sqrt(N))

for i in reversed(range(1, A + 1)):
    print(i)
    if N % i == 0:
        print(i + (N // i) - 2)
        exit()

Fixed code:
import math

N = int(input())

A = int(math.sqrt(N))

for i in reversed(range(1, A + 1)):
    if N % i == 0:
        print(i + (N // i) - 2)
        exit()
Buggy code:
import sys
readline = sys.stdin.buffer.readline

import math
N = int(readline())

ans = N

for i in range(1, math.ceil(math.sqrt(N))):
    if N % i == 0:

        if i == 1:
            ans = min(ans, i + N//i - 1)
        else:
            ans = min(ans, i + N//i - 2)


print(ans)

Fixed code:
import sys
readline = sys.stdin.buffer.readline

import math
N = int(readline())

ans = N

for i in range(1, math.ceil(math.sqrt(N)) + 1):
    if N % i == 0:
        ans = min(ans, i + N//i - 2)


print(ans)
Buggy code:
# -*- coding: utf-8 -*-
"""
Created on Wed Nov  6 21:49:38 2019

@author: over-
"""

N=int(input())

ans=N
for i in range(1,10**6):
    if i > N: break
    if N%i == 0:
        A=(N/i-1)+(i-1)
        if A < ans:
            ans = A
            
print(int(A))

Fixed code:
# -*- coding: utf-8 -*-
"""
Created on Wed Nov  6 21:49:38 2019

@author: over-
"""

N=int(input())

ans=N
for i in range(1,10**12):
    if i**2 > N: break
    if N%i == 0:
        A=(N/i-1)+(i-1)
        if A < ans:
            ans = A
            
print(int(A))
Buggy code:
import math
n=int(input())
m=math.sqrt(n)
m=math.floor(m)+1
li=[]
for i in range(1,m):
    a=i+n/i
    li.append(a)
li=[li[i] for i in range(m-1) if li[i].is_integer()]
print(int(min(li))-2)
print(li)


Fixed code:
import math
n=int(input())
m=math.sqrt(n)
m=math.floor(m)+1
li=[]
for i in range(1,m):
    a=i+n/i
    li.append(a)
li=[li[i] for i in range(m-1) if li[i].is_integer()]
print(int(min(li))-2)
Buggy code:
def main():
    ans = 10**9
    n = int(input())
    for i in range(1,int(n**0.5)+1):
        if n % i == 0:
            ans = min(ans,i+n//i-2)
    else:
        print(ans)


if __name__ == "__main__":
    main()

Fixed code:
def main():
    ans = 10**12
    n = int(input())
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ans=min(ans, i+n//i)
    else:
        print(ans-2)


if __name__ == "__main__":
    main()
Buggy code:

class Solution:
    def solve(self, n: int) -> int:

        maxDivisor = int(math.sqrt(n) + 0.5)

        for i in range(1, maxDivisor + 1):
            if n % i == 0:
                p = i

        q = n // p

        return p+q-2


if __name__ == '__main__':

    # standard input
    n = int(input())

    # solve
    solution = Solution()
    print(solution.solve(n))


Fixed code:
import math


class Solution:
    def solve(self, n: int) -> int:

        maxDivisor = int(math.sqrt(n) + 0.5)

        for i in range(1, maxDivisor + 1):
            if n % i == 0:
                p = i

        q = n // p

        return p+q-2


if __name__ == '__main__':

    # standard input
    n = int(input())

    # solve
    solution = Solution()
    print(solution.solve(n))
Buggy code:
N = int(input())

i = 1
j = 1 
l = []
while i <= (N/i):

  if N%i == 0:
    j = int(N/i)
    l.append([i,j])
  
  i+=i

res = l.pop()

print(res[0]+ res[1] -2)


Fixed code:
N = int(input())

i = 1
j = 1 
l = []
while i <= (N/i):
  if N%i == 0:
    j = int(N/i)
    l.append([i,j])
  
  i+=1

res = l.pop()
print(res[0]+ res[1] -2)
Buggy code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math

n = ni()
nn = n
mn = 10**12
nums = [1]

i=2
while i<=math.ceil(math.sqrt(n)+1):
  while n%i==0:
    nums.append(i)
  i+=1

for num in nums:
  other = nn//num
  mn = min(mn, num+other-2)

print(mn)

Fixed code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math

n = ni()
nn = n
mn = 10**12
nums = [1]

i=2
while i<=math.ceil(math.sqrt(n)+1):
  if n%i==0:
    nums.append(i)
  i+=1

for num in nums:
  other = nn//num
  mn = min(mn, num+other-2)

print(mn)
Buggy code:
n=int(input());print(min(x+n/x-2for x in range(1,int(n**.5)+1)if n%x<0))

Fixed code:
n=int(input());print(min(x+n//x-2for x in range(1,int(n**.5)+1)if n%x<1))
Buggy code:
import math
n = int(input())
c = n - 1
for i in (1, int(math.sqrt(n)) + 1):
    if n % i == 0:
        c = min(c, i + n // i - 2)
print(c)

Fixed code:
import math
n = int(input())
c = n - 1
for i in range(2, int(math.sqrt(n)) + 1):
    if n % i == 0:
        c = min(c, i + n // i - 2)
print(c)
Buggy code:
import math
n=int(input())
div=[]
for i in range(1,math.ceil(n**0.5)):
    if n%i==0:
        div.append(i)
        if i!=n//i:
            div.append(n//i)
div.sort()
print(div)
if len(div)%2==0:
    print(div[len(div)//2]+div[len(div)//2-1]-2)

Fixed code:
import math
n=int(input())
div=[]
for i in range(1,math.ceil(n**0.5)+1):
    if n%i==0:
        div.append(i)
        if i!=n//i:
            div.append(n//i)
div.sort()
if len(div)%2==0:
    print(div[len(div)//2]+div[len(div)//2-1]-2)
else:
    print(div[len(div)//2]*2-2)
Buggy code:
n = int(input())
ln = []
for k in range(1,n+1):
    if n % k == 0:
        ln.append(k)
if not n**0.5 % 1 == 0:
    i = ln[len(ln) // 2 - 1]
    j = ln[len(ln) // 2]
    ans = i + j -2
else:
    ans = int(2*n**0.5)-2
print(ans)

Fixed code:
n = int(input())
ln = []
for k in range(1,(int(n**0.5))+1):
    if n % k == 0:
        ln.append(k)
if not n**0.5 % 1 == 0:
    for k in reversed(range(0, len(ln))):
        ln.append(n // ln[k])
else:
    for k in reversed(range(0, len(ln)-1)):
        ln.append(n // ln[k])
if not n**0.5 % 1 == 0:
    i = ln[len(ln) // 2 - 1]
    j = ln[len(ln) // 2]
    ans = i + j -2
else:
    ans = int(2*n**0.5)-2
print(ans)
Buggy code:
from math import sqrt

N = int(input())

ans = N ** 2
for i in range(2, int(sqrt(N)) + 1):
    if N % i == 0:
        ans = min(ans, i + (N // i) - 2)
print(ans)


Fixed code:
from math import sqrt

N = int(input())

ans = N ** 2
for i in range(2, int(sqrt(N)) + 1):
    if N % i == 0:
        ans = min(ans, i + (N // i) - 2)
if ans == N ** 2:
    ans = N - 1

print(ans)
Buggy code:
import math

N = int(input())

for i in reverse(range(int(math.sqrt(N))+1)):
  if N % i == 0:
    print(i-1+(N//i)-1)
    break

Fixed code:
import math
 
N = int(input())
 
for i in reversed(range(int(math.sqrt(N))+1)):
  if N % i == 0:
    print(i-1+(N//i)-1)
    break
Buggy code:
import math
import itertools
n = int(input())
x = 1
for i in reversed(range(1, int(math.sqrt(n)))):
    if n % i == 0:
        x = n / i
        break

print(x - 1 + n / x - 1)

Fixed code:
import math
import itertools
n = int(input())
x = 1
for i in reversed(range(1, math.ceil(math.sqrt(n))+1)):
    if n % i == 0:
        x = n / i
        break

print(math.floor(x - 1 + n / x - 1))
Buggy code:
N=int(input())
a=[]
for i in range(1,N+1):
    if N%i==0:
        x=i+N//i
        a.append(x)
b=min(a)
print(b-2)

Fixed code:
N=int(input())
a=[]
for i in range(1,int(N**(1/2)+1)):
    if N%i==0:
        x=i+N//i
        a.append(x)
b=min(a)
print(b-2)
Buggy code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N = I()
    ans = N - 1
    max_sq = int(math.sqrt(N)) + 1
    for i in range(1, max_sq):
        if N % i != 0:
            continue
        j = N / i
        ans = min(ans, i+j-2)
    print(ans)

main()



Fixed code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N = I()
    ans = N - 1
    max_sq = int(math.sqrt(N)) + 1
    for i in range(1, max_sq):
        if N % i != 0:
            continue
        j = N // i
        ans = min(ans, i+j-2)
    print(ans)
main()
Buggy code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
def main():
    N = int(input())
    ans = N-1
    max_sq = int(math.sqrt(N)+1)
    for i in range(1, max_sq):
        if N % i != 0:
            continue
        j = N / i
        ans = min(ans, i+j-2)
    print(ans)
main()



Fixed code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
def main():
    N = int(input())
    ans = 10e+12 
    max_sq = int(math.sqrt(N)+1)
    for i in range(1, max_sq):
        if N % i == 0:
            j = N // i
            ans = min(ans, i+j-2)
    print(ans)
main()
Buggy code:
n=int(input())
i=1
ans=10**13
while(i*i<=n):
    if(n%i==0):
        ans=min(ans,n/i+i-2)
    i+=1
print(ans)

Fixed code:
n=int(input())
i=1
ans=10**13
while(i*i<=n):
    if(n%i==0):
        ans=min([ans,n/i+i-2])
    i+=1
print(int(ans))
Buggy code:
import math

N=int(input())

ans=999999999999
for i in range(1,math.sqrt(N)+1):
  if N % i == 0:
    ans = min(ans,i + N//i - 2)
print(ans)

Fixed code:
import math

N=int(input())

ans=999999999999
for i in range(1,int(math.sqrt(N))+1):
  if N % i == 0:
    ans = min(ans,i + N//i - 2)
print(ans)
Buggy code:
import math

N = int(input())

route_N = math.sqrt(N)

# a+b-2 minimum
# a*b = N 

ans = 10e+12

for a in range(1,int(route_N)+1):
    if N%a ==0:
        ans = min(ans,a+(N/a)-2)

print(ans)




Fixed code:
import math

N = int(input())

route_N = math.sqrt(N)

# a+b-2 minimum
# a*b = N 

ans = 10e+12

for a in range(1,int(route_N)+1):
    if N%a ==0:
        ans = min(ans,a+(N/a)-2)

print(int(ans))
Buggy code:
import numpy as np
n = int(input())

mean = int(np.sqrt(n))

for i in range(mean):
    div = mean - i
    if n % div == 0:
        print(div + n/div - 2)
        break

Fixed code:
import numpy as np
n = int(input())

mean = int(np.sqrt(n))

for i in range(mean):
    div = mean - i
    if n % div == 0:
        print(int(div + n/div - 2))
        break
Buggy code:

N = int(input())
 
search_max = int(sqrt(N))
 
min_number = 10**12
for x in range(1, search_max + 1):
    if N % x == 0:
        y = N // x
        if x + y < min_number:
            min_number = x + y
 print(min_number-2)

Fixed code:
N = int(input())
search_max = int(N**0.5)
 
min_number = 10**12
for x in range(1, search_max + 1):
    if N % x == 0:
        y = N // x
        if x + y < min_number:
         
            min_number = x + y
print(min_number-2)
Buggy code:
N = int(input())

ans = 10000000000
for i in range(1,1000001):
  if N%i == 0:
    ans = min(ans,i+N//i-2)
    
print(ans)


Fixed code:
N = int(input())

ans = 10000000000000000000
for i in range(1,1000001):
  if N%i == 0:
    ans = min(ans,i+N//i-2)
    
print(ans)
Buggy code:
N = int(input())
ans = 10 ** 12
print(int(N ** 0.5) + 1)
for x1 in range(1, int(N ** 0.5) + 1):
    if N % x1 == 0:
        y1 = N // x1
        now = x1 + y1 - 2
        ans = min(ans, now)
print(ans)

Fixed code:
N = int(input())
ans = 10 ** 12
for x1 in range(1, int(N ** 0.5) + 1):
    if N % x1 == 0:
        y1 = N // x1
        now = x1 + y1 - 2
        ans = min(ans, now)
print(ans)
Buggy code:
import math

def sq(n):
    for i in range(math.floor(math.sqrt(N)), 0, -1):
        print(i)
        if n % i == 0:
            return (i, n//i)

N = int(input())
a, b = sq(N)
print(a + b - 2)

Fixed code:
import math

def sq(n):
    for i in range(math.floor(math.sqrt(N)), -1, -1):
        if n % i == 0:
            return (i, n//i)

N = int(input())
a, b = sq(N)
print(a + b - 2)
Buggy code:
N = int(input())

def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            tmp = []
            tmp.append(i)
            tmp.append(n//i)
            divisors.append(tmp)
    return divisors

L = divisors(N)
ans = float('inf')
print(L)
for l in L:
    tmp = sum(l) - 2
    ans = min(ans,tmp)
print(ans)

Fixed code:
N = int(input())

def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            tmp = []
            tmp.append(i)
            tmp.append(n//i)
            divisors.append(tmp)
    return divisors

L = divisors(N)
ans = float('inf')

for l in L:
    tmp = sum(l) - 2
    ans = min(ans,tmp)
print(ans)
Buggy code:
n = int(input())
m = 10**13
for x in range(1,1000001):
  y = n / x
  if y % 1 == 0:
    v = x + y -2
    m = min(m, v)
print(m)

Fixed code:
n = int(input())
m = 10**13
for x in range(1,1000001):
  y = n / x
  if y % 1 == 0:
    v = x + y -2
    m = min(m, v)
print(int(m))
Buggy code:
n = int(input())
def make_divisors(n):
    k = 0
    divisors = []
    for i in reversed(range(1, int(n**0.5)+1)):
        if n % i == 0:
            k = i

    # divisors.sort()
    return k
k = make_divisors(n)
kk = n // k
print(kk + k - 2)

Fixed code:
n = int(input())
def make_divisors(n):
    k = 0
    divisors = []
    for i in reversed(range(1, int(n**0.5)+1)):
        if n % i == 0:
            k = i
            break
    # divisors.sort()
    return k
k = make_divisors(n)
kk = n // k
print(kk + k - 2)
Buggy code:
N = int(input())

for i in range(int(N**0.5), 1, -1):
    if (N / i).is_integer():
        a = N // i
        b = N // a
        break

print(a+b-2)

Fixed code:
N = int(input())

for i in range(int(N**0.5), 0, -1):
    if (N / i).is_integer():
        a = N // i
        b = N // a
        break

print(a+b-2)
Buggy code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def main():
    Min = 2000000000000
    divisors = make_divisors(int(input()))
    if len(divisors)%2==1:
        divisors.append(divisors[len(divisors)-1])
    print(divisors)
    for i in range(0,len(divisors)-1,2):
        Min = min(divisors[i]+divisors[i+1],Min)
    print(Min-2)

main()

Fixed code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def main():
    Min = 2000000000000
    divisors = make_divisors(int(input()))
    if len(divisors)%2==1:
        divisors.append(divisors[len(divisors)-1])
    #print(divisors)
    for i in range(0,len(divisors)-1,2):
        Min = min(divisors[i]+divisors[i+1],Min)
    print(Min-2)

main()
Buggy code:
import numpy as np

N = int(input())
print(int(np.sqrt(N)))
for i in range(int(np.sqrt(N)), 0, -1) :
  if N%i == 0 :
    print(int(N/i)+i-2)
    exit()

print(N-1)

Fixed code:
import numpy as np

N = int(input())
for i in range(int(np.sqrt(N)), 0, -1) :
  if N%i == 0 :
    print(int(N/i)+i-2)
    exit()

print(N-1)
Buggy code:
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            divisors.append(n//i)

    # divisors.sort()
    return divisors

n_list = make_divisors(n)
n_ans = []
print(n_list)
for i in range(0, len(n_list)-1, 2):
    n_ans.append(n_list[i]+n_list[i+1])

n_ans.sort()

print(n_ans[0]-2)

Fixed code:
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            divisors.append(n//i)

    # divisors.sort()
    return divisors

n_list = make_divisors(n)
n_ans = []

for i in range(0, len(n_list)-1, 2):
    n_ans.append(n_list[i]+n_list[i+1])

n_ans.sort()

print(n_ans[0]-2)
Buggy code:
import math
n = int(input())
m = int(math.sqrt(n))

ans = n - 1

for a in range(m):
  if n % a == 0:
    b = n // a
    ans = min(ans, a + b - 2)
    
print(ans)

Fixed code:
import math
n = int(input())
m = int(math.sqrt(n)) + 1

ans = n - 1

for a in range(2, m):
  if n % a == 0:
    ans = min(ans, a + n//a - 2)
    
print(ans)