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 Java8 (OpenJDK 1.8.0) (judge verdict: Time Limit Exceeded)

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.SynchronousQueue;

public class Main {
	public static void main(String[] args) {
		new Main().solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		--a;
		--b;
		long[] x = new long[n];
		long[] y = new long[n];
		ArrayList<Point> ps = new ArrayList<>();
		for (int i = 0; i < n; ++i) {
			x[i] = sc.nextLong();
			y[i] = sc.nextLong();
			ps.add(new Point(x[i] + y[i], x[i] - y[i], i));
		}
		long D = Math.abs(x[a] - x[b]) + Math.abs(y[a] - y[b]);
		int[] cnt = new int[n];
		DJSet ds = new DJSet(n);
		for (int dir = 0; dir < 2; ++dir) {
			Collections.sort(ps);
			int[] cum = new int[2 * n];
			for (int i = 0; i < n; ++i) {
				pre(ps, ps.get(i), D, cnt, cum, ds, dir);

			}
			for (int i = 1; i < cum.length; ++i) {
				cum[i] += cum[i - 1];
			}
//			for (int i = 0; i < n; ++i) {
//				if (i + 1 < n && cum[2 * i] > 0 && cum[2 * i + 1] > 0) {
//					ds.setUnion(i, i + 1);
//				}
//				if (i > 0 && cum[2 * i - 1] > 0 && cum[2 * i] > 0) {
//					ds.setUnion(i, i - 1);
//				}
//			}
			for (int i = 0; i < n; ++i) {
				ps.get(i).rotate();
			}
		}

		long ans = 0;
		for (int i = 0; i < n; ++i) {
			if (ds.equiv(i, a)) {
				ans += cnt[i];
			}
		}
		System.out.println(ans / 2);
	}

	void pre(ArrayList<Point> list, Point p, long D, int[] cnt, int[] cum, DJSet ds, int dir) {
		{
			int r = lower(list, new Point(p.x + D + 1 - (dir), p.y + D, -1));
			int l = lower(list, new Point(p.x - D + (dir), p.y + D, -1));
			cnt[p.id] += r - l;
			if (r > l) {
				for(int i=r;i>l;--i){
					ds.setUnion(p.id, list.get(i).id);
				}
				if (2 * (l + 1) + 1 < cum.length)
					++cum[2 * (l + 1) + 1];
				if (2 * r < cum.length)
					--cum[2 * r];
				ds.setUnion(p.id, list.get(r).id);
			}

		}
		{
			int r = lower(list, new Point(p.x + D + 1 - (dir), p.y - D, -1));
			int l = lower(list, new Point(p.x - D + (dir), p.y - D, -1));
			cnt[p.id] += r - l;
			if (r > l) {
				for(int i=r;i>l;--i){
					ds.setUnion(p.id, list.get(i).id);
				}
				if (2 * (l + 1) + 1 < cum.length)
					++cum[2 * (l + 1) + 1];
				if (2 * r < cum.length)
					--cum[2 * r];
				ds.setUnion(p.id, list.get(r).id);
			}
		}
		return;
	}

	int lower(ArrayList<Point> list, Point p) {
		// 0 0 1 1 2 3
		// p = 1 の時 1の隣の0を返したい

		int ok = -1, ng = list.size();
		while (ng - ok > 1) {
			int middle = (ok + ng) / 2;
			if (list.get(middle).compareTo(p) < 0) {
				ok = middle;
			} else {
				ng = middle;
			}
		}
		return ok;
	}

	class Point implements Comparable<Point> {
		long x, y;
		int id;

		public Point(long x_, long y_, int id_) {
			x = x_;
			y = y_;
			id = id_;
		}

		void rotate() {
			long d = x;
			x = y;
			y = d;
		}

		@Override
		public int compareTo(Point o) {
			if (y != o.y) {
				return Long.compare(y, o.y);
			} else {
				return Long.compare(x, o.x);
			}
		}
	}

	class DJSet {
		int n;
		int[] upper;

		public DJSet(int n_) {
			n = n_;
			upper = new int[n];
			Arrays.fill(upper, -1);
		}

		int root(int x) {
			return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
		}

		boolean equiv(int x, int y) {
			return root(x) == root(y);
		}

		void setUnion(int x, int y) {
			x = root(x);
			y = root(y);
			if (x == y)
				return;
			if (upper[x] < upper[y]) {
				int d = x;
				x = y;
				y = d;
			}
			upper[y] += upper[x];
			upper[x] = y;
		}
	}

	public static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}