# Variation

We say that two integers x and y have a variation of at least _K_, if |x − y| ≥ _K_ (the absolute value of their difference is at least _K_). Given a sequence of N integers a1,a2,...,aN and _K_, the total variation count is the number of pairs of elements in the sequence with variation at least _K_, i.e. it is the size of the set of pairs

_{(i,j)|1≤i\<j≤N and|ai−aj|≥K}_

For example if _K_ = 1 and the sequence is 3,2,4 the answer is 3. If _K_ = 1 and the sequence is 3, 1, 3 then the answer is 2.

Your task is to write a program that takes a sequence and the value _K_ as input and computes the total variation count.

#### Input format

The first line contains two positive integers _N_ and _K_, separated by a space.

This is followed by a line containing _N_ integers separated by space giving the values of the sequence.

#### Output format

A single integer in a single line giving the total variation count.

#### Test data

You may assume that all integers in the input are in the range 0 to 10^8 inclusive.

**Subtask 1 (40 marks)** : 1 ≤ _N_ ≤ 4000, 1 ≤ _K_ ≤ 10^8

**Subtask 2 (60 marks)** : 1 ≤ _N_ ≤ 65000, 1 ≤ _K_ ≤ 10^8

#### Sample Input

```
3 1 
3 1 3
```

#### Sample Output

```
2
```

```java
class Codechef {
    // O(NlogN)
    public static int numberOfVariations(int[] arr, int k) {
        Arrays.sort(arr);
        int ans = 0;
        for (int i = 1; i < arr.length; i++)
            // Binary searching for element <= arr[i]-k
            ans += findJustSmaller(arr, arr[i] - k, 0, i) + 1;
        return ans;
    }

    public static int findJustSmaller(int[] arr, int value, int start, int end) {
        int ans = -1;
        while (start <= end) {
            int mid = start + (end - start) / 2;
            if (arr[mid] <= value) {
                ans = mid;
                start = mid + 1;
            } else
                end = mid - 1;
        }
        return ans;
    }
}
```
