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# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        int N = Reader.Int(), A = Reader.Int() - 1, B = Reader.Int() - 1;
        var P = Reader.IntTable(N).Select(a => new[] { a[0] + a[1], a[0] - a[1] }).ToArray();
        long D = Math.Max(Math.Abs(P[A][0] - P[B][0]), Math.Abs(P[A][1] - P[B][1]));
        var uf = new UnionFind(N);
        var deg = new long[N];
        Calc(P, D, uf, deg, 0);
        foreach (var p in P) Swap(ref p[0], ref p[1]);
        Calc(P, D, uf, deg, 1);
        long ans = deg.Where((d, i) => uf.Same(i, A)).Sum() / 2;
        Console.WriteLine(ans);
    }

    void Calc(int[][] P, long D, UnionFind uf, long[] deg, int offset)
    {
        var dic = new Dictionary<long, List<Point>>();
        for (int i = 0; i < P.Length; i++)
            AddDic(dic, P[i][0], new Point(P[i][1], i));
        foreach (var a in dic.Values) a.Sort();

        for (int i = 0; i < P.Length; i++)
            for (long dx = -D; dx <= D; dx += D * 2)
            {
                long x = P[i][0] + dx, y = P[i][1];
                if (!dic.ContainsKey(x)) continue;
                int a = LowerBound(dic[x], new Point(y - D + offset, 0));
                int b = LowerBound(dic[x], new Point(y + D - offset + 1, 0));
                deg[i] += b - a;
                if (a < b) uf.Unite(i, dic[x][a].id);
            }
    }

    struct Point : IComparable<Point>
    {
        public long p;
        public int id;
        public Point(long p, int id)
        {
            this.p = p;
            this.id = id;
        }
        public int CompareTo(Point other)
        {
            return p != other.p ? Math.Sign(p - other.p) : id - other.id;
        }
        public override string ToString()
        {
            return "p:" + p + " id:" + id;
        }
    }

    static void Swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; }

    void AddDic(Dictionary<long, List<Point>> dic, long key, Point val)
    {
        if (!dic.ContainsKey(key)) dic[key] = new List<Point>();
        dic[key].Add(val);
    }

    static int LowerBound(List<Point> A, Point val, int L = 0, int R = -1)
    {
        if (R == -1) R = A.Count;
        while (R - L >= 1)
        {
            int mid = (L + R) / 2;
            if (A[mid].CompareTo(val) >= 0) R = mid;
            else L = mid + 1;
        }
        return R;
    }
}

class UnionFind
{
    private int[] parent;
    private int[] rank;

    public UnionFind(int N)
    {
        parent = new int[N];
        rank = new int[N];
        for (int i = 0; i < N; i++)
            parent[i] = i;
    }
    public int Root(int x)
    {
        if (parent[x] == x) return x;
        return parent[x] = Root(parent[x]);
    }
    public bool Same(int x, int y)
    {
        return Root(x) == Root(y);
    }
    public bool Unite(int x, int y)
    {
        x = Root(x); y = Root(y);
        if (x == y) return false;
        if (rank[x] > rank[y]) { var t = x; x = y; y = t; }
        if (rank[x] == rank[y]) rank[y]++;
        parent[x] = y;
        return true;
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}