let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = Array.init n @@ fun _ -> Scanf.sscanf (read_line ()) "%d" @@ fun a -> a

module IntMap = Map.Make(struct type t = int let compare = compare end)

let add i map =
  let v = try IntMap.find i map with Not_found -> 0 in
  IntMap.add i (v + 1) map

let remove i map =
  let v = IntMap.find i map in
  if v = 1 then IntMap.remove i map
  else IntMap.add i (v - 1) map

let solve map i =
  let mi, _, _ = IntMap.split i map in
  add i (
    if IntMap.is_empty mi then map
    else remove (fst @@ IntMap.max_binding mi) map
  )

let () = 
  Array.fold_left solve IntMap.empty a
  |> IntMap.bindings
  |> List.map snd
  |> List.fold_left (+) 0
  |> Printf.printf "%d\n"