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

}




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

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

}




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

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

}


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

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

}

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

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

}


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

    }
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <vector>

#include <map>

#include <set>

#include <string>

#include <cmath>

#include <iomanip>

#include <queue>

#include <unordered_map>

#include <unordered_set>

#include <bitset>

#include <cassert>

#include <cstring>

#include <climits>



using namespace std;



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

#define REP(i, n) FOR(i, 0, n)

#define SORT(c) sort((c).begin(), (c).end())



typedef long long ll;

typedef pair<int, int> P;

typedef vector<int> V;

typedef map<int, int> M;



constexpr ll INF = 1e18;

constexpr ll MOD = 1e9 + 7;

constexpr double PI = 3.14159265358979323846;

constexpr int dx[] = {0, 0, 1, -1};

constexpr int dy[] = {1, -1, 0, 0};



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);



    int n, a[112345];



    cin >> n;

    REP(i, n)

    cin >> a[i];



    int res = 0;



    bool used[112345] = {false};



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

    {

        int cnt = 0;

        int exa = -1;

        REP(j, n)

        {

            if ((a[j] == (1 << i)) && !used[j])

                exa = j;

            if (a[j] & (1 << i))

            {

                cnt++;

                a[j] -= (1 << i);

            }

        }



        if (cnt % 2)

        {

            if (exa == -1)

            {

                cout << -1 << endl;

                return 0;

            }

            else

            {

                used[exa] = true;

                a[exa]--;

                a[exa] += (1 << i);

                res++;

            }

        }

    }



    cout << res << endl;



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.116437136449537x):
#include <iostream>

#include <algorithm>

#include <vector>

#include <map>

#include <set>

#include <string>

#include <cmath>

#include <iomanip>

#include <queue>

#include <unordered_map>

#include <unordered_set>

#include <bitset>

#include <cassert>

#include <cstring>

#include <climits>



using namespace std;



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

#define REP(i, n) FOR(i, 0, n)

#define SORT(c) sort((c).begin(), (c).end())



typedef long long ll;

typedef pair<int, int> P;

typedef vector<int> V;

typedef map<int, int> M;



constexpr ll INF = 1e18;

constexpr ll MOD = 1e9 + 7;

constexpr double PI = 3.14159265358979323846;

constexpr int dx[] = {0, 0, 1, -1};

constexpr int dy[] = {1, -1, 0, 0};



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);



    int n, a[112345];

    int x = 0;



    cin >> n;

    REP(i, n)

    {

        cin >> a[i];

        x ^= a[i];

    }



    int res = 0;



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

    {

        if (!(x & (1 << i)))

            continue;



        REP(j, n)

        {

            if ((a[j] ^ (a[j] - 1)) == (1 << (i + 1)) - 1)

            {

                res++;

                a[j] = 0;

                x ^= (1 << (i + 1)) - 1;



                break;

            }

        }

    }



    if (x == 0)

        cout << res << endl;

    else

        cout << -1 << endl;



    return 0;

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

}

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

}
// Slower C++ solution:
/*

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

}


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

#include <math.h>

long long int factors (long long int n);

int main()

{

    long long int n,i,y,x;

    double pro;

    scanf("%lld", &n);

    if(factors(n)==0)printf("%lld",n-1);

    else{

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

        pro=n/i;

        if(pro*i==n){

            y=pro;

            x=n/y;

            break;

        }

        else continue;

    }

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

    return 0;

}}

long long int factors (long long int n)

{

    long long int i,u=0;

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

        if(n%i==0){

            u++;

        }

    }

    return u;

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

}

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

#include <math.h>

long long int factors (long long int n);

int main()

{

    long long int n,i,y,x;

    double pro;

    scanf("%lld", &n);

    if(factors(n)==0)printf("%lld",n-1);

    else{

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

        pro=n/i;

        if(pro*i==n){

            y=pro;

            x=n/y;

            break;

        }

        else continue;

    }

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

    return 0;

}}

long long int factors (long long int n)

{

    long long int i,u=0;

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

        if(n%i==0){

            u++;

        }

    }

    return u;

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

}

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

#include <math.h>

long long int factors (long long int n);

int main()

{

    long long int n,i,y,x;

    double pro;

    scanf("%lld", &n);

    if(factors(n)==0)printf("%lld",n-1);

    else{

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

        pro=n/i;

        if(pro*i==n){

            y=pro;

            x=n/y;

            break;

        }

        else continue;

    }

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

    return 0;

}}

long long int factors (long long int n)

{

    long long int i,u=0;

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

        if(n%i==0){

            u++;

        }

    }

    return u;

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

}


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

#include <math.h>

long long int factors (long long int n);

int main()

{

    long long int n,i,y,x;

    double pro;

    scanf("%lld", &n);

    if(factors(n)==0)printf("%lld",n-1);

    else{

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

        pro=n/i;

        if(pro*i==n){

            y=pro;

            x=n/y;

            break;

        }

        else continue;

    }

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

    return 0;

}}

long long int factors (long long int n)

{

    long long int i,u=0;

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

        if(n%i==0){

            u++;

        }

    }

    return u;

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

		}

	}

}

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

#include <math.h>

long long int factors (long long int n);

int main()

{

    long long int n,i,y,x;

    double pro;

    scanf("%lld", &n);

    if(factors(n)==0)printf("%lld",n-1);

    else{

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

        pro=n/i;

        if(pro*i==n){

            y=pro;

            x=n/y;

            break;

        }

        else continue;

    }

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

    return 0;

}}

long long int factors (long long int n)

{

    long long int i,u=0;

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

        if(n%i==0){

            u++;

        }

    }

    return u;

}