import           Control.Monad

main :: IO ()
main = do
  n <- getLine
  a <- map read . words <$> getLine
  let (q, r) = (maximum a + minimum a) `divMod` 2
  print $ sum [ (x - (q + r)) ^ 2 | x <- a ]
