#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <cstring>
 
 
using namespace std;
 
#define ll long long
 
const int maxn = 1 << 20;

int n;
int d;
int x[maxn], y[maxn];
pair<int, int> a[maxn];
int ans;

int Sqrt(int x) {
 	int res = sqrt(x + 0.5);
	if (1LL * res * res != x) return -1;
	return res;
}

void check(int l1, int l2, int r1, int r2, int d) {
 	if (d < 0) {
 	 	d = -d;
		swap(l1, r1);
		swap(l2, r2);
	}
	int r = r1;
	for (int l = l1; l <= l2; l++) {
	 	while (r < r2 && a[r].second - a[l].second < d) r++;
		ans += a[r].second - a[l].second == d;
	}
}

void repair(vector<pair<int, int> > &v) {
 	vector<pair<int, int> > res;
	for (int i = 0; i < (int)v.size(); i++) if (v[i].first > 0 || v[i].first == 0 && v[i].second > 0) res.push_back(v[i]);
	v = res;
}
 
int main() {
	freopen("distances.in", "r", stdin);
	freopen("distances.out", "w", stdout);

	scanf("%d%d", &n, &d);
	for (int i = 0; i < n; i++) {
	 	scanf("%d%d", &x[i], &y[i]);
		a[i] = make_pair(x[i], y[i]);
	}
	sort(a, a + n);
	
	vector<pair<int, int> > v;
	for (int dx = 0; dx * dx <= d; dx++) {
	 	int yy = d - dx * dx;
		int dy = Sqrt(yy);
		if (dy == -1) continue;
		for (int it = 0; it < 2; it++) {
		 	for (int sx = -1; sx <= 1; sx += 2) {
		 	 	for (int sy = -1; sy <= 1; sy += 2) {
		 	 	 	v.push_back(make_pair(dx * sx, dy * sy));
				}
			}
			swap(dx, dy);
		}
	}
	sort(v.begin(), v.end());
	v.resize(unique(v.begin(), v.end()) - v.begin());
	repair(v);
	cerr << v.size() << endl;

	ans = 0;
	for (int j = 0; j < (int)v.size(); j++) {
		int r = 0;
		for (int l = 0; l < n; l++) {
			int l1 = l;
			while (l1 + 1 < n && a[l1 + 1].first == a[l].first) l1++;

			while (r < n && a[r].first - a[l].first < v[j].first) r++;
			if (a[r].first - a[l].first == v[j].first) {
				int r1 = r;
				while (r1 + 1 < n && a[r1 + 1].first == a[r].first) r1++;

				check(l, l1, r, r1, v[j].second);
				r = r1;
			}

			l = l1;			
		}
	}

	cout << ans << endl;

    return 0;
}                                                                           