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 C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1000000000000
#define fr first
#define sc second
using vl =vector<ll>;
using vvl =vector<vl>;
const ll md = 1000000007;
vl fac(2,1), ifac(2,1);

ll ad(ll a, ll b, ll mod = md) {
    return (a%mod + b%mod + mod) % mod;
}

ll ml(ll a, ll b, ll mod = md) {
    return ( (a%mod) * (b%mod) ) % mod;
}

ll pw(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = (res*x)%mod;
        n = (n >> 1);
        x = (x*x)%mod;
    }
    return res;
}

void cachefact(ll lim, ll mod = md) {
    for(int i = 2; i <= lim; i++) {
        ifac.push_back((ifac[mod%i] * (mod - mod/i) % mod)%mod);
    }
    for(ll i = 2; i <= lim; i++) {
        fac.push_back((fac[i-1] * i)%mod);
        ifac[i] = (ifac[i-1] * ifac[i])%mod;
    }
}

ll C(ll n, ll r, ll mod = md) {
    if(n < r) return 0;
    return ml(fac[n], ml(ifac[r], ifac[n-r], mod), mod);
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	int n;
   	cin >> n;
   	vector<pair<ll,ll>> a(n);
   	for(int i = 0; i < n; ++i) {
   		cin >> a[i].fr >> a[i].sc;
   	}
   	sort(a.begin(), a.end());
   	vl diff(n), diff2(n);
   	diff[0] = a[0].sc - a[0].fr;
   	diff2[0] = a[0].fr + a[0].sc;
   	for(int i = 1; i < n; ++i) {
   		diff[i] = max(diff[i-1], a[i].sc - a[i].fr);
   		diff2[i] = min(diff2[i-1], a[i].fr + a[i].sc);
   	}
   	ll hi = 0;
   	for(int i = 0; i < n; ++i) {
   		hi = max(hi, a[i].fr + a[i].sc - diff2[i-1]);
   	}
   	for(int i = 1; i < n; ++i) {
   		hi =  max(hi, a[i].fr - a[i].sc + diff[i-1]);
   	}
   	cout << hi << "\n";
    return 0;
}