local n=io.read("n")
local a={}
for i=1,n do
    a[i]=io.read("n")
end

local mincost=1000000000000000
for i=-100,100 do
    local cost=0
    for j=1,n do
        cost=cost+(a[j]-i)*(a[j]-i)
    end
    mincost=math.min(cost,mincost)
end
print(mincost)