stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <string>

#include <cstring>

#include <cstdio>

#include <cstdlib>

#include <vector>

#include <cmath>

#include <algorithm>

#include <map>

#include <sstream>

#include <queue>

#include <deque>

#include <set>

#include <stack>

#include <functional>

#include <utility>

#include <stdio.h>

#define ll long long

#define MP make_pair

#define PII pair<int, int>

#define PLL pair<ll, ll>

#define PLI pair<ll, int>

#define PIL pair<int, ll>

#define F first

#define S second

#define SHN 1e9

#define LSHN 1e18

using namespace std;

map<int, int> mp;

int n,m;

int res=0;

vector<int> v;

int main()

{

	cin >>n>>m;

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

	{

		int x;

		cin >>x;

		mp[x-1]++;

	}

	if (mp.size()<=m)

	{

		cout <<"0";

		return 0;

	}

	for (map<int, int>::iterator it=mp.begin();it!=mp.end();it++)

	    v.push_back(it->second);

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

	for (int i=0;i<v.size()-m;i++) res+=v[i];

	cout <<res;

	return 0;

}


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

#include<algorithm>

using namespace std;



int n,k,a,maxa,c[200001],ans;



int main(){

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

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

        scanf("%d",&a);

        if(a>maxa)maxa=a;

        c[a]++;

    }

    n=maxa;

    sort(&c[1],&c[n+1]);

    for(int i=1;i<=n-k;i++)ans+=c[i];

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

    return 0;

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

        intt(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;  

}  

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

using namespace std;

const int uchiha=1e3+5;

int main(){

    map<int,int> mp;

    vector<int> v;

int n,k,c1=0,w;

cin>>n>>k;

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

        cin>>w;

    mp[w]++;

}

for(auto e : mp){

    v.push_back(e.second);

}

sort(v.begin(),v.end(),greater<int>());

while(v.size()>k){

    c1+=v.back();

    v.pop_back();

}

cout<<c1;

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

        intt(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;  

}  

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

using namespace std;

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

// Mahmoud Magdy    *

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

#define ll long long

#define endl "\n"



void fast()

{

    ios_base :: sync_with_stdio( 0 ) ;

    cin.tie( 0 ) ;

    cout.tie( 0 ) ;

}

inline int D()

{

    int m ;

    cin>>m;

    return m ;

}

inline ll lD()

{

    ll m ;

    cin>>m;

    return m ;

}

inline double dD()

{

    double m ;

    cin>>m;

    return m ;

}

int fr[1000006];

int main()

{

int n=D(),k=D();

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

    int a=D();

   fr[a]++;

}

vector<int>v;

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

{

    if(fr[i]!=0)

    v.push_back(fr[i]);

}

sort(v.rbegin(),v.rend());

int c=0;

for(int i=k;i<v.size();++i)

 c+=v[i];

cout<<c<<endl;

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

        intt(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;  

}  

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

using namespace std;



map<int, int> mp;

vector<int> v;



int main(){



    int n, k, a;

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

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

        scanf("%d", &a);

        ++mp[a];

    }



    int cnt=mp.size();

    if(cnt<=k)

        puts("0");

    else{

        long long ans=0LL;

        for(auto i:mp)

            v.push_back(i.second);

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

        int sz=cnt-k;

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

            ans+=(1LL*v[i]);



        printf("%d", ans);

    }













    return 0;

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

}  

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

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

}  

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

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

}

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

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

}

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

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



}

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

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

}

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

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

}

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

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

}

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

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

    }

}

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

    }

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

}

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

}