#P7463. [2017年杭电多校]RXD and numbers
[2017年杭电多校]RXD and numbers
RXD and numbers
Problem Description
RXD has a sequence , which possesses the following properties:
- for all , there is at least one position where .
- for all , the number of which satisfies is . One day, naughty boy DXR clear the sequence. RXD wants to know, how many valid sequences are there. Output the answer module .
Input
There are several test cases, please keep reading until EOF. There are about 10 test cases, but only 1 of them satisfies For each test case, the first line consists of 1 integer , which means the range of the numbers in sequence. For the next lines, in the -th line, it consists of integers, the -th integer means . We can easily conclude that .
Output
For each test case, output "Case #x: y", which means the test case number and the answer.
Sample Input
2
1 2
2 1
4
1 0 0 2
0 3 0 1
2 1 0 0
0 0 3 1
4
0 1 0 0
1 0 0 0
0 0 0 1
0 0 1 0
Sample Output
Case #1: 6
Case #2: 18
Case #3: 0
Source
2017 Multi-University Training Contest - Team 3