#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 3e5 + 9;
void solve() {
  long long n, k, cnt = 0;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  for (long long i = 0; i < n; i++) {
    long long x = upper_bound(v.begin(), v.end(), v[i] + k) - v.begin() - 1;
    long long len = x - i;
    cnt += len * (len - 1) / 2;
  }
  cout << cnt << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) solve();
  return 0;
}
