11611161 SUSTech Online Judge
Problem 1161 -- Counting

## 1161: Counting

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1574  Solved: 212
[Submit][Status][Web Board]

## Description

Give you an increasing sequence A of length n, and ﬁnd the number of ordered tuples (i, j, k) such that the maximum element in {A[i], A[j], A[k]} minus the minimum element in {A[i], A[j], A[k]} <= m.

## Input

The ﬁrst line of the input is T (T <= 5), which is the number of test cases.
For each test cases, the ﬁrst line is n, m, the next line contains n integers which is the given sequence A. (1 ≤ n ≤ 100000 ; 1 ≤ m≤  1000000000) abs(A[i] <= 1000000000).

## Output

For each test cases, print the number of tuples satisfying requirements  in one line.

## Sample Input

2
4 3
1 2 3 4
5 19
1 10 20 30 50


## Sample Output

4
1

[Submit][Status]