题目描述
Problem Description
There are $ N $ cities numbered $ 1, 2, ..., N $. These cities are arranged in a straight line in this order. For each $ i $ ($1 \leq i \leq N$), the coordinate of city $ i $ is $ X_i $.
Takahashi chooses the means of transportation between city $ i $ and city $ j $ as follows:
- If the distance between city $ i $ and city $ j $, $ |X_i - X_j| $, is $ D $ or less, he walks.
- Otherwise, he takes the train.
Find the number of triples of city indices $ (i, j, k) $ that satisfy the following conditions:
- $ i < j < k $
- Takahashi walks between city $ i $ and city $ j $, and between city $ j $ and city $ k $.
- Takahashi takes the train between city $ i $ and city $ k $.
Input Format
The input is given from the standard input in the following format:
$ N $ $ D $ $ X_1 $ $ X_2 $ $ ... $ $ X_N $
Output Format
Output the answer.
Sample Input and Output
Sample Input #1
5 7
11 13 17 19 23
Sample Output #1
5
Sample Input #2
4 10
0 3 6 10
Sample Output #2
0
Sample Input #3
6 36
0 5 32 48 69 71
Sample Output #3
4
Sample Input #4
6 405885562
133510576 158828561 245133494 461153833 840383806 867039395
Sample Output #4
6
Notes/Hints
Constraints
- $3 \leq N \leq 10^5$
- $0 \leq X_i \leq 10^9$ ($1 \leq i \leq N$)
- $ X_i < X_{i + 1} $ ($1 \leq i < N$)
- $0 \leq D \leq 10^9$
Sample Explanation 1
The triples $ (i, j, k) $ that satisfy the conditions are $ (1, 2, 4) $, $ (1, 3, 4) $, $ (1, 3, 5) $, $ (2, 3, 5) $, and $ (2, 4, 5) $, totaling 5.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分
样例输入
5 7
11 13 17 19 23
样例输出
5