values. Call a subsequence (elements taken in their original order, not necessarily adjacent) **smooth** if every two neighbouring elements in it differ by exactly 1, up or down; the direction may change along the way. A one-element subsequence is always smooth.
Subsequences taken from different positions count separately, even if they hold the same numbers.
Return the sum of the elements of all smooth subsequences, modulo 10⁹ + 7.values=[2, 3, 2] → 24
The valid picks are [2], [3], [2], [2, 3], [3, 2] and [2, 3, 2]. Their sums: 2 + 3 + 2 + 5 + 5 + 7 = 24.
values=[4, 6, 5] → 35
The valid picks are [4], [6], [5], [4, 5] and [6, 5]; [4, 6] does not count because the step is 2. The total is 15 + 9 + 11 = 35.
values=[0, 0, 1] → 3
values=[2, 3, 2]
24
Run checks the first 3 tests in your browser. Submit checks all 124 tests on the server, hidden ones included.