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++ (Clang 10.0.0) (judge verdict: Wrong Answer)

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <deque>
#include <string>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <map>
#include <unordered_map>
#include <bitset>

#define _crt_secure_no_warnings
#define FREEELO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define INF 0x3F3F3F3F3F3F3F3F
#define MAX 300001
#define MOD 1000000007
#define ALPHABET 128
#define loop(i, n) for (int i = 1; i <= (n); i++)
#define loop0(i, n) for (int i = 0; i < (n); i++)
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll, ll> llll;
typedef pair<int, int> ii;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;

int main() {
    int n; cin >> n;
    vector<ii> v(n);
    for (auto &i : v) cin >> i.F >> i.S;
    int ans = 0;
    map<int, int> diff, sum;
    for (auto [a, b] : v){
        diff[a - b]++;
        sum[a + b]++;
    }
    auto rem = [&] (int v, map<int, int> &mp){
        int t = --mp[v];
        if (!t) mp.erase(v);
    };
    auto read = [&] (int v, map<int, int> &mp){
        mp[v]++;
    };
    for (auto [a, b] : v){
        rem(a - b, diff);
        rem(a + b, sum);
        if (!sum.empty()){
            int cur = a + b;
            auto iter = sum.begin();
            ans = max(ans, cur - iter->F);
        }
        if (!diff.empty()){
            int cur = b - a;
            auto iter = diff.begin();
            ans = max(ans, cur + iter->F);
        }
        read(a - b, diff);
        read(a + b, sum);
    }
    cout << ans << endl;
}