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

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

solve :: [Int] -> Int
solve as =
  let v = average as in
    sum $ map (\x -> squre (x - v)) as

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