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;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<pair<int,int>>vp(n);
    for (int i = 0; i < n; i++)
    {
        cin>>vp[i].first>>vp[i].second;
    }
    int xmin=INF;
    int xmax=-INF;
    int ymin=INF;
    int ymax=-INF;
    for (int i = 0; i < n; i++)
    {
        chmin(xmin,vp[i].first);
        chmax(xmax,vp[i].first);
        chmin(ymin,vp[i].second);
        chmax(ymax,vp[i].second);
    }
    vector<int>minx,maxx,miny,maxy;
    for (int i = 0; i < n; i++)
    {
        if(vp[i].first==xmin) minx.push_back(vp[i].second);
        if(vp[i].first==xmax) maxx.push_back(vp[i].second);
        if(vp[i].second==ymin) miny.push_back(vp[i].first);
        if(vp[i].second==ymax) maxy.push_back(vp[i].first);
        
    }
    
    sort(ALL(minx));
    sort(ALL(maxx));
    sort(ALL(miny));
    sort(ALL(maxy));
    vector<pair<int,int>>loc;
    loc.push_back({xmin,minx[0]});
    loc.push_back({xmin,minx.back()});
    loc.push_back({xmax,maxx[0]});
    loc.push_back({xmax,maxx.back()});

    loc.push_back({miny[0],ymin});
    loc.push_back({miny.back(),ymin});
    loc.push_back({maxy[0],ymax});
    loc.push_back({maxy.back(),ymax});
    


    //show(loc);
    int dis=0;
    for (int i = 0; i < 8; i++)
    {
        for (int j = 0; j < 8; j++)
        {
            int x1=loc[i].first;
            int x2=loc[j].first;
            int y1=loc[i].second;
            int y2=loc[j].second;
            chmax(dis ,abs(x1-x2) + abs(y1-y2));
        }
        
    }
    cout<<dis<<endl;
    

  
    return 0;
}