import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    as <- getIntList
    let m = (sum as) `div` n
    print $ max (sum (map (\a -> (a - m)^2) as)) (sum (map (\a -> (a - m - 1)^2) as))