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

import kotlin.math.abs
import kotlin.math.max

fun main() {
    val n = nextInt()
    val points = (0 until n).map {
        val (x, y) = nextLongList()
        x to y
    }
    var centerX = 0.0
    var centerY = 0.0
    points.forEach {
        centerX += it.first
        centerY += it.second
    }
    centerX /= points.size
    centerY /= points.size
    points.map { pair ->
        listOf(
            pair.first.toDouble(),
            pair.second.toDouble(),
            pair.first - centerX,
            pair.second - centerY
        )
    }.let {
        val x = it.sortedBy { it[2] as Double }
        val y = it.sortedBy { it[3] as Double }

        var m = 0L
        x.forEach { pair ->
            val x0 = x[0]
            val xl = x.last()
            m = max(
                m, max(
                    abs(x0[0] - pair[0]) + abs(x0[1] - pair[1]),
                    abs(xl[0] - pair[0]) + abs(xl[1] - pair[1])
                ).toLong()
            )
        }
        y.forEach { pair ->
            val y0 = y[0]
            val yl = y.last()
            m = max(
                m, max(
                    abs(y0[0] - pair[0]) + abs(y0[1] - pair[1]),
                    abs(yl[0] - pair[0]) + abs(yl[1] - pair[1])
                ).toLong()
            )
        }
        println(m)
    }
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

fun gcd(x: Int, y: Int): Int {
    fun innerGcd(x: Int, y: Int): Int {
        return if (x % y == 0) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

fun gcd(x: Long, y: Long): Long {
    fun innerGcd(x: Long, y: Long): Long {
        return if (x % y == 0L) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}