#P7439. [2017年杭电多校]Function
[2017年杭电多校]Function
Function
Problem Description
You are given a permutation from to and a permutation from to . Define that the domain of function is the set of integers from to , and the range of it is the set of integers from to . Please calculate the quantity of different functions satisfying that for each from to . Two functions are different if and only if there exists at least one integer from to mapped into different integers in these two functions. The answer may be too large, so please output it in modulo .
Input
The input contains multiple test cases. For each case: The first line contains two numbers . The second line contains numbers, ranged from to , the -th number of which represents . The third line contains numbers, ranged from to , the -th number of which represents . It is guaranteed that .
Output
For each test case, output " Case #: " in one line (without quotes), where indicates the case number starting from and denotes the answer of corresponding case.
Sample Input
3 2
1 0 2
0 1
3 4
2 0 1
0 2 3 1
Sample Output
Case #1: 4
Case #2: 4
Source
2017 Multi-University Training Contest - Team 1