let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  Array.to_list as_
  |> List.sort (fun i j -> compare j i)
  |> List.mapi (fun i a -> (i, a))
  |> List.partition (fun (i, _) -> i mod 2 = 0)
  |> (fun (as_, bs) -> [as_; bs])
  |> List.map (List.map snd)
  |> List.map (List.fold_left ( + ) 0)
  |> (fun [a; b] -> a - b)
  |> Printf.printf "%d\n"