#include<bits/stdc++.h>
using namespace std;
int n[200010];
int BS1(int number[],int n,int x){
int low=0,high=n-1,mid;
int result=-1;
while(low<=high){
mid=low+(high-low)/2;
if(x<=number[mid]){
result=mid;
high=mid-1;
}else {
low=mid+1;
}
}
return result;
}
int BS2(int number[],int n,int x){
int low=0,high=n-1,mid;
int result=-1;
while(low<=high){
mid=low+(high-low)/2;
if(x<number[mid]){
result=mid;
high=mid-1;
}else {
low=mid+1;
}
}
return result;
}
int main(){
int N,c;
cin>>N>>c;
for(int i=0;i<N;i++){
cin>>n[i];
}
sort(n,n+N);
int sum=0;
for(int i=0;i<N;i++){
int t=n[i]+c;
int ans1=BS1(n,N,t);
int ans2=BS2(n,N,t);
if(ans1==-1){
if(ans2==-1){
sum+=0;
}
else{
sum+=0;
}
}
else{
if(ans2==-1){
sum+=(N-ans1);
}
else{
sum+=(ans2-ans1);
}
}
}
cout<<sum;
return 0;
}