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



Sample input:
3
1 1
2 4
3 2


Sample output:
4

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# E

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
import numpy as np
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

n = int(input())
d1 = [] * n
d2 = [] * n

for i in range(n):
    x, y = map(int, input().split())
    d1.append(x+y)
    d2.append(x-y)

print(max(max(d1) - min(d1), max(d2)-min(d2)))

Submission status: Runtime Error

Solution code:
from dataclasses import dataclass
from operator import itemgetter, attrgetter

@dataclass
class P:
    x: float
    y: float
    def __add__(self, p: P): return P(self.x + p.x, self.y + p.y)
    def __sub__(self, p: P): return P(self.x - p.x, self.y - p.y)
    def dot(self, p: P): return (self.x*p.x + self.y*p.y)
    def cross(self, p: P): return (self.x*p.y - self.y*p.x)
    def abs(self): return (abs(self.x) + abs(self.y))

def convex_hull(Ps):
    Ps.sort(key=attrgetter('x', 'y'))
    ret1, ret2 = list(), list()
    for i in range(len(Ps)):
        k = len(ret1)
        while k>=2 and (Ps[i]-ret1[k-1]).cross(ret1[k-1]-ret1[k-2]) <= 0:
            ret1.pop()
            k = len(ret1)
        ret1.append(Ps[i])
    for i in range(len(Ps)):
        k = len(ret2)
        while k>=2 and (Ps[i]-ret2[k-1]).cross(ret2[k-1]-ret2[k-2]) >= 0:
            ret2.pop()
            k = len(ret2)
        ret2.append(Ps[i])
    return ret1 + ret2[::-1]

N = int(input())
Ps = list()
for i in range(N):
    x, y = list(map(int, input().split()))
    Ps.append(P(x, y))

# produce convex hull
CPs = convex_hull(Ps)

# brute force
ans = 0
for i in range(len(CPs)):
    for j in range(i, len(CPs)):
        mdis = (CPs[i]-CPs[j]).abs()
#        print(i, j, mdis)
        if ans < mdis: ans = mdis

print (ans)

Submission status: Runtime Error

Solution code:
n = int(input())

points = []

for i in range(n) :
    point = list(map(int, input(" ")))
    points.append(point)

z = []
w = []

for i in range(len(points)) :
    z.append(points[i][0] + points[i][1])

for i in range(len(points)) :
    w.append(points[i][0] - points[i][1])

max_z = max(z) - min(z)
max_w = max(w) - min(w)

if max_z > max_w :
    print(max_z)
else :
    print(max_w)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())

x = np.empty(N, dtype=np.longlong)
y = np.empty(N, dtype=np.longlong)

for i in range(N):
    x[i], y[i] = (int(t) for t in input().split())

ind = np.argsort(x)
X = x[ind]
Y = y[ind]

# max_dist = [0]
# for i in range(1, N):
#     max_dist.append(np.max(-X[:i] - Y[:i]) + X[i] + Y[i])
#     max_dist.append(np.max(-X[:i] + Y[:i]) + X[i] - Y[i])

# print(max(max_dist))


dist = np.abs(x.reshape([-1, 1]) - x.reshape([1, -1])) + np.abs(y.reshape([-1, 1]) - y.reshape([1, -1]))

print(dist.max())

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())

x = np.empty(N, dtype=np.longlong)
y = np.empty(N, dtype=np.longlong)

for i in range(N):
    x[i], y[i] = (int(t) for t in input().split())

ind = np.argsort(x)
X = x[ind]
Y = y[ind]

# max_dist = [0]
# for i in range(1, N):
#     max_dist.append(np.max(-X[:i] - Y[:i]) + X[i] + Y[i])
#     max_dist.append(np.max(-X[:i] + Y[:i]) + X[i] - Y[i])

# print(max(max_dist))


dist = np.abs(x.reshape([-1, 1]) - x.reshape([1, -2])) + np.abs(y.reshape([-1, 1]) - y.reshape([1, -2]))

print(dist.max())

Submission status: Runtime Error

Solution code:
n = int(input())
l = list()
for i in range(n):
  l.append(list(map(int, input().split())))
max_d = 0
for i in range(n):
  for j in range(i,n):
    d = abs(array[i][0] - array[j][0]) + abs(array[i][1] - array[j][1])
    if max_d < d:
      max_d = d
print(max_d)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
array = np.empty(n)
for i in range(n):
  array[i] = np.array(map(int, input().split()))
max_d = 0
for i in range(n):
  for j in range(i,n):
    d = np.abs(array[i,0] - array[j,0]) + np.abs(array[i,1] - array[j,1])
    if max_d < d:
      max_d = d
print(max_d)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
array = np.empty((n,2))
for i in range(n):
  array[i] = np.array(map(int, input().split()))
max_d = 0
for i in range(n):
  for j in range(i,n):
    d = np.abs(array[i,0] - array[j,0]) + np.abs(array[i,1] - array[j,1])
    if max_d < d:
      max_d = d
print(max_d)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
array = np.empty((n,2))
for i in range(n):
  array[i] = np.array(map(int, input().split()))

max_d = 0
for i in range(n):
  for j in range(i,n):
  	d = np.abs(array[i,0] - array[j,0]) + np.abs(array[i,1] - array[j,1])
    if max_d < d:
      max_d = d
print(max_d)

Submission status: Runtime Error

Solution code:
def manhattan(n, x, y):
    x2 = [0] * n
    y2 = [0] * n
    for i in range(n):
        x0, y0 = xy[i]
        x2[i] = x0 - y0
        y2[i] = x0 + y0
    print(max(max(x2) - min(x2), max(y2) - min(y2)))

n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
    x[i] , y[i] = map(int, input().split())
manhattan(n, x, y)

Submission status: Runtime Error

Solution code:
x = [0] ** ((10**9)+1)
y = [0] ** ((10**9)+1)

n = int(input())
for i in range(n):
	a,b = map(int,input().split())
	x[a],y[b] = 1,1

#flag1,flag2 = 0,0
# for i in range((10**9)+1):
# 	if flag1 > 0:
# 		break
# 	else:
# 		 if x[i] == 1:
# 		 	flag1 = i

# for i in range((10**9)+1):
# 	if x[i] == 1: 
# 		flag2 = i

a = less(x)
b = less(y)
c = more(x)
d = more(y)
print(abs(a-c) + abs(b-d))


def less(x):
	flag1= 0
	for i in range((10**9)+1):
		if flag1 > 0:
			break
		else:
			 if x[i] == 1:
			 	flag1 = i

	return flag1

def more(x):
	flag2 = 0
	for i in range((10**9)+1):
		if x[i] == 1: 
			flag2 = i

	return flag2

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())

x = np.empty(N, dtype=np.longlong)
y = np.empty(N, dtype=np.longlong)


for i in range(N):
    x[i], y[i] = (int(t) for t in input().split())

    
dist = np.abs(x.reshape([-1, 1]) - x.reshape([1, -1])) + np.abs(y.reshape([-1, 1]) - y.reshape([1, -1]))

print(dist.max())

Submission status: Runtime Error

Solution code:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N = next(it)

    if N == 3:
        raise 1

    D = 32
    x1 = y1 = 10**9+1
    x2 = y2 = 0
    vis = set()
    for xy in zip(it, it):
        if xy in vis:
            continue
        vis.add(xy)
        x, y = xy
        x1 = min(x1, x); x2 = max(x2, x)
        y1 = min(y1, y); y2 = max(y2, y)
    dd = max(1, (x2-x1) // D, (y2-y1) // D)
    dx = (x2-x1+1)//dd + 1
    dy = (y2-y1+1)//dd + 1
    d = [[[] for j in range(dx)] for i in range(dy)]


    md = [[] for i in range(dx+dy-1)]
    for i in range(dx*dy):
        ay1, ax1 = divmod(i, dx)
        md[0].append((ax1, ay1, ax1, ay1))
        for j in range(i+1, dx*dy):
            ay2, ax2 = divmod(j, dx)
            md[abs(ax1-ax2)+abs(ay1-ay2)].append((ax1, ay1, ax2, ay2))

    for xy in vis:
        x, y = xy
        ix = (x-x1) // dd
        iy = (y-y1) // dd
        d[iy][ix].append(xy)

    ans = 0
    cnt = 1
    i = len(md)
    for md1 in reversed(md):
        i -= 1
        for x1, y1, x2, y2 in md1:
            if len(d[y2][x2]) == 0:
                continue

            for xx1, yy1 in d[y1][x1]:
                for xx2, yy2 in d[y2][x2]:
                    val = abs(xx1-xx2) + abs(yy1-yy2)

                    ans = max(ans, val)
        if ans:
            if (i+1)*dd -2 < ans:
                break
            if cnt: cnt -= 1
            else: break
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
import heapq
#import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

n = ri()
a = []
b = []
for i in range(n):
    x,y = rl()
    a.append(x+y)
    b.append(x-y)
a.sort()
b.sort()
print(max(a[-1]-a[0], b[-1]-[0]))

Submission status: Runtime Error

Solution code:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N = next(it)

    if N == 3:
        raise 1

    D = 32
    x1 = y1 = 10**9+1
    x2 = y2 = 0
    vis = set()
    for xy in zip(it, it):
        if xy in vis:
            continue
        vis.add(xy)
        x, y = xy
        x1 = min(x1, x); x2 = max(x2, x)
        y1 = min(y1, y); y2 = max(y2, y)
    dd = max(1, (x2-x1) // D, (y2-y1) // D)
    dx = (x2-x1+1)//dd + 1
    dy = (y2-y1+1)//dd + 1
    d = [[[] for j in range(dx)] for i in range(dy)]


    md = [[] for i in range(dx+dy-1)]
    for i in range(dx*dy):
        ay1, ax1 = divmod(i, dx)
        md[0].append((ax1, ay1, ax1, ay1))
        for j in range(i+1, dx*dy):
            ay2, ax2 = divmod(j, dx)
            md[abs(ax1-ax2)+abs(ay1-ay2)].append((ax1, ay1, ax2, ay2))

    for xy in vis:
        x, y = xy
        ix = (x-x1) // dd
        iy = (y-y1) // dd
        d[iy][ix].append(xy)

    ans = 0
    cnt = 1
    for md1 in reversed(md):
        for x1, y1, x2, y2 in md1:
            if len(d[y2][x2]) == 0:
                continue

            for xx1, yy1 in d[y1][x1]:
                for xx2, yy2 in d[y2][x2]:
                    val = abs(xx1-xx2) + abs(yy1-yy2)

                    ans = max(ans, val)
        if ans:
            if cnt: cnt -= 1
            else: break
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N = next(it)

    if N == 2:
        raise 1

    D = 16
    x1 = y1 = 10**9+1
    x2 = y2 = 0
    vis = set()
    for xy in zip(it, it):
        if xy in vis:
            continue
        vis.add(xy)
        x, y = xy
        x1 = min(x1, x); x2 = max(x2, x)
        y1 = min(y1, y); y2 = max(y2, y)
    dd = max(1, (x2-x1) // D, (y2-y1) // D)
    dx = (x2-x1+1)//dd + 1
    dy = (y2-y1+1)//dd + 1
    d = [[[] for j in range(dx)] for i in range(dy)]


    md = [[] for i in range(dx+dy-1)]
    for i in range(dx*dy):
        ay1, ax1 = divmod(i, dx)
        md[0].append((ax1, ay1, ax1, ay1))
        for j in range(i+1, dx*dy):
            ay2, ax2 = divmod(j, dx)
            md[abs(ax1-ax2)+abs(ay1-ay2)].append((ax1, ay1, ax2, ay2))

    for xy in vis:
        x, y = xy
        ix = (x-x1) // dd
        iy = (y-y1) // dd
        d[iy][ix].append(xy)

    ans = 0
    cnt = 1
    for md1 in reversed(md):
        for x1, y1, x2, y2 in md1:
            if len(d[y2][x2]) == 0:
                continue

            for xx1, yy1 in d[y1][x1]:
                for xx2, yy2 in d[y2][x2]:
                    val = abs(xx1-xx2) + abs(yy1-yy2)

                    ans = max(ans, val)
        if ans:
            if cnt: cnt -= 1
            else: break
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
import sys

def f(x,y):
    return x-y.x+y

def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    x = [0]*n
    y = [0]*n
    for i in range(n):
        x[i],y[i] = map(int,input().split())
    f0 = [0]*n
    f1 = [0]*n
    for i in range(n):
        f0[i],fi[i] = f(x[i],y[i])
    print(max(max(f0)-minf(0),max(f1)-minf(1)))

if __name__ = "__main__":
    main()

Submission status: Runtime Error

Solution code:
x=[]
for i in range(N):
    x.append(list(map(int,input().split())))
t=[]
for i in range(N):
    for j in range(N):
        t.append(abs(x[i][0]-x[j][0])+abs(x[i][1]-x[j][1]))
print(max(t))

Submission status: Runtime Error

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())

l=lnii()

if len(l)==1:
  print(0)
  exit()

x_max=0
x_min=10**10
y_max=0
y_min=10**10

for x,y in l:
  s=x-y
  x_max=max(x_max,s)
  x_min=min(x_min,s)

  t=x+y
  y_max=max(y_max,t)
  y_min=min(y_min,t)

x_ans=x_max-x_min
y_ans=y_max-y_min
print(max(x_ans,y_ans))

Submission status: Runtime Error

Solution code:
from __future__ import print_function

from functools import reduce
from operator import mul
from collections import Counter
from collections import deque
from itertools import accumulate
from queue import Queue
from queue import PriorityQueue as pq
from heapq import heapreplace
from heapq import heapify
from heapq import heappushpop
from heapq import heappop
from heapq import heappush
import heapq
import time
import random
import bisect
import itertools
import collections
from fractions import Fraction
import fractions
import string
import math
import operator
import functools
import copy
import array
import re
import sys
sys.setrecursionlimit(500000)


input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


mod = 1000000007


def combinations_count_mod(n, r):
    r = min(r, n - r)
    numer = reduce(lambda x, y: x * y % mod, range(n, n - r, -1), 1)
    denom = pow(reduce(lambda x, y: x * y % mod, range(1, r + 1), 1), mod - 2, mod)
    return numer * denom % mod


def solve():
    pass


def solve01():
    n = int(input().strip())
    L = []
    Xmin, Ymin, Xmax, Ymax = (sys.maxsize, sys.maxsize, -100, -100)

    for i in range(n):
        a, b = map(int, input().strip().split())
        L.append((a, b))
        Xmin, Ymin, Xmax, Ymax = (min(Xmin, a), min(Ymin, b), max(Xmax, b), max(Ymax, b))
    A, B, C, D = ((Xmin, Ymax), (Xmin, Ymin), (Xmax, Ymin), (Xmax, Ymax))

    flag = 1
    for i in range(len(L) - 1):
        flag *= (L[i] == L[i + 1])
    if flag == 1:
        try:
            raise ValueError("error!")
        except ValueError as e:
            eprint(e)

    if Xmax = Xmin or Ymax = Ymin:
        try:
            raise ValueError("error!")
        except ValueError as e:
            eprint(e)

    # 対角線ACについて
    d_MinDistFromA = sys.maxsize    # 点Aからの距離が最小であるような，その最小の距離の値を求める
    for a, b in L:
        d_MinDistFromA = min(d_MinDistFromA, abs(a - Xmin) + abs(b - Ymax))

    d_MinDistFromC = sys.maxsize    # 点Cからの距離が最小であるような，その最小の距離の値を求める
    for a, b in L:
        d_MinDistFromC = min(d_MinDistFromC, abs(a - Xmax) + abs(b - Ymin))
    ans1 = abs(A[0] - C[0]) + abs(A[1] - C[1]) - (d_MinDistFromA + d_MinDistFromC)  #

    # 対角線BDについて
    d_MinDistFromB = sys.maxsize    # 点Bからの距離が最小であるような，その最小の距離の値を求める
    for a, b in L:
        d_MinDistFromB = min(d_MinDistFromB, abs(a - Xmin) + abs(b - Ymin))

    d_MinDistFromD = sys.maxsize    # 点Dからの距離が最小であるような，その最小の距離の値を求める
    for a, b in L:
        d_MinDistFromD = min(d_MinDistFromD, abs(a - Xmax) + abs(b - Ymax))
    ans2 = abs(B[0] - D[0]) + abs(B[1] - D[1]) - (d_MinDistFromB + d_MinDistFromD)

    # 出力
    # eprint('ans1,ans2 ', end=':\n')
    # eprint(ans1, ans2)
    print(max(ans1, ans2))


def solve00():
    n = int(input().strip())
    L = []
    Xmin = sys.maxsize
    Ymin = sys.maxsize
    Xmax = -100
    Ymax = -100
    for i in range(n):
        a, b = map(int, input().strip().split())
        L.append((a, b))
        Xmin = min(Xmin, a)
        Ymin = min(Ymin, b)
        Xmax = max(Xmax, b)
        Ymax = max(Ymax, b)

    A = (Xmin, Ymax)
    B = (Xmin, Ymin)
    C = (Xmax, Ymin)
    D = (Xmax, Ymax)

    # 対角線ACについて
    d_MinDistFromA = sys.maxsize    # 点Aからの距離が最小であるような，その最小の距離の値を求める
    for a, b in L:
        d_MinDistFromA = min(d_MinDistFromA, abs(a - Xmin) + abs(b - Ymax))

    d_MinDistFromC = sys.maxsize    # 点Cからの距離が最小であるような，その最小の距離の値を求める
    for a, b in L:
        d_MinDistFromC = min(d_MinDistFromC, abs(a - Xmax) + abs(b - Ymin))
    ans1 = abs(A[0] - C[0]) + abs(A[1] - C[1]) - (d_MinDistFromA + d_MinDistFromC)  #

    # 対角線BDについて
    d_MinDistFromB = sys.maxsize    # 点Bからの距離が最小であるような，その最小の距離の値を求める
    for a, b in L:
        d_MinDistFromB = min(d_MinDistFromB, abs(a - Xmin) + abs(b - Ymin))

    d_MinDistFromD = sys.maxsize    # 点Dからの距離が最小であるような，その最小の距離の値を求める
    for a, b in L:
        d_MinDistFromD = min(d_MinDistFromD, abs(a - Xmax) + abs(b - Ymax))
    ans2 = abs(B[0] - D[0]) + abs(B[1] - D[1]) - (d_MinDistFromB + d_MinDistFromD)

    # 出力
    # eprint('ans1,ans2 ', end=':\n')
    # eprint(ans1, ans2)
    print(max(ans1, ans2))


def main():
    solve01()


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
X = []
Y = []
for _ in range(N):
    x,y = map(int, input().split())
    X.append(x)
    Y.append(y)
X = np.array(X)
Y = np.array(Y)
X_ = X.reshape((N,1))
Y_ = Y.reshape((N,1))
Z = np.abs(X-X_)+np.abs(Y-Y_)
z = Z.reshape((1,-1))
print(np.max(z))

Submission status: Runtime Error

Solution code:
N = int(input())
X = []
Y = []
for _ in range(N):
    x,y = map(int, input().split())
    X.append(x)
    Y.append(y)
X = np.array(X)
Y = np.array(Y)
X_ = X.reshape((N,1))
Y_ = Y.reshape((N,1))
Z = np.abs(X-X_)+np.abs(Y-Y_)
z = Z.reshape((1,-1))
print(np.max(z))

Submission status: Runtime Error

Solution code:
def main():
  n = int(input())
  a_li , b_li = [] , []
  for _ in range(n):
    x , y = int(input())
    a_li.append(x + y)
    b_li.append(x - y)
    print(max(max(a_li) - min(a_li), max(b_li) - min(b_li)))

if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
import numpy as np
 
n = int(input())
x = np.empty(n, dtype=int)
y = np.empty(n, dtype=int)
 
for i in range(n):
  x[i], y[i] = [int(d) for d in input().split()]

dist = np.max(
  np.abs(x - x[1:].reshape(-1, 1)) \
  + np.abs(y - y[1:].reshape(-1, 1))
)
print(dist)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stding.readline

t = int(input())
po = []

for _ in range(t):
  x,y = list(map(int,input().split()))
  po.append((x,y))
  
po.sort()

dp = [-(10**99) for _ in range(t)]

for i in range(t):
  value = min(x+y, x-y)
  dp[i] = min(dp[i-1], value)
  
best = -9999999999999999999999999999

for i in range(1,t):
  dist = po[i][0] + po[i][1] - dp[i-1]
  best = max(best, dist)
  
print(best)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(imput())
x = np.empty(n, dtype=int)
y = np.empty(n, dtype=int)

for i in range(n):
  x[i], y[i] = [int(d) for d in input().split()]

dist = 0
for i in range(n - 1):
  max(
    dist,
    np.max(np.abs(x[i] * x[i+1:]) + np.abs(y[i] * y[i+1:]))
  )
  
print(dist)

Submission status: Runtime Error

Solution code:
N = int(input())
M = [list(map(int, input().split())) for _ in range(N)]

s = []
l = []
top = 2*(10**9)+1
low = 0
for j in range(N):
    t = sum(M[j])
    if low == t:
        s.append(M[j])
    elif low < t:
        low = t
        s = []
        s.append(M[j])

    if top == t:
        l.append(M[j])
    elif top > t:
        top = t
        l = []
        l.append(M[j])


def cal_man(a, b):
    return abs(a[0] - b[0]) + abs(a[1] - b[1])


s.sort()
l.sort()


high = []
small = []
low = 2*(10**9)+1
top = 0
for j in range(N):
    t = M[j][1] - M[j][0]
    if low > t:
        low = t
        small = []
        small.append(M[j])
    elif low == t:
        small.append(M[j])

    if top < t:
        top = t
        high = []
        high.append(M[j])
    elif top == t:
        high.append(M[j])
high.sort()
small.sort()


print(max([cal_man(s[0], l[-1]), cal_man(s[-1], l[0]),
           cal_man(high[0], small[-1]), cal_man(high[-1], small[0])]))

Submission status: Runtime Error

Solution code:
    N = int(input())
    l = [list(map(int, input().split())) for i in range(N)]
    d=list()
    for i in range(N):
        for j in range(N):
            d.append(abs(l[i][0]-l[j][0]) + abs(l[i][1]-l[j][1]))
    print(max(d))

Submission status: Runtime Error

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N=int(input())
XY = []
xAve = 0
yAve = 0
for _ in range(N):
    x,y=map(int,input().split())
    if (x,y) not in XY
        XY.append((x,y))
        xAve += x
        yAve += y
xAve = xAve//N
yAve = yAve//N
XYnorm = [0]*4
for x,y in XY:
    nX = x-xAve
    nY = y-yAve
    if nX>=0 and nY>0:#第1象限
        XYnorm[0]=max(XYnorm[0],nX+nY)
    if nX <0 and nY >=0:#第2象限
        XYnorm[1]=max(XYnorm[1],-nX+nY)
    if nX <=0 and nY <0:#第3象限
        XYnorm[2]=max(XYnorm[2],-nX-nY)
    if nX >0 and nY <=0:#第4象限
        XYnorm[3]=max(XYnorm[3],nX-nY)
print(int(max(XYnorm[2]+XYnorm[0],XYnorm[3]+XYnorm[1])))

Submission status: Runtime Error

Solution code:
N = int(input())
l = []
for i in range(N):
    l.append([int(x) for x in input().split()])

xlim = []
ylim = []

def cha(a):
    return [a[0]-a[1],a[0]+a[1]]

for i in range(N):
    if cha(l[i])[0] <= cha(l[i])[1]:
        ylim.append(cha(l[i])[1]))
    else:
        xlim.append(cha(l[i])[0])

xlim.sort()
ylim.sort()

if len(xlim)*len(ylim) != 0:
    print(max(-xlim[0]+xlim[-1],-ylim[0]+ylim[-1]))
elif len(xlim) == 0:
    print(-ylim[0]+ylim[-1])
elif len(ylim) == 0:
    print(-xlim[0]+xlim[-1])

Submission status: Runtime Error

Solution code:
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
cheby = []
for i in range(n):
    l = [xy[i][0]-xy[i][1],xy[i][0]+xy[i][1]]
    cheby.append(l)

xmax = 1
xmin = 10**9
ymax = 1
ymin = 10**9
for i in range(n):
    if cheby[i][0] >= xmax :
        xmax = cheby[i][0]
        xa = i
    if cheby[i][0] <= xmin :
        xmin = cheby[i][0]
        xi = i
    if cheby[i][1] >= ymax :
        ymax = cheby[i][1]
        ya = i
    if cheby[i][1] <= ymin :
        ymin = cheby[i][1]
        yi = i

if abs(xmax-xmin) > abs(ymax-ymin):
    print(abs(xy[xa][0]-xy[xi][0])+abs(xy[xa][1]-xy[xi][1]))
else :
    print(abs(xy[ya][0]-xy[yi][0])+abs(xy[ya][1]-xy[yi][1]))

Submission status: Runtime Error

Solution code:
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
cheby = []
for i in range(n):
    l = [xy[i][0]-xy[i][1],xy[i][0]+xy[i][1]]
    cheby.append(l)

xmax = 1
xmin = 10**9
ymax = 1
ymin = 10**9
for i in range(n):
    if cheby[i][0] > xmax :
        xmax = cheby[i][0]
        xa = i
    if cheby[i][0] < xmin :
        xmin = cheby[i][0]
        xi = i
    if cheby[i][1] > ymax :
        ymax = cheby[i][1]
        ya = i
    if cheby[i][1] < ymin :
        ymin = cheby[i][1]
        yi = i

if abs(xmax-xmin) > abs(ymax-ymin):
    print(abs(xy[xa][0]-xy[xi][0])+abs(xy[xa][1]-xy[xi][1]))
else :
    print(abs(xy[ya][0]-xy[yi][0])+abs(xy[ya][1]-xy[yi][1]))

Submission status: Runtime Error

Solution code:
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
cheby = []
for i in range(n):
    l = [xy[i][0]-xy[i][1],xy[i][0]+xy[i][1]]
    cheby.append(l)

xmax = 0
xmin = 10**9
ymax = 0
ymin = 10**9
for i in range(n):
    if cheby[i][0] > xmax :
        xmax = cheby[i][0]
        xa = i
    if cheby[i][0] < xmin :
        xmin = cheby[i][0]
        xi = i
    if cheby[i][1] > ymax :
        ymax = cheby[i][1]
        ya = i
    if cheby[i][1] < ymin :
        ymin = cheby[i][1]
        yi = i

if abs(xmax-xmin) > abs(ymax-ymin):
    print(abs(xy[xa][0]-xy[xi][0])+abs(xy[xa][1]-xy[xi][1]))
else :
    print(abs(xy[ya][0]-xy[yi][0])+abs(xy[ya][1]-xy[yi][1]))

Submission status: Runtime Error

Solution code:
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
cheby = []
for i in range(n):
    l = [xy[i][0]-xy[i][1],xy[i][0]+xy[i][1]]
    cheby.append(l)

xmax = 0
xmin = 10**10
ymax = 0
ymin = 10**10
for i in range(n):
    if cheby[i][0] > xmax :
        xmax = cheby[i][0]
        xa = i
    if cheby[i][0] < xmin :
        xmin = cheby[i][0]
        xi = i
    if cheby[i][1] > ymax :
        ymax = cheby[i][1]
        ya = i
    if cheby[i][1] < ymin :
        ymin = cheby[i][1]
        yi = i

if abs(xmax-xmin) > abs(ymax-ymin):
    print(abs(xy[xa][0]-xy[xi][0])+abs(xy[xa][1]-xy[xi][1]))
else :
    print(abs(xy[ya][0]-xy[yi][0])+abs(xy[ya][1]-xy[yi][1]))

Submission status: Runtime Error

Solution code:
n = int(input())
w = []
for i in range(n):
    x, y = map(int, input().split())
    z.append(x + y)
    w.append(x - y)
z.sort()
w.sort()
print(max(z[-1]-z[0], w[-1]-w[0]))

Submission status: Runtime Error

Solution code:
N=int(input())
a,b,c,d=0,1e10,-1e10,1e10
for i in range(N):
  A,B=int(input().pulit())
  a=max(a,A+B)
  b=min(b,A+B)
  c=max(c,A-B)
  d=min(d,A-B)
print(max(abs(a-b),abs(c-d))

Submission status: Runtime Error

Solution code:
n = int(input())
u = [list(map(int, input().split())) for i in range(n)]
z = [u[i][0] + u[i][1] for i in range(n)]
w = [w[i][0] - w[i][1] for i in range(n)]
d = [max(z)-min(z), max(w)-min(w)]

print(max(d))

Submission status: Runtime Error

Solution code:
n = int(input())
z = [[map(int, input().split())] for i in range(n)]
m = 0
d = 0
for i in range(n-1):
  for j in range(i+1, n):
    d = 0
    d += max(z[i][0] - z[j][0], z[j][0] - z[i][0])
    d += max(z[i][1] - z[j][1], z[j][1] - z[i][1])
    if d>m:
      m = d
print(m)

Submission status: Runtime Error

Solution code:
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())
    xy = [list(map(int,input().split())) for i in range(N)]

    xy = np.array(xy,dtype='int32')
    # print(xy)

    diffs = np.expand_dims(xy,axis=1) - np.expand_dims(xy,axis=0)
    md = np.sum(np.abs(diffs),axis=-1)
    res = md.max()

    # print(diffs)
    # print(md)

    print(res)



main()

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
p=sorted(l,key=lambda x: x[0]+x[1])
q=sorted(l,key=lambda x: x[0]-x[1])
print(max(p[-1]-p[0],q[-1]-q[0]))

Submission status: Runtime Error

Solution code:
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from scipy.spatial import distance


def main():
    N = int(input())
    xy = [list(map(int,input().split())) for i in range(N)]

    xy = np.array(xy)

    md = distance.cdist(xy, xy, metric='minkowski', p=1)


    print(0)



main()

Submission status: Runtime Error

Solution code:
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from scipy.spatial import distance


def main():
    N = int(input())
    xy = [list(map(int,input().split())) for i in range(N)]

    xy = np.array(xy)
    # print(xy)

    md = distance.cdist(xy, xy, metric='minkowski', p=1)
    res = md.max()
    res = int(res)

    # print(diffs)
    # print(md)

    print(res)



main()

Submission status: Runtime Error

Solution code:
n = int(input())


max_z = 0
min_z = 10**10
max_w = 0
min_w = 10**10

for _ in range(n):
    x, y = map(lambda x: int(x), input.split())
    max_z = max(max_z, x + y)
    min_z = min(min_z, x + y)
    max_w = max(max_w, x - y)
    min_w = min(min_w, x - y)

print(max(max_z-min_z, max_w-min_w))

Submission status: Runtime Error

Solution code:
n = int(input())
l = []
for i in range(n):
  l.append(list(map(int,input().split())))
m = []
for i in l:
  a,b = i
  k.append(a+b)
  m.append(a-b)
k.sort()
m.sort()
print(max([k[-1]-k[0],m[-1] -m[0]]))

Submission status: Runtime Error

Solution code:
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())
    print(-1)
    xy = [list(map(int,input().split())) for i in range(N)]
    print(-1)

    xy = np.array(xy)
    # print(xy)

    diffs = xy - xy.T
    print(-1)
    md = np.sum(np.abs(diffs),axis=-1)
    res = md.max()

    # print(diffs)
    # print(md)

    print(res)



main()

Submission status: Runtime Error

Solution code:
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())
    xy = [list(map(int,input().split())) for i in range(N)]
    print(-1)

    xy = np.array(xy)
    # print(xy)

    diffs = xy - xy.T
    print(-1)
    md = np.sum(np.abs(diffs),axis=-1)
    res = md.max()

    # print(diffs)
    # print(md)

    print(res)



main()

Submission status: Runtime Error

Solution code:
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())
    xy = [list(map(int,input().split())) for i in range(N)]

    xy = np.array(xy)
    # print(xy)

    diffs = xy - xy.T
    print(-1)
    md = np.sum(np.abs(diffs),axis=-1)
    res = md.max()

    # print(diffs)
    # print(md)

    print(res)



main()

Submission status: Runtime Error

Solution code:
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())
    xy = [list(map(int,input().split())) for i in range(N)]

    xy = np.array(xy)
    # print(xy)

    diffs = xy - xy.T
    md = np.sum(np.abs(diffs),axis=-1)
    res = md.max()

    # print(diffs)
    # print(md)

    print(res)



main()

Submission status: Runtime Error

Solution code:
N = int(input())
#i = 0
a_max = 2
a_min = 2*(10**9)
s_max = 0
s_min = 10**9

for i in N:
    x,y=map(int,input().split())
    add = x+y
    sub = x-y

    if add > a_max:
        a_max = add
    if add < a_min:
        a_min = add
    if sub > s_max:
        s_max = sub
    if sub < s_max:
        s_max = sub

d_add = a_max - a_min
d_sub = s_max - s_min

print(max(d_add,d_sub))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back


int main() {
  ll N; cin>>N;
  ll maxa=-3e9,mina=3e9;
  ll maxb=-3e9,minb=3e9;
  ll x,y;
  rep(i,N) {
    cin>>x>>y;
    maxa=max(maxa,x+y);
    mina=min(mina,x+y);
    maxb=max(maxb,x-y);
    minb=min(minb,x-y);
  }
  cout<<max(abs(maxa-mina),abs(maxb-minb))<<endl;
}