section A B C D E F

state 3 1 1 1 2 1

lenght 10 10 10 10 10 10

I have 6 sections (A-F) that will have a condition from 1-10.
I want to start the calculation from the left and go to the right.
I want to start the calculation when the state is not 1, and end it when it is not 1.
For this example i will have two results. Section A will give the result 40m (A+B+C+D), and section E will give the result 20 m (E+F).
So i can have 1 to 6 results depending on the state condition.
The state condition could be modified, so 1 will become 0, and the rest of thestate numbers transformed to 1.