nearest :: [Int] -> Int
nearest xs = minimum [ sum [ (x - a) ^ 2 | x <- xs ]
                     | a <- [-100 .. 100]
                     ]

main :: IO ()
main = do
  getLine
  as <- mapM readIO . words =<< getLine
  print $ nearest as
