qyliang/CodeNanoFix huggingface dataset:
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((n//i, i))
            if i != n // i:
                divisors.append((n//i, i))
    return set(divisors)


pairs = list(make_divisors(n))
min_pair = n-1
for p in pairs[1:]:
    result = p[0] + p[1] -2
    if result < min_pair:
        min_pair = result

print(min_pair)

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


pairs = list(make_divisors(n))
min_pair = n-1

for p in pairs:
    result = p[0] + p[1] -2
    if result < min_pair:
        min_pair = result

print(min_pair)
Buggy code:
import math

def f(n):
    divisor = [1]
    limit = math.ceil(math.sqrt(n))
    for n2 in range(2, limit+1):
        if n % n2 == 0:
            divisor.append(n2)
    n1 = max(divisor)
    n2 = n // n1
    return n1 + n2 - 2

n = int(input())
f(n)


Fixed code:
import math

def f(n):
    divisor = [1]
    limit = math.ceil(math.sqrt(n))
    for n2 in range(2, limit+1):
        if n % n2 == 0:
            divisor.append(n2)
    n1 = max(divisor)
    n2 = n // n1
    print(n1 + n2 - 2)

n = int(input())
f(n)
Buggy code:
import math
N = int(input())
i = 1
min = 9000000000000
for _ in range(1, int(math.sqrt(N)+1)):
  if N % i == 0:
    j = N/i
    sum = j + i
    if sum < min:
      min = sum
      ans = i-1+j-1
    else:
      break
  i += 1
print(ans)

Fixed code:
import math
N = int(input())
i = 1
min = 9000000000000
for _ in range(1, int(math.sqrt(N)+1)):
  if N % i == 0:
    j = N/i
    sum = j + i
    if sum < min:
      min = sum
      ans = i-1+j-1
    else:
      break
  i += 1
print(int(ans))
Buggy code:
N = int(input())

ans = 1

for i in range(1,int(N**0.5)+1):
    if N % i == 0:
        ans = i

print(ans+(N/ans)-2)

Fixed code:
N = int(input())

ans = 1

for i in range(1,int(N**0.5)+1):
    if N % i == 0:
        ans = i

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

print(ans)

Fixed code:
N = int(input())

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

print(ans)
Buggy code:
n=int(input())
mx=10**15
for i in range(1,n//2+1):
    if n%i==0 and n//i+i-2<mx:
        mx=n//i+i-2
print(mx)


Fixed code:
n=int(input())
mx=10**15
for i in range(1,int(n**.5+1)):
    if n%i==0 and n//i+i-2<mx:
        mx=n//i+i-2
print(mx)
Buggy code:
import math
n=int(input())
temp=n+1
for i in range(int(math.sqrt(n)),0,-1):
  if n%i==0:
    print(i,n//i,i+n//i-2)
    exit()

Fixed code:
import math
n=int(input())
temp=n+1
for i in range(int(math.sqrt(n)),0,-1):
  if n%i==0:
    print(i+n//i-2)
    exit()
Buggy code:
N = int(input())
a = 0
s = 0
ans = 10000000000000000
for x in range(1,N):
    s=N//x
    if N%x==0:
        a = (x-1)+(s-1)
        if ans > a:
            ans = a
print(ans)


Fixed code:
N = int(input())
a = 0
ans = N-1
s = 0
for x in range(1,1000001):
    s=N//x
    if N%x==0:
        a = (s-1)+(x-1)
        if ans>a:
             ans = a
print(ans)
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)
            
aaa = 0
bbb = 10**12+1
j = 0

for i in range(1,len(divisors)//2+1):
    aaa = divisors[j]+divisors[j+1]-2
    print(aaa)
    if aaa < bbb:
        bbb = aaa
    j += 2
    
print(bbb)

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.append(divisors[-1])

aaa = 0
bbb = 10**12+1
j = 0

for i in range(1,len(divisors)//2+1):
    aaa = divisors[j]+divisors[j+1]-2
    if aaa < bbb:
        bbb = aaa
    j += 2
    
print(bbb)
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

num = int(input())
yakusu_list = make_divisors(num)
nine = [1,2,3,4,5,6,7,8,9]
yakusu_pair_list = []
a = 0
b = 0
for i, yakusu in enumerate(yakusu_list):
    
    if i == len(yakusu_list):
        if yakusu == yakusu_list[-1]:
            yakusu_pair_list.append([yakusu, yakusu])
    
    else:
        if i % 2 == 0:
            a = yakusu
        else:
            b = yakusu
            yakusu_pair_list.append([a, b])
best_pair = yakusu_pair_list[0]
print(yakusu_pair_list)
best_move_num = best_pair[0] + best_pair[1] -2
for yakusu_pair in yakusu_pair_list:
    this_move_num = yakusu_pair[0] + yakusu_pair[1] -2
    if this_move_num < best_move_num:
        best_pair = yakusu_pair    
        best_move_num = this_move_num
print(best_move_num)

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

num = int(input())
yakusu_list = make_divisors(num)
nine = [1,2,3,4,5,6,7,8,9]
yakusu_pair_list = []
a = 0
b = 0
for i, yakusu in enumerate(yakusu_list):
    
    if len(yakusu_list) % 2 == 0:
        if i % 2 == 0:
            a = yakusu
        else:
            b = yakusu
            yakusu_pair_list.append([a, b])
    else:

        if i == len(yakusu_list) -1:
            yakusu_pair_list.append([yakusu, yakusu])
    
        else:
            if i % 2 == 0:
                a = yakusu
            else:
                b = yakusu
                yakusu_pair_list.append([a, b])
best_pair = yakusu_pair_list[0]
best_move_num = best_pair[0] + best_pair[1] -2
for yakusu_pair in yakusu_pair_list:
    this_move_num = yakusu_pair[0] + yakusu_pair[1] -2
    if this_move_num < best_move_num:
        best_pair = yakusu_pair    
        best_move_num = this_move_num
print(best_move_num)
Buggy code:
import array
import sys
from collections import deque
import math

def input():
    return sys.stdin.readline().rstrip('\n')

N = int(input())
#S = deque(list(input()))

for i in reversed(range(1,int(math.sqrt(N))+1)):
    if N % i == 0:
        j = N // i
        print(i,j,i+j-2)
        sys.exit()


Fixed code:
import array
import sys
from collections import deque
import math

def input():
    return sys.stdin.readline().rstrip('\n')

N = int(input())
#S = deque(list(input()))

for i in reversed(range(1,int(math.sqrt(N))+1)):
    if N % i == 0:
        j = N // i
        print(i+j-2)
        sys.exit()
Buggy code:
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys
import itertools

# import math

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10 ** 9

N = int(readline())
temp = INF
a = 0
b = 0
for i in range(1, (N - 1) // 2 + 1):
    if N % i == 0:
        if temp >= abs(i - N // i):
            temp = abs(i - N // i)
            a = i
            b = N // i
print(a+b-2)

Fixed code:
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys
import itertools

# import math

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10 ** 13

N = int(readline())
temp = INF
a = 0
b = 0
for i in range(1, int(N**.5)+1):
    if N % i == 0:
        if temp >= abs(i - N // i):
            temp = abs(i - N // i)
            a = i
            b = N // i
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
  
N = int(input())
Nlist = make_divisions(N)
L = len(Nlist)
if L%2==0:
    print(Nlist[int(L/2)]+Nlist[int(L/2)-1]-2)
else:
    print(int(math.sqrt(N)*2-2)

Fixed code:
import math
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())
Nlist = make_divisors(N)
L = len(Nlist)
if L%2==0:
    print(Nlist[int(L/2)]+Nlist[int(L/2)-1]-2)
else:
    print(int(math.sqrt(N)*2-2))
Buggy code:
n = int(input())

ans = 1000000000000

a = 1
while a * a <= n:
	if n % a != 0:
      continue
    b = n % a
    ans = min(ans, a + b - 2)
    a += 1

print(ans)

Fixed code:
n = int(input())

ans = 1000000000000

a = 1
while a * a <= n:
  if n % a != 0:
    a += 1
    continue
  b = n // a
  ans = min(ans, a + b - 2)
  a += 1

print(ans)
Buggy code:
n=int(input())
l=2
for i in range(2,int(n**0.5)):
	if n%i==0:
		l=i
k=n//l
print(l+k-2)

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

Fixed code:
import math
n = int(input())
l = []
for i in range(1, int(math.sqrt(n)) + 1):
  if n % i == 0:
    a = i
    b = n // i
    l.append(a + b - 2)
print(min(l))
Buggy code:
import math
N=int(input())
x=[]
min=10000000
ans=0
sqN=math.ceil(math.sqrt(N))
for i in range(1,sqN+1):
  if N%i==0:
    j=int(N/i)
    a=[i,j]
    x.append(a)
for i,j in x:
  if i+j<=min:
    ans=i+j-2
    min=i+j
print(ans)

Fixed code:
import math
N=int(input())
x=[]
min=10000000000000000
ans=0
sqN=math.ceil(math.sqrt(N))
for i in range(1,sqN+1):
  if N%i==0:
    j=int(N/i)
    a=[i,j]
    x.append(a)
for i,j in x:
  if i+j<=min:
    ans=i+j-2
    min=i+j
print(ans)
Buggy code:
N = int(input())
N_sqrt = int(N**(1/2))
for i in range(1,N_sqrt):
    if N%i == 0:
        num = i
ans = num+N/num-2
print(ans)


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

Fixed code:
N=int(input())
import math
ans=int(math.sqrt(N))
for i in range(ans,0,-1):
    if N%i==0:
        print(i+N//i-2)
        break
Buggy code:
#ABC-144-C
N = int(input())
root_N = N ** 0.5
ans = 10 ** 9

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

print(int(ans))

Fixed code:
#ABC-144-C
N = int(input())
root_N = N ** 0.5
ans = 10 ** 13

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

print(int(ans))
Buggy code:
import itertools
n = int(input())

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]

div_list = make_divisors(n)
print(div_list)

mn =2**50
for i in div_list:
    mn = min(mn,i+n//i)

print(mn-2)

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

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]

div_list = make_divisors(n)
#print(div_list)

mn =2**50
for i in div_list:
    mn = min(mn,i+n//i)

print(mn-2)
Buggy code:
import numpy as np

def isPrime(n):
  s = int(np.sqrt(n))
  for i in range(2, s+1):
    if n % i == 0:
      return False
  return True

def sum_devisor(n):
  s = int(np.sqrt(n))
  while(n % s != 0):
    s -= 1
  return s + n/s

n = int(input())
if isPrime(n) == True:
  print(n-1)
else:
  print(sum_devisor(n)-2)
  

Fixed code:
import numpy as np

def isPrime(n):
  s = int(np.sqrt(n))
  for i in range(2, s+1):
    if n % i == 0:
      return False
  return True

def sum_devisor(n):
  s = int(np.sqrt(n))
  while(n % s != 0):
    s -= 1
  return s + n/s

n = int(input())
if isPrime(n) == True:
  print(n-1)
else:
  print(int(sum_devisor(n)-2))
Buggy code:
N=int(input())
print([sum([i-1,round(N/i)-1]) for i in range(1,int(N**0.5)+1) if N%i==0])


Fixed code:
N=int(input())
print(min([sum([i-1,round(N/i)-1]) for i in range(1,int(N**0.5)+1) if N%i==0]))
Buggy code:
N = int(input())

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

print(int(min(answer_list)) - 2)

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

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

print(int(min(answer_list)) - 2)
Buggy code:
n = int(input())

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

q = n//p

print(p+q-2)

Fixed code:
n = int(input())

for i in range(1, int(n**.5)+1):
  if n%i == 0:
    p = i

q = n//p

print(p+q-2)
Buggy code:
n=int(input())
ans=n
i=1
while(i<math.sqrt(n)):
    if n%i==0:
        d=i+n/i-2
        ans=min(ans,d)
    i+=1
print(int(ans))

Fixed code:
import math
n=int(input())
ans=n
i=1
while(i<=math.sqrt(n)):
    if n%i==0:
        d=i+n/i-2
        ans=min(ans,d)
    i+=1
print(int(ans))
Buggy code:
inport sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())

U = 10**6 + 100

div = np.arange(1, U, dtype=np.int64)
div = div[N%div==0]

div = np.union1d(div, N//div)

answer = (div + (N//div)).min() - 2
print(answer)

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

import numpy as np

N = int(readline())

U = 10**6 + 100

div = np.arange(1, U, dtype=np.int64)
div = div[N%div==0]

div = np.union1d(div, N//div)

answer = (div + (N//div)).min() - 2
print(answer)
Buggy code:
n = int(input())

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


Fixed code:
n = int(input())

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

Fixed code:
N=int(input())
for i in reversed(range(int(N**0.5)+1)):
    if N % i == 0:
        print(int(i+N//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())

div = make_divisors(n)
print(div)
if len(div)%2 == 0:
    print(div[len(div)//2 - 1]+div[(len(div)//2)]-2)
else:
    print(div[(len(div)//2)]*2-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())

div = make_divisors(n)
if len(div)%2 == 0:
    print(div[len(div)//2 - 1]+div[(len(div)//2)]-2)
else:
    print(div[(len(div)//2)]*2-2)
Buggy code:
import math
N=10000000019
han=999999999999999999999999999999999999999999
b=0



for a in range(1,int(math.sqrt(N))+1):
    if N%a==0:
        A=N/a
        if A>a:
            gou=A-a
        else:
            gou=a-A
        b=a
        if gou<han:
            han=gou
            kot=A+a
if b==A:
    print(int(kot)-1)
else:
    print(int(kot)-2)


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

han=999999999999999999999999999999999999999999
b=0



for a in range(1,int(math.sqrt(N))+1):
    if N%a==0:
        A=N/a
        if A>a:
            gou=A-a
        else:
            gou=a-A
        b=a
        if gou<han:
            han=gou
            kot=A+a

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

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


def main():
    a = int(input())
    for i in range(int(math.sqrt(a)) + 1, 0, -1):
        if(a % i == 0):
            print(i + (a / i) - 2)
            return


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


Fixed code:
import math


def main():
    a = int(input())
    for i in range(int(math.sqrt(a)) + 1, 0, -1):
        if(a % i == 0):
            print(int(i + (a / i) - 2))
            return


if(__name__ == "__main__"):
    main()
Buggy code:
import math
n = int(input())
m = n
for i in range(1,int(math.sqrt(n))):
  if n%i==0:
    m = min(m,i+n//i)
print(n)

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


n = int(input())

cost = sys.maxsize
tmp = 0
k = int(n/2)
for i in range(1,k):
    q, mod = divmod(n,i)
    if(mod==0):
        tmp = i + int(q) - 2
        cost = min(tmp,cost)
        tmp = 0

print(cost)


Fixed code:
import sys
import math

n = int(input())

cost = sys.maxsize
tmp = 0
k = math.sqrt(n)
for i in range(1,int(k)+1):
    q, mod = divmod(n,i)
    if(mod==0):
        tmp = i + int(q) - 2
        cost = min(tmp,cost)
        tmp = 0

print(cost)
Buggy code:
import math
import sys

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

for i in range(round(math.sqrt(N))):
  j = i + 1
  if N % j == 0:
    if a > j + N / j:
      a = j + N / j
print(a - 2)

Fixed code:
import math

N = int(input())
a = N + 1
b = round(math.sqrt(N))

for i in range(b):
  j = i + 1
  if N % j == 0:
    if a > j + N / j:
      a = j + N / j
print(round(a) - 2)
Buggy code:
import math
n = int(input())
a = [1,1]
ans = 100000000
for i in range(int(math.sqrt(n))):
    a[0] += 1
    if(n%a[0] == 0):
        ans =min(ans,a[0] + int(n/a[0])-2)
    

a[1] = int(n/a[0])

print(ans)




Fixed code:
import math
n = int(input())
a = [1,1]
ans = 100000000000000
for i in range(int(math.sqrt(n))):
    
    if(n%a[0] == 0):
        ans =min(ans,a[0] + int(n/a[0])-2)
    a[0] += 1

a[1] = int(n/a[0])

print(ans)
Buggy code:
from numpy import sqrt
n = int(input())
q = int(sqrt(n)) + 1
for i in reversed(range(1,q)):
    if n%i == 0:
        print(n//i, i)
        print(n//i + i - 2)
        break


Fixed code:
from numpy import sqrt
n = int(input())
q = int(sqrt(n)) + 1
for i in reversed(range(1,q)):
    if n%i == 0:
        print(n//i + i - 2)
        break
Buggy code:
N = int(input())

for i in range(math.floor(N**0.5),0,-1):
    if N % i == 0:
        x,y = i, N//i
        break
print(x+y-2)

Fixed code:
import math

N = int(input())
for i in range(math.floor(N**0.5),0,-1):
    if N % i == 0:
        x,y = i, N//i
        break
print(x+y-2)
Buggy code:
import numpy as np

def solve():
    N = int(input())
    
    r = 1e12
    for i in range(N - 1, int(np.sqrt(N)) - 1, -1):
        if N % i == 0:
            r = min(r, (N / i - 1) + (i - 1))
            
    
    print(int(r))

solve()

Fixed code:
import numpy as np

def solve():
    N = int(input())
    
    r = 1e12
    for i in range(1, int(np.sqrt(N)) + 1):
        if N % i == 0:
            r = min(r, (N / i - 1) + (i - 1))
            
    
    print(int(r))

solve()
Buggy code:
n = int(input())

import math
max = math.trunc(n**0.5)
for i in range(max:0:-1):
  if n % i == 0:
    j = n / i
    print(i+j-2)
  

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

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


# def factorization(n):
#     factor = []
#     tmp = int(math.sqrt(n)) + 1
#     for i in range(2, tmp):
#         while n % i == 0:
#             n //= i
#             factor.append(i)
#         if len(factor) != 0:
#             factor.append(n)
#             return factor
#     return []


def solve(inputs):
    N = int(inputs[0])
    # factors = factorization(N)
    min_diff = None
    for i in range(1, 1000000):
        if N % i == 0:
            a = N // i
            diff = a + i - 2
            print(a, i, diff)
            if min_diff is None or min_diff > diff:
                min_diff = diff
    return min_diff


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Fixed code:
import sys
import math

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


# def factorization(n):
#     factor = []
#     tmp = int(math.sqrt(n)) + 1
#     for i in range(2, tmp):
#         while n % i == 0:
#             n //= i
#             factor.append(i)
#         if len(factor) != 0:
#             factor.append(n)
#             return factor
#     return []


def solve(inputs):
    N = int(inputs[0])
    # factors = factorization(N)
    min_diff = None
    for i in range(1, 1000001):
        if N % i == 0:
            a = N // i
            diff = a + i - 2
            if min_diff is None or min_diff > diff:
                min_diff = diff
    return min_diff


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)
Buggy code:
n=int(input())

div = 1
result = 10**12

for i in range(1,int(n**0.5//1)+1):
  if n % i == 0:
    div = div // i
    result = min(result, i+div)

print(int(result-2))


Fixed code:
n=int(input())

result = 10**12
for i in range(1,int(n**0.5)+1):
  if n % i == 0:
    result = min(result, i + n//i)

print(int(result-2))
Buggy code:
n=int(input())

div = n
result = 10**12

for i in range(1,n):
  if n % i == 0:
    result = min(result, i+div)
    div = div // i

print(int(result-2))

Fixed code:
n=int(input())

div = n
result = 10**12

for i in range(1,1000001):
  if n % i == 0:
    div = n // i
    result = min(result, i+div)

print(int(result-2))
Buggy code:
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())
div=make_divisors(N)

from math import sqrt

tmpmin=10*10
for i in range(len(div)):
  if tmpmin>abs(sqrt(N)-div[i]):
    tmpmin=abs(sqrt(N)-div[i])
    minidx=i

a=div[i]
b=N//a

print(a-1+b-1)


Fixed code:
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())
div=make_divisors(N)

from math import sqrt

tmpmin=10**16
for i in range(len(div)):
  if tmpmin>abs(sqrt(N)-div[i]):
    tmpmin=abs(sqrt(N)-div[i])
    minidx=i

a=div[minidx]
b=N//a

print(a-1+b-1)
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

from math import sqrt
N = int(input())
a = make_divisors(N)
print(a)

l = len(a)
if (l%2 == 0):
    print(a[-1] + a[-2] - 2)
else:
    print(a[-1]*2 - 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

from math import sqrt
N = int(input())
a = make_divisors(N)

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