For a given permutation $$$P$$$ of $$$1,2,\dots,n$$$, denote $$$inv(P)$$$ the number of inversions of the array $$$P_1,P_2,\dots, P_n$$$. For two permutations $$$A$$$ $$$B$$$ of $$$1,2,\dots,n$$$, define $$$ A(B)$$$ the permutation $$$A_{B_1}, A_{B_2},\dots,A_{B_n}$$$. Denote the inverse of permutation $$$P$$$ as $$$P^{-1}$$$, the only permutation such that $$$P(P^{-1})$$$ is the permutation $$$1,2,\dots,n$$$.
You are given two permutations $$$A,B$$$ of $$$1,2,\dots,n$$$. You have to choose a permutation $$$P$$$ of $$$1,2,\dots,n$$$ such that $$$inv(A(P^{-1}))+inv(P(B^{-1}))$$$ is minimized. How many such permutations exist?
The first line contains an integer $$$n$$$ $$$(1 \leq n \leq 20)$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$ $$$(1 \leq a_i \leq n)$$$. The third line contains $$$n$$$ integers $$$b_1,b_2,\dots,b_n$$$ $$$(1 \leq b_i \leq n)$$$.
A single integer containing the number of permutations $$$P$$$.
43 1 2 42 1 4 3
3
63 2 6 1 5 41 2 5 6 4 3
12
111
1
| Name |
|---|


