#abc247f. [abc247_f]Cards
[abc247_f]Cards
Problem Statement
There are cards numbered . Card has written on the front and written on the back.
Here, and are permutations of .
How many ways are there to choose some of the cards such that the following condition is satisfied? Find the count modulo .
Condition: every number is written on at least one of the chosen cards.
Constraints
- and are permutations of .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
1 2 3
2 1 3
Sample Output 1
3
For example, if you choose Cards and , then is written on the front of Card , on the back of Card , and on the front of Card , so this combination satisfies the condition.
There are ways to choose cards satisfying the condition: .
Sample Input 2
5
2 3 5 4 1
4 2 1 3 5
Sample Output 2
12
Sample Input 3
8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
Sample Output 3
1