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

result = None
for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        j = i + (N // i)
        if result is None or j < result:
            result = j

print(N, result - 2)

Fixed code:
N = int(input())

result = None
for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        j = i + (N // i)
        if result is None or j < result:
            result = j

print(result - 2)
Buggy code:
import math
N=int(input())
p=math.floor(math.sqrt(N))
while N % p > 0:
    p-=1
q=N//p
print(p+q)

Fixed code:
import math
N=int(input())
p=math.floor(math.sqrt(N))
while N % p > 0:
    p-=1
q=N//p
print(p+q-2)
Buggy code:
N=int(input())

ans=1e9
i=1
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())

ans=1e15
i=1
while i*i<=N:
    if (N%i==0):
       ans=min(ans,(i-1)+(N/i-1)) 
    i+=1
print(int(ans))
Buggy code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(int(i+n/i-2))
            if i != n // i:
                divisors.append(n//i)
    return divisors
ans = float("inf")
for i in make_divisors(int(input())):
    ans = min(ans,i)
print(ans)

Fixed code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(int(i+n/i-2))
    return divisors
ans = float("inf")
for i in make_divisors(int(input())):
    
    ans = min(ans,i)
print(ans)
Buggy code:
import math
N=int(input())
m=N+1
for j in range(2,math.sqrt(N)):
    if N%j==0:
        a=j
        b=N//j
        if a>b:
            break
        else:
            m=min(m,(a+b))

print(m-2)


Fixed code:
import math
N=int(input())
m=N+1
for j in range(2,int(math.sqrt(N))+1):
    if N%j==0:
        a=j
        b=N//j
        if a>b:
            break
        else:
            m=min(m,(a+b))

print(m-2)
Buggy code:
N=int(input())
n=round(N**(1/2))
for i in range(1,n+2):
	if N/i==N//i:
		ans=i+N/i-2
print(ans)

Fixed code:
N=int(input())
n=round(N**(1/2))
for i in range(1,n+2):
	if N/i==N//i:
		ans=i+N/i-2
print(int(ans))
Buggy code:
import math as m

n = int(input())
q = int(m.sqrt(n))

for i in range(q,1,-1):
    if n%i == 0:
        k = i
        l = n/i
        break

print(int(k+l-2))



Fixed code:
import math as m

n = int(input())
q = int(m.sqrt(n))

for i in range(q,0,-1):
    if n%i == 0:
        k = i
        l = int(n/i)
        break

print(int(k+l-2))
Buggy code:
import sys
input = sys.stdin.readline


def main():
    sc = Scan()
    n = sc.intarr()[0]
    minimum = n
    for i in range(1, n//2):
        if n % i == 0:
            cost = (n//i) + i-2
            if cost < n:
                minimum = cost
    print(minimum)


class Scan():

    def intarr(self):
        self.line = input()
        array = self.line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        self.line = input()
        array = self.line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()


Fixed code:
import math
import sys
input = sys.stdin.readline


def main():
    sc = Scan()
    n = sc.intarr()[0]
    ns = int(math.sqrt(n)) + 1
    minimum = n
    for i in range(1, ns):
        if n % i == 0:
            cost = (n//i) + i - 2
            if cost < minimum:
                minimum = cost
    print(minimum)


class Scan():

    def intarr(self):
        self.line = input()
        array = self.line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        self.line = input()
        array = self.line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()
Buggy code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    n = int(input())
    for a in range(1,10**6+1):
        if n%a==0:
            b=n//a
        ans=a+b-2
    print(ans)

if __name__=="__main__":
    main()

Fixed code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    n = int(input())
    ans=10**12
    for a in range(1,10**6+1):
        if n%a==0:
            b=n//a
        ans=min(ans,a+b-2)
    print(ans)

if __name__=="__main__":
    main()
Buggy code:
import sys
import math
N = int(input())
for i in range(int(math.sqrt(N)),2,-1):
    if N % i ==0:
        print(N//i+i-2)
        sys.exit()
print(N-1)

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

def dictcheck(dict):
    min = 0
    for k,v in dict.items():
#        print("k:",k ,"+", "v:",v)
        if min == 0:
            min=(int(k)-1)+(int(v)-1)
        elif min > (int(k)-1)+(int(v)-1):
            min = (int(k)-1)+(int(v)-1)
        else:
            continue
    print(min)

def main():
    N = int(input())
    i = 2
    tmpdict= {}
    while i < math.sqrt(N):
        if N % i == 0:
            tmpdata = {i:N/i}
            tmpdict.update(tmpdata)
            i+=1
        else:
            i+=1
    if len(tmpdict)==0:
        tmpdata = {1,N-1}
        tmpdict.update(tmpdata)
#    print(tmpdict)
    dictcheck(tmpdict)

if __name__ == "__main__":
    main()

Fixed code:
import math

def dictcheck(dict):
    min = 0
    for k,v in dict.items():
        if k == 1:
            min = v
            break
        elif min == 0:
            min=(int(k)-1)+(int(v)-1)
        elif min > (int(k)-1)+(int(v)-1):
            min = (int(k)-1)+(int(v)-1)
        else:
            continue
    print(min)

def main():
    N = int(input())
    i = 2
    tmpdict= {}
    while i <= math.sqrt(N):
        if N % i == 0:
            tmpdata = {i:N/i}
            tmpdict.update(tmpdata)
            i+=1
        else:
            i+=1
    if len(tmpdict)==0:
        tmpdata = {1:N-1}
        tmpdict.update(tmpdata)
#    print(tmpdict)
    dictcheck(tmpdict)

if __name__ == "__main__":
    main()
Buggy code:
import sys
import math
n = int(input())
tmp = 10**12

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

Fixed code:
import sys
import math
n = int(input())
tmp = 10**12

for i in range(int(math.sqrt(n))+1, 0, -1):
    if n % i != 0:
        continue
    else:
        if tmp > (n//i)+(i)-2:
            tmp = (n//i)+i-2
print(tmp)
Buggy code:
n=int(input())
p=1
for i in range(2,int(n**0.5)+1):
  if n%i==0:
    p=i
print(p+n/p-2)

Fixed code:
n=int(input())
p=1
for i in range(2,int(n**0.5)+1):
  if n%i==0:
    p=i
print(p+n//p-2)
Buggy code:
N=int(input())
a=10**12
for i in range(1,int(N**.5)+1):
    if N%i==0:
        a=min(a,N//n+n-2)
print(min(N,a))

Fixed code:
N=int(input())
a=10**12
for i in range(1,int(N**.5)+1):
    if N%i==0:
        a=min(a,N//i+i-2)
print(min(N,a))
Buggy code:
n=int(input())
r=100000000000000000000000000000
for i in range(1,int(pow(n,0.5))+1):
  if(n%i==0):
    r=min(r,abs(i-1)+abs(n//i-1))
print(r(


Fixed code:
n=int(input())
r=100000000000000000000000000000
for i in range(1,int(pow(n,0.5))+1):
  if(n%i==0):
    r=min(r,abs(i-1)+abs(n//i-1))
print(r)
Buggy code:
from operator import itemgetter
n = int(input())

list_p = []
for i in range(1, n):

    j = n / i

    if j.is_integer():
        list_p.append([i, j, i+j])
list_sorted = sorted(list_p, key=itemgetter(2))
print(int(list_sorted[0][0] + list_sorted[0][1] - 2))

Fixed code:
from operator import itemgetter
n = int(input())

list_p = []
for i in range(1, int(n**0.5)+1):

    j = n / i

    if j.is_integer():
        list_p.append([i, j, i+j])

list_sorted = sorted(list_p, key=itemgetter(2))
print(int(list_sorted[0][0] + list_sorted[0][1] - 2))
Buggy code:
import math
n = int(input())

for i in range(int(math.sqrt(n)), 0, -1):
  if n % i:
    next
  else:
    print(i+n//i-2)
    break
print(len(range(int(math.sqrt(n)), n+1)))

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

for i in range(int(math.sqrt(n)), 0, -1):
  if n % i:
    next
  else:
    print(i+n//i-2)
    break
Buggy code:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())

    ret = float('inf')
    for i in range(1, 100000000):
        q, mod = divmod(N, i)
        if mod == 0:
            j = N // i
            ret = min(ret, ((j-1)+(i-1)))

    print(ret)


if __name__ == '__main__':
    main()

Fixed code:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())

    ret = float('inf')
    for i in range(1, 10000000):
        q, mod = divmod(N, i)
        if mod == 0:
            j = N // i
            ret = min(ret, ((j-1)+(i-1)))

    print(ret)


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

l1 = []
for i in range(n // 2):
  q, mod = divmod(n , i + 1)
  if mod == 0:
    l1.append(q + i -1)
print(min(l1))

Fixed code:
n = int(input())
 
l1 = []
for i in range(1, int(n ** 0.5) + 1):
  q, mod = divmod(n , i)
  if mod == 0:
    l1.append(q + i -2)
print(min(l1))
Buggy code:
N=int(input())
K=list()

for i in range(1,int(N**0.5)+1):
  if(N/i in list(range(1,N+1))):
    M=int(N/i)  #N<=M
    L=i
    K.append(M+L-2)
    
print(min(K))

Fixed code:
N=int(input())
K=list()

for i in range(1,int(N**0.5)+1):
  if(int(N/i)==N/i):
    M=int(N/i)  #N<=M
    L=i
    K.append(M+L-2)
    
print(min(K))
Buggy code:
n = int(input())

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

Fixed code:
n = int(input())

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

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

Fixed code:
n=int(input())
ans=n-1
for i in range(2,int(n**(1/2))+1):
	if n%i==0:
		ans=min(ans,i+n//i-2)
print(ans)
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)
    return divisors
X=make_divisors(N)
m=N
for i in range(len(X)//2):
    if X[2*i]+X[2*i+1] < m:
        m=X[2*i]+X[2*i+1]
if len(X)%2==1:
    if 2*X[-1]<m:
        m=2*X[-1]
print(m-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)
            if i != n // i:
                divisors.append(n//i)
    return divisors
X=make_divisors(N)
m=N
for i in range(len(X)//2):
    if X[2*i]+X[2*i+1]-2 < m:
        m=X[2*i]+X[2*i+1]-2
if len(X)%2==1:
    if 2*X[-1]-2<m:
        m=2*X[-1]-2
print(m)
Buggy code:
import math
N = int(input())

a = math.ceil(math.sqrt(N))

yaku = {1,N}

for i in range(2,a+1):
  if N % i == 0:
    yaku.add(i)
    yaku.add(N // i)

sl = len(yaku)
lyaku =list(yaku)
if sl % 2 == 1:
  print((lyaku[sl//2]-1)*2)
else:
  print(lyaku[sl//2]+lyaku[sl//2-1] -2)






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

a = math.ceil(math.sqrt(N))

yaku = {1,N}

for i in range(2,a+1):
  if N % i == 0:
    yaku.add(i)
    yaku.add(N // i)

sl = len(yaku)
lyaku =list(yaku)
lyaku.sort()
if sl % 2 == 1:
  print((lyaku[sl//2]-1)*2)
else:
  print(lyaku[sl//2]+lyaku[sl//2-1] -2)
Buggy code:
import math

n = int(input())

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

Fixed code:
import math

n = int(input())

m = n-1
for k in range(2, int(math.sqrt(n)) + 1):
  if n % k == 0:
    m = k + n//k - 2
    
print(m)
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())

d=make_divisors(n)


count=0
ans=[]
for i in d:
    pair=n/i
    count=(pair-1)+(i-1)
    ans.append(count)

print(min(ans))


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())

d=make_divisors(n)


count=0
ans=[]
for i in d:
    pair=n//i
    count=(pair-1)+(i-1)
    ans.append(count)

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

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

Fixed code:
n = int(input())
ans = n-1

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


def main():
    n = int(input())
    divs = make_divisors(n)
    res = divs[0]

    print(res - 2)


if __name__ == '__main__':
    main()

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


def main():
    n = int(input())
    divs = make_divisors(n)
    res = divs[0]
    print(res - 2)


if __name__ == '__main__':
    main()
Buggy code:
=int(input())
count=1
ans=10000000000000
k=c
for i in range(1,int(c**(1/2)+100000)):
    if c%i==0:
        count*=i
        k=int(k/i)
        if ans>count+k:
            ans=count+k
            count=0
            k=c
        else:
            count=0
            k=c
print(ans-2)


Fixed code:
c=int(input())
count=1
ans=10000000000000
k=c
for i in range(1,int(c**(1/2)+100000)):
    if c%i==0:
        if ans>i+int(c/i):
            ans=i+int(c/i)
        else:
            continue
print(ans-2)
Buggy code:
from math import sprt

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

Fixed code:
from math import sqrt

n=int(input())
for i in range(int(sqrt(n)),1,-1):
  if n%i==0:
    print(i-1 + n//i-1)
    break
else:
  print(n-1)
Buggy code:
import math
n=int(input())
p=math.sqrt(n)
def x(g):
  a=g
  c=0
  while a>=0:
    a-=1
    c+=1
  return c-1

m=x(p)
for i in range(m):
  if n%(m-i)==0:
    print(m-i+(n//(m-i)))
    break



Fixed code:
import math
n=int(input())
p=math.sqrt(n)
def x(g):
  a=g
  c=0
  while a>=0:
    a-=1
    c+=1
  return c-1

m=x(p)
for i in range(m):
  if n%(m-i)==0:
    print(m-2-i+(n//(m-i)))
    break
Buggy code:
N = int(input())
import math
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
if is_prime(N):
  print(N-1)
else:
  a = np.floor(math.sqrt(N))
  while True:
    if N%a==0:
      break
      a=a-1
      b=N/a
      print(int(a+b-2))

Fixed code:
N = int(input())
import math
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
if is_prime(N):
  print(N-1)
else:
  a = math.floor(math.sqrt(N))
  while True:
    if N%a==0:
      break
    a=a-1
  print(int(a+N/a-2))
Buggy code:
n = int(input())
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()
print(divisors)
if len(divisors) % 2 == 1:
    print(2 * divisors[len(divisors) // 2] -2)
else:
    print(divisors[len(divisors) // 2] + divisors[len(divisors) // 2 - 1] - 2)

Fixed code:
n = int(input())
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()
if len(divisors) % 2 == 1:
    print(2 * divisors[len(divisors) // 2] -2)
else:
    print(divisors[len(divisors) // 2] + divisors[len(divisors) // 2 - 1] - 2)
Buggy code:
# -*- coding: utf-8 -*-
import math
a = int(input())
b = round(math.sqrt(a))
while a % b != 0:
    print(a,b)
    b+=1
c = int(a / b)
print(b+c-2)

Fixed code:
# -*- coding: utf-8 -*-
import math
a = int(input())
b = round(math.sqrt(a))
while a % b != 0:
    b -= 1
c = int(a / b)
print(b + c - 2)
Buggy code:
N = int(input())
import math 
yakusuu_list = []
for i in range (int(math.sqrt(N)),0,-1):
  if N % i == 0:
    yakusuu = i
    break
print(i+ N/i -2)
  

Fixed code:
N = int(input())
import math 
yakusuu_list = []
for i in range (int(math.sqrt(N)),0,-1):
  if N % i == 0:
    yakusuu = i
    break
print(i+ N//i -2)
Buggy code:
import math
N = int(input())
ans = 10000000020
for i in range(1,int(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 = 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:
from math import sqrt
from math import floor
n = int(input())
for i in range(2, floor(sqrt(n)) + 1):
    if n % i == 0:
        min_div = i
        break
else:
    min_div = n
ans = min_div + int(n / min_div) - 2
print(ans)


Fixed code:
from math import sqrt
from math import floor
n = int(input())
for i in range(floor(sqrt(n)), 1, -1):
    if n % i == 0:
        min_div = i
        break
else:
    min_div = n
ans = min_div + int(n / min_div) - 2
print(ans)
Buggy code:
N = int(input())

i = 1
answer = N - 1
while i * i <= N:
    if N % i == 0:
        new_answer = (i - 1) + ((N / i) - 1)
        if answer > new_answer:
            answer = new_answer
    i += 1

print(answer)

Fixed code:
N = int(input())

i = 1
answer = N - 1
while i * i <= N:
    if N % i == 0:
        new_answer = (i - 1) + ((N / i) - 1)
        if answer > new_answer:
            answer = new_answer
    i += 1

print(int(answer))
Buggy code:
n=int(input())
ans=10**15
for i in range(1,int(n**0.5)+2):
  if n%i!=0:continue
  check=(n//i)+i-2
  if ans>check-2:
    ans=check-2
print(ans)

Fixed code:
n=int(input())
ans=10**15
for i in range(1,int(n**0.5)+2):
  if n%i!=0:continue
  check=(n//i)+i
  if ans>check-2:
    ans=check-2
print(ans)
Buggy code:
N = int(input())
x = int(N**0.5)
ans_1 = N

for i in range(N):
    if N % x == 0:
        ans_1 = x
        break
    else:
        x += 1

ans_2 = N//ans_1
print(ans_1 + ans_2 - 2)


Fixed code:
N = int(input())
x = int(N**0.5)+1
ans_1 = N

for i in range(x):
    if N % x == 0:
        ans_1 = x
        break
    else:
        x -= 1

ans_2 = N//ans_1
print(ans_1 + ans_2 - 2)
Buggy code:
a = int(input())
b = 0
count = 0
for i in range(a):
    i = i+1
    if a%i == 0:
        j = a//i
    if i*j == a:
        if count == 0:
            count += 1
            c = i
            d = j
        if count>0:
            if (c+d)>(i+j):
                c = i
                d = j
ans = c+d-2
print(ans)

Fixed code:
a = int(input())
b = 0
l = int(a**0.5)+1
count = 0
for i in range(l):
    i = i+1
    if a%i == 0:
        j = a//i
    if i*j == a:
        if count == 0:
            count += 1
            c = i
            d = j
        if count>0:
            if (c+d)>(i+j):
                c = i
                d = j
ans = c+d-2
print(ans)
Buggy code:
N = int(input())
i = 1
ans = 10 ** 10
while (i ** 2 <= N):
  if (N % i == 0):
    ans = min(ans, N // i + i - 2)
  i += 1

print(ans)

Fixed code:
N = int(input())
i = 1
ans = N
while (i ** 2 <= N):
  if (N % i == 0):
    ans = min(ans, N // i + i - 2)
  i += 1

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

    
print(ans)
        


Fixed code:
import math
N = int(input())
ans = N-1
n = math.sqrt(N)
n = int(n)+1
for i in range(1, n):
    if N%i==0:
        tmp = N//i
        ans = (tmp-1)+(i-1)

    
print(ans)
Buggy code:
n = int(input())
ans = 10**13
for i in range(int(n**0.5)+1, 1, -1):
    if n%i==0:
        m = n//i
        ans = min(ans, m+i-2)
        # print(i,m)
        break
print(ans)

Fixed code:
n = int(input())
ans = 10**13
for i in range(int(n**0.5)+1, 0, -1):
    if n%i==0:
        m = n//i
        ans = min(ans, m+i-2)
        # print(i,m)
        break
print(ans)
Buggy code:
import math
n = int(input())
nrt = int(math.sqrt(n))
for i in range(nrt):
    j = nrt-i
    if n % j == 0:
        s = n // j
        ans = j+s-2
print(ans)

Fixed code:
import math
n = int(input())
nrt = int(math.sqrt(n))
for i in range(nrt):
    j = nrt-i
    if n % j == 0:
        s = n // j
        ans = j+s-2
        break
print(ans)
Buggy code:
import math

def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


n = int(input())
divisors_list = make_divisors(n)
ans = []
n_sqrt = math.sqrt(n)
print(divisors_list)
if n_sqrt == int(n_sqrt):
    for i in range(len(divisors_list) // 2 + 1):
        move = divisors_list[i] + divisors_list[-1 - i] - 2
        ans.append(move)
else:
    for i in range(len(divisors_list) // 2):
        move = divisors_list[i] + divisors_list[-1 - i] - 2
        ans.append(move)
print(min(ans))


Fixed code:
import math

def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


n = int(input())
divisors_list = make_divisors(n)
ans = []
n_sqrt = math.sqrt(n)
if n_sqrt == int(n_sqrt):
    for i in range(len(divisors_list) // 2 + 1):
        move = divisors_list[i] + divisors_list[-1 - i] - 2
        ans.append(move)
else:
    for i in range(len(divisors_list) // 2):
        move = divisors_list[i] + divisors_list[-1 - i] - 2
        ans.append(move)
print(min(ans))
Buggy code:
from math import sqrt, floor

def solve(n):
    m = floor(sqrt(n)) + 1
    for i in range(m + 1, 1, -1):
        if n % i == 0:
            return i + n // i - 2

_n = int(input())
print(solve(_n))

Fixed code:
from math import sqrt, floor

def solve(n):
    m = floor(sqrt(n)) + 1
    for i in range(m + 1, 0, -1):
        if n % i == 0:
            return i + n // i - 2

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

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

a=1
b=N//a
dis=abs(a-b)

for i in range(int(N**0.5)+1):
    if N%i==0:
        _a=i
        _b=N/i
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis

print(a-1+b-1)

Fixed code:
N=int(input())

a=1
b=N//a
dis=abs(b-a)

for i in range(1,int(N**0.5)+1):
    if N%i==0:
        _a=i
        _b=N//i
        _dis=abs(_b-_a)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis

print(a-1+b-1)
Buggy code:
import math
N=int(input())
rN=math.ceil(math.sqrt(N))
for i in range(rN,0,-1):
  if N//i == math.floor(N/i):
    print(i+(N//i)-2)


Fixed code:
import math
N=int(input())
rN=math.ceil(math.sqrt(N))
for i in range(rN,0,-1):
  if N//i == N/i:
    print(i+(N//i)-2)
    exit()