#include <bits/stdc++.h>
using namespace std;
int x[100005];
int main() {
#pragma warning(disable : 4996)
  long long int n, d, s, r;
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
  }
  s = 0;
  r = 2;
  for (long long int l = 1; l <= n - 2; l++) {
    while ((r < n) && (d >= x[r + 1] - x[l])) r++;
    s = s + (r - l) * (r - l - 1) / 2;
  }
  cout << s;
  return 0;
}
