#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, d, x = 0, ans = 0;
  cin >> n >> d;
  vector<long long> a(n);
  a.push_back(1e12);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    while (a[i] - a[x] > d) x++;
    ans += ((x - i) * (x - i + 1) / 2);
  }
  cout << ans;
}
