Counting Good Triplets
You are given an array a_1, a_2, …, a_n of integers and three bounds x, y and z.
A triple of indices (i, j, k) with 1 ≤ i < j < k ≤ n is good if all three of these hold:
|a_i − a_j| ≤ x|a_j − a_k| ≤ y|a_i − a_k| ≤ z
Count the good triples. Triples are counted by their indices, so equal values at different positions give different triples.
Input
The first line contains t (1 ≤ t ≤ 100), the number of test cases.
Each test case consists of two lines. The first line contains four integers n, x, y, z
(1 ≤ n ≤ 100, 0 ≤ x, y, z ≤ 1000). The second line contains n integers a_1, …, a_n
(0 ≤ a_i ≤ 1000).
The sum of n over all test cases does not exceed 500.
Output
For each test case, print one line with the number of good triples.
Notes
In the first test case of the first example, the array is 3 0 1 1 9 7 with x = 7, y = 2,
z = 3. The good triples are (1,2,3), (1,2,4), (1,3,4) and (2,3,4), with values
(3,0,1), (3,0,1), (3,1,1) and (0,1,1). In the second test case no triple is good. In the
third test case n = 2, so there are no triples at all and the answer is 0.
In the second example every triple of an all-equal array is good, so the answer is the number of ways to pick three of the five positions.