https://www.luogu.com.cn/record/57847346
#include<bits/stdc++.h>
#define rg register
using namespace std;
int a[(int)1e7];int ans=0;
int main(){
int n,c;
scanf("%d %d",&n,&c);
//ios::sync_with_stdio(false);
for (rg int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
sort(a+1,a+1+n);
for (rg int i=1;i<=n;i++){
int b=a[i]-c;
rg int l=1,r=n;
while (l<=r){
int mid=(l+r)/2;
if (b<=a[mid]) r=mid-1;
else l=mid+1;
}
for (rg int j=l;;j++){
if (a[j]!=b) break;
else ans++;
}
}
cout<<ans;
return 0;
}