#abc150c. [abc150_c]Count Order
[abc150_c]Count Order
Problem Statement
We have two permutations and of size (that is, and are both rearrangements of ).
There are possible permutations of size . Among them, let and be the -th and -th lexicographically smallest permutations, respectively. Find .
Notes
For two sequences and , is said to be lexicographically smaller than if and only if there exists an integer such that and .
Constraints
- and are permutations of size .
Input
Input is given from Standard Input in the following format:
Output
Print .
Sample Input 1
3
1 3 2
3 1 2
Sample Output 1
3
There are permutations of size : , , , , , and . Among them, and come -nd and -th in lexicographical order, so the answer is .
Sample Input 2
8
7 3 5 4 2 1 6 8
3 8 2 5 4 6 7 1
Sample Output 2
17517
Sample Input 3
3
1 2 3
1 2 3
Sample Output 3
0