import Data.List
import Data.List.Split
main = mapM_ (print . solve) . chunksOf 2 . map (map read . words) . lines =<< getContents
solve [n,as] = minimum $ map (\v->sum . map (\a->(a-v)^2) $ as) [minimum as..maximum as]