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