import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  getLine
  solve <$> getl (wrds toInt) >>= print

solve :: [Int] -> Int
solve xs = minimum $ map f [mi..mx]
  where
    f x = sum [(x - i) ^ 2|i <- xs]
    mi = minimum xs
    mx = maximum xs

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine
