#JSUTCPC2026A. Blast Master —— 爆破大师
Blast Master —— 爆破大师
Problem Description
Timothy is the on-site commander of a demolition company. Currently, there is a row of aging large oil tanks that are moving closer together, each containing a different amount of waste oil (a positive integer ).
Since the oil tanks were adjacent, Timothy decided to adopt a "spark ignition chain" approach to save on demolition costs:
- Choose two adjacent oil tanks and .
- Extract liter of waste oil from as fuel, and use the heat generated by the blowtorch to directly vaporize and burn all the waste oil in the adjacent tank .
- After tank is emptied, the construction team will quickly hoist it away. At this time, the tanks originally located on both sides of will automatically move closer and become adjacent.
- If is also fully utilized at this point, the construction team will promptly remove it. At this time, the oil tanks originally located on both sides of will automatically move closer together, becoming adjacent.
If all the oil tanks in this row can be emptied (removed) through this method, we call this sequence of oil tanks "completely removable".
There are numbered oil tank positions on site, and the oil volume of some oil tanks is known. Positions marked with indicate that the oil tank label is damaged, but it is known that their maximum capacity is liters (i.e., the oil volume is between and ). Now, please calculate: among all the possible capacities filled in the positions where the labels are damaged, how many different combinations of oil volumes can make the construction team successfully empty the row of oil tanks?
Input
The first line contains two integers and satisfying (, ).
The second line contains integers satisfying ( or ).
Output
Output an integer representing the total number of fuel combinations that can be successfully emptied, modulo .
Samples
2 2
-1 -1
3
6 10
-1 -1 -1 -1 1 7
9125
Note
In the first set of test cases, the array . After replacing the two unknown oil tanks with , one possible outcome is . At this point, we select two adjacent oil tanks: subtract from the first tank's oil volume and burn the second tank, resulting in . After removing all empty oil tanks, the clearance is successfully completed, so is a possible scenario.
Similarly, if the unknown oil tank is replaced with either or , both of these two oil tanks can be emptied. Therefore, there are a total of different possible scenarios.