Buggy python submission (verdict: Time Limit Exceeded):
import itertools

def primes(n):
    l = []
    i = 2
    while i <= n**(1/2):
        while n % i == 0:
            n //= i
            l.append(i)
        i += 1
    if n > 1:
        l.append(n)
    return l

def mul(l):
    result = 1
    for i in l:
        result *= i
    return result

n = int(input())

prime_list = primes(n)

i,j = 1,n
for m in range(len(prime_list)//2 + 1):
    cmb = set(itertools.combinations(prime_list, m))
    for c in cmb:
        s = mul(c)
        t = n//s
        if abs(s-t) < abs(i-j):
            i,j = s,t

print(i+j-2)


Fixed submission:
import math

N = int(input())

ans = 10**15
for k in range(1, int(math.sqrt(N))+1):
    if N % k > 0:
        continue
    ans = min(ans, k + N//k - 2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

def primes(n):
    l = []
    i = 2
    while i <= n**(1/2):
        while n % i == 0:
            n //= i
            l.append(i)
        i += 1
    if n > 1:
        l.append(n)
    return l

def mul(l):
    result = 1
    for i in l:
        result *= i
    return result

n = int(input())

prime_list = primes(n)

i,j = 1,n
for m in range(len(prime_list)):
    cmb = set(itertools.combinations(prime_list, m))
    for c in cmb:
        s = mul(c)
        t = n//s
        if abs(s-t) < abs(i-j):
            i,j = s,t

print(i+j-2)


Fixed submission:
import math

N = int(input())

ans = 10**15
for k in range(1, int(math.sqrt(N))+1):
    if N % k > 0:
        continue
    ans = min(ans, k + N//k - 2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

def primes(n):
    l = []
    i = 2
    while i <= n**(1/2):
        while n % i == 0:
            n //= i
            l.append(i)
        i += 1
    if n > 1:
        l.append(n)
    return l

def mul(l):
    result = 1
    for i in l:
        result *= i
    return result

n = int(input())

prime_list = primes(n)

i,j = 1,n
for m in range(len(prime_list)):
    cmb = list(set(itertools.combinations(primes(n), m)))
    for c in cmb:
        s = mul(c)
        t = n//s
        if abs(s-t) < abs(i-j):
            i,j = s,t

print(i+j-2)


Fixed submission:
import math

N = int(input())

ans = 10**15
for k in range(1, int(math.sqrt(N))+1):
    if N % k > 0:
        continue
    ans = min(ans, k + N//k - 2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

def primes(n):
    l = []
    i = 2
    while i <= n**(1/2):
        while n % i == 0:
            n //= i
            l.append(i)
        i += 1
    l.append(n)
    return l

def mul(l):
    result = 1
    for i in l:
        result *= i
    return result

n = int(input())

per = list(set(itertools.permutations(primes(n))))

i,j = 1,n
for p in per:
    for k in range(len(p)):
        s,t = mul(p[:k]), mul(p[k:])
        if abs(s-t) < abs(i-j):
            i,j = s,t

print(i+j-2)


Fixed submission:
import math

N = int(input())

ans = 10**15
for k in range(1, int(math.sqrt(N))+1):
    if N % k > 0:
        continue
    ans = min(ans, k + N//k - 2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

def primes(n):
    l = []
    i = 2
    while i <= n**(1/2):
        while n % i == 0:
            n //= i
            l.append(i)
        i += 1
    l.append(n)
    return l

def mul(l):
    result = 1
    for i in l:
        result *= i
    return result

n = int(input())

per = list(set(itertools.permutations(primes(n))))

i,j = 1,n
for p in per:
    for k in range(len(p)):
        s,t = mul(p[:k]), mul(p[k:])
        if abs(s-t) < abs(i-j):
            i,j = s,t

print(i+j-2)


Fixed submission:
import math

N = int(input())

ans = 10**15
for k in range(1, int(math.sqrt(N))+1):
    if N % k > 0:
        continue
    ans = min(ans, k + N//k - 2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

def primes(n):
    l = []
    i = 2
    while i <= n**(1/2):
        while n % i == 0:
            n //= i
            l.append(i)
        i += 1
    l.append(n)
    return l

def mul(l):
    result = 1
    for i in l:
        result *= i
    return result

n = int(input())

per = list(itertools.permutations(primes(n)))

i,j = 1,n
for p in per:
    for k in range(len(p)):
        s,t = mul(p[:k]), mul(p[k:])
        if abs(s-t) < abs(i-j):
            i,j = s,t

print(i+j-2)


Fixed submission:
import math

N = int(input())

ans = 10**15
for k in range(1, int(math.sqrt(N))+1):
    if N % k > 0:
        continue
    ans = min(ans, k + N//k - 2)
print(ans)