#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> vec;
int n, k;
int recur(int l, int r) {
int ans = 0;
if (l + 1 >= r) {
return ans;
}
int mid = (l + r) / 2;
ans += recur(l, mid);
ans += recur(mid, r);
cout << l << " " << r << endl;
// Debugging output
// cout << l << " " << r << endl;
// Count inversions
// int ans1 = 0;
for(int i = l, j = mid; i < mid; i++){
while(j < r && vec[i] >= vec[j] + k) j++;
ans += j - mid;
}
// cout << ans1 << endl;
inplace_merge(vec.begin() + l, vec.begin() + mid, vec.begin() + r);
return ans;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> k;
vec.resize(n);
for (int i = 0; i < n; i++) {
cin >> vec[i];
}
cout << recur(0, n) << endl;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgaW50IGxvbmcgbG9uZyAKdmVjdG9yPGludD4gdmVjOwppbnQgbiwgazsKCmludCByZWN1cihpbnQgbCwgaW50IHIpIHsKICAgIGludCBhbnMgPSAwOwogICAgaWYgKGwgKyAxID49IHIpIHsKICAgICAgICByZXR1cm4gYW5zOwogICAgfQogICAgaW50IG1pZCA9IChsICsgcikgLyAyOwogICAgYW5zICs9IHJlY3VyKGwsIG1pZCk7CiAgICBhbnMgKz0gcmVjdXIobWlkLCByKTsKICAgIGNvdXQgPDwgbCA8PCAiICIgPDwgciA8PCBlbmRsOyAKICAgIC8vIERlYnVnZ2luZyBvdXRwdXQKICAgIC8vIGNvdXQgPDwgbCA8PCAiICIgPDwgciA8PCBlbmRsOwogICAgCiAgICAvLyBDb3VudCBpbnZlcnNpb25zCiAgICAKICAgIC8vIGludCBhbnMxID0gMDsKICAgIGZvcihpbnQgaSA9IGwsIGogPSBtaWQ7IGkgPCBtaWQ7IGkrKyl7CiAgICAJd2hpbGUoaiA8IHIgJiYgdmVjW2ldID49IHZlY1tqXSArIGspIGorKzsKICAgIAlhbnMgKz0gaiAtIG1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