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 Rust (1.42.0) (judge verdict: Accepted)

use core::ops::Bound::Excluded;
use core::ops::Bound::Included;
use std::collections::BTreeSet;
use std::cmp::Ordering;
use std::fmt::Debug;

fn read_line() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("No Line");
    buffer
}
fn read_lines<R, T: Fn(&str)->R> (count: usize, transformer: T) -> Vec<R> {
    let mut buffer = String::new();
    let mut vec = Vec::with_capacity(count);
    for _ in 0 .. count {
        std::io::stdin().read_line(&mut buffer).expect("No Line");
        vec.push(transformer(buffer.trim()));
        buffer.clear();
    }
    vec
}
fn read_value<T: std::str::FromStr>() -> T {
    read_line().trim().parse().ok().unwrap()
}
fn read_values<T: std::str::FromStr>() -> Vec<T> {
    read_line().trim().split(' ').map(|x| x.parse().ok().expect("Can't Parse")).collect::<Vec<T>>()
}
fn read_tabulate<T: std::str::FromStr>(count: usize) -> Vec<T> {
    let mut buffer = String::new();
    let mut vec = Vec::with_capacity(count);
    for _ in 0 .. count {
        std::io::stdin().read_line(&mut buffer).expect("No Line");
        vec.push(buffer.trim().parse().ok().expect("Can't Parse"));
        buffer.clear();
    }
    vec
}
macro_rules! define {
    () => {};
    ($($token:tt)*) => {
        let mut iter = read_values::<String>().into_iter();
        define_iter!(iter, $($token)*);
    };
}
macro_rules! define_iter {
    ($iter:expr) =>{};
    ($iter:expr,) =>{};
    ($iter:expr, $id:ident:$t:tt $($tail:tt)*) => {
        let $id: $t = $iter.next().unwrap().parse().ok().expect("Can't Parse");
        define_iter!($iter, $($tail)*);
    };
    ($iter:expr, mut $id:ident:$t:tt $($tail:tt)*) => {
        let mut $id: $t = $iter.next().unwrap().parse().ok().expect("Can't Parse");
        define_iter!($iter, $($tail)*)
    };
}
macro_rules! freeze {
    ($($id:ident), *) => {
        $(let $id = $id;)*
    };
}
struct KeyValue<K, V> {
    key: K,
    value: V
}
impl <K: PartialOrd, V> PartialEq for KeyValue<K, V> {
    fn eq(&self, other: &Self) -> bool {
        self.key.eq(&other.key)
    }
}
impl <K: PartialOrd, V> Eq for KeyValue<K, V> {}
impl <K: PartialOrd, V> PartialOrd for KeyValue<K, V> {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        self.key.partial_cmp(&other.key)
    }
}
impl <K: PartialOrd, V> Ord for KeyValue<K, V> {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        self.key.partial_cmp(&other.key).ok_or("Can't Compare").unwrap()
    }
}
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
struct Coordinate {
    x: i32, y: i32
}
impl Coordinate {
    fn intercept45(&self) -> i32 {
        self.y - self.x
    }
    fn intercept135(&self) -> i32 {
        self.y + self.x
    }
    fn manhattan_distance(&self, that: &Coordinate) -> i32 {
        (self.x - that.x).abs() + (self.y - that.y).abs()
    }
}
fn lower_bound<T, F: Fn(&T) -> bool>(array: &Vec<T>, predicate: F) -> usize {
    let mut min = 0usize;
    let mut max = array.len();
    while min < max {
        let mid = (min + max) >> 1;
        if predicate(&array[mid]) {
            min = mid + 1;
        }else {
            max = mid;
        }
    }
    max
}
fn lower_bound_with_range<T, F: Fn(&T) -> bool> (array: &Vec<T>, mut from: usize, mut until: usize, predicate: F) -> usize {
    while from < until {
        let mid = (from + until) >> 1;
        if predicate(&array[mid]) {
            from = mid + 1;
        }else {
            until = mid;
        }
    }
    until
}
struct Range {
    from: usize, until: usize
}
fn up(base: Coordinate, distance: i32, vec: &Vec<usize>, holes: &Vec<Coordinate>) -> Range {
    let lower_i = lower_bound(&vec, |&i| holes[i].intercept45() < base.intercept45() + distance);
    let upper_i = lower_bound(&vec, |&i| holes[i].intercept45() <= base.intercept45() + distance);
    let lower_x = lower_bound_with_range(&vec, lower_i, upper_i, |&i| holes[i].x + distance < base.x);
    let upper_x = lower_bound_with_range(&vec, lower_x, upper_i, |&i| holes[i].x <= base.x);
    Range{from: lower_x, until: upper_x}
}
fn right(base: Coordinate, distance: i32, vec: &Vec<usize>, holes: &Vec<Coordinate>) -> Range {
    let lower_i = lower_bound(&vec, |&i| holes[i].intercept135() - distance < base.intercept135());
    let upper_i = lower_bound(&vec, |&i| holes[i].intercept135() - distance <= base.intercept135());
    let lower_x = lower_bound_with_range(&vec, lower_i, upper_i, |&i| holes[i].x <= base.x);
    let upper_x = lower_bound_with_range(&vec, lower_x, upper_i, |&i| holes[i].x < base.x + distance);
    Range{from: lower_x, until: upper_x}
}
fn down(base: Coordinate, distance: i32, vec: &Vec<usize>, holes: &Vec<Coordinate>) -> Range {
    let lower_i = lower_bound(&vec, |&i| holes[i].intercept45() < base.intercept45() - distance);
    let upper_i = lower_bound(&vec, |&i| holes[i].intercept45() <= base.intercept45() - distance);
    let lower_x = lower_bound_with_range(&vec, lower_i, upper_i, |&i| holes[i].x < base.x);
    let upper_x = lower_bound_with_range(&vec, lower_x, upper_i, |&i| holes[i].x <= base.x + distance);
    Range{from: lower_x, until: upper_x}
}
fn left(base: Coordinate, distance: i32, vec: &Vec<usize>, holes: &Vec<Coordinate>) -> Range {
    let lower_i = lower_bound(&vec, |&i| holes[i].intercept135() < base.intercept135() - distance);
    let upper_i = lower_bound(&vec, |&i| holes[i].intercept135() <= base.intercept135() - distance);
    let lower_x = lower_bound_with_range(&vec, lower_i, upper_i, |&i| holes[i].x + distance <= base.x);
    let upper_x = lower_bound_with_range(&vec, lower_x, upper_i, |&i| holes[i].x < base.x);
    Range{from: lower_x, until: upper_x}
}
fn move_to(from: usize, until: usize, map: &Vec<usize>, src: &mut BTreeSet<usize>, dst: &mut Vec<usize>) {
    for i in src.range((Included(from), Excluded(until))).copied().collect::<Vec<_>>() {
        dst.push(map[i]);
        src.remove(&i);
    }
}
fn neighbor(base: Coordinate, distance: i32, i45: &Vec<usize>, i135: &Vec<usize>, holes: &Vec<Coordinate>, i45_set: &mut BTreeSet<usize>, i135_set: &mut BTreeSet<usize>) -> (usize, Vec<usize>) {
    let mut result = Vec::new();
    let mut sum = 0usize;
    match up(base, distance, i45, holes) {
        Range{from, until} => {
            move_to(from, until, i45, i45_set, &mut result);
            sum += until - from;
        }
    }
    match down(base, distance, i45, holes) {
        Range{from, until} => {
            move_to(from, until, i45, i45_set, &mut result);
            sum += until - from;
        }
    }
    match right(base, distance, i135, holes) {
        Range{from, until} => {
            move_to(from, until, i135, i135_set, &mut result);
            sum += until - from;
        }
    }
    match left(base, distance, i135, holes) {
        Range{from, until} => {
            move_to(from, until, i135, i135_set, &mut result);
            sum += until - from;
        }
    }
    (sum, result)
}
fn main() {
    define! {
        n: usize
        a: usize
        b: usize
    }
    let mut holes = Vec::with_capacity(n);
    for _ in 0 .. n {
        define! {
            x: i32
            y: i32
        }
        holes.push(Coordinate{x, y});
    }
    let mut intercept45 = (0 .. n).collect::<Vec<_>>();
    intercept45.sort_by(|&i, &j| holes[i].intercept45().cmp(&holes[j].intercept45()).then(holes[i].x.cmp(&holes[j].x)));
    let mut intercept135 = (0 .. n).collect::<Vec<_>>();
    intercept135.sort_by(|&i, &j| holes[i].intercept135().cmp(&holes[j].intercept135()).then(holes[i].x.cmp(&holes[j].x)));
    let mut in_stack = vec![false; n];
    let mut stack = Vec::new();
    in_stack[a - 1] = true; in_stack[b - 1] = true;
    stack.push(a - 1); stack.push(b - 1);
    let distance = holes[a - 1].manhattan_distance(&holes[b - 1]);
    let mut result = 0usize;
    let mut i45_set = (0 .. n).collect::<BTreeSet<_>>();
    let mut i135_set = i45_set.clone();
    while let Some(top) = stack.pop() {
        let (count, next) = neighbor(holes[top], distance, &intercept45, &intercept135, &holes, &mut i45_set, &mut i135_set);
        //println!("top: {}, count: {}, next: {:?}", top, count, next);
        result += count;
        for i in next {
            if !in_stack[i] {
                in_stack[i] = true;
                stack.push(i);
            }
        }
    }
    println!("{}", result >> 1);
}