ceildiv a b = div (a + b - 1) b

main = do
    n <- readLn :: IO Int
    x <- map read . words <$> getLine :: IO [Int]
    let sum_x = sum x
    let p0 = div sum_x n
    let p1 = ceildiv sum_x n
    let cost0 = sum [(x0 - p0) ^ 2 | x0 <- x]
    let cost1 = sum [(x0 - p1) ^ 2 | x0 <- x]
    print $ min cost0 cost1
