Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 10**12
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

q = factorization(n)
ans_list = []
for i in range(len(q)):
    for j in range(q[i][1]):
        ans_list.append(q[i][0])

p = 1
for i in ans_list:
    p *= i
s = len(ans_list)
for i in range(2 ** s):
    bag = []
    for j in range(s):
        if ((i >> j) & 1): 
            bag.append(ans_list[j]) 
    a = 1
    for t in bag:
        a *= t
    b = p/a
    
    ans = min(ans,a+b-2)
    
print(int(ans))

Fixed submission:
N=int(input())
a=1
for i in range(1,int(N**(1/2))+2):
    if N%i==0:
        a=max(a,i)
print(a+N//a-2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 10**12
def factorization(n): #素因数分解
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

q = factorization(n)
ans_list = []
for i in range(len(q)):#分解してリストに一つずつ格納
    for j in range(q[i][1]):
        ans_list.append(q[i][0])

if len(ans_list) == 1:
    print(ans_list[0]-1)
    exit()
        
ans_list = sorted(ans_list,reverse = True)#最小となるようにソートして掛けていく
p = 1
for i in ans_list:
    p *= i
s = len(ans_list)
for i in range(2 ** s):
    bag = []
    for j in range(s):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            bag.append(ans_list[j]) 
    a = 1
    for t in bag:
        a *= t
    b = p/a
    
    ans = min(ans,a+b-2)
    
print(int(ans))




Fixed submission:
N=int(input())
a=1
for i in range(1,int(N**(1/2))+2):
    if N%i==0:
        a=max(a,i)
print(a+N//a-2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 10**12
def factorization(n): #素因数分解
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

q = factorization(n)
ans_list = []
for i in range(len(q)):#分解してリストに一つずつ格納
    for j in range(q[i][1]):
        ans_list.append(q[i][0])

if len(ans_list) == 1:
    print(ans_list[0]-1)
    exit()
        
ans_list = sorted(ans_list,reverse = True)#最小となるようにソートして掛けていく
p = 1
for i in ans_list:
    p *= i
s = len(ans_list)
for i in range(2 ** s):
    bag = []
    for j in range(s):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            bag.append(ans_list[j]) 
    a = 1
    for t in bag:
        a *= t
    b = p/a
    
    ans = min(ans,a+b-2)
    
print(int(ans))




Fixed submission:
N=int(input())
a=1
for i in range(1,int(N**(1/2))+2):
    if N%i==0:
        a=max(a,i)
print(a+N//a-2)

Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
m = math.sqrt(n)
m = int(n + 1)
ans = []
for i in range(m):
    for j in range(m):
        if i * j == n:
            ans.append(i+j-2)
print(min(ans))

Fixed submission:
N=int(input())
a=1
for i in range(1,int(N**(1/2))+2):
    if N%i==0:
        a=max(a,i)
print(a+N//a-2)