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: Accepted)

#include <bits/stdc++.h>
using namespace std;

//  誤差を考慮して足し算を行う
long long add(long long a, long long b)
{
    // if (abs(a + b) < EPS * (abs(a) + abs(b)))
    //     return 0;
    return a + b;
}

//  二次元ベクトル構造体
struct P
{
    long long x, y;
    P() {}
    P(long long x, long long y) : x(x), y(y)
    {
    }
    P operator+(P p)
    {
        return P(add(x, p.x), add(y, p.y));
    }
    P operator-(P p)
    {
        return P(add(x, -p.x), add(y, -p.y));
    }
    P operator*(long long d)
    {
        return P(x * d, y * d);
    }
    long long dot(P p)
    { //  内積
        return add(x * p.x, y * p.y);
    }
    long long det(P p)
    { //  外積
        return add(x * p.y, -y * p.x);
    }
};

//  辞書順で比較
bool cmp_x(const P &p, const P &q)
{
    if (p.x != q.x)
        return p.x < q.x;
    return p.y < q.y;
}

//  凸包を求める
vector<P> convex_hull(P *ps, int n)
{
    sort(ps, ps + n, cmp_x);
    int k = 0;           //  凸包の頂点数
    vector<P> qs(n * 2); //  構築中の凸包

    //  下側凸包の作成
    for (int i = 0; i < n; i++)
    {
        while (k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0)
            k--;
        qs[k++] = ps[i];
    }
    //  上側凸包の作成
    for (int i = n - 2, t = k; i >= 0; i--)
    {
        while (k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0)
            k--;
        qs[k++] = ps[i];
    }
    qs.resize(k - 1);
    return qs;
}

//  マンハッタン距離
long long dist(P p, P q)
{
    return abs(p.x - q.x) + abs(p.y - q.y);
}

void solve(long long N, std::vector<long long> x, std::vector<long long> y)
{
    P ps[N];
    for (int i = 0; i < N; i++)
    {
        ps[i] = P(x[i], y[i]);
    }

    vector<P> qs = convex_hull(ps, N);
    long long res = 0;
    for (int i = 0; i < qs.size(); i++)
    {
        for (int j = 0; j < i; j++)
        {
            res = max(res, dist(qs[i], qs[j]));
        }
    }

    cout << res << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &x[i]);
        scanf("%lld", &y[i]);
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}