#include <bits/stdc++.h>
using namespace std;
int num;
long long v[100005];
long long dp[100005];
long long n, D;
long long C(long long b) {
  if (b < 2) return 0;
  return (b * (b - 1)) / 2;
}
int main() {
  while (cin >> n >> D) {
    for (int i = 1; i <= n; i++) {
      cin >> v[i];
    }
    num = 1;
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++) {
      for (int j = num; j < i; j++) {
        if (v[i] - v[j] <= D) {
          dp[i] += C(i - j);
          num = j;
          break;
        }
      }
      dp[i] += dp[i - 1];
    }
    cout << dp[n] << endl;
  }
  return 0;
}
