stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>



using namespace std;



#define ll long long

#define X first

#define Y second

#define all(x) x.begin(), x.end()



const int MX = (int)1e5 + 10;

const int mod = (int)1e9 + 7;



void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}

void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}

void mul(int &x, int y){x = x * 1LL * y % mod;}





int main(){



    cin.tie(0); cout.tie(0);

    ios_base::sync_with_stdio(0);



    ll n;

    cin >> n;



    ll res = n - 1;

    for(ll i = 2; i * i <= n; ++i){

        if(n % i) continue;

        res = min(res, i + n / i - 2);

    }



    cout << res << endl;



    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cmath>

typedef long long ll;

using namespace std;



int main()

{

	ll n;

	scanf("%lld",&n);

	ll ans=0;

	ll ans1=0;

	for(ll i=sqrt(n)+1;i>=1;i--)

	{

		if(n%i==0)

		{

			ans=i;

			ans1=n/i;

			break;

		}

	}

	if(ans==1)

	printf("%lld\n",n-1);

	else

	printf("%lld\n",ans+ans1-2);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#include <cstring>

using namespace std;

#define ll  long long

#define endl '\n'

const ll mod = 1000000007;

const double PI = 3.141592653589793238463;

using namespace std;

int main()

{

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    ll x;

    cin>>x;

    ll m=sqrtl(x);

    for (int i=m;i>0;i--){

        if (x%i==0){

            cout<<x/i+i-2<<endl;

            break;

        }

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cmath>

typedef long long ll;

using namespace std;



int main()

{

	ll n;

	scanf("%lld",&n);

	ll ans=0;

	ll ans1=0;

	for(ll i=sqrt(n)+1;i>=1;i--)

	{

		if(n%i==0)

		{

			ans=i;

			ans1=n/i;

			break;

		}

	}

	if(ans==1)

	printf("%lld\n",n-1);

	else

	printf("%lld\n",ans+ans1-2);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



int main()

{

    long long int num,n;

    int digits;

    vector<long long int>vec;

    cin>>n;

    digits=int(floor(log10(n)+1));

    digits=(digits/2);

    for(int i = 1; i <=int(pow(10,(digits+1))); i++)

    {

        if(n % i == 0 && vec.size()==0)

            {vec.push_back(i);vec.push_back((n/i));}

        else if(n%i==0 && vec.size()!=0)

            {vec.push_back(i);vec.push_back((n/i));}

    }

    sort(vec.begin(),vec.end());

    num=(vec.size()/2);

    cout<<(vec[num-1]-1)+(vec[num]-1)<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cmath>

typedef long long ll;

using namespace std;



int main()

{

	ll n;

	scanf("%lld",&n);

	ll ans=0;

	ll ans1=0;

	for(ll i=sqrt(n)+1;i>=1;i--)

	{

		if(n%i==0)

		{

			ans=i;

			ans1=n/i;

			break;

		}

	}

	if(ans==1)

	printf("%lld\n",n-1);

	else

	printf("%lld\n",ans+ans1-2);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream> 

#include<cmath>

using namespace std;

long long n;



int main(){

	cin>>n;

	if(n==1)

	{

		puts("0");return 0;

	}

	for(int i =sqrt(n);i>0;--i){

		if(n%i==0){

			cout<<n/i+i-2;return 0;

		}

	}

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cmath>

typedef long long ll;

using namespace std;



int main()

{

	ll n;

	scanf("%lld",&n);

	ll ans=0;

	ll ans1=0;

	for(ll i=sqrt(n)+1;i>=1;i--)

	{

		if(n%i==0)

		{

			ans=i;

			ans1=n/i;

			break;

		}

	}

	if(ans==1)

	printf("%lld\n",n-1);

	else

	printf("%lld\n",ans+ans1-2);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cmath>

typedef long long int ll;

using namespace std;

int main(){

    ll n; cin>>n;

    ll t=sqrt(n);

    ll ans;

    bool m=true;

    for(;t>=2;t--){

        if(n%t==0) {

            m=false;

            ans=n/t+t-2;

            break;

        }

    }

    if(m) ans=n-1;

    cout<<ans;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cmath>

typedef long long ll;

using namespace std;



int main()

{

	ll n;

	scanf("%lld",&n);

	ll ans=0;

	ll ans1=0;

	for(ll i=sqrt(n)+1;i>=1;i--)

	{

		if(n%i==0)

		{

			ans=i;

			ans1=n/i;

			break;

		}

	}

	if(ans==1)

	printf("%lld\n",n-1);

	else

	printf("%lld\n",ans+ans1-2);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



int main()

{

    long long n , ans;



    cin >> n;



    ans = n;



    for(long long i = 1; i * i <= n; i++)

    {

        if(n % i == 0)

        {

            ans = min(ans, i + n/i - 2);

        }

    }

    cout << ans << endl;

    return 0;

}


// Optimized solution to the same problem (faster):
/**

 * Created By: Anonyman637

 * Created On: 3/6/2020 6:27:28 AM

 */



/* =============================================================================

   ================================== HEADERS ==================================

   ========================================================================== */



#include <cstdio>

#include <string>

#include <cmath>



/* =============================================================================

   ================================= TYPEDEFS ==================================

   ========================================================================== */



typedef char i8;

typedef short i16;

typedef int i32;

typedef long long i64;



typedef unsigned char ui8;

typedef unsigned short ui16;

typedef unsigned int ui32;

typedef unsigned long long ui64;



using namespace std;



/* =============================================================================

   ================================== MACROS ===================================

   ========================================================================== */



#ifdef DEBUG

#define debug(format, ...) printf(format, __VA_ARGS__)

#else

#define debug(format, ...) 

#endif



#ifdef FILEIO

#define INFILE "fileio\\"__FILE__"In.txt"

#define OUTFILE "fileio\\"__FILE__"Out.txt"

#endif



/* =============================================================================

   ================================== GLOBALS ==================================

   ========================================================================== */





/* =============================================================================

   =================================== SETUP ===================================

   ========================================================================== */



i32 setup() {



#ifdef FILEIO

        if(freopen(INFILE, "r", stdin) == NULL) return 401;

        if(freopen(OUTFILE, "w", stdout) == NULL) return 402;

#endif



        return 0;

}





/* =============================================================================

   ================================= FUNCTIONS =================================

   ========================================================================== */



i32 main() {



        i32 errorInSetup = setup();

        if (errorInSetup) exit(errorInSetup);



        i64 i, t;

        i64 n, sqrtN, steps;

        scanf("%lld", &n);

        sqrtN = ceil(sqrt((double) n));

        for (i = sqrtN; i > 0; i--) {

                if (n % i == 0) {

                        steps = (n / i) + i - 2;

                        break;

                }

        }



        printf("%lld", steps);

        

        return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#include <math.h>

using namespace std;



int main()

{

    long long int N,m;

    cin >>N;

    m=sqrt(N);

    while((N%m)!=0){

        m--;

    }

    m=m+(N/m)-2;

    cout << m;

}


// Optimized solution to the same problem (faster):
/**

 * Created By: Anonyman637

 * Created On: 3/6/2020 6:27:28 AM

 */



/* =============================================================================

   ================================== HEADERS ==================================

   ========================================================================== */



#include <cstdio>

#include <string>

#include <cmath>



/* =============================================================================

   ================================= TYPEDEFS ==================================

   ========================================================================== */



typedef char i8;

typedef short i16;

typedef int i32;

typedef long long i64;



typedef unsigned char ui8;

typedef unsigned short ui16;

typedef unsigned int ui32;

typedef unsigned long long ui64;



using namespace std;



/* =============================================================================

   ================================== MACROS ===================================

   ========================================================================== */



#ifdef DEBUG

#define debug(format, ...) printf(format, __VA_ARGS__)

#else

#define debug(format, ...) 

#endif



#ifdef FILEIO

#define INFILE "fileio\\"__FILE__"In.txt"

#define OUTFILE "fileio\\"__FILE__"Out.txt"

#endif



/* =============================================================================

   ================================== GLOBALS ==================================

   ========================================================================== */





/* =============================================================================

   =================================== SETUP ===================================

   ========================================================================== */



i32 setup() {



#ifdef FILEIO

        if(freopen(INFILE, "r", stdin) == NULL) return 401;

        if(freopen(OUTFILE, "w", stdout) == NULL) return 402;

#endif



        return 0;

}





/* =============================================================================

   ================================= FUNCTIONS =================================

   ========================================================================== */



i32 main() {



        i32 errorInSetup = setup();

        if (errorInSetup) exit(errorInSetup);



        i64 i, t;

        i64 n, sqrtN, steps;

        scanf("%lld", &n);

        sqrtN = ceil(sqrt((double) n));

        for (i = sqrtN; i > 0; i--) {

                if (n % i == 0) {

                        steps = (n / i) + i - 2;

                        break;

                }

        }



        printf("%lld", steps);

        

        return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int main()

{



   long long int n,i,k=0,j,l,m,sum;

   cin>>n;

 vector<long long int>a;

   for(i=1;i*i<=n;i++)

   {

       sum=0;

       if(n%i==0)

       {

          sum+=i;

       }

       if(n%(n/i)==0)

       {

       sum+=n/i;

   }

   if(sum!=0){

   a.push_back(sum);

   }

   }

  m=999999999999;

  for(j=0;j<a.size();j++)

  {

      if(a[j]<m)

      {

          m=a[j];

      }

  }



cout<<m-2<<endl;



}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<math.h>

int main()

{

    long long int i,j,x,p,k,mn,N;

    int c=0;





    long long int A[10000];

    scanf("%lld",&N);



    x=sqrt(N);



    for(int i=1,k=0; i<=x; i++)

    {

        if( N%i==0)

        {





                j=N/i;

                p=i+j-2;

                c=c+1;







                A[k]=p;





                k++;



        }



    }









    mn=A[0];

    for(int k=1; k<c; k++)

    {

        if(A[k]<mn)

        {

            mn=A[k];



        }

    }

    printf("%lld\n",mn);







    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



#define ll long long





int main() {

	ll n;

	cin >> n;

	ll sqr = sqrt(n);

	

	for(int i = sqr; i > 0; i--) {

		if(n%i == 0) {

			printf("%lld\n", i+n/i-2);

			return 0;

		}

	}

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<math.h>

int main()

{

    long long int i,j,x,p,k,mn,N;

    int c=0;





    long long int A[10000];

    scanf("%lld",&N);



    x=sqrt(N);



    for(int i=1,k=0; i<=x; i++)

    {

        if( N%i==0)

        {





                j=N/i;

                p=i+j-2;

                c=c+1;







                A[k]=p;





                k++;



        }



    }









    mn=A[0];

    for(int k=1; k<c; k++)

    {

        if(A[k]<mn)

        {

            mn=A[k];



        }

    }

    printf("%lld\n",mn);







    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

typedef long long int ll;

using namespace std;

int main()

{

    ll i,n,j,x,y,m=1e12+7;

    cin>>n;



    for(i=1; i<=sqrt(n); i++)

    {

        if(n%i==0)

        {

            x=i;

            y=n/i;

            if(x+y<m)

                m=x+y;

        }

    }

    cout<<m-2<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<math.h>

int main()

{

    long long int i,j,x,p,k,mn,N;

    int c=0;





    long long int A[10000];

    scanf("%lld",&N);



    x=sqrt(N);



    for(int i=1,k=0; i<=x; i++)

    {

        if( N%i==0)

        {





                j=N/i;

                p=i+j-2;

                c=c+1;







                A[k]=p;





                k++;



        }



    }









    mn=A[0];

    for(int k=1; k<c; k++)

    {

        if(A[k]<mn)

        {

            mn=A[k];



        }

    }

    printf("%lld\n",mn);







    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#pragma GCC optimize ("03")

#pragma GCC optimize ("unroll-loops")

#define ll long long

#define ms(a,b) memset(a,b,sizeof(a))

#define endl '\n'

#define pb push_back

#define mp(a,b) make_pair(a,b)

#define mpp(a,b,c) make_pair(a,make_pair(b,c))

#define fi first

#define se second

#define rep(a,b,c) for(int a=b;a<=c;a++)

#define repp(a,b,c) for(int a=b;a>=c;a--)



int main(){

/////////////////////////////////////////////

//	ios_base::sync_with_stdio(0);

//	cin.tie(0); cout.tie(0);

/////////////////////////////////////////////

	ll a,res=1e18;

	cin >> a;

	ll sqr;

	sqr = sqrt(a);

	repp(i,sqr,1){

		if(a%i==0){

			res = min(res,abs(i-1)+abs((a/i)-1));

		}

	}

	cout << res << endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cmath>

#define ll long long

using namespace std;

int main(){

    ll n,k;

    scanf("%lld",&n);

    k=ceil(sqrt(n));

    while(k){

        if(n%k==0){

            printf("%lld",k-1+n/k-1);

            return 0;

        }

        k--;

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
/*	MASTER HAS FAILED MORE TIMES

	THAN BEGINNER HAS EVER TRIED

*/



#include <bits/stdc++.h>



using namespace std;



#define endl            '\n'

#define mem(a, n)       memset(a, n, sizeof(a))

#define repeat(n)       for(int i=0; i<n; i++)

#define Unique(n)       (n).erase(unique(all(n)), (n).end())

#define isPowerOfTwo(n) (n && !(n & (n - 1)))

#define NumofDigits(n)  ((int)log10(n)+1)

#define all(a)          a.begin(), a.end()



unsigned long long pow(long long base, long long power);



long long gcd(long long a, long long b){ return a%b ? gcd(b, a%b) : b; }

long long lcm(long long a, long long b){ return a*b/gcd(a, b); }



void quicken(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }



/*

    Special functions:

        find_by_order(k) --> returns iterator to the kth largest element counting from 0

        order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

*/



int main(){

    quicken();



    long long n, ans=LLONG_MAX; cin >> n;

    for(int i=1; i<=sqrt(n); i++)

        if(!(n%i))

            ans = min(ans, i+n/i-2);



    cout << ans;



    return 0;

}



unsigned long long pow(long long base, long long power){

    if(power==0) return 1;

    if(power==1) return base;



    unsigned long long ans = pow(base, power/2);

    ans *= ans; /// ans = (ans%mod)*(ans%mod);



    if(power&1) return ans*base; /// (ans%mod)*(base%mod);

    return ans;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cmath>

#define ll long long

using namespace std;

int main(){

    ll n,k;

    scanf("%lld",&n);

    k=ceil(sqrt(n));

    while(k){

        if(n%k==0){

            printf("%lld",k-1+n/k-1);

            return 0;

        }

        k--;

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;





int main()

{

    long long n ;   cin>>n ;

    long long ans=n;

    int sq=sqrt(n);

    for(int i=1 ; i<=sq ;i++)

    {

        if(n%i==0)

            ans = min(ans , i+n/i-2);

    }

    cout<<ans ;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cmath>

#define ll long long

using namespace std;

int main(){

    ll n,k;

    scanf("%lld",&n);

    k=ceil(sqrt(n));

    while(k){

        if(n%k==0){

            printf("%lld",k-1+n/k-1);

            return 0;

        }

        k--;

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



#define fori( tt,aa)      for(long long i= tt; i<aa; i++)

#define forj( yy,bb)      for(long long j=yy; j<bb; j++)

#define fork( uu,cc)      for(long long k=uu; k<cc; k++)

#define sz(v)    v.size()

#define all(v)   v.begin(), v.end()

#define endl "\n";

#define pb push_back

#define pf push_front

#define popb pop_back

#define popf pop_front

#define EPS 1e-7

#define F first

#define S second

#define THINK_TWICE_CODE_ONCE; fast();



typedef long long ll;

typedef long double ld;

typedef double dd;

typedef string String;

typedef string str;

typedef vector<int> vecint;

typedef vector<ll> vecll;

typedef pair<int, int> pii;





void accuSum2D(vector<vector<int>>&a){

    //accumulate each row

    fori(1, 101)

     forj(1, 101)

        a[i][j] +=a[i][j-1];



    //accumulate each col

    forj(1, 101)

     fori(1, 101)

        a[i][j] +=a[i-1][j];

}



int sum_range(int i, int j, int k, int l, vector<vector<int>>&s){

    return s[k][l] - s[k][j-1] - s[i-1][l] + s[i-1][j-1];

}



void fast(){

    cin.tie(0);

    cout.tie(0);

    cin.sync_with_stdio(0);

}



ld pow (ll a, ll b);

ll numOfDigits(ll n);

int main()

{

    THINK_TWICE_CODE_ONCE;

    //freopen("great Vova Wall1.txt", "r", stdin);

    ll n; cin>>n;

    ll sq = sqrt(n);

    ll mn = n-1;

    fori(1, sq+1){

        if(!(n%i)){

            ll div = n/i;

            ll mn2 = min(div, i), mx2 = max(div, i);

            mn = min(mn, mx2 + mn2 -2);

        }

    }

    cout<<mn;

    return 0;

}

ld pow (ll a, ll b){

    ld pow = 1;

    fori(0,b)

        pow *=a;

    return pow;

}



ll numOfDigits(ll n){

    if(!n) return 1;

    return (ll)(log10(n)+1);

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cmath>

#define ll long long

using namespace std;

int main(){

    ll n,k;

    scanf("%lld",&n);

    k=ceil(sqrt(n));

    while(k){

        if(n%k==0){

            printf("%lld",k-1+n/k-1);

            return 0;

        }

        k--;

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5+10 , OO = 0x3f3f3f3f;



#define clr(arr,val) memset(arr , val , sizeof (arr))

#define loop(i,n) for(int i = 0;i < int(n);i++)

#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)

#define xloop(i,a,b) for(int i = int(a);i <= int(b);i++)

#define range(n) for(int &x : n) cin >> x;

#define ALL(v) ((v).begin()) , ((v).end())

#define SZ(v)  ((int)((v).size()))

typedef pair <int,int> pii ;

typedef vector < pii > vii ;

typedef vector < int > vi;

int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction

//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction

//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

//freopen("input.txt", "r", stdin);

//freopen("output.txt", "w", stdout);





int n;





int main()

{   



      ios_base::sync_with_stdio(0) , cin.tie(0);cout.tie(0);





      ll n;

      cin >> n;

      ll ans = 1e18;

      for (ll i=1 ;i*i<=n;i++) {

            ll div = n/i;

            if ( i*div == n) 

                  ans = min(ans,i+div-2);

      }

      cout << ans << endl;





      return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cmath>

#define ll long long

using namespace std;

int main(){

    ll n,k;

    scanf("%lld",&n);

    k=ceil(sqrt(n));

    while(k){

        if(n%k==0){

            printf("%lld",k-1+n/k-1);

            return 0;

        }

        k--;

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include "bits/stdc++.h"

#include "sstream"

#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

const int N=1e5+1;

const double EulerConstant = exp(-1);

int main() {

        quick

long long ans=LONG_LONG_MAX,n; cin>>n;

for(long long i=1;i*i<=n;i++){

    if(n%i==0){

        if(n/i==i){ans=min(ans,(i-1)+(n/i-1));}

        else{

            ans=min(ans,(i-1)+(n/i-1));

            ans=min(ans,(n/i-1)+(n-1));

        }

    }

}

cout<<ans;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cmath>

#define ll long long

using namespace std;

int main(){

    ll n,k;

    scanf("%lld",&n);

    k=ceil(sqrt(n));

    while(k){

        if(n%k==0){

            printf("%lld",k-1+n/k-1);

            return 0;

        }

        k--;

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <bits/stdc++.h>

using namespace std;



#define pb push_back

#define F first

#define S second

#define fo(i,a,b)  for(int i = a; i < b; i++)



using ll = long long;

using ld = long double;

using ul = unsigned long long;

using ii = pair<int, int>;

#define Mosta     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define ReadFile            freopen("input.in","r",stdin)

#define WriteFile           freopen("output.txt","w",stdout)

const ll mod7 = 1000000007,mod = 1000000000,OO = 0x3f3f3f3f;

const ld EPS = 1e-7;

double Pi=acos(-1);

const ld rad=Pi/180.0;

ll power(ll x, ll y, ll p)

{

    ll res = 1;

    while (y > 0)

    {

        if (y & 1)

            res = (res*x) % p;

        y = y>>1;

        x = (x*x) % p;

    }

    return res;

}

ll nCr (ll n,ll m)

{

        return(m == 0)?1:n*nCr(n-1,m-1)/m;

}

/*****************************************************/



int main()

{

    ll n, ans= 1e12;

    cin >> n;

    

    for(ll i=1;i*i<=n;i++){

        if(n%i==0)

            ans=min(ans,(i+n/i));

    }



     cout << ans-2 << endl;





    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cmath>

#define ll long long

using namespace std;

int main(){

    ll n,k;

    scanf("%lld",&n);

    k=ceil(sqrt(n));

    while(k){

        if(n%k==0){

            printf("%lld",k-1+n/k-1);

            return 0;

        }

        k--;

    }

    return 0;

}


// Fastest known solution for this problem: