首页 > 代码库 > HDU 多校1.7

HDU 多校1.7

Function

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
You are given a permutation a技术分享 from 0技术分享 to n1技术分享 and a permutation b技术分享 from 0技术分享 to m1技术分享.

Define that the domain of function f技术分享 is the set of integers from 0技术分享 to n1技术分享, and the range of it is the set of integers from 0技术分享 to m1技术分享.

Please calculate the quantity of different functions f技术分享 satisfying that f(i)=b技术分享f(a技术分享i技术分享)技术分享技术分享 for each i技术分享 from 0技术分享 to n1技术分享.

Two functions are different if and only if there exists at least one integer from 0技术分享 to n1技术分享 mapped into different integers in these two functions.

The answer may be too large, so please output it in modulo 10技术分享9技术分享+7技术分享.
 

 

Input
The input contains multiple test cases.

For each case:

The first line contains two numbers n,技术分享 m技术分享. (1n100000,1m100000)技术分享

The second line contains n技术分享 numbers, ranged from 0技术分享 to n1技术分享, the i技术分享-th number of which represents a技术分享i1技术分享技术分享.

The third line contains m技术分享 numbers, ranged from 0技术分享 to m1技术分享, the i技术分享-th number of which represents b技术分享i1技术分享技术分享.

It is guaranteed that n10技术分享6技术分享,技术分享 m10技术分享6技术分享技术分享.
 

 

Output
For each test case, output "Case #x技术分享: y技术分享" in one line (without quotes), where x技术分享 indicates the case number starting from 1技术分享 and y技术分享 denotes the answer of corresponding case.
 

 

Sample Input
3 21 0 20 13 42 0 10 2 3 1
 

 

Sample Output
Case #1: 4Case #2: 4

HDU 多校1.7