main = putStrLn =<< solve <$> parse

parse :: IO [Int]
parse = getLine >> map read . words <$> getLine

solve :: [Int] -> String
solve = show . solve'

solve' :: [Int] -> Int
solve' xs = minimum $ map (rewrite xs) [minX..maxX] where
    minX = minimum xs
    maxX = maximum xs

rewrite :: [Int] -> Int -> Int
rewrite xs y = sum $ map (rewrite' y) xs

rewrite' :: Int -> Int -> Int
rewrite' x y = (x - y) * (x - y)
