local n = io.read("*n") local cur = 0 local ret = 0 for i = 1, n do local a = io.read("*n") for j = 1, a do cur = cur + 1 ret = ret + math.abs(cur - i) end end print(ret)