
main = interact $ show . sol . map read . words

sol :: [Integer] -> Integer
sol (_:as) = min (calc mean) (calc (mean+1))
    where
    mean = sum as `div` fromIntegral (length as)
    calc t = sum . map ((\x -> x*x) . (t-)) $ as
