import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import Control.Monad
import Data.Char
import Data.List

solve :: VU.Vector Int -> Int -> Int
solve xs n = minimum $ map (\i -> VU.sum $ VU.map (\x -> (i-x)^2) xs :: Int) [-100..100]

main = do
    n <- readLn :: IO Int
    as <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    print $ solve as n