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<set>
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 200000;
const int INF = 1000000000;
struct node{
	long long x, y;
	int id;
}pnt[MAXN + 5];
struct node1{
	long long key; int id;
	node1(long long k, int i):key(k), id(i){}
};
bool operator < (node1 a, node1 b) {
	return a.key < b.key;
}
long long p[2*MAXN + 5]; int pcnt = 0;
set<node1>sx[2*MAXN + 5], sy[2*MAXN + 5];
vector<long long>s1[2*MAXN + 5], s2[2*MAXN + 5];
set<node1>::iterator it1, it2;
int GetX(int x, int y) {
	return (x + y) / 2;
}
int GetY(int x, int y) {
	return (y - x) / 2;
}
int main() {
	int N, a, b;
	scanf("%d%d%d", &N, &a, &b);
	for(int i=1;i<=N;i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		pnt[i].x = x - y, pnt[i].y = x + y;
		p[++pcnt] = pnt[i].x, p[++pcnt] = pnt[i].y;
		pnt[i].id = i;
	}
	int dis = abs(GetX(pnt[a].x, pnt[a].y) - GetX(pnt[b].x, pnt[b].y)) + abs(GetY(pnt[a].x, pnt[a].y) - GetY(pnt[b].x, pnt[b].y));
	sort(p+1, p+pcnt+1);
	pcnt = unique(p+1, p+pcnt+1) - p - 1;
	for(int i=1;i<=N;i++) {
		pnt[i].x = lower_bound(p+1, p+pcnt+1, pnt[i].x) - p;
		pnt[i].y = lower_bound(p+1, p+pcnt+1, pnt[i].y) - p;
		sx[pnt[i].x].insert(node1(p[pnt[i].y], i));
		sy[pnt[i].y].insert(node1(p[pnt[i].x], i));
		s1[pnt[i].x].push_back(p[pnt[i].y]);
		s2[pnt[i].y].push_back(p[pnt[i].x]);
	}
	for(int i=0;i<=2*MAXN;i++) {
		s1[i].push_back(INF+INF+5); s1[i].push_back(-INF-INF-5);
		s2[i].push_back(INF+INF+5); s2[i].push_back(-INF-INF-5);
		s1[i].push_back(INF+INF+5); s1[i].push_back(-INF-INF-5);
		s2[i].push_back(INF+INF+5); s2[i].push_back(-INF-INF-5);
		sort(s1[i].begin(), s1[i].end());
		sort(s2[i].begin(), s2[i].end());
		sx[i].insert(node1(INF+INF+5, 1)); sx[i].insert(node1(-INF-INF-5, 1));
		sy[i].insert(node1(INF+INF+5, 1)); sy[i].insert(node1(-INF-INF-5, 1));
		sx[i].insert(node1(INF+INF+5, 1)); sx[i].insert(node1(-INF-INF-5, 1));
		sy[i].insert(node1(INF+INF+5, 1)); sy[i].insert(node1(-INF-INF-5, 1));
	}
	queue<int>que; que.push(a); que.push(b);
	sx[pnt[a].x].erase(node1(p[pnt[a].y], a)); sy[pnt[a].y].erase(node1(p[pnt[a].x], a));
	sx[pnt[b].x].erase(node1(p[pnt[b].y], b)); sy[pnt[b].y].erase(node1(p[pnt[b].x], b));
	long long ans = 0;
	while( !que.empty() ) {
		int f = que.front(); que.pop();
		long long *q = lower_bound(p+1, p+pcnt+1, p[pnt[f].x]+dis);
		if( q-p != pcnt+1 && *q == p[pnt[f].x]+dis ) {
			int r = q - p;
			ans += upper_bound(s1[r].begin(), s1[r].end(), p[pnt[f].y]+dis) - lower_bound(s1[r].begin(), s1[r].end(), p[pnt[f].y]-dis);
			while( !sx[r].empty() && sx[r].lower_bound(node1(p[pnt[f].y]-dis, 1))->key <= p[pnt[f].y]+dis ) {
				que.push(sx[r].lower_bound(node1(p[pnt[f].y]-dis, 1))->id);
				it1 = sx[r].lower_bound(node1(p[pnt[f].y]-dis, 1));
				if( sy[pnt[it1->id].y].count(node1(p[pnt[it1->id].x], it1->id)) )
					sy[pnt[it1->id].y].erase(node1(p[pnt[it1->id].x], it1->id));
				sx[r].erase(it1);
			}
		}
		q = lower_bound(p+1, p+pcnt+1, p[pnt[f].x]-dis);
		if( q-p != pcnt+1 && *q == p[pnt[f].x]-dis ) {
			int r = q - p;
			ans += upper_bound(s1[r].begin(), s1[r].end(), p[pnt[f].y]+dis) - lower_bound(s1[r].begin(), s1[r].end(), p[pnt[f].y]-dis);
			while( !sx[r].empty() && sx[r].lower_bound(node1(p[pnt[f].y]-dis, 1))->key <= p[pnt[f].y]+dis ) {
				que.push(sx[r].lower_bound(node1(p[pnt[f].y]-dis, 1))->id);
				it1 = sx[r].lower_bound(node1(p[pnt[f].y]-dis, 1));
				if( sy[pnt[it1->id].y].count(node1(p[pnt[it1->id].x], it1->id)) )
					sy[pnt[it1->id].y].erase(node1(p[pnt[it1->id].x], it1->id));
				sx[r].erase(it1);
			}
		}
		q = lower_bound(p+1, p+pcnt+1, p[pnt[f].y]+dis);
		if( q-p != pcnt+1 && *q == p[pnt[f].y]+dis ) {
			int r = q - p;
			ans += upper_bound(s2[r].begin(), s2[r].end(), p[pnt[f].x]+dis) - lower_bound(s2[r].begin(), s2[r].end(), p[pnt[f].x]-dis);
			if( *lower_bound(s2[r].begin(), s2[r].end(), p[pnt[f].x]-dis) == p[pnt[f].x]-dis ) {
				it1 = lower_bound(sy[r].begin(), sy[r].end(), node1(p[pnt[f].x]-dis, 1) );
				if( sx[pnt[it1->id].x].count(node1(p[pnt[it1->id].y], it1->id)) )
					sx[pnt[it1->id].x].erase(node1(p[pnt[it1->id].y], it1->id));
				sy[r].erase(it1);
				ans--;
			}
			if( *lower_bound(s2[r].begin(), s2[r].end(), p[pnt[f].x]+dis) == p[pnt[f].x]+dis ) {
				it1 = lower_bound(sy[r].begin(), sy[r].end(), node1(p[pnt[f].x]+dis, 1) );
				if( sx[pnt[it1->id].x].count(node1(p[pnt[it1->id].y], it1->id)) )
					sx[pnt[it1->id].x].erase(node1(p[pnt[it1->id].y], it1->id));
				sy[r].erase(it1);
				ans--;
			}
			while( !sy[r].empty() && sy[r].lower_bound(node1(p[pnt[f].x]-dis, 1))->key <= p[pnt[f].x]+dis ) {
				it1 = sy[r].lower_bound(node1(p[pnt[f].x]-dis, 1));
				if( it1->key != p[pnt[f].x]-dis && it1->key != p[pnt[f].x]+dis )
					que.push(sy[r].lower_bound(node1(p[pnt[f].x]-dis, 1))->id);
				if( sx[pnt[it1->id].x].count(node1(p[pnt[it1->id].y], it1->id)) )
					sx[pnt[it1->id].x].erase(node1(p[pnt[it1->id].y], it1->id));
				sy[r].erase(it1);
			}
		}
		q = lower_bound(p+1, p+pcnt+1, p[pnt[f].y]-dis);
		if( q-p != pcnt+1 && *q == p[pnt[f].y]-dis ) {
			int r = q - p;
			ans += upper_bound(s2[r].begin(), s2[r].end(), p[pnt[f].x]+dis) - lower_bound(s2[r].begin(), s2[r].end(), p[pnt[f].x]-dis);
			if( *lower_bound(s2[r].begin(), s2[r].end(), p[pnt[f].x]-dis) == p[pnt[f].x]-dis ) {
				it1 = lower_bound(sy[r].begin(), sy[r].end(), node1(p[pnt[f].x]-dis, 1) );
				if( sx[pnt[it1->id].x].count(node1(p[pnt[it1->id].y], it1->id)) )
					sx[pnt[it1->id].x].erase(node1(p[pnt[it1->id].y], it1->id));
				sy[r].erase(it1);
				ans--;
			}
			if( *lower_bound(s2[r].begin(), s2[r].end(), p[pnt[f].x]+dis) == p[pnt[f].x]+dis ) {
				it1 = lower_bound(sy[r].begin(), sy[r].end(), node1(p[pnt[f].x]+dis, 1) );
				if( sx[pnt[it1->id].x].count(node1(p[pnt[it1->id].y], it1->id)) )
					sx[pnt[it1->id].x].erase(node1(p[pnt[it1->id].y], it1->id));
				sy[r].erase(it1);
				ans--;
			}
			while( !sy[r].empty() && sy[r].lower_bound(node1(p[pnt[f].x]-dis, 1))->key <= p[pnt[f].x]+dis ) {
				it1 = sy[r].lower_bound(node1(p[pnt[f].x]-dis, 1));
				if( it1->key != p[pnt[f].x]-dis && it1->key != p[pnt[f].x]+dis )
					que.push(sy[r].lower_bound(node1(p[pnt[f].x]-dis, 1))->id);
				if( sx[pnt[it1->id].x].count(node1(p[pnt[it1->id].y], it1->id)) )
					sx[pnt[it1->id].x].erase(node1(p[pnt[it1->id].y], it1->id));
				sy[r].erase(it1);
			}
		}
	}
	printf("%lld\n", ans/2);
}