stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 4.172571489157682x):
/**

 * 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;

}
// Slower C++ solution:
#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;



}


// Faster C++ solution for the same problem (measured speedup: 1.8008302847351276x):
#include<stdio.h>

#include<math.h>

int main()

{

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

    int c=0;

    double N;



    long long int A[10000];

    scanf("%lf",&N);



    x=sqrt(N);



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

    {

        if( fmod(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;

}
// Slower C++ solution:
#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;

		}

	}

}

// Faster C++ solution for the same problem (measured speedup: 1.6951027091992787x):
#include<stdio.h>

#include<math.h>

int main()

{

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

    int c=0;

    double N;



    long long int A[10000];

    scanf("%lf",&N);



    x=sqrt(N);



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

    {

        if( fmod(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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.7393650583274605x):
#include<stdio.h>

#include<math.h>

int main()

{

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

    int c=0;

    double N;



    long long int A[10000];

    scanf("%lf",&N);



    x=sqrt(N);



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

    {

        if( fmod(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;

}
// Slower C++ solution:
#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;



}


// Faster C++ solution for the same problem (measured speedup: 4.20677507341629x):
#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;

}
// Slower C++ solution:
#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;

		}

	}

}

// Faster C++ solution for the same problem (measured speedup: 3.9597933710831548x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 4.06319109189096x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 3.895582020422794x):
#include <stdio.h>

#include <math.h>



int main()

{

    long long int n, i, j, flag;

    scanf("%lld", &n);

    flag = n;



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

        if(n%i == 0 && (i+(n/i)-2)<flag)

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

    }

    printf("%lld", flag);

    return 0;

}
// Slower C++ solution:
/*	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;

}


// Faster C++ solution for the same problem (measured speedup: 3.955361252188024x):
#include <stdio.h>

#include <math.h>



int main()

{

    long long int n, i, j, flag;

    scanf("%lld", &n);

    flag = n;



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

        if(n%i == 0 && (i+(n/i)-2)<flag)

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

    }

    printf("%lld", flag);

    return 0;

}
// Slower C++ solution:
#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 ;

}

// Faster C++ solution for the same problem (measured speedup: 3.855322687405839x):
#include <stdio.h>

#include <math.h>



int main()

{

    long long int n, i, j, flag;

    scanf("%lld", &n);

    flag = n;



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

        if(n%i == 0 && (i+(n/i)-2)<flag)

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

    }

    printf("%lld", flag);

    return 0;

}
// Slower C++ solution:
#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);

}


// Faster C++ solution for the same problem (measured speedup: 3.9157016212774476x):
#include <stdio.h>

#include <math.h>



int main()

{

    long long int n, i, j, flag;

    scanf("%lld", &n);

    flag = n;



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

        if(n%i == 0 && (i+(n/i)-2)<flag)

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

    }

    printf("%lld", flag);

    return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 3.952770480206384x):
#include <stdio.h>

#include <math.h>



int main()

{

    long long int n, i, j, flag;

    scanf("%lld", &n);

    flag = n;



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

        if(n%i == 0 && (i+(n/i)-2)<flag)

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

    }

    printf("%lld", flag);

    return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 3.9371193632475348x):
#include <stdio.h>

#include <math.h>



int main()

{

    long long int n, i, j, flag;

    scanf("%lld", &n);

    flag = n;



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

        if(n%i == 0 && (i+(n/i)-2)<flag)

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

    }

    printf("%lld", flag);

    return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 3.8891857151622675x):
#include <stdio.h>

#include <math.h>



int main()

{

    long long int n, i, j, flag;

    scanf("%lld", &n);

    flag = n;



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

        if(n%i == 0 && (i+(n/i)-2)<flag)

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

    }

    printf("%lld", flag);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main()

{

    long long n,mx=0;

    cin >> n;

    long long i,arr[10000];

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

    {

        if(n%i==0)

        {

            mx=i;

            break;

        }

    }

    cout << mx-1 + n/mx-1 << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.8183277493654586x):
#include <stdio.h>

#include <math.h>



int main()

{

    long long int n, i, j, flag;

    scanf("%lld", &n);

    flag = n;



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

        if(n%i == 0 && (i+(n/i)-2)<flag)

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

    }

    printf("%lld", flag);

    return 0;

}
// Slower C++ solution:
/*

Md.Shahnewaz Siddique Labib

Dept. of CSE

IUT,19

*/

#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);

#define vi vector<int>

#define pii pair<int, int>

#define vpii vector<pair<int, int>>

#define ll long long

#define ld long double

#define pb push_back

#define mp make_pair



using namespace std;



int main(){

    fastio;

    ll n, moves;

    cin >> n;

    moves = n;

    for(long long i = 1; i*i < n + 1; i++) if(n%i == 0) moves = min(moves, i + n/i - 2);

    cout << moves;

}


// Faster C++ solution for the same problem (measured speedup: 3.9381806531628625x):
#include <stdio.h>

#include <math.h>



int main()

{

    long long int n, i, j, flag;

    scanf("%lld", &n);

    flag = n;



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

        if(n%i == 0 && (i+(n/i)-2)<flag)

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

    }

    printf("%lld", flag);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



int main() {

    uint64_t n;

    cin >> n;



    uint64_t minima = UINT64_MAX;

    for (uint64_t x = 1; x*x <= n; x++) {

        if (n % x == 0) {

            uint64_t y = n / x;

            minima = min(minima, (x + y - 2));

        }

    }



    cout << minima << endl;

}

// Faster C++ solution for the same problem (measured speedup: 3.8416904700647407x):
#include <stdio.h>

#include <math.h>



int main()

{

    long long int n, i, j, flag;

    scanf("%lld", &n);

    flag = n;



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

        if(n%i == 0 && (i+(n/i)-2)<flag)

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

    }

    printf("%lld", flag);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



int main()

{

    long long n  , sum=1e18;

    cin>>n;

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

    {

        if( n%i==0 )

        {

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

        }

    }

    cout<<sum<<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.906632795410006x):
#include <stdio.h>

#include <math.h>



int main()

{

    long long int n, i, j, flag;

    scanf("%lld", &n);

    flag = n;



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

        if(n%i == 0 && (i+(n/i)-2)<flag)

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

    }

    printf("%lld", flag);

    return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 4.26693586920936x):
#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;

}