#include <bits/stdc++.h>
using namespace std;
int Arr[100100], n;
int BS(int d, int k) {
  int L = k, R = n - 1;
  while (L < R) {
    int mid = L + (R - L + 1) / 2;
    if (Arr[mid] <= d)
      L = mid;
    else
      R = mid - 1;
  }
  return R;
}
int main() {
  int d;
  long long ans = 0;
  cin >> n >> d;
  for (int i = 0; i < n; i++) cin >> Arr[i];
  for (int i = 0; i < n - 1; i++) {
    if (Arr[i + 1] - Arr[i] <= d) {
      int max = BS(Arr[i] + d, i + 1);
      ans += ((max - i) * 1LL * (max - i - 1)) / 2;
    }
  }
  cout << ans;
  return 0;
}
