#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int size = 100 * 1000 + 100;
int n, d;
long long ans;
int pts[size];
int main() {
  scanf("%d%d", &n, &d);
  int ps = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &pts[i]);
    while (pts[i] - pts[ps] > d) ps++;
    ans += max(i - ps, 0) * 1ll * max(i - ps - 1, 0) / 2;
  }
  cout << ans << endl;
  return 0;
}
