Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import numpy as np
N = int(input())

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

primes = prime_factorize(N)
prod = np.prod(np.array(primes))
index = [i for i in range(len(primes))]
ans = prod - 1

for i in range(1, len(primes) // 2 + 1):
    for cmb in itertools.combinations(index, i):
        i_next = np.prod(np.array([primes[c] for c in cmb]))
        j_next = prod // i_next
        ans = min(ans, i_next + j_next - 2)
            
print(ans)

Fixed submission:
N = int(input())
div = []
ans = N - 1
i = 2
while i ** 2 <= N:
    if N % i == 0:
        div.append(i)
    i += 1

for d in div:
    ans = min(ans, d + N // d - 2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import numpy as np
N = int(input())

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

primes = prime_factorize(N)
prod = np.prod(np.array(primes))
index = [i for i in range(len(primes))]
ans = prod - 1

for i in range(1, len(primes)):
    for cmb in itertools.combinations(index, i):
        i_next = np.prod(np.array([primes[k] for k in range(len(primes)) if k in cmb]))
        j_next = prod // i_next
        ans = min(ans, i_next + j_next - 2)
            
print(ans)

Fixed submission:
N = int(input())
div = []
ans = N - 1
i = 2
while i ** 2 <= N:
    if N % i == 0:
        div.append(i)
    i += 1

for d in div:
    ans = min(ans, d + N // d - 2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import numpy as np
N = int(input())

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

primes = prime_factorize(N)
index = [i for i in range(len(primes))]
ans = False

for i in range(1, len(primes) // 2 + 1):
    for cmb in itertools.combinations(index, i):
        if i != len(primes):
            i_moved = np.prod(np.array([primes[k] for k in range(len(primes)) if k in cmb])) - 1
            j_moved = np.prod(np.array([primes[k] for k in range(len(primes)) if k not in cmb])) - 1 
        else:
            i_moved = np.prod(np.array(primes)) - 1
            j_moved = 0
        if ans is not False:
            ans = min(ans, i_moved + j_moved)
        else:
            ans = i_moved + j_moved
            
print(ans)

Fixed submission:
N = int(input())
div = []
ans = N - 1
i = 2
while i ** 2 <= N:
    if N % i == 0:
        div.append(i)
    i += 1

for d in div:
    ans = min(ans, d + N // d - 2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import numpy as np
N = int(input())

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

primes = prime_factorize(N)
index = [i for i in range(len(primes))]
ans = False

for i in range(1, len(primes) + 1):
    for cmb in itertools.combinations(index, i):
        if i != len(primes):
            i_moved = np.prod(np.array([primes[k] for k in range(len(primes)) if k in cmb])) - 1
            j_moved = np.prod(np.array([primes[k] for k in range(len(primes)) if k not in cmb])) - 1 
        else:
            i_moved = np.prod(np.array(primes)) - 1
            j_moved = 0
        if ans is not False:
            ans = min(ans, i_moved + j_moved)
        else:
            ans = i_moved + j_moved
            
print(ans)

Fixed submission:
N = int(input())
div = []
ans = N - 1
i = 2
while i ** 2 <= N:
    if N % i == 0:
        div.append(i)
    i += 1

for d in div:
    ans = min(ans, d + N // d - 2)

print(ans)