values. Consider all of its non-empty subsequences: collections obtained by crossing out any elements (possibly none) while keeping the rest in order. Selections taken from different positions count separately, even if their values match.
Return the sum of the spreads of all these selections modulo 10⁹ + 7.values=[5, 1, 4] → 12
Single-element selections have spread 0. Pairs: {5, 1} → 4, {5, 4} → 1, {1, 4} → 3. The whole array: 5 − 1 = 4. Total: 4 + 1 + 3 + 4 = 12.
values=[7, 7] → 0
Every selection has equal maximum and minimum, so the answer is 0.
values=[3] → 0
values=[5, 1, 4]
12
Run checks the first 3 tests in your browser. Submit checks all 87 tests on the server, hidden ones included.