stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

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

#define ll long long

#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

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

const int N = 2e5 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;

const ll inf = 1e18;



int freq[N];



int main() {

  fastIO;

#ifdef LOCAL

  freopen("input.in", "rt", stdin);

#endif

  int n, k, a;

  cin >> n >> k;

  vector<int> vec;

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

    cin >> a;

    freq[a]++;

  }

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

    if(freq[i])

      vec.push_back(freq[i]);

  }

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

  ll total = 0;

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

    total += vec[i];

  }

  cout << total;

  return 0;

}


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

using namespace std;

#define ll long long

#define pb push_back

#define F first

#define S second

const int mod = 1e9+7, A = 1e3+5;



int main()

{

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

	int n, k;

	cin >> n >> k;

	map<int, int> mop;

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

		cin >> x, mop[x]++;

	vector<int> v;

	for (auto i : mop)

		v.pb(i.S);

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

	int ans = 0;

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

		ans += v[i];

	cout << ans;

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

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

#define ll long long

#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

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

const int N = 2e5 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;

const ll inf = 1e18;



int freq[N];



int main() {

  fastIO;

#ifdef LOCAL

  freopen("input.in", "rt", stdin);

#endif

  int n, k, a;

  cin >> n >> k;

  vector<int> vec;

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

    cin >> a;

    freq[a]++;

  }

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

    if(freq[i])

      vec.push_back(freq[i]);

  }

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

  ll total = 0;

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

    total += vec[i];

  }

  cout << total;

  return 0;

}


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

using namespace std;

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

#define ll long long

#define endl '\n'

int main()

{

    Hello

    int n, k;

    cin >> n >> k;

    int arr[n + 5], freq[n + 5] = {}, mn = 1e9, mx = 0;

    set<int> st;

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

    {

        cin >> arr[i];

        freq[arr[i]]++;

        st.insert(arr[i]);

        mn = min(mn, arr[i]);

        mx = max(mx, arr[i]);

    }

    if(st.size() <= k)

        return cout << 0, 0;

    pair<int, int> pr[n + 5];

    int idx = 0, ans = 0;

    for(int i = mn; i <= mx; i++)

    {

        if(freq[i])

        {

            pr[idx].first = freq[i];

            pr[idx].second = i;

            idx++;

        }

    }

    sort(pr, pr + idx);

    //for(int i = 0; i < idx; i++)

    //    cout << pr[i].first << " " << pr[i].second << endl;

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

    {

        ans += pr[i].first;

        st.erase(pr[i].second);

        if(st.size() <= k)

            return cout << ans, 0;

    }

    cout << ans, 0;

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

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

#define ll long long

#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

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

const int N = 2e5 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;

const ll inf = 1e18;



int freq[N];



int main() {

  fastIO;

#ifdef LOCAL

  freopen("input.in", "rt", stdin);

#endif

  int n, k, a;

  cin >> n >> k;

  vector<int> vec;

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

    cin >> a;

    freq[a]++;

  }

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

    if(freq[i])

      vec.push_back(freq[i]);

  }

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

  ll total = 0;

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

    total += vec[i];

  }

  cout << total;

  return 0;

}


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

using namespace std;

int main()

{

    int n,m,sum=0;

    cin>>n>>m;

    m=n+1-m;

    int a[n],i,b[n+1];

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

    b[i]=0;

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

        cin>>a[i];

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

    {

        int k=a[i];

        b[k]++;

    }

    sort(b,b+n+1);

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

   sum=sum+b[i];



    cout<<sum<<endl;

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

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

#define ll long long

#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

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

const int N = 2e5 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;

const ll inf = 1e18;



int freq[N];



int main() {

  fastIO;

#ifdef LOCAL

  freopen("input.in", "rt", stdin);

#endif

  int n, k, a;

  cin >> n >> k;

  vector<int> vec;

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

    cin >> a;

    freq[a]++;

  }

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

    if(freq[i])

      vec.push_back(freq[i]);

  }

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

  ll total = 0;

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

    total += vec[i];

  }

  cout << total;

  return 0;

}


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



using namespace std;



const int N = 200005;

int 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;

        mp[x]++;

    }

    int sz = 0;

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

        aux[sz++] = it->second;

    }

    sort(aux, aux + sz);

    int res = 0;

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

        res += aux[i];

    }

    cout << res;

    return 0;

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

#include <algorithm>

#include <vector>

using namespace std;



int main() {

    int n,k;

    int a[200001] = {};



    cin >> n >> k;

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

        int nn;

        cin >> nn;

        a[nn]++;

    }

    vector<int> cnt;

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

        if(a[i] == 0)continue;

        cnt.push_back(a[i]);

    }

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

    int rem = cnt.size() - k;

    int nums = 0;

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

        nums += cnt[i];

    }

    cout << nums << endl;

    return 0;

}


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

#include <algorithm>

#include <vector>

using namespace std;



int a[200001];

int main() {

    int n,k;

   

    cin >> n >> k;

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

        int nn;

        cin >> nn;

        a[nn]++;

    }

    vector<int> cnt;

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

        if(a[i] == 0)continue;

        cnt.push_back(a[i]);

    }

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

    int rem = cnt.size() - k;

    int nums = 0;

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

        nums += cnt[i];

    }

    cout << nums << endl;

    return 0;

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

#include <iostream>

using namespace std;



const int maxn=200005;



int a[maxn];



bool cmp(int a,int b)

{

	return a>b;

}



int main()

{

	int n,k;

	cin>>n>>k;

	int max=-0x3f3f;

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

	{

		int x;

		cin>>x;

		max=(x>max)?x:max;

		a[x]++;

	}

	sort(a+1,a+1+max,cmp);

	int ans=0;

	for(int i=k+1;a[i];++i)

	{

		ans+=a[i];

	}

	cout<<ans<<endl;

	return 0;

}

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

#define ll long long

#define met(a,x) memset(a,x,sizeof(a))

#define inf 0x3f3f3f3f

using namespace std;

const int mod=1e9+7;

const int N=200010;

int a[N],b[N];

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    int i,j,k,m,n;

    int ans=0,cnt=0,num=0;

    cin>>n>>k;

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

    {

        cin>>m;

        a[m]++;

    }

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

        if(a[i])

            cnt++;

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

    if(cnt<k)

    {

        cout<<0<<endl;

        return 0;

    }

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

    {

        if(cnt==k+num)

            break;

        if(a[i])

        {

            num++;

            ans+=a[i];

        }

    }

    cout<<ans<<endl;

    return 0;

}


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

int main(){

	int n,k,m,l,sum=0,cot=0,x=1e7,y=-1;

	memset(a,0,sizeof(a));

	cin>>n>>k;

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

		cin>>m;

		a[m]++;

		x=min(x,m);

		y=max(y,m);

	}

	if((y-x+1)<=k){

		cout<<0;

		return 0;

	}

	sort(a+x,a+y+1);

	while((y-x+1)>k){

		sum+=a[x];

		x++;

	}

	cout<<sum;

	return 0;

}

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

int main(){

	int n,k,m,l,sum=0,cot=0,x=1e7,y=-1;

	memset(a,0,sizeof(a));

	cin>>n>>k;

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

		cin>>m;

		a[m]++;

		x=min(x,m);

		y=max(y,m);

	}

	if((y-x+1)<=k){

		cout<<0;

		return 0;

	}

	sort(a+x,a+y+1);

	while((y-x+1)>k){

		sum+=a[x];

		x++;

	}

	cout<<sum;

	return 0;

}

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

#include<cmath>

#include<algorithm>

#include<cctype>

#include<cstring>

#include<queue>

#include<iostream>

#include<map>

using namespace std;

typedef long long ll;

typedef double lf;

typedef unsigned un;

typedef int in;

#define mian main

#define maxn 10000+10

#define maxm 10000+10

#define _(a) read(a)

#define non void

#define inf 2147483647

#define bre break

#define con continue

#define prq priority_queue

#define re register

#define bu bool

#define cz char

#define cst const

#define ope operator

#define inl inline

#define upp upper_bound

#define low lower_bound

#define next_per next_permutation

inl cz gc(){static cz buf[100000],*L=buf,*R=buf;return L==R&&(R=(L=buf)+fread(buf,1,100000,stdin),L==R)?EOF:*L++;}

template<typename T>inl T Max(T a,T b){return a>b?a:b;}

template<typename T>inl T Min(T a,T b){return a<b?a:b;}

template<typename T>inl T Abs(T a){return a<0?-a:a;}

template<typename T>inl non read(T &a){a=0;T k=1;char c=gc();while(c<'0'||c>'9')k=c=='-'?-1:k,c=gc();while(c>='0'&&c<='9')a=a*10+(c^48),c=gc();if(c!='.'){a*=k;return;}T t=0.1;while(c<'0'||c>'9')c=gc();while(c>='0'&&c<='9')a+=t*(c^48),c=gc(),t*=0.1;a*=k;}

template<typename T>non write(T a,cz t=' '){if(a==0){putc(48,stdout),putc(t,stdout);return;}if(a<0){a=-a;putc('-',stdout);}cz c[30];in le=0;while(a){c[++le]=a%10+48;a/=10;}for(re in i=le;i>=1;--i)putc(c[i],stdout);putc(t,stdout);}

in n,k,a,s,m[300000];

in main()

{

	read(n),read(k);

	for(re in i=1;i<=n;++i){read(a);++m[a];}

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

	for(in i=n;i>n-k;--i)s+=m[i];

	write(n-s);

	//freopen(".in","r",stdin);

	//freopen(".out","w",stdout);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int a[200010];

int main(){

	int n,k,m,l,sum=0,cot=0,x=1e7,y=-1;

	memset(a,0,sizeof(a));

	cin>>n>>k;

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

		cin>>m;

		a[m]++;

		x=min(x,m);

		y=max(y,m);

	}

	if((y-x+1)<=k){

		cout<<0;

		return 0;

	}

	sort(a+x,a+y+1);

	while((y-x+1)>k){

		sum+=a[x];

		x++;

	}

	cout<<sum;

	return 0;

}

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

#include<iostream>

#include<algorithm>

#include<cstdlib>

#include<cstring>

using namespace std;

int n,k,m,a[200005],sum,num;

int main()

{

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

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

	{

		scanf("%d",&m);

		a[m]++;

		if(a[m]==1)sum++;

	}

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

	{

		if(a[i]==0)a[i]=99999999;

	}

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

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

	{

		if(sum<=k)break;

		num+=a[i];

		sum--;

	}

	cout<<num<<endl;

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main()

{

	int a,n,k,b[200010]={0},t=0,ans=0,x,m=0;

	cin>>n>>k;

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

	{

		cin>>a;

		b[a]++;

	} 

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

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

		if(b[i])t++;

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

	{

		if(t-m<=k){cout<<ans;return 0;} 

		else

		{

			if(b[i])

		    { 

			ans+=b[i];

		    m++;

		    } 

		}

	}

	return 0;

}

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

#include<iostream>

#include<algorithm>

#include<cstdlib>

#include<cstring>

using namespace std;

int n,k,m,a[200005],sum,num;

int main()

{

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

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

	{

		scanf("%d",&m);

		a[m]++;

		if(a[m]==1)sum++;

	}

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

	{

		if(a[i]==0)a[i]=99999999;

	}

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

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

	{

		if(sum<=k)break;

		num+=a[i];

		sum--;

	}

	cout<<num<<endl;

	return 0;

}
// Slower C++ solution:
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;



int main()

{

    int n, k, a[1000009];

    while(~scanf("%d %d", &n ,&k))

    {

        memset(a, 0, sizeof(a));

        int num, l = 999999, r = 0;

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

        {

            scanf("%d", &num);

            a[num]++;

            l = min(l, num);

            r = max(r, num);

        }

        if(r - l + 1 <= k)

            printf("0\n");

        else

        {

            sort(a+l, a+r+1);

            int ans = 0;

            while(r - l + 1 > k)

                ans += a[l++];

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

        }

    }

    return 0;

}


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

#include <algorithm>

using namespace std; 

int arrCount[200005] = { 0 }; 

bool cmp(int iNum1, int iNum2)

{ 

    return iNum1 > iNum2;

}

int main()

{

    int n, m, i, t, iSum=0,maxn(1); 

    cin >> n >> m; 

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

    { 

        cin >> t;

        ++arrCount[t]; 

        maxn=(t>maxn?t:maxn);

    }

    sort(arrCount, arrCount + maxn+1,cmp); 

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

    { 

        iSum += arrCount[i]; 

    }

    cout << iSum << endl; 

    return 0; 

}
// Slower C++ solution:
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;



int main()

{

    int n, k, a[1000009];

    while(~scanf("%d %d", &n ,&k))

    {

        memset(a, 0, sizeof(a));

        int num, l = 999999, r = 0;

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

        {

            scanf("%d", &num);

            a[num]++;

            l = min(l, num);

            r = max(r, num);

        }

        if(r - l + 1 <= k)

            printf("0\n");

        else

        {

            sort(a+l, a+r+1);

            int ans = 0;

            while(r - l + 1 > k)

                ans += a[l++];

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

        }

    }

    return 0;

}


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

using namespace std; 

int arrCount[200005] = { 0 }; 

bool cmp(int iNum1, int iNum2)

{ 

    return iNum1 > iNum2;

}

int main()

{

    int n, m, i, t, iSum=0,maxn(1); 

    cin >> n >> m; 

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

    { 

        scanf("%d",&t);

        ++arrCount[t]; 

        maxn=(t>maxn?t:maxn);

    }

    sort(arrCount, arrCount + maxn+1,cmp); 

    for (i = m; arrCount[i]; ++i)

    { 

        iSum += arrCount[i]; 

    }

    cout << iSum << endl; 

    return 0; 

}
// Slower C++ solution:
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;



int main()

{

    int n, k, a[1000009];

    while(~scanf("%d %d", &n ,&k))

    {

        memset(a, 0, sizeof(a));

        int num, l = 999999, r = 0;

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

        {

            scanf("%d", &num);

            a[num]++;

            l = min(l, num);

            r = max(r, num);

        }

        if(r - l + 1 <= k)

            printf("0\n");

        else

        {

            sort(a+l, a+r+1);

            int ans = 0;

            while(r - l + 1 > k)

                ans += a[l++];

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

        }

    }

    return 0;

}


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

 }
// Slower C++ solution:
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;



int main()

{

    int n, k, a[1000009];

    while(~scanf("%d %d", &n ,&k))

    {

        memset(a, 0, sizeof(a));

        int num, l = 999999, r = 0;

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

        {

            scanf("%d", &num);

            a[num]++;

            l = min(l, num);

            r = max(r, num);

        }

        if(r - l + 1 <= k)

            printf("0\n");

        else

        {

            sort(a+l, a+r+1);

            int ans = 0;

            while(r - l + 1 > k)

                ans += a[l++];

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

        }

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.341569930106217x):
#include<bits/stdc++.h>//懒人专用头文件

#define rpt(n) for(register int ttxyc=0;ttxyc<n;++ttxyc)//宏定义

using namespace std;

inline int read()//快读

{

	register int x=0,t=0;register char c=getchar();

	for(;c<'0'||c>'9';t|=c=='-',c=getchar());

	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+(c^48),c=getchar());

	return t?-x:x;

}

int n,k,a[200000],b,ans;map<int,int>mmp;

main()

{

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

	rpt(n)++mmp[read()];

	for(map<int,int>::iterator i=mmp.begin();i!=mmp.end();++i)a[b++]=i->second;

	if(b<=k){puts("0");return 0;}

	sort(a,a+b);

	rpt(b-k)ans+=a[ttxyc];

	printf("%d",ans);

}/**/
// Slower C++ solution:
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;



int main()

{

    int n, k, a[1000009];

    while(~scanf("%d %d", &n ,&k))

    {

        memset(a, 0, sizeof(a));

        int num, l = 999999, r = 0;

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

        {

            scanf("%d", &num);

            a[num]++;

            l = min(l, num);

            r = max(r, num);

        }

        if(r - l + 1 <= k)

            printf("0\n");

        else

        {

            sort(a+l, a+r+1);

            int ans = 0;

            while(r - l + 1 > k)

                ans += a[l++];

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

        }

    }

    return 0;

}


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

using namespace std;

int a[200001],n,k,m,ans,i,j,g;

int main(){

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

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

		scanf("%d",&m);

		a[m]++;

	}

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

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

		ans+=a[i];

	printf("%d",ans);

	return 0;

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

}

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

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

	}

}


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

}