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 <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define pi 3.1415926535
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for( i=n-1;i>=0;i--)
#define rep(i,n) for( i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll M = 1e9 + 7 ;
ll inf = 1e18;

ll n, m;
v<pair<ll, ll>> tv, lazy, a; //to initialize update each element
pair<ll, ll> combine1(pair<ll, ll> a, pair<ll, ll> b) { //for range update
	return {a.fi + b.fi, a.se + b.se};
}
pair<ll, ll> combine2(pair<ll, ll> a, pair<ll, ll> b) { //for range query
	if ((abs(a.fi) + abs(a.se) ) > (abs(b.fi) + abs(b.se)))
		return a;
	else
		return b;
}
void build(ll v, ll tl, ll tr) {
	if (tl > tr)
		return ;
	else {
		tv[v] = {0, 0};
	}
}

void push(ll v) {
	tv[v * 2] = combine1( tv[v * 2], lazy[v]);
	lazy[v * 2] = combine1(lazy[v * 2], lazy[v]);
	tv[v * 2 + 1] = combine1(tv[v * 2 + 1], lazy[v]);
	lazy[v * 2 + 1] = combine1( lazy[2 * v + 1], lazy[v]);
	lazy[v] = {0, 0};
}

void update(ll v, ll tl, ll tr, ll l, ll r, pair<ll, ll> updaterange) {
	if (l > r)
		return;
	if (l == tl && tr == r) {
		tv[v] = combine1( tv[v], updaterange);
		lazy[v] = combine1(lazy[v], updaterange);
	} else {
		push(v);
		ll tm = (tl + tr) / 2;
		update(v * 2, tl, tm, l, min(r, tm), updaterange);
		update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, updaterange);
		tv[v] = combine2(tv[v * 2], tv[v * 2 + 1]);
	}
}
pair<ll, ll> query(ll v, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return {0, 0};
	if (l <= tl && tr <= r)
		return tv[v];
	push(v);
	ll tm = (tl + tr) / 2;
	return combine2(query(v * 2, tl, tm, l, min(r, tm)), query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
int main() {
	// your code goes here
	IOS;

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z, N;

	cin >> n;
	a.resize(n);
	tv.resize(4 * n);
	lazy.resize(4 * n);
	rep(i, n) {
		cin >> x >> y;
		a[i] = {x, y};
	}
	build(1, 0, n - 1);
	rep(i, n) {
		update(1, 0, n - 1, i, i, a[i]);
	}
	ll mx = -inf;
	rep(i, n) {
		update(1, 0, n - 1, 0, n - 1, { -a[i].fi, -a[i].se});
		pair<ll, ll> out = query(1, 0, n - 1, 0, n - 1);
		mx = max(mx, abs(out.fi) + abs(out.se));
		update(1, 0, n - 1, 0, n - 1, a[i]);
	}
	cout << mx;
	return 0;
}