check :: Integer -> Integer -> [Integer] -> Integer check acm v xs | null xs = acm | otherwise = check (acm + (abs ((head xs) - v))) v (tail xs) main :: IO () main = do n <- readLn xs <- fmap (map read . words) getLine :: IO [Integer] let avg = (sum xs) `div` n print $ min (min (check 0 (avg - 1) xs) (check 0 avg xs)) (check 0 (avg + 1) xs)