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>

typedef long long lol;
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline A abs(A &a) { return (a <= 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const lol MOD=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >>n;
  vector<lol> x(n),y(n);
  lol xx,yy;
  xx=yy=0;
  for(int i=0;i<n;i++){
    cin >>x[i]>>y[i];
    xx+=x[i];
    yy+=y[i];
  }
  xx/=n;
  yy/=n;
  lol tmp=0;
  lol tmp2=0;
  int pint=0;
  int pi=n-1;
  lol tmp3=0;
  int p=0;
  //cout <<' '<<xx<<' '<<yy<<'\n';
  for(int i=0;i<n;i++){
    if(tmp<abs(xx-x[i])+abs(yy-y[i])){
      tmp3=tmp2;
      p=pi;
      tmp2=tmp;
      pi=pint;
      tmp=abs(xx-x[i])+abs(yy-y[i]);
      pint=i;
    }else if(tmp2<abs(xx-x[i])+abs(yy-y[i])){
      tmp3=tmp2;
      p=pi;
      tmp2=abs(xx-x[i])+abs(yy-y[i]);
      pi=i;
    }else if(tmp3<abs(xx-x[i])+abs(yy-y[i])){
      tmp3=abs(xx-x[i])+abs(yy-y[i]);
      p=i;
    }
  }
  lol ans=0;
  for(int i=0;i<n;i++){
    chmax(ans,abs(x[pint]-x[i])+abs(y[pint]-y[i]));
    chmax(ans,abs(x[pi]-x[i])+abs(y[pi]-y[i]));
    chmax(ans,abs(x[p]-x[i])+abs(y[p]-y[i]));
  }
  cout <<ans<<'\n';
  return(0);
}