#include <bits/stdc++.h>
using namespace std;
long long int A[500005];
long long int tree[2000005];
void update(long long int node, long long int start, long long int end,
            long long int idx, long long int val) {
  if (start == end) {
    A[idx] += val;
    tree[node] += val;
  } else {
    long long int mid = (start + end) / 2;
    if (start <= idx and idx <= mid) {
      update(2 * node, start, mid, idx, val);
    } else {
      update(2 * node + 1, mid + 1, end, idx, val);
    }
    tree[node] = tree[2 * node] + tree[2 * node + 1];
  }
}
long long int query(long long int node, long long int start, long long int end,
                    long long int l, long long int r) {
  if (r < start or end < l) {
    return 0;
  }
  if (l <= start and end <= r) {
    return tree[node];
  }
  long long int mid = (start + end) / 2;
  long long int p1 = query(2 * node, start, mid, l, r);
  long long int p2 = query(2 * node + 1, mid + 1, end, l, r);
  return (p1 + p2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  long long int a[n];
  pair<long long int, long long int> p[n];
  long long int c[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    p[i] = make_pair(a[i], i);
  }
  sort(p, p + n);
  long long int b[n];
  for (long long int i = 0; i < n; i++) {
    b[p[i].second] = i;
    c[i] = p[i].first;
  }
  for (long long int i = n - 1; i >= 0; i--) {
    long long int ub = upper_bound(c, c + n, a[i] + k) - c;
    ub--;
    long long int lb = lower_bound(c, c + n, a[i] - k) - c;
    long long int xxx = query(1, 0, n, lb, ub);
    xxx++;
    update(1, 0, n, b[i], xxx);
  }
  long long int ans = query(1, 0, n, 0, n);
  cout << ans << endl;
  return 0;
}
