import Control.Applicative

main :: IO()
main = do
	getLine
	a <- map (read::String->Int) . words <$> getLine
	let min' = minimum a
	let max' = maximum a
	print $ minimum [sum (map (\x->(x-i)^2) a) | i<-[min'..max']]