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 Kotlin (1.3.71) (judge verdict: Accepted)

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.sqrt

fun main(args: Array<String>) {

    // IO Templates
    val br = BufferedReader(InputStreamReader(System.`in`))
    val out = PrintWriter(System.out)

    val n = br.readLine()!!.toInt()

    val points = mutableListOf<MyVector>()

    for (i in 1..n) {
        val (x, y) = br.readLine()!!.split(' ').map { it.toInt() }
        points.add(MyVector(x, y))
    }

    var ru = points.first()
    var lu = points.first()
    var ld = points.first()
    var rd = points.first()

    for (i in 1 until n) {
        val point = points[i]
        if ((point.x - ru.x) + (point.y - ru.y) > 0) ru = point
        if ((-point.x + lu.x) + (point.y - lu.y) > 0) lu = point
        if ((-point.x + ld.x) + (-point.y + ld.y) > 0) ld = point
        if ((point.x - rd.x) + (-point.y + rd.y) > 0) rd = point
    }

    out.println(
        max(
            abs(ru.x - ld.x) + abs(ru.y - ld.y),
            abs(lu.x - rd.x) + abs(lu.y - rd.y)
        )
    )

    out.flush()
}

data class MyVector(
    var x: Long,
    var y: Long
) {

    constructor(x: Int, y: Int) : this(x = x.toLong(), y = y.toLong())

    fun plus(x: Long, y: Long) {
        this.x += x
        this.y += y
    }

    operator fun plus(v: MyVector) {
        plus(v.x, v.y)
    }

    fun minus(x: Long, y: Long) {
        this.x -= x
        this.y -= y
    }

    operator fun minus(v: MyVector) {
        minus(v.x, v.y)
    }

    fun scalarTimes(m: Long) {
        x *= m
        y *= m
    }

    operator fun times(v: MyVector): Long = x * v.x + y * v.y

    fun squareMagnitude(): Long = this.times(this)

    fun magnitude(): Double = sqrt(squareMagnitude().toDouble())
}