
open Scanf
open Printf

let read_int () = scanf " %d" (fun x -> x)

let rec read_ints n =
  if n = 0
  then []
  else scanf " %d" (fun x -> x) :: read_ints (n-1)

let () =
  let n = read_int () in
  let xs = List.sort (fun a b -> b - a) (read_ints n) in
  let _, ans = List.fold_left (fun (m, s) v -> (-m, s + v * m)) (1, 0) xs in
  printf "%d\n" ans
