import Data.List

main :: IO
main = do
  getLine
  as <- map read . words <$> getLine
  print $ solve as 

solve :: [Int] -> Int
solve = solve' 0 0 . sortBy (flip compare)

solve' :: Int -> Int -> [Int] -> Int
solve' x y [] = x - y
solve' x y [a] = x + a - y
solve' x y (a:b:as) = solve' (x + a) (y + b) as
