Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02862 (python)

Fixed submission:
import math
M = 10**9+7
X,Y = map(int,input().split())
if (X+Y)/3 != (X+Y)//3:
    print(0)
    exit()
n = (X+Y)//3
r = Y-n
if r<0 or r>n:
    print(0)
    exit()
 
 
#nCr and Mod
def nCr(n, r, mod=10**9+7):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod
 
print(nCr(n,r,M))

Buggy submission (verdict: Runtime Error):
x,y = map(int, input().split())
 
if (x + y) % 3  != 0:
  print(0)
  exit()
  
k = x - (x+y)//3
m = y - (x+y)//3
 
if k < 0 or m < 0:
  print(0)
  exit()
  
def nCr(k,m):
  mod = 10**9 + 7
  k,m = max(k,m),min(k,m)
  l = s = 0
  for i in range(m,k - m + 1):
    l = l * (m + i) % mod
    s = s * (i + 1) % mod
    
print(l/s)

Buggy submission (verdict: Runtime Error):
x,y = map(int, input().split())
 
if (x + y) % 3  == 0:
  print(0)
  exit()
  
k = x - (x+y)//3
m = y - (x+y)//3
 
if k < 0 or m < 0:
  print(0)
  exit()
  
def nCr(k,m):
  mod = 10**9 + 7
  k,m = max(k,m),min(k,m)
  l = s = 0
  for i in range(m,k - m + 1):
    l = l * (m + i) % mod
    s = s * (i + 1) % mod
    
print(l/s)

Buggy submission (verdict: Runtime Error):
x,y = map(int, input().split())

if (x + y) % 3  == 0:
  print(0)
  exit()
  
k = x - (x+y)//3
m = y - (x+y)//3

if k < 0 or m < 0:
  print(0)
  exit()
  
def nCr(k,m):
  mod = 10**9 + 7
  k,m = max(k,m),min(k,m)
  l = s = 0
  for i in range(m,k + 1):
    l = l * (m + i) % mod
    s = s * (i + 1) % mod
    
print(l/s)
Problem p02879 (python)

Fixed submission:
a = list(map(int, input().split()))
if 1<=a[0] and a[0]<=9:
    if 1<=a[1] and a[1]<=9:
        print(a[0]*a[1])
    else:
        print(-1)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
a = int(input())

for i in range(int(a**0.5),0,-1):
    if a % i == 0:
        print(int(a/i + i -2))
        break

Buggy submission (verdict: Runtime Error):
a = int(input())

for i in range(int(i**0.5),0,-1):
    if a % i == 0:
        print(int(a/i + i -2))
        break

Buggy submission (verdict: Runtime Error):
a = int(input())

for i in range(int(i**0.5),0,-1):
    if a % i == 0:
        print(a/i + i -2)
        break

Buggy submission (verdict: Runtime Error):
def prime_factorize(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

a = int(input())

b = prime_factorize(a)

c = 10**10
d = 10**10
for i in range(len(b)):
    if i % 2 == 0:
        c *= b[i]
    else:
        d *= b[i]

print(c + d - 2)
Problem p02881 (python)

Fixed submission:
a = int(input())

for i in range(int(a**0.5),0,-1):
    if a % i == 0:
        print(int(a/i + i -2))
        break

Buggy submission (verdict: Runtime Error):
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

i = int(input())
a = factorization(i)
for i in range(len(a)-1):
  if a[i][0] == a[i + 1][0]:
    a.remove(a[i])
flag = False
for i in a:
  
  if i[1] == 1:
    
    flag = True
  else:
    flag = False

if flag:
  b = [0 if i % 2 == 0 else 1 for i in range(len(a))]
else:
  b = [i[1]//2 for i in a]

c = [a[i][1]-b[i] for i in range(len(b))]

d = [a[i][0]**b[i] for i in range(len(a))]


f = 1
for i in range(len(c)):
  f *= a[i][0]**c[i]

g = 1
for i in range(len(c)):
  g *= d[i]

print(f + g - 2)
Problem p02688 (python)

Fixed submission:
import math
import time
from collections import defaultdict,deque
from sys import stdin,stdout
from bisect import bisect_left,bisect_right
n,k=map(int,stdin.readline().split())
ans=n
done=defaultdict(lambda:False)
for _ in range(k):
    d=int(input())
    a=list(map(int,stdin.readline().split()))
    for i in a:
        if(i not in done):
            ans-=1
            done[i]=True
print(ans)

Buggy submission (verdict: Runtime Error):
import math
import time
from collections import defaultdict,deque
from sys import stdin,stdout
from bisect import bisect_left,bisect_right
n,k=map(int,stdin.readline().split())
ans=n
done=defaultdict(lambda:False)
for _ in range(k):
    d=int(input())
    a=list(map(int,stdin.readline().split()))
    for i in d:
        if(i not in done):
            ans-=1
            done[i]=True
print(ans)
Problem p02699 (python)

Fixed submission:
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
s,w=map(int,stdin.readline().split())
if(w>=s):
    print("unsafe")
else:
    print("safe")

Buggy submission (verdict: Runtime Error):
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
n = int(input())
ans = 0
c = defaultdict(lambda: 0)
for _ in n:
    s = input()
    if(s in c):
        ans += 1
        c[s] += 1
print(ans)
Problem p02701 (python)

Fixed submission:
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
n = int(input())
ans = 0
c = defaultdict(lambda: 0)
for _ in range(n):
    s = input()
    if(s not in c):
        ans += 1
        c[s] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
n = int(input())
ans = 0
c = defaultdict(lambda: 0)
for _ in n:
    s = input()
    if(s in c):
        ans += 1
        c[s] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import math
import time
from collections import defaultdict,deque
from sys import stdin,stdout
from bisect import bisect_left,bisect_right
n=int(input())
ans=0
c=defaultdict(lambda:0)
for _ in n:
    s=int(input())
    if(s in c):
        ans+=1
        c[s]+=1
print(ans)
Problem p03834 (python)

Fixed submission:

s=input()
a=list(s.split(","))
print(*a)

Buggy submission (verdict: Runtime Error):
s=input()
a=list(input.split(","))
print(*a)
Problem p02862 (python)

Fixed submission:
X, Y = map(int, input().split())
MOD = 10**9+7

N = 10**6+1
def pow_mod(x, n):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return pow_mod(x * x % MOD, n // 2) % MOD
    else:
        return x * pow_mod(x * x % MOD, n // 2) % MOD

fact = [1]
for i in range(1,N+1):
    fact.append( (fact[i-1] * i) % MOD )

inv = [1] * (N+1)
inv[N] = pow_mod(fact[N], MOD-2)
for i in range(N, 1, -1):
    inv[i-1] = inv[i] * (i) % MOD

def cmb_mod(n,r):
    return fact[n] * inv[r] * inv[n-r] % MOD


if (X+Y) % 3 != 0:
    print(0)
else:
    n = (2*X - Y) // 3
    m = (2*Y - X) // 3
    if n < 0 or m < 0:
        print(0)
    else:
        print(cmb_mod(n+m, n))

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
MOD = 10**9+7

N = min(X,Y)
def pow_mod(x, n):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return pow_mod(x * x % MOD, n // 2) % MOD
    else:
        return x * pow_mod(x * x % MOD, n // 2) % MOD

fact = [1]
for i in range(1,N+1):
    fact.append( (fact[i-1] * i) % MOD )

inv = [1] * (N+1)
inv[N] = pow_mod(fact[N], MOD-2)
for i in range(N, 1, -1):
    inv[i-1] = inv[i] * (i) % MOD

def cmb_mod(n,r):
    return fact[n] * inv[r] * inv[n-r] % MOD


cnt = 0
x,y = X,Y
while x > 0 and y > 0:
    if x == 2*y or y == 2*x:
        break
    x -= 3
    y -= 3
    cnt += 1

ans = 0
if x == 0 and y == 0:
    ans = cmb_mod(cnt*2, cnt)
elif x == 2*y or y == 2*x:
    ans = cmb_mod(cnt+2, cnt) * (cnt+1) % MOD

print(ans)
Problem p02623 (python)

Fixed submission:
import bisect
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

asum, bsum = [0], [0]
for i in range(n):
  if k < a[i] + asum[i]:
    break
  asum.append(a[i] + asum[i])
for i in range(m):
  if k < b[i] + bsum[i]:
    break
  bsum.append(b[i] + bsum[i])

ans = 0
for i in range(len(asum)):
  tmp = i + bisect.bisect(bsum, k-asum[i]) - 1
  if ans < tmp:
    ans = tmp
print(ans)

Buggy submission (verdict: Runtime Error):
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = 0
ai = 0
bi = 0
while True:
  if len(a) != ai and a[ai] <= b[bi]:
    k -= a[ai]
    ai += 1
  elif len(b) != bi:
    k -= b[bi]
    bi += 1
  else:
    break
  if k < 0:
    break
  count += 1
print(count)

Buggy submission (verdict: Runtime Error):
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = 0
while True:
  if a != [] and a[0] <= b[0]:
    k -= a[0]
    a.pop(0)
  elif b !=[]:
    k -= b[0]
    b.pop(0)
  else:
    break
  if k < 0:
    break
  count += 1
print(count)
Problem p02659 (python)

Fixed submission:
A, B = input().split()
A = int(A)
B = int(B[:-3])*100 + int(B[-2:])

print(A*B // 100)

Buggy submission (verdict: Runtime Error):
A, B = input().split()
A = int(A)
B = int(B)*100 + int(B[-2:])

print(A*B // 100)
Problem p02723 (python)

Fixed submission:
string = input()

if string[2] == string[3] and string[4] == string[5]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
string = input()

if string[2] == string[3] and string[4] == string[5]:
  print 'Yes'
else:
  print 'No'
Problem p02682 (python)

Fixed submission:
A, B, C, K = map(int, input().split())

def mysum(A, B, C, K):
  if K <= A:
    return(K)
  
  if K <= A+B:
    return(A)
  
  return(A + -1 * (K-A-B))
 
print(mysum(A, B, C, K))

Buggy submission (verdict: Runtime Error):
A, B, C, K = map(int, input().split())

L = [1] * A + [0] * B + [-1] * C
print(sum(L[:K]))
Problem p02785 (python)

Fixed submission:
import numpy as np
N, K = map(int,input().split())
H = np.array(list(map(int,input().split())))

if K >= N:
    print(0)
elif K == 0:
    answer = np.sum(H)
    print(answer)
else:
    ind = np.argpartition(H, -K)[-K:]
    top_k = H[ind]
    answer = np.sum(H) - np.sum(top_k)
    print(answer)

Buggy submission (verdict: Runtime Error):
if K >= N:
    print(0)
elif K == 0:
    answer = np.sum(H)
    print(answer)
else:
    ind = np.argpartition(H, -K)[-K:]
    print(ind)
    top_k = H[ind]
    answer = np.sum(H) - np.sum(top_k)
    print(answer)
Problem p03038 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
from operator import itemgetter
 
N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))
 
BC.sort(key = itemgetter(1),reverse=True)
 
BC.append((N,-1))
 
change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break
 
A += change
A.sort()
answer = sum(A[-N:])
print(answer)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, M = map(int, input().split())

A_list = list(map(int, input().split()))

R_list = []

for _ in range(M):
  B, C = map(int, input().split())
  BC_list = [C]*B
  R_list.extend(BC_list)

R_list = np.array(R_list)
R_list = np.sort(R_list)
R_list = R_list[::-1]
R_list = R_list[:N]

A_list = np.array(A_list)
A_list = np.sort(A_list)

short_len = N - len(R_list)

if short_len > 0:
  R_list = np.append(R_list, [0]*short_len)

print(np.sum(np.maximum(A_list,R_list)))
Problem p02707 (python)

Fixed submission:
n=int(input())
s=list(map(int,input().split()))
k=[0]*n
for i in s:
  k[i-1]+=1
for i in k:
  print(i)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=list(map(int,input()))
for i in range(n):
  print(s.count(i+1))
Problem p02831 (python)

Fixed submission:
import math
a,b=map(int,input().split())
x,y=a,b
while b!=0:
  a,b=b,a%b
print(x*y//a)

Buggy submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
print(a*b/gcd(a,b))
Problem p02835 (python)

Fixed submission:
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
if a+b+c<=21:
  print("win")
else:
  print("bust")

Buggy submission (verdict: Runtime Error):
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
if a+b+c<=21:
  print(win)
else:
  print(bust)
Problem p02847 (python)

Fixed submission:
s=input()
l=["SUN","MON","TUE","WED","THU","FRI","SAT"]
print(7-l.index(s))

Buggy submission (verdict: Runtime Error):
s=input()
l=["SUN","MON","TUE","WED","THU","FRI","SAT"]
print(7-l.index(s)
Problem p03013 (python)

Fixed submission:
N, M = map(int, input().split())
steps = [True] * (N + 1)
for _ in range(M):
    steps[int(input())] = False
dp = [0] * (N + 1)
dp[0] = 1
for prev in range(N):
    for now in range(prev + 1, min(N, prev + 2) + 1):
        if steps[now]:
            dp[now] += dp[prev]
            dp[now] %= 10 ** 9 + 7
print(dp[N])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
steps = [True] * (N + 1)
for _ in range(M):
    steps[int(input())] = False
dp = [0] * (N + 1)
dp[0] = 1
for prev in range(N):
    for now in range(prev + 1, min(N, prev + 2) + 1):
        if steps[now]:
            dp[now] += dp[prev]
            dp[now] %= 1_000_000_007
print(dp[N])
Problem p02622 (python)

Fixed submission:
a=input()
b=input()
c=0
for i in range(len(a)):
  if(a[i]!=b[i]):
    c=c+1
print(c)

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
c=0
for i in range(a):
  if(a[i]!=b[i]):
    c=c+1
print(c)
Problem p02659 (python)

Fixed submission:
def multiply(num1, num2): 
    len1 = len(num1) 
    len2 = len(num2) 
    if len1 == 0 or len2 == 0: 
        return "0"
  
    # will keep the result number in vector 
    # in reverse order 
    result = [0] * (len1 + len2) 
      
    # Below two indexes are used to  
    # find positions in result. 
    i_n1 = 0
    i_n2 = 0
  
    # Go from right to left in num1 
    for i in range(len1 - 1, -1, -1): 
        carry = 0
        n1 = ord(num1[i]) - 48
  
        # To shift position to left after every 
        # multiplication of a digit in num2 
        i_n2 = 0
  
        # Go from right to left in num2 
        for j in range(len2 - 1, -1, -1): 
              
            # Take current digit of second number 
            n2 = ord(num2[j]) - 48
          
            # Multiply with current digit of first number 
            # and add result to previously stored result 
            # at current position. 
            summ = n1 * n2 + result[i_n1 + i_n2] + carry 
  
            # Carry for next iteration 
            carry = summ // 10
  
            # Store result 
            result[i_n1 + i_n2] = summ % 10
  
            i_n2 += 1
  
            # store carry in next cell 
        if (carry > 0): 
            result[i_n1 + i_n2] += carry 
  
            # To shift position to left after every 
            # multiplication of a digit in num1. 
        i_n1 += 1
          
        # print(result) 
  
    # ignore '0's from the right 
    i = len(result) - 1
    while (i >= 0 and result[i] == 0): 
        i -= 1
  
    # If all were '0's - means either both or 
    # one of num1 or num2 were '0' 
    if (i == -1): 
        return "0"
  
    # generate the result string 
    s = "" 
    while (i >= 0): 
        s += chr(result[i] + 48) 
        i -= 1
  
    return s 
  
# Driver code 
str1, str2 = input().split()
str2 = str2.replace(".", "")
# print(str1)
# print(str2)
if((str1[0] == '-' or str2[0] == '-') and 
   (str1[0] != '-' or str2[0] != '-')): 
    print("-", end = '') 
  
  
if(str1[0] == '-' and str2[0] != '-'): 
    str1 = str1[1:] 
elif(str1[0] != '-' and str2[0] == '-'): 
    str2 = str2[1:] 
elif(str1[0] == '-' and str2[0] == '-'): 
    str1 = str1[1:] 
    str2 = str2[1:]
res = multiply(str1, str2)
if len(res)>2:
    print(multiply(str1, str2)[:-2]) 
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import math
A, B = input()
A = int(A)
B = float(B)
print(math.floor(A*B))

Buggy submission (verdict: Runtime Error):
import math
A = int(input())
B = float(input())
print(math.floor(A*B))

Buggy submission (verdict: Runtime Error):
import math
A = input()
B = input()
print(math.floor(A*B))
Problem p03250 (python)

Fixed submission:
a, b, c = (int(i) for i in input().split())  
integers = [a, b, c]
integers.sort()
print(integers[2]*10+integers[1]+integers[0])

Buggy submission (verdict: Runtime Error):
a, b, c = (int(i) for i in input().split())  
integers = [a, b, c]
integers = [a, b, c].sort()
print(integers[2]*10+integers[1]+integers[0])
Problem p03252 (python)

Fixed submission:
s = list(str(input()))
t = list(str(input()))

def judge(S,T):
    start = [-1 for i in range(26) ] 
    goal = [-1 for i in range(26)]
    for i in range(len(S)):
        a = ord(S[i]) - ord('a')
        b = ord(T[i]) - ord('a')
        if start[a] != -1 or goal[b] != -1:
            if start[a]!= b or goal[b] !=a:
                print("No")
                break
        else:
            start[a] = b
            goal[b] =a
        if i==len(S)-1:
            print("Yes")
            
judge(s,t)

Buggy submission (verdict: Runtime Error):
s = list(str(input()))
t = list(str(input()))



def judge(S,T):
    start = [-1 for i in range(26) ] 
    goal = [-1 for i in range(26)]
    for i in range(len(S)):
        a = ord(S[i]) - ord('a')
        b = ord(T[i]) - ord('a')
        if start[a] != -1 or goal[b] != -1:
            if start[a]!= b or goal[b] !=a:
                print("No")
                break
        else:
            start[a] = b
            goal[b] =a
        if i==len(S)-1:
            print("Yes")
            
            
 judge(s,t)

Buggy submission (verdict: Runtime Error):
S = list(str(input()))
T = list(str(input()))

count = 0
while True:
    if S[count] == T[count]:
        count = count + 1
    else:
        c1 = S[count]
        c2 = T[count]
        for i in range(len(S)):
            if S[i] == c1:
                S[i] = c2
            elif S[i] == c2:
                S[i] = c1
    count = count + 1
    if count == len(S)-1:
        break

if S == T:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
S = list(str(input()))
T = list(str(input()))

count = 0
while True:
    if S[count] == T[count]:
        count = count + 1
        #print(count)
    else:
        c1 = S[count]
        c2 = T[count]
        for i in range(len(S)):
            if S[i] == c1:
                S[i] = c2
            elif S[i] == c2:
                S[i] = c1
    if count == len(S)-1:
        break

if S == T:
    print("Yes")
else:
    print("No")
Problem p03011 (python)

Fixed submission:
p,q,r=map(int,input().split())
print(min(p+q,q+r,r+p))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
A=set(int(input()) for i in range(m))
dp=[0]*(n+1)
dp[0]=1
for i in range(1,n+1):
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
    if i in A:dp[i]=0
print(dp[n])
Problem p03012 (python)

Fixed submission:
n=int(input())
w=list(map(int,input().split()))
m=sum(w)
for i in range(n):m=min(m,abs(sum(w[:i+1])-sum(w[i+1:])))
print(m)

Buggy submission (verdict: Runtime Error):
n=int(input())
w=list(map(int,input().split()))
m=sum(w)
for i in range(n)m=min(m,abs(sum(w[:i+1])-sum(w[i+1:])))
print(m)
Problem p03107 (python)

Fixed submission:
s=list(input())
n=len(s)
zero=s.count("0")
one=s.count("1")
if n==1:print(0)
else:print(2*min(zero,one))

Buggy submission (verdict: Runtime Error):
S=input()
stack=[]
ans=0
for s in S:
    if not stack:
        stack.append(s)
    elif stack[-1]!=s
        stack.pop()
        ans+=2
    else:
        stack.append(s)
print(ans)
Problem p03221 (python)

Fixed submission:
import collections
import bisect
n,m=map(int,input().split())
p=[[int(j) for j in input().split()] for i in range(m)]
a=collections.defaultdict(list)
for x,y in sorted(p):
    a[x]+=[y]
for x,y in p:
    z=bisect.bisect(a[x],y)
    print("%06d%06d"%(x,z))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
PY=[list(map(int,input().split())) for i in range(M)]
x=collections.defaultdict(list)
for city,year in PY:
    x[city]+=[year]
for city,year in PY:
    num=bisect.bisect(x[city],year)
    print("%06d%06d"%(city,num))
Problem p03252 (python)

Fixed submission:
from collections import Counter
s=Counter(list(input()))
t=Counter(list(input()))
s,t=list(s.values()),list(t.values())
print("Yes" if sorted(s)==sorted(t) else "No")

Buggy submission (verdict: Runtime Error):
s=sorted(map(list(input()).count,set(s)))
t=sorted(map(list(input()).count,set(t)))
print("Yes" if s==t else "No")
Problem p03307 (python)

Fixed submission:
n=int(input())
print(2*n if n%2 else n)

Buggy submission (verdict: Runtime Error):
n=int(input())
print([N,N*2][N%2])
Problem p02881 (python)

Fixed submission:
# coding: utf-8
# Your code here!
import math
import sys
N = int(input())

def divisor(N):
    lst = []
    for i in range(2,math.ceil(math.sqrt(N))+1):
        if N%i == 0:
            lst.append(i)
            #if i != int(N/i):
                #lst.append(int(N/i))
    #lst.sort()
    return lst
    
ans = divisor(N)
#print(ans,len(ans))
if N == 2:
    print(1)
    sys.exit()
    
if len(ans) > 0:
    A = ans[-1]
    if A*A < N:
        B = int(N/A)
        print(A+B-2)
    else:
        print(2*A-2)
else:
    print(N-1)

'''
if len(ans)%2 == 0 and len(ans)>1:
    A = ans[len(ans)//2-1]
    B = ans[len(ans)//2]
    #print(A,B)
    print(A+B-2)
elif len(ans)%2 == 1 and len(ans)>1:
    A = ans[len(ans)//2]
    print(2*A-2)
else:
    print(N-1)
'''

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import math
N = int(input())

def divisor(N):
    lst = []
    for i in range(2,math.ceil(math.sqrt(N))+1):
        if N%i == 0:
            lst.append(i)
            #if i != int(N/i):
                #lst.append(int(N/i))
    #lst.sort()
    return lst
    
ans = divisor(N)
#print(ans,len(ans))
if len(ans) > 0:
    A = ans[-1]
else:
    print(N-1)
if A*A < N:
    B = int(N/A)
    print(A+B-2)
else:
    print(2*A-2)
'''
if len(ans)%2 == 0 and len(ans)>1:
    A = ans[len(ans)//2-1]
    B = ans[len(ans)//2]
    #print(A,B)
    print(A+B-2)
elif len(ans)%2 == 1 and len(ans)>1:
    A = ans[len(ans)//2]
    print(2*A-2)
else:
    print(N-1)
'''

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import math
N = int(input())

def divisor(N):
    lst = []
    for i in range(2,math.ceil(math.sqrt(N))+1):
        if N%i == 0:
            lst.append(i)
            if i != int(N/i):
                lst.append(int(N/i))
    lst.sort()
    return lst
    
ans = divisor(N)
#print(ans,len(ans))
A = ans[len(ans)//2-1]
B = ans[len(ans)//2]
#print(A,B,A*B)
if A*B == N and len(ans)>1:
    print(A+B-2)
elif B**2 == N and len(ans)>1:
    print(2*B-2)
else:
    print(N-1)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import math
N = int(input())

def divisor(N):
    lst = []
    for i in range(2,math.ceil(math.sqrt(N))):
        if N%i == 0:
            lst.append(i)
            
    return lst[-1]
    
def isPrime(n):
  if n == 2:
    return True
  if n % 2 == 0:
    return False
  m = math.floor(math.sqrt(n)) + 1
  for p in range(3, m, 2):
      if n % p == 0:
        return False
  return True
  
if isPrime(N):
    print(N-1)
else:
    ans = divisor(N)
    A = ans
    B = N/ans
    print(int(A+B-2))#
#print(ans)