CumSumInv function

Internal function that calculates the inverted cumsum