#include <bits/stdc++.h>
using namespace std;
int a[100001];
long long int n, i, j, k, l, s, m, d, ans;
int main() {
  cin >> n >> d;
  k = 2;
  for (i = 1; i <= n; i++) cin >> a[i];
  ans = 0;
  j = 2;
  for (i = 1; i <= n; i++) {
    while (a[j] - a[i] <= d && j <= n) j++;
    l = j - i - 1;
    ans += (l * (l - 1)) / 2;
  }
  cout << ans;
  return 0;
}
