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)

#pragma optimization_level 3
#include <bits/stdc++.h>
#define  f               first
#define  s               second
#define  sym(s)          s = "#" + s + "#";
#define  all(x)          (x).begin(), (x).end()
#define  alll(x,n)       x+1, x+n+1
#define  newl            cout<<"\n";
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.f<<" "<<a.s<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}

using namespace std;
using ll              =  long long;
using ld              =  long double;
const ll   MOD        =  1e+9 + 7;
const ll   INF        =  LLONG_MAX;
const int  N          =  (int)2e+5 + 8;

ll n, x[N], y[N];

void MAIN(int tc){
    cin >> n;\
    ll mnx, mxx, mny, mxy;
    mnx = mny = INF;
    mxx = mxy = -INF;
    for(int i = 1; i <= n; i++){
        cin >> x[i] >> y[i];
        mnx = min(mnx, x[i]);
        mxx = max(mxx, x[i]);
        mny = min(mny, y[i]);
        mxy = max(mxy, y[i]);
    }

    set<pair<ll,ll>> points;
    ll tmn, tmx;

    tmn = INF; tmx = -INF;
    for(int i = 1; i <= n; i++){
        if(x[i] == mnx){
            tmn = min(tmn, y[i]);
            tmx = max(tmx, y[i]);
        }
    }
    points.insert({mnx,tmn});
    points.insert({mnx,tmx});

    tmn = INF; tmx = -INF;
    for(int i = 1; i <= n; i++){
        if(x[i] == mxx){
            tmn = min(tmn, y[i]);
            tmx = max(tmx, y[i]);
        }
    }
    points.insert({mxx,tmn});
    points.insert({mxx,tmx});


    tmn = INF; tmx = -INF;
    for(int i = 1; i <= n; i++){
        if(y[i] == mny){
            tmn = min(tmn, x[i]);
            tmx = max(tmx, x[i]);
        }
    }
    points.insert({tmn, mny});
    points.insert({tmx, mny});

    tmn = INF; tmx = -INF;
    for(int i = 1; i <= n; i++){
        if(y[i] == mxy){
            tmn = min(tmn, x[i]);
            tmx = max(tmx, x[i]);
        }
    }
    points.insert({tmn, mxy});
    points.insert({tmx, mxy});

    ll res = 0;
    for(auto [x1,y1]: points){
        for(auto [x2, y2]: points){
            res = max(res, abs(x1 - x2) + abs(y1 - y2));
        }
    }

    deb1(res);


}

int main(){
    ios:: sync_with_stdio(false); 
    cin.tie(nullptr); cout.tie(nullptr);
    cout<<fixed; cout<<setprecision(10);

    int test_cases = 1;
    //cin>>test_cases;
    for(int i = 1; i <= test_cases; i++){
        MAIN(i);
    }
}