Problem:
Score : 300 points

Problem Statement

Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.

He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.

Find the minimum number of balls that Takahashi needs to rewrite the integers on them.

Constraints

1 \leq K \leq N \leq 200000

1 \leq A_i \leq N

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of balls that Takahashi needs to rewrite the integers on them.

Sample Input 1

5 2
1 1 2 2 5

Sample Output 1

1

For example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2.
On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.

Sample Input 2

4 4
1 1 2 2

Sample Output 2

0

Already in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.

Sample Input 3

10 3
5 1 3 2 4 1 1 2 3 4

Sample Output 3

3

Solution in C (GCC 5.4.1) (judge verdict: Accepted)

#include<stdio.h>
#include<math.h>

void QSort(long long x[ ], long long left, long long right);
void Swap(long long x[ ], long long i, long long j);

int main(){
  long long n,k;
  scanf("%lld%lld",&n,&k);
  
  long long a[n];
  long long b[n];

  for(int i=0;i<n;i++){
    b[i]=0;
  }
  
  
  for(int i=0;i<n;i++){ 
    scanf("%lld",&a[i]);
    b[a[i]-1]++;
  }
  QSort(b,0,n-1);

  long long hiku=0;
  for(long long i=0;i<k;i++){
    hiku=hiku+b[i];
  }

  printf("%lld\n",n-hiku);
  
  
  return 0;
}

  /* クイックソートを行う */
void QSort(long long x[ ], long long left, long long right)
{
    int i, j;
    long long pivot;
 
    i = left;                      /* ソートする配列の一番小さい要素の添字 */
    j = right;                     /* ソートする配列の一番大きい要素の添字 */
 
    pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */
 
    while (1) {                    /* 無限ループ */
 
        while (x[i] > pivot)       /* pivot より大きい値が */
            i++;                   /* 出るまで i を増加させる */
 
        while (pivot > x[j])       /* pivot より小さい値が */
            j--;                   /*  出るまで j を減少させる */
        if (i >= j)                /* i >= j なら */
            break;                 /* 無限ループから抜ける */
 
        Swap(x, i, j);             /* x[i] と x[j]を交換 */
        i++;                       /* 次のデータ */
        j--;
    }
   
 
    if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
        QSort(x, left, i - 1);     /* 左の配列を Q ソートする */
    if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
        QSort(x, j + 1, right);    /* 右の配列を Q ソートする */
}
 
  /* 配列の要素を交換する */
void Swap(long long x[ ], long long i, long long j)
{
    long long temp;
 
    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}