#P8096. [USACO22JAN] Drought G
[USACO22JAN] Drought G
Problem Description
All the grass in Farmer John’s pasture has dried up in a severe drought. After hours of despair and thinking, FJ comes up with a brilliant idea: buy corn to feed his precious cows.
FJ’s cows () are standing in a line. The hunger level of the -th cow in the line is a non-negative integer . Since FJ’s cows are social animals, they insist on eating together. The only way for FJ to decrease the cows’ hunger levels is to choose two adjacent cows and and feed each of them one bag of corn, which decreases both of their hunger levels by 1.
FJ wants to feed his cows until all cows have the same non-negative hunger level. Although he does not know the exact hunger levels of his cows, he knows an upper bound for each cow; specifically, the hunger level of the -th cow is at most ().
Your task is to compute the number of -tuples that satisfy the above upper bounds and for which it is possible for FJ to achieve his goal. Output the answer modulo .
Input Format
The first line of input contains .
The second line contains .
Output Format
Output the number of valid -tuples of hunger levels, modulo .
3
9 11 7
241
4
6 8 5 9
137
Hint
[Sample Explanation]
There are different 3-tuples that are consistent with .
is one such tuple. In this case, it is possible to make all cows have the same hunger level: feed cows and two bags of corn each, then feed cows and five bags of corn each, and all cows will end up with hunger level .
is another tuple. In this case, it is not possible to make the cows’ hunger levels equal.
[Constraints]
-
In test points with even indices, is even. In test points with odd indices, is odd.
-
Test points 3-4 satisfy and .
-
Test points 5-10 satisfy and .
-
Test points 11-20 have no additional constraints.
Translated by ChatGPT 5