#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e+9 + 9;
const long double EPS = 1e-9;
const long double PI = 3.1415926535897932384626433832795;
const int N = 100500;
int n, d, a[N];
long long ans;
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  for (int i = 0; i < n; ++i) {
    int j = upper_bound(a, a + i, a[i] - d - 1) - a;
    ans += ((i - j) * 1ll * (i - j - 1)) / 2;
  }
  cout << ans;
  return 0;
}
