qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import math
A = int(input())
p = int(math.sqrt(A))
all_lis = []
ans_lis = []

for i in range(1,p,1):
    if A % i == 0:
        kumi = [i,int(A/i)]
        all_lis.append(kumi)
        
print(all_lis)

for j in all_lis:
    ans_lis.append(j[0]+j[1])
    
print(int(min(ans_lis)-2))

Fixed code:
import math
A = int(input())
p = int(math.sqrt(A)) + 1
all_lis = []
ans_lis = []

for i in range(1,p,1):
    if A % i == 0:
        kumi = [i,int(A/i)]
        all_lis.append(kumi)

for j in all_lis:
    ans_lis.append(j[0]+j[1])
    
print(int(min(ans_lis)-2))
Buggy code:
import sqrt from math
N=int(input())
for i in range(int(sqrt)+1,-1,-1):
    if N%i==0:
        print(i-1+N//i-1)
        exit()


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)
        exit()
Buggy code:
N = int(input())
n = round(N ** 1/2)
i = n
m = 0
while m == 0:
    if N%i == 0:
        m = N/i
    else:
        i -=1
print(round(i+m-2))

Fixed code:
N = int(input())
n = round(N ** (1/2))
i = n
m = 0
while m == 0:
    if N%i == 0:
        m = N/i
    else:
        i -=1
print(round(i+m-2))
Buggy code:
import math
N=int(input())
dis=N-1

for i in range(2,int(math.sqrt(N))+1):
    if N%i==0:
        if ((N/i)-1)+(i-1)<dis:
            dis=((N/i)-1)+(i-1)
        else:
            pass
    else:
        pass
print(dis)
        
        


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

for i in range(2,int(math.sqrt(N))+1):
    if N%i==0:
        if ((N/i)-1)+(i-1)<dis:
            dis=((N/i)-1)+(i-1)
        else:
            pass
    else:
        pass
print(int(dis))
Buggy code:
import math
import numpy as np

n = int(input())
n_2 = int(math.sqrt(n + 1))   
div = x[n % x == 0]
ans = 10 ** 12
for i in div:
    j = (n // i) + i - 2
    ans = min(ans, j)
print(ans)

Fixed code:
import math
import numpy as np

n = int(input())
n_2 = int(math.sqrt(n) + 1)
x = np.arange(1, n_2)
div = x[n % x == 0]
ans = 10 ** 12
for i in div:
    j = (n // i) + i - 2
    ans = min(ans, j)
print(ans)
Buggy code:
def main():
  n = int(input())
  i = int((n)**0.5) + 1
  while i * i > n: i -= 1
  while i >= 1:
    if n % i == 0:
      print(i+n//i)
      return
    i -= 1
main()


Fixed code:
def main():
  n = int(input())
  i = int((n)**0.5) + 1
  while i * i > n: i -= 1
  while i >= 1:
    if n % i == 0:
      print(i+n//i-2)
      return
    i -= 1
main()
Buggy code:
import math
N = int(input())
Min = float('inf')
Max = math.ceil(math.sqrt(N))
for i in range(1,Max+1):
    if N%i==0:
        b = N//i
        Min = min(Min,i+b-2)
print(Min

Fixed code:
import math
N = int(input())
Min = float('inf')
Max = math.ceil(math.sqrt(N))
for i in range(1,Max+1):
    if N%i==0:
        b = N//i
        Min = min(Min,i+b-2)
print(Min)
Buggy code:
n = int(input())

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

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

end = int(math.sqrt(10**12))
result = 10**9
for i in range(1,end+1):
    j = n//i
    if i * j == n:
        result = min(result,i+j-2)
print(result)




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

end = int(math.sqrt(10**12))
result = 10**13
for i in range(1,end+1):
    j = n//i
    if i * j == n:
        result = min(result,i+j-2)
print(result)
Buggy code:
a=input()
a=int(a)
c=1
b=round(a*0.5)+2
for n in range(1,b):
    if a%n==0:
        c=n
d=a/c
print(d+c-2)

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

x = int(input())

tmp = []

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

print(min(tmp))

Fixed code:
import math

x = int(input())

tmp = []

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

print(min(tmp))
Buggy code:
n=int(input())
ans=n
for i in range(2,n):
  if n%i:continue
  j=n//i
  if j<i:break
  ans=j+i-2
print(ans)

Fixed code:
n=int(input())
ans=n-1
for i in range(2,n):
  j=n//i
  if j<i:break
  if n%i:continue
  ans=j+i-2
print(ans)
Buggy code:
import math
N = int(input())
A = int(math.sqrt(N))
B = 10**12
ans = 10**6
for i in range(1,A+1):
    if N % i == 0:
        C = i + (N//i) - 2
        if C < ans:
            ans = C
print(ans)

Fixed code:
import math
N = int(input())
A = int(math.sqrt(N))
B = 10**12
ans = B
for i in range(1,A+1):
    if N % i == 0:
        C = i + (N//i) - 2
        if C < ans:
            ans = C
print(ans)
Buggy code:
import math

a=int(input())
x=(math.ceil(a/2))
for i in range(x+1):
 if a%(x-i+1)==0:
  print(int(x-i-1+(a/(x-i+1))))
  break

Fixed code:
import math

a=int(input())
x=(math.ceil(a**(1/2)))
for i in range(x+1):
 if a%(x-i+1)==0:
  print(int(x-i-1+(a/(x-i+1))))
  break
Buggy code:
import math
n = int(input())
m = int(math.sqrt(n))
for i in reversed(range(1, m+1)):
  print(i)
  if n % i == 0:
    j =  n // i
    print(i+j-2)
    break

Fixed code:
import math
n = int(input())
m = int(math.sqrt(n))
for i in reversed(range(1, m+1)):
  if n % i == 0:
    j =  n // i
    print(i+j-2)
    break
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)            
    return divisors
a=int(input())
divisors=make_divisors(a)
divisors.sort()
b=len(divisors)
if b%2==0:
  c = (divisors[int(b/2-0.5)]-1)+(divisors[int(b/2+0.5)]-1)
else:
  c = 2*(divisors[int(b/2)]-1)

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)            
    return divisors
a=int(input())
divisors=make_divisors(a)
divisors.sort()
b=len(divisors)
if b%2==0:
  c = (divisors[int(b/2-0.5)]-1)+(divisors[int(b/2+0.5)]-1)
else:
  c = 2*(divisors[int(b/2)]-1)
print(c)
Buggy code:
N=int(input())
ans=[]
for i in range(1,N**.5):
    if N%i==0:
        ans.append(N//i+i-2)
print(min(ans))

Fixed code:
N = int(input())

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

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

print(N/i + i -2)


Fixed code:
N = int(input())
root = int(N**0.5)
for i in range(root,-1,-1):
  if N % i ==0:
    break

print(int(N/i + i -2))
Buggy code:
N = int(input())
check = N
if N > 10**6:
    check = 10**6+2
mi = N+1
for i in range(1,check+1):
    if N%check==0:
        if mi > i + (N//i):
            mi = i + (N//i)
print(mi-2)


Fixed code:
N = int(input())
check = N
if N > 10**6:
    check = 10**6+2
mi = N+1
for i in range(1,check+1):
    if N%i==0:
        if mi > i + (N//i):
            mi = i + (N//i)
print(mi-2)
Buggy code:
N = int(input())
minstep = 9999999999999999999999999999999
for i in range(int(N**0.5+1)):
  if N%i == 0:
    minstep = min(minstep, N+i-2)
print(minstep)

Fixed code:
N = int(input())
minstep = 9999999999999999999999999999999
for i in range(1, int(N**0.5+1)):
  if N%i == 0:
    minstep = min(minstep, i+N//i-2)
print(minstep)
Buggy code:
n = int(input())
from math import sqrt
root = int(sqrt(n))
print(root)

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


Fixed code:
n = int(input())
from math import sqrt
root = int(sqrt(n))

for i in range(root,0,-1):
    if n%i == 0:
        ans = i+(n/i)-2
        break
print(int(ans))
Buggy code:
n = int(input())

class Kake:
    def __init__(self, n):
        self.n = n
        
    def div(self):
        div_dict = {}
        
        for i in range(1, int(self.n/2)+1):
            if self.n % i == 0 and i <= (self.n/i):
                div_dict[i] = int(self.n / i)

        sa_list = list()
        for i in div_dict:
            sa_list.append((i-1)+(div_dict[i]-1))
        print(min(sa_list))
        
kake = Kake(n)
kake.div()


Fixed code:
n = int(input())

class Kake:
    def __init__(self, n):
        self.n = n

    def div(self):
        div_dict = {}
        
        for i in range(1, int(self.n**0.5)+1):
            if self.n % i == 0 and i <= (self.n/i):
                div_dict[i] = int(self.n / i)     
    
        sa_list = list()
        for i in div_dict:
            sa_list.append((i-1)+(div_dict[i]-1))
        print(min(sa_list))
         
kake = Kake(n)
kake.div()
Buggy code:
n=int(input())
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
p=make_divisors(n)

l=len(p)
if l%2==1:
  ans=p[l-1]*2-2
  
else:
  ans=p[l-1]+p[l-2]-2
  
print(ans)

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
p=make_divisors(n)

l=len(p)
if l%2==1:
  ans=p[l-1]*2-2
  
else:
  ans=p[l-1]+p[l-2]-2
  
print(ans)
Buggy code:
import sys
input = sys.stdin.readline
s = 0
N = int(input())
for i in range(1, int(N/2)):
    if N%i == 0 and i > s:
        s = i
print(s+(N//s)-2)

Fixed code:
import sys
input = sys.stdin.readline
s = 0
N = int(input())
for i in range(1, int(N**(1/2))+1):
    if N%i == 0 and i > s:
        s = i
print(s+(N//s)-2)
Buggy code:
import math

def solv(N):
    x = N-1
    for i in range(1, int(math.sqrt(N))):
        if N % i == 0:
            x = min(x, i + N / i -2)
    return x

N = int(input())
print(solv(N))


Fixed code:
import math

def solv(N):
    x = N-1
    for i in range(1, int(math.sqrt(N)) + 1):
        if N % i == 0:
            x = min(x, i + N / i -2)
    return x

N = int(input())
print(int(solv(N)))
Buggy code:
import math
n=int(input())
sn=int(math.sqrt(n))
tl=list(range(1,sn+1))
ans=0
for i in range(1,sn+1):
    a=n/tl[-i]
    if a.is_integer():
        ans=int(a)
        break
b=int(n/ans)
print(n,ans,b)
print(ans-1+b-1)

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

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

for i in range(int(n ** 0.5), 0, -1):
  if n % i == 0:
    j = n / i
    print(i + j - 2)
    break

Fixed code:
n = int(input())

for i in range(int(n ** 0.5), 0, -1):
  if n % i == 0:
    j = n // i
    print(i + j - 2)
    break
Buggy code:
import collections
A= 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
  
primelist=make_divisors(A)
S = primelist[-1]
G = int(A/S)
print(primelist,S,G)
print((G-1)+(S-1))

Fixed code:
import collections
A= 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
  
primelist=make_divisors(A)
S = primelist[-1]
G = int(A/S)

print((G-1)+(S-1))
Buggy code:
N=int(input())
l=[]
for i in range(1,N):
    if N%i==0:
        l.append([i,N/i])
L=len(l)
s=[0]*L
for j in range(L):
    s[j]=l[j][0]+l[j][1]
print(int(min(s))-2)

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

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

print(ans)


Fixed code:
N = int(input())

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

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

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

Fixed code:
n=int(input())
a=int(n**(1/2))
for i in range(a):
    if n%(a-i)==0:
        print(int((a-i)+(n/(a-i))-2))
        break
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())
a = make_divisors(N)
b = []
c = []

for j in range(round(len(a)):
    for k in range(len(a)):
        if a[j] * a[k] == N:
            b.append([a[j],a[k]])

for l in range(len(b)):
    c.append(b[l][0] + b[l][1])

print(b)
print(min(c) - 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)

    return divisors

N = int(input())
a = make_divisors(N)
b = []
c = []

for j in range(len(a)):
    for k in range(len(a)):
        if a[j] * a[k] == N:
            b.append([a[j],a[k]])

for l in range(len(b)):
    c.append(b[l][0] + b[l][1])

print(min(c) - 2)
Buggy code:
# https://atcoder.jp/contests/abc144/tasks/abc144_c
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
import math
from heapq import heappush, heappop, heapify


def main():
    n = int(input())

    v = 1
    while v * v <= n:
        v += 1

    ans = 10**15
    for i in range(1, v):
        if v % i == 0:
            print(i + v // i - 2)
            return


if __name__ == '__main__':
    main()


Fixed code:
# https://atcoder.jp/contests/abc144/tasks/abc144_c
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
import math
from heapq import heappush, heappop, heapify


def main():
    n = int(input())

    v = 1
    while v * v <= n:
        v += 1

    for i in range(v, 0, -1):
        if n % i == 0:
            j = n // i
            print(i + j - 2)
            return


if __name__ == '__main__':
    main()
Buggy code:
n = int(input())
cost = []
i = 2
while i =< n**0.5:
  if n % i == 0:
    cost.append(i+n/i-2)
  i += 1
if len(cost) == 0:
  cost.append(n-1)
print(int(min(cost)))

Fixed code:
n = int(input())
cost = []
i = 2
while i <= n**0.5:
  if n % i == 0:
    cost.append(i+n/i-2)
  i += 1
if len(cost) == 0:
  cost.append(n-1)
print(int(min(cost)))
Buggy code:
n = int(input())
sqrtN = n**(1/2)
if sqrtN.is_integer():
    Pos = [int(sqrtN), int(sqrtN)]
else:
    for i in range(int(sqrtN), n+1):
        if n%i == 0:
            Pos = [i, n//i]
            break
print(sum(Pos) - 2)

Fixed code:
n = int(input())
sqrtN = n**(1/2)
if sqrtN.is_integer():
    Pos = [int(sqrtN), int(sqrtN)]
#    print(Pos)
else:
    for i in range(int(sqrtN), 0, -1):
#        print(i)
        if n%i == 0:
            Pos = [i, n//i]
#            print(Pos)
            break
print(sum(Pos) - 2)
Buggy code:
import math
input_num = int(input())
num_sqrt = int(math.sqrt(input_num))

minimam = input_num
for i in range(num_sqrt+1,0,-1):
    print(i)
    q, mod = divmod(input_num, i)
    distance = q + i -2
    if mod == 0 and minimam > distance:
        minimam = distance
print(minimam)

Fixed code:
import math
input_num = int(input())
num_sqrt = int(math.sqrt(input_num))+1

minimam = input_num
for i in range(1,num_sqrt+1):
    q, mod = divmod(input_num, i)
    distance = q + i -2
    if mod == 0 and minimam > distance:
        minimam = distance
print(minimam)
Buggy code:
N=int(input())

i=int(N**0.5);

while i>0:
    if N%i==0:
        i,j=(i,N/i)
        break
    i-=1

print(i+j-2)

Fixed code:
N=int(input())

i=int(N**0.5);

while i>0:
    if N%i==0:
        i,j=(i,N/i)
        break
    i-=1

print(int(i+j-2))
Buggy code:
n = int(input())
# divisors = []
move =[]
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
#         divisors.append(i)
        move.append(i+n//i)
        if i != n // i:
            divisors.append(n//i)
        
# divisors.sort()
# print(divisors)
# print(move)
print(min(move)-2)

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

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)
INF = float('inf')


def main():
    N = INT()

    num = [i + 1 for i in range(ceil(sqrt(N)))]

    minimum = INF
    for i in num:
        if N % i == 0:
            temp = i + N//i
            if temp < minimum:
                minimum = temp

    print(minimum - 2)


if __name__ == '__main__':
    main()


Fixed code:
import sys
from math import ceil, sqrt

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)
INF = float('inf')


def main():
    N = INT()

    num = [i + 1 for i in range(ceil(sqrt(N)))]

    minimum = INF
    for i in num:
        if N % i == 0:
            temp = i + N//i
            if temp < minimum:
                minimum = temp

    print(minimum - 2)


if __name__ == '__main__':
    main()
Buggy code:
n = int(input())
ans = []
for i in range(1,int(n**0.5)+1):
    if n % i == 0:
        x = n/i
        ans.append(i + x -2)
print(min(ans))


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


def devide2(x):
    ar = []
    for i in range(1, int(x)):
        if x % i == 0:
            ar.append([i, x // i])
    return ar


kumi = devide2(n)

ans = 10 ** 12 + 1000
for i in range(len(kumi)):
    ans = min(ans, sum(kumi[i]))

print(ans - 2)


Fixed code:
n = int(input())


def devide2(x):
    ar = []
    ar.append([1, x])
    for i in range(2, int(-(-x ** 0.5 // 1)) + 1):
        if x % i == 0:
            ar.append([i, x // i])
    return ar


kumi = devide2(n)
# print(kumi)

ans = 10 ** 12 + 1000
for i in range(len(kumi)):
    ans = min(ans, sum(kumi[i]))

print(ans - 2)
Buggy code:
N = int(input())

ans=N
for i in range(1, int(N**0.5+1)):
    if N%i==0:
        a = N/i
        b = N/a
        up_ans = a + b -2
        print(up_ans)
        ans = min(ans, up_ans)
    else:
        continue
print(int(ans))

Fixed code:
N = int(input())

ans=N
for i in range(1, int(N**0.5+1)):
    if N%i==0:
        a = N/i
        b = N/a
        up_ans = a + b -2
        ans = min(ans, up_ans)
    else:
        continue
print(int(ans))
Buggy code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

inf = float('inf')

m = inf
n = ri()
for i in range(1, n//2):
  a = n//i
  if a*i == n:
    if m > a+i:
      m = a+i
else:
  print(m-2)




Fixed code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

m = float('inf')
n = ri()
for i in range(1, int(n**0.5) + 1):
  a = n//i
  if a*i == n:
    if m > a+i:
      m = a+i
else:
  print(m-2)
Buggy code:
import math
n=int(input())

d=1e12
for i in range(1,int(math.sqrt(n))+1):
    if(n % i == 0):
        m=n/i + i- 2;
        if(m < d):
            d=m
print(d)


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

d=1e12
for i in range(1,int(math.sqrt(n))+1):
    if(n % i == 0):
        m=n/i + i- 2;
        if(m < d):
            d=m
print(int(d))
Buggy code:
import math

n=int(input())
m=int(math.sqrt(n))
for i in reverse(range(1,m+1)):
	if n%i==0:
		print(int(i+n/i-2))
		break

Fixed code:
import math

n=int(input())
m=int(math.sqrt(n))
for i in reversed(range(1,m+1)):
	if n%i==0:
		print(int(i+n/i-2))
		break
Buggy code:
N=int(input())
minn=N-1
for i in range(2,round((N-1)**0.5)):
    if N%(i+1)==0 and minn>N//(i+1)-1+i:
        minn=N//(i+1)-1+i
if minn<=(N-1):
    print(minn)
else:
    print(N-1)

Fixed code:
N=int(input())
minn=N-1
for i in range(2,round((N)**0.5+1)):
    if N%i==0 and minn>N//(i)-2+i:
        minn=N//(i)-2+i
print(minn)
Buggy code:
import math

def make_divisors(n):
  divisors = []
  for i in range(1, int(math.sqrt(n))+1):
    if n % i == 0:
      print(i)
      x = i
      y = n // i
      divisors.append([x, y])

  return divisors

def list_sum(t_list):
  return t_list[0] + t_list[1]

n = int(input())
yakusu = make_divisors(n)

data = list(map(list_sum, yakusu))
print(min(data) - 2)


Fixed code:
import math

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

  return divisors

def list_sum(t_list):
  return t_list[0] + t_list[1]

n = int(input())
yakusu = make_divisors(n)

data = list(map(list_sum, yakusu))
print(min(data) - 2)
Buggy code:
n = int(input())
b = 10**12
a = int(n**0.5)
for i in range(1,a+1):
  if n%i==0:
    b = min(b,i+(n/i)-2)
print(b)

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

b=n
a=[]
N=math.sqrt(n)

for i in range(1,n+1):
  q, mod=divmod(n,i)
  if(mod==0):
   a=q+i
   if(a<b):
     b=a
 
print (b-2)
   


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

b=n
a=[]
N=int(math.sqrt(n))

for i in range(1,N+1):
 q, mod=divmod(n,i)
 a=q+i-2

 if(mod==0 and a<b):
     b=a

print(b)
Buggy code:
N = int(input())
max_int = int(N**0.5)
for v in range(max_int,N+1):
    if N % v == 0:
        w = int(N/v)
        print(v+w-2)
        break
    else:
        pass

Fixed code:
N = int(input())
max_int = int(N**0.5)
for v in reversed(range(max_int+1)):
    if N % v == 0:
        w = int(N/v)
        print(v+w-2)
        break
    else:
        pass
Buggy code:
import math 
 
n = int(input())
m = int(round(math.sqrt(n)))
while True:
    p, q = divmod(n, m)
    if q == 0:
        print(m + p - 2)
        break
    else:
        m += 1


Fixed code:
import math 
 
n = int(input())
m = int(round(math.sqrt(n)))
while m >= 1:
    p, q = divmod(n, m)
    if q == 0:
        print(m + p - 2)
        break
    else:
        m -= 1
Buggy code:
import math
input_num = int(input())
sqrt_num = math.floor(math.sqrt(input_num))

min_count = 1 + input_num
for i in range(sqrt_num + 1, 1, -1):
  if(input_num % i == 0) and (min_count >= input_num//i + i):
    min_count = input_num//i + i
print(min_count)


Fixed code:
import math
input_num = int(input())
sqrt_num = math.floor(math.sqrt(input_num))

min_count = 1 + input_num
for i in range(sqrt_num + 1, 1, -1):
  if(input_num % i == 0) and (min_count > input_num//i + i):
    min_count = input_num//i + i
print(min_count - 2)