You are given two non-decreasing sequences \(A = (A_1, A_2, ..., A_M)\) and \(B = (B_1, B_2, ..., B_N)\).
You can choose any two indices \(i\) and \(j\), and then swap \(A_i\) and \(B_j\).
Note that the you can do the operations as many times as you want, and your goal is to transform \(A\) into an arithmetic sequence. After opeartions, you can rearrange the sequence \(A\).
Now, determine how many distinct arithmetic sequences you can obtain.
Input Format
- The first line contains a single integer \(T\) — the number of test cases.
- For each testcase:
- The first line contains two integer \(M\) and \(N\) — the lengths of the sequences \(A\) and \(B\), respectively.
- The second line contains \(M\) integers \(A_1, A_2, ..., A_M\).
- The third line contains \(N\) integers \(B_1, B_2, ..., B_N\).
Output Format
- For each testcase, output the number of distinct arithmetic sequences you can obtain.
Constraints
- \(1 \leq T \leq 10^3\)
- \(2 \leq N \leq M \leq 10 ^ 5\)
- \(-M \leq A_i, B_j \leq M\)
- \(\)The sum of \(M + N\) across all test cases does not exceed \(2 \cdot 10 ^ 7\).
2 3 3 -1 0 2 0 1 2 3 3 0 0 1 0 1 1
4 2
In the first case, the sequence \(A\) could be transfromed into \((-1, 0, 1)\), \((1, 0, -1)\), \((0, 1, 2)\) or \((2, 1, 0)\) by operations.
In the second case, the sequence \(A\) could be transfromed into \((1, 1, 1)\) or \((0, 0, 0)\) by operations.
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
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