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