average :: Int -> [Int] -> Int
average n xs = 
  let v = (sum xs) `mod` n in
    if v == 0
      then (sum xs) `div` n
      else (+) 1 $ (sum xs) `div` n

squre :: Int -> Int
squre x = x * x

solve :: Int -> [Int] -> Int
solve n as =
  let v = average n as in
    foldr (\x acc -> (+) acc $ squre (x - v)) 0 as

main = do
  n <- read <$> getLine :: IO Int
  line <- getLine
  let as = fmap read (words line) :: [Int]
  putStrLn $ show $ solve n as
