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++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cctype>
#define LL long long
const int maxn = 1e5 + 5;
using namespace std;
inline int read(){
	int x = 0; char ch = getchar();
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) x = (x * 10) + (ch & 15), ch = getchar();
	return x;
}
vector <pair<int, int> > X[maxn], Y[maxn];
set <pair<int, int> > sx[maxn], sy[maxn];
int n, s1, s2, d, mx, my;
int x[maxn], y[maxn], lx[maxn], ly[maxn], ox[maxn], oy[maxn];
LL ans = 0;
queue <int> q;
bool vis[maxn];
pair<int, int> addx(int l, int f){
	set <pair<int, int> >::iterator it = lower_bound(sx[l].begin(), sx[l].end(), make_pair(oy[f] - d, 0));
	ans += 1ll * (upper_bound(X[l].begin(), X[l].end(), make_pair(oy[f] + d, n)) - lower_bound(X[l].begin(), X[l].end(), make_pair(oy[f] - d, 0)));
	while (oy[it->second] <= oy[f] + d && it != sx[l].end()){
		if (!vis[it->second]) q.push(it->second), vis[it->second] = 1;
	//	it = sx[l].erase(it);
	}
	auto p1 = lower_bound(X[l].begin(), X[l].end(), make_pair(oy[f] - d, 0));
	auto p2 = lower_bound(X[l].begin(), X[l].end(), make_pair(oy[f] + d, 0));
	return make_pair(p1 == X[l].end() ? 0 : p1->second, p2 == X[l].end() ? 0 : p2->second);
}
pair<int, int> addy(int c, int f){
	set <pair<int, int> >::iterator it = lower_bound(sy[c].begin(), sy[c].end(), make_pair(ox[f] - d, 0));
	ans += 1ll * (upper_bound(Y[c].begin(), Y[c].end(), make_pair(ox[f] + d, n)) - lower_bound(Y[c].begin(), Y[c].end(), make_pair(ox[f] - d, 0)));
	while (ox[it->second] <= ox[f] + d && it != sy[c].end()){
		if (!vis[it->second]) q.push(it->second), vis[it->second] = 1;
	//	it = sy[c].erase(it);
	}
	auto p1 = lower_bound(Y[c].begin(), Y[c].end(), make_pair(ox[f] - d, 0));
	auto p2 = lower_bound(Y[c].begin(), Y[c].end(), make_pair(ox[f] + d, 0));
	return make_pair(p1 == Y[c].end() ? 0 : p1->second, p2 == Y[c].end() ? 0 : p2->second);
}
void bfs(){
	q.push(s1); vis[s1] = 1;
	while (!q.empty()){
		int cur = q.front(); q.pop();
		int l1 = lower_bound(lx + 1, lx + mx + 1, ox[cur] - d) - lx;
		int l2 = lower_bound(lx + 1, lx + mx + 1, ox[cur] + d) - lx;
		int c1 = lower_bound(ly + 1, ly + my + 1, oy[cur] - d) - ly;
		int c2 = lower_bound(ly + 1, ly + my + 1, oy[cur] + d) - ly;
		bool f1 = (lx[l1] == ox[cur] - d), f2 = (lx[l2] == ox[cur] + d);
		bool f3 = (ly[c1] == oy[cur] - d), f4 = (ly[c2] == oy[cur] + d);
		pair <int, int> p1, p2, p3, p4;
		if (f1) p1 = addx(l1, cur);
		if (f2) p2 = addx(l2, cur);
		if (f3) p3 = addy(c1, cur);
		if (f4) p4 = addy(c2, cur);
		if (p1.first && p3.first && p1.first == p3.first) --ans;
		if (p1.second && p4.first && p1.second == p4.first) --ans;
		if (p2.first && p3.second && p2.first == p3.second) --ans;
		if (p2.second && p4.second && p2.second == p4.second) --ans;
	}
}
int _abs(int x){
	return x < 0 ? -x : x;
}
int main(){
	scanf("%d%d%d", &n, &s1, &s2);
	for (int a, b, i = 1; i <= n; i++){
		a = read(), b = read();
		x[i] = a - b; y[i] = a + b;
		ox[i] = x[i], oy[i] = y[i];
		lx[i] = x[i], ly[i] = y[i];
	}
	sort(lx + 1, lx + n + 1); sort(ly + 1, ly + n + 1);
	mx = unique(lx + 1, lx + n + 1) - (lx + 1);
	my = unique(ly + 1, ly + n + 1) - (ly + 1);
//	for (int i = 1; i <= mx; i++) printf("%d ", lx[i]); puts("");
//	for (int i = 1; i <= my; i++) printf("%d ", ly[i]); puts("");
	for (int i = 1; i <= n; i++){
		x[i] = lower_bound(lx + 1, lx + mx + 1, x[i]) - lx;
		y[i] = lower_bound(ly + 1, ly + my + 1, y[i]) - ly;
		X[x[i]].push_back(make_pair(oy[i], i));
		Y[y[i]].push_back(make_pair(ox[i], i));
		sx[x[i]].insert(make_pair(oy[i], i));
		sy[y[i]].insert(make_pair(ox[i], i));
	}
	for (int i = 1; i <= mx; i++) sort(X[i].begin(), X[i].end());
	for (int i = 1; i <= my; i++) sort(Y[i].begin(), Y[i].end());
	d = max(_abs(ox[s1] - ox[s2]), _abs(oy[s1] - oy[s2]));
	bfs();
	printf("%lld\n", ans / 2ll);
	return 0;
}