#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> arr(n);
  for (auto& i : arr) cin >> i;
  long long l = 0, r = 2, ans = 0;
  while (r < n) {
    if (arr[r] - arr[l] <= k) {
      long long val = r - l - 1;
      val = (val * (val + 1)) / 2;
      ans += val;
      r++;
    } else {
      l++;
    }
    if (r == l + 1) r++;
  }
  cout << ans << "\n";
  return 0;
}
