#include <bits/stdc++.h>
int dx[] = {0, 0, -1, +1, -1, +1, -1, +1};
int dy[] = {-1, +1, 0, 0, -1, +1, +1, -1};
using namespace std;
void ONLINE__JUDGE();
const int mod = 998244353;
const int MAX = 510;
long long x, y, z, cnt;
vector<long long> vec;
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(NULL);
  ONLINE__JUDGE();
  cin >> x >> y;
  for (int i = 0; i < x; i++) cin >> z, vec.push_back(z);
  sort(vec.begin(), vec.end());
  for (int i = 0; i < x; i++) {
    long long val = vec[i] + y;
    long long index =
        upper_bound(vec.begin(), vec.end(), val) - vec.begin() - 1;
    index = index - i;
    cnt += (index * (index - 1)) / 2;
  }
  cout << cnt;
  return 0;
}
void ONLINE__JUDGE() {}
