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# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Program {
    static void Main (string[] args) {
        int N = int.Parse (Console.ReadLine ());

        long[] xdash = new long[N];
        long[] ydash = new long[N];
        long[] x = new long[N];
        long[] y = new long[N];
        long[] xindex = new long[N];
        long[] yindex = new long[N];

        for (int i = 0; i < N; i++) {
            var strtmp = Console.ReadLine ().Split (' ');
            xdash[i] = long.Parse (strtmp[0]);
            ydash[i] = long.Parse (strtmp[1]);
            x[i] = xdash[i] + ydash[i];
            y[i] = xdash[i] - ydash[i];
            xindex[i] = i;
            yindex[i] = i;
        }

        QuickSortS2B (x, xindex);
        QuickSortS2B (y, yindex);

        long xdiff = x[N - 1] - x[0];
        long ydiff = y[N - 1] - y[0];
        long ans = 0;
        if (xdiff > ydiff) {
            long orig_xdash1 = xdash[xindex[N - 1]];
            long orig_xdash2 = xdash[xindex[0]];
            long orig_ydash1 = ydash[xindex[N - 1]];
            long orig_ydash2 = ydash[xindex[0]];
            ans = Math.Abs (orig_xdash1 - orig_xdash2) + Math.Abs (orig_ydash1 - orig_ydash2);
        } else {
            long orig_xdash1 = xdash[yindex[N - 1]];
            long orig_xdash2 = xdash[yindex[0]];
            long orig_ydash1 = ydash[yindex[N - 1]];
            long orig_ydash2 = ydash[yindex[0]];
            ans = Math.Abs (orig_xdash1 - orig_xdash2) + Math.Abs (orig_ydash1 - orig_ydash2);
        }
        Console.WriteLine (ans);
    }

    static void QuickSortS2B (long[] a, long[] index) {
        QuickSortS2B (a, index, 0, a.Length - 1);
    }

    static void QuickSortS2B (long[] a, long[] index, int left, int right) {
        if (left < right) {
            int i = left;
            int j = right;
            long tmp;
            long pivot = med3 (a[i], a[i + (j - i) / 2], a[j]);
            while (true) {
                while (a[i] < pivot) i++;
                while (pivot < a[j]) j--;
                if (i >= j) break;
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
                tmp = index[i];
                index[i] = index[j];
                index[j] = tmp;
                i++;
                j--;
            }
            QuickSortS2B (a, index, left, i - 1);
            QuickSortS2B (a, index, j + 1, right);
        }
    }

    static long med3 (long x, long y, long z) {
        if (x < y) {
            if (y < z) {
                return y;
            } else if (z < x) {
                return x;
            } else {
                return z;
            }
        } else {
            if (z < y) {
                return y;
            } else if (x < z) {
                return x;
            } else {
                return z;
            }
        }
    }
}

//dotnet run --project test