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>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 2e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
inline ll kissme(ll x,ll y)
{
	ll res=1;
	if(x==0)return 1;
	if(x==1)return y;
	res=kissme(x/2,y);
	res=res*res%mod;
	if(x%2==1)res=res*y%mod;
	return res;
}
struct segmentree{
	int lazy,mx,mi,add;
}tree[N*8];ll ans;
inline void pushdown(int id)
{
	int lz=tree[id].lazy;
	tree[id<<1].mx+=lz+tree[id].add;
	tree[id<<1|1].mx+=lz+tree[id].add;
	tree[id<<1].mi-=lz-tree[id].add;
	tree[id<<1|1].mi-=lz-tree[id].add;
	tree[id<<1].lazy+=lz;
	tree[id<<1|1].lazy+=lz;
	tree[id<<1].add+=tree[id].add;
	tree[id<<1|1].add+=tree[id].add;
	tree[id].add=0;
	tree[id].lazy=0; 
}
inline void pushup(int id)
{
	tree[id].mx=max(tree[id<<1].mx,tree[id<<1|1].mx);
	tree[id].mi=min(tree[id<<1].mi,tree[id<<1|1].mi);
}
void update(int l,int r,int x,int y,int add,int ADD,int id)
{
	pushdown(id);
	if(x<=l&&r<=y)
	{
		tree[id].mi-=add-ADD;
		tree[id].mx+=add+ADD;
		tree[id].lazy+=add;
		tree[id].add+=ADD;
		return;
	}
	int mid=(l+r)>>1;
	if(x<=mid)update(l,mid,x,y,add,ADD,id<<1);
	if(mid<y)update(mid+1,r,x,y,add,ADD,id<<1|1);
	pushup(id);
}
int query(int l,int r,int x,int y,bool f,int id)
{
	pushdown(id);
	if(x<=l&&r<=y)
		return (f?tree[id].mx:tree[id].mi);
	int mid=(l+r)>>1,res;
	if(f){
		res=-1e9;
		if(x<=mid)res=max(res,query(l,mid,x,y,f,id<<1));
		if(mid<y)res=max(res,query(mid+1,r,x,y,f,id<<1|1));
	}else{
		res=1e9;
		if(x<=mid)res=min(res,query(l,mid,x,y,f,id<<1));
		if(mid<y)res=min(res,query(mid+1,r,x,y,f,id<<1|1));
	}
	return res;
}
int n;pii p[N];
signed main()
{
	Very_fast;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>p[i].F>>p[i].S;
	sort(p+1,p+n+1);
	for(int i=1;i<=n;i++)update(1,n,i,i,0,p[i].S,1);
	for(int i=2;i<=n;i++)
	{
		ans=max(ans,(ll)max(query(1,n,1,i-1,1,1)-p[i].S,
		p[i].S-query(1,n,1,i-1,0,1))+p[i].F-p[i-1].F);
		update(1,n,1,i,p[i].F-p[i-1].F,0,1);
	}
	cout<<ans<<"\n";
	return 0;
}