Problem:
Score : 900 points

Problem Statement

There are N pinholes on the xy-plane. The i-th pinhole is located at (x_i,y_i).

We will denote the Manhattan distance between the i-th and j-th pinholes as d(i,j)(=|x_i-x_j|+|y_i-y_j|).

You have a peculiar pair of compasses, called Manhattan Compass.
This instrument always points at two of the pinholes.
The two legs of the compass are indistinguishable, thus we do not distinguish the following two states: the state where the compass points at the p-th and q-th pinholes, and the state where it points at the q-th and p-th pinholes.

When the compass points at the p-th and q-th pinholes and d(p,q)=d(p,r), one of the legs can be moved so that the compass will point at the p-th and r-th pinholes.

Initially, the compass points at the a-th and b-th pinholes.
Find the number of the pairs of pinholes that can be pointed by the compass.

Constraints

2≦N≦10^5

1≦x_i, y_i≦10^9

1≦a < b≦N

When i ≠ j, (x_i, y_i) ≠ (x_j, y_j)

x_i and y_i are integers.

Input

The input is given from Standard Input in the following format:

N a b
x_1 y_1
:
x_N y_N

Output

Print the number of the pairs of pinholes that can be pointed by the compass.

Sample Input 1

5 1 2
1 1
4 3
6 1
5 5
4 8

Sample Output 1

4

Initially, the compass points at the first and second pinholes.

Since d(1,2) = d(1,3), the compass can be moved so that it will point at the first and third pinholes.

Since d(1,3) = d(3,4), the compass can also point at the third and fourth pinholes.

Since d(1,2) = d(2,5), the compass can also point at the second and fifth pinholes.

No other pairs of pinholes can be pointed by the compass, thus the answer is 4.

Sample Input 2

6 2 3
1 3
5 3
3 5
8 4
4 7
2 5

Sample Output 2

4

Sample Input 3

8 1 2
1 5
4 3
8 2
4 7
8 8
3 3
6 6
4 8

Sample Output 3

7

Solution in C++ (GCC 9.2.1) (judge verdict: Runtime Error)

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SZ = 2e5 + 10;

vector<pair<ll, ll>> vec;
map<pair<ll, ll>, ll> ind;
bool used[SZ];
map<ll, ll> ch;
set<ll> mp1[SZ * 3], mp2[SZ * 3];
vector<ll> mp_s1[SZ * 3], mp_s2[SZ * 3];

int main() {
	fastInp;

	ll n, a, b;
	cin >> n >> a >> b;

	vector<ll> bal;
	a--; b--;

	for (int i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		vec.push_back({ x, y });
	}
	ll d = abs(vec[a].first - vec[b].first) + abs(vec[a].second - vec[b].second);
	for (int i = 0; i < n; i++) {
		ll x = vec[i].first, y = vec[i].second;
		bal.push_back(x + y);
		bal.push_back(x - y);

		bal.push_back(x - d + y);
		bal.push_back(x + d + y);

		bal.push_back(x - d - y);
		bal.push_back(x + d - y);
	}
	sort(bal.begin(), bal.end());
	auto it = unique(bal.begin(), bal.end());
	bal.erase(it, bal.end());
	for (int i = 0; i < bal.size(); i++) ch[bal[i]] = i;

	
	for (int i = 0; i < n; i++) {
		ll x, y;
		x = vec[i].first;
		y = vec[i].second;
		ind[{x, y}] = i;

		mp1[ch[x + y]].insert(x);
		mp2[ch[x - y]].insert(x);

		mp_s1[ch[x + y]].push_back(x);
		mp_s2[ch[x - y]].push_back(x);
	}

	used[a] = 1;
	used[b] = 1;

	queue<ll> q;
	q.push(a);
	q.push(b);
	cout << 2 / 0;
	while (!q.empty()) {
		ll v = q.front();
		q.pop();
		ll x = vec[v].first, y = vec[v].second;

		ll mnX = x - d;
		ll curB = (mnX + y);
		ll curB1 = ch[curB];
		while (lower_bound(mp1[curB1].begin(), mp1[curB1].end(), mnX) != mp1[curB1].end() && *(lower_bound(mp1[curB1].begin(), mp1[curB1].end(), mnX)) <= x) {
			ll vl = *(lower_bound(mp1[curB1].begin(), mp1[curB1].end(), mnX));
			pair<ll, ll> crds = { vl, curB - vl };
			ll i = ind[{crds.first, crds.second}];
			mp1[curB1].erase(vl);
			if (!used[i]) {
				used[i] = 1;
				q.push(i);
			}
		}

		ll mxX = x + d;
		curB = (mxX + y);
		curB1 = ch[curB];
		while (lower_bound(mp1[curB1].begin(), mp1[curB1].end(), x) != mp1[curB1].end() && (*(lower_bound(mp1[curB1].begin(), mp1[curB1].end(), x))) <= mxX) {
			ll vl = *(lower_bound(mp1[curB1].begin(), mp1[curB1].end(), x));
			pair<ll, ll> crds = { vl, curB - vl };
			ll i = ind[{crds.first, crds.second}];
			mp1[curB1].erase(vl);
			if (!used[i]) {
				used[i] = 1;
				q.push(i);
			}
		}

		mnX = x - d;
		curB = mnX - y;
		curB1 = ch[curB];
		while (lower_bound(mp2[curB1].begin(), mp2[curB1].end(), mnX) != mp2[curB1].end() && (*(lower_bound(mp2[curB1].begin(), mp2[curB1].end(), mnX)) <= x)) {
			ll vl = *(lower_bound(mp2[curB1].begin(), mp2[curB1].end(), mnX));
			pair<ll, ll> crds = { vl, -(curB - vl) };
			ll i = ind[{crds.first, crds.second}];
			mp2[curB1].erase(vl);
			if (!used[i]) {
				used[i] = 1;
				q.push(i);
			}
		}

		mxX = x + d;
		curB = (mxX - y);
		curB1 = ch[curB];
		while (lower_bound(mp2[curB1].begin(), mp2[curB1].end(), x) != mp2[curB1].end() && (*(lower_bound(mp2[curB1].begin(), mp2[curB1].end(), x)) <= mxX)) {
			ll vl = *(lower_bound(mp2[curB1].begin(), mp2[curB1].end(), x));
			pair<ll, ll> crds = { vl, -(curB - vl) };
			ll i = ind[{crds.first, crds.second}];
			mp2[curB1].erase(vl);
			if (!used[i]) {
				used[i] = 1;
				q.push(i);
			}
		}
	}

	for (int i = 0; i < SZ * 3; i++) {
		sort(mp_s1[i].begin(), mp_s1[i].end());
	}
	for (int i = 0; i < SZ * 3; i++) {
		sort(mp_s2[i].begin(), mp_s2[i].end());
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		if (used[i]) {
			ll addNw = ans;
			ll x = vec[i].first, y = vec[i].second;
			ll mnX = x - d;
			ll curB = ch[(mnX + y)];

			ans += (upper_bound(mp_s1[curB].begin(), mp_s1[curB].end(), x) - lower_bound(mp_s1[curB].begin(), mp_s1[curB].end(), mnX));

			ll mxX = x + d;
			curB = ch[(mxX + y)];
			ans += upper_bound(mp_s1[curB].begin(), mp_s1[curB].end(), mxX) - lower_bound(mp_s1[curB].begin(), mp_s1[curB].end(), x);

			mnX = x - d;
			curB = ch[mnX - y];
			ans += upper_bound(mp_s2[curB].begin(), mp_s2[curB].end(), x) - lower_bound(mp_s2[curB].begin(), mp_s2[curB].end(), mnX);

			mxX = x + d;
			curB = ch[(mxX - y)];
			ans += upper_bound(mp_s2[curB].begin(), mp_s2[curB].end(), mxX) - lower_bound(mp_s2[curB].begin(), mp_s2[curB].end(), x);
			addNw -= ans;
			addNw = abs(addNw);

			if (ind.find({ x - d, y }) != ind.end()) {
				ans--;
			}
			if (ind.find({ x + d, y }) != ind.end()) {
				ans--;
			}
			if (ind.find({ x, y - d }) != ind.end()) {
				ans--;
			}
			if (ind.find({ x, y + d }) != ind.end()) {
				ans--;
			}
		}
	}

	cout << ans / 2;

	return 0;
}