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>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<vector>
#include<set>
#define il inline
#define re register
using namespace std;
typedef double db;
const long long N=200010;
struct P{long long x,y;} a[N],s[N];
long long n,top=0,ans=0;
il P operator-(P a,P b){
    return (P){a.x-b.x,a.y-b.y};
}
il long long operator*(P a,P b){
    return a.x*b.y-a.y*b.x;
}
il long long dis(P a){
    return abs(a.x)+abs(a.y);
}
il bool cmp(P x,P y){
    if(abs((x-a[1])*(y-a[1]))>0) return (x-a[1])*(y-a[1])>0;
    return dis(x-a[1])<dis(y-a[1]);
}
il long long S(P a,P b,P c){
    return abs((a-b)*(a-c))/2;
}
int main(){
    scanf("%d",&n);
    for(long long i=1;i<=n;i++)
        scanf("%d%d",&a[i].x,&a[i].y);
    for(long long i=2;i<=n;i++)
        if(a[i].y<a[1].y||(a[i].y==a[1].y&&a[i].x<a[1].x)) 
            swap(a[1],a[i]);
    sort(a+2,a+n+1,cmp);
    top=2;s[1]=a[1];s[2]=a[2];
    for(long long i=3;i<=n;i++){
        while(top>1&&(a[i]-s[top-1])*(s[top]-s[top-1])>=0) top--;
        s[++top]=a[i];
    }
    for(long long i=0;i<top;i++)
        s[i]=s[i+1];
    n=top;
    for(long long i=0,j=2;i<n;i++){
        while(S(s[i],s[(i+1)%n],s[j])<S(s[i],s[(i+1)%n],s[(j+1)%n])) j=(j+1)%n;
        ans=max(dis(s[i]-s[j]),ans);
    }
    printf("%lld",ans);
    return 0;
}