#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define INF 0x3f3f3f3f3f
const int N = 1000010;
using namespace std;
int arr[N];
int n,C;
//二分找第一个位置
int b_search1(int arr[],int n,int x){
int l = 0;
int r = n+1;
while(l+1<r){
int mid = (l+r)/2;
if(arr[mid]<x){
l = mid;
}else{
r = mid;
}
}
if(arr[r] == x){
return r;
}else{
return -1;
}
}
//二分找最后一个位置
int b_search2(int arr[],int n,int x){
int l = 0;
int r = n+1;
while(l+1<r){
int mid = (l+r)/2;
//这里不一样了!
if(arr[mid]<=x){
l = mid;
}else{
r = mid;
}
}
//还有这
if(arr[l] == x){
return l;
}else{
return -1;
}
}
signed main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>C;
int cnt;//记录count
for(int i = 1; i<= n ;i++){
cin>>arr[i];
}
//从小到大 排个序 二分前置条件
sort(arr+1,arr+n+1);
for(int B = 1; B <= n; B++){
int A = arr[B] + C;
int flag = b_search1(arr,n,A);
if(flag == -1){
//找不到就继续往下找
continue;
}else{
//找到了最左符合元素的位置
//flag2表示最右符合元素的位置
int flag2 = b_search2(arr,n,A);
cnt += (flag2-(flag-1));
}
}
cout<<cnt;
return 0;
}