#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, d, a[N];
long long ans;
int Bs(int l, int r) {
  int mid, k = a[l];
  while (l + 1 < r) {
    mid = (l + r) / 2;
    if (a[mid] - k <= d) {
      l = mid;
    } else {
      r = mid;
    }
  }
  return l;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    long long j = (Bs(i, n) - i);
    ans += ((j * (j - 1)) / 2);
  }
  cout << ans << endl;
}
