You are given two sequences \(A\) and \(B\) of length \(N\). Determine the number of different ways to permute the sequence \(A\) such that it is lexicographically smaller than the sequence \(B\).
A sequence \((X_1, X_2, \dots, X_K)\) is strictly lexicographically smaller than a sequence \((Y_1,Y_2, \dots, Y_K)\), if there exists an index \(t\) \((1 \le t \le K)\) such that:
\(1. \ X_t < Y_t\)
\(2. \ X_r = Y_r\) for all \(1 \le r < t\)
A permutation \(X\) of \(A\) is considered different from another permutation \(Y\) of \(A\), if there exists an index \(i \ (1 \le i \le N)\) such that \(X_i \neq Y_i\). For example:
- If \(A = (1,1,1)\), then there is only one different permutation of \(A\).
- If \(A = (1,1,2,2)\), then there are \(6\) different permutations of \(A\).
Input format
- First line: Integer \(N \ (1 \le N \le 10^5)\)
- Second line: \(N\) integers - \(A_1, A_2, \dots, A_N \ (1 \le A_i \le 2 \cdot 10^5)\)
- Third line: \(N\) integers - \(B_1, B_2, \dots, B_N \ (1 \le B_i \le 2 \cdot 10^5)\)
Output format
Print the remainder of the final answer when divided by \(10^9 + 7.\)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial