Counting Orders solution codeforces
You are given two arrays 𝑎� and 𝑏� each consisting of 𝑛� integers. All elements of 𝑎� are pairwise distinct.
Find the number of ways to reorder 𝑎� such that 𝑎𝑖>𝑏𝑖��>�� for all 1≤𝑖≤𝑛1≤�≤�, modulo 109+7109+7.
Two ways of reordering are considered different if the resulting arrays are different.
Each test contains multiple test cases. The first line contains the number of test cases 𝑡� (1≤𝑡≤1041≤�≤104). The description of the test cases follows.
The first line of each test case contains a single integer 𝑛� (2≤𝑛≤2⋅1052≤�≤2⋅105) — the length of the array 𝑎� and 𝑏�.
The second line of each test case contains 𝑛� distinct integers 𝑎1�1, 𝑎2�2, ……, 𝑎𝑛�� (1≤𝑎𝑖≤1091≤��≤109) — the array 𝑎�. It is guaranteed that all elements of 𝑎� are pairwise distinct.
The second line of each test case contains 𝑛� integers 𝑏1�1, 𝑏2�2, ……, 𝑏𝑛�� (1≤𝑏𝑖≤1091≤��≤109) — the array 𝑏�.
It is guaranteed that the sum of 𝑛� over all test cases does not exceed 2⋅1052⋅105.
Counting Orders solution codeforces
For each test case, output the number of ways to reorder array 𝑎� such that 𝑎𝑖>𝑏𝑖��>�� for all 1≤𝑖≤𝑛1≤�≤�, modulo 109+7109+7.
input
output
32 0 1 0 13824