local n = io.read("*n") local tot = 0 local a = {} for i = 1, n do local tmp = io.read("*n") tot, a[i] = tot + tmp, tmp end local minmvcnt = 10000 for i = 1, 100 do if(tot < i * i) then break end local mvcnt = 0 -- check only MINUS count for j = 1, n do local tgt = 0 if(j <= i) then tgt = j elseif(j < 2 * i) then tgt = 2 * i - j end mvcnt = mvcnt + math.max(0, a[j] - tgt) end minmvcnt = math.min(minmvcnt, mvcnt) end print(minmvcnt)