import qualified Data.ByteString.Char8 as B
import           Data.Maybe            (fromJust)

readInts :: B.ByteString -> [Int]
readInts = map (fst . fromJust . B.readInt) . B.words

getInts :: IO [Int]
getInts = readInts <$> B.getLine

main :: IO ()
main = do
  n <- readLn
  xs <- getInts
  print $ solve n xs

solve :: Int -> [Int] -> Int
solve n xs = min (calcHP aveF xs) (calcHP aveC xs) where
  aveF = floor ave
  aveC = ceiling ave
  ave = fromIntegral (sum xs) / fromIntegral n :: Double

calcHP :: Int -> [Int] -> Int
calcHP p xs = sum [(x - p) ^ (2 :: Int) | x <- xs]
