let () =
  Scanf.scanf "%d\n" @@ fun n -> 
  Array.init n (fun _ -> Scanf.scanf "%d " (fun x -> x))
  |> Array.to_list
  |> List.sort Pervasives.compare
  |> List.rev
  |> List.fold_left (fun (x, k) y -> (x + k * y, -k)) (0, 1)
  |> fst
  |> Printf.printf "%d\n"