#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[111111];
long long ans;
long long calc(long long x) { return x * (x - 1) / 2; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0, j = 0; i < n; i++) {
    while (j < n && a[j] - a[i] <= m) j++;
    ans += calc(j - i - 1);
  }
  cout << ans << endl;
  return 0;
}
