local function lltonumber(str) local ret = 0LL for i = 1, #str do ret = ret * 10LL + str:sub(i, i):byte() - 48 end return ret end local function llprint(llnumber) local str = tostring(llnumber):gsub("LL", "") print(str) end local n = io.read("*n", "*l") local flag = true local minlim = 1LL local maxlim = 1000000000000000000LL local offset = 0LL local valid = true local b = {} for i = 1, n do local bs = io.read() b[i] = lltonumber(bs) if i % 2 == 1 then --a[i+1] = b[i] - a[i] flag = not flag offset = b[i] - offset else --a[i+1] = a[i] - b[i] offset = offset - b[i] end if flag then local ma = 1000000000000000000LL - offset if ma < maxlim then maxlim = ma end -- 1 <= offset + x if minlim < 1LL - offset then minlim = 1LL - offset end else local ma = offset - 1LL if ma < maxlim then maxlim = ma end local mi = offset - 1000000000000000000LL if minlim < mi then minlim = mi end end -- print(i, tostring(minlim), tostring(maxlim), tostring(offset), flag) if maxlim < minlim then valid = false end end if valid then print(n + 1) local v = minlim llprint(v) for i = 1, n do if i % 2 == 1 then --a[i+1] = b[i] - a[i] v = b[i] - v else v = v - b[i] end llprint(v) end else print(-1) end