#P5952. [POI 2018] 水箱
[POI 2018] 水箱
Problem Description
There is a water tank on the ground. Its top view is divided into a grid of rows and columns. Between every pair of adjacent cells there is a wall whose thickness can be ignored. Between the tank and the outside world there is a wall of infinite height, so water cannot leak out.
It is known that the water level in each cell can only be an integer in . Please count how many possible water level configurations there are.
Since the answer may be very large, output it modulo .
We say two configurations are different if and only if there exists at least one cell whose water level is different in the two configurations.
Input Format
The first line contains three positive integers .
The next lines each contain integers , representing the height of the wall between and .
The next lines each contain integers , representing the height of the wall between and .
Output Format
Output one line with one integer, the number of configurations modulo .
3 2 2
1
1
1
1 2
1 1
65
Hint
For of the testdata, , .
Sample Explanation
Either the water level in all cells is , or the water level in all cells is in . In total, there are configurations.
Translated by ChatGPT 5