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

}


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

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

}

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

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

}

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

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

 } 

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

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

}

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

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

}


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

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

}


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

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

}




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

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

}


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

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

}

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

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

}

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

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

}

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

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

}


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

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

}

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

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

}

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

#include <algorithm>

#include <utility>

#include <fstream>

#include <iomanip>

#include <complex>

#include <cmath>

#include <vector>

#include <cstring>

#include <string>

#include <sstream>

#include <map>

#include <set>

#include <queue>



#define IO ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);

typedef long long ll;

typedef long double ld;

const ll INF = 1e18;

const int N = 1e3 + 5, inf = 1e9, mod = 998244353;

using namespace std;



int main()

{

    IO

    int n, k, a, cnt = 0;

    vector <int> vec, ans;

    map <int, int> mp;

    cin >> n >> k;

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

    {

        cin >> a;

        if(!mp[a])

            vec.push_back(a);

        mp[a]++;

    }

    for(auto i : vec)

        ans.push_back(mp[i]);

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

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

        cnt += ans[i];

    cout << cnt << '\n';

    return 0;

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

}

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

 

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



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

template<class T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;



typedef long long  ll;

typedef unsigned long long  ull;

typedef long double ld;

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

#define lpi(i,j,n)   for(int i=j;i<n;i++)

#define lpd(i,j,n)   for(int i=j;i>=n;i--)

#define MP           make_pair

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

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

#define N 100005

const double pi = acos(-1);



ll n,t,m,k;



ll ans;

ll mod = 1e9 +7;

ll mat[105][105],a[10005];







int main() {

 

ios_base::sync_with_stdio(0);

cin.tie(0);cout.tie(0);

// freopen("e.txt","r",stdin); 

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

cout.precision(10);







cin>>n>>k;

vector<int>a(n),cnt;

map<int,int>mp;

lp(i,n){

  cin>>a[i];

  mp[a[i]]++;

}

for(auto& u:mp)cnt.push_back(u.second);

sort(all(cnt));

lp(i,(int)cnt.size()-k)ans+=cnt[i];

cout<<ans;







  

}

  

 







// bool isPrime(ll h){

//      for(ll i=0;primes[i]*primes[i]<= h;i++)

//      if (h%primes[i]==0)

//      	return 0;

//      return h!=1;

//  }

 bool isPrime(ll g){

   if((g%2==0 && g>2) || g==1)return 0;

   for(ll i=3;i*i<=g;i+=2)if(g%i==0)return 0;

   return 1;   

 

 }