#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int MAXN=2*10e5+10;
int p_ans;
int pre=-1;
int D[MAXN];
int a,b,c,N,tosearch;
unsigned long long ans=0;
bool cmp(int a,int b)
{
return a<b;
}
void find(int l,int r)
{
int mid=(l+r)/2;
if(l>=r)
{
if(D[l]!=tosearch) return;
else
{
while(D[l]==tosearch)
{
++l;
++ans;
++p_ans;
}
return;
}
}
if(D[mid]<tosearch) find(mid+1,r);
else find(l,mid);
}
int main()
{
memset(D,0,sizeof D);
cin>>N>>c;
for(int i=1;i<=N;++i)
{
scanf("%d",&D[i]);
}
sort(D+1,D+N+1,cmp);
for(int i=1;i<=N;++i)
{
if(D[i]==pre)
{
ans+=p_ans;
continue;
}
p_ans=0;
tosearch=D[i]+c;
if(c>0) find(i,N);
else find(1,i-1);
pre=D[i];
}
printf("%d",ans);
return 0;
}