let n = read_int();; let a = read_line() |> String.split_on_char ' ' |> List.map int_of_string |> List.sort compare |> Array.of_list;; let inf = 1000000000;; let dp = Array.make (n+1) inf;; dp.(0) <- 0;; for i = 0 to n do if i + 2 <= n then dp.(i+2) <- min dp.(i+2) (dp.(i) + a.(i+1) - a.(i)); if i + 3 <= n then dp.(i+3) <- min dp.(i+3) (dp.(i) + a.(i+2) - a.(i)); done;; print_int dp.(n);; print_newline ();;