import qualified Data.ByteString.Char8 as C
import Data.List

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    _ <- getLine
    xs <- r'
    let opt = ceiling ((fromIntegral $ sum xs) / (fromIntegral $ length xs))
    print $ sum $ map ((^2).(opt-)) xs