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: Wrong Answer)

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

namespace ProgramingStudying2
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var x = new int[n];
            var y = new int[n];

            var xmax = 0;
            var xmin = 1000000000 + 7;
            var ymax = 0;
            var ymin = 1000000000 + 7 ;

            for (int i = 0; i < n; i++)
            {
                var xy = Console.ReadLine().Split().Select(int.Parse).ToArray();
                x[i] = xy[0];
                y[i] = xy[1];

                if (x[i] > xmax)
                {
                    xmax = x[i];
                }
                if (x[i] < xmin)
                {
                    xmin = x[i];
                }
                if (y[i] > ymax)
                {
                    ymax = y[i];
                }
                if (y[i] < ymin)
                {
                    ymin = y[i];
                }
            }

            var xmaxlist = new List<int>();
            var xminlist = new List<int>();
            var ymaxlist = new List<int>();
            var yminlist = new List<int>();

            for(int i = 0; i < n; i++)
            {
                if(x[i] == xmax)
                {
                    xmaxlist.Add(i);
                }
                if (x[i] == xmin)
                {
                    xminlist.Add(i);
                }
                if (y[i] == ymax)
                {
                    ymaxlist.Add(i);
                }
                if (y[i] == ymax)
                {
                    yminlist.Add(i);
                }
            }

            var xmaxYmax = 0;
            var xmaxYmin = 1000000000 + 7;
            var xminYmax = 0;
            var xminYmin = 1000000000 + 7;

            var ymaxXmax = 0;
            var ymaxXmin = 1000000000 + 7;
            var yminXmax = 0;
            var yminXmin = 1000000000 + 7;

            foreach (var i in xmaxlist)
            {
                if(y[i] > xmaxYmax)
                {
                    xmaxYmax = y[i];
                }
                if(y[i] < xmaxYmin)
                {
                    xmaxYmin = y[i];
                }
            }
            foreach (var i in xminlist)
            {
                if (y[i] > xminYmax)
                {
                    xminYmax = y[i];
                }
                if (y[i] < xminYmin)
                {
                    xminYmin = y[i];
                }
            }
            foreach (var i in ymaxlist)
            {
                if (x[i] > ymaxXmax)
                {
                    ymaxXmax = x[i];
                }
                if (x[i] < ymaxXmin)
                {
                    ymaxXmin = x[i];
                }
            }
            foreach (var i in yminlist)
            {
                if (x[i] > yminXmax)
                {
                    yminXmax = x[i];
                }
                if (x[i] < yminXmin)
                {
                    yminXmin = x[i];
                }
            }

            var d1 = Math.Abs(xmax - xmin) + Math.Abs(xmaxYmax - xminYmin);
            var d2 = Math.Abs(xmax - xmin) + Math.Abs(xmaxYmin - xminYmax);
            var d3 = Math.Abs(ymax - ymin) + Math.Abs(ymaxXmax - yminXmin);
            var d4 = Math.Abs(ymax - ymin) + Math.Abs(yminXmax - ymaxXmin);
            var d5 = Math.Abs(xmax - ymaxXmin) + Math.Abs(xmaxYmin - ymax);
            var d6 = Math.Abs(xmax - yminXmin) + Math.Abs(xmaxYmax - ymin);
            var d7 = Math.Abs(xmin - ymaxXmax) + Math.Abs(xminYmin - ymax);
            var d8 = Math.Abs(xmin - yminXmax) + Math.Abs(xminYmax - ymin);

            var list = new List<int>();
            list.Add(d1);
            list.Add(d2);
            list.Add(d3);
            list.Add(d4);
            list.Add(d5);
            list.Add(d6);
            list.Add(d7);
            list.Add(d8);

            Console.WriteLine(list.Max());

        }
    }
}