qyliang/CodeNanoFix huggingface dataset:
Buggy code:
for i in range(int(N**0.5), 0, -1):
    if N % i == 0:
        x = i
        y = N // i
        break
print(x+y-2)

Fixed code:
N = int(input())

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

for i in range(1, 10**8+1):
    q, m = divmod(n, i)
    if m == 0:
        ans = min(ans, q+i)

print(ans-2)


Fixed code:
n = int(input())
ans = float('inf')

for i in range(1, 10**6+1):
    q, m = divmod(n, i)
    if m == 0:
        ans = min(ans, q+i)

print(ans-2)
Buggy code:
import math

def test():
    n = int(input())
    ans = float("inf")
    for i in range(2,int(math.sqrt(n)+1)):
        if n % i == 0:
            ans = min(i+(n//i)-2,ans)
    print(ans)


if __name__ == "__main__":
    test()


Fixed code:
import math

def test():
    n = int(input())
    ans = float("inf")
    for i in range(1,int(math.sqrt(n)+1)):
        if n % i == 0:
            ans = min(i+(n//i)-2,ans)
    print(ans)


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

Fixed code:
import math

n = int(input())

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

true_ans = 10 ** 12
for i in range(1,N):
    if N % i == 0:
        ans = N // i
        true_ans = min(ans + i - 2, true_ans)
        if(i > N ** 0.5):
            break

print(true_ans)

Fixed code:
N = int(input())

n_hoge = int(N ** 0.5)
print

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

print(true_ans)
Buggy code:
from math import sqrt

N = int(input())

it = int(sqrt(N))

for i in range(it, 0, -1):
    remain = N % i
    if remain == 0:
        shou = N / i

        if shou:
            print(i+shou-2)
            break


Fixed code:
from math import sqrt

N = int(input())

it = int(sqrt(N))

for i in range(it, 0, -1):
    remain = N % i
    if remain == 0:
        shou = N / i

        print(int(i+shou-2))
        break
Buggy code:
import math
N = int(input())

max = math.floor(N**0.5)
A = 1
B = 1

for i in range(max):
    if N % (max - i) == 0:
        A = N
        B = N // A

print(A + B - 2)

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

max = math.floor(N**0.5)
A = 1
B = 1
for i in range(max):
    if N % (max - i) == 0:
        A = (max - i)
        B = N // A
        break

print(A + B - 2)
Buggy code:
n = int(input())

steps = []

for x in range(n):
    if n % (x + 1) == 0:
        steps.append(x + n // (x + 1) - 1)

print(min(steps))

Fixed code:
n = int(input())

steps = []

for x in range(int(n ** 0.5)):
    if n % (x + 1) == 0:
        steps.append(x + n // (x + 1) - 1)

print(min(steps))
Buggy code:
from math import sqrt
n=int(input())

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

print(ans)

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

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

print(ans)
Buggy code:
import math
import copy

n=int(input())

i=int(n**0.5)
j=0
# print(i)

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


Fixed code:
import math
import copy

n=int(input())

i=int(n**0.5)
j=0
# print(i)

for i in range(i+1,0,-1):
    # print(i)
    if n==i:
        print(n-1)
        break
    if n%i==0:
        j=n/i
        print(int(i+j-2))
        break
Buggy code:
import math

n = int(input())
sq = int(math.sqrt(n))

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


Fixed code:
import math

n = int(input())
sq = int(math.sqrt(n))

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

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


Fixed code:
n=int(input())
for i in range(int(n**0.5),0,-1):
    if n%i==0:
        print(i+n//i-2)
        exit()
Buggy code:
import sys
input = sys.stdin.readline
def print_ans(input_line):
    """Test Case
    >>> print_ans("10")
    5
    >>> print_ans("50")
    13
    >>> print_ans("10000000019")
    10000000018
    """
    N = int(input_line)
    min_ans = N - 1
    for i in range(1,N):
        q, mod= divmod(N,i)
        if mod == 0:
            min_ans = min(min_ans, q + i -2 )
    print(min_ans)

if __name__ == '__main__':
    print_ans(input())


Fixed code:
import sys
input = sys.stdin.readline
def print_ans(input_line):
    """Test Case
    >>> print_ans("10")
    5
    >>> print_ans("50")
    13
    >>> print_ans("10000000019")
    10000000018
    """
    N = int(input_line)
    min_ans = N - 1
    for i in range(1,int(N ** 0.5) + 1):
        q, mod= divmod(N,i)
        if mod == 0:
            min_ans = min(min_ans, q + i -2 )
    print(min_ans)

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

Fixed code:
n = int(input())
list = []
for i in range(1, int(n**0.5+1)):
  if n%i == 0:
    list.append(int(i + n/i))
print(min(list)-2)
Buggy code:
N = int(input())
from math import sqrt
res = set()
for i in range(int(sqrt(N)+1),0,-1):
  if N%i==0:
    print(i)
    res |= {N//i+i-2}
print(min(res))  

Fixed code:
N = int(input())
from math import sqrt
res = set()
for i in range(int(sqrt(N)+1),0,-1):
  if N%i==0:
    res |= {N//i+i-2}
print(min(res))
Buggy code:
import numpy as np
 
N = int(input())
ans = 10^12
for i in range(int(np.sqrt(N)+0.5)):
  a = i+1
  if N % a != 0:
    continue
  step = a + int(N/a) -2
  if step < ans:
    ans = step
    
print(str(ans))

Fixed code:
import numpy as np
 
N = int(input())
ans = 10**12
for i in range(int(np.sqrt(N)+0.5)):
  a = i+1
  if N % a != 0:
    continue
  step = a + int(N/a) -2
  if step < ans:
    ans = step
print(ans)
Buggy code:
import math
N = int(input())
s = 0
if N % 2 == 0:
  s = 2 + N // 2

for i in range(3, math.ceil(math.sqrt(N)) + 3, 2):
  if N % i == 0 and (not s or s > i + N // i):
    s = i + N // i

print(s-2)

Fixed code:
import math
def main():
  N = int(input())
  s = 0
  if N % 2 == 0:
    s = 2 + N // 2

  for i in range(3, math.ceil(math.sqrt(N)) + 3):
    if N % i == 0 and (not s or s > i + N // i):
      s = i + N // i

  if not s:
    s = N + 1

  print(s-2)
  
main()
Buggy code:
from math import sqrt
N = int(input()) # 2 <= N <= 10^12
# (1,1) (x,y) = x*y
a = N-1
for x in range(2, int(sqrt(N))+1):
  q, r = divmod(N, x):
  if r == 0:
    a = min(x-1 + q - 1, a)
print(a)
    
    
  
  

Fixed code:
from math import sqrt
N = int(input()) # 2 <= N <= 10^12
# (1,1) (x,y) = x*y
a = N-1
for x in range(2, int(sqrt(N))+1):
  q, r = divmod(N, x)
  if r == 0:
    a = min(x-1 + q - 1, a)
print(a)
Buggy code:
import math

N = int(input())

def factortwo(N):
    factors = []
    for i in range(1, int(math.sqrt(N))+1):
        if N % i == 0:
            factors.append((i, N // i))
    return factors

print(sum(factortwo(N)[-1]))

Fixed code:
import math

N = int(input())

def factortwo(N):
    factors = []
    for i in range(1, int(math.sqrt(N))+1):
        if N % i == 0:
            factors.append((i, N // i))
    return factors

print(sum(factortwo(N)[-1]) - 2)
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

d = make_divisors(N)
# print(d)

Ans_min = 1+N-2

for x in d:
  y = N/x
  Ans = x+y-2
  if Ans < Ans_min:
    Ans_min = Ans
    
print(Ans_min)


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

d = make_divisors(N)
# print(d)

Ans_min = 1+N-2

for x in d:
  y = N/x
  Ans = x+y-2
  if Ans < Ans_min:
    Ans_min = Ans
    
print(int(Ans_min))
Buggy code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    t = n
    mt = 10 ** 20
    for i in range(2, int(n ** 0.5) + 1):
        if t % i == 0:
            mt = min(mt, (i - 1) + (t // i - 1))
    print(mt)


if __name__ == '__main__':
    solve()


Fixed code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    t = n
    mt = 10 ** 20
    for i in range(1, int(n ** 0.5) + 1):
        if t % i == 0:
            mt = min(mt, (i - 1) + (t // i - 1))
    print(mt)


if __name__ == '__main__':
    solve()
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


n = int(input())
low, up = make_divisors(n)
if up:
    ans = low[0] + up[0]
    for i in range(1, len(low)):
        tmp = low[i] + up[i]
        if tmp < ans:
            ans = tmp
    print(tmp - 2)
else:
    print(n - 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)
            upper_divisors.append(n//i)
        i += 1
    return lower_divisors, upper_divisors


n = int(input())
low, up = make_divisors(n)
if len(low) != 1:
    # ans = low[0] + up[0]
    # for i in range(1, len(low)):
    #     tmp = low[i] + up[i]
    #     if tmp < ans:
    #         ans = tmp
    print(low[-1] + up[-1] - 2)
else:
    print(n - 1)
Buggy code:
N = int(input())

divisor = []
for i in range(1 , N+1):
    if N % i == 0:
        divisor.append(i)

distance = []
for j in range(int(len(divisor))-1):
    M = (N / int(divisor[j])) + int(divisor[j])
    distance.append(M)

import math

if int(len(divisor)) == 2:
    print(N-1)
else:
    print(math.floor(min(distance))-2)

Fixed code:
import math

N = int(input())

divisor = []
for i in range(1 , math.floor(N**(1/2))+1):
    if N % i == 0:
        divisor.append(i)

distance = []
for j in range(int(len(divisor))):
    M = (N / int(divisor[j])) + int(divisor[j])
    distance.append(M)

if int(len(divisor)) == 1:
    print(N-1)
else:
    print(math.floor(min(distance))-2)
Buggy code:
import numpy as np
n=int(input())
m=np.floor(np.sqrt(n))

l=[]
for i in range(1,m+1,1):
    if n%i==0:
        a=i+(n/i)
        l.append(a)
        
c=int(min(l))
print(c-2)


Fixed code:
import numpy as np
n=int(input())
m=int(np.ceil(np.sqrt(n)))+1
l=[]

for i in range(1,m,1):
    if n%i==0:
        a=i+(n/i)
        l.append(a)
        
c=int(min(l))
print(c-2)
Buggy code:
import math


n = int(input())
a = math.sqrt(n)//1
while a > 0:
  if n%a == 0:
    s = a
    t = n//a    
    break
  a -= 1
print(s+t-2)

Fixed code:
import math


n = int(input())
a = int(math.sqrt(n))
while a > 0:
  if n%a == 0:
    s = a
    t = n//a    
    break
  a -= 1
print(s+t-2)
Buggy code:
import math

N = int(input())

flag = True
s = math.floor(math.sqrt(N))
for i in range(s, 1, -1):
    if N % i == 0:
        ii = N // i
        print(i - 1 + ii - 1)
        flag = False
if flag:
    print(N - 1)

Fixed code:
import math

N = int(input())

flag = True
s = math.floor(math.sqrt(N))
for i in range(s, 1, -1):
    if N % i == 0:
        ii = N // i
        print(i - 1 + ii - 1)
        flag = False
        break
if flag:
    print(N - 1)
Buggy code:
a=int(input())
for x in range(int(a**0.5),0,-1):
	if a%x==0:
    d=int(a//x)
    break
print(d+x-2)


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

Fixed code:
import math
n=int(input())
ans=n+1
i=1
while i<=math.sqrt(n):
    if n%i==0 and ans > i +n/i:
        ans = i + n/i
    i+=1
ans = int(ans)
print(ans-2)
Buggy code:
import math
A = int(input())
B = int(math.sqrt(A))
count = 0
for i in reversed(range(1,B)):
	if count == 0:
    	if A % i == 0:
			print(i+A/i-2)
        	count += 1

Fixed code:
import math
A = int(input())
B = int(math.sqrt(A))
count = 0
for i in reversed(range(1,B+1)):
	if count == 0:
		if A % i == 0:
			print(int(i+A/i-2))
			count += 1
Buggy code:
tall = int(input())
bit = round(tall**(1/2))
while (bit/tall%1 != 0):
  bit -= 1
print(bit+tall/b-2)

Fixed code:
tall = int(input())
bit = int(tall**(1/2))
while ((tall/bit)%1 != 0):
  bit -= 1
print(int(bit+tall/bit-2))
Buggy code:
import numpy as np
ans=1000000000000
N=int(input())
for i in range(1,N+1):
    if (N%i==0):
        j=N//i
        move=(i-1)+(j-1)
        ans=min(ans,move)
print(ans)

Fixed code:
import numpy as np
ans=1000000000000
N=int(input())
for i in range(1,int(np.sqrt(N)+1)):
    if (N%i==0):
        j=N//i
        move=(i-1)+(j-1)
        ans=min(ans,move)
print(ans)
Buggy code:
import math
N = int(input())
a = 1
b = 1
ran = math.floor(math.sqrt(N))
max = 0
for i in range(ran):
    if N%i == 0:
        if i > max:
            max = i
print(i + N/i -2)

Fixed code:
import math
N = int(input())
a = 1
b = 1
ran = int(math.floor(math.sqrt(N)))
m = 1
for i in range(1,ran+1):
    if N%i == 0:
        if i > m:
            m = i
print(int(m + N/m -2))
Buggy code:
N = int(input())
li = list()
n = N
for i in range(1, N+1):
	if N % i == 0:
		li.append([i, int(N/i)])
for x in li:
	tmp = x[0] + x[1]
	if tmp <= n:
		n = tmp
ans = n - 2
print(ans)

Fixed code:
N = int(input())
li = list()
n = N + 1
for i in range(1, int(N**0.5+1)):
	if N % i == 0:
		li.append([i, int(N/i)])
for x in li:
	tmp = x[0] + x[1]
	if tmp <= n:
		n = tmp
ans = n - 2
print(ans)
Buggy code:
N = int(input())
n = int((N**(1/2))//1)
s =[0]*n
for i in range(1,n+1):
  if N//i == 0:
    s[i] = i
maxs = s[0]
for j in range(1,n+1):
  if s[j] > maxs:
    maxs = s[j]
p = int(N/maxs)
walk = p + maxs - 2
print(walk)


Fixed code:
N = int(input())
n = int((N**(1/2))//1)
s =[0]*(n+10)
for i in range(1,n+1):
  if N%i == 0:
    s[i] = i
maxs = s[0]
for j in range(1,n+1):
  if s[j] > maxs:
    maxs = s[j]
p = int(N/maxs)
walk = p + maxs - 2
print(walk)
Buggy code:
n=int(input())
i=int(n**0.5)
while i<n:
  if n%i==0:
    break
  else:
    i+=1
if i==n:
  print(i-1)
else:
  print(int(i+n/i)-2)

Fixed code:
n=int(input())
i=int(n**0.5)+1
while i>0:
  if n%i==0:
    break
  else:
    i-=1
if i==n:
  print(i-1)
else:
  print(int(i+n/i)-2)
Buggy code:
n=int(input())
import math
l= n-1
for i in range (1,int(math.sqrt(n))+1):
  if n % i ==0 and i+ n/i -2<l:
    l = i + n/i -2
print(l)

Fixed code:
n=int(input())
import math
l= n-1
for i in range (1,int(math.sqrt(n))+1):
  if n % i ==0 and i+ n/i -2<l:
    l = i + n/i -2
print(int(l))
Buggy code:
n = int(input())
for i in range(int(n**0.5)+1, 0, -1):
  if n//i == 0 and i <= n//i:
    key = i
    break
print(i+n//i-2)

Fixed code:
n = int(input())
for i in range(int(n**0.5)+1, 0, -1):
  if n%i == 0 and i <= n//i:
    key = i
    break
print(i+n//i-2)
Buggy code:
a = int(input())
b = int(math.sqrt(a))-1
for i in range(b):
    x = a/b
    if x.is_integer():
        break
    else:
        b -= 1
print(int(x + b -2))

Fixed code:
import math
a = int(input())
b = int(math.sqrt(a))
for i in range(b):
    x = a/b
    if x.is_integer():
        break
    else:
        b -= 1
print(int(x + b -2))
Buggy code:
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = float('inf')
for i in range(1,math.sqrt(n)):
    if n%i == 0:
        res = min(res, i + n/i)
print(int(res-2))


Fixed code:
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = float('inf')
for i in range(1,2*10**6):
    if (n/i).is_integer():
        res = min(res, i + n/i)
print(int(res-2))
Buggy code:
N = int(input())

def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table
 
if len(divisor(N)) < 3:
    print(N - 1)
else:
    divisor_list = divisor(N)
    tmp = N
    for i in divisor_list:
        print(i)
        A = i
        B = N / i
        if tmp > (A + B - 2):
            tmp = (A + B - 2)
    print(int(tmp))

Fixed code:
N = int(input())

def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table
 
if len(divisor(N)) < 3:
    print(N - 1)
else:
    divisor_list = divisor(N)
    tmp = N
    for i in divisor_list:
        A = i
        B = N / i
        if tmp > (A + B - 2):
            tmp = (A + B - 2)
    print(int(tmp))
Buggy code:
if __name__ == '__main__':

	n = int(input())
	m = int(n//2)

	end = n - 1
	for x in range(2,int(n**0.5)+1):
		if n % x == 0:
			y = n // x
			end = min(n+m-2,end)

	print(end)


Fixed code:
if __name__ == '__main__':

	n = int(input())
	m = int(n//2)

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

	print(end)
Buggy code:
#!/usr/bin/env python3
import math
import numpy as np

n = int(input())
ans = np.inf
for i in range(1, int(math.sqrt(n)+1)):
    if n%i==0:
        q = n//i
        tmp = i+q 
        if tmp <= ans:
            ans = tmp 
            i_ = i 
            q_ = q 

if i_ == 1 or q_ == 1:
    print(ans-1)
else:
    print(ans-2)


Fixed code:
#!/usr/bin/env python3
import math
import numpy as np

n = int(input())
ans = np.inf
for i in range(1, int(math.sqrt(n))+1):
    if n%i==0:
        q = n//i
        tmp = i+q 
        if tmp <= ans:
            ans = tmp 
            i_ = i 
            q_ = q 

print(ans-2)
Buggy code:
import os

def main():
	n = int(input())
	list_a = make_divisors(n)
	min_num = 1000000000000
	print(list_a)
	for i in range(0,len(list_a),2):
		if n//list_a[i] == list_a[i]:
			min_num = list_a[i] * 2 - 2
			break
		if min_num < (list_a[i] + list_a[i+1] - 2):
			pass
		else:
			min_num = list_a[i] + list_a[i+1] - 2
	print(min_num)
	
			


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

	
if __name__ == "__main__":
	main()


Fixed code:
import os

def main():
	n = int(input())
	list_a = make_divisors(n)
	min_num = 1000000000000
	for i in range(0,len(list_a),2):
		if n//list_a[i] == list_a[i]:
			min_num = list_a[i] * 2 - 2
			break
		if min_num < (list_a[i] + list_a[i+1] - 2):
			pass
		else:
			min_num = list_a[i] + list_a[i+1] - 2
	print(min_num)
	
			


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

	
if __name__ == "__main__":
	main()
Buggy code:
n = int(input())
ma = 10**100
for i in range(1, 10**6+2):
  if N % i == 0:
    ma = min(ma,((i-1)+(n//i)-1))
print(ma)


Fixed code:
n = int(input())
ma = 10**100
for i in range(1, 10**6+2):
  if n % i == 0:
    ma = min(ma,((i-1)+(n//i)-1))
print(ma)
Buggy code:
n=int(input())
ans=10**18
for i in range(10**6+1):
  if n%i==0:
    j=n//i
  ans=min(ans,i+j-2)
print(ans)

Fixed code:
n=int(input())
ans=10**18
for i in range(1,10**6+1):
  if n%i==0:
    j=n//i
  ans=min(ans,i+j-2)
print(ans)
Buggy code:
n = int(input())
ans = n - 1
a = 1
while a * a <= n:
  if n % a == 0:
    ans = min(ans, a - 1 + (n / a) - 1)
print(ans)

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

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

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

Fixed code:
n=int(input())
t=1
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        t=i
print((n//t)-1+t-1)
Buggy code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 01:55:56 2020

@author: liang
"""

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

ans = 10**12
for i in range(1,N+1):
    if N%i == 0:
        tmp = i-1 + N//i -1
        if ans > tmp:
            ans = tmp
print(ans)

Fixed code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 01:55:56 2020

@author: liang
"""

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

ans = 10**12
for i in reversed(range(1,key+1)):
    if N%i == 0:
        ans = i-1 + N//i -1
        break
print(ans)
Buggy code:
import math

def main():
    n = int(input())
    m = math.sqrt(n)
    ans = []
    for i in range(int(n) + 1):
        div = i / n
        if not float.is_integer(div):
            continue
        ans.append((div+i)-2)
    print(min(ans))



if __name__ == '__main__':
    main()

Fixed code:
import math

def main():
    n = int(input())
    m = math.sqrt(n)
    ans = []
    for i in range(1, int(m) + 1):
        div = n / i
        if not float.is_integer(div):
            continue
        ans.append((div+i)-2)

    print(int(min(ans)))


if __name__ == '__main__':
    main()
Buggy code:
n=int(input())
num=int(n**0.5)
ans=float('inf')
for i in range(2,num+1):
    if n%i==0:
        temp=n//i+i-2
        if ans>temp:ans=temp

print(ans)

Fixed code:
n=int(input())

num=int(n**0.5)
ans=float('inf')
for i in range(1,num+1):
    if n%i==0:
        temp=i+n//i-2
        if temp<ans:ans=temp

print(temp)
Buggy code:
import math
n = input()
n = int(n)
spl_list = [1]
for i in range(1,round(math.sqrt(n)) + 1):
  if n % i == 0:
    spl_list.append(i)

max_i = max(spl_list)
max_j = n / max_i
print(round(max_i + maxj -2))
  

Fixed code:
import math
n = input()
n = int(n)
spl_list = [1]
for i in range(1,round(math.sqrt(n)) + 1):
  if n % i == 0:
    spl_list.append(i)

max_i = max(spl_list)
max_j = n / max_i
print(round(max_i + max_j -2))