#include <bits/stdc++.h>
using namespace std;
int p[100050];
int first[2];
int main() {
  int n, d;
  while (~scanf("%d%d", &n, &d)) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &p[i]);
    }
    int f = 0;
    long long ans = 0;
    for (int i = 2; i < n; i++) {
      for (; f <= i - 2; f++) {
        if (p[i] - p[f] <= d) {
          long long a = i - f;
          ans += a * (a - 1) / 2;
          break;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
