100 atcoder#ABC150C. [ABC150C] Count Order
[ABC150C] Count Order
Score : points
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 .
3
1 3 2
3 1 2
3
There are permutations of size : , , , , , and . Among them, and come -nd and -th in lexicographical order, so the answer is .
8
7 3 5 4 2 1 6 8
3 8 2 5 4 6 7 1
17517
3
1 2 3
1 2 3
0