Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
from collections import deque


def p_f(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


hoge = p_f(N)
DP = deque()
DP.append(1)

if len(hoge) == 1:
    print(hoge[0]-1)
else:
    Min = 10**12

    for i in range(len(hoge)):
        for j in range(len(DP)):
            x = DP[j]*hoge[i]
            DP.append(x)
            if (x + (N // x) - 2) < Min:
                Min = (x + (N // x) - 2)

    print(Min)

Fixed submission:
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


List = make_divisors(N)

if len(List) % 2 == 1:
    print(List[len(List) // 2] * 2 - 2)
else:
    print(List[len(List) // 2 - 1] + (List[len(List) // 2] - 2))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())


def p_f(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


hoge = p_f(N)

DP = [1]

if len(hoge) == 1:
    print(hoge[0]-1)
else:
    Min = 10**12

    for i in range(len(hoge)):
        for j in range(len(DP)):
            x = DP[j]*hoge[i]
            DP.append(x)
            if (x + (N // x) - 2) < Min:
                Min = (x + (N // x) - 2)

    print(Min)

Fixed submission:
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


List = make_divisors(N)

if len(List) % 2 == 1:
    print(List[len(List) // 2] * 2 - 2)
else:
    print(List[len(List) // 2 - 1] + (List[len(List) // 2] - 2))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())


def p_f(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


hoge = p_f(N)

DP = [1]

if len(hoge) == 1:
    print(hoge[0]-1)
else:
    Min = 10**12

    for i in range(len(hoge)):
        for j in range(len(DP)):
            
            DP.append(DP[j]*hoge[i])

    for i in range(len(DP)):
        if (DP[i] + (N//DP[i]) - 2) < Min:
            Min = (DP[i] + (N//DP[i]) - 2)
            
    print(Min)

Fixed submission:
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


List = make_divisors(N)

if len(List) % 2 == 1:
    print(List[len(List) // 2] * 2 - 2)
else:
    print(List[len(List) // 2 - 1] + (List[len(List) // 2] - 2))