#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int n,target;
	cin>>n>>target;
	int arr[n];
	for(int i = 0; i < n; i++){
		cin>>arr[i];
	}
	unordered_map<int,int> ump;
	
	int cnt = 0;
	
	for(int j = 0; j < n; j++){
		int r1 = arr[j] + target;
		int r2 = arr[j] - target;
		
		//Here ump[r] tells us the frequency of targer-arr[j] in the left side of j
		
		if (target == 0) {
            // r1 == r2, so count only once
            cnt += ump[r1];
        }
        else {
        	cnt += ump[r1];
            cnt += ump[r2];
        }
		
		ump[arr[j]]++;
	}
	cout<<cnt<<endl;
	return 0;
}