#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <limits>
using namespace std;
int main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
int n, k;
cin >> n >> k;
int result = 0;
vector<int> table;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
table.push_back(x);
}
for (int a = 0; a < n; a++) {
for (int b = a; b < n; b++) {
int small = INT_MAX; // iso luku
int large = 0;
for (int c = a; c <= b; c++) {
small = min(small, table[c]);
large = max(large, table[c]);
}
if (large - small <= k) {
result += 1;
}
}
}
cout << result << "\n";
}