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

}

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

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

} 


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

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

#include <vector>

#include <iostream>

#include <algorithm>

using namespace std;

int H, W; vector<string> s;

int main() {

	ios::sync_with_stdio(false);

	cin >> H >> W; s.resize(H);

	for (int i = 0; i < H; i++) cin >> s[i];

	vector<pair<int, int> > v;

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

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

			if (s[i][j] == '.' || s[i][j] == '9') continue;

			int cnt = 0;

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

				for (int l = -1; l <= 1; l++) {

					int tx = j + l, ty = i + k;

					if (0 <= tx && tx < W && 0 <= ty && ty < H && s[ty][tx] == '.') cnt++;

				}

			}

			if (cnt >= s[i][j] - 48) v.push_back(make_pair(j, i));

		}

	}

	int ret = 0;

	for (; !v.empty(); ret++) {

		for (pair<int, int> i : v) s[i.second][i.first] = '.';

		vector<pair<int, int> > w;

		for (pair<int, int> i : v) {

			int sx = i.first, sy = i.second;

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

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

					int tx = sx + k, ty = sy + j;

					if (!(0 <= tx && tx < W && 0 <= ty && ty < H)) continue;

					if (s[ty][tx] == '.' || s[ty][tx] == '9') continue;

					int cnt = 0;

					for (int l = -1; l <= 1; l++) {

						for (int m = -1; m <= 1; m++) {

							int ux = tx + m, uy = ty + l;

							if (0 <= ux && ux < W && 0 <= uy && uy < H && s[uy][ux] == '.') cnt++;

						}

					}

					if (cnt >= s[ty][tx] - 48) w.push_back(make_pair(tx, ty));

				}

			}

		}

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

		w.resize(unique(w.begin(), w.end()) - w.begin());

		v = w;

	}

	cout << ret << endl;

	return 0;

}

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

#include <vector>

#include <algorithm>

using namespace std;

int H, W; char s[1009][1009];

int main() {

	scanf("%d%d", &H, &W);

	for (int i = 0; i < H; i++) scanf("%s", s[i]);

	vector<pair<int, int> > v;

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

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

			if (s[i][j] == '.' || s[i][j] == '9') continue;

			int cnt = 0;

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

				for (int l = -1; l <= 1; l++) {

					int tx = j + l, ty = i + k;

					if (0 <= tx && tx < W && 0 <= ty && ty < H && s[ty][tx] == '.') cnt++;

				}

			}

			if (cnt >= s[i][j] - 48) v.push_back(make_pair(j, i));

		}

	}

	int ret = 0;

	for (; !v.empty(); ret++) {

		for (pair<int, int> i : v) s[i.second][i.first] = '.';

		vector<pair<int, int> > w;

		for (pair<int, int> i : v) {

			int sx = i.first, sy = i.second;

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

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

					int tx = sx + k, ty = sy + j;

					if (!(0 <= tx && tx < W && 0 <= ty && ty < H)) continue;

					if (s[ty][tx] == '.' || s[ty][tx] == '9') continue;

					int cnt = 0;

					for (int l = -1; l <= 1; l++) {

						for (int m = -1; m <= 1; m++) {

							int ux = tx + m, uy = ty + l;

							if (0 <= ux && ux < W && 0 <= uy && uy < H && s[uy][ux] == '.') cnt++;

						}

					}

					if (cnt >= s[ty][tx] - 48) w.push_back(make_pair(tx, ty));

				}

			}

		}

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

		w.resize(unique(w.begin(), w.end()) - w.begin());

		v = w;

	}

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

	return 0;

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

}

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

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

}

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

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

}

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

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



}




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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

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

using namespace std;

using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag,

		tree_order_statistics_node_update> ordered_set;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag,

		tree_order_statistics_node_update> indexed_multiset;







map<int,int>mp;

set<int>s;

int main(){	

	int n, k;

	cin>>n>>k;

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

		int x ; cin>>x;

		s.insert(x);

		mp[x]++;

	}

	vector<int>vi;

	for(auto it : s){

		vi.push_back(mp[it]);

	}

	long long cnt = 0;

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

	for(int i = 0;  i < min((int)vi.size(),k) ; i++)

		cnt+=vi[i];

	cout<<n-cnt;

    return 0;

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



}




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

using namespace std;

int main()

{

    int n,k,x;

    vector<int>v;

    map<int,int>m;

    cin>>n>>k;

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

    {

        cin>>x;

        m[x]++;

    }

    map<int,int>::iterator it;

    for(it=m.begin();it!=m.end();it++)

    {

        v.push_back(it->second);

    }

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

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

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

    {

        ans+=v[i];

    }

    cout<<ans<<endl;

    return 0;

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



}




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

using namespace std;

int main()

{



 map<int,int>m;

vector<int>v,vv;

int a,n,b,c,d,e,o=0,i,j,k;

cin>>a>>b;

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

{

cin>>c;

m[c]++;

if(m[c]==1)v.push_back(c);



}

   // cout<<v.size()<<endl;

    if(v.size()<=b)cout<<"0"<<endl;

   else

  {

  for(i=0;i<v.size();i++)

  {

  k=m[v[i]];vv.push_back(k);

  }

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

 for(i=0;i<v.size()-b;i++)

    {o+=vv[i];

  }

       cout<<o<<endl; 

  }

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



}




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

using namespace std;

int main()

{

    int a,b,c,d,e,f,g,h;

    int i,j;

    cin>>a>>b;

    int ar[a];

    map<int,int>m;

    map<int,int>::iterator it;

    set<int>s;

    for(i=0;i<a;i++)

    {

        cin>>ar[i];

        m[ar[i]]++;



    }

    vector<int>v;

    c=m.size();

    for(it=m.begin();it!=m.end();it++)

    {

        v.push_back((*it).second);





    }

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

    if(b>=c)

    {

        cout<<"0"<<endl;

    }

    else{

        int k=c-b;

        d=0;e=0;

        for(i=0;i<v.size();i++)

        {

            k-=1;

            d+=v[i];

            if(k<=0)

            {

                break;

            }

        }

        cout<<d<<endl;

    }



    m.clear();

    v.clear();

    return 0;





}