main :: IO ()
main = do
  [n] <- getInts
  as <- getInts
  print $ solve as n

getInts = map (read :: String -> Int). words <$> getLine

solve :: [Int] -> Int -> Int
solve as n = sum $ map (\x -> (x - ave) * (x - ave)) as
  where
    ave = (sum as + n - 1) `div` n
