let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ =
    Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  List.sort compare as_
  |> (fun (a :: as_) -> List.fold_left (fun (a, s) a' -> (a', a' - a + s)) (a, 0) as_)
  |> snd
  |> Printf.printf "%d\n"