program dec1;
var
n,m,i,j,ans,t,l,r,x,y:longint;
a:array[1..200000] of longint;
procedure sort(l,r:longint);
var
i,j,mid:longint;
begin
i:=l;j:=r;mid:=a[random(j-i+1)+i];
repeat
while a[i]<mid do inc(i);
while a[j]>mid do dec(j);
if not(i>j) then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
inc(i);dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
assign(input,'dec.in');
assign(output,'dec.out');
reset(input);
rewrite(output);
readln(n,m);
for i:=1 to n do read(a[i]);
sort(1,n);
l:=1;
r:=2;
i:=0;
j:=0;
while r<=n do
begin
if a[r]-a[l]=m then
begin
y:=a[r];
x:=a[l];
i:=1;
j:=1;
while (a[r+1]=y)and (r<n) do
begin
r:=r+1;
j:=j+1;
end;
while a[l+1]=x do
begin
i:=i+1;
l:=l+1;
end;
ans:=ans+i*j;
l:=l+1;
r:=r+1;
end
else
begin
if a[r]-a[l]<m
then r:=r+1
else l:=l+1;
end;
end;
writeln(ans);
close(input);
close(output);
end.