import Data.List
import Data.Ord
 
split :: [Int] -> [(Int, Int)]
split [] = [(0, 0)]
split [x] = [(x, 0)]
split (x:y:xys) = (x, y) : split xys
 
main :: IO ()
main = do
    n <- readLn :: IO Int
    cards <- (map read) . words <$> getLine :: IO [Int]
    let phases = split $ sortBy (comparing Down) cards
    let folded = foldl (\(f1, s1) (f2, s2) -> (f1+f2, s1+s2)) (0, 0) phases
    print $ fst folded - snd folded