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:
N=int(input())

X=[]
Y=[]
Z=[]

import sys

if N==2:
    x_1,y_1=map(int,input().split())
    x_2,y_2=map(int,input().split())
    print(abs(x_1-x_2)+(y_1-y_2))
    sys.exit()
    
for i in range(N):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
    if [x,y] not in Z:
        Z.append([x,y])
    #Z.append([x,y])

def det(p, q):
    return p[0]*q[1] - p[1]*q[0]


def sub(p, q):
    return (p[0]-q[0], p[1]-q[1])


def get_convex_hull(points):
    # どの3点も直線上に並んでいないと仮定する。
    n = len(points)
    points.sort()
    size_convex_hull = 0
    ch = []
    for i in range(n):
        while size_convex_hull > 1:
            v_cur = sub(ch[-1], ch[-2])
            v_new = sub(points[i], ch[-2])
            if det(v_cur, v_new) > 0:
                break
            size_convex_hull -= 1
            ch.pop()
        ch.append(points[i])
        size_convex_hull += 1

    t = size_convex_hull
    for i in range(n-2, -1, -1):
        while size_convex_hull > t:
            v_cur = sub(ch[-1], ch[-2])
            v_new = sub(points[i], ch[-2])
            if det(v_cur, v_new) > 0:
                break
            size_convex_hull -= 1
            ch.pop()
        ch.append(points[i])
        size_convex_hull += 1

    return ch[:-1]

W=get_convex_hull(Z)

W_len=len(W)

dp=[-1]*W_len

for i in range(W_len):
    if dp[i]!=-1:
        continue
    dist=0
    ind=-1
    for j in range(i+1,W_len):
        tmp = abs(W[i][0]-W[j][0])+abs(W[i][1]-W[j][1])
        if dist < tmp:
            dist = tmp
            ind = j
    dp[i]=dist
    dp[j]=dist

print(max(dp))

Submission status: Runtime Error

Solution code:
points = []
max = 0
for i in range(int(input()):
    a,b = map(int, input().split())
	points.append([a,b])
               
for i in points:
    tempanswer = 0
	for j in points[i:]:
        tempanswer = abs(j[0] - i[0]) + abs(i[1] - j[1])
    	if tempanswer > max:
        	max = tempanswer
               
print(max)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
nums=[]
for _ in range(N):
  nums.append(list(map(int,input().split())))
spots = np.array(nums)
all_diffs = np.expand_dims(spots, axis=1) - np.expand_dims(spots, axis=0)
distance = np.sum(abs(all_diffs), axis=-1)
print(distance)
print(distance.max())

Submission status: Runtime Error

Solution code:
import numpy as np
from scipy.spatial import distance
def main():
    n = int(input())
    lis = []
    for i in range(n+1):
        x,y = map(int, input().split())
        lis.append([x,y])
    M = np.array(lis)
    try:
        dist_M = distance.cdist(M, M, metric='cityblock')
        print(str(np.max(dist_M)).split('.')[0])
    except:
        print(0)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n=int(input())
l=[input().split() for _ in range(n)]
dp=[0]*(n+2)
dp1=[0]*(n+2)
for i in range(n):
    for j in range(1,n):
        dp[i+j] = max(abs(int(l[i][0]) - int(l[j][0])), dp[i+j-1])
        dp1[i+j] = max(abs(int(l[i][1]) - int(l[j][1])), dp[i+j-1])
dp=sorted(dp)
dp1=sorted(dp1)
print(int(dp[-1])+int(dp1[-1]))

Submission status: Runtime Error

Solution code:
import itertools

n = int(input())
ps = list({
    tuple(map(int, input().split()))
    for _ in range(n)
})

g = sum([p[0] for p in ps]) / len(ps)
g = sum([p[1] for p in ps]) / len(ps)

maxd = 0
maxp = ps[0]
for p in ps:
    d = abs(g[0] - p[0]) + abs(g[1] - p[1])
    if d > maxd:
        maxp = p
        maxd = d

maxd = 0
for p in ps:
    maxd = max(maxd, abs(maxp[0] - p[0]) + abs(maxp[1] - p[1]))
print(maxd)

Submission status: Runtime Error

Solution code:
n = int(input())
 
c = 0
c1 = 0
xx = 0
yy = 0
 
for i in range(n):
    p = input()
    q = p.split(" ")
  
    x = int(q[0])
    y = int(q[1])
  
    k = i + 1
    for j in range(k, n):
        m = input()
        l = m.split(" ")
    
        a = int(l[0])
        b = int(l[1])
    
        if x >= a and y >= b:
            if (x - a) + (y - b) > (xx + yy):
                xx = x - a
                yy = y - b
      
            if (x - a) + (y - b) == (xx + yy):
                c += 1
    
        elif x < a and y < b:
            if (a - x) + (b - y) > (xx + yy):
                xx = a - x
                yy = b - y
      
            if (a - x) + (b - y) == (xx + yy):
                c += 1
    if k >= 2:   
        for j in range(0, k - 1):
            m = input()
            l = m.split(" ")

            a = int(l[0])
            b = int(l[1])

            if x >= a and y >= b:
                if (x - a) + (y - b) > (xx + yy):
                    xx = x - a
                    yy = y - b

                if (x - a) + (y - b) == (xx + yy):
                    c += 1

            elif x < a and y < b:
                if (a - x) + (b - y) > (xx + yy):
                    xx = a - x
                    yy = b - y

                if (a - x) + (b - y) == (xx + yy):
                    c += 1
 
print(c)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[list(map(int, input().split()))]

temp1=cp.deepcopy(A[0])
temp2=cp.deepcopy(A[0])
for i in range(N-1):
    f=0
    x,y=map(int, input().split())
    if abs(temp1[0]-x)+abs(temp1[1]-y):
        temp2[0]=x
        temp2[1]=y
        f=1
    if f==1:
        for i,j in A:
           if max(abs(temp2[0]-i)+abs(temp2[1]-j),abs(temp2[0]-temp1[0])+abs(temp2[1]-temp1[1])):
               temp1[0]=i
               temp2[1]=j
    A.append([x,y])


print(abs(temp2[0]-temp1[0])+abs(temp2[1]-temp1[1]))

Submission status: Runtime Error

Solution code:
for i, (x, y) in enumerate(pairs):
    xy = x+y
    if i == 0:
        min_x = max_x = x
        min_y = max_y = y
        min_xi = [0]
        max_xi = [0]
        min_yi = [0]
        max_yi = [0]

        min_xyi = [0]
        max_xyi = [0]
        min_xy = max_xy = xy 
    else:
        if x < min_x:
            min_xi = [i]
            min_x = x
        elif x == min_x:
            min_xi.append(i)

        if y < min_y:
            min_yi = [i]
            min_y = y
        elif y == min_y:
            min_yi.append(i)

        if xy < min_xy:
            min_xyi = [i]
            min_xy = xy
        elif xy == min_xy:
            min_xyi.append(i)

        if x > max_x:
            max_xi = [i]
            max_x = x
        elif x == min_x:
            max_xi.append(i)

        if y > max_y:
            max_yi = [i]
            max_y = y
        elif y == min_y:
            max_yi.append(i)

        if xy > max_xy:
            max_xyi = [i]
            max_xy = xy
        elif xy == min_xy:
            max_xyi.append(i)



max_iter = 100

fmax_dist = -2

final_out = 0

#print("min_xi", min_xi, "min_yi", min_yi, "max_xi", max_xi, "max_yi", max_yi, "min_xyi", min_xyi, "max_xyi", max_xyi)

first_jibuns = set([random.randint(0, n-1) for i in range(100)])
#first_jibuns = set(min_xi + max_xi + min_yi + max_yi + min_xyi + max_xyi + randoms)

True
for first_jibun in first_jibuns:
    jibun = first_jibun
    #for iter_i in range(max_iter):
    max_dist = -1
    while True:
        jx, jy = pairs[jibun]
        for cur_aite in range(n):
            if jibun == cur_aite:
                continue
            ax, ay = pairs[cur_aite]
            cdist = abs(jx-ax) + abs(jy-ay)
            
            if cdist > max_dist:
                next_jibun = cur_aite
                max_dist = cdist

        if fmax_dist == max_dist:
            out = max_dist
            break
        else:
            jibun = next_jibun 
            fmax_dist = max_dist

    final_out = max(final_out, out)
    
    
print(final_out)

Submission status: Runtime Error

Solution code:
N = int(input())

A = list()
for i in range(N):
  A.append(list(map(int,input().split())))
ret = 0
for i in range(N-1):
  for j in range(i + 1,N):
    tmp = abs(A[i][0] - A[j][0]) + abs(A[i][1] - A[j][1])
    if ret < tmp:
      ret = tmp
return ret

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 = np.expand_dims(xy,axis=1) - np.expand_dims(xy,axis=0)
    md = np.sum(np.abs(diffs),axis=2)
    res = md.max()
    res = int(res)

    # print(diffs)
    # print(md)

    print(res)



main()

Submission status: Runtime Error

Solution code:
N = int(input())
M=N*N
x = [0] * N
y = [0] * N
z=[0]*M
for i in range(0,N):
    x[i], y[i] = map(int, input().split())
for i in range(0,M):
    z.append(abs(x[i//N]-x[i%N])+abs(y[i//N]-y[i%N]))
print(max(z))

Submission status: Runtime Error

Solution code:
#ABC178 E
import numpy as np
n = int(input())
l = [list(map(int, input().split())) for l in range(n)]
list = np.array(l)
#print(list)
all_diffs = np.expand_dims(list, axis=1) - np.expand_dims(list, axis=0)
#print(all_diffs)
distance = np.sum(abs(all_diffs), axis=-1)
#print(distance)
ans = np.max(distance)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

xy = [ [0,0] ]*N

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

max = 0

xy = list(set(xy))

for s in range(N-1):
  for t in range(s+1,N):
    manh = 0
    x_d = xy[s][0] - xy[t][0]
    y_d = xy[s][1] - xy[t][1]
    if x_d > 0:
      manh += x_d
    else:
      manh -= x_d
    if y_d > 0:
      manh += y_d
    else:
      manh -= y_d
    
    if manh > max:
      max = manh

print(max)

Submission status: Runtime Error

Solution code:
N=int(input())
xy=[map(int,input().split()) for i in range(N)]
x,y=[list(j) for j in zip(*xy)]

m=0
t=0
for k in range(N):
  for l in range(k,N-1):
    if (abs(x[k]-x[l]))<t:
      m=m
    else:
      if (abs(x[k]-x[l])+abs(y[k]-y[l]))>m:
        t=(abs(x[k]-x[l])
        m=(abs(x[k]-x[l])+abs(y[k]-y[l]))
    
print(m)

Submission status: Runtime Error

Solution code:
def solve():
    N = int(input())

    xs, ys = [], []
    for _ in range(N):
        x, y = map(int, input().split())
        xs.append(x)
        ys.append(y)
    
    T, B = max(ys), min(ys)
    L, R = min(xs), max(xs)

    # print(T, B, L, R)

    if T == B:
        return abs(R - L)

    if L == R:
        return abs(T - B)

    # T, B
    top_l, top_r = 10**10, -1
    bot_l, bot_r = 10**10, -1
    for i in range(N):
        if ys[i] == T:
            top_l = min(top_l, xs[i])
            top_r = max(top_r, xs[i])
        if ys[i] == B:
            bot_l = min(bot_l, xs[i])
            bot_r = max(bot_r, xs[i])

    # print(top_l, top_r)
    # print(bot_l, bot_r)

    # L, R
    left_t, left_b = -1, 10**10
    right_t, right_b = -1, 10**10
    for i in range(N):
        if xs[i] == L:
            left_t = max(left_t, ys[i])
            left_b = min(left_b, ys[i])
        if xs[i] == R:
            right_t = max(right_t, ys[i])
            right_b = min(right_b, ys[i])

    # print(left_t, left_b)
    # print(right_t, right_b)

    ans = -1
    for i in range(N):
        if ys[i] == T:
            d1 = abs(T - B) + abs(xs[i] - bot_l)
            d2 = abs(T - B) + abs(xs[i] - bot_r)
            ans = max(ans, max(d1, d2))
        if ys[i] == B:
            d1 = abs(T - B) + abs(xs[i] - top_l)
            d2 = abs(T - B) + abs(xs[i] - top_r)
            ans = max(ans, max(d1, d2))
        if xs[i] == L:
            d1 = abs(R - L) + abs(ys[i] - right_t)
            d1 = abs(R - L) + abs(ys[i] - right_b)
            ans = max(ans, max(d1, d2))
        if xs[i] == R:
            d1 = abs(R - L) + abs(ys[i] - left_t)
            d1 = abs(R - L) + abs(ys[i] - left_b)
            ans = max(ans, max(d1, d2))
    return ans


print(solve())

Submission status: Runtime Error

Solution code:
N = int(input())
xpy_max = 0
xpy_min = 10 ** 9 + 3
xmy_max = 0
xmy_min = 10 ** 9 + 3
for i in range(N):
    x, y = map(int, input().split())
    if x + y <= xpy_min:
        xpy_min = x + y
        a = (x, y)
    if x + y >= xpy_max:
        xpy_max = x + y
        b = (x, y)
    if x - y >= xmy_max:
        xmy_max = x - y
        c = (x, y)
    if x - y <= xmy_min:
        xmy_min = x - y
        d = (x, y)
ans = max(b[0] - a[0] + b[1] - a[1], c[0] - d[0] + c[1] - d[1])
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())

X=[]
Y=[]
Z=[]

import sys

if N==2:
    x_1,y_1=map(int,input().split())
    x_2,y_2=map(int,input().split())
    print(abs(x_1-x_2)+(y_1-y_2))
    sys.exit()
    
for i in range(N):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
    if [x,y] not in Z:
        Z.append([x,y])
    #Z.append([x,y])


def signed_area(p1, p2, p3):
    '''符号付き面積を計算 '''

    area = (((p2[0] - p1[0]) * (p3[1] - p1[1])) - ((p3[0] - p1[0]) * (p2[1] - p1[1]))) / 2
    return area


def convex_hull(p_list):
    '''グラハムの凸包走査 '''

    p_sort = []
    for i in p_list:
        p_sort.append(i[0])

    # x座標が最小のものをリストの先頭に配置。
    min_index = p_sort.index(min(p_sort))
    min_p = p_list.pop(min_index)
    p_list.insert(0, min_p)

    # 座標最小の点と他の点との角度順にソート ソートアルゴリズムに選択の余地が有る。
    p_length = len(p_list)
    count = 0
    index = 0
    while True:
        count += 1
        index += 1

        area_sign = signed_area(p_list[0], p_list[index], p_list[index + 1])

        # 符号付き面積が負ならば点を入れ替え
        if area_sign < 0:
            p_list[index], p_list[index + 1] = p_list[index + 1], p_list[index]
            count = 0

        if count == p_length - 1:
            break

        if index == p_length - 2:
            index = 0

    # 凹部の点を削除する。
    index = -1
    count = 0
    while True:
        index += 1
        count += 1

        area_sign = signed_area(p_list[index], p_list[index + 1], p_list[index + 2])
        if area_sign < 0:
            del p_list[index + 1]
            count = 0

        if count == len(p_list):
            break

        if index >= len(p_list) - 3:
            index = -1
    return p_list
    
W=convex_hull(Z)

W_len=len(W)

dp=[-1]*W_len

for i in range(W_len):
    if dp[i]!=-1:
        continue
    dist=0
    ind=-1
    for j in range(i+1,W_len):
        tmp = abs(W[i][0]-W[j][0])+abs(W[i][1]-W[j][1])
        if dist < tmp:
            dist = tmp
            ind = j
    dp[i]=dist
    dp[j]=dist
print(max(dp))

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())
    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象限
        if XYnorm[0]<= nX+nY:
            XYnorm[0] = nX+nY
            XY0 =[x,y]

    if nX <=0 and nY >=0:#第2象限
        if XYnorm[1]<= -nX+nY:
            XYnorm[1] = -nX+nY
            XY1 =[x,y]
            
    if nX <=0 and nY <=0:#第3象限
        if XYnorm[2]<= -nX-nY:
            XYnorm[2] = -nX-nY
            XY2 =[x,y]
            
    if nX >=0 and nY <=0:#第4象限
        if XYnorm[3]<= nX-nY:
            XYnorm[3] = nX-nY
            XY3 =[x,y]

try:
    XY01 = abs(XY0[0]-XY1[0])+abs(XY0[1]-XY1[1])
except:
    XY01=0
    
try:
    XY02 = abs(XY0[0]-XY2[0])+abs(XY0[1]-XY2[1])
except:
    XY02=0
try:
    XY03 = abs(XY0[0]-XY3[0])+abs(XY0[1]-XY3[1])
except:
    XY03=0
try:
    XY12 = abs(XY1[0]-XY2[0])+abs(XY1[1]-XY2[1])
except:
    XY12 = 0
try:
    XY13 = abs(XY1[0]-XY3[0])+abs(XY1[1]-XY3[1])
except:
    XY13 = 0
try:
    XY23 = abs(XY2[0]-XY3[0])+abs(XY2[1]-XY3[1])
except:
    XY23 = 0
print(max([XY01,XY02,XY03,XY12,XY13,XY23])

Submission status: Runtime Error

Solution code:
n=int(input())
a_list=[list(map(int,input().split())) for i in range(n)]
import  numpy as np
A=[]
for i in range(n):
    A.append(a_list[i][0]**2+a_list[i][1]**2)
A2=np.array(A)
maxIndex = [i for i, x in enumerate(a) if x == max(a)]
minIndex = [i for i, x in enumerate(a) if x == min(a)]
B=[]
for i in range(len(maxIndex)):
    for j in range(len(minIndex)):
        B.append(abs(a_list[i][0]-a_list[j][0])+abs(a_list[i][1]-a_list[j][1]))
print(max(B))

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())
        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象限
            if XYnorm[0]<= nX+nY:
                XYnorm[0] = nX+nY
                XY0 =[x,y]

        if nX <=0 and nY >=0:#第2象限
            if XYnorm[1]<= -nX+nY:
                XYnorm[1] = -nX+nY
                XY1 =[x,y]
                
        if nX <=0 and nY <=0:#第3象限
            if XYnorm[2]<= -nX-nY:
                XYnorm[2] = -nX-nY
                XY2 =[x,y]
                
        if nX >=0 and nY <=0:#第4象限
            if XYnorm[3]<= nX-nY:
                XYnorm[3] = nX-nY
                XY3 =[x,y]

    try:
        XY01 = abs(XY0[0]-XY1[0])+abs(XY0[1]-XY1[1])
    except:
        XY01=0
        
    try:
        XY02 = abs(XY0[0]-XY2[0])+abs(XY0[1]-XY2[1])
    except:
        XY02=0
    try:
        XY03 = abs(XY0[0]-XY3[0])+abs(XY0[1]-XY3[1])
    except:
        XY03=0
    try:
        XY12 = abs(XY1[0]-XY2[0])+abs(XY1[1]-XY2[1])
    except:
        XY12 = 0
    try:
        XY13 = abs(XY1[0]-XY3[0])+abs(XY1[1]-XY3[1])
    except:
        XY13 = 0
    try:
        XY23 = abs(XY2[0]-XY3[0])+abs(XY2[1]-XY3[1])
    except:
        XY23 = 0
    print(max([XY01,XY02,XY03,XY12,XY13,XY23]))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
nums=[]
for _ in range(N):
  nums.append(list(map(int,input().split())))
cities = np.array(nums)
all_diffs = np.expand_dims(cities, axis=1) - np.expand_dims(cities, axis=0)
degree_distance = np.sum(abs(all_diffs), axis=-1)

print(degree_distance.max())

Submission status: Runtime Error

Solution code:
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())
0<=a<=N-1,0<=b<=N-1,a!=b
for a in range(N):
    for b in range(N):
        P=list(abs(x[a]-x[b])+abs(y[a]-y[b]))
l=sum(P)
print(P.count(l))

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())
    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象限
        if XYnorm[0]<= nX+nY:
            XYnorm[0] = nX+nY
            XY0 =[x,y]

    if nX <=0 and nY >=0:#第2象限
        if XYnorm[1]<= -nX+nY:
            XYnorm[1] = -nX+nY
            XY1 =[x,y]
            
    if nX <=0 and nY <=0:#第3象限
        if XYnorm[2]<= -nX-nY:
            XYnorm[2] = -nX-nY
            XY2 =[x,y]
            
    if nX >=0 and nY <=0:#第4象限
        if XYnorm[3]<= nX-nY:
            XYnorm[3] = nX-nY
            XY3 =[x,y]

try:
    XY01 = abs(XY0[0]-XY1[0])+abs(XY0[1]-XY1[1])
except:
    XY01=0
    
try:
    XY02 = abs(XY0[0]-XY2[0])+abs(XY0[1]-XY2[1])
except:
    XY02=0
try:
    XY03 = abs(XY0[0]-XY3[0])+abs(XY0[1]-XY3[1])
except:
    XY03=0
try:
    XY12 = abs(XY1[0]-XY2[0])+abs(XY1[1]-XY2[1])
except:
    XY12 = 0
try:
    XY13 = abs(XY1[0]-XY3[0])+abs(XY1[1]-XY3[1])
except:
    XY13 = 0
try:
    XY23 = abs(XY2[0]-XY3[0])+abs(XY2[1]-XY3[1])
except:
    XY13 = 0
print(max([XY01,XY02,XY03,XY12,XY13,XY23]))

Submission status: Runtime Error

Solution code:
N = int(input())
hw = [[int(i) for i in input().split()] for _ i range(N)]

minD = 2*10**9
min = 0
maxD = 0
max = 0

for i in range(N):
    if (minD > (hw[i][0] + hw[i][1])):
        minD = hw[i][0] + hw[i][1]
        min = i
    if (maxD < hw[i][0] + hw[i][1]):
        maxD = hw[i][0] + hw[i][1]
        max = i

print(abs(hw[max][0] - hw[min][0]) + abs(hw[max][1] - hw[min][1]))

Submission status: Runtime Error

Solution code:
n = int(input())
c = [list(map(int,input().split())) for i in range(n)]
c= list(map(list, set(map(tuple, c))))
ans = 0
if len(c) >= 2:
  for i in range(n):
    for l in range(i,n):
      tmp = abs(c[i][0] - c[l][0]) + abs(c[i][1]-c[l][1])
      ans = max(ans,tmp)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
lx=[]
ly=[]
for i in range(n):
  x,y=map(int,input().split())
  lx.append(x+y)
  ly.append(x-y)
ax,bx,ay,by=max(lx),min(lx),max(ly),min(ly)
print(max(ax-bx,ay-by))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
xy = list()
for i in range(N):
    x,y = map(int,input().split())
    xy.append([x,y])
XY = np.array(xy)

dif = np.expand_dims(XY,axis=1) - np.expand_dims(XY,axis=0)
dis = np.sum(np.abs(dif), axis=-1).astype(np.int64)


idx = np.unravel_index(np.argmax(dis),dis.shape)
print(dis[idx])

Submission status: Runtime Error

Solution code:
n=int(input())
l=[input().split() for _ in range(n)]
dp=[0]*n*n
dp1=[0]*n*n
for i in range(n):
    for j in range(1,n):
        dp[i+j] = max(abs(int(l[i][0]) - int(l[j][0])), dp[i+j-1])
        dp1[i+j] = max(abs(int(l[i][1]) - int(l[j][1])), dp[i+j-1])
dp=sorted(dp)
dp1=sorted(dp1)
print(int(dp[-1])+int(dp1[-1]))

Submission status: Runtime Error

Solution code:
from itertools import combinations

N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

min_diff = 10**9
max_diff = 1
min_sum = 2 * 10**9
max_sum = 2

for x,y in XY:
    min_diff = min(x-y, min_x)
    max_diff = max(x-y, max_x)
    min_sum = min(x+y, min_sum)
    max_sum = max(x+y, max_sum)

cand_set = set()
for x,y in XY:
    if x-y in (min_diff, max_diff) or x+y in (min_sum, max_sum):
        cand_set.add((x, y))

dist = 0
for p1, p2 in combinations(cand_set, 2):
    print(p1, p2)
    dist = max(dist, abs(p1[0]-p2[0]) + abs(p1[1]-p2[1]))
    
print(dist)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[input().split() for _ in range(n)]
dp=[0]*n*n
dp1=[0]*n*n
for i in range(n):
    for j in range(1,n):
        dp[i+j] = max(abs(int(l[i][0]) - int(l[j][0])), dp[i+j-1])
        dp1[i+j] = max(abs(int(l[i][1]) - int(l[j][1])), dp[i+j-1])
dp=sorted(dp)
dp1=sorted(dp1)
print(dp[-1]+dp1[-1])

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
a = [[0] *2] * N
for i in range(N):
    a[i] = list(map(int, input().split()))
cities = np.array(a)

all_diffs = np.expand_dims(cities, axis=1) - np.expand_dims(cities, axis=0)
distance = np.sum(np.abs(all_diffs), axis=-1)

print(np.max(distance))

Submission status: Runtime Error

Solution code:
N = int(input())

ListN = [[0 for i in range(2)] for j in range(N)]

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

ListN = list(map(list, set(map(tuple, ListN))))
ListN.sort(reverse=True)
m = 0
minN = ListN[0][0] + ListN[0][1]
maxN = ListN[0][0] + ListN[0][1]

print((ListN[0][0] - ListN[0][0]) + abs(ListN[N-1][1] - ListN[N-1][1]))

Submission status: Runtime Error

Solution code:
N=int(input())

X=[]
Y=[]
Z=[]

for i in range(N):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
    Z.append([x,y])

def signed_area(p1, p2, p3):
    '''符号付き面積を計算 '''

    area = (((p2[0] - p1[0]) * (p3[1] - p1[1])) - ((p3[0] - p1[0]) * (p2[1] - p1[1]))) / 2
    return area


def convex_hull(p_list):
    '''グラハムの凸包走査 '''

    p_sort = []
    for i in p_list:
        p_sort.append(i[0])

    # x座標が最小のものをリストの先頭に配置。
    min_index = p_sort.index(min(p_sort))
    min_p = p_list.pop(min_index)
    p_list.insert(0, min_p)

    # 座標最小の点と他の点との角度順にソート ソートアルゴリズムに選択の余地が有る。
    p_length = len(p_list)
    count = 0
    index = 0
    while True:
        count += 1
        index += 1

        area_sign = signed_area(p_list[0], p_list[index], p_list[index + 1])

        # 符号付き面積が負ならば点を入れ替え
        if area_sign < 0:
            p_list[index], p_list[index + 1] = p_list[index + 1], p_list[index]
            count = 0

        if count == p_length - 1:
            break

        if index == p_length - 2:
            index = 0

    # 凹部の点を削除する。
    index = -1
    count = 0
    while True:
        index += 1
        count += 1

        area_sign = signed_area(p_list[index], p_list[index + 1], p_list[index + 2])
        if area_sign < 0:
            del p_list[index + 1]
            count = 0

        if count == len(p_list):
            break

        if index >= len(p_list) - 3:
            index = -1
    return p_list
    
W=convex_hull(Z)

W_len=len(W)

dp=[-1]*W_len

for i in range(W_len):
    if dp[i]!=-1:
        continue
    dist=0
    ind=-1
    for j in range(i+1,W_len):
        tmp = abs(X[i]-X[j])+abs(Y[i]-Y[j])
        if dist < tmp:
            dist = tmp
            ind = j
    dp[i]=dist
    dp[j]=dist
print(max(dp))

Submission status: Runtime Error

Solution code:
N = int(input())

ListN = [[0 for i in range(2)] for j in range(N)]

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

ListN = list(map(list, set(map(tuple, ListN))))
ListN.sort(reverse=True)
m = 0
minN = ListN[0][0] + ListN[0][1]
maxN = ListN[0][0] + ListN[0][1]

print(ListN[0][0] - ListN[0][0]) + abs(ListN[N-1][1] - ListN[N-1][1])

Submission status: Runtime Error

Solution code:
N = int(input())
XY = []
for i in range(N):
  val = input()
  if val:
    XY.append(val)

V=[]
c = 0
for i in range(N):
  for j in range(i+1,N):
    V.append(abs(int(XY[i][0])-int(XY[j][0]))+abs(int(XY[i][2])-int(XY[j][2])))

print(max(V))

Submission status: Runtime Error

Solution code:
n = int(input())

c = 0
xx = 0
yy = 0

for i in range(n):
  p = input()
  q = p.split(" ")
  
  x = int(q[0])
  y = int(q[1])
  
  k = i + 1
  for j in range(k, n):
    m = input()
    l = m.split(" ")
    
    a = int(l[0])
    b = int(l[1])
    
    if x >= a and y >= b:
      if (x - a) + (y - b) > (xx + yy):
        xx = x - a
        yy = y - b
      
      if (x - a) + (y - b) == (xx + yy):
        c += 1
    
    elif x < a and y < b:
      if (a - x) + (b - y) > (xx + yy):
        xx = a - x
        yy = b - y
      
      if (a -x) + (b - y) == (xx + yy):
        c += 1

print(c)

Submission status: Runtime Error

Solution code:
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())
1<=a<=N,1<=b<=N,a!=b
for a in range(1,N+1):
    for b in range(1,N+1):
        P=list(abs(x[a]-x[b])+abs(y[a]-y[b]))
l=sum(P)
print(P.count(l))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
a = [[0] *2] * N
for i in range(N):
    a[i] = list(map(int, input().split()))
#print(a)
cities = np.array(a)
    
all_diffs = np.expand_dims(cities, axis=1) - np.expand_dims(cities, axis=0)
#print(all_diffs)
degree_distance = np.sum(np.abs(all_diffs), axis=-1)
#print(degree_distance)
distance = (degree_distance).astype(np.int32)

print(np.max(distance))

Submission status: Runtime Error

Solution code:
import numpy as np
from scipy.spatial import distance
def main():
    n = int(input())
    lis = []
    for i in range(n):
        x,y = map(int, input().split())
        lis.append([x,y])
    M = np.array(lis)
    dist_M = distance.cdist(M, M, metric='cityblock')
    print(int(np.max(dist_M)))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
from numba import njit

N = int(input())
x=[0]*N
y=[0]*N
add=[0]*N
for i in range(N):
    xy=list(map(int,input().split()))
    x[i]=xy[0]
    y[i]=xy[1]
    add=x[i]+y[i]

@njit
def solve(N, x, y, add):
    temp=np.array(add)
    index_list=np.argsort(temp)
    return int(abs(x[index_list[0]-x[index_list[N-1])+abs(y[index_list[0]-y[index_list[N-1]))
print(solve(N,x,y,add))

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
N = int(input())
mx = - float("inf")
nums=[]

for _ in range(N):
  nums.append(list(map(int,input().split())))
cities = np.array(nums)
all_diffs = np.expand_dims(cities, axis=1) - np.expand_dims(cities, axis=0)
degree_distance = np.sum(abs(all_diffs), axis=-1)

print(degree_distance.max())

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())
    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象限
        if XYnorm[0]<= nX+nY:
            XYnorm[0] = nX+nY
            XY0 =[x,y]

    if nX <=0 and nY >=0:#第2象限
        if XYnorm[1]<= -nX+nY:
            XYnorm[1] = -nX+nY
            XY1 =[x,y]
            
    if nX <=0 and nY <=0:#第3象限
        if XYnorm[2]<= -nX-nY:
            XYnorm[2] = -nX-nY
            XY2 =[x,y]
            
    if nX >=0 and nY <=0:#第4象限
        if XYnorm[3]<= nX+nY:
            XYnorm[3] = nX+nY
            XY3 =[x,y]
XY02 = abs(XY0[0]-XY2[0])+abs(XY0[1]-XY2[1])
XY13 = abs(XY1[0]-XY3[0])+abs(XY1[1]-XY3[1])
print(max(XY02,XY13))

Submission status: Runtime Error

Solution code:
n = int(input())

edge0 = list(map(lambda x: int(x), input().split()))
edge1 = list(map(lambda x: int(x), input().split()))
dis = abs(edge0[0]-edge1[0]) + abs(edge0[1]-edge1[1])

for _ in range(n-2):
    x, y = map(lambda x: int(x), input().split())
    if (x < min(edge0[0], edge1[0])) | (max(edge0[0], edge1[0]) < x) | (y < min(edge0[1], edge1[1])) | (max(edge0[1], edge1[1]) < y):
            dis_from_edge0 = abs(x-edge0[0]) + abs(y-edge0[1])
            dis_from_edge1 = abs(x-edge1[0]) + abs(y-edge1[1])

#             print(dis_from_edge0, dis_from_edge1)
            # 更新なし
            if max(dis_from_edge0, dis_from_edge1) <= dis:
#                 print('#1', edge0, edge1, dis)
                continue
            # どちらも更新
            if min(dis_from_edge0, dis_from_edge1) > dis:
                if dis_from_edge0 < dis_from_edge1:
                    dis  = dis_from_edge1
                    edge0 = [x, y]
                else:
                    dis = dis_from_edge0
                    edge1 = [x, y]
#                 print('#2', edge0, edge1, dis)
                continue
            if dis_from_edge0 > dis_from_edge1:
                dis = dis_from_edge0
                edge1 = [x, y]
#                 print('#3', edge0, edge1, dis)
                continue
            else:
                dis = dis_from_edge1
                edge0 = [x, y]
            h
print(dis)

    #     x_max = max(x, x_max)
    #     x_min = min(x, x_min)
    #     y_max = max(y, y_max)
    #     y_min = min(y, y_min)