#include <bits/stdc++.h>
using namespace std;
long long i, k, t, n, d, j, a[100005], s;
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n - 2; i++) {
    t = upper_bound(a + i, a + n + 1, a[i] + k) - a - i - 1;
    s = s + t * (t - 1) / 2;
  }
  cout << s << endl;
}
