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

#include <cstdio>  

#include <cstring>  

#include <algorithm>  

  

using namespace std;  

const int maxn=2e5+100;  

int par[maxn],sum[maxn];  

int N,K,p,tot;  

  

void init(int n)  

{  

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

        par[i]=i;  

}  

  

int find(int x)  

{  

    if(par[x]==x)  

        return x;  

    return par[x]=find(par[x]);  

}  

void unit(int a,int b)  

{  

    int fx=find(a),fy=find(b);  

    if(fx!=fy)  

        par[fx]=fy;  

}  

bool same(int x,int y)  

{  

    return find(x)==find(y);  

}  

int main()  

{  

    while(~scanf("%d%d",&N,&K))  

    {  

        int ans=0;  

        memset(sum,0,sizeof(sum));  

        memset(par,0,sizeof(par));  

        tot=0;  

        init(N);  

        int t;  

        scanf("%d",&t);  

        sum[t]++;  

        p=t;  

        tot++;  

        for(int i=2;i<=N;i++)  

        {  

            scanf("%d",&t);  

            sum[t]++;  

            if(!same(t,p))  

            {  

                tot++;  

                unit(t,p);  

            }  

        }  

        sort(sum,sum+N+1);  

        if(tot<=K)  

            ans=0;  

        else  

        {  

            int cnt=tot-K;  

            int pos=lower_bound(sum,sum+N+1,1)-sum;  

            while(cnt--)  

                ans+=sum[pos++];         

        }  

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

    }  

    return 0;  

}  

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

#include<sstream>

#include<fstream>

#include<string>

#include<vector>

#include<deque>

#include<queue>

#include<stack>

#include<set>

#include<map>

#include<algorithm>

#include<functional>

#include<utility>

#include<bitset>

#include<cmath>

#include<cstdlib>

#include<ctime>

#include<cstdio>

using namespace std;

int n,k,a[202020],cnt,ans;

int main()

{

	cin>>n>>k;

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

	{

		a[i]=1e9;

	}

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

	{

		int x;

		cin>>x;

		if(a[x]==1e9)

		{

			a[x]=0;

		}

		a[x]++;

	}

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

	{

		if(a[i]<1e9)

		{

			cnt++;

		}

	}

	sort(a,a+n+1);

	for(int i=0;i<cnt-k;i++)

	{

		ans+=a[i];

	}

	cout<<ans<<endl;

	return 0;

}

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

#include <cstdio>  

#include <cstring>  

#include <algorithm>  

  

using namespace std;  

const int maxn=2e5+100;  

int par[maxn],sum[maxn];  

int N,K,p,tot;  

  

void init(int n)  

{  

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

        par[i]=i;  

}  

  

int find(int x)  

{  

    if(par[x]==x)  

        return x;  

    return par[x]=find(par[x]);  

}  

void unit(int x,int y)  

{  

    int fx=find(x),fy=find(y);  

    if(fx!=fy)  

        par[fx]=fy;  

}  

bool same(int x,int y)  

{  

    return find(x)==find(y);  

}  

int main()  

{  

    while(~scanf("%d%d",&N,&K))  

    {  

        int ans=0;  

        memset(sum,0,sizeof(sum));  

        memset(par,0,sizeof(par));  

        tot=0;  

        init(N);  

        int t;  

        scanf("%d",&t);  

        sum[t]++;  

        p=t;  

        tot++;  

        for(int i=2;i<=N;i++)  

        {  

            scanf("%d",&t);  

            sum[t]++;  

            if(!same(t,p))  

            {  

                tot++;  

                unit(t,p);  

            }  

        }  

        sort(sum,sum+N+1);  

        if(tot<=K)  

            ans=0;  

        else  

        {  

            int cnt=tot-K;  

            int pos=lower_bound(sum,sum+N+1,1)-sum;  

            while(cnt--)  

                ans+=sum[pos++];         

        }  

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

    }  

    return 0;  

}  

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

#include<map>

#include<algorithm>

using namespace std;

int s[200000 + 10];

int n, k;



int main() {

	scanf("%d%d", &n, &k);

	int cnt = 0;

	map<int, int> m;

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

		int t;

		scanf("%d", &t);

		if (m.count(t))s[m[t]]++;

		else {

			m[t] = cnt;

			s[cnt++] = 1;

		}

	}

	sort(s, s + cnt);

	int ans = 0;

	for (int i = 0;i < cnt - k;i++)ans += s[i];

	printf("%d", ans);

	return 0;

}

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

#include <algorithm>

#include <map>

#include <vector>

#include <string>

#include <cstdio>

#define INF 100000000



using namespace std;

int dp[205][205] = { 0 }, t[205], a[205], b[205], c[205];

int main(){

	int d, n;

	cin >> d >> n;

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

		cin >> t[i];

	}

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

		cin >> a[j] >> b[j] >> c[j];

	}

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

		for (int j = 0; j < 201; j++) {

			dp[i][j] = -1;

		}

	}

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

		if (a[i] <= t[1] && t[1] <= b[i]) dp[1][i] = 0;

	}

	for (int i = 2; i <= d; i++) {

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

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

				if (a[j] <= t[i] && t[i] <= b[j]&&a[k]<=t[i-1]&&t[i-1]<=b[k]) {

					dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(c[k] - c[j]));

				}

			}

		}

	}

	int ans = -1;

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

		if (ans < dp[d][i]) ans = dp[d][i];

	}

	cout << ans << endl;

	return 0;

}

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

#include <algorithm>

using namespace std;

int d, n;

int t[205] = { 0 }, a[205] = { 0 }, b[205] = { 0 }, c[205] = { 0 };

int dp[205][205] = { 0 };

int main() {

	cin >> d >> n;

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

		cin >> t[i];

	}

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

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

	}

	for (int i = 2; i <= d; i++) {

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

			if (a[j] <= t[i] && t[i] <= b[j]) {

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

					if(a[k]<=t[i-1]&&t[i-1]<=b[k]) dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(c[k] - c[j]));

				}

			}

			else continue;

		}

	}

	int res = 0;

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

		res = max(res, dp[d][j]);

	}

	cout << res << endl;

	return 0;

}


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

#include <cstring>

#include <algorithm>

#define INF (1145141919)

using namespace std;



typedef struct

{

	int mi;

	int ma;

	int f;

} CLOTHES;



CLOTHES clothes[1000];

int T[1000];

int dp[1000][1000];



int main()

{

	memset(dp, -1, sizeof(dp));

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

		dp[0][i] = 0;

	}

	

	int D, N;

	

	scanf("%d %d", &D, &N);

	

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

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

	}

	

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

		scanf("%d %d %d", &clothes[i].mi, &clothes[i].ma, &clothes[i].f);

	}

	

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

		for (int j = 0; j < N; j++){

			for (int k = 0; k < N; k++){

				if (T[i] >= clothes[k].mi && T[i] <= clothes[k].ma && dp[i][j] != -1){

					if (i > 0){

						dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abs(clothes[j].f - clothes[k].f));

					}

					else {

						dp[i + 1][k] = 0;

					}

				}

			}

		}

	}

	

	int maxi = -INF;

	

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

		maxi = max(maxi, dp[D][i]);

	}

	

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

	

	return 0;

}

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

using namespace std;

#define MAX_D (200)

#define MAX_N (200)



int d, n;

int t[MAX_D];

int a[MAX_N], b[MAX_N], c[MAX_N];



int dp[MAX_D + 1][MAX_N];

// dp[ ?????\????????§??????????????? ][ ?????????????????? ] = ????????§????´??????????????¨?



int search(int i, int last)

{

	int &res = dp[i][last];

	

	if (res != -1) return (res);

	

	if (i == d) return (res = 0);

	

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

		if (t[i] < a[j] || b[j] < t[i]) continue;

		int sub = abs(c[last] - c[j]);

		res = max(res, sub + search(i + 1, j));

	}

	

	return res;

}



int main()

{

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

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

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

	}

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

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

	}

	

	memset(dp, -1, sizeof(dp));

	

	int ans = 0;

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

		if (t[0] < a[i] || b[i] < t[0]) continue;

		ans = max(ans, search(1, i));

	}

	

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

	

	return 0;

}

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

#include<string.h>

#include<cstdio>

#include<algorithm>

#include<stack>

#include<queue>

#include<vector>

#include<cmath>

#include<utility>

#define ll long long int

#define ld long double

#define INF 1000000000

#define EPS 0.0000000001

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

using namespace std;

typedef pair<int, int> P;



string str;



int main()

{

  int d,n;

  int degree[205];

  int clothes[200][3];

  int i,j,k;

  int dp[205][205]={};



  cin>>d>>n;

  rep(i,d)

    cin>>degree[i];

  rep(i,n)

    cin>>clothes[i][0]>>clothes[i][1]>>clothes[i][2];



  rep(j,n)

    if(clothes[j][0] > degree[0] || degree[0] > clothes[j][1])

      dp[0][j]=-1;



  for(i=1;i<d;i++)

    rep(j,n){

      if(clothes[j][0] > degree[i] || degree[i] > clothes[j][1]){

	dp[i][j]=-1;

	continue;

      }

      int m=0;

      rep(k,n)

	if(dp[i-1][k] >= 0)

	  m=max(m,dp[i-1][k]+abs(clothes[k][2]-clothes[j][2]));

      dp[i][j]=m;   

    }



  int ans=0;

  rep(j,n)

    ans=max(ans,dp[d-1][j]);

  cout<<ans<<endl;



}

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

#include<algorithm>

#include<cstdio>

#include<cmath>

#include<math.h>

#include<string>

#include<string.h>

#include<stack>

#include<queue>

#include<vector>

#include<utility>

#include<set>

#include<map>

#include<stdlib.h>

#include<iomanip>



using namespace std;



#define ll long long

#define ld long double

#define EPS 0.0000000001

#define INF 1e9

#define MOD 1000000007

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

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

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

#define shosu(x) fixed<<setprecision(x)



typedef vector<int> vi;

typedef pair<int,int> pii;



int main(void) {

  int i,j,k;

  int d,n;

  cin>>d>>n;

  vi t(d),a(n),b(n),c(n);

  rep(i,d)cin>>t[i];

  rep(i,n)cin>>a[i]>>b[i]>>c[i];

  vector<vi> dp(d+1,vi(n,-INF));

  rep(i,n)

    if(a[i]<=t[0]&& t[0]<=b[i])dp[0][i]=0;



  loop(i,1,d)rep(j,n)if(a[j]<=t[i] && t[i]<=b[j])

    rep(k,n)if(a[k]<=t[i-1] && t[i-1]<=b[k])

      dp[i][j]=max(dp[i][j],dp[i-1][k]+abs(c[k]-c[j]));

  int ans=0;

  rep(i,n)ans=max(ans,dp[d-1][i]);

  cout<<ans<<endl;

}

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

using namespace std;

void k(int,int);

int m;

int main(){

  int e,i,j,k;

  while(1){

    m=10000000;

    cin >> e;

    if(e==0) break;

    for(i=0;i<=100;i++){

      for(j=0;j<=1000;j++){

	k=e-j*j-i*i*i;

        if(k>=0&&j>=0&&i>=0&&m>i+j+k){

	  m=i+j+k;

	}

      }

    }

    cout << m << endl;

  }

  return 0;

}

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

using namespace std;



int main(){

  int e,ans;

  while(1){

    cin>>e;

    if(!e)break;

    ans=(1e9);

    for(int z=0;z*z*z<=e;z++){

      int Z=z*z*z;

      for(int y=0;y*y<=e-Z;y++){

	int Y=y*y;

	int X=e-Y-Z;

	if(X+Y+Z!=e)continue;

	ans=min(ans,X+y+z);

      }

    }

    cout<<ans<<endl;

  }

  return 0;

}

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

using namespace std;

void k(int,int);

int m;

int main(){

  int e,i,j,k;

  while(1){

    m=10000000;

    cin >> e;

    if(e==0) break;

    for(i=0;i<=100;i++){

      for(j=0;j<=1000;j++){

	k=e-j*j-i*i*i;

        if(k>=0&&m>i+j+k){

	  m=i+j+k;

	}

      }

    }

    cout << m << endl;

  }

  return 0;

}

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

using namespace std;



int main(){

  int e,ans;

  while(1){

    cin>>e;

    if(!e)break;

    ans=(1e9);

    for(int z=0;z*z*z<=e;z++){

      int Z=z*z*z;

      for(int y=0;y*y<=e-Z;y++){

	int Y=y*y;

	int X=e-Y-Z;

	if(X+Y+Z!=e)continue;

	ans=min(ans,X+y+z);

      }

    }

    cout<<ans<<endl;

  }

  return 0;

}

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

#include<vector>

#include<queue>

#include<cmath>



using namespace std;



int main(){

	while(1){

		int e; cin >> e;

		if (e == 0) break;



		int min = 1000000;

		for (int z = 0; z <= 100; z++){

			for (int y = 0; y <= 1000; y++){

				int x = e - (z *z * z) - (y * y);

				if (x >=  0 and min > x + y + z){

					min = x + y + z;

				}

				

			}

		}

		cout << min<< endl;

	}

return 0;

}

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

#define INF 2000000000

#define MOD 1000000007

#define EPS (1e-10)



using namespace std;





vector<int>  dx = {1,-1,0,0};

vector<int>  dy = {0,0,1,-1};





int main() {



	while(1) {

		int n; cin >> n;

		if (n == 0) break;

		int min = 1000000001;

		/*

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

			if (x > n) break;

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

				if (x + y * y > n) break;

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

					int energy = x + y * y + z * z * z;

					int m = x + y + z;

					if (energy > n) break;

					if (energy == n and min > m) {

						min = m;

					}

				}

			}

		}

		*/

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

			if (z * z * z > n) break;

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

				int x = n - (z * z * z + y * y);

				int m = x + y + z;

				if (x < 0) break;

				if (min > m) {

					min = m;

				}

			}

		}

		cout << min << endl;

	}

	return 0;

}




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

#include <iostream>

#include <string>

#include <algorithm>

#include <math.h>



using namespace std;



#define MAX_N 128;



int ans;





int main()

{

    int e;

    

    int ans = 100000000;;

    int temp = 10000000;

    

    

    while(cin >> e && e)

    {

        ans = 100000;

        for(int z=0; z<=100; ++z)

        {

            for(int y=0; y<=1000; ++y)

            {

                

                int m = (e - y*y - z*z*z) + y*y + z*z*z;

                if(m == e)

                {

                    int x = e - y*y - z*z*z;

                    if(x >= 0)

                    {

                        if(ans > x+y+z){ans = x+y+z;}

                    }

                }

            }

        }

        cout << ans << endl;

    }

}

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

#include <iostream>

#include <string>

#include <algorithm>

#include <math.h>



using namespace std;



#define MAX_N 128;



int ans;





int main()

{

    int e;

    

    int ans = 100000000;;

    int temp = 10000000;

    

    

    while(cin >> e && e)

    {

        ans = 100000;

        for(int z=0; z<=100; ++z)

        {

            for(int y=0; y<=1000; ++y)

            {

                

                int m = (e - y*y - z*z*z) + y*y + z*z*z;

                if(m == e)

                {

                    int x = e - y*y - z*z*z;

                    if(x < 0){break;}

                    if(ans > x+y+z){ans = x+y+z;}

                }

            }

        }

        cout << ans << endl;

    }

}

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

#include <algorithm>

#include <vector>

#include <string>

#include <stack>

#include <cstdio>

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

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

using namespace std;

int main()

{

	int e; while (cin >> e && e != 0)

	{

		int m = 214214, x = 0;

		rep(z, 111) rep(y, 1111)

		{

			x = e - (y * y + z * z * z);

			if (e == x + (y * y) + (z * z * z) && x >= 0 ) 

			{ m = min(x + y + z, m); }

		}

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

	}

	return 0;

}

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

#include <algorithm>

#include <vector>

#include <string>

#include <stack>

#include <cstdio>

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

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

using namespace std;

int main()

{

	int e; while (cin >> e , e)

	{

		int m = 214214, x = 0;

		rep(z, 101) rep(y, 1001)

		{

			x = e - (y * y + z * z * z);

			if (e == x + (y * y) + (z * z * z) && x >= 0 ) 

			{ m = min(x + y + z, m); }

		}

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

	}

	return 0;

}

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

#include <algorithm>

#include <vector>

#include <string>

#include <stack>

#include <cstdio>

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

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

using namespace std;

int main()

{

	int e; while (cin >> e , e)

	{

		int m = 214214, x = 0;

		rep(y, 1001) rep(z, 101)

		{

			x = e - (y * y + z * z * z);

			if (e == x + (y * y) + (z * z * z) && x >= 0 ) 

			{ m = min(x + y + z, m); }

			else if (e > x + (y * y) + (z * z * z)) { break; }

		}

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

	}

	return 0;

}

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

#include <algorithm>

#include <vector>

#include <string>

#include <stack>

#include <cstdio>

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

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

using namespace std;

int main()

{

	int e; while (cin >> e , e)

	{

		int m = 214214, x = 0;

		rep(z, 101) rep(y, 1001)

		{

			x = e - (y * y + z * z * z);

			if (e == x + (y * y) + (z * z * z) && x >= 0 ) 

			{ m = min(x + y + z, m); }

		}

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

	}

	return 0;

}

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

#include <string>

#include <vector>

#include <algorithm>

#include <cmath>

#include <cstdio>

#include <functional>

#include <numeric>

#include <stack>

#include <queue>

#include <map>

#include <set>

#include <utility>

#include <sstream>

#include <complex>



using namespace std;



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

#define REP(i,N) for(long long i=0;i<(N);i++)

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

#define fi first

#define se second



#define PI acos(-1.0)

#define INF 1000000007

#define EPS 1e-10

#define MAX_N 20000

#define MAX_M 16



typedef long long ll;

typedef pair<ll, ll> P;

typedef pair<double, double> PD;

typedef pair<string, ll> PS;

typedef vector<ll> V;

typedef pair<P, char> PC;



int e, m;



int main(){

	while (cin >> e&&e){

		int m = 1000001;

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

			for (int j = 0; j <= 1000; j++){

				int x = e - i*i*i - j*j;

				if (x >= 0){

					m = min(m, x + i + j);

				}

			}

		}

		cout << m << endl;

	}

}

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

#include <string>

#include <vector>

#include <algorithm>

#include <cmath>

#include <cstdio>

#include <functional>

#include <numeric>

#include <stack>

#include <queue>

#include <map>

#include <set>

#include <utility>

#include <sstream>

#include <complex>

#include <fstream>

#include <bitset>

#include <time.h>

#include <tuple>

#include <iomanip>



using namespace std;



typedef long long ll;

typedef pair<ll, ll> P;

typedef vector<ll> V;

typedef complex<double> Point;



#define PI acos(-1.0)

#define EPS 1e-10

const ll INF = 1e12;

const ll MOD = 1e9 + 7;



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

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

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

#define EQ(a,b) (abs((a)-(b))<EPS)

#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )

#define fi first

#define se second

#define N_SIZE 100100

#define NIL -1

#define MAX_N 100100



double sq(double num) { return num*num; }

ll mod_pow(ll x, ll n) {

	if (n == 0)return 1;

	if (n == 1)return x%MOD;

	ll res = sq(mod_pow(x, n / 2));

	res %= MOD;

	if (n % 2 == 1) {

		res *= x;

		res %= MOD;

	}

	return res;

}

ll mod_add(ll a, ll b) { return (a + b) % MOD; }

ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }

ll mod_mul(ll a, ll b) { return a*b % MOD; }



ll e;



int main(){

	while (cin >> e&&e) {

		ll sum = INF;

		for (ll k = 0; k*k*k <= e;k++) {

			for (ll j = 0; j*j + k*k*k <= e; j++) {

				ll i = e - (j*j + k*k*k);

				if (sum > i + j + k)sum = i + j + k;

			}

		}

		cout << sum << endl;

	}

}


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

using namespace std;



int main()

{

  int e, x;

  while(cin >> e && e > 0){

    int m = 1e6;

    for(int z=0; z<=1e2; z++){

      for(int y=0; y<=1e3; y++){

        x = e - z*z*z - y*y;

        if(x < 0){

          continue;

        }

        if(x+y+z<m){

          m = x + y + z;

        }

      }

    }

    cout << m << endl;

  }

  return 0;

}

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

using namespace std;

int E;



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

{

    while ( cin >> E and E > 0 ) {

        int m = E;

        for (int z = 0; z * z * z <= E ; z++) {

            for (int y = 0; y * y <= E - z * z * z; y++) {

                int x = E - z * z * z - y * y;

                if ( x + y + z < m) m = x + y + z;

            }

        }

        cout << m << endl;

    }

    return 0;

}

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

#include <math.h>

using namespace std;

int N, S, y_max, z_max, ans;



int main(){

  while( cin >> N && N > 0){

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

      for(int j = 0; j <= 100; j++){

        if(i == 0 && j == 0) ans = N;

        if(ans > (i + j +(N-i*i-j*j*j)) && N-i*i-j*j*j >= 0) ans = i + j +(N-i*i-j*j*j);

      }

    }





    cout << ans << endl;





  }









}


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

#include<map>

#include<vector>

#include<algorithm>

#include<cmath>

#include<climits>

#include<ctime>

#include<cstring>

#include<numeric>



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

#define REP(i,p,n) for(int i=p;i<(int)(n);++i)

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

#define dump(a) (cerr << #a << "=" << (a) << endl)

#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;



using namespace std;



int main(){

  int N, k;

  while(cin >> N && N > 0){

    int ans = -1;

    rep(i, 101){

      rep(j, 1001){

        k = N - j*j - i*i*i;

        if (k < 0) break;

        if(ans == -1) {

          ans = i + j + k;

        } else{

          if (ans > i + j + k) ans = i + j + k;

        }



      }

    }

    cout << ans << endl;

  }



  return 0;

}




// Fastest known solution for this problem: