#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const double E = 1e-6;
const long long ll1 = 1;
int n, md;
vector<int> v;
vector<long long> d;
int main() {
  cin >> n >> md;
  v.resize(n);
  d.resize(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  d[0] = 0;
  for (int i = 1; i < n; ++i) {
    vector<int>::iterator lst =
        lower_bound(v.begin(), v.begin() + i, v[i] - md);
    long long dst = i - (lst - v.begin()) - 1;
    d[i] = d[i - 1] + dst * (dst + 1) / 2;
  }
  cout << d[n - 1];
  return 0;
}
