#include <bits/stdc++.h>
using namespace std;
long long ar[100005];
int main() {
  long long n, dis;
  cin >> n >> dis;
  for (long long i = 0; i < n; i++) cin >> ar[i];
  long long ans = 0;
  for (long long i = 0; i < n - 2; i++) {
    long long k = ar[i] + dis;
    long long temp = upper_bound(ar, ar + n, k) - ar;
    long long x = temp - i - 2;
    ans += x * (x + 1) / 2;
  }
  cout << ans << endl;
  return 0;
}
