var
	n, r, i, j : longint;
	ans : int64;
	a : array[0..300000] of longint;


procedure qsort(l,r:longint);
var k,i,j,y:longint;
begin
	i:=l;
	j:=r;
	k:=a[(l+r) div 2];
	repeat 
		while a[i]<k do inc(I);
		while a[j]>k do dec(j);
		if i<=j then 
		begin
			y:=a[i]; a[i]:=a[j]; a[j]:=y;
			inc(i); dec(j);
		end;
		if l<j then qsort(l,j);
		if i<r then qsort(i,r);
	until i > j;
end;

begin
	reset(input, 'che.in');
	rewrite(output, 'che.out');
	read(n, r);
	for i := 1 to n do
		read(a[i]);
	
{	qsort(1, n);
 }



	ans := 0;
	j := 0;
	for i := 1 to n do
	begin
		if (j <= i) then j := i + 1;
		while ((j <= n) and (a[j] - a[i] <= r)) do
			inc(j);
		ans := ans + (n - j);
	end;
	writeln(ans);
end.
	
