#P1373. 小 a 和 uim 之大逃离
小 a 和 uim 之大逃离
Description
In a flash, a gigantic matrix appeared on the ground, and each cell of the matrix held an amount of magic fluid between .
The monster gave Xiao a and uim a magic bottle each, and said: You may start from any cell of the matrix, move one step to the right or down each time, and end at any cell. At the start, Xiao a uses his bottle to absorb the magic fluid on the ground; on the next step, uim absorbs; and so on, alternating. Moreover, the last absorption must be performed by uim. Each magic bottle has capacity , meaning the amount in a bottle is always taken modulo : if it reaches it resets to , if it reaches it becomes , and so on.
The monster also said that whoever has more magic fluid in their bottle at the end will survive. Xiao a and uim are very close, like brothers. How could he bear to let his partner perish? After a brief silence, Xiao a had a brainwave: if the amounts in their bottles are the same, both can survive. Xiao a and his partner burst into laughter.
Now he wants to know in how many ways both of them can survive.
Input Format
The first line contains three integers separated by spaces.
The next lines each contain integers, representing the amount of magic fluid in each cell of the matrix. Numbers in the same row are separated by spaces.
Output Format
Output a single integer: the number of ways. Since the answer may be large, output it modulo .
2 2 3
1 1
1 1
4
Hint
[Problem Source]
Adapted by lzn.
[Sample Explanation]
Sample explanation: The four valid schemes are: , , , .
[Constraints]
For of the testdata, , . For of the testdata, , . For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号