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 5.4.1) (judge verdict: Runtime Error)

#include <stdio.h>
#include <stdlib.h>
#define int long long
#define max_pair_size 100000000

typedef struct {
	int num;
	int x;
	int y;
}pos;

typedef struct {
	int a;
	int b;
}pair;

pair e[max_pair_size];

#define ms_valtype pos

//比較関数
int compare_ms_xpy(ms_valtype a, ms_valtype b){
	if(a.x + a.y == b.x + b.y){
		return a.x - b.x;
	}
	else{
		return (a.x + a.y) - (b.x + b.y);
	}
}

int compare_ms_xmy(ms_valtype a, ms_valtype b){
	if(a.x - a.y == b.x - b.y){
		return a.x - b.x;
	}
	else{
		return (a.x - a.y) - (b.x - b.y);
	}
}

//昇順
void sort_sub(ms_valtype *origin, int left, int right, ms_valtype *tmp, int (*compare_ms)(ms_valtype a, ms_valtype b)){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp, compare_ms);
		sort_sub(origin, half, right, tmp, compare_ms);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare_ms(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(ms_valtype *origin, int N, int (*compare_ms)(ms_valtype a, ms_valtype b)){
	ms_valtype *tmp = (ms_valtype *)malloc(sizeof(ms_valtype) * N);
	sort_sub(origin, 0, N, tmp, compare_ms);
	free(tmp);
}

typedef struct {
	int N;
	int *u;
	int *u_rank;
}union_find;

union_find *make_union_find(int N){
	int i;
	union_find *uf = (union_find *)malloc(sizeof(union_find));
	uf->N = N;
	uf->u = (int *)malloc(sizeof(int) * N);
	uf->u_rank = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		(uf->u)[i] = i;
		(uf->u_rank)[i] = 1;
	}
	return uf;
}

int root_uf(int x, union_find *uf){
	int *u = uf->u;
	if(u[x] == x){
		return x;
	}
	else{
		u[x] = root_uf(u[x], uf);
		return u[x];
	}
}

void combine_uf(int x, int y, union_find *uf){
	int x_root = root_uf(x, uf);
	int y_root = root_uf(y, uf);
	int *u = uf->u;
	int *u_rank = uf->u_rank;
	if(x_root == y_root){
		return;
	}
	else if(u_rank[x_root] < u_rank[y_root]){
		u[x_root] = y_root;
		u_rank[y_root] += u_rank[x_root];
		u_rank[x_root] = 0;
	}
	else{
		u[y_root] = x_root;
		u_rank[x_root] += u_rank[y_root];
		u_rank[y_root] = 0;
	}
}

//xとyが同じ集合に属していれば1を,そうでなければ0を返す
int is_same_union_uf(int x, int y, union_find *uf){
	if(root_uf(x, uf) == root_uf(y, uf)){
		return 1;
	}
	else{
		return 0;
	}
}

//xが属する集合の要素数を返す
int rank_uf(int x, union_find *uf){
	return (uf->u_rank)[root_uf(x, uf)];
}

int ABS(int a){
	return a >= 0 ? a : -a;
}

int dis(pos a, pos b){
	return ABS(a.x - b.x) + ABS(a.y - b.y);
}

signed main(){
	int N, a, b, d, i, j, k;
	scanf("%lld%lld%lld", &N, &a, &b);
	a--;
	b--;
	pos *ps = (pos *)malloc(sizeof(pos) * N);
	for(i = 0; i < N; i++){
		ps[i].num = i;
		scanf("%lld%lld", &ps[i].x, &ps[i].y);
	}
	d = dis(ps[a], ps[b]);
	union_find *uf = make_union_find(N);
//	pair *e = (pair *)malloc(sizeof(pair) * max_pair_size);
	k = 0;
	int l, h, r;
	pos p1, p2;

	sort(ps, N, compare_ms_xpy);
/*	for(i = 0; i < N; i++){
		printf("%d ", ps[i].num);
	}
	printf("\n");
*/	for(i = 0; i < N; i++){
//		printf("i = %d\n", i);
		p1.x = ps[i].x - d;
		p1.y = ps[i].y;
		p2.x = ps[i].x;
		p2.y = ps[i].y - d;
		l = -1;
		r = N;
		while(r - l > 1){
			h = (l + r) / 2;
			if(compare_ms_xpy(ps[h], p1) < 0){
				l = h;
			}
			else{
				r = h;
			}
		}
//		printf("r = %d\n", r);
		for(j = r; j < N; j++){
			if(compare_ms_xpy(ps[j], p2) <= 0){
//				printf("(ps[i].num, ps[j].num) = (%d, %d)\n", ps[i].num, ps[j].num);
				combine_uf(ps[i].num, ps[j].num, uf);
				e[k].a = ps[i].num;
				e[k].b = ps[j].num;
				k++;
			}
			else{
				break;
			}
		}
	}

	sort(ps, N, compare_ms_xmy);
/*	for(i = 0; i < N; i++){
		printf("%d ", ps[i].num);
	}
	printf("\n");
*/	for(i = 0; i < N; i++){
//		printf("i = %d\n", i);
		p1.x = ps[i].x - d + 1;
		p1.y = ps[i].y + 1;
		p2.x = ps[i].x - 1;
		p2.y = ps[i].y + d - 1;
		l = -1;
		r = N;
		while(r - l > 1){
			h = (l + r) / 2;
			if(compare_ms_xmy(ps[h], p1) < 0){
				l = h;
			}
			else{
				r = h;
			}
		}
//		printf("r = %d\n", r);
		for(j = r; j < N; j++){
			if(compare_ms_xmy(ps[j], p2) <= 0){
//				printf("(ps[i].num, ps[j].num) = (%d, %d)\n", ps[i].num, ps[j].num);
				combine_uf(ps[i].num, ps[j].num, uf);
				e[k].a = ps[i].num;
				e[k].b = ps[j].num;
				k++;
			}
			else{
				break;
			}
		}
	}

	int ans = 0;
//	printf("k = %d\n", k);
	for(i = 0; i < k; i++){
//		printf("(a, b) = (%d, %d)\n", e[i].a, e[i].b);
		if(is_same_union_uf(a, e[i].a, uf) == 1){
//			printf("test3\n");
			ans++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}