#P10893. 城市化发展委员会
城市化发展委员会
Background
The Great Emperor MLE once said:

So, to deal with this situation, we established the Urbanization Development Committee.
Problem Description
On a high school campus, we often see randomly appearing young couples. Their feelings are still too deep for OIers. Even the retired AzureHair cannot understand this behavior. However, as a standing member of the self-proclaimed Urbanization Development Committee, he has his own way to interpret it.
He believes that girls are often very strict with boys. At the start of each day, the boy’s score in the girl’s mind increases by . If he makes her angry times that day, the score decreases by on top of that. The score keeps accumulating, and once it becomes , it may lead to the serious consequence of de-urbanization.
Now William is doing a kind of urbanization behavior with Chtholly. With the help of Nahida, William gains superpowers: first, he can foresee the score changes for the next cycle, whose initial length is ; second, he can choose to start from any day, and the days before that will be appended after the last day.
After trying starting from every day once, he finds starting days that can keep him from being de-urbanized. Then he concatenates the sequences of these cases in the order of their starting days, forming a new cycle whose length is times the original. He repeats this operation times. Since trying day by day is too tiring, William only wants to know, after the last operation, how many starting days can keep him from being de-urbanized, modulo .
Formally, we call a sequence “safe” if all its prefix sums are always greater than .
For a sequence of length , construct a sequence using the following algorithm. Initially, is empty.
- Repeat times:
-
If is safe, append the entire to the end of .
-
Cyclically left shift by one position, i.e. set .
Now given , with every element not greater than 1.
Starting from , generate sequences to according to the rules above. Please find the length ratio of to . If this value exists, it must be an integer. Output its value modulo . In particular, if is empty, output 0.
Input Format
Plain statement:
There are two lines. The first line contains two integers and , representing the initial cycle length and the number of operations.
The second line contains integers not greater than , representing the daily score changes.
Formal statement:
There are two lines. The first line contains two integers: the length of and .
The second line is .
Output Format
One line with one integer, representing the answer modulo .
8 0
1 1 -2 1 1 -1 0 1
2
6 0
1 1 -4 -5 1 -4
0
Hint
[Sample Explanation 1]
For sample #1, the initial cycle is 1 1 -2 1 1 -1 0 1. The sequences obtained by starting from each day are:
1 1 -2 1 1 -1 0 1
1 -2 1 1 -1 0 1 1
-2 1 1 -1 0 1 1 1
1 1 -1 0 1 1 1 -2
1 -1 0 1 1 1 -2 1
-1 0 1 1 1 -2 1 1
0 1 1 1 -2 1 1 -1
1 1 1 -2 1 1 -1 0
Only the sequences starting from day 4 and day 8 satisfy the condition.
Formal statement:
, with length 16, so the output should be 2.
[Sample Explanation 2]
It can be proven that no valid solution exists.
Hey! Isn’t it too much that all samples have ?!
Constraints:
For of the testdata, , .
For another of the testdata, .
For of the testdata, , , .
Translated by ChatGPT 5