let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = List.sort compare @@ Array.to_list @@ Array.init n @@ fun _ -> Scanf.sscanf (read_line ()) "%d" @@ fun a -> a

let rec take res n acc = match (n, acc) with
  | (_, []) | (0, _) -> List.rev res
  | (i, x :: xs) -> take (x :: res) (n - 1) xs
let take = take []

let rec drop n acc = match (n, acc) with
  | (0, acc) -> acc
  | (_, []) -> []
  | (n, x :: xs) -> drop (n - 1) xs

let sum = List.fold_left (+) 0

let solve_1 () = 
  let left, right = take (n / 2) a, drop (n / 2) a in
  let head_r, tail_l = List.hd right, List.hd (List.rev left) in
  (sum right - sum left) * 2 - head_r + tail_l

let solve_2 () = 
  let left, right = take (n / 2) a, drop (n / 2 + 1) a in
  let acc = take 3 (drop (n / 2 - 1) a) in
  match acc with 
  | mid_l :: mid :: mid_r :: [] -> max 
                                     ((sum right - sum left) * 2 - mid + mid_l)
                                     ((sum right - sum left) * 2 - mid_r + mid)
  | _ -> failwith "program error"

let () = Printf.printf "%d\n" @@ (if n mod 2 = 0 then solve_1 else solve_2) ()