let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = read_line () |> split_string ~pattern:" " |> List.map int_of_string |> List.sort compare |> List.rev

let rec loop sum acc = function
  | 0 -> sum
  | 1 -> sum + (List.hd acc)
  | i -> loop (sum + (List.hd acc) * 2) (List.tl acc) (i - 2)

let () = Printf.printf "%d\n" @@ loop (List.hd a) (List.tl a) (n - 2)