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.7172616910277954x):
#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;

     }

    

    



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

using namespace std;

 

int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    

    int N, K; cin >> N >> K;

    vector<int> A;

    //int x;

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

        int x; cin >> x;

        A.push_back(x);

    }

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

 

    int cnt[200003] = {};

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

        ++cnt[A[i]];

    }

    sort(cnt, cnt + N + 1 , greater<int>());



    /*

    vector<int> cnt;

    int i = 0;

    while (i < N){

        int x = count(A.begin(), A.end(), A[i]);

        cnt.push_back(x);

        i += x;

    }

    sort(cnt.begin(), cnt.end(), greater<int>());

    */



    int sum = 0;

    //int sizecnt = cnt.size();

    //if (sizecnt <= K) {cout << 0; return 0;}

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

        

        sum += cnt[i];

    }

    /*

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



        sum += cnt[i];

    }

    */

    cout << N - sum << endl;

    return 0;

}

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

#include <vector>

#include <algorithm>

#include <numeric>

using namespace std;



char in[1<<21];

char const*o;



inline void init_in() { 

  o = in;

  in[fread(in,1,sizeof(in)-4,stdin)] = 0;

}



int readInt(){ 

  unsigned u = 0, s = 0;

  while(*o && *o <= 32){

    ++o;

  }

  if (*o == '-'){

    s = ~s, ++o;

  } else if (*o == '+'){

    ++o;

  }

   

  while(*o>='0' && *o<='9'){

    u = (u<<3) + (u << 1) + (*o++ - '0');

  }



  return static_cast<int>((u^s) + !!s) ;

}



int cnt[202020];

template<typename T> void fastout(T &n) {

  T N = n, rev, count = 0;

  rev = N;

  if (N == 0) {

    putchar_unlocked('0');

    putchar_unlocked('\n');

    return;

  }

  while ((rev % 10) == 0) { 

    ++count; rev /= 10;

  }

  rev = 0;

  while (N != 0) { 

    rev = (rev << 3) + (rev << 1) + N % 10;

    N /= 10;

  }

  while (rev != 0) { 

    putchar_unlocked(rev % 10 + '0');

    rev /= 10;

  }

  while (count--) putchar_unlocked('0');

  putchar_unlocked('\n');

}

int main(){

  init_in();

  int n = readInt(); int k = readInt();

  

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

    int x = readInt();

    ++cnt[x];

  }

  

  sort(cnt, cnt + n + 1 , greater<int>());



  n -= accumulate(cnt, cnt + k, int());



  fastout(n);



  return 0;

}
// Slower C++ solution:
/**

 *      ABC 81 C

 *      author  : kyomukyomupurin

 *      created : 2018-09-03 03:03:21

**/



#include <bits/stdc++.h>

using namespace std;

 

int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    

    int N, K; cin >> N >> K;

    vector<int> A;



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

        int x; cin >> x;

        A.push_back(x);

    }

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

 

    int cnt[200003] = {};//vector は遅い！！

    for (int i = 0; i < N; ++i) {//うまいやり方：個数分布を作る

        ++cnt[A[i]];

    }

    sort(cnt, cnt + N + 1 , greater<int>());



    int sum = 0;



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

        sum += cnt[i];

    }



    cout << N - sum << endl;

    return 0;

}

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

#include <vector>

#include <algorithm>

#include <numeric>

using namespace std;



char in[1<<21];

char const*o;



inline void init_in() { 

  o = in;

  in[fread(in,1,sizeof(in)-4,stdin)] = 0;

}



int readInt(){ 

  unsigned u = 0, s = 0;

  while(*o && *o <= 32){

    ++o;

  }

  if (*o == '-'){

    s = ~s, ++o;

  } else if (*o == '+'){

    ++o;

  }

   

  while(*o>='0' && *o<='9'){

    u = (u<<3) + (u << 1) + (*o++ - '0');

  }



  return static_cast<int>((u^s) + !!s) ;

}



int cnt[202020];

template<typename T> void fastout(T &n) {

  T N = n, rev, count = 0;

  rev = N;

  if (N == 0) {

    putchar_unlocked('0');

    putchar_unlocked('\n');

    return;

  }

  while ((rev % 10) == 0) { 

    ++count; rev /= 10;

  }

  rev = 0;

  while (N != 0) { 

    rev = (rev << 3) + (rev << 1) + N % 10;

    N /= 10;

  }

  while (rev != 0) { 

    putchar_unlocked(rev % 10 + '0');

    rev /= 10;

  }

  while (count--) putchar_unlocked('0');

  putchar_unlocked('\n');

}

int main(){

  init_in();

  int n = readInt(); int k = readInt();

  

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

    int x = readInt();

    ++cnt[x];

  }

  

  sort(cnt, cnt + n + 1 , greater<int>());



  n -= accumulate(cnt, cnt + k, int());



  fastout(n);



  return 0;

}
// Slower C++ solution:
#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; arrCount[i]; ++i)

    { 

        iSum += arrCount[i]; 

    }

    cout << iSum << endl; 

    return 0; 

}

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

#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<cstdio>

#include<cstring>

#include<algorithm>

#include<functional>

int n,m,a[200010];

signed main(){memset(a,0,sizeof(a));scanf("%d%d",&n,&m);int t,maxn(1),ans(0);while(n--){scanf("%d",&t),a[t]++,maxn=(maxn>t?maxn:t);}sort(a,a+maxn+1,std::greater<int>());while(a[m]){ans+=a[m++];}return printf("%d\n",ans),0;}

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

#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:
//inlclude before define 

#define _USE_MATH_DEFINES



//include

#include<iostream>

#include<string>

#include<algorithm>

#include<vector>

#include<cmath>

#include<type_traits>

#include<numeric>

#include<assert.h>

#include<deque>

#include<iomanip>

#include<set>

#include<tuple>

#include<map>



using namespace std;



//typedef

typedef vector<int> VI;

typedef vector<string> VS;

typedef vector<char> VC;

typedef pair<int, int> P1;

typedef long long int ll;



//define

#define INF 1e9

#define NUM 1000000007

#define all(x) begin(x),end(x)

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

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

#define chmin(a,b) a=min((a),(b))

#define chmax(a,b) a=max((a),(b))



int main () {

	int n,m;

	cin >> n>>m;

	int a;

	map<int, int> mp;

	rep (i, n) {

		cin >> a;

		mp[a]++;

	}



	int cnt = 0;

	vector<pair<int, int>> p;

	for (const auto& x : mp) {

		if (x.second > 0) cnt++;

		p.emplace_back (x.second, x.first);

	}



	sort (all(p));

	int ans = 0;

	if (cnt <= m) {

		cout << 0 << endl;

		return 0;

	} else {

		for (int i = 0; i < cnt - m; i++) {

			ans += p[i].first;

		}

	}



	cout << ans << endl;

	

}




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

#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 a[200001],ans=0,sum=0;

int main(){

	int i,j,k,n,l;

	cin>>n>>k;

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

		cin>>l;

		a[l]++;

	}

	sort(a,a+n+1);

	for(i=n;i>n-k;i--)sum+=a[i];

	cout<<n-sum<<endl;

	return 0;

}

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

#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 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<=maxn; ++i)

    { 

        iSum += arrCount[i]; 

    }

    cout << iSum << endl; 

    return 0; 

}

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

#include<cstring>

#include<algorithm>

#include<functional>

int n,m,a[200010];

signed main()

{

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

	scanf("%d%d",&n,&m);int t,maxn(1),ans(0);

	while(n--)

	{

		scanf("%d",&t),a[t]++,maxn=(maxn>t?maxn:t);

	}

	sort(a,a+maxn+1,std::greater<int>());

	while(a[m])

	{

		ans+=a[m++];

	}

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

}

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

int main()

{

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

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

	{

		int x;

		scanf("%d",&x);

		if(a[x]==0) q++;

		a[x]++;

	}

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

	int p=0,ans=0;

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

	if(a[i])

	{

		if(q-p<=k) break;

		p++;

		ans+=a[i];

	}

	printf("%d",ans);

}

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

int n,k,a;

int ans=0;

int ejud=0,fjud=0;

int main()

{

    cin>>n>>k;

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

    {

        countx[i]=0;

    }

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

    {

        cin>>a;

        if(countx[a]==0)

            fjud++;

        countx[a]++;

    }

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

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

    {

        if(countx[i]>0)

            ejud++;

        ans+=countx[i];

        if(ejud+k==fjud)

            break;

    }

    if(k<=fjud)

        cout<<ans<<endl;

    else

        cout<<0<<endl;

}

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

#include <string>

#include <cmath>

#include <vector>

#include <functional>

#include <stack>

#include <utility>

#include <map>

#include <queue>

#include <set>

#include <climits>



using namespace std;



typedef long long ll;

typedef pair<ll, ll> P;



const ll MOD = 1000000007;

const ll INF = LLONG_MAX;

const ll MAX_N = 100000;



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





int main() {

	int n, k, a[200001]{}, ans = 0;

	set<int> st;

	cin >> n >> k;

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

		int t;

		cin >> t;

		a[t]++;

		st.insert(t);

	}

	sort(a, a + n + 1);

	int siz = st.size();

	for (int i = 0; siz > k;i++) {

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

		ans += a[i];

		siz--;

	}

	cout << ans << endl;

	return 0;

}

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

#include <vector>

#include <algorithm>

using namespace std;



int main() {

    int n, k;

    cin >> n >> k;

    vector<int> cnt(n+1, 0);

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

        int a;

        cin >> a;

        cnt[a]++;

    }

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

    int ans = n;

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

        ans -= cnt[i];

    }

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

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

#define ll long long

#define max(a,b) (a>b?a:b)

#define min(a,b) (a<b?a:b)

#define max3(x,y,z) max(x,max(y,z))

#define min3(x,y,z) min(x,min(y,z))

#define f first

#define s second

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

#define rev(a) reverse(a.begin(),a.end())

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

#define rall(a) a.rbegin(),a.rend()

#define lb(a,v) lower_bound(all(a),v)

#define ub(a,v) upper_bound(all(a),v)

#define ins(v) insert(v)

#define pb(v) push_back(v)

#define sz(x) (int)(x).size()

#define MOD 1000000007

#define sf1(a) scanf("%d",&a)

#define sf2(a,b) scanf("%d %d",&a,&b)

#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)

#define sf4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)

using namespace std;

const int N=2e6+5;

int main()

{

    int x,n,k ;

    map<int,int>mp;

    cin>>n>>k;

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

    {

        cin>>x;

        mp[x]++;

    }

    int s=sz(mp);

    int arr[s],i=0;

    for(auto x:mp)

        arr[i++]=x.s;

    sort(arr,arr+s);

    int ss=0;

    if(s>k)

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

                ss+=arr[i];

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



using namespace std;



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

#define SZ(v)			((int)((v).size()))

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

#define pb			    push_back



typedef long long ll;



int main() {



	ios_base::sync_with_stdio(false);

	cin.tie(nullptr);

	cout.tie(nullptr);



	int n, k;

	cin >> n >> k;

	vector<int> v(n);

	int x;

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

		cin >> x;

		x--;

		v[x]++;

	}

	sort(all(v));

	int ans = 0;

	int len = n - k;

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

		ans += v[i];

	}

	cout << ans;

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

#include<cstdio>

using namespace std;

int main()

{

    long long int n,p,q,r,cur,i,j,k,x,y,z,c1=0,c2=0,c3=0,f=0;

    cin>>n>>k;

    map<long long int,long long int>m;

    vector<long long int>v;

    set<long long int>s;

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

    {

        cin>>x;

        m[x]++;

        s.insert(x);

    }

    for(auto y:s)

    {

        v.push_back(m[y]);

    }

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

    if(v.size()<=k)

    {

        cout<<0<<endl;

    }

    else

    {

        //y=v.size()-k;

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

        {

            c1+=v[i];



        }

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

using namespace std;

#define ll long long

int main()

{

    ll n,i,j,k,l,m,s,c;

    cin>>n>>k;

    map<ll,ll>mp;

    c=0;

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

    {

        cin>>l;

        if(mp[l]==0)

        {

            c++;

        }

        mp[l]++;

    }

    vector<ll>vc;

    map<ll,ll>::iterator it;

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

    {

        vc.push_back(it->second);

    }

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

    s=0;

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

    {

        s+=vc[i];

    }

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

using namespace std;

#define ll long long

bool sorting(const pair<ll,ll >&a,const pair<ll,ll>&b)

{

    return a.second<b.second;

}

int main()

{

    ll n,i,j,k,l,m,s,c;

    map<ll,ll>mp;

    map<ll,ll>::iterator it;

    vector<pair <ll,ll> >vc;

    cin>>n>>k;

    c=0;

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

    {

        cin>>l;

        if(mp[l]==0)

        {

            c++;

        }

        mp[l]++;

    }

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

    {

        vc.push_back( make_pair(it->first,it->second));

    }

    sort(vc.begin(),vc.end(),sorting);

    s=0;

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

    {

        s+=vc[i].second;

    }

    cout<<s<<endl;

    return 0;

}