stablegradients/pie-gem5-pairs huggingface dataset:
// 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.807307946180086x):
#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);

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

}


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

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



}

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

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

    }

}

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

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

}


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

using namespace std;



#define      ll     long long int



const int N = 200005;

int ara[N];

map<int, int> mp;

map<int, int>::iterator it;

vector< int > v;



int main()

{

    int n, k, i, j, l;

    pair<int, int> p;

    cin >> n >> k;

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

        cin >> ara[i];

        mp[ara[i]]++;

    }

    l = (int) mp.size();

    if (l <= k) {

        cout << "0\n";

    }

    else {

        for (it = mp.begin(); it != mp.end(); it++) {

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

        }

        int s = 0;

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

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

            s += v[i];

        }

        cout << s << '\n';

    }

    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.7974421250089783x):
#include <bits/stdc++.h>

using namespace std;



#define      ll     long long int



const int N = 200005;

int ara[N];

map<int, int> mp;

map<int, int>::iterator it;

vector< int > v;



int main()

{

    int n, k, i, j, l;

    pair<int, int> p;

    cin >> n >> k;

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

        cin >> ara[i];

        mp[ara[i]]++;

    }

    l = (int) mp.size();

    if (l <= k) {

        cout << "0\n";

    }

    else {

        for (it = mp.begin(); it != mp.end(); it++) {

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

        }

        int s = 0;

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

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

            s += v[i];

        }

        cout << s << '\n';

    }

    return 0;

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

}


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

#define ll long long int

ll v[1000000+9];

using namespace std;

int main()

{

    ll i,j,ans=0,x,p,n,k;



    map<ll,ll>m;

    map<ll,ll> :: iterator it;



    cin>>n>>k;



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

    {

        cin>>p;

        m[p]++;

    }



    x=m.size();

    //cout<<x<<endl;

    if(x<=k)

    {

        cout<<0<<endl;

    }

    else

    {



        j=0;

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

        {

            v[j]=it->second;

            j++;

        }

        x=m.size();

        sort(v,v+x);



        ll s=m.size()-k;



        for(i=0; i<s; 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.7846360477436058x):
#include<bits/stdc++.h>

#define ll long long int

ll v[1000000+9];

using namespace std;

int main()

{

    ll i,j,ans=0,x,p,n,k;



    map<ll,ll>m;

    map<ll,ll> :: iterator it;



    cin>>n>>k;



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

    {

        cin>>p;

        m[p]++;

    }



    x=m.size();

    //cout<<x<<endl;

    if(x<=k)

    {

        cout<<0<<endl;

    }

    else

    {



        j=0;

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

        {

            v[j]=it->second;

            j++;

        }

        x=m.size();

        sort(v,v+x);



        ll s=m.size()-k;



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

        {

            ans+=v[i];

        }

        cout<<ans<<endl;

    }

    return 0;

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

}


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

using namespace std;

#include<vector>

int main()

{

    long long n,k,i,ans=0,c=0;

    cin>>n>>k;

    int a[n+2];

    vector<int>v;

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

    {

        cin>>a[i];

    }

    sort(a,a+n);

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

    {

        c++;

        ans=1;

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

        {

            i++;

            ans++;

        }

        v.push_back(ans);

    }

    if(c<=k)

    {

        cout<<0<<endl;

    }

    else

    {

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

        ans=0;

        for(i=0;i<(c-k);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.7797892431703337x):
#include<bits/stdc++.h>

using namespace std;

#include<vector>

int main()

{

    long long n,k,i,ans=0,c=0;

    cin>>n>>k;

    int a[n+2];

    vector<int>v;

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

    {

        cin>>a[i];

    }

    sort(a,a+n);

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

    {

        c++;

        ans=1;

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

        {

            i++;

            ans++;

        }

        v.push_back(ans);

    }

    if(c<=k)

    {

        cout<<0<<endl;

    }

    else

    {

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

        ans=0;

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

        {

            ans+=v[i];

        }

        cout<<ans<<endl;

    }

    return 0;

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

}


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

}
// 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.8076302712333914x):
#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;

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

}


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

using namespace std;

int main()

{

 int N,k,i,j,a[200002],l;

  int n[200002],idx=0,sum=0;

    map<int,int>m;

    set<int>s;

    cin>>N>>k;

    for(i=0;i<N;i++){cin>>a[i];m[a[i]]++;}

    for(i=0;i<N;i++){s.insert(a[i]);}

    set<int>::iterator it;

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

       n[idx]=m[*it];idx++;

    }

    sort(n,n+idx);

    if(s.size()<=k){cout<<"0\n";}

    else{

       l=s.size()-k+1;

       for(j=0;j<l-1;j++){sum+=n[j];}

        cout<<sum<<endl;

     }

    

    



    }