skill[i] is the skill of the i-th one. A crew is one or more workers standing next to each other.
The power of a crew is the product of two numbers: the skill of its weakest member and the total skill of all its members.
Return the sum of the powers of all possible crews modulo 10⁹ + 7.skill=[2, 4, 1] → 45
Crews: [2] → 2·2 = 4, [4] → 4·4 = 16, [1] → 1·1 = 1, [2, 4] → 2·6 = 12, [4, 1] → 1·5 = 5, [2, 4, 1] → 1·7 = 7. The sum is 45.
skill=[3, 3] → 36
[3] → 9 twice and [3, 3] → 3·6 = 18, for 36 in total.
skill=[10] → 100
skill=[2, 4, 1]
45
Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.