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: Runtime Error)

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
struct lpl{
	int x, y;
	bool operator < (const lpl &A)const{return (x == A.x) ? (y < A.y) : (x < A.x);}
}point[maxn];
int N, a, b, tot, lpd, cntx, cnty, d;
int idx[maxn], idy[maxn], ld[maxn];
set<int> xx, yy, sx[maxn], sy[maxn];
map<int, int> mpx, mpy;
map<lpl, int> dian;
queue<int> q;
stack<int> s;

inline void putit(){
	set<int>::iterator iter;
	scanf("%d%d%d", &N, &a, &b);
	for(int x, y, i = 1; i <= N; ++i){
		scanf("%d%d", &x, &y);
		point[i].x = x + y; point[i].y = x - y;
		xx.insert(point[i].x); yy.insert(point[i].y);
	}
	for(iter = xx.begin(); iter != xx.end(); ++iter){mpx[*iter] = ++cntx; idx[cntx] = *iter;}
	for(iter = yy.begin(); iter != yy.end(); ++iter){mpy[*iter] = ++cnty; idy[cnty] = *iter;}
	for(int i = 1; i <= N; ++i){
		dian[(lpl){mpx[point[i].x], mpy[point[i].y]}] = i;
		sx[mpx[point[i].x]].insert(point[i].y);
		sy[mpy[point[i].y]].insert(point[i].x);
		/////////////////////
	//	printf("i = %d x = %d y = %d mpx = %d mpy = %d\n", i, point[i].x, point[i].y, mpx[point[i].x], mpy[point[i].y]);		
	}
	//////////////////
	//printf("\n");
	d = max(abs(point[a].x - point[b].x), abs(point[a].y - point[b].y));
}

inline void prepare(){
	q.push(a); q.push(b);
	sx[mpx[point[a].x]].erase(point[a].y);
	sy[mpy[point[a].y]].erase(point[a].x);
	sx[mpx[point[b].x]].erase(point[b].y);
	sy[mpy[point[b].y]].erase(point[b].x);
	int t, shang, xia, zuo, you;
	set<int>::iterator iter;
	while(!q.empty()){
		t = q.front(); q.pop();	ld[++lpd] = t;
		shang = mpy[point[t].y + d]; xia = mpy[point[t].y - d];
		zuo = mpx[point[t].x - d]; you = mpx[point[t].x + d];
		//----------------
		//	printf("t = %d shang = %d xia = %d zuo = %d you = %d\n", t, shang, xia, zuo, you);
		//----------------
		if(shang){
			iter = sy[shang].lower_bound(point[t].x - d);
			while(iter != sy[shang].end()){
				if(*iter > point[t].x + d) break;
				int lin = dian[(lpl){mpx[*iter], shang}];
				q.push(lin); s.push(lin); ++iter;
			}
			while(!s.empty()){
				int now = s.top(); s.pop(); 
				int x = mpx[point[now].x], y = mpy[point[now].y];
				sx[x].erase(point[now].y); sy[y].erase(point[now].x);
			}
		}
		
		if(xia){
			iter = sy[xia].lower_bound(point[t].x - d);
			while(iter != sy[xia].end()){
				if(idx[*iter] > point[t].x + d) break;
				int lin = dian[(lpl){mpx[*iter], xia}];
				q.push(lin); s.push(lin); ++iter;
			}
			while(!s.empty()){
				int now = s.top(); s.pop(); 
				int x = mpx[point[now].x], y = mpy[point[now].y];
				sx[x].erase(point[now].y); sy[y].erase(point[now].x);
			}
		}
		
		if(zuo){
			iter = sx[zuo].lower_bound(point[t].y - d);
			while(iter != sx[zuo].end()){
				if(idy[*iter] > point[t].y + d) break;
				int lin = dian[(lpl){zuo, mpy[*iter]}];
				q.push(lin); s.push(lin); ++iter;				
			}
			while(!s.empty()){
				int now = s.top(); s.pop(); 
				int x = mpx[point[now].x], y = mpy[point[now].y];
				sx[x].erase(point[now].y); sy[y].erase(point[now].x);
			}
		}
		
		if(you){
			iter = sx[you].lower_bound(point[t].y - d);
			while(iter != sx[you].end()){
				if(idy[*iter] > point[t].y + d) break;
				int lin = dian[(lpl){you, mpy[*iter]}];
				q.push(lin); s.push(lin); ++iter;
			}
			while(!s.empty()){
				int now = s.top(); s.pop(); 
				int x = mpx[point[now].x], y = mpy[point[now].y];
				sx[x].erase(point[now].y); sy[y].erase(point[now].x);
			}			
		}
	}
}

inline void check(){
	for(int i = 1; i <= lpd; ++i) printf("%d ", ld[i]);
}

long long ans = 0;
vector<int> X[maxn], Y[maxn];
set<int> xxx, yyy;

inline void workk(){
	int xi, yi;
	for(int i = 1; i <= lpd; ++i){
		xi = mpx[point[ld[i]].x]; yi = mpy[point[ld[i]].y];
		X[xi].push_back(point[ld[i]].y); Y[yi].push_back(point[ld[i]].x);
		xxx.insert(xi); yyy.insert(yi);
	}
	set<int>::iterator iter;
	for(iter = xxx.begin(); iter != xxx.end(); ++iter) sort(X[*iter].begin(), X[*iter].end());
	for(iter = yyy.begin(); iter != yyy.end(); ++iter) sort(Y[*iter].begin(), Y[*iter].end());
	int t, shang, xia, zuo, you;
	//////////////////
//	printf("xxx\n");
//	for(iter = xxx.begin(); iter != xxx.end(); ++iter){
//		int now = *iter; printf("now = %d\n", now);
//		for(int i = X[now].size() - 1; i >= 0; --i) printf("%d ", X[now][i]);
//		printf("\n");
//	}
//	printf("yyy\n");
//	for(iter = yyy.begin(); iter != yyy.end(); ++iter){
//		int now = *iter; printf("now = %d\n", now);
//		for(int i = Y[now].size() - 1; i >= 0; --i) printf("%d ", Y[now][i]);
//		printf("\n");
//	}
	//////////////////
	for(int i = 1; i <= lpd; ++i){
		t = ld[i];
		shang = mpy[point[t].y + d]; xia = mpy[point[t].y - d];
		zuo = mpx[point[t].x - d]; you = mpx[point[t].x + d];
		
	//	printf("t = %d shang = %d xia = %d zuo = %d you = %d\n", t, shang, xia, zuo, you);
		
		if(shang) 
			ans += upper_bound(Y[shang].begin(), Y[shang].end(), point[t].x + d) - lower_bound(Y[shang].begin(), Y[shang].end(), point[t].x - d);
		if(xia) 
			ans += upper_bound(Y[xia].begin(), Y[xia].end(), point[t].x + d) - lower_bound(Y[xia].begin(), Y[xia].end(), point[t].x - d);
		if(zuo) 
			ans += upper_bound(X[zuo].begin(), X[zuo].end(), point[t].y + d) - lower_bound(X[zuo].begin(), X[zuo].end(), point[t].y - d);
		if(you) 
			ans += upper_bound(X[you].begin(), X[you].end(), point[t].y + d) - lower_bound(X[you].begin(), X[you].end(), point[t].y - d);
		if(dian[(lpl){zuo, shang}]) ans--;
		if(dian[(lpl){you, shang}]) ans--;
		if(dian[(lpl){zuo, xia}]) ans--;
		if(dian[(lpl){you, xia}]) ans--;
	}
	cout << ans / 2;
}

int main()
{
	//freopen("lpl.in", "r", stdin);
	putit();
	prepare();
	//check();
	workk();
	return 0;
}