weights. You choose a non-empty set of items (any positions of the array, each at most once). A pick is handy if the weight of its lightest item plus the weight of its heaviest item does not exceed limit. In a pick of one item, that item is both the lightest and the heaviest.
Count the handy picks. Two picks that differ in at least one position are different, even if their weights look the same.
The answer can be huge, so return it modulo 10⁹ + 7.weights=[2, 4, 7], limit=8 → 3
The picks [2], [4], [2, 4] and [2, 7] work: in each, the lightest plus the heaviest is at most 8. But [4, 7], [7] and [2, 4, 7] do not.
weights=[5, 5], limit=10 → 3
Each 5 on its own and both together: 5 + 5 = 10. Equal weights at different positions count as different picks.
weights=[9, 6], limit=5 → 0
Even a single item of weight 6 gives 6 + 6 = 12 > 5, so no pick works.
weights=[2, 4, 7], limit=8
3
Run checks the first 3 tests in your browser. Submit checks all 84 tests on the server, hidden ones included.