Problem:


Score : 300 points

Problem Statement

Takahashi is standing on a multiplication table with infinitely many rows and columns.

The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1).

In one move, he can move from (i,j) to either (i+1,j) or (i,j+1).

Given an integer N, find the minimum number of moves needed to reach a square that contains N.

Constraints

2 \leq N \leq 10^{12}

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum number of moves needed to reach a square that contains the integer N.

Sample Input 1

10

Sample Output 1

5

(2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.

Sample Input 2

50

Sample Output 2

13

(5, 10) can be reached in 13 moves.

Sample Input 3

10000000019

Sample Output 3

10000000018

Both input and output may be enormous.



Sample input:
10


Sample output:
5

Submission status: Runtime Error

Solution code:
N = int(input())
L = []

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

Submission status: Runtime Error

Solution code:
tall = int(input())
bit = round(tall**(1/2))
while (bit/tall%1 != 0):
  bit -= 1
print(bit+tall/b-2)

Submission status: Runtime Error

Solution code:
a = int(input())
b = 0
count = 0
for i in range(9):
  for j in range(9):
    if (i+1)*(j+1) == a:
      count += 1
      if count>0:
        if (c+d)>(i+1)+(j+1):
		  c = i+1
          d = j+1
      else :
        c = i+1
        d = j+1
ans = c+d-2
print(ans)

Submission status: Runtime Error

Solution code:
a = int(input())
b = 0
count = 0
for i in range(9):
  for j in range(9):
    if (i+1)*(j+1) == a:
      count += 1
      if count>0:
        if (c+d)>(i+1)+(j+1):
		  c = i+1
          d = j+1
      else :
        c = i+1
        d = j+1
ans = c+d-2
print

Submission status: Runtime Error

Solution code:
from math import sqrt, inf

a = []


def dis(n):
    for i in range(1, int(sqrt(n)) + 1):
        if n % i == 0: a.append(i)


num = int(input())
dis(num)
ans = 100000000
for e in a:
    ans = min(ans, e + num // e - 2)
print(ans)

Submission status: Runtime Error

Solution code:
from math import inf

a = []


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


num = int(input())
dis(num)
ans = inf
for e in a:
    if e + num // e - 2 < ans:
        ans = e + num // e - 2
    # ans = min(ans, e + num / e - 2)
print(int(ans))

Submission status: Runtime Error

Solution code:
from math import inf

a = []


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


num = int(input())
dis(num)
ans = inf
for e in a:
    if e + num / e - 2 < ans:
        ans = e + num / e - 2
    # ans = min(ans, e + num / e - 2)
print(int(ans))

Submission status: Runtime Error

Solution code:
from math import sqrt, inf

a = []


num = int(input())
for i in range(1, int(num ** 0.5) + 1):
    if num % i == 0:
        a.append(int(i))
ans = inf
for e in a:
    ans = min(ans, e + num / e - 2)
print(int(ans))

Submission status: Runtime Error

Solution code:
from math import sqrt, inf

a = []


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


num = int(input())
dis(num)
ans = inf
for e in a:
    ans = min(ans, e + num / e - 2)
print(int(ans))

Submission status: Runtime Error

Solution code:
from math import sqrt, inf

a = []


def dis(n):
    for i in range(1, int(sqrt(n)) + 1):
        if n % i == 0:
            a.append(int(i))


num = int(input())
dis(num)
ans = inf
for e in a:
    ans = min(ans, e + num / e - 2)
print(int(ans))

Submission status: Runtime Error

Solution code:
from math import sqrt, inf

a = []


def dis(n):
    for i in range(1, int(sqrt(n)) + 1):
        if n % i == 0:
            a.append(i)


num = int(input())
dis(num)
ans = inf
for e in a:
    ans = min(ans, e + num // e - 2)
print(ans)

Submission status: Runtime Error

Solution code:
from math import sqrt, inf

a = []


def dis(n):
    for i in range(1, int(sqrt(n)) + 1):
        if n % i == 0: a.append(i)


num = int(input())
dis(num)
ans = inf
for e in a:
    ans = min(ans, e + num // e - 2)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = []

for i in range(N):
    for j in range(N):
        if i * j == N:
            A.append((i+j))

print(min(A)-2)

Submission status: Runtime Error

Solution code:
N = int(input())
fac = []
for i in range(1, N**(1/2) + 1):
  if (N % i == 0 and N // i <= i):
    print(N // i + i - 2)
    exit()

Submission status: Runtime Error

Solution code:
s = input().split() #標準入力　sに値を入れる

def sort(A):
    if len(A) < 2:
        return A
    c = len(A)//2
    return merge(sort(A[:c]), sort(A[c:]))

def merge(X, Y):
    if len(X) < 1:
        return Y
    if len(Y) < 1:
        return X
    if (X[0] > Y[0]):
        return [Y[0]]+ merge(X, Y[1:])
    else:
        return [X[0]] + merge(X[1:], Y)

n = int(s[0])
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(divisors)
l = len(divisors)
n1 = divisors[l // 2 - 1]
n2 = divisors[l // 2]
ans = n1 + n2 - 2
print(n2)

Submission status: Runtime Error

Solution code:
N = int(input())

lst = []
for i in range(1, N + 1):
	if N % i == 0 and i < == N // i:
		row = i
		column = N // i
		move = row - 1 + column - 1
		lst.append(move)
print(min(lst))

Submission status: Runtime Error

Solution code:
N = int(input())

lst = []
for i in range(1, N + 1):
	if N % i == 0 and i < = N // i:
		row = i
		column = N // i
		move = row - 1 + column - 1
		lst.append(move)
print(min(lst))

Submission status: Runtime Error

Solution code:
N = int(input())

lst = []
move = []
for i in range(1, N + 1):
	if N % i == 0:
		square = tuple(i, N // i)
		lst.append(square)
for k in range(0, len(lst)):
	move.append(lst[k][0] - 1 + lst[k][1] -1)
print(min(move))

Submission status: Runtime Error

Solution code:
from math import sqrt

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

Submission status: Runtime Error

Solution code:
from math import sqrt

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

Submission status: Runtime Error

Solution code:
from math import sqrt
n=int(input())
for i in range(int(sqrt(n)),0,-1):
  if n%i==0:
    j=n/i
    pirnt(i+j-2)
    break

Submission status: Runtime Error

Solution code:
from math import sqrt
n=int(input())
for i in range(int(sqrt(n)),0,-1):
  if n%i==0:
    j=n//i
    pirnt(i+j-2)
    break

Submission status: Runtime Error

Solution code:
from math import sqrt
n=int(input())
for i in range(sqrt(n),0,-1):
  if n%i==0:
    j=n//i
    pirnt(i+j-2)
    break

Submission status: Runtime Error

Solution code:
from math import sqrt
n=input()
for i in range(sqrt(n),0,-1):
  if n%i==0:
    j=n//i
    pirnt(i+j-2)
    break

Submission status: Runtime Error

Solution code:
n=input()
for i in range(sqrt(n),0,-1):
  if n%i==0:
    j=n//i
    pirnt(i+j-2)
    break

Submission status: Runtime Error

Solution code:
n=inupt()
for i in range(sqrt(n),0,-1):
  if n%i==0:
    j=n//i
    pirnt(i+j-2)
    break

Submission status: Runtime Error

Solution code:
N = int(input())
n = N

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

if n < N:
    print(int(n-2))
else:
    print(int(n-1))

Submission status: Runtime Error

Solution code:
import sys
n=int(input())
L=[]
for i in range(1,int(n**(1/2))):
    if n//i == n/i:
        L.append(n//i+i-2)
print(min(L))

Submission status: Runtime Error

Solution code:
def prime_factors(n):
    i = 2
    factors = 1
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors = i
    if n > 1:
        factors = i
    return factors
N = int(input())
large_factor = prime_factor(N)
print(large_factor+(N/large_factor)-2)

Submission status: Runtime Error

Solution code:
from heapq import heapify, heappush, heappop
N = int(input())
heap = []
heapify(heap)
for i in range(1, int(N**(0.5))):
    if N % i == 0:
        heappush(heap, i - 1 + N // i - 1)
print(heappop(heap))

Submission status: Runtime Error

Solution code:
N = int(input)

Submission status: Runtime Error

Solution code:
import math

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

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
result=100000000000000000000000000
for i in range(n):
  nn=n/i
  if (nn.is_integer() and result>nn+i-2):
	result=nn+i-2
print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
n = int(input())
ans = int('inf')
for i in range(10^6):
  if n%(i+1) == 0:
    j = n/(i+1)
    ans = min(ans, (i+1)+j-2)
print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
ans = float('inf')
for i in range(10^6):
  if n%i == 0:
    j = n/i
    ans = min(ans, i+j-2)
print(ans)

Submission status: Runtime Error

Solution code:
def devide2two(n):
    arr=[]
    arr.append((n-1))
    for i in range(2, int(-(-n**0.5//1))+1):
        if n%i==0:
            a = n/i
            arr.append(i-1+ a-1)
    
    return min(arr)
n = input()
print(devide2two(n))

Submission status: Runtime Error

Solution code:
n= int(input())
for i in range(1, int(n/2)+1):
  if n%i == 0:
    L.append(i + int(n/i)-2)
    
print(min(L))

Submission status: Runtime Error

Solution code:
n = int(input())
L = []
for i in range(1, n/2+1):
  if n%i == 0:
    L.append(i + n/i -2)
print(min(L))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
ef div_make(n):
    divisor =[]
    n=int(n)
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisor.append([i,n//i])
    return divisor

a=int(input())

lst=[]
for i in div_make(a):
    lst.append(i[0]+i[1])
ans=0
ans=min(lst)-2
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

ress = []

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

print(min(ress)-2)

Submission status: Runtime Error

Solution code:
n = int(input())
for i in range(int(n**0.5))[::-1]:
    if n%i == 0:
        print(i + n//i - 2)
        break

Submission status: Runtime Error

Solution 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 = []
for i in range(0,len(a),2):
    sum = a[i] + a[i+1]
    b.append(sum)
b.sort()
print(b[0]-2)

Submission status: Runtime Error

Solution code:
import numpy as np
N = input()
N = int(N)
sqrt_N = np.sqrt(N)
road = []
for i in range(1, int(sqrt_N)):
  b = N/i
  if N%i==0:
    road.append(i+b-2)
  
print(min(road))

Submission status: Runtime Error

Solution code:
import numpy as np
N = input()
N = int(N)
sqrt_N = np.sqrt(N)
road = []
for i in range(1, int(sqrt_N)):
  b = N/i
  road.append(i+b-2)
  
print(min(road))

Submission status: Runtime Error

Solution code:
import numpy as np
N = input()
N = int(N)

sqrt_N = np.sqrt(N)
road = []
for i in range(0, int(sqrt_N)+1):
  b =  N/i
  road.append(b+i-2)
print(min(road))

Submission status: Runtime Error

Solution code:
import math
n = int(input())
m = int(math.sqrt(n))

ans = n - 1

for a in range(m):
  if n % a == 0:
    b = n // a
    ans = min(ans, a + b - 2)
    
print(ans)

Submission status: Runtime Error

Solution code:
import math
 
n = int(input())
if(n == 2 or n == 3):
  print(n-1)
else:
  for i in range(int(math.sqrt(n)) - 1, n):
  if(n % i == 0):
    print(i + (n/i) - 2)
    break

Submission status: Runtime Error

Solution code:
import math

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

Submission status: Runtime Error

Solution code:
import math

N = int(input())

sn = math.sqrt(N) // 1
a = 0

for i in range(1, sn + 1):
  if N % i == 0:
    a = i
    break

print(int(a + (N / a) - 2))

Submission status: Runtime Error

Solution code:
import math

N = int(input())

sn = math.sqrt(N) // 1
a = 0

for i in range(1, sn + 1):
  if N % i == 0:
    a = i
    break

print(int(i + (N / i) - 2))

Submission status: Runtime Error

Solution code:
import math

N = int(input())

sn = math.sqrt(N) // 1
i = 0

for i in range(1, sn + 1):
  if N % i == 0:
    break

print(int(i + (N / i) - 2))

Submission status: Runtime Error

Solution code:
N = int(input())

sn = math.sqrt(N) // 1

while True:
  if N % sn == 0:
    break
  sn += 1

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

Submission status: Runtime Error

Solution code:
N = int(input())

sn = math.sqrt(N)

while True:
  if N % sn == 0:
    break
  sn += 1

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a=int(input())
for x in range(int(a**0.5),0,-1):
	if a%x==0:
    d=int(a//x)
    s=d+x-2
    break
print(s)

Submission status: Runtime Error

Solution code:
a=int(input())
for x in range(int(a**0.5),0,-1):
	if a%x==0:
    d=a//x
    s=d+x-2
    break
print(s)

Submission status: Runtime Error

Solution code:
a=int(input())
for x in range(int(a**0.5),0,-1)
	if a%x==0:
    d==a//x
    s==d+x-2
    break
print(s)

Submission status: Runtime Error

Solution code:
a=int(input())
for x in range(a**0.5,0,-1)
	if a%x==0:
    s=a+x-2
    break
print(s)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
import itertools
input = sys.stdin.readline

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

n=int(input())

l=factorize(n)

if len(l)==2:
    print(l[0]+l[1]-2)
    exit()

while True:
    l.sort(reverse=True)
    temp=l[-1]*l[-2]
    l.pop()
    l.pop()
    l.append(temp)
    if len(l)==2:
        break

print(l[0]+l[1]-2)

Submission status: Runtime Error

Solution code:
import sys
import itertools
input = sys.stdin.readline

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

n=int(input())

l=factorize(n)
print(l)
if len(l)==2:
    print(l[0]+l[1]-2)
    exit()

while True:
    l.sort(reverse=True)
    temp=l[-1]*l[-2]
    l.pop()
    l.pop()
    l.append(temp)
    if len(l)==2:
        break

print(l[0]+l[1]-2)

Submission status: Runtime Error

Solution code:
import sys
import itertools
input = sys.stdin.readline

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

n=int(input())

l=factorize(n)

if len(l)==2:
    print(l[0]+l[1]-2)

while True:
    l.sort(reverse=True)
    temp=l[-1]*l[-2]
    l.pop()
    l.pop()
    l.append(temp)
    if len(l)==2:
        break

print(l[0]+l[1]-2)

Submission status: Runtime Error

Solution code:
import sys
import itertools
input = sys.stdin.readline

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

n=int(input())

l=factorize(n)

while True:
    l.sort(reverse=True)
    temp=l[-1]*l[-2]
    l.pop()
    l.pop()
    l.append(temp)
    if len(l)==2:
        break

print(l[0]+l[1]-2)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
min=1000000000000
if N%2==0:
    for i in range(int(N/2),1, -1):
        if N%i==0:
            if min>int(i+N/i-2):
                min=int(i+N/i-2)
    print(min)
else:
    for i in range(int((N-1)/2), 1,-1):
        if N%i==0:
            if min>print(int(i+N/i-2)):
                min=print(int(i+N/i-2))
    print(min)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
for i in range (2, n):
    if n % i == 0:
        j = n // i
        anser = i + j - 2
    if i * i > n:
        break
print(anser)

Submission status: Runtime Error

Solution code:
n=int(input())
r=n-1
for i in range(int(n**0.5)+1):
    if (n%i==0):
        s=(n//i)+i-2
        if s<r:
            r=s
print(r)

Submission status: Runtime Error

Solution code:
=int(input())
r=n-1
for i in range(2,int(n**0.5)):
    if (n%i==0):
        s=n//i+i-2
        if s<r:
            r=s
print(r)

Submission status: Runtime Error

Solution code:
n=int(input()) 
r=False
i=2
m=n-1
i=2
while (i<=int(n**0.5)):
	if ((n%i)==0 ):		
        s=i+n//i-2
		if (s<m):
			m=s
	i+=1
print(m)

Submission status: Runtime Error

Solution code:
N = int(input())
 
mi = 10**10
 
for a in range(int(math.sqrt(N)), N+1, 1):
  N % a == 0:
    b = N//a
    if mi > a+b-2:
      mi = a+b-2
print(mi)

Submission status: Runtime Error

Solution code:
N = int(input())

mi = 10**10

for a in range(N):
  for b in range(a):
    if a*b = N:
      if mi < a*b-2:
        mi == a*b-2
print(mi)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [i for i in range(1,100)]
b = []
for j in range(100):
    if n%int(a[j]) == 0:
        b.append(int(a[j]) + n//int(a[j]) -2)
print(min(b))

Submission status: Runtime Error

Solution code:
n = int(input())
a = [i for i in range(1,n+1)]
b = []
for j in range(9):
    if n%int(a[j]) == 0:
        b.append(int(a[j]) + n//int(a[j]) -2)
print(min(b))

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int N,mi=99999999999999;
    cin >> N;
    vector<long long int> yakusu;
    for(long long int i=1;i*i<=N;i++)
        if(N % i == 0){
            mi = min(mi,(N/i+i) - 2);
        }
    cout << mi << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
min = n
for i in range(1,n+1):
  if n % i == 0:
      if min < x + n/i
      
print(min)

Submission status: Runtime Error

Solution code:
n = int(input())
min = -1
for i in range(1,n+1):
  if min == -1:
    if n % i == 0:
      if min < x + n/i
      
print(min)

Submission status: Runtime Error

Solution code:
N = int(input())
import math
n = math.floor(N**0.5)
s = N + 1
for i in range(1,n):
    if N % i == 0:
        a = i + (N/i)
        if s >= a:
            s = a
print(int(a-2))

Submission status: Runtime Error

Solution code:
N = int(input())
s = N + 1
t = 0
for i in range(1,N**0.5):
    if N % i == 0:
        a = i + (N//i)
        if s > a:
            t = a
print(a-2)

Submission status: Runtime Error

Solution code:
def dis(xa,ya):
  return abs(xa - 1) + abs(ya - 1)

n = int(input())
ans = 2*n
i = 1
while i*i <= n:
	if (n % i == 0):
      ans = min(ans,dis(i,n//i))
    i += 1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
a = 0

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

b = N // a

ans = (a - 1) + (b - 1)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
s = N + 1
for i in range(N):
    if N % i == 0:
        a = i + (N/i)
        if s > a:
            s = a
print(a-2)

Submission status: Runtime Error

Solution code:
import math

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
from io import StringIO
import unittest
import math


def check(A, F, x, N, K):
    for i in range(N):
        if A[i] * F[i] > x:
            k = math.ceil(A[i] - x / F[i])
            K -= k
    if K < 0:
        return False
    else:
        return True


def resolve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    A.sort(reverse=True)
    F.sort()

    # binary search
    l = 0
    r = max(A) * max(F)
    result = None
    while l <= r:
        # print('l {}, r {}'.format(l, r))
        if l == r:
            result = l
            break
        mid = (l + r) // 2
        if check(A, F, mid, N, K):
            r = mid
        else:
            l = mid + 1

    print(result)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 5
4 2 1
2 3 1"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 8
4 2 1
2 3 1"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """11 14
3 1 4 1 5 9 2 6 5 3 5
8 9 7 9 3 2 3 8 4 6 2"""
        output = """12"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Runtime Error

Solution code:
Input = list(map(int,input().split()))

point =[]
for i in range(Input[0]):
    point.append(0)

for i in range(Input[2]):
    aa = int(input())
    point[aa-1] +=1
gouhi =[]
for i in range(Input[0]):
    bb = 0
    if Input[1]-Input[2]+point[i] > 0 :
        bb = "Yes"
    else:
        bb = "No"
    gouhi.append(bb)
print("\n".join(gouhi))

Submission status: Runtime Error

Solution code:
from enum import Enum
from queue import Queue

import numpy as np

import collections
import bisect
import sys
import math

from scipy.sparse.csgraph import floyd_warshall

BIG_NUM = 200000000000
MOD = 1000000007
EPS = 0.000000001

N = int(input())
ans = BIG_NUM

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

print(ans)

Submission status: Runtime Error

Solution 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

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

d = prime_factorize(N)

import math
ans = math.inf

A = d

for i in range(1 << len(A)):
    a = []
    b = []
    ao = 1
    bo = 1
    for j in range(len(A)):
        if ((i >> j) & 1) == 1:
            a.append(A[j])
        else:
            b.append(A[j])
            
    for j in range(len(a)):
        ao *= a[j]
    for j in range(len(b)):
        bo *= b[j]
        
    ans = min(ans, ao+bo-2)
    
print(ans)

Submission status: Runtime Error

Solution 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

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

d = prime_factorize(N)

import math
ans = math.inf

A = d

for i in range(1 << len(A)):
    a = []
    b = []
    ao = 1
    bo = 1
    for j in range(len(A)):
        if ((i >> j) & 1) == 1:
            a.append(A[j])
        else:
            b.append(A[j])
            
    for j in range(len(a)):
        ao *= a[j]
    for j in range(len(b)):
        bo *= b[j]
        
    ans = min(ans, ao+bo-2)
    print(ans)

Submission status: Runtime Error

Solution 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

d = make_divisors(N)
d.sort()

a = 0
b = 0
ans = 0
if len(d)%2==0:
    a = d[len(d)//2-1]
    b = d[len(d)//2]
    ans = a+b
else:
    a = d[len(d)//2]
    b = d[len(d)//2+1]
    c = d[len(d)//2+2]
    ans = min(a+b,b+c)

ans -= 2
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
lis = []
for a in range(1,int(N**0.5)):
    b = N // a
    if a * b == N:
       lis.append(a + b - 2)
print(min(lis))

Submission status: Runtime Error

Solution code:
import sympy
n=int(input())
a = sympy.divisors(n)
ans = 11451481019191919191919
for i in a:
	ans = min(ans, i+n/i)
	
print(int(ans-2))

Submission status: Runtime Error

Solution code:
import math

n = int(input())
r_n = int(math.sqrt(n))
s = []

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

Submission status: Runtime Error

Solution code:
from math import sqrt, inf

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

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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution 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(min(c) - 2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

N = int(input())
N_half = round(N/2)
a =[]

for i in range(N_half):
    for j in range(N_half - i+1):
        if i * j == N:
            a.append([i,j])


sum=[]

for k in range(len(a)-1):
    sum.append(a[k][0] + a[k][1])

sum.sort
print(sum[0]-2)

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
ans = n-1
for i in range(int(np.sqrt(n))+1):
  if n % i == 0:
    ans = min(ans, i + n/i -2)
print(ans)

Submission status: Runtime Error

Solution code:
 N = int(input())
s = N-1
for i in range(1, int(N**0.5) + 1):
    for j in range(1, int(N**0.5) + 1):
        if N == i * j:
            flag = i + j - 2

            if flag <= s:
                s = flag

print(s)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

list_p = []
for i in range(n):
    for j in range(n - i):
        if i*j == 100:
            list_p.append([i, j, i+j])
list_sorted = sorted(list_p, key=itemgetter(2))
print(list_sorted[0][0] + list_sorted[0][1] - 2)

Submission status: Runtime Error

Solution 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

Submission status: Runtime Error

Solution code:
N=int(input())
a=[]
from math import*
for i in range(1,int(sqrt(N))):
    if N%i==0:
        a.append(int(i+(N/i)-2))
print(min(a))

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(range(2,n+1))
ans=10**9
for i in l:
    if n%i==0:
        a=i+int(n/i)-2
        ans=min(ans,a)
print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
res = 10**9+7
for i in range(math.ceil(math.sqrt(n))):
  if n%i==0:
    res = min(res,i+n//i-2)
print(res)

Submission status: Runtime Error

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

n = int(input())
root = int(math.sqrt(n))
for i in reversed(range(root)):
    if(n%i == 0):
        j=int(n/i)
        print(i+j-2)
        break

Submission status: Runtime Error

Solution code:
import math.sprt
N=int(input())

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

Submission status: Runtime Error

Solution 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

Submission status: Runtime Error

Solution code:
import math

n = int(input())
n_h = round(math.sqrt(n))

yakusu = []
for i in range(1, n_h):
    if n % i == 0:
        yakusu.append(i)

if yakusu[-1]*yakusu[-1] == n:
    ans = yakusu[-1]*2 -2
else:
    tmp = n / yakusu[-1]
    ans = tmp + yakusu[-1] - 2

print(int(ans))

Submission status: Runtime Error

Solution code:
import math

n = int(input())

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
ans = n
for i in range(int(n**0.5),0,-1):
  if n % i == 0:
    j = target // i
    if (i+j-2) < ans:
      ans = i+j-2
print(ans)