Very mysterious. I do not claim to have fully grasped the logic here.
Despite that, I have generated the numbers with alternative formulae that may be of some interest.
Firstly I converted the data to a table to bring it up to an Excel 2007 level and used that to create formulae that are more readable.
For anyone using the latest versions of Excel 365, I have addressed the OP question using the SCAN Lambda function helper. Accumulation formulae of the type arising here were notoriously difficult using dynamic arrays so the problem has allowed me to check out potential solutions. For anyone not using 365, neither the problem nor its solution are of relevance.