-- Try AtCoder
-- author: Leonardone @ NEETSDKASU
 
 
 
main = print . solve . map read . tail . words=<< getContents

cost a b = (b - a) ^ 2

solve xs = ans where
    min = minimum xs
    max = maximum xs
    g f = sum $ map f xs
    ans = minimum . map g $ map cost [min .. max]
    