stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;



}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
/**

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

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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; 

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//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;

	

}




// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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; 

}

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

#include<algorithm>

using namespace std;

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

int main()

{

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

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

   {scanf("%d",&t);

   srx[t]++;}

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

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

   sry+=srx[i];

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

   return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<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;

}

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

#include<algorithm>

using namespace std;

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

int main()

{

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

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

   {scanf("%d",&t);

   srx[t]++;}

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

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

   sry+=srx[i];

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

   return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <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);

}

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

#include<algorithm>

using namespace std;

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

int main()

{

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

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

   {scanf("%d",&t);

   srx[t]++;}

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

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

   sry+=srx[i];

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

   return 0;

}

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

using namespace std;

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

}

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

#include<algorithm>

using namespace std;

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

int main()

{

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

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

   {scanf("%d",&t);

   srx[t]++;}

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

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

   sry+=srx[i];

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

   return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

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

#include<algorithm>

using namespace std;

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

int main()

{

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

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

   {scanf("%d",&t);

   srx[t]++;}

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

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

   sry+=srx[i];

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

   return 0;

}

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

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

}


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

#include<algorithm>

using namespace std;

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

int main()

{

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

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

   {scanf("%d",&t);

   srx[t]++;}

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

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

   sry+=srx[i];

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

   return 0;

}

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

using namespace std;

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

}

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

#include<algorithm>

using namespace std;

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

int main()

{

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

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

   {scanf("%d",&t);

   srx[t]++;}

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

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

   sry+=srx[i];

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

   return 0;

}

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

using namespace std;

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

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem: