#include <bits/stdc++.h>
long long i, j, k, m, M, n, ans, co, s, f, len, T, t;
long long a[100001], d, p = 1, q = 1;
int main() {
  scanf("%lld %lld", &n, &d);
  for (i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (p = 1; p <= n - 2; p++) {
    while (a[q + 1] - a[p] <= d && q <= n - 1) q++;
    s += (q - p) * (q - p - 1) / 2;
  }
  printf("%lld", s);
  return 0;
}
