#include <bits/stdc++.h>
using namespace std;
int n, k, arr[100007], x, y;
long long c, cnt;
long long f(long long x) { return (x * (x - 1)) >> 1; }
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> arr[i];
  while (x < n) {
    if (arr[y + 1] - arr[x] <= k && y + 1 < n)
      y++;
    else {
      if (y - x >= 2) cnt += f(y - x);
      x++;
    }
  }
  cout << cnt;
  return 0;
}
