Buggy python submission (verdict: Time Limit Exceeded):
# ABC144 C
from itertools import combinations
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def factorize(n):
    retlist = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
                retlist.append(i)
    if temp!=1:
        retlist.append(temp)

    if retlist==[]:
        retlist.append(n)

    return retlist

N = ni()

ans = 0
L = []
L = factorize(N)

ans = 10**13
m = ((len(L)+1)//2) + 1
for i in range(1,len(L)+1):
    if i<=m:
        C = []
        C = list(combinations(L,i))
    for c in C:
        a,b = 1,0
        for j in range(len(c)):
            a *= c[j]
            b = N//a
            ans = min(ans,a-1+b-1)

print(ans)


Fixed submission:
# ABC144 C - Walk on Multiplication Table
import math
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n = ni()
sqrtn = int(math.sqrt(n))
for i in range(sqrtn, 0, -1):
    if n%i == 0:
        j = n // i
        print(i+j-2)
        break

Buggy python submission (verdict: Time Limit Exceeded):
# ABC144 C
from itertools import combinations
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def factorize(n):
    retlist = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
                retlist.append(i)
    if temp!=1:
        retlist.append(temp)

    if retlist==[]:
        retlist.append(n)

    return retlist

N = ni()

ans = 0
L = []
L = factorize(N)

ans = 10**13
m = ((len(L)+1)//2) + 1
for i in range(1,len(L)+1):
    if i<=m:
        C = []
        C = list(combinations(L,i))
    for c in C:
        a,b = 1,0
        for j in range(len(c)):
            a *= c[j]
            b = N//a
            ans = min(ans,a-1+b-1)

print(ans)


Fixed submission:
# ABC144 C - Walk on Multiplication Table
import math
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n = ni()
sqrtn = int(math.sqrt(n))
for i in range(sqrtn, 0, -1):
    if n%i == 0:
        j = n // i
        print(i+j-2)
        break

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def factorize(n):
    retlist = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
                retlist.append(i)
    if temp!=1:
        retlist.append(temp)

    if retlist==[]:
        retlist.append(n)

    return retlist

N = ni()

ans = 0
L = []
L = factorize(N)

ans = 10**13

for i in range(1,len(L)+1):
    C = []
    C = list(combinations(L,i))
    for c in C:
        a,b = 1,0
        for j in range(len(c)):
            a *= c[j]
            b = N//a
            ans = min(ans,a-1+b-1)

print(ans)


Fixed submission:
# ABC144 C - Walk on Multiplication Table
import math
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n = ni()
sqrtn = int(math.sqrt(n))
for i in range(sqrtn, 0, -1):
    if n%i == 0:
        j = n // i
        print(i+j-2)
        break

Buggy python submission (verdict: Time Limit Exceeded):
# ABC144 C
from itertools import combinations
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def factorize(n):
    retlist = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
                retlist.append(i)
    if temp!=1:
        retlist.append(temp)

    if retlist==[]:
        retlist.append(n)

    return retlist

N = ni()

ans = 0
L = []
L = factorize(N)

ans = 10**13

for i in range(1,len(L)+1):
    C = []
    C = list(combinations(L,i))
    for c in C:
        a,b = 1,0
        for j in range(len(c)):
            a *= c[j]
            b = N//a
            ans = min(ans,a-1+b-1)

print(ans)


Fixed submission:
# ABC144 C - Walk on Multiplication Table
import math
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n = ni()
sqrtn = int(math.sqrt(n))
for i in range(sqrtn, 0, -1):
    if n%i == 0:
        j = n // i
        print(i+j-2)
        break