import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Foldable
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  n <- getInt
  as <- getIntList

  let cost y = sum $ map (\x -> (x - y)^2) as
      solve y m | y > 100   = m
                | otherwise = solve (y+1) (min (cost y) m)
      inf = 10^9 :: Int

  print $ solve (-100) inf