import Control.Applicative
import Control.Monad
import Data.List

type I = Int

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

solve :: I -> [I] -> I
solve n as = sum $ map (cost mean) as where
  mean = roundUpOn5 $ fromIntegral (sum as) / fromIntegral n
  cost x y = (x - y)^2

roundUpOn5 :: (RealFrac a, Integral b) => a -> b
roundUpOn5 x
  | n <= -0.5 = m - 1
  | n >= 0.5 = m + 1
  | otherwise = m
  where (m, n) = properFraction x

--  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --

readi :: String -> I
readi = read

toTuple :: [a] -> (a, a)
toTuple [x, y] = (x, y)

toTriple :: [a] -> (a, a, a)
toTriple [x, y, z] = (x, y, z)
