atcoder#ABC247F. [ABC247F] Cards
[ABC247F] Cards
Score : points
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.
3
1 2 3
2 1 3
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: .
5
2 3 5 4 1
4 2 1 3 5
12
8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1