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

#include<string>

#include<vector>

#include<set>

#include<map>

#include<utility>

#include<algorithm>

#include<cmath>

#include<climits>

using namespace std;



int main(){

	int n, k;

	cin >> n >> k;

	int a[200000]={};

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

		int tmp;

		cin >> tmp;

		a[tmp-1]++;

	}

	sort(a, a+n, greater<int>());

	int sum=0;

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

		sum+=a[i];

	cout << n-sum << '\n';

	return 0;

}

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

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

using namespace std;

using ll = long long;

using ld = long double;

const int INF = (1<<30)-1;

const long long LINF = (1LL<<62)-1;

const long double PI = acos(-1.0L);

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

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

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

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



signed main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int n, k;

  cin >> n >> k;

  vector<int> num(n);

  rep(i, n) {

    int a;

    cin >> a;

    num[--a]++;

  }

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

  int ans = n;

  rep(i, k)

    ans -= num[i];

  cout << ans << endl;

  return 0;

}

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

#include <vector>

#include <algorithm>

using namespace std;



int N,K;

//vector<int> A(200010,0);



int main(){

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

		int ans = 0;

		vector<int> A(N+10,0);

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

			int a;

			cin >> a;

			A[a]++;

		}

		//for(int i=0;i<A.size();i++) cout << A[i] << endl;

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

		reverse(A.begin(),A.end());

		for(int i=K;i<A.size();i++){

			ans += A[i];

		}

		cout << ans << endl;

	}

}


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

#include <stdlib.h>



int cmp(const void* a,const void* b){

	return *(int*)a - *(int*)b;

}

int b[200000]={};

int main(void){

	int n,k;

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

	int i,c=0;

	int a[n];

	for(i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),cmp);

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

		b[c]++;

		while(a[i]==a[i+1]){

			i++;

			b[c]++;

		}

		c++;

	}

	//cはボールの種類数で,b[i]にはその数が入る

	//ボールに書かれている整数がK種類以下にする最適な方法は、

	//b[i]が小さいヤツから消していく

	qsort(b,c,sizeof(int),cmp);

	int ans = 0;

	for(i=0;i<c-k;i++){

		ans += b[i];

	}

	printf("%d",ans);

	return 0;

}


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

#include <math.h>

#include <string>

#include <algorithm>

#include <ctype.h>

#include <vector>

using namespace std;



#define ll long long int



int main()

{

    int n, k, a;

    int cnt[200000] = {};



    cin >> n >> k;

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

    {

        cin >> a;

        cnt[a - 1]++;

    }

    sort(cnt, cnt + n);

    reverse(cnt, cnt + n);

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

    {

        n -= cnt[i];

    }

    cout << n << endl;

}


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

#include <math.h>

#include <string>

#include <algorithm>

#include <ctype.h>

#include <vector>

using namespace std;



#define ll long long int

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

#define INF 1e9

#define LINF 1e17

#define MOD (int)(1e9 + 7)

#define pi 3.141592653589

#define pii pair<int, int>

#define vi vector<int>



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

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



int main()

{

    int n, k;

    cin >> n >> k;



    vi a(n), cnt(n, 0);

    rep(i, 0, n)

    {

        cin >> a[i];

        cnt[a[i] - 1]++;

    }

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

    reverse(cnt.begin(), cnt.end());

    rep(i, 0, k)

    {

        n -= cnt[i];

    }

    cout << n << endl;

}


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

#include<algorithm>

using namespace std;

int n,k,ans,x,a[200001];

int main()

{

	cin>>n>>k;

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

	{

		cin>>x;

		++a[x];

	}

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

	for(int i=n;i>n-k;--i)

		ans+=a[i];

	cout<<n-ans<<endl;

	return 0;

}

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

#include<algorithm>

using namespace std;

int n,k,i,j,srx[200001],sry,t,p;

int main()

{

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

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

   {

        scanf("%d",&t);

        srx[t]++;

   }

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

   for(i=n;i>n-k;--i)

   sry+=srx[i];

   printf("%d",n-sry);

   return 0;

}

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

using namespace std;

int sum=0,n,x,k,ans=0;

int a[1000001];

map<int,int> m; 

int main()

{

    cin>>n>>k;

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

    {

        scanf("%d",&x);

        m[x]++;

    }

    int q=m.size();

    map<int,int>::iterator it=m.begin();

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

    {

        a[++sum]=(*it).second;

    }

    sort(a+1,a+sum+1);

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

    {

        ans+=a[i];

    }

    cout<<ans<<endl;

    return 0;

 } 

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

#include<algorithm>

using namespace std;

int n,k,i,j,srx[200001],sry,t,p;

int main(){

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

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

   scanf("%d",&t);

   srx[t]++;

   } 

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

   for(i=n;i>n-k;--i) 

   sry+=srx[i]; 

   printf("%d",n-sry); 

   return 0;

}

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

using namespace std;

typedef long long ll;

#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)

const ll INF=1e9+7;

const ll N = 200001;

ll n,ans=0,a[N],k;

priority_queue<ll> q;

int main(){

	cin>>n>>k;

	FOR(i,0,N)a[i]=0;

	FOR(i,0,n){

		ll w;

		cin>>w;

		a[w]++;

	}

	FOR(i,0,N){

		if(a[i]!=0){

			q.push(-a[i]);

		}

	}

	while(q.size()>k){

		ll w=-q.top();

		ans+=w;

		q.pop();

	}

	cout<<ans<<endl;

	return 0;

}

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

using namespace std;

typedef long long ll;

#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)

#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted

#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted

#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted

#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9

#define REV(x) (reverse(x.begin(),x.end())) //reverse

#define TO(x,t,f) ((x)?(t):(f))

#define CLR(mat) memset(mat, 0, sizeof(mat))

#define FILV(x,a) fill(x.begin(),x.end(),a)

#define FILA(ar,N,a) fill(ar,ar+N,a)

#define NEXTP(x) next_permutation(x.begin(),x.end())

ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}

ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu

#define pb push_back

#define pri(aa) cout<<(aa)<<endl

const ll INF=1e9+7;

const ll N = 200002;

 

int main(){

	ios::sync_with_stdio(false);

	cin.tie(0);

	ll k,n,ans=0;

	vector<ll> v;

	cin>>n>>k;

	FOR(i,0,n){

		ll r;cin>>r;

		v.pb(r);

	}

	SORT(v);

	vector<ll> kosu;

	FOR(i,0,n){

		ll r=NUM(v,v[i]);

		kosu.pb(r);

		i+=r;

		i--;

	}

	SORT(kosu);

	ll i=0;

	while(1){

		if(kosu.size()<=k+i)break;

		ans+=kosu[i];

		i++;

	}

	pri(ans);

    return 0;

}


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

#include<math.h>

#include<string.h>

#include<iostream>

#include<algorithm>

#include<queue>

#include<stack>

#include<set>

#include<map>

#include<vector>

#include<deque>

#include<string>

#define dint __int128

using namespace std;

#define kk putchar(32)

#define gc getchar()

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

#define fdn(i,a,b) for(int i=a,i##e=b;i>=i##e;--i)

#define mem(a,b) memset(a,b,sizeof(a))

#define hh putchar(10)

#define ll long long

inline ll rrr(){ll x,f=1;char a;while((a=gc)<48||a>57)if(a==45)f=-1;

for(x=a^48;(a=gc)>47&&a<58;x=(x<<3)+(x<<1)+(a^48));return f*x;}

struct nnn{int x,y,z;};

void Main();



int main()

{

    Main();

    return 0;

}

int b[200004],a[200004];

void Main()

{

    int n,k;

    cin>>n>>k;

    fup(i,0,n-1)b[i]=rrr();

    sort(b,b+n);

//    fup(i,0,n-1)cout<<b[i]<<' ';hh;

    int p=0;

    fup(i,0,n-1){

        ++a[p];

        while(b[i]==b[i+1]){

            ++i;++a[p];

        }

        ++p;

    }

    sort(a,a+p);

//    fup(i,0,p-1)cout<<a[i]<<' ';hh;

    int ans=0;

    fup(i,0,p-k-1)ans+=a[i];

    cout<<ans;

}


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

#define N 200002



int a[N] = {0}, b[N] = {0};



int read()

{

	char c;

	while((c = getchar()) < 48 || c > 57);

	int x = c - 48;

	while((c = getchar()) > 47 && c < 58) x = x * 10 + c - 48;

	return x;

}



int main()

{		

	int n, k, i, c = 0, t, ans = 0;

	

	n = read(), k = read();

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

		a[read()]++;

	}

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

		if(t = a[i]) b[t]++, c++;

	}

	if(c <= k) puts("0");

	else{

		c -= k;

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

			if(t = b[i]){

				if(c > t) c -= t, ans += t * i;

				else{

					ans += c * i;

					c = 0;

					break;

				}

			}

		}

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

	}

				

	return 0;

}

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



using namespace std;

int c[200001];

int main()

{

    int n,x,k ;

    cin >> n >> k ;

    set<int>s;

    vector<int>v;



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

    {

        cin >> x;

        c[x]++;

        s.insert(x);

    }

    set<int>::iterator it = s.begin() ;

    x=0;

    v.clear();

    if(k<s.size())

    {

        for( it ; it!=s.end() ;it++)

        {

            v.push_back(c[*it]);

        }

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

        x=0;

        for(int i = 0 ; i < s.size()-k ;i++)

        {

            x+=v[i];

        }

        cout << x <<"\n";

    }

    else

    {

        cout << 0;

    }

    return 0;

}


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

#define N 200002



int a[N] = {0}, b[N] = {0};



int read()

{

	char c;

	while((c = getchar()) < 48 || c > 57);

	int x = c - 48;

	while((c = getchar()) > 47 && c < 58) x = x * 10 + c - 48;

	return x;

}



int main()

{		

	int n, k, i, c = 0, t, ans = 0;

	

	n = read(), k = read();

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

		a[read()]++;

	}

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

		if(t = a[i]) b[t]++, c++;

	}

	if(c <= k) puts("0");

	else{

		c -= k;

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

			if(t = b[i]){

				if(c > t) c -= t, ans += t * i;

				else{

					ans += c * i;

					c = 0;

					break;

				}

			}

		}

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

	}

				

	return 0;

}

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

using namespace std;

int main()

{

    long long int n,k,a,p,ct;

    cin>>n>>k;;

    ct=0;

    long long arr[n+2]={0};

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

    {

        cin>>a;

        if(arr[a]==0){ct++;}

        arr[a]++;

    }

    p=0;

    if(ct>k){sort(arr,arr+n+1);

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

        {

            if(arr[i]>0)

            {

                p+=arr[i];

                --ct;

                if(ct==k) break;

            }

        }

    }

    cout<<p<<endl;;

    return 0;

}




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

#define N 200002



int a[N] = {0}, b[N] = {0};



int read()

{

	char c;

	while((c = getchar()) < 48 || c > 57);

	int x = c - 48;

	while((c = getchar()) > 47 && c < 58) x = x * 10 + c - 48;

	return x;

}



int main()

{		

	int n, k, i, c = 0, t, ans = 0;

	

	n = read(), k = read();

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

		a[read()]++;

	}

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

		if(t = a[i]) b[t]++, c++;

	}

	if(c <= k) puts("0");

	else{

		c -= k;

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

			if(t = b[i]){

				if(c > t) c -= t, ans += t * i;

				else{

					ans += c * i;

					c = 0;

					break;

				}

			}

		}

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

	}

				

	return 0;

}

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

#define  ll  long long int

#define  sz  200010



using namespace std;



ll num[sz];

priority_queue<ll>q;

set<ll>st;

set<ll> :: iterator it;



int main()

{



    ll n,i,j,s=0,d,k,x,a,b,p;



    cin>>n>>k;



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

    {

        cin>>d;

        st.insert(d);

        num[d]++;

    }



    p=st.size();



    if(p<=k)

    {

        cout<<0<<endl;

        return 0;

    }



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

    {

        d=*it;

        x=num[d];

        q.push(-x);



    }



    ll c=0;

    d=p-k;



    while(!q.empty())

    {

        x=q.top();

        q.pop();

        x=x*-1;

        c++;



        s+=x;



        if(c==d)break;

    }





    cout<<s<<endl;





    return 0;

}


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

#define N 200002



int a[N] = {0}, b[N] = {0};



int read()

{

	char c;

	while((c = getchar()) < 48 || c > 57);

	int x = c - 48;

	while((c = getchar()) > 47 && c < 58) x = x * 10 + c - 48;

	return x;

}



int main()

{		

	int n, k, i, c = 0, t, ans = 0;

	

	n = read(), k = read();

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

		a[read()]++;

	}

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

		if(t = a[i]) b[t]++, c++;

	}

	if(c <= k) puts("0");

	else{

		c -= k;

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

			if(t = b[i]){

				if(c > t) c -= t, ans += t * i;

				else{

					ans += c * i;

					c = 0;

					break;

				}

			}

		}

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

	}

				

	return 0;

}

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



using namespace std;



typedef long long ll;



double getTime() {

  return clock() / (double) CLOCKS_PER_SEC;

}



void read() {};



template<typename T, typename... Args>

void read(T& a, Args&... args) {

  cin >> a;

  read(args...);

}



void print() {};



template <typename T, typename... Args>

void print(T a, Args... args) {

  cout << a << " \n"[sizeof...(args) == 0];

  print(args...);

}



ll get(ll x, ll y) {

  return (x / y);

}



int main() {

  int n, k; read(n, k);

  map <int, int> cnt;

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

    int x; cin >> x;

    cnt[x]++;

  }

  vector <int> p;

  for(auto x : cnt) p.push_back(x.second);

  if(p.size() <= k) {

    cout << 0 << '\n';

    return 0;

  }

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

  int ans = 0;

  for(int i = 0; i < p.size() - k; i++) ans += p[i];

  cout << ans << '\n';

}

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

#define N 200002



int a[N] = {0}, b[N] = {0};



int read()

{

	char c;

	while((c = getchar()) < 48 || c > 57);

	int x = c - 48;

	while((c = getchar()) > 47 && c < 58) x = x * 10 + c - 48;

	return x;

}



int main()

{		

	int n, k, i, c = 0, t, ans = 0;

	

	n = read(), k = read();

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

		a[read()]++;

	}

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

		if(t = a[i]) b[t]++, c++;

	}

	if(c <= k) puts("0");

	else{

		c -= k;

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

			if(t = b[i]){

				if(c > t) c -= t, ans += t * i;

				else{

					ans += c * i;

					c = 0;

					break;

				}

			}

		}

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

	}

				

	return 0;

}

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

#define ll long long

#define ld long double

#define f first

#define s second

using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;



const int N = 2e5+5;

ll cnt[N];



int main()

{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);



    ll n,k;

    cin >> n >> k;

    set<ll> st;

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

    {

        ll x;

        cin >> x;

        st.insert(x);

        cnt[x]++;

    }



    vector< ll > v;



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

    {

        if (cnt[i])

        {

            v.push_back(cnt[i]);

        }

    }



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

    int dif = max( (ll)0 , (ll)st.size()-k);

    ll ans=0;

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

        ans += v[i];



    cout << ans;



    return 0;

}

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

#define N 200002



int a[N] = {0}, b[N] = {0};



int read()

{

	char c;

	while((c = getchar()) < 48 || c > 57);

	int x = c - 48;

	while((c = getchar()) > 47 && c < 58) x = x * 10 + c - 48;

	return x;

}



int main()

{		

	int n, k, i, c = 0, t, ans = 0;

	

	n = read(), k = read();

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

		a[read()]++;

	}

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

		if(t = a[i]) b[t]++, c++;

	}

	if(c <= k) puts("0");

	else{

		c -= k;

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

			if(t = b[i]){

				if(c > t) c -= t, ans += t * i;

				else{

					ans += c * i;

					c = 0;

					break;

				}

			}

		}

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

	}

				

	return 0;

}

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

using namespace std;

typedef long long ll;

int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int n, k;

    cin >> n >> k;

    map<int, int> mm;

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

        int in;

        cin >> in;

        mm[in]++;

    }

    vector<pair<int, int>> vec;

    for (auto &x : mm) {

        vec.push_back({x.second, x.first});

    }

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

    if (vec.size() <= k)

        return cout << 0, 0;

    int cnt = vec.size();

    ll res = 0;

    int idx = 0;

    for (int i = 0; i < vec.size()  - 1; i++) {

        if (cnt == k)

            break;

        cnt--;

        res += vec[i].first;

    }

    cout << res;

    return  0;

}

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

#define N 200002



int a[N] = {0}, b[N] = {0};



int read()

{

	char c;

	while((c = getchar()) < 48 || c > 57);

	int x = c - 48;

	while((c = getchar()) > 47 && c < 58) x = x * 10 + c - 48;

	return x;

}



int main()

{		

	int n, k, i, c = 0, t, ans = 0;

	

	n = read(), k = read();

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

		a[read()]++;

	}

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

		if(t = a[i]) b[t]++, c++;

	}

	if(c <= k) puts("0");

	else{

		c -= k;

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

			if(t = b[i]){

				if(c > t) c -= t, ans += t * i;

				else{

					ans += c * i;

					c = 0;

					break;

				}

			}

		}

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

	}

				

	return 0;

}

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

#define H ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define ll long long

#define ld long double

using namespace std;

const ll  mod = 998244353;



    int frq[200001];



int main()

{

    H

    int n, k;

    cin >> n >> k;

    int x;

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

        cin >> x;

        frq[x]++;

    }

    priority_queue<int> pq;

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

        if (frq[i]) {

            pq.push(-frq[i]);

        }



    }

    int ans = 0;

    while (pq.size() > k){

        ans += -pq.top();

        pq.pop();

    }

    cout << ans;

    return 0 ;

}


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

#define N 200002



int a[N] = {0}, b[N] = {0};



int read()

{

	char c;

	while((c = getchar()) < 48 || c > 57);

	int x = c - 48;

	while((c = getchar()) > 47 && c < 58) x = x * 10 + c - 48;

	return x;

}



int main()

{		

	int n, k, i, c = 0, t, ans = 0;

	

	n = read(), k = read();

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

		a[read()]++;

	}

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

		if(t = a[i]) b[t]++, c++;

	}

	if(c <= k) puts("0");

	else{

		c -= k;

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

			if(t = b[i]){

				if(c > t) c -= t, ans += t * i;

				else{

					ans += c * i;

					c = 0;

					break;

				}

			}

		}

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

	}

				

	return 0;

}

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



using namespace std;



const int N = 200005;

int cnt[N], aux[N];



int main() {

    int n, k;

    cin >> n >> k;

    map <int, int> mp;

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

        int x;

        cin >> x;

        cnt[x]++;

    }

    int sz = 0;

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

        if (cnt[i]) {

            aux[sz++] = cnt[i];

        }

    }

    sort(aux, aux + sz);

    int res = 0;

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

        res += aux[i];

    }

    cout << res;

    return 0;

}

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

#define N 200002



int a[N] = {0}, b[N] = {0};



int read()

{

	char c;

	while((c = getchar()) < 48 || c > 57);

	int x = c - 48;

	while((c = getchar()) > 47 && c < 58) x = x * 10 + c - 48;

	return x;

}



int main()

{		

	int n, k, i, c = 0, t, ans = 0;

	

	n = read(), k = read();

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

		a[read()]++;

	}

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

		if(t = a[i]) b[t]++, c++;

	}

	if(c <= k) puts("0");

	else{

		c -= k;

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

			if(t = b[i]){

				if(c > t) c -= t, ans += t * i;

				else{

					ans += c * i;

					c = 0;

					break;

				}

			}

		}

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

	}

				

	return 0;

}

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

using namespace std;



int main()

{

    ////////////////////////////

    //入力

    int n,k;

    cin >> n >> k;



    int a[n];

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

	cin >> a[i];

    }



    //計算

    int cnt[200000]={};

    int types = 0;



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

	//もしi番目のボールの数字が初登場なら種類数を1増やす

	if (cnt[a[i]] == 0){

	    types++;

	}

	//「i番目のボールに書かれていた数字」の登場回数メモを1増やす

	cnt[a[i]]++;

    }

    

    //既にk種類以下の場合、書き換える数は0なので出力して終了する

    if (types <= k){

	cout << 0 << endl;

	return 0;

    }

    int ans = 0;

    for (int f=1; f<200000; f++){

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

	    //登場回数が1回の数字から書き換えて行く

	    if (cnt[j] == f){

	        types--;

		ans += f;

		if (types <= k){

		    cout << ans << endl;

		    return 0;

		}

	    }

	}

    }

    ////////////////////////////

    return 0;

}

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

#include <algorithm>



using namespace std;



int main()

{

    ////////////////////////////

    //入力

    int n,k;

    cin >> n >> k;



    int a;

    int cnt[n+1] = {};

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

	cin >> a;

	cnt[a]++;

    }



    //計算

    sort(cnt, cnt+n+1);

    int types = 0;



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

	if (cnt[i] > 0){

	    types++;

	}

    }

    

    int num = max(0, types-k);

    int ans = 0;

    int i = 0;

    while( cnt[i] == 0 ){

	i++;

    }

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

	ans += cnt[i];

	i++;

    }

    cout << ans << endl;

    ////////////////////////////

    return 0;

}

// Fastest known solution for this problem: