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

solve :: Int -> [Int] -> Int
solve n as = sum $ map (\x -> (x - m) ^ 2) as
  where m = round $ (realToFrac $ sum as) / (realToFrac n)