qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N=int(input())
ans=10**12
for  x in range(1,N+1):
    if N%x==0:
        if (x+(N/x)-2)<ans:
            ans=(x+(N/x)-2)
print(ans)

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

Fixed code:
N = int(input())
for i in range(1,int(N**0.5+1)):
  if N % i == 0:
    ans = i + N // i - 2
print(ans)
Buggy code:
n = int(input())
for i in range(-int(-n**0.5//1),0,-1):
  if n%i=0:
    a=i
    b=n//i
print(a+b-2)

Fixed code:
n = int(input())
for i in range(-int(-n**0.5//1),0,-1):
  if n%i==0:
    a=i
    b=n//i
    break
print(a+b-2)
Buggy code:
import math

N = int(input())
ans = N-1
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 = N-1
for i in range(1, int(math.sqrt(N)+1)):
    if N%i==0:
        ans = min(ans, i+(N/i)-2)
print(int(ans))
Buggy code:
import math
N = int(input())
x = math.floor(math.sqrt(N))
y = 0
for i in range(1, x+1):
    if N % i == 0:
        y = i
        break
    else:
        continue
ans = y + (N/y) - 2
print(int(ans))


Fixed code:
import math
N = int(input())
x = math.floor(math.sqrt(N))
y = 0
for i in reversed(range(1, x+1)):
    if N % i == 0:
        y = i
        break
    else:
        continue
ans = y + (N/y) - 2
print(int(ans))
Buggy code:
import math

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

ans=1000000000000

for i in range(1,n+1):
    if N%i==0:
        if ans>i+(N/i):
            ans=i+(N/i)
            print(i,N/i,ans)

print(ans-2)


Fixed code:
import math

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

ans=1000000000000

for i in range(1,n+1):
    if N%i==0:
        if ans>i+(N/i):
            ans=i+(N/i)

print(int(ans-2))
Buggy code:
import math
n = int(input())

ans = 10**18
for i in range(1, int(math.sqrt(n))+1):
  if n % i == 0:
    ans = min(ans, i + n / i)
print(ans-2)

Fixed code:
import math
n = int(input())

ans = 10**18
for i in range(1, int(math.sqrt(n))+1):
  if n % i == 0:
    ans = min(ans, i + n / i)
print(int(ans)-2)
Buggy code:
N = input()
N_sqrt = int(np.sqrt(N))+1
N_ = [i for i in range(2, N_sqrt) if N % i == 0]

if len(N_) == 0:
    print(N-1)
else:
    pair = [(i, int(N/i)) for i in N_]
    my_lambda = lambda x : sum(x)
    x = list(map(my_lambda, pair))
    print(min(x)-2)

Fixed code:
import numpy as np

N = int(input())
N_sqrt = int(np.sqrt(N))+1
N_ = [i for i in range(2, N_sqrt) if N % i == 0]

if len(N_) == 0:
    print(N-1)
else:
    pair = [(i, int(N/i)) for i in N_]
    my_lambda = lambda x : sum(x)
    x = list(map(my_lambda, pair))
    print(min(x)-2)
Buggy code:
from math import ceil, sqrt
N = int(input())

for i in range(floor(sqrt(N)), 0, -1):
    if N % i == 0:
        print((N//i) + i - 2)
        break
    

Fixed code:
from math import ceil, sqrt
N = int(input())

for i in range(ceil(sqrt(N)), 0, -1):
    if N % i == 0:
        print((N//i) + i - 2)
        break
Buggy code:
n = int(input())
ans = n
for i in range(1,n+1):
#  print(n,i)
  if n % i == 0:
    q = n / i
    qplusmod = q + i
#    print(n,i,qplusmod)
    if qplusmod < ans:
      ans = qplusmod
print(int(ans - 2))

Fixed code:
n = int(input())
qplusmod = 0
i = 1
ans = n+1
for i in range(1,int(n)):
#  print(n,i)
  if n % i == 0:
    q = n / i
    qplusmod = q + i
#    print(n,i,qplusmod)
    if qplusmod < ans:
      ans = int(qplusmod)
  if i > n/i:
#    print(i)
    break
print(int(ans - 2))
Buggy code:
import math
N=int(input())
for i in reversed(range(int(math.sqrt(N)))):
    if N%(i+1)==0:
        print(N//(i+1)+i+1)
        break

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


Fixed code:
n=int(input())
m=10**12+1
for i in range(1,int(n**.5)+1):
    if n%i==0:
        m=min(m, n//i+i)
print(m-2)
Buggy code:
import math
N = int(input())
sqN = int(math.sqrt(N))
for i in range(sqN):
  if N % (sqN-i) == 0:
    print(int(N/(sqN-i)+sqN-i))
    break

Fixed code:
import math
N = int(input())
sqN = int(math.sqrt(N))
for i in range(sqN):
  if N % (sqN-i) == 0:
    print(int(N/(sqN-i)+sqN-i)-2)
    break
Buggy code:
n=int(input())
for i in range(1,int(n**0.5+1)):
  if n%i==0:
    a=i
    b=n//i
print(a,b)
print(a+b-2)

Fixed code:
n=int(input())
for i in range(1,int(n**0.5+1)):
  if n%i==0:
    a=i
    b=n//i
print(a+b-2)
Buggy code:
import math
n = int(input())
min_ = n-1
for i in range(1, math.floor(math.sqrt(n))+1):
  if n % i == 0:
    hosu = i+ n/i -2
    if hosu < min_:
      min_ = hosu
      
print(min_)

Fixed code:
import math
n = int(input())
min_ = n-1
for i in range(1, math.floor(math.sqrt(n))+1):
  if n % i == 0:
    hosu = i+ n//i -2
    if hosu < min_:
      min_ = hosu
      
print(min_)
Buggy code:
from math import sqrt

N = int(input())

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


Fixed code:
from math import sqrt

N = int(input())

for i in range(int(sqrt(N) + 1), -1, -1):
    if N % i == 0:
        print((i - 1) + (N // i - 1))
        break
Buggy code:
n=int(input())
keep=10**100
for i in range(1,10**6+1):
  if n%i==0:
    temp=i+n//i
    if temp<keep:
      keep=temp
print(temp-2)

Fixed code:
n=int(input())
keep=10**100
for i in range(1,10**6+1):
  if n%i==0:
    temp=i+n//i
    if temp<keep:
      keep=temp
print(keep-2)
Buggy code:
def factorize(n):
    a = []
    f = 2
    while f * f <= n:
        if n % f == 0:
            a.append((f, n//f))
        f += 1
    return a

n = int(input())
factor = factorize(n)

ans = int(1e13)
for fa in factor:
    a, b = fa
    ans = min(ans, a + b - 2)
print(ans)

Fixed code:
def factorize(n):
    a = []
    f = 2
    while f * f <= n:
        if n % f == 0:
            a.append((f, n//f))
        f += 1
    if not len(a):
        a.append((1, n))
    return a

n = int(input())
factor = factorize(n)

ans = int(1e13)
for fa in factor:
    a, b = fa
    ans = min(ans, a + b - 2)
print(ans)
Buggy code:
n=int(input())
k=list()
for i in range(n):
  if n%(i+1)==0:
    k.append(int(i+n/(i+1)-1))
print(min(k))

Fixed code:
n=int(input())
k=list()
for i in range(int(n**0.5)):
  if n%(i+1)==0:
    k.append(int(i+n/(i+1)-1))
print(min(k))
Buggy code:
import math
n = int(input())
for i in range(int(math.sqrt(n)), 0, -1):
    if n%i==0:
        print(int((i-1)+(n/i-1)))

Fixed code:
import sys
import math
n = int(input())
for i in range(int(math.sqrt(n)), 0, -1):
    if n%i==0:
        print(int((i-1)+(n/i-1)))
        sys.exit()
Buggy code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

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

def main():
  n = ni()

  x = divi(n)
  
  ans = 1e18+7
  for i in range(0, len(x), 2):
    print(x[i])
    ans = min(ans, x[i] - 1 + x[i+1] - 1)
  print(ans)
  

main()

Fixed code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

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

def main():
  n = ni()

  x = divi(n)
  
  ans = 1e18+7
  for i in range(0, len(x), 2):
    # print(x[i])
    try:
      ans = min(ans, x[i] - 1 + x[i+1] - 1)
    except:
      ans = min(ans, (x[i] - 1) * 2)  
  print(ans)
  
main()
Buggy code:
n = int(input())
r = int(n**0.5)
while r>0:
    if n % r == 0:
        print(int(r + n/r - 2))
        break
    else:
        r =- 1

Fixed code:
n = int(input())
r = int(n**0.5)
while r>0:
    if n % r == 0:
        print(int(r + n/r - 2))
        break
    r = r - 1
Buggy code:
n = int(input())
l = []
for i in range(1, n + 1):
    if n % i == 0:
        j = n // i
        l.append(i + j)

print(min(l) - 2)

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

print(min(l) - 2)
Buggy code:
N = int(input())
lst=[]
for i in range(1,int(N**0.5)+1):
    if n%i==0:
        lst.append(i+n//i-1)
print(min(lst))

Fixed code:
N = int(input())
lst=[]
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        lst.append(i+N//i-2)
print(min(lst))
Buggy code:
import math
import sys

n = int(input())

ans = sys.maxsize

for i in range(1, int(math.sqrt(n)) + 1):
    if n % i == 0:
        tmp = min((i - 1) + (n // i - 1), ans)

print(ans)


Fixed code:
import math
import sys

n = int(input())

ans = sys.maxsize

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

print(ans)
Buggy code:
n = int(input())
stop = int(sqrt(n)) + 1
min_count = 10 ** 100
for a in range(1, stop):
    if n % a != 0:
        continue
    else:
        b = n // a
    count = a + b - 2
    if count < min_count:
        min_count = count
print(min_count)

Fixed code:
from math import sqrt
n = int(input())
stop = int(sqrt(n)) + 1
min_count = 10 ** 100
for a in range(1, stop):
    if n % a != 0:
        continue
    else:
        b = n // a
    count = a + b - 2
    if count < min_count:
        min_count = count
print(min_count)
Buggy code:
N = int(input())
a = []
b = []
for i in range(1,10**6):
	if N % i == 0:
		b.append(N // i)
		a.append(i)
	if i > N:
		break
ab = 10**7
for i in range(len(a)):
	ab = min(ab,(a[i]-1)+(b[i]-1))
print(ab)

Fixed code:
N = int(input())
a = []
b = []
for i in range(1,10**6+1):
	if N % i == 0:
		b.append(N // i)
		a.append(i)
	if i > N:
		break
ab = 10**13
for i in range(len(a)):
	ab = min(ab,(a[i]-1)+(b[i]-1))
print(ab)
Buggy code:
import math
b = input()
a = int(b)

sqA = int(math.sqrt(a))

for i in range(10000000):
    d = a / (sqA - i)
    if d.is_integer() == True:
        break


e = d + sqA - i - 2
print(d)
print(sqA + i)
print(int(e))


Fixed code:
import math
b = input()
a = int(b)

sqA = int(math.sqrt(a))

for i in range(10000000):
    d = a / (sqA - i)
    if d.is_integer() == True:
        break


e = d + sqA - i - 2

print(int(e))
Buggy code:
import math

n = int(input())
startnum = math.floor(math.sqrt(n))
for i in range(startnum,0,-1):
	if n % i == 0:
		print(i + (n//i) - 1)
		exit()


Fixed code:
import math

n = int(input())
startnum = math.floor(math.sqrt(n))
for i in range(startnum,0,-1):
	if n % i == 0:
		print(i + (n//i) - 2)
		exit()
Buggy code:
N = int(input())
k = 0
while k ** 2 < N:
  k++
for i in range(k, 0, -1):
  if N % i:
    continue
  print(N // i + i - 2)
  break

Fixed code:
N = int(input())
k = 0
while k ** 2 < N:
  k += 1
for i in range(k, 0, -1):
  if N % i:
    continue
  print(N // i + i - 2)
  break
Buggy code:
from math import sqrt
n = int(input())
d = 1000000000000000000000
for i in range(1, sqrt(n)+1):
  if n % i == 0:
    d = min(d, i + n // i - 2)
print(d)


Fixed code:
from math import sqrt
n = int(input())
d = 1000000000000000000000
for i in range(1, int(sqrt(n))+1):
  if n % i == 0:
    d = min(d, i + n // i - 2)
print(d)
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)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

mi = 10**10
for i in make_divisors(n):
    a = i;b = n//i
    mi = min(mi,a+b-2)

print(mi)

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)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

mi = 10**15
for i in make_divisors(n):
    a = i;b = n//i
    mi = min(mi,a+b-2)

print(mi)
Buggy code:
n = int(input())
rn = int(n**(0.5))+1
ans = n
for i in range(n):
	if n%(i+1) == 0:
		ans = min(int(n/(i+1))+i+1, ans)

print(ans-2)

Fixed code:
n = int(input())
rn = int(n**(0.5))+1
ans = n
for i in range(1,rn):
	if n%i == 0:
		
		ans = min((n//i)+i-2, ans)
		

print(ans)
Buggy code:
n=int(input())
xlist=[]

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

ans=max(xlist)
print(ans+n/ans-2)

Fixed code:
n=int(input())
xlist=[]
 
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        xlist.append(i)
 
ans=max(xlist)
print(int(ans+n/ans-2))
Buggy code:
import math

def divisor_generator(n):
    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            large_divisors.append(n // i)
    for divisor in reversed(large_divisors):
        yield divisor

n = int(input())


divs = list(divisor_generator(n))
print(divs)
l = len(divs) - 1
best = 2 if n == 1 else min([divs[i] + divs[l-i] for i in range(len(divs)>>1)] )

print(best-2)

Fixed code:
import math

def divisor_generator(n):
    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            large_divisors.append(n // i)
    for divisor in reversed(large_divisors):
        yield divisor

n = int(input())


divs = list(divisor_generator(n))
l = len(divs) - 1
best = 2 if n == 1 else min([divs[i] + divs[l-i] for i in range(len(divs)>>1)] )

print(best-2)
Buggy code:
import math

N = int(input())

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

Fixed code:
import math

N = int(input())

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

N = int(input())
min_move_count = 10**7

for i in range(1, int(math.sqrt(N)) + 1):
    if N % i == 0:
        move_count = i + (N // i) - 2
        if move_count < min_move_count:
            min_move_count = move_count

ans = min_move_count
print(ans)


Fixed code:
import math

N = int(input())
min_move_count = 10**13

for i in range(1, int(math.sqrt(N)) + 1):
    if N % i == 0:
        move_count = i + (N // i) - 2
        if move_count < min_move_count:
            min_move_count = move_count

ans = min_move_count
print(ans)
Buggy code:
N = int(input())
list = []
for i in range(N):
    if(N%(i+1) == 0):
        list.append([i+1, N//(i+1)])
min = 1000000000000
for i in list:
    if(min > i[0]+i[1]):
        min = i[0]+i[1]
print(min-2)

Fixed code:
import math
N = int(input())
list = []
for i in range(int(math.sqrt(N))):
    if(N%(i+1) == 0):
        list.append([i+1, N//(i+1)])
min = 1000000000000
for i in list:
    if(min > i[0]+i[1]):
        min = i[0]+i[1]
print(min-2)
Buggy code:
N = int(input())
a = 2
while a * a <= N:
  if N % a = 0:
    k = a
  a += 1
print(k + N//k -2)


Fixed code:
N = int(input())
a = 1
while a * a <= N:
  if N % a == 0:
    k = a
  a += 1
b = N //k
print(b + k - 2)
Buggy code:
import math
N=int(input())    
NS=math.floor(N**0.5)

ans=1000000000
for i in range(NS,0,-1):
  if N%i==0:
    tmp=N//i
    anst=tmp+i-2
    ans=min(ans,anst)
            
print(ans)

Fixed code:
import math
N=int(input())    
NS=math.floor(N**0.5)

ans=1000000000000
for i in range(NS,0,-1):
  if N%i==0:
    tmp=N//i
    anst=tmp+i-2
    ans=min(ans,anst)
            
print(ans)
Buggy code:
n = int(input())

ans = n

i = 1

while i*i<=n :
  if n%i == 0 :
    d = n/i
    if ans > i*d-2 : ans = i*d-2
  i++
      
print(ans)

Fixed code:
n = int(input())
ans = n
i = 1
while i*i<=n :
  if n%i == 0 :
    d = n//i
    if ans > i+d-2 : ans = i+d-2
  i+=1
print(int(ans))
Buggy code:
n=int(input())

r=[]

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

print(min(r))

Fixed code:
n=int(input())

r=[]

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

print(min(r))
Buggy code:
N=int(input())
for i in range(int(N**0.5)+1,1,-1):
  if N%i==0:
    print(N/i+i-2)

Fixed code:
N=int(input())
for i in range(int(N**0.5)+1,0,-1):
  if N%i==0:
    print(int(N/i+i-2))
    exit()
Buggy code:
a = int(input())
s = int(a ** 0.5)
for i in range(s):
  if a%(s-i)==0:
    print(a/(s-i) + (s-i) - 2)
    break

Fixed code:
a = int(input())
s = int(a ** 0.5)
for i in range(s):
  if a%(s-i)==0:
    print(int(a/(s-i) + (s-i) - 2))
    break
Buggy code:
n=int(input())
import math
list=[ ]

for i in range(1,math.floor(n*0.5)+1):
  if (n/i)%1==0:
    j=n/i
    list.append(i+j)

print(int(min(list)-2))


Fixed code:
n=int(input())
import math
list=[ ]

for i in range(1,math.floor(n**0.5)+1):
  if (n/i)%1==0:
    j=n/i
    list.append(i+j)

print(int(min(list)-2))
Buggy code:
import math
n=int(input())

a=0
b=0
for i in range(int(math.sqrt(n)),2,-1):
  if n%i==0:
    a=i
    b=n//i
if a==0:
  print(n-1)
else:
  print(a+b-2)

Fixed code:
import math
n=int(input())

a=0
b=0
for i in range(int(math.sqrt(n)),1,-1):
  if n%i==0:
    a=i
    b=n//i
    break
if a==0:
  print(n-1)
else:
  print(a+b-2)
Buggy code:
import math.sprt
N=int(input())

A=int(sqrt(N))
a=1
b=1
for i in range(1, A+1):
  if N%i==0:
    a=i
    b=N/i
print(a+b-2)

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

A=int(math.sqrt(N))
a=1
b=1
for i in range(1, A+1):
  if N%i==0:
    a=i
    b=N/i
print(int(a+b-2))
Buggy code:

N = int(input())
b = n**0.5//1.0
while True:
    if N%b != 0:
        b -= 1
    else:
        break
print(int(b+N/b-2))

Fixed code:

N = int(input())
b = N**0.5//1.0
while True:
    if N%b != 0:
        b -= 1
    else:
        break
print(int(b+N/b-2))
Buggy code:
n = int(input())
tmp = 1
 
for i in range(1,10**10):
  if n//i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
  elif tmp == 1 and i >= n/i:
    break
    
      
print(tmp + (n//tmp) -2)

Fixed code:
n = int(input())
tmp = 1
 
for i in range(1,10**6+1):
  if n%i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
  elif tmp == 1 and i >= n/i:
    break
      
print(tmp + (n//tmp) -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

N = int(input())

n = make_divisors(N)
n.sort()
mannaka_ = int(len(n)/2)
mannaka = mannaka_ - 1
print(n)
if len(n)%2 == 0:
    print((n[mannaka_]-1)+ (n[mannaka]-1))
else:
    print(n[mannaka_] * 2)

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

N = int(input())

n = make_divisors(N)
n.sort()
mannaka_ = int(len(n)/2)
mannaka = mannaka_ - 1
#print(n)
if len(n)%2 == 0:
    print((n[mannaka_]-1)+ (n[mannaka]-1))
else:
    print(n[mannaka_] * 2 - 2)
Buggy code:
N = int(input())
for i in range(int(N ** 0.5),0,-1):
  if(N % i == 0):
    print(i - 1 + N // i - 1): 
    break

Fixed code:
N = int(input())
for i in range(int(N ** 0.5),0,-1):
  if(N % i == 0):
    print(i - 1 + N // i - 1)
    break
Buggy code:
import math
from functools import reduce

def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def prime(n1):
	for i in range(2, int(math.sqrt(n1))):
		if n1%i == 0:
			return False
	return True

n = int(input())
if prime(n):
	print(n - 1)
else:
	k = sorted(list(factors(n)))
	#print(k)
	s = k[len(k)//2] + k[len(k)//2 + 1]
	print(s - 2)


Fixed code:
import math
from functools import reduce

def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def prime(n1):
	for i in range(2, int(math.sqrt(n1))+1):
		if n1%i == 0:
			return False
	return True

n = int(input())
if prime(n):
	print(n - 1)
else:
	k = sorted(list(factors(n)))
	#print(k)
	if len(k) % 2 != 0:
		if k[len(k)//2]*k[len(k)//2] == n:
			print(2*k[len(k)//2] - 2)
		#else:

	else:
		s = k[len(k)//2 - 1] + k[len(k)//2]
		print(s - 2)
Buggy code:
n = int(input())
min1 = 10**10
for i in range(1,int(n**0.5)+1):
  if n/i %1 == 0:
    j = n//i
    min1 = min(min1,i+j)
print(min1-2)

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

n = int(input())

ans = []

def n2divide(n):
    for i in range(1, n):
            if n % i == 0:
                ans.append(i + n/i -2)   
    return ans
    
    
a = n2divide(n)
print(int(min(a)))

Fixed code:
import math

n = int(input())

array = []
ans = []

def n2divide(n):
    for i in range(1, int(math.sqrt(n))+1):
            if n % i == 0:
                array.append(i)
                
    for j in array:
        ans.append(j + n/j -2)
        
    return ans
    
    
a = n2divide(n)
print(int(min(a)))
Buggy code:
import math

n = int(input())

ans  = 10 ** 7 
for i in range(1, math.sqrt(n) + 1):
    if n%i != 0:
        continue
    j = n/i
    ans = min(ans, i+j-2)

print(ans)

Fixed code:
import math

n = int(input())

ans  = 10 ** 12 
for i in range(1, math.floor(math.sqrt(n)) + 1):
    if n%i != 0:
        continue
    j = int(n/i)
    ans = min(ans, i+j-2)

print(ans)
Buggy code:
from itertools import product
n = int(input())
def factorization(num):
    result = []
    count = 0
    temp = num
    for i in range(2, int(num ** 0.5) + 1):
        if temp % i == 0:
            count = 0
            while temp % i == 0:
                count += 1
                temp /= i
            result.append([i, count])
    if temp != 1:
        result.append([temp, 1])
    if result == []:
        result.append([num, 1])
    return result
factors = factorization(n)
exps = [range(factor[1] + 1) for factor in factors]
ans = 1001001001001
for exp0 in product(*exps):
    f0 = 1
    for i in range(len(exp0)):
        f0 *= factors[i][0] ** exp0[i]
    f1 = n // f0
    ans = min(ans, f0 + f1 - 2)
print(ans)

Fixed code:
from itertools import product
n = int(input())
def factorization(num):
    result = []
    count = 0
    temp = num
    for i in range(2, int(num ** 0.5) + 1):
        if temp % i == 0:
            count = 0
            while temp % i == 0:
                count += 1
                temp /= i
            result.append([i, count])
    if temp != 1:
        result.append([temp, 1])
    if result == []:
        result.append([num, 1])
    return result
factors = factorization(n)
exps = [range(factor[1] + 1) for factor in factors]
ans = 1001001001001
for exp0 in product(*exps):
    f0 = 1
    for i in range(len(exp0)):
        f0 *= factors[i][0] ** exp0[i]
    f1 = n // f0
    ans = min(ans, f0 + f1 - 2)
print(int(ans))
Buggy code:
import math
N = int(input())
n = round(math.sqrt(N))
counter = 0
for i in range(n):
		if N%(n-i) == 0 and counter == 0:
			counter+=1
			var1=(n-i)
			var2=N/(n-i)
            
print(var1+var2-2)        


Fixed code:
import math
N = int(input())
n = round(math.sqrt(N))
counter = 0
for i in range(n):
		if N%(n-i) == 0 and counter == 0:
			counter+=1
			var1=(n-i)
			var2=N/(n-i)
            
print(int(var1+var2-2))
Buggy code:
n = int(input())
ans = n - 1
i = 2
while i*i <= n:
	if n % i == 0:
		ans = min(ans, i - 1, n // i - 1)

	i += 1
print(ans)

Fixed code:
n = int(input())

i, ans = 1, n
while i*i <= n:
    if n % i == 0:
        ans = min(ans, i+n//i-2)
    i += 1

print(ans)
Buggy code:
import math

N = int(input())
n = math.sqrt(N)
ans = 10 ** 12

for i in range(1 , math.ceil(n) + 1):
  if i * math.ceil(N / i) == N:
    count = (i - 1) + ((N / i) - 1)
    ans = min(ans , count)
    
print(ans)

Fixed code:
import math

N = int(input())
n = math.sqrt(N)
ans = 10 ** 12

for i in range(1 , math.ceil(n) + 1):
  if i * (N // i) == N:
    count = (i - 1) + ((N // i) - 1)
    ans = min(ans , count)
    
print(ans)