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<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ll long long
#define MOD 1000000007
#define ull unsigned long long int
#define db double
#define fi first
#define se second
#define pb push_back
#define vec vector<ll>
#define pr pair<ll,ll>
#define pq priority_queue<ll,vector<ll>, compare_queue >
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define repn(i,n) for(ll i=0;i<n;i++)
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define GS(s)   string s; getline(cin,s);
#define lll __int128_t
#define endl "\n"
#define Next cout.flush()

struct compare_queue
{
    bool operator()(const pair<ll,pr>& a, const pair<ll,pr>& b)
    {
        return a.fi < b.fi;
    }
};

ll gcd(ll u,ll v)
{
	if(v==0)
	return u;
	
	else
	return gcd(v,u%v);
}

// ll power(ll x,ll y) 
// { 
//     if (y == 0) 
//         return 1; 
//     ll p = power(x, y/2)%MOD; 
//     p = ((p%MOD) * (p%MOD))%MOD; 

//     return (y%2 == 0)? p%MOD : ((x%MOD) * (p%MOD))%MOD; 
// } 

    // ll power(ll x,ll y){
    //     ll i;
    //     ll ans=1;
    //     for(i=0;i<y;i++){
    //         ans=ans*x;
    //     }
    //     return ans;
    // }


// ll modInverse(int a, int m) 
// { 
//     if(a==1){return 1;}
//     return power(a, m-2, m); 
// } 
  



// // // #define MAX 1000000
// int primes[100009],cnt=0;
// // vector<int> factors[1000009];
// char str[1000009];
// void pre()
// {
//     // calcualting primes
//     int n=100000;
//     for(int i=2; i*i<=n; i++)
//         if(str[i]==0)
//             for(int j=i; j*i<=n; j++)
//                 str[i*j]=1;
//     for(int i=2; i<=n; i++)
//         if(str[i]==0)primes[cnt]=i,cnt++;
// }


// A O(log n) function returning primefactorization 
// by dividing by smallest prime factor at every step 
// vector<ll> getFactorization(ll x) 
// { 
//     vector<ll> ret; 
//     while (x != 1) 
//     { 
//         ret.push_back(spf[x]); 
//         x = x / spf[x]; 
//     } 
//     return ret; 
// } 

// C:\Users\A\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\lambda


// ll getPow(ll n,ll k){
//     double f=log((double)n);
//     double g=log((double)k);
//     f=f/g;
//     return (ll)f;
// }




void Function(){
ll n;
cin >> n;
ll x,y,i,ans=0;
vector<pr> a;
priority_queue<pair<ll,pr>,vector<pair<ll,pr> > ,compare_queue > q1,q2;
repn(i,n){
    cin >> x >> y;
    q1.push({x+y,{x,y}});
    a.pb({x,y});
}
sort(a.begin(),a.end());
for(i=0;i<a.size();i++){
    while(!q1.empty() && q1.top().se.fi < a[i].fi){
        pair<ll,pr> foo=q1.top();
        q1.pop();
        foo.fi=MOD-foo.se.fi+foo.se.se;
        q2.push(foo);
        }
        if(!q1.empty()){
            x=q1.top().se.fi;
                y=q1.top().se.se;
                ans=max(ans,abs(x-a[i].fi) + abs(y-a[i].se));
        }

                if(!q2.empty()){
            x=q2.top().se.fi;
                y=q2.top().se.se;
                ans=max(ans,abs(x-a[i].fi) + abs(y-a[i].se));
        }

 
}

cout << ans << endl;

}


int main(){ 
fast;
ll t=1,i=0,j=0,k,h;
 //pre();
// cin >> t;
for(h=1;h<=t;h++){

Function();

}


return 0;

}