import Data.List

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

cost :: [Int] -> Int
cost xs = sum [(x-y)^2 | x <- xs]
  where
    y   = round $ mean xs'
    xs' = map fromIntegral xs

mean :: Fractional a => [a] -> a
mean xs = sum xs / genericLength xs