eolymp
bolt
Try our new interface for solving problems
Problems

Significant inversions

Significant inversions

Consider an arbitrary sequence of numbers x1, x2, ..., xn. A pair of indices (j, k) is called an inversion (violation of the order), if j < k and xj > xk. For any non-negative integer t a pair of indices (j, k) is called a t-_significant inversion_, if j < k and xj > xk + t.

Count the number of t-significant inversions in the sequence x1, x2, ..., xn.

Input

The first line contains two integers n (1n50000) and t (0t109). The second line contains integers x1, x2, ..., xn, not greater than 109 by absolute value.

Output

Print the number of t-significant inversions in the sequence x1, x2, ..., xn.

Time limit 0.5 seconds
Memory limit 32 MiB
Input example #1
6 0
1 2 2 9 5 4
Output example #1
3

Example description: In sample 1 the inversions are: (4, 5), (4, 6) and (5, 6). They all are 0-significant. In sample 2 the inversions are (3, 4) and (3, 5). But x3 ≤ x5 + 2, inversion (3, 5) is not 2-significant. But pair (3, 4) is so.

Author Alexandr Rybak
Source ІІІ (городской) этап Всеукраинской олимпиады школьников по информатике, 2013, г. Киев