#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-8;
const long long INF = (long long)(2e9);
const long long mod = (int)(1e+9 + 7);
const int N = (int)(1e5);
int days_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
long long C(long long x) { return x * (x - 1) / 2; }
int main() {
  int n, d;
  cin >> n >> d;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  int it1, it2;
  it1 = it2 = 0;
  long long ans = 0;
  while (it2 != n) {
    if (x[it2] - x[it1] > d) {
      it1++;
      continue;
    }
    ans += C(it2 - it1);
    it2++;
  }
  cout << ans;
  return 0;
}
