import Data.List
import Data.Array
import Data.Maybe
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
 
getInts :: IO [Int]
getInts = (map parseInt . BS8.words) <$> BS.getLine 
    where parseInt = fst . fromJust . BS8.readInt
 
solve :: [Int] -> Int
solve arr = minimum $ map f [minimum arr .. maximum arr]
    where f k = sum $ map (\x -> (x-k) * (x-k)) arr

main :: IO ()
main = do
    [n] <- getInts
    arr <- getInts
    print (solve arr)