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