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

using namespace std;



int l[200010], r[200010], lqz[200010], rqz[200010], s[200010];



int main()

{

	int n;

	scanf("%d", &n);

	for (int i = 0; i < n; ++i)

	{

		scanf("%d%d", &l[i], &r[i]);

		lqz[l[i]]++;

		rqz[r[i]]++;

		s[l[i]]++;

		s[r[i]]--;

	}

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

	{

		lqz[i] += lqz[i - 1];

		rqz[i] += rqz[i - 1];

		s[i] += s[i - 1];

	}

	int ans1(0), ans2(0);

	for (int i = 0; i < n; ++i)

		ans1 = max(ans1, lqz[r[i] - 1] - rqz[l[i]]);

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

		ans2 = max(ans2, s[i]);

	printf("%d %d\n", ans1, ans2);

	

	return 0;

}


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

#define LL long long

#define N 200100

using namespace std;



int cnt[N],a[N],b[N];

int l[N],r[N];

int n,ans1,ans2,m;



int main()

{

	scanf("%d",&n); m=0;

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

	{ 

		scanf("%d %d",&l[i],&r[i]); m=max(m,r[i]);

		cnt[l[i]]++; cnt[r[i]]--;

		a[l[i]]++;   b[r[i]]++;

	}

	for (int i=1;i<=m;i++) a[i]+=a[i-1],b[i]+=b[i-1],cnt[i]+=cnt[i-1];

	for (int i=1;i<=n;i++) ans1=max(ans1,n-(n-a[r[i]-1])-b[l[i]]);

	for (int i=1;i<=m;i++) ans2=max(ans2,cnt[i]);

	printf("%d %d\n",ans1,ans2);

}


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

#define vi vector<int>

#define pb push_back

#define LIM 210005



using namespace std;



vi lft,rgt;

int n, xx[LIM], yy[LIM];



#define MAX 200105



int arr[LIM];



int notun()

{

//    int n;

//    sf(n);

    for(int i=0; i<n; i++)

    {

//        int a,b;



//        sff(a,b);

        arr[ xx[i] ]++;

        arr[ yy[i] ]--;

    }



    int mx = INT_MIN;



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

    {

        arr[i] += arr[i-1];

        mx = max(mx,arr[i]);

    }



    cout << " " << mx << endl;







    return 0;

}



int main() {

    scanf("%d", &n);

    for(int i=0; i<n; i++) {

        int x,y;

        scanf("%d %d", &x,&y);

        xx[i] = x; yy[i] = y;

        lft.pb(x); rgt.pb(y);

    }

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

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



    int ans = 0;

    for(int i=0; i<n; i++) {

        int pise = upper_bound(rgt.begin(), rgt.end(), xx[i])-rgt.begin();

        int samne= n-(lower_bound(lft.begin(), lft.end(), yy[i])-lft.begin());

        ans = max( ans, n - pise - samne );

//        cout << i << ' ' << pise << ' ' << samne << endl;

    }

    cout << ans ;



    notun();

}




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

#define LL long long

#define N 200100

using namespace std;



int cnt[N],a[N],b[N];

int l[N],r[N];

int n,ans1,ans2,m;



int main()

{

	scanf("%d",&n); m=0;

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

	{ 

		scanf("%d %d",&l[i],&r[i]); m=max(m,r[i]);

		cnt[l[i]]++; cnt[r[i]]--;

		a[l[i]]++;   b[r[i]]++;

	}

	for (int i=1;i<=m;i++) a[i]+=a[i-1],b[i]+=b[i-1],cnt[i]+=cnt[i-1];

	for (int i=1;i<=n;i++) ans1=max(ans1,n-(n-a[r[i]-1])-b[l[i]]);

	for (int i=1;i<=m;i++) ans2=max(ans2,cnt[i]);

	printf("%d %d\n",ans1,ans2);

}


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

using namespace std;

const int maxn=2*1e5+100;

int a[maxn],b[maxn],s[maxn],sum[maxn],rr[maxn],ll[maxn];

int main()

{

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

    int n,t,last,ans2=0,ans1=0;

    scanf("%d",&n);

    priority_queue<int,vector<int>,greater<int> >r;

    priority_queue<int,vector<int>,less<int> >l;

    for(int i=0; i<n; i++)

    {

        scanf("%d %d",&a[i],&b[i]);

        s[a[i]]++,s[b[i]]--;

        l.push(a[i]),r.push(b[i]);

    }

    t=r.top(),r.pop();

    rr[last=t]=1;

    while(!r.empty())

    {

        t=r.top(),r.pop();

        rr[t]=rr[last]+1;

        last=t;

    }

    t=l.top(),l.pop();

    ll[last=t]=1;

    while(!l.empty())

    {

        t=l.top(),l.pop();

        ll[t]=ll[last]+1;

        last=t;

    }

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

        if(!rr[i])rr[i]=rr[i-1];

    for(int i=100000; i>=0; i--)

        if(!ll[i])ll[i]=ll[i+1];

    for(int i=0; i<n; i++)

        ans1=max(n-ll[b[i]]-rr[a[i]],ans1);

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

        ans2=max(s[i]=s[i-1]+s[i],ans2);

    printf("%d %d\n",ans1,ans2);

}




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

#include<iostream>

#include<string>

#include<stack>

#include<algorithm>

#include<cstdio>

#include<map>

#include<cmath>

#include<queue>

#include<iomanip>

#include<cstring>

#include<list>

#include<typeinfo>

#include<vector>



using namespace std;

const int maxn = 2e5+10;

int ans1,ans2,a[maxn],b[maxn],r[maxn],MAX;

int sc[maxn];

int xc[maxn];

int main()

{

    int n;

    cin>>n;

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

    {

        cin>>a[i]>>b[i];

        sc[a[i]]++;

        xc[b[i]]++;

        r[a[i]]++;

        r[b[i]]--;

        MAX = max(MAX, b[i]);

    }

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

    {

        sc[i]+= sc[i-1];

        xc[i]+= xc[i-1];

    }

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

        ans1=max(ans1,sc[b[i]-1]-xc[a[i]]);

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

    {

        r[i]+=r[i-1];

        ans2 = max(ans2,r[i]);

    }

    cout<<ans1<<' '<<ans2<<endl;



    return 0;

}




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

using namespace std;

const int maxn=2*1e5+100;

int a[maxn],b[maxn],s[maxn],vl[maxn],vr[maxn];

int main()

{

    int n,t,last,ans2=0,ans1=0;

    scanf("%d",&n);

    for(int i=0; i<n; i++)

    {

        scanf("%d %d",&a[i],&b[i]);

        s[a[i]]++,s[b[i]]--;

        vl[a[i]]++,vr[b[i]]++;

    }

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

    {

        ans2=max(s[i]=s[i-1]+s[i],ans2);

        vr[i]+=vr[i-1];

        vl[100001-i]+=vl[100002-i];

    }

    for(int i=0; i<n; i++)ans1=max(n-vl[b[i]]-vr[a[i]],ans1);

    printf("%d %d\n",ans1,ans2);

}




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

#include<iostream>

#include<string>

#include<stack>

#include<algorithm>

#include<cstdio>

#include<map>

#include<cmath>

#include<queue>

#include<iomanip>

#include<cstring>

#include<list>

#include<typeinfo>

#include<vector>



using namespace std;

const int maxn = 2e5+10;

int ans1,ans2,a[maxn],b[maxn],r[maxn],MAX;

int sc[maxn];

int xc[maxn];

int main()

{

    int n;

    cin>>n;

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

    {

        cin>>a[i]>>b[i];

        sc[a[i]]++;

        xc[b[i]]++;

        r[a[i]]++;

        r[b[i]]--;

        MAX = max(MAX, b[i]);

    }

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

    {

        sc[i]+= sc[i-1];

        xc[i]+= xc[i-1];

    }

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

        ans1=max(ans1,sc[b[i]-1]-xc[a[i]]);

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

    {

        r[i]+=r[i-1];

        ans2 = max(ans2,r[i]);

    }

    cout<<ans1<<' '<<ans2<<endl;



    return 0;

}




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

#include <cstdio>

#include <algorithm>

#include <cstring>

#include <cstdlib>



#define FRER() freopen("i.txt", "r", stdin);



using namespace std;



const int maxn = 200000 + 5;



int l[maxn], r[maxn], ml[maxn] = {0}, mr[maxn] = {0}, sum[maxn] = {0};



int main()

{

	int n, ans1 = 0, ans2 = 0;

	scanf("%d", &n);

	for(int i = 0; i < n; ++i) {

		scanf("%d %d", &l[i], &r[i]);

		++sum[l[i]];

		--sum[r[i]];

		++ml[l[i]];

		++mr[r[i]];

	}

	for(int i = 1; i < maxn; ++i) {

		sum[i] += sum[i - 1];

		ml[i] += ml[i - 1];

		mr[i] += mr[i - 1];

		ans2 = max(ans2, sum[i]);

	}

	for(int i = 0; i < n; ++i) {

		ans1 = max(ans1, ml[r[i] - 1] - mr[l[i]]);

	}

	printf("%d %d\n", ans1, ans2);

	return 0;

}


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

#include<iostream>

#include<string>

#include<stack>

#include<algorithm>

#include<cstdio>

#include<map>

#include<cmath>

#include<queue>

#include<iomanip>

#include<cstring>

#include<list>

#include<typeinfo>

#include<vector>



using namespace std;

const int maxn = 2e5+10;

int ans1,ans2,a[maxn],b[maxn],r[maxn],MAX;

int sc[maxn];

int xc[maxn];

int main()

{

    int n;

    cin>>n;

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

    {

        cin>>a[i]>>b[i];

        sc[a[i]]++;

        xc[b[i]]++;

        r[a[i]]++;

        r[b[i]]--;

        MAX = max(MAX, b[i]);

    }

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

    {

        sc[i]+= sc[i-1];

        xc[i]+= xc[i-1];

    }

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

        ans1=max(ans1,sc[b[i]-1]-xc[a[i]]);

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

    {

        r[i]+=r[i-1];

        ans2 = max(ans2,r[i]);

    }

    cout<<ans1<<' '<<ans2<<endl;



    return 0;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
//Bokan ga bokka--nn!!

//Daily Lunch Special Tanoshii !!

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <string>

#include <algorithm>

#include <vector>

#include <queue>

#include <stack>

#include <functional>

#include <iostream>

#include <map>

#include <set>

using namespace std;

typedef pair<int,int> P;

typedef pair<int,P> P1;

typedef pair<P,P> P2;

typedef long long ll;

#define pu push

#define pb push_back

#define mp make_pair

#define eps 1e-7

#define INF 2000000000

#define s(x) scanf("%d",&x)

#define rep(i,x) for(int i=0;i<x;i++)

int a[3005],b[3005];

int dp[3005][2]={};

int main()

{

	int n,t,s;

	scanf("%d %d %d",&n,&t,&s);

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

	{

		scanf("%d %d",&a[i],&b[i]);

	}

	int cur=0;

	int nex=1;

	dp[0][cur]=0;

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

	{

		for(int j=0;j<3005;j++)dp[j][nex]=0;

		for(int j=0;j<=t;j++)

		{

			dp[j][nex]=max(dp[j][nex],dp[j][cur]);

		}

		for(int j=0;j<=t-b[i];j++)

		{

			if(j<s && s<j+b[i]) continue;

			dp[j+b[i]][nex]=max(dp[j+b[i]][nex],dp[j][cur]+a[i]);

		}

		cur=1-cur; nex=1-nex;

	}

	int ret=0;

	for(int i=0;i<=t;i++) ret=max(ret,dp[i][cur]);

	printf("%d\n",ret);

}

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

int max(int a,int b){ return a<b?b:a;}

int n,t,s;

int dp[3005]={},a[3005],b[3005],ret=0;

int main(){

	scanf("%d%d%d",&n,&t,&s);

	for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);

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

		for(int j=t;j>=b[i];j--){

			if(j-b[i]>=s || j<=s){

				dp[j]=max(dp[j],dp[j-b[i]]+a[i]);

			}

			ret=max(ret,dp[j]);

		}

	}

	printf("%d\n",ret);

}

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

using namespace std;

typedef long long LL;

typedef unsigned long long ULL;

const int maxn = 200000 + 5;

const int mod = 10007;

const double PI = acos(-1.0);

const double eps = 1e-10;

int n, a[maxn], c[maxn];

stack<int> stk;

ULL ans ;

int main()

{

    while (~scanf("%d", &n)) {

        memset(c,0,sizeof c);

        int q = 0, m = 233;

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

            scanf("%d", &a[i]);

            c[a[i]]++;

            q = max(q, a[i]); m = min(m, a[i]);

        }

        int flag = 0;

        if (m != (q+1)/2) flag = 1;

        else {

            if ((q%2==1 && c[m]!=2) || (q%2==0 && c[m]!=1)) flag = 1;

            else {

                for (int i=m+1; i<=q; i++) {

                    if (c[i] < 2) {flag = 1; break;}

                }

            }

        }

        if (flag) puts("Impossible");

        else puts("Possible");

    }

    return 0;

}


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

    using namespace std;

    typedef long long LL;

    typedef unsigned long long ULL;

    const int maxn = 200000 + 5;

    const int mod = 10007;

    const double PI = acos(-1.0);

    const double eps = 1e-10;

    int a[maxn], n, l[maxn], r[maxn];

    stack<int> stk;

    ULL ans ;

    int main()

    {

        while (~scanf("%d", &n)) {

            for (int i=1; i<=n; i++) scanf("%d", &a[i]);

            sort(a+1, a+n+1);

            int q = a[n], flag = 0;

            if (a[1] != (q+1)/2) flag = 1;

            else {

                int cnt = 1, now = a[1], i;

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

                    if (a[i] == now) cnt++;

                    else break;

                }

                if ((q%2==1 && cnt!=2) || (q%2==0 && cnt!=1)) flag = 1;

                else {

                    cnt = 0; now = a[i];

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

                        //printf("%d: %d %d\n",i,now,cnt);

                        if (a[i] == now) cnt++;

                        else {

                            if (cnt < 2 || a[i]-now!=1) { //puts("===");

                                flag = 1;

                                break;

                            }

                            cnt = 1; now = a[i];

                        }

                    }

                }

            }

            if (flag) puts("Impossible");

            else puts("Possible");

        }

        return 0;

    }

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

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

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



using namespace std;



typedef long long ll;

typedef pair<int, int> P;



const int MAX_N = (int)1e5 + 5;



bool used[MAX_N];	// この数字を使ったかどうか

bool change[MAX_N];	// この桁が１引く事によって変化するかどうか

bool cand[MAX_N];	// この数字が候補である

int main()

{

	memset(used, false, sizeof(used));

	

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	int N; cin >> N;

	vector<int> a(N, 0);

	rep (i, N) cin >> a[i];



	int ans = 0;

	int res = 0;

	rep (i, N) ans ^= a[i];

	if (ans == 0){

		res = 0;

	}else{



		for(int digit = 31; digit >= 0; --digit){

			memset(cand, false, sizeof(cand));

			memset(change, false, sizeof(change));

			int cnt = 0;

			rep (i, N){

				if (a[i] & (1<<digit)){

					++cnt;

					if (!used[i]) cand[i] |= true;

					if (!used[i] && !((a[i] - 1) & (1<<digit))) change[i] |= true;

				} // end if

			} // end rep



			if (cnt % 2 == 0){

				rep (i, N) used[i] |= change[i];

			}else{

				bool one = false;

				rep (i, N){

					if (!used[i] && change[i]){

						if (!one){

							--a[i];

							++res;

							one |= true;

						} // end if

						used[i] |= true;

					} // end if

				} // end rep

				if (!one){

					res = -1;

					break;

				} // end if

			} // end if

		} // end for

	} // end if

	cout << res << endl;



	return 0;

}

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

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

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



using namespace std;



typedef long long ll;

typedef pair<int, int> P;



const int MAX_N = (int)1e5 + 5;



bool used[MAX_N];	// この数字を使ったかどうか

bool cand[MAX_N];	// この桁が１引く事によって変化するかどうか



int main()

{

	memset(used, false, sizeof(used));

	

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	int N; cin >> N;

	vector<int> a(N, 0);

	rep (i, N) cin >> a[i];



	int res = 0;

	for(int digit = 31; digit >= 0; --digit){

		memset(cand, false, sizeof(cand));

		int cnt = 0;

		rep (i, N){

			if (a[i] & (1<<digit)){

				++cnt;

				if (!used[i] && !((a[i] - 1) & (1<<digit))) cand[i] |= true;

			} // end if

		} // end rep



		if (cnt % 2 == 0){ 

			rep (i, N) used[i] |= cand[i]; // 1 引いて変化するものはもう使えない。よって"使った"にフラグ。

		}else{

			bool one = false;

			rep (i, N){

				if (!used[i] && cand[i]){

					if (!one){

						--a[i];

						++res;

						one |= true;

					} // end if

					used[i] |= true;

				} // end if

			} // end rep

			if (!one){ // 一個もない

				res = -1;

				break;

			} // end if

		} // end if

	} // end for

	cout << res << endl;



	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/*

the top of the losers

*/

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

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

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

#define  allr(v)    ((v).rbegin()),((v).rend())

#define   pb         push_back

#define   mp         make_pair

#define    Lcm(a,b)  ((a*b)/(__gcd(a,b)))

#define    X            real()

#define    Y            imag()

#define    clr(v,d)      memset( v, d ,sizeof(v))

#define   angle(n)      atan2((n.imag()),(n.real()))

#define   vec(a,b)       ((b)-(a))

#define   length(a)      hypot( (a.imag()),(a.real()) )

#define   normalize(a)      (a)/(length(a))

#define    dp(a,b)          (((conj(a))*(b)).real())

#define    cp(a,b)          (((conj(a))*(b)).imag())

#define    lengthsqrt(a)       dp(a,a)

#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))

#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)

#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))

#define    reflection0(m,v)         (conj((v)/(m))*(m))

#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0

#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )

#define     point                    complex<double>

#define     point        complex<double>

#define    cp(a,b)          (((conj(a))*(b)).imag())

#define    PI  acos(-1)

typedef  long long     ll ;

typedef  unsigned long long     ull ;

const double eps= (1e-9);

using namespace std;

using namespace __gnu_pbds;

int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}

int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}

int setBit1(int num, int idx) {return num | (1<<idx);}

ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}

ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}

int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}

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

void solve(ll n){

   ll mi=n*2;

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

      if(n%i==0){

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

      }

   }

   cout<<mi<<endl;



}

int main(){

    ll n;

    cin>>n;

    solve(n);

}


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

#include<math.h>

int main()

{

    long long n;

    scanf("%lld", &n);

    long long x=1;

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

    {

        if((n%i==0) && (((n/i)-i)<((n/x)-x)))

            x=i;

    }

    long long a=x, b=(n/x);

    long long moves=(a+b)-2;

    printf("%lld", moves);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

#define ll long long

#define ld long double

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

using namespace std;

const int N = 2e5 + 5, M = 2 * N + 5;





int main(){

    IO;

    ll n;

    cin >> n;

    ll mn = LLONG_MAX;

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

        if(n % i == 0)

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

    cout << mn << endl;

}

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

#include<math.h>

int main()

{

    long long n;

    scanf("%lld", &n);

    long long x=1;

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

    {

        if((n%i==0) && (((n/i)-i)<((n/x)-x)))

            x=i;

    }

    long long a=x, b=(n/x);

    long long moves=(a+b)-2;

    printf("%lld", moves);

    return 0;

}

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

using namespace std;



int main(int argc, char const *argv[])

{

	long long n;

	cin>>n;

	long long mi=n+1;

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

	{

		if(n%i==0)

		{

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

		}

	}

	cout<<mi-2<<endl;

	return 0;

}

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

#include<math.h>

int main()

{

    long long n;

    scanf("%lld", &n);

    long long x=1;

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

    {

        if((n%i==0) && (((n/i)-i)<((n/x)-x)))

            x=i;

    }

    long long a=x, b=(n/x);

    long long moves=(a+b)-2;

    printf("%lld", moves);

    return 0;

}

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

#include <sstream>

#include <vector>

#include <utility>

#include <map>

#include <algorithm>

#include <string>

#include <string.h>

#include <iomanip>

#include <cmath>

#define ll long long

#define PI 3.14159265358979323846

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

#define rep(i, v) for (int i = 0; i < int(v.size()); i++)

using namespace std;

vector<ll> div(ll n)

{

	vector<ll> v;

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

		if(n%i==0)

				v.push_back((i+n/i)-2);

	}

	return v;

}		

int main()

{

	ll n;

	vector<ll> v;

	cin>>n;

	v=div(n);

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

	cout<<v.front();

	return 0;

}


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

#include<math.h>

int main()

{

    long long n;

    scanf("%lld", &n);

    long long x=1;

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

    {

        if((n%i==0) && (((n/i)-i)<((n/x)-x)))

            x=i;

    }

    long long a=x, b=(n/x);

    long long moves=(a+b)-2;

    printf("%lld", moves);

    return 0;

}

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

using namespace std;



int main()

{

	long long n, i, x, y;

	scanf("%lld", &n);

	for(i=(int)sqrt(n); i>=1; i--)

	{

		if(n%i==0)

		{

			x=i;

			y=n/i;

			printf("%lld", x+y-2);

			return 0;

		}

	}

}

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

#include<math.h>

int main()

{

    long long n;

    scanf("%lld", &n);

    long long x=1;

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

    {

        if((n%i==0) && (((n/i)-i)<((n/x)-x)))

            x=i;

    }

    long long a=x, b=(n/x);

    long long moves=(a+b)-2;

    printf("%lld", moves);

    return 0;

}

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

#include<cmath>



using namespace std;

int main()

{

	long long int c,cc;

	long long int a;

	cin>>a;

	c=1E13;

	for(int i=2;i<=sqrt((long double)a) + 1;i++)

	{

		if(a%i==0)

			c=i+a/i-2;

		cc=min(c,a-1);

	}

	cout<<cc;

	

	



	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;



typedef long long ll;



ll n;



int main(){

	scanf("%lld",&n);

	ll ans = 1e15;

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

		if(n%i==0){

			ll x = i;

			ll y = n/i;

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

		}

	}

	printf("%lld\n",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: