Problem:
Score : 500 points

Problem Statement

There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate.
What is the maximum possible Manhattan distance between two distinct points?

Here, the Manhattan distance between two points (x_i, y_i) and (x_j, y_j) is defined by |x_i-x_j| + |y_i-y_j|.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq x_i,y_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
:
x_N y_N

Output

Print the answer.

Sample Input 1

3
1 1
2 4
3 2

Sample Output 1

4

The Manhattan distance between the first point and the second point is |1-2|+|1-4|=4, which is maximum possible.

Sample Input 2

2
1 1
1 1

Sample Output 2

0

Solution in Rust (1.42.0) (judge verdict: Time Limit Exceeded)

use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn cross(a: (i64, i64), b: (i64, i64), c: (i64, i64), d: (i64, i64)) -> i64 {
    return (b.0 - a.0) * (d.1 - c.1) - (b.1 - a.1) * (d.0 - c.0);
}

fn covex_hull(ps: &[(i64, i64)]) -> Vec<(i64, i64)> {
    let mut qs: Vec<(i64, i64)> = vec![];
    let n: usize = ps.len();
    for p in ps {
        while qs.len() > 1 && cross(qs[qs.len() - 1], qs[qs.len() - 2], qs[qs.len() - 1], *p) >= 0 {
            qs.pop();
        }
        qs.push(*p);
    }
    let t = qs.len();
    for i in (0..=n - 2).rev() {
        let p = ps[i];
        while qs.len() > t && cross(qs[qs.len() - 1], qs[qs.len() - 2], qs[qs.len() - 1], p) >= 0 {
            qs.pop();
        }
        qs.push(p);
    }
    return qs;
}

fn dist(a: (i64, i64), b: (i64, i64)) -> i64 {
    return (a.0 - b.0).abs() + (a.1 - b.1).abs();
}

fn rotating_calipers(ps: &Vec<(i64, i64)>) -> i64 {
    let qs = covex_hull(ps);
    let n = qs.len();
    if n == 2 {
        return dist(qs[0], qs[1]);
    }

    let mut i: usize = 0;
    let mut j: usize = 0;
    for k in 0..n {
        if qs[k] < qs[i] {
            i = k;
        }
        if qs[j] < qs[k] {
            j = k;
        }
    }
    let mut res: i64 = 0;
    let si = i;
    let sj = j;
    while i != sj || j != si {
        res = cmp::max(res, dist(qs[i], qs[j]));
        let x: i64 = i as i64 - n as i64 + 1;
        let x: usize = if x < 0 {
            (x + qs.len() as i64) as usize
        } else {
            x as usize
        };

        let y: i64 = j as i64 - n as i64 + 1;
        let y: usize = if y < 0 {
            (y + qs.len() as i64) as usize
        } else {
            y as usize
        };

        if cross(qs[i], qs[x], qs[j], qs[y]) < 0 {
            //if cross(qs[i], qs[i - n + 1], qs[j], qs[j - n + 1]) < 0 {
            i = (i + 1) % n;
        } else {
            j = (j + 1) % n;
        }
    }

    return res;
}

fn main() {
    let n: usize = read_as_vec()[0];
    let mut ps: Vec<(i64, i64)> = vec![];
    for _ in 0..n {
        let line: Vec<i64> = read_as_vec();
        ps.push((line[0], line[1]));
    }

    ps.sort();
    ps.dedup();
    if ps.len() == 1 {
        println!("0");
        return;
    }
    let ans = rotating_calipers(&ps);
    println!("{}", ans);
}