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: Accepted)

#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use std::collections::VecDeque;
use std::io::stdin;
use std::str::FromStr;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let mut sc = Scanner::new();
    let n = sc.next_usize();
    let mut xy = Vec::with_capacity(n);
    for i in 0..n {
        let x = sc.next_isize();
        let y = sc.next_isize();
        xy.push((x, y));
    }

    xy.sort();

    let mut k = 0;
    let mut qs = vec![(0, 0); n * 2];
    for i in 0..n {
        while k > 1
            && ((qs[k - 1].0 - qs[k - 2].0) * (xy[i].1 - qs[k - 1].1)
                - (xy[i].0 - qs[k - 1].0) * (qs[k - 1].1 - qs[k - 2].1))
                <= 0
        {
            k -= 1;
        }
        qs[k] = xy[i];
        k += 1;
    }
    
    let t = k;
    for i in (0..=(n - 2)).rev() {
        while k > t
            && ((qs[k - 1].0 - qs[k - 2].0) * (xy[i].1 - qs[k - 1].1)
                - (xy[i].0 - qs[k - 1].0) * (qs[k - 1].1 - qs[k - 2].1))
                <= 0
        {
            k -= 1;
        }
        qs[k] = xy[i];
        k += 1;
    }
    qs.resize(k - 1, (0, 0));
    // eprintln!("{:?}", qs);
    
    
    let l = qs.len();
    let mut ans = 0;
    for i in 0..l {
        for j in i+1..l {
            let tmp = (qs[i].0-qs[j].0).abs() +(qs[i].1-qs[j].1).abs();
            ans = (ans).max(tmp);
        }
    }
    
    println!("{}", ans);
}

pub struct Scanner {
    buf: VecDeque<String>,
}

impl Scanner {
    pub fn new() -> Self {
        Self {
            buf: VecDeque::new(),
        }
    }

    fn scan_line(&mut self) {
        let mut flag = 0;
        while self.buf.is_empty() {
            let mut s = String::new();
            stdin().read_line(&mut s).unwrap();
            let mut iter = s.split_whitespace().peekable();
            if iter.peek().is_none() {
                if flag >= 5 {
                    panic!("There is no input!");
                }
                flag += 1;
                continue;
            }

            for si in iter {
                self.buf.push_back(si.to_string());
            }
        }
    }

    pub fn next<T: FromStr>(&mut self) -> T {
        self.scan_line();
        self.buf
            .pop_front()
            .unwrap()
            .parse()
            .unwrap_or_else(|_| panic!("Couldn't parse!"))
    }

    pub fn next_usize(&mut self) -> usize {
        self.next()
    }

    pub fn next_isize(&mut self) -> isize {
        self.next()
    }

    pub fn next_chars(&mut self) -> Vec<char> {
        self.next::<String>().chars().collect_vec()
    }

    pub fn next_string(&mut self) -> String {
        self.next()
    }

    pub fn fill_vec_line<T: FromStr>(&mut self, v: &mut Vec<T>) {
        for vi in v {
            *vi = self.next();
        }
    }

    pub fn fill_vec<T: FromStr>(&mut self, v: &mut Vec<Vec<T>>) {
        for vi in v {
            for vii in vi {
                *vii = self.next();
            }
        }
    }

    pub fn make_vec_line<T: FromStr + Default + Clone>(&mut self, i: usize) -> Vec<T> {
        let mut v = vec![Default::default(); i];
        self.fill_vec_line(&mut v);
        v
    }

    pub fn make_vec<T: FromStr + Default + Clone>(&mut self, i: usize, j: usize) -> Vec<Vec<T>> {
        let mut v = vec![vec![Default::default(); j]; i];
        self.fill_vec(&mut v);
        v
    }
}