Scanf.scanf "%d %d" (fun n k ->
    let module M = Map.Make (struct type t = int let compare = compare end) in
    let rec loop i map =
        if i = 0 then map else
            let map = Scanf.scanf " %d" (fun a -> 
                M.add a (1 + try M.find a map with _ -> 0) map)
            in
            loop (i - 1) map
    in
    let map = loop n M.empty in
    let arr = Array.of_list (M.bindings map) in
    Array.sort (fun (_, a) (_, b) -> compare b a) arr;
    let rec loop i sum =
        if i >= Array.length arr then sum else
            let (_, a) = arr.(i) in
            loop (i + 1) (sum + a)
    in
    loop k 0 |> Printf.printf "%d\n"
)