#include <bits/stdc++.h>
using namespace std;
int N, D;
int x[100010];
int main(void) {
  int i, j;
  cin >> N >> D;
  for ((i) = 0; (i) < (int)(N); (i)++) scanf("%d", &x[i]);
  long long ans = 0;
  j = 0;
  for ((i) = 0; (i) < (int)(N); (i)++) {
    while (j + 1 < N && x[j + 1] - x[i] <= D) j++;
    long long tmp = j - i;
    ans += tmp * (tmp - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}
