--[[
sig{(x_i - c)^2}
= sig{x_i^2} -2c * sig{x_i} + nc^2
c = sig{x_i} / n
]]
local n = io.read("*n")
local sum = 0
local sumsq = 0
for i = 1, n do
  local a = io.read("*n")
  sum = sum + a
  sumsq = sumsq + a * a
end
local cmin, cmax = math.floor(sum / n), math.ceil(sum / n)
print(math.min(sumsq - 2 * cmin * sum + n * cmin * cmin, sumsq - 2 * cmax * sum + n * cmax * cmax))
