#include<bits/stdc++.h>
//#define lowbit(x) x&(-x)
using namespace std;
#define int long long
typedef pair<int,int> PII;
map<int,int> bo;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int i,j;
cin>>i>>j;
vector<int> a;
set<int> b;
for(int x=0;x<i;x++)
{
int y;
cin>>y;
bo[y]++;
b.insert(y);
}
int l1=b.size();
int c[l1];
set<int>::iterator it;
int e;
for(e=0,it=b.begin();e<l1,it!=b.end();e++,it++)
{
c[e]=*it;
}
int l=0;
int r=l+1;
int c1=0;
while(l<=l1)
{
if(c[l]+j<c[r]) l++;
else
{
if(c[l]+j==c[r])
{
c1+=(bo[c[l]]*bo[c[r]]);
l++;
r++;
}
else r++;
}
}
cout<<c1<<endl;
}
#include<bits/stdc++.h>
//#define lowbit(x) x&(-x)
using namespace std;
#define int long long
//自己做的单指针版
map<int ,int> bo;
int n,c;
vector<int> a;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>c;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
a.push_back(x);
bo[x]++;
}
sort(a.begin(),a.end());
int l=0;
int d=0;
while(a[l]+c<=a[a.size()-1])
{
if(bo[a[l]+c]>=1)
{
d+=bo[a[l]+c];
}
l++;
}
cout<<d;
}