=LET(
note, "the core elements of this method were taken from Peter Bartholomew's custom FIFO functions",
FIFO, LAMBDA(inAmt,outAmt,
LET(
inRows, ROWS(inAmt) + 1,
outRows, ROWS(outAmt) + 1,
inRecords, HSTACK(EXPAND(SEQUENCE(inRows),, 2, ""), VSTACK(0, SCAN(0, inAmt, LAMBDA(a,v, a + v)))),
outRecords, CHOOSECOLS(HSTACK(EXPAND(SEQUENCE(outRows),, 2, ""), VSTACK(0, SCAN(0, outAmt, LAMBDA(a,v, a + v)))), 2, 1, 3),
unionAll, SORT(VSTACK(inRecords, outRecords), 3),
inId, SCAN(1, CHOOSECOLS(unionAll, 1), LAMBDA(a,v, IF(v = "", a, v))),
outId, SCAN(1, CHOOSECOLS(unionAll, 2), LAMBDA(a,v, IF(v = "", a, v))),
amt, CHOOSECOLS(unionAll, 3),
netAmt, VSTACK(DROP(amt, 1), TAKE(amt, -1)) - amt,
FILTER(HSTACK(outId, netAmt), netAmt <> 0)
)
),
rng, A2:A100,
arr, FIFO(rng, EXPAND(50, QUOTIENT(SUM(rng), 50),, 50)),
one, CHOOSECOLS(arr, 1),
add, one = VSTACK("", DROP(one, -1)),
HSTACK(arr, SCAN(0, SEQUENCE(ROWS(arr)), LAMBDA(a,v, INDEX(arr, v, 2) + INDEX(add, v) * a)))
)