import Data.List
import Data.Function

main = print . solve . map read . drop 1 . words =<< getContents

solve :: [Int] -> Int
solve as = sum $ map ((^2) . (subtract v)) as
    where v = ceiling $ ((/) `on` fromIntegral) (sum as) (length as)
