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

#include <string>

#include <algorithm>



#define LEN 100000

using namespace std;



class Pro{

public:

	string name;

	int time;

};



class Que{

	Pro* p = new Pro[LEN];

public:

	~Que(){ delete[] p; }

	int head=0, tail=0, n;

	void enqueue(Pro x){

		p[tail] = x;

		tail = (tail + 1) % LEN;

	}



	Pro dequeue(){

		Pro x = p[head];

		head = (head + 1) % LEN;

		return x;

	}

};





int main()

{

	int n;//??????????????°

	cin >> n;

	int q;//?????????????????????

	cin >> q;

	

	Que Q;

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

		Pro x;

		cin >> x.name;

		cin >> x.time;

		Q.enqueue(x);

	}



	//????????????

	int t=0;



	while (Q.head != Q.tail){

		Pro c;

		c = Q.dequeue();

		int b = min(c.time, q);

		c.time -= b;

		t += b;



		if (c.time > 0) {

			Q.enqueue(c);

		}

		else{

		cout << c.name << ' ' << t << '\n';

		}

	}

	return 0;

}

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

#include <algorithm>

#define LEN 100005

using namespace std;



//?????????????????¨????§???????

typedef struct pp{

	char name[100];

	int t;

}P;



P Q[LEN];

int head, tail, n;



void enqueue(P x){

	Q[tail] = x;

	tail = (tail + 1) % LEN;

}



P dequeue(){

	P ret = Q[head];

	head = (head + 1) % LEN;

	return ret;

}



int main()

{

	//??????????????°

	int n;



	//???????????????

	int q;



	cin >> n;

	cin >> q;



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

		cin >> Q[i].name;

		cin >> Q[i].t;

	}



	head = 1;

	tail = n + 1;



	//????????????

	int elaps = 0;



	//sim

	while (tail != head){

		P u = dequeue();



		//??°????°?????????????????????¨

		int c = min(u.t, q);



		//?????????????¨????

		u.t -= c;



		//?????????????????????

		elaps += c;



		if (u.t > 0){

			enqueue(u);

		}

		else {

			cout << u.name << ' ' << elaps << '\n';

		}

	}



	return 0;

}

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

#include<iostream>

#include<vector>

#include<string>

using namespace std;

class process {

public:

	string name;

	int time;

};

class queue {

public:

	process A[100000];

	int head, tail;

	void enqueue(process x) {

		A[tail] = x;

		tail = (tail + 1) % 100000;

		return;

	}

	process dequeue() {

		process x = A[head];

		head = (head + 1) % 100000;

		return x;

	}

};

int main() {

	int elaps = 0, c, n, q;

	cin >> n >> q;

	queue z;

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

		cin >> z.A[i].name >> z.A[i].time;

	}

	z.head = 0; z.tail = n % 100000;

	while (z.head != z.tail) {

		process u = z.dequeue();

		c = min(q, u.time);

		u.time -= c;

		elaps += c;

		if (u.time > 0)z.enqueue(u);

		else cout << u.name << " " << elaps << endl;

	}

	return 0;

}

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

using namespace std;

#ifdef _DEBUG

#include "dump.hpp"

#else

#define dump(...)

#endif



//#define int long long

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

#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)

#define all(c) begin(c),end(c)

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;

const int MOD = (int)(1e9) + 7;

const double PI = acos(-1);

const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }

template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

struct Job {

	char name[20];

	int time;

	Job() {}

	Job(char *c, int t) {

		strcpy(name, c);

		time = t;

	}

};

struct Queue {

	int b, e, len;;

	Job j[100000];

	Queue() {

		len = 100000;

		b = 0;

		e = 0;

	}

	Job front() {

		Job ret = j[b];

		b = (b + 1) % len;

		return ret;

	}

	void push(Job in) {

		j[e] = in;

		e = (e + 1) % len;

	}

	bool empty() {

		return b == e;

	}

};

signed main() {

	int n, q; cin >> n >> q;

	int now = 0;

	static Queue m;

	rep(i, 0, n) {

		char c[20]; int t;

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

		m.push(Job(c, t));

	}

	while (!m.empty()) {

		Job tmp = m.front();

		//printf("debug : %s %d\n", tmp.name, tmp.time);

		int x = min(q, tmp.time);

		now += x;

		tmp.time -= x;

		if (tmp.time == 0) {

			printf("%s %d\n", tmp.name, now);

		}

		else {

			m.push(tmp);

		}

	}

	return 0;

}

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

using namespace std;

int main(){

    string s[100002];

    int a[100002];

    string s1;

    int x,n,q,head,tail,tot=0;

    head=0; tail=0;

    cin>>n>>q;

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

    	cin>>s1>>a[i];

    	s[i]=s1;

    	tail++;

	}

	while (head!=tail){

		  if (a[head]>q){

		  	 tot+=q;

		     x=a[head]-q;

		     s1=s[head];

			 head++;

			 if (head>n) head=0;

			 a[tail]=x;	

			 s[tail]=s1;

			 tail++;

			 if (tail>n) tail=0; 

		  }

		  else{

		  	 cout<<s[head]<<' '<<a[head]+tot<<endl;

		  	 tot+=a[head];

		  	 head++;

		  	 if (head>n) head=0;

		  }

	}

    return 0;

} 


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

using namespace std;

int main(){

	queue<pair<string,int> > a;

    //int a[100002];

    string s1;

    int x,n,q,head,tail,t,tot=0;

    pair<string,int> u;

    cin>>n>>q;

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

    	cin>>s1>>t;

    	a.push(make_pair(s1,t));

	}

	while (!a.empty()){

		  u=a.front();

		  if (u.second>q){

		  	 tot+=q;

		     x=u.second-q;

		     a.pop();

			 a.push(make_pair(u.first,x));

		  }

		  else{

		  	 cout<<u.first<<' '<<u.second+tot<<endl;

		  	 tot+=u.second;

		  	 a.pop();

		  }

	}

    return 0;

} 


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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<long long,P> P1;

typedef pair<P,P> P2;

#define pu push

#define pb push_back

#define mp make_pair

#define eps 1e-7

#define INF 2000000000

P pa1[100005];

P pa2[100005];

int h,w,n;

bool comp1(P a,P b){

	return a.first<b.first;

}

bool comp2(P a,P b){

	return a.second<b.second;

}

bool decide(P1 a,P1 b){

	if(a.first<b.first){

		return true;

	}else if(a.first>b.first){

		return false;

	}else{

		if(a.second.first<b.second.first){

			return true;

		}else if(a.second.first>b.second.first){

			return false;

		}else{

			return a.second.second<b.second.second;

		}

	}

}

int main(){

	scanf("%d %d",&h,&w);

	scanf("%d",&n);

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

		int x,y;

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

		pa1[i]=mp(x,y);

		pa2[i]=pa1[i];

	}

	sort(pa1+1,pa1+(n+1),comp1);

	int ha=(n+1)/2;

	int ax=pa1[ha].first;

	vector<P1>vec;

	vector<int>dx,dy;

	if(pa1[ha+1].first!=ax){

		dx.pb(ax);

		dx.pb(pa1[ha+1].first);

	}

	else{

		dx.pb(ax);

		dx.pb(ax-1);	

		dx.pb(ax+1);		

	}

	sort(pa1+1,pa1+(n+1),comp2);

	int ay=pa1[ha].second;

	if(pa1[ha+1].second!=ay){

		dy.pb(ay);

		dy.pb(pa1[ha+1].second);

	}

	else{

		dy.pb(ay);

		dy.pb(ay-1);	

		dy.pb(ay+1);		

	}



	for(int i=0;i<dx.size();i++){

		for(int j=0;j<=dy.size();j++){

			long long sd=0;

			int maxi=0;

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

				sd+=(abs(pa1[g].first-dx[i])+abs(pa1[g].second-dy[j]));

				maxi=max(maxi,(abs(pa1[g].first-dx[i])+abs(pa1[g].second-dy[j])));

			}

			vec.pb(mp(sd*2-maxi,mp(dx[i],dy[j])));

		}

	}

sort(vec.begin(),vec.end(),decide);

printf("%lld\n%d %d\n",vec[0].first,vec[0].second.first,vec[0].second.second);

return 0;

}

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

#include <algorithm>

using namespace std;

typedef long long ll;

#define mp make_pair

int x[100005],y[100005];

int a[100005],b[1000005];

int main(){

	int n,m,k;

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

	for(int i=0;i<k;i++) scanf("%d%d",&x[i],&y[i]);

	for(int i=0;i<k;i++) a[i]=x[i],b[i]=y[i];

	sort(a,a+k); sort(b,b+k);

	ll ret=1e15; int rx,ry;

	for(int i=(k-1)/2;i<=(k+1)/2;i++)

	{

		for(int j=(k-1)/2;j<=(k+1)/2;j++)

		{

			ll sum=0LL,gen=0LL;

			for(int s=0;s<k;s++)

			{

				sum+=2LL*(abs(x[s]-a[i])+abs(y[s]-b[j]));

				gen=max(gen,1LL*(abs(x[s]-a[i])+abs(y[s]-b[j])));

			}

			if(sum-gen<ret){ rx=a[i]; ry=b[j]; ret=sum-gen;}

			else if(sum-gen==ret && mp(rx,ry)>mp(a[i],b[j])) rx=a[i],ry=b[j];

		}

	}

	printf("%lld\n%d %d\n",ret,rx,ry);

}

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

#include <cstdlib>

#include <algorithm>

#include <vector>

using namespace std;

typedef pair<int,int>P;

typedef pair<long long,P>P1;

#define pb push_back

#define mp make_pair

P pa1[100005],pa2[100005];

int h,w,n;

bool comp(P a,P b){

	return a.second<b.second;

}

bool decide(P1 a,P1 b){

	if(a.first<b.first){

		return true;

	}else if(a.first>b.first){

		return false;

	}else{

		if(a.second.first<b.second.first){

			return true;

		}else if(a.second.first>b.second.first){

			return false;

		}else{

			return a.second.second<b.second.second;

		}

	}

}

int main(){

	scanf("%d %d",&h,&w);

	scanf("%d",&n);

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

		int x,y;

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

		pa2[i]=pa1[i]=mp(x,y);

	}

	sort(pa2+1,pa2+(n+1),comp);

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

	int ha=(n+1)/2;

	int ax=pa1[ha].first;

	int ay=pa2[ha].second;

	vector<P1>vec;

	vector<int>dx,dy;

	dx.pb(ax);

	dy.pb(ay);

	if(pa1[ha+1].first!=ax){

		dx.pb(pa1[ha+1].first);

	}

	if(pa2[ha+1].second!=ay){

		dy.pb(pa2[ha+1].second);

	}

	for(int i=0;i<dx.size();i++){

		for(int j=0;j<dy.size();j++){

			long long sd=0;

			int maxi=0;

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

				sd+=(abs(pa1[g].first-dx[i])+abs(pa1[g].second-dy[j]));

				maxi=max(maxi,(abs(pa1[g].first-dx[i])+abs(pa1[g].second-dy[j])));

			}

			vec.pb(mp(sd*2-maxi,mp(dx[i],dy[j])));

		}

	}

	sort(vec.begin(),vec.end(),decide);

	printf("%lld\n%d %d\n",vec[0].first,vec[0].second.first,vec[0].second.second);

	return 0;

}

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

#include <algorithm>

using namespace std;

typedef long long ll;

#define mp make_pair

int x[100005],y[100005];

int a[100005],b[1000005];

int main(){

	int n,m,k;

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

	for(int i=0;i<k;i++) scanf("%d%d",&x[i],&y[i]);

	for(int i=0;i<k;i++) a[i]=x[i],b[i]=y[i];

	sort(a,a+k); sort(b,b+k);

	ll ret=1e15; int rx,ry;

	for(int i=(k-1)/2;i<=(k+1)/2;i++)

	{

		for(int j=(k-1)/2;j<=(k+1)/2;j++)

		{

			ll sum=0LL,gen=0LL;

			for(int s=0;s<k;s++)

			{

				sum+=2LL*(abs(x[s]-a[i])+abs(y[s]-b[j]));

				gen=max(gen,1LL*(abs(x[s]-a[i])+abs(y[s]-b[j])));

			}

			if(sum-gen<ret){ rx=a[i]; ry=b[j]; ret=sum-gen;}

			else if(sum-gen==ret && mp(rx,ry)>mp(a[i],b[j])) rx=a[i],ry=b[j];

		}

	}

	printf("%lld\n%d %d\n",ret,rx,ry);

}

// 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 <ctime>

#include <cassert>

#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 f first

#define s second

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

struct house

{

	int x,y;

	house(){}

	house(int x,int y):x(x),y(y){}

}h[100005];

struct comp_x

{

	bool operator()(const house& a, const house& b)const

	{

		if(a.x!=b.x) return a.x<b.x;

		return a.y<b.y;

	}

};

struct comp_y

{

	bool operator()(const house& a, const house& b)const

	{

		if(a.y!=b.y) return a.y<b.y;

		return a.x<b.x;

	}

};

int main()

{

	srand((unsigned int)time(NULL));

	int hh,w,n; scanf("%d %d",&hh,&w); scanf("%d",&n);

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

	{

		scanf("%d %d",&h[i].x,&h[i].y);

	}

	set<int>se1,se2;

	sort(h,h+n,comp_x());

	se1.insert(h[(n-2)/2].x);

	se1.insert(h[n/2].x);

	sort(h,h+n,comp_y());

	se2.insert(h[(n-2)/2].y);

	se2.insert(h[n/2].y);

	ll ret=1e15;int px=INF,py=INF;

	for(set<int>::iterator it=se1.begin();it!=se1.end();++it)

	{

		for(set<int>::iterator it2=se2.begin();it2!=se2.end();++it2)

		{

			int X=*it; int Y=*it2; //cout << X << " " << Y << endl;

			ll val=0,gen=0;

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

			{

				val+=2LL*(abs(h[i].x-X)+abs(h[i].y-Y));

				gen=max(gen,1LL*(abs(h[i].x-X)+abs(h[i].y-Y)));

			}

			if(ret>val-gen || (ret==val-gen && ((px>X)||(px==X&&py>Y))))

			{

				ret=val-gen;

				px=X;py=Y;

			}

		}

	}

	printf("%lld\n%d %d\n",ret,px,py);

}

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

#include <algorithm>

using namespace std;

typedef long long ll;

#define mp make_pair

int x[100005],y[100005];

int a[100005],b[1000005];

int main(){

	int n,m,k;

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

	for(int i=0;i<k;i++) scanf("%d%d",&x[i],&y[i]);

	for(int i=0;i<k;i++) a[i]=x[i],b[i]=y[i];

	sort(a,a+k); sort(b,b+k);

	ll ret=1e15; int rx,ry;

	for(int i=(k-1)/2;i<=(k+1)/2;i++)

	{

		for(int j=(k-1)/2;j<=(k+1)/2;j++)

		{

			ll sum=0LL,gen=0LL;

			for(int s=0;s<k;s++)

			{

				sum+=2LL*(abs(x[s]-a[i])+abs(y[s]-b[j]));

				gen=max(gen,1LL*(abs(x[s]-a[i])+abs(y[s]-b[j])));

			}

			if(sum-gen<ret){ rx=a[i]; ry=b[j]; ret=sum-gen;}

			else if(sum-gen==ret && mp(rx,ry)>mp(a[i],b[j])) rx=a[i],ry=b[j];

		}

	}

	printf("%lld\n%d %d\n",ret,rx,ry);

}

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

#include <ext/pb_ds/assoc_container.hpp> // Common file

#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#include <ext/pb_ds/detail/standard_policies.hpp>



using namespace std;

using namespace __gnu_pbds;



typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,

		tree_order_statistics_node_update> ordered_set;



#define el				'\n'

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

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

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



double const EPS = 1e-8, PI = acos(-1);

const int N = 200000 + 9, M = 20 + 9, OO = (int) 1e9 + 1;

const long long MOD = 1e9 + 7, INF = 1e18 + 9;



typedef long long ll;



void OUTPUT() {

	cout << fixed << setprecision(0);

	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

}



void INPUT() {

#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);

//	freopen("output.txt", "w", stdout);

#endif

}



int n, k, x, arr[N];



int main() {

//	INPUT();

	OUTPUT();

	cin >> n >> k;

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

		cin >> x;

		arr[x]++;

	}

	vector<int> v;

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

		if (arr[i])

			v.push_back(arr[i]);

	}

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

	ll ans = 0;

	int m = max(0, sz(v) - k);

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

		ans += v[i];

	}

	cout << ans;



	return 0;



}




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



using namespace std;



typedef long long ll;



const int N = 2e5+5;





int n , k;

int ar[N];

int cnt[N];



int main(){

    int dif = 0;

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

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

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

        if(cnt[ar[i]] == 0)

            dif ++;

        cnt[ar[i]]++;



    }

    if(dif <= k){

        puts("0");

        return 0;

    }

    vector < int > all;

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

        if(cnt[ar[i]]){

            all.push_back(cnt[ar[i]]);

            cnt[ar[i]] = 0;

        }

    }

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

    int ans = 0;

    for(auto v : all){

        ans += v;

        dif--;

        if(dif <= k)

            break;

    }

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

}


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

using namespace std;

int xx[5000000];

int main()

{

    int n,k,v,c=0;

    cin>>n>>k;

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

    {

        cin>>v;

        xx[v]++;

    }

    vector<int>vc;

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

    {

        if(xx[i]!=0)vc.push_back(xx[i]);

    }



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

    int si=vc.size();

    si-=k;

    if(si<=0)cout<<"0"<<endl;

    else{

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

            c+=vc[i];

        cout<<c<<endl;

    }



    return 0;

}


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



using namespace std;



typedef long long ll;



const int N = 2e5+5;





int n , k;

int ar[N];

int cnt[N];



int main(){

    int dif = 0;

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

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

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

        if(cnt[ar[i]] == 0)

            dif ++;

        cnt[ar[i]]++;



    }

    if(dif <= k){

        puts("0");

        return 0;

    }

    vector < int > all;

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

        if(cnt[ar[i]]){

            all.push_back(cnt[ar[i]]);

            cnt[ar[i]] = 0;

        }

    }

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

    int ans = 0;

    for(auto v : all){

        ans += v;

        dif--;

        if(dif <= k)

            break;

    }

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

}


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

#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef pair<ll,ll> pll;

#define mp make_pair

#define f first

#define s second

#define pb push_back



const int N = 2e5 + 5;

const int OO = 2e9;



int n,k,a[N],f[N],ans;

vector<int>  v;



void init() {







}



int main() {



    ios_base::sync_with_stdio(false);

    cin.tie(0);



    cin >> n >> k;



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



        cin >> a[i];

        f[a[i]]++;



    }



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



        if(f[i]) v.pb(f[i]);



    }



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



    for(int i=0;i<max(0,int(v.size())-k);++i) {



        ans += v[i];



    }



    cout << ans << '\n';



    return 0;



}

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



using namespace std;



typedef long long ll;



const int N = 2e5+5;





int n , k;

int ar[N];

int cnt[N];



int main(){

    int dif = 0;

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

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

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

        if(cnt[ar[i]] == 0)

            dif ++;

        cnt[ar[i]]++;



    }

    if(dif <= k){

        puts("0");

        return 0;

    }

    vector < int > all;

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

        if(cnt[ar[i]]){

            all.push_back(cnt[ar[i]]);

            cnt[ar[i]] = 0;

        }

    }

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

    int ans = 0;

    for(auto v : all){

        ans += v;

        dif--;

        if(dif <= k)

            break;

    }

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

}


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

#include <bits/stdc++.h>

using namespace std;

#define N 200000

int n, k;

int cnt[N+5];

vector<pair<int, int>> v;

int in;

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

{

    while(cin >> n >> k && (n||k))

    {

        memset(cnt, 0, sizeof(cnt));

        v.clear();

        //

        for(int i = 0; i < n && cin >> in; i++)

            cnt[in]++;

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

            if(cnt[i])

                v.push_back(make_pair(cnt[i], i));

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

        int d = v.size() - k, ans = 0;

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

        {

            ans += v[i].first;

        }

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

    }

}

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



using namespace std;



typedef long long ll;



const int N = 2e5+5;





int n , k;

int ar[N];

int cnt[N];



int main(){

    int dif = 0;

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

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

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

        if(cnt[ar[i]] == 0)

            dif ++;

        cnt[ar[i]]++;



    }

    if(dif <= k){

        puts("0");

        return 0;

    }

    vector < int > all;

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

        if(cnt[ar[i]]){

            all.push_back(cnt[ar[i]]);

            cnt[ar[i]] = 0;

        }

    }

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

    int ans = 0;

    for(auto v : all){

        ans += v;

        dif--;

        if(dif <= k)

            break;

    }

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

}


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

#include<iostream>

#include<string.h>

#include<algorithm>

using namespace std;

#include<stdlib.h>

#define ll long long

int a[200010];

int book[200010];

int main()

{

    int n,k,t=0;

    memset(book,0,sizeof(book));

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

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

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

    sort(a,a+n);

    book[0]=1;

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

    {

        if(a[i]==a[i-1])

           book[t]++;

        else

        {

            t++;

            book[t]++;

        }

    }

    sort(book,book+t+1);

    int sum=0,cnt=1;

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

    {

        if(cnt<=k)

        {

            sum=sum+book[i];

            cnt++;

        }

    }

    printf("%d\n",n-sum);

    return 0;

}


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

#include<cstdio>

#include<string>

#include<vector>

#include<queue>

#include<cmath>

#include<algorithm>

#include<iomanip>

#include<functional>

#include<set>

#include<map>

#include<climits>

#include<utility>

#define ul unsigned long long int

#define ll long long int

#define MAX 1000000+1

using namespace std;

#define F first

#define S second

#define pi 2*acos(0.0)

#define PB push_back

#define CL clear()







ll arr[2000010];





int main()

{

    ll n, m;

    cin >> n >> m;

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

        arr[i] = 0;



    ll t = 0;

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

    {

        ll r;

        cin >> r;

        if(arr[r]==0)

            t++;

        arr[r]++;

    }

    if(t<= m)

        cout <<0 ;

    else

    {

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

        {

            if(arr[i]==0)

                arr[i] = LONG_MAX;

        }

        ll e = 0;

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

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

//            cout << arr[i] <<" ";

        for(int i = 1; i <= t - m; i++)

        {



            e += arr[i];

        }

        cout << e;

    }





    return 0;

}


// Fastest known solution for this problem: