For Python users, make sure to select PyPy3 / PyPy2 (depending on which version of Python you're using) instead of Python3 or Python2 when submitting.
You're given two arrays and of length (|a|=|b|=n). Your task is to count the number of valid index selections such that the three chosen values form a non-degenerate triangle. Different selections of indices are counted separately, even if they produce the same multiset of side lengths.
A triplet can be formed in one of the following ways:
Choose one index from array and two distinct indices from array and form a triplet (a_i,b_j,b_k).
Choose two distinct indices from array and one index from array and form a triplet (a_i,a_j,b_k).
A triangle with side lengths (x,y,z) is called non-degenerate if and only if the following conditions hold:
x+y>z
x+z>y
y+z>x
The first line contains a single integer (1 \le t \le 100) — the number of test cases.
For each test case: The first line contains a single integer (2 \le n \le 2000) — the length of arrays and .
The second line contains integers a_1,a_2,\dots,a_n (1 \le a_i \le 10^9) — the elements of array .
The third line contains integers b_1,b_2,\dots,b_n (1 \le b_i \le 10^9) — the elements of array .
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output a single integer — the total number of valid triplets.
Example 1
In the first test case , the only way to form a valid triplet
Pick x=a_1=2 , y=a_2=3 from array and z=b_1=4 from array
In the second test case , there are three ways to form a valid triplet
(2,3,2) Pick x=a_1=2 , y=a_2=3 from array and z=b_1=2 from array
(2,3,4) Pick x=a_1=2 , y=a_2=3 from array and z=b_2=4 from array
(2,4,3) Pick x=b_1=2 , y=b_2=4 from array and z=a_2=3 from array
In the third test case , there are six ways to form a valid triplet
Pick x=a_1=1 , y=a_2=1 from array and z=b_1=1 from array
Pick x=a_1=1 , y=a_3=1 from array and z=b_1=1 from array
Pick x=a_2=1 , y=a_3=1 from array and z=b_1=1 from array
Pick x=b_2=2 , y=b_3=2 from array and z=a_1=1 from array
Pick x=b_2=2 , y=b_3=2 from array and z=a_2=1 from array
Pick x=b_2=2 , y=b_3=2 from array and z=a_3=1 from array
Subtask ( points) : (1 \le \sum n \le 100)
Subtask ( points) : (1 \le a_1,a_2,\ldots,a_n \le 10) and (1 \le b_1,b_2,\ldots,b_n \le 10).
Subtask ( points) : No additional constraints