#USACOC2222A. Drought
Drought
Description
The grass has dried up in Farmer John's pasture due to a drought. After hours ofdespair and contemplation, FJ comes up with the brilliant idea of purchasingcorn to feed his precious cows.
FJ’s cows are arranged in a line such that the thcow in line has a non-negative integer hunger level of . As FJ’s cows aresocial animals and insist on eating together, the only way FJ can decrease thehunger levels of his cows is to select two adjacent cows and and feedeach of them a bag of corn, causing each of their hunger levels to decrease byone.
FJ wants to feed his cows until all of them have the same non-negative hungerlevel. Although he doesn't know his cows' exact hunger levels, hedoes know an upper bound on the hunger level of each cow; specifically, thehunger level of the -th cow is at most .
Your job is to count the number of -tuples of hunger levels that are consistent with these upper bounds such that itis possible for FJ to achieve his goal, modulo .
Input Format
The first line contains .
The second line contains .
Output Format
The number of -tuples of hunger levels modulo .
3
9 11 7
3
9 11 7
There are -tuples that are consistent with.
One of these tuples is . In this case, it is possible to make allcows have equal hunger values: give two bags of corn to both cows and ,then give five bags of corn to both cows and , resulting in each cowhaving a hunger level of .
Another one of these tuples is . In this case, it is impossible to make the hunger levels of the cows equal.
4
6 8 5 9
4
6 8 5 9
Scoring
is even in even-numbered tests and odd in odd-numbered tests.
- Tests 3 and 4 satisfy and .
- Tests 5 through 10satisfy and .
- Tests 11 through 20 satisfy nofurther constraints.
Problem Credit
Problem credits: Arpan Banerjee and Benjamin Qi