import Control.Applicative

main = do
    n <- read <$> getLine
    as <- (map read . words) <$> getLine
    putStrLn  $ show $ solve n as

solve :: Int -> [Int] -> Int
solve n as = 
    let sas = fromIntegral $ sum as
        fn = fromIntegral n
        mean = round $ sas / fn
    in sum $ map ((^2) . (mean-)) as