#include <bits/stdc++.h>
using namespace std;
int x[1000 * 100 + 2], dp[1000 * 100 + 2], p[1000 * 100 + 2];
int main() {
  int n, pos = 0, d;
  cin >> n >> d;
  for (int i = 1; i <= n; i++) cin >> x[i], dp[i] = dp[i - 1] + 1;
  bool ogey = false;
  for (int i = 1; i <= n; i++) {
    if (!ogey)
      for (int j = pos + 1; j <= n; j++) {
        if (x[j] - x[i] > d) {
          p[i] = j - 1;
          pos = j - 1;
          break;
        } else if (j == n) {
          ogey = true;
          break;
        }
      }
    if (ogey) {
      pos = n;
      p[i] = n;
    }
  }
  long long ans = 0, c = 1;
  for (int i = 1; i <= n; i++) {
    c = 1;
    c *= ((long long)(dp[p[i]] - dp[i]) * (long long)(dp[p[i]] - dp[i] - 1)) /
         (long long)2;
    if (c <= 0) c = 0;
    ans += c;
  }
  cout << ans;
}
