import Data.List

main :: IO()
main = do
    getLine
    ls <- map read . words <$> getLine
    print $ nijouhou ls

nijouhou :: [Int] -> Int
nijouhou ls = 
    let sortLs = sort ls
        minNum = head sortLs
        maxNum = last sortLs
    in minimum [ sum [(x - n)^2 | x <- sortLs] | n <- [minNum .. maxNum]]
