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 Rust (1.15.1) (judge verdict: Wrong Answer)

use std::io;
use std::collections::HashMap;
use std::collections::BinaryHeap;
use std::mem;
use std::cmp;

fn read_line() -> String{
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_ints() -> Vec<i64>{
    let s = read_line();
    let split:Vec<&str> = s.split(" ").collect();
    split.iter().map(|&x| x.to_string().parse().unwrap()).collect()
}


fn main(){
    let arr = read_ints();
    let (n,k) = (arr[0] as i32,arr[1] as i32);
    let mut cnt : Vec<i32> = vec![0;200005];
    let mut heap = BinaryHeap::new();
    let mut n_color = 0 as i32;
    
    let arr = read_ints();
    for idx in arr.iter(){
        cnt[*idx as usize] += 1;
    }
    
    for i in 0..200005{
        if cnt[i]>0 {
            heap.push(cnt[i]);
            n_color+=1;
        }
    }
    
    let mut vs : Vec<i32>= heap.into_vec();
    vs.reverse();
    
    let mut ans = 0;
    
    for v in vs.iter(){
        if n_color > k{
            ans += *v;
            n_color -= 1;
        }
    }
    println!("{}",ans);
}

/*
struct Uf{
    n_size: usize,
    par   : Vec<i32>,
    rank  : Vec<i32>,
}

impl Uf{
    fn new(n_size:usize) -> Uf{
        Circle{
            n_size:n_size,
            par  :(0..n_size).collect(),
            rank :vec![0;n_size]
        }
    }
    
    fn find(&self, x: i64)->i64{
        let h = self.hash(x);
        
        if( par[h] == x ){
            x
        }else{
            par[h] = self.find(x);
            
        }
    }
}

*/



/*
DOCS


let mut h = HashMap::new();
let a = 5;
h.insert(a,true);
match h.get(&a){
    Some(v) => println!("{}",v),
    None    => println!("none"),
}


use std::mem;

let mut x = 5;
let mut y = 1;
mem::swap(&mut x,&mut y);


let v = vec![0;2]; // [0,0]

s.chars().nth(i as usize).unwrap();





*/