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 <stdio.h>
#include <stdlib.h>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define max(l,r) ((l)>(r)?(l):(r))
#define min(l,r) ((l)<(r)?(l):(r))

ll x[202020],y[202020];
ll wa[202020], wai[202020];
ll sa[202020], sai[202020];

/////merge sort(ll)
ll tllar[202020];
void msortll(ll *ar, int l, int r){ // [l,r)
    if(r-l<=1) return;
    int mid=(l+r)/2;
    if(r-mid>1) msortll(ar,mid,r);
    if(mid-l>1) msortll(ar,l,mid);
    for(int li=l,ri=mid,afi=l;afi<r;afi++){
        if(ri>=r||(li<mid&&ri<r&&ar[li]<=ar[ri])) tllar[afi]=ar[li++]; //cmp
        else tllar[afi]=ar[ri++];
    }
    for(int i=l;i<r;i++) ar[i]=tllar[i];
}
/////

int main(){
    int n; scanf("%d", &n);
    rep(i,n){
        scanf("%lld%lld", &x[i], &y[i]);
        wa[i] = x[i] + y[i];
        wai[i] = -wa[i];
        sa[i] = x[i] - y[i];
        sai[i] = -sa[i];
    }
    msortll(wa,0,n);
    msortll(wai,0,n);
    msortll(sa,0,n);
    msortll(sai,0,n);

    ll ans = max(max(wa[n-1]-wa[0],sa[n-1]-sa[0]),max(wai[n-1]-wai[0],sai[n-1]-sai[0]));
    printf("%lld\n", ans);
    //rep(i, n) scanf("%lld", ans+i);
    //if(ans){ puts("YES"); rep(i,n) printf("%lld ", a[i]);}else puts("NO");
}