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 Haskell (GHC 8.8.3) (judge verdict: Wrong Answer)

{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getInt
  xs <- VM.new n
  ys <- VM.new n

  forM_ [0..(n-1)] $ \i -> do
    [x, y] <- getIntList
    VM.write xs i x
    VM.write ys i y

  xs' <- V.freeze xs
  ys' <- V.freeze ys

  let getCorners i xa ya xb yb xc yc xd yd ma mb mc md
        | i >= n = (xa, ya, xb, yb, xc, yc, xd, yc)
        | otherwise = let x = xs' V.! i
                          y = ys' V.! i
                          da =      x
                          db = abs (x - 10^6)
                          dc =      y
                          dd = abs (y - 10^6)
                          (xa', ya') | da > ma = (xa, ya)
                                     | otherwise = (x, y)
                          (xb', yb') | db > mb = (xb, yb)
                                     | otherwise = (x, y)
                          (xc', yc') | dc > mc = (xc, yc)
                                     | otherwise = (x, y)
                          (xd', yd') | dd > md = (xd, yd)
                                     | otherwise = (x, y)
                          ma' = min da ma
                          mb' = min db mb
                          mc' = min dc mc
                          md' = min dd md
                      in getCorners (i+1) xa' ya' xb' yb' xc' yc' xd' yd' ma' mb' mc' md'

      mm = 10^6 :: Int

      (xa, ya, xb, yb, xc, yc, xd, yd) =
        getCorners 0 mm 0 0 0 0 mm 0 0 inf inf inf inf

      solve i res
        | i >= n = res
        | otherwise = let x = xs' V.! i
                          y = ys' V.! i
                          da = abs (x - xa) + abs (y - ya)
                          db = abs (x - xb) + abs (y - yb)
                          dc = abs (x - xc) + abs (y - yc)
                          dd = abs (x - xd) + abs (y - yd)
                          md = max da (max db (max dc dd))
                          res' = max res md
                      in solve (i+1) res'

  print $ solve 0 0