import Data.List

main = do
  n <- getLine
  a <- map read . words <$> getLine
  putStrLn . show $ solve 0 $ sort a

solve:: Int -> [Int] -> Int
solve d [] = 0
solve d (a:as) = d + solve (head as - a) as