#include <bits/stdc++.h>
using namespace std;
long long arr[100010];
int main() {
  long long n, d, i, x, ans, s, l, r, m;
  cin >> n >> d;
  for (i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  ans = 0;
  for (i = 1; i <= n; i++) {
    x = arr[i] + d;
    l = i;
    r = n;
    while (l + 1 < r) {
      m = (l + r) / 2;
      if (arr[m] < x)
        l = m;
      else
        r = m;
    }
    if (abs(arr[i] - arr[r]) <= d)
      x = r;
    else
      x = l;
    s = x - i - 1;
    ans += (s * (s + 1)) / 2;
  }
  cout << ans;
  return 0;
}
