#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 7;
int n;
long long a[N], d;
long long cal(int st, int ed) {
  if (ed - st < 2) return 0;
  return 1ll * (ed - st) * (ed - st - 1) / 2;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> d;
  for (int i = 1; i <= n; i++) cin >> a[i];
  long long ans = 0;
  int st = 1, ed = 2;
  while (ed < n) {
    ed++;
    while (labs(a[ed] - a[st]) > d && st < ed) st++;
    ans += cal(st, ed);
  }
  cout << ans << endl;
  return 0;
}
