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