#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1000 * 101;
const long long INF = 1e18;
long long n, k, a[maxn], ans = 0;
bool first(long long i, long long j) {
  if ((a[i] - a[j]) <= k)
    return true;
  else
    return false;
}
long long c(long long n1) {
  if (n1 < 2) return 0;
  long long x = n1 * (n1 - 1);
  x /= 2;
  return x;
}
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    long long l = 0, r = i, x1;
    long long mid = (r + l) / 2;
    while (r - l > 1) {
      mid = (r + l) / 2;
      if (first(i, mid))
        r = mid;
      else
        l = mid;
    }
    if (!first(i, mid)) mid++;
    x1 = i - mid;
    ans += c(x1);
  }
  cout << ans;
  return 0;
}
