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

solve' n as = minimum $ fmap (\v -> solve n as v) [ -100 .. 100 ]

solve :: Int -> [Int] -> Int -> Int
solve n as v = 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
