Both ROW and OFFSET are volatile functions. This formula uses neither, and you only need to declare the variables "a" and "b".
=LET( a, A1:A30, b, B1:B30, SCAN(0, SEQUENCE(ROWS(a)), LAMBDA(acc,v, IF(INDEX(b,v), INDEX(a,v) + acc, 0))) )