totals of length n. Split every element into two non-negative integer parts: totals[i] = up[i] + down[i].
A split is valid when up never decreases (up[0] ≤ up[1] ≤ … ≤ up[n-1]) and down never increases (down[0] ≥ down[1] ≥ … ≥ down[n-1]).
How many valid splits are there? Two splits are different if their up arrays differ. The count can be huge, so return it modulo 10⁹ + 7.totals=[3, 1] → 3
Three splits work: up=[0, 0], down=[3, 1]; up=[0, 1], down=[3, 0]; up=[1, 1], down=[2, 0].
totals=[4, 4, 4] → 35
Here up can be any non-decreasing triple of numbers from 0 to 4, and down then comes out non-increasing on its own. There are 35 such triples.
totals=[1, 5, 1] → 0
The jump from 1 to 5 forces up to grow by at least 4, yet its last element can be at most 1. No split exists.
totals=[3, 1]
3
Run checks the first 3 tests in your browser. Submit checks all 79 tests on the server, hidden ones included.