#include <iostream>
#include <string>
#include <algorithm>
int length;
int maxIndex;
int minIndex;
int max;
int min;
int* nums;
void maxmin(int start, int end);
int main()
{
int diff;
std::cin >> length >> diff;
nums = new int[length];
int tablecount = length;
for (int i = 0; i < length; i++)
{
std::cin >> nums[i];
}
for (int i = 0; i < length; i++)
{
int current = nums[i];
for (int j = length-1; j > i; j--)
{
maxmin(i,j);
int m1 = std::max(minIndex, maxIndex);
if (max - min > diff)
{
j = m1;
continue;
}
tablecount += j - i;
j = m1;
}
}
std::cout << tablecount;
}
void maxmin(int start, int end)
{
int tmax = INT_MIN;
int tmin = INT_MAX;
int maxi = start;
int mini = end;
for (int i = start; i < end; i++)
{
if (nums[i] > tmax)
{
tmax = nums[i];
maxi = i;
}
if (nums[i] < tmin)
{
tmin = nums[i];
mini = i;
}
}
max = tmax;
min = tmin;
maxIndex = maxi;
minIndex = mini;
}