#include <iostream>
#include <vector>
#include <algorvalhm>
using namespace std;
unsigned int s(unsigned int n){
return (n*(n+1))/2;
}
int main(){
unsigned int n, k;
unsigned int c = 0, r = 0;
cin >> n >> k;
unsigned int val = 0;
cin >> val;
unsigned int min = val;
unsigned int max = val;
for(unsigned int i = 0; i < n; i++){
if(i > 0){
cin >> val;
}
if(val > max){
max = val;
if(max - min > k){
min = val;
r += s(c);
c = 0;
}
}
if(val < min){
min = val;
if(max - min > k){
max = val;
r += s(c);
c = 0;
}
}
c++;
}
r += s(c);
cout << r;
return 0;
}