#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const long double eps = 1e-9;
const int MAXN = 100010;
long long arr[MAXN];
long long calc(int n) { return 1ll * n * (n + 1) / 2ll; }
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  arr[n] = 1e12;
  long long ans = 0;
  int lo = 0, hi = 0;
  while (lo < n) {
    if (abs(arr[hi + 1] - arr[lo]) <= k) {
      hi++;
    } else {
      if (lo == hi) {
        hi++;
      }
      ans += (hi - lo + 1 > 2) ? calc(hi - lo - 1) : 0;
      lo++;
    }
  }
  cout << ans << '\n';
  return 0;
}
