let split_on_char sep s = let r = ref [] in let j = ref (String.length s) in for i = String.length s - 1 downto 0 do if String.unsafe_get s i = sep then begin r := String.sub s (i + 1) (!j - i - 1) :: !r; j := i end done; String.sub s 0 !j :: !r;; let pow x y = let rec inner_pow i result = match i with | 0 -> result | _ -> inner_pow (i - 1) (result * x) in inner_pow y 1;; let rec shop_tumeru cost k hairu lst = match lst with | [] -> cost | _ -> let max_k = pow 2 k in if (hairu >= max_k) then shop_tumeru cost (k + 1) 0 lst else let next_shop = List.hd lst in let lst = List.tl lst in let cost = cost + (next_shop * k) in let hairu = hairu + 1 in shop_tumeru cost k hairu lst;; let () = read_line () |> ignore; let lst = read_line () |> split_on_char ' ' |> List.map int_of_string |> List.fast_sort (fun x y -> - ( compare x y)) in shop_tumeru 0 0 0 lst |> print_int; print_newline ();;