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:
#include "bits/stdc++.h"
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define int long long int
#define tc int t; cin>>t; while(t--)
#define fora(i,n) for(int i=0;i<n;i++)
#define forb(i,a,n) for(int i=a;i<n;i++)
#define dbg(x)    { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y)  { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define mod 1000000007
#define pb push_back
#define pii pair<int,int>
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<class T> T power(T N,T P){ return (P==0)?  1: N*power(N,P-1);}

int32_t main()
{
    fastio
    int n; cin>>n;
    pii arr[n];
    fora(i,n) cin>>arr[i].first>>arr[i].second;
    sort(arr,arr+n,[](pii x, pii y) { return (x.first+x.second<y.first+y.second);});
    cout<<abs((arr[n-1].first+arr[n-1].second)-(arr[0].first+arr[0].second));
    

    return 0;


}

Submission status: Runtime Error

Solution code:
n = int(input())
c = []
for _ in range(n):
    c.append(list(map(int,input().split())))

ans = 0
a = 100000000000000
m = 0
lm = 0
rm = 0
lt  = []
rt  = []
lb = []
rb = []

for l in c:
    m = max(m,l[0]+l[1])
    a = min(a,l[0]+l[1])
    if l[0] > l[1]:
        rm = max(rm,l[0]-l[1])
    if l[0] < l[1]:
        lm = max(lm,l[1]-l[0])

for l in c:
    if l[0] + l[1] == m:
        rt.append(l)
    if l[0] + l[1] == a:
        lb.append(l)
    if l[0] > l[1] and l[0] - l[1] == rm:
        rb.append(l)
    if l[0] < l[1] and l[1] - l[0] == lm:
        lt.append(l)


if lt is not None and rb is not None:
    i = lt[0]
    j = rb[0]
    ans = max(ans,abs(i[0]-j[0])+abs(i[1]-j[1]))

if rt is not None and lb is not None:
    i = rt[0]
    j = lb[0]
    ans = max(ans,abs(i[0]-j[0])+abs(i[1]-j[1]))
print(ans)

Submission status: Runtime Error

Solution code:
def main():
	N = int(input())
	p = []
	for i in range(N):
		x, y = [int(a) for a in input().split(" ")]
		p.append({"x" : x, "y" : y})
	aveX = 0
	aveY = 0
	for i in range(N):
		aveX += p[i]["x"]
		aveY += p[i]["y"]
	aveX /= N
	aveY /= N
	for i in range(N):
		p[i]["d"] = abs(aveX - p[i]["x"]) + abs(aveY - p[i]["y"])
	p.sort(key=lambda z: z["d"])
	D = []
	P = [p[-1]]
	k = 1
	while abs(p[-k-1]["d"] - P[0]["d"]) < 1 and k < len(p):
		P.append(p[-k-1])
		k += 1
	for i in range(N - 1):
		for j in range(len(P)):
			D.append(abs(P[j]["x"] - p[i]["x"]) + abs(P[j]["y"] - p[i]["y"]))
	print(max(D))

main()

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)


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

Submission status: Runtime Error

Solution code:
import math

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

if __name__=="__main__":
  n=int(input())
  l=[]
  for _ in range(n):
    x=[int(i) for i in input().split()]
    l.append(x)
  if len(l)==1:
    print(0)
    exit
  n=len(l)
  ans=[]
  for i in range(n-1):
    l=i+1
    r=len(l)
    ma=-1
    while(i<r):
      mid=l+(r-l)//2
      if dist(l[i],l[mid])>ma:
        ma=dist(l[i],l[mid])
        l=mid+1
      else:
        break
  print(ma)
    
  print(max(ans))

Submission status: Runtime Error

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

if max(x) == min(x):
    ans = abs(max(y) - min(y))
elif max(y) == min(y):
    ans = abs(max(x) -min(x))

else:
    list = []
    l_a = [i for i, j in enumerate(x) if j == max(x)]
    l_b = [i for i, j in enumerate(x) if j == min(x)]
    l_c = [i for i, j in enumerate(y) if j == max(y)]
    l_d = [i for i, j in enumerate(x) if j == min(y)]
    for i in range(len(l_a)):
        for j in range(len(l_b)):
            for k in range(len(l_c)):
                for l in range(len(l_d)):
                    list.append(abs(x[i]+x[j])+abs(y[k]+y[l]))
    ans = max(list)

print(ans)

Submission status: Runtime Error

Solution code:
from math import sqrt
from functools import reduce

def convex_hull_graham(points):
  TURN_LEFT, TURN_RIGHT, TURN_NONE = (1, -1, 0)

#  def cmp(a, b):
#    return (a > b) - (a < b)
  def turn(p, q, r):
    a=(q[0] - p[0])*(r[1] - p[1]) - (r[0] - p[0])*(q[1] - p[1])
    (a > b) - (a < b)
  def _keep_left(hull, r):
    while len(hull) > 1 and turn(hull[-2], hull[-1], r) == TURN_RIGHT:
      hull.pop()
    if not len(hull) or hull[-1] != r:
      hull.append(r)
    return hull
  points = sorted(points)
  l = reduce(_keep_left, points, [])
  u = reduce(_keep_left, reversed(points), [])
  return l.extend(u[i] for i in range(1, len(u) - 1)) or l


# Function to find the maximum 
# distance between any two points 
def maxDist(p): 
  n = len(p) 
  maxm = 0
  # Iterate over all possible pairs 
  for i in range(n): 
    for j in range(i + 1, n): 
      # Update maxm
      dist=  abs( p[i][0] - p[j][0])+abs( p[i][1] - p[j][1]) 
      maxm = max(maxm, dist) 
  # Return actual distance 
  #return sqrt(maxm) 
  return maxm
# Driver Code 
if __name__ == '__main__': 
  # Number of points 
  n=int(input())
  xy=[None]*n
  for i in range(n):
    xy[i]=list(map(int,input().split()))
  # Given points 
  # Function Call 
  xy=convex_hull_graham(xy)
  print(maxDist(xy))

Submission status: Runtime Error

Solution code:
2
1 1
1 1

Submission status: Runtime Error

Solution code:
N = int(input())
v = [list(map(input().split)) for i in range(N)]
v.sort(key = lambda x:abs(x[0]) + abs(x[1]))
d = abs(v[0][0] - v[N-1][0]) + abs(v[0][1] - v[N-1][1])
print(d)

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)
print(np.max(distance))

Submission status: Runtime Error

Solution code:
N = int(input())
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
if x1+y1 > x2+y2:
    xmax = x1+y1
    xmin = x2+y2
else:
    max1 = x2+y2
    min1 = x1+y1

if x1-y1 > x2-y2:
    max2 = x1-y1
    min2 = x2-y2
else:
    max2 = x2-y2
    min2 = x1-y1

for i in range(N-2):
    x, y = map(int, input().split())
    if x+y > max1:
        max1 = x+y
    elif x+y < min1:
        min1 = x+y
    
    if x-y > max2:
        max2 = x-y
    elif x-y < min2:
        min2 = x-y

print(max((max1-min1), (max2-min2)))

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
X = []
Y = []
for _ in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)

sumxy = [x+y for x,y in zip(X,Y)]
maxidx = bisect.bisect_left(sumxy,max(sumxy))
minidx = bisect.bisect_left(sumxy,min(sumxy))

ans = abs(X[maxidx] - X[minidx]) + abs(Y[maxidx] - Y[minidx])
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
arr=[]
for i in range(N):
	arr.append((map(int,input().split(' '))))

most=0
for j in range(len(arr)):
	for k in range(i,len(arr)):
		x1,y1,x2,y2=arr[j],arr[k]
		most=max(most,(abs(x1-x2)+abs(y1-y2)))

print(most)

Submission status: Runtime Error

Solution code:
N = int(input())

Xmax = -2*10**9
Ymax = -2*10**9
Xmin = 2*10**9
Ymin = 2*10**9


for i in range(N):
    x, y = map(int, input().split())
    if (x + y >= Xmax):
        Xmax = x + y
    if (x + y =< Xmin):
        Xmin = x + y
    if (x - y >= Ymax):
        Ymax = x - y
    if (x - y =< Ymin):
        Ymin = x - y

print(max(Xmax - Xmin, Ymax - Ymin))

Submission status: Runtime Error

Solution code:


N=int(input())
arr=[]
for i in range():
	arr.append((map(int,input().split(' '))))

most=0
for j in range(len(arr)):
	for k in range(i,len(arr)):
		x1,y1,x2,y2=arr[j],arr[k]
		most=max(most,(abs(x1-x2)+abs(y1-y2)))

print(most)

Submission status: Runtime Error

Solution code:
n=int(input())
l1=[]
l2=[]
for i in range(n):
    a,b=map(int,input().split())
    if a==b:
        l1.append(a+b)
        l2.append(a+b)
    elif a>b:
        l1.append(a+b)
    else:
        l2.append(a+b)
l1.sort()
l2.sort()
a,b,c,d=l1[0],l1[-1],l2[0],l2[-1]
print(abs(max(a-c,a-d,b-c,b-d,key=abs)))

Submission status: Runtime Error

Solution code:
def mahattan([x1,y1],[x2,y2]):
	return (abs(x1-x2)+abs(y1-y2))

N=int(input())
arr=[]
for i in range():
	arr.append((map(int,input().split(' '))))

most=0
for j in range(len(arr)):
	for k in range(i,len(arr)):
		x1,y1,x2,y2=arr[j],arr[k]
		most=max(most,mahattan(arr[j],arr[k]))

print(most)

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]

  m = 0
  minN = ListN[0][0] + ListN[0][1]
  maxN = ListN[0][0] + ListN[0][1]

  for i in range (len(ListN)-1):
    flg = False
    if minN >= ListN[i][0] + ListN[i][1]:
      minN = ListN[i][0] + ListN[i][1]
      flg = True
    elif maxN <= ListN[i][0] + ListN[i][1]:
      maxN = ListN[i][0] + ListN[i][1]
      flg = True
    if flg:
      for j in range (i,len(ListN)):
       m = max(m, abs(ListN[i][0] - ListN[j][0]) + abs(ListN[i][1] - ListN[j][1]) )

  print(m)

Submission status: Runtime Error

Solution code:
s=int(input())
li=[]
row=[]
col=[]
for i in range(s):
  x,y = map(int,input().split())
  row.append(x)
  col.append(y)
  li.append([x,y])
row.sort()
col.sort()


print(li)
def max_seek(row,col,li):
  print("row",row)
  if (([row[-1],col[-1]]  in li) and ([row[0],low[0]]  in li)) or (([row[0],col[-1]] in li) and ([row[-1],col[0]] in li)):
    return (row[-1]-row[0])+(col[-1]-col[0])
  elif len(row)<=2 or len(col)<=2:
    pass
  
  else:
    max_seek(row[1:],col,li)
    max_seek(row[:-2],col,li)
    max_seek(row,col,li[1:])
    max_seek(row,col,li[:-2])
    
print(max_seek(row,col,li))

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(dif, axis=-1)


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

Submission status: Runtime Error

Solution code:
def mahattan([x1,y1],[x2,y2]):
	return (abs(x1-x2)+abs(y1-y2))

N=int(input())
arr=[]
for i in range():
	arr.append([map(int,input().split(' '))])

most=0
for j in range(len(arr)):
	for k in range(i,len(arr)):
		most=max(most,mahattan(arr[j],arr[k]))

print(most)

Submission status: Runtime Error

Solution code:
n=int(input())
x=[]

for i in range(n):
  a,b=map(int,input().split(" "))
  x.append([a,b])
x=list(map(list, set(map(tuple, x))))
if len(x)==1:
  print(0)
else:
  ans=0
  for i in range(n):
    for j in range(n):
      y=abs(x[i][0]-x[j][0])+abs(x[i][1]-x[j][1])
      if ans<y:
        ans=y
  print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
 
dins=sys.stdin.readlines()
 
data=np.array([ [ int(r) for r in ln.split(' ') if r != '' ] for ln in dins[1:]])
 
d0=data
d1=data
dists=[]
while d0.shape[0] > 0:
    d0=d0[1:]
    d1=d1[:-1]
    dists=np.concatenate([dists,abs(x[i]-x[j])+abs(y[i]-y[j])])
print(dists.max())

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
#def input():
    #return sys.stdin.readline()[:-1]
import numpy as np
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]
add=np.array(add)
index_list=np.argsort(add)
print(int(abs(x[index_list[0]-x[index_list[N-1])+abs(y[index_list[0]-y[index_list[N-1])))
#d=0
#mi=x[0]+y[0]
#ma=mi
#nmi=0
#nma=0
#for i in range(N):
#    mi=min(mi,x[i]+y[i])
#    if mi == x[i]+y[i]:
#        nmi=i
#    ma=max(ma,x[i]+y[i])
#    if ma == x[i]+y[i]:
#        nma=i
#
#print(int(abs(x[nmi]-x[nma])+abs(y[nmi]-y[nma])))

Submission status: Runtime Error

Solution code:
n = int(input())
min = 10000000000
max = -10000000000

for _ in range(n):
    x, y = map(int,input().split())
    if x+y < min:
        l = [x,y]
        min = x+y
    elif x+y > max:
        r = [x,y]
        max = x+y

print(abs(l[0]-r[0]) + abs(r[1]-l[1]))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
if n%2==0:
    mid = n//2-1
else:
    mid = n//2
if sorted(list(set(b)))==sorted(list(set(a))):
    if  b[mid+1:] + b[:mid+1] != a:
        print('Yes')
        print(" ".join(map(str,b[mid+1:] + b[:mid+1])))
    else:
        print('No')
        break
    
else:
    print('no')

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)

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

    print(res)



main()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
def dist(a,b):
  return sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)
import numpy as np
if __name__=="__main__":
  n=int(input())
  l=[]
  for _ in range(n):
    l.append([int(i) for i in input().split()])
  l=list(np.unique(np.array(l)))
  l.sort()
  if len(l)==1:
    print(0)
    exit
  n=len(l)
  ans=[]
  for i in range(n):
    for j in range(1,n):
      ans.append(dist(l[i],l[j]))
  print(max(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
x = [0 for _ in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
xx = sum([i[0] for i in x])/n
yy = sum([i[1] for i in x])/n
for i in x:
    i.append(abs(xx-i[0]) + abs(yy-i[1]))
x.sort(key = lambda s:s[2])
ans = 0
for i in range(1, min(6, n)):
    ans = max(ans, abs(x[-i][0] - i[0]) + abs(x[-i][1] - i[1]))
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
xlis = [0]
ylis = [0]
for _ in range(n):
    x, y = map(int, input().split())
    xlis.append(x)
    ylis.append(y)

if (xlis[2]-xlis[1]) + (ylis[2]-ylis[1]) >= 0:
    defa1 = 1
    defa2 = 2
elif (xlis[2]-xlis[1]) + (ylis[2]-ylis[1]) <= 0:
    defa1 = 2
    defa2 = 1
def checkplace(defalt1, defalt2, new1,):
    defa1p = (xlis[dafalt1], ylis[defalt1])
    defa2p = (xlis[defalt2], ylis[defalt2])
    new1p = (xlis[new1], ylis[new1])

    if (new1p[0]-defa2p[0])+(new1p[1]-defa2p[1]) >= 0:
        defa2 = new1
    elif (new1p[0]-defa2p[0])+(new1p[1]-defa2p[1]) <= 0 <= (new1p[0]-defa1p[0])+(new1p[1]-defa1p[1]):
        pass
    elif (new1p[0]-defa1p[0])+(new1p[1]-defa1p[1]) <= 0:
        defa1 = new1

for i in range(3, n):
    new1 = i
    checkplace(defa1, defa2, new1)

print((xlis[defa2]-xlis[defa1]) + (ylis[defa2]-ylis[defa1]))

Submission status: Runtime Error

Solution code:
import numpy as np
N=int(input())
cities = np.array([list(map(int,input().split())) for _ in range(N)])
all_diffs = np.expand_dims(cities, axis=1) - np.expand_dims(cities, axis=0)
dist = np.sum(np.abs(all_diffs), axis=-1)
print(np.max(dist))

Submission status: Runtime Error

Solution code:
N = int(input())
XY = []
for i in range(N):
  val = input()
  if val:
    XY.append(val)
    
c = 0
for i in range(N):
  for j in range(i+1,N):
    c = max(c,abs(int(XY[i][0])-int(XY[j][0]))+abs(int(XY[i][2])-int(XY[j][0])))

print(c)

Submission status: Runtime Error

Solution code:
3
1 1
2 4
3 2

Submission status: Runtime Error

Solution code:
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################
    
def solve():
    n = inp()
    q = 0
    w = 1000000000000000000000000000
    qq = 0
    ww = 1000000000000000000000000000
    qqqq = 0
    wwww = 1000000000000000000000000000
    a = []
    for i in range(n):
        x,y = invr()
        a.append([x,y])
        q = max(q,x + y)
        w = min(w,x + y)
        qq = max(qq,x - y)
        ww = min(ww,x - y)
        qqqq = max(qqqq,y - x)
        wwww = min(wwww,y - x)
    if len(set(a)) == 1:
        print(0)
    else:
        print(max(q - w,qq - ww,qqqq - wwww))
    
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)

def counter_elements(a):
    q = dict()
    for i in range(len(a)):
        if a[i] not in q:
            q[a[i]] = 0
        q[a[i]] = q[a[i]] + 1
    return(q)

def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97],1
    return(q)
 
def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))
 
def prime_factors(n):
    q = []
    while n % 2 == 0: q.append(2); n = n // 2
    for i in range(3,int(n ** 0.5) + 1,2):
        while n % i == 0: q.append(i); n = n // i
    if n > 2: q.append(n)
    return(list(sorted(q)))

def transpose(a):
    n,m = len(a),len(a[0])
    b = [[0] * n for i in range(m)]
    for i in range(m): 
        for j in range(n): 
            b[i][j] = a[j][i]
    return(b)

#-----------------------------------------------------------------------#
        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
main()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
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

n = int(input())
point = []
for _ in range(n):
    x, y = map(int, input().split())
    point.append([x, y])

point = convex_hull(point)
ans = 0
for i in range(len(point)):
    for j in range(len(point)):
        if i != j:
            ans = max(ans, abs(point[i][0] - point[j][0]) + abs(point[i][1] - point[j][1]))
print(ans)

Submission status: Runtime Error

Solution code:
def cost(x1,y1,x2,y2):
    return abs(x1-x2) + abs(y1-y2)


n = int(input())

x = []
y = []
for i in range(n):
    a,b = map(int,input().split())
    x.append(a)
    y.append(b)
ans = - math.inf
for i in range(n):
    for j in range(i+1,n):
        ans = max(ans,cost(x[i],y[i],x[j],y[j]))
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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

n = int(input())
point = []
for _ in range(n):
    x, y = map(int, input().split())
    point.append([x, y])
convex_hull(point)    

point = convex_hull(point)
ans = 0
for i in range(len(point)):
    for j in range(len(point)):
        if i != j:
            ans = max(ans, abs(point[i][0] - point[j][0]) + abs(point[i][1] - point[j][1]))
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
for i in range(0,n):
  a,b=int(input())
  l.append((a,b))
i=0
while i<n:
  c=abs(l[i%n][0]-l[(i+1)%n][0])+abs(l[i%n][1]-l[(i+1)%n][1])
  w.append(c)
  i=i+1
print(max(w))

Submission status: Runtime Error

Solution code:
n = input()
n = int(n)

p = []
for i in range(n):
  x,y = map(int, input().split(' '))
  p.append([x, y])

maXP = max(p, key=lambda x:x[0])
miXP = min(p, key=lambda x:x[0])
maYP = max(p, key=lambda x:x[1])
miYP = min(p, key=lambda x:x[1])
mp = [maXP, miXP, maYP, miYP]
md = -1
for i in range(3):
  for j in range(i+1, 4):
    x1, y1 = mp[i]
    x2, y2 = mp[j]
	md = abs(x1 - x2) + abs(y1 - y2)
	md = int(md)
print(md)

Submission status: Runtime Error

Solution code:
import numpy as np
from numba import jit
@jit
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]
a=[]
b=[]
for i in range(len(x)):
    for j in range(i+1,len(x)):
        a.append(abs(x[j]-x[i]))
        b.append(abs(y[j]-y[i]))
a_n = np.array(a)
b_n = np.array(b)
c = a_n+b_n
print(c[np.argmax(b+c)])

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
for i in range(0,n):
  a,b=int(input())
  l.append((a,b))
i=0
w=[]
while i<n:
  c=abs(l[i][0]-l[i+1][0])+abs(l[i][1]-l[i+1][1])
  w.append(c)
  i=i+2
print(max(w))

Submission status: Runtime Error

Solution code:
n=int(input())
for i in range(0,n):
  a,b=int(input())
  l.append((a,b))
i=0
while i<n:
  c=abs(l[i][0]-l[i+1][0])+abs(l[i][1]-l[i+1][1])
  w.append(c)
print(max(w))

Submission status: Runtime Error

Solution code:
n=int(input())
max=0
for i in range(n):
    x,y=map(int,input().split())

for j in range(n):
    for k in range(j,n):
        if (abs(x[j]-x[k])+abs(y[j]-y[k]))>max:
            max = (abs(x[j]-x[k])+abs(y[j]-y[k]))
print(max)

Submission status: Runtime Error

Solution code:
n = int(input())
xy = [list(map(int,input())) for _ in range(n)]
max = 0
for xy1 in xy:
  for xy2 in xy:
    dis = abs(xy1[0]-xy2[0]) + abs(xy1[1]-xy2[1])
    if dis > max:
      max = dis
print(max)

Submission status: Runtime Error

Solution code:
import itertools

n = int(input())
node = {}
for i in range(n):
    x, y = map(int, input().strip().split())
    if x in node.keys():
        if y < node[x][0]:
            node[x][0] = y
        elif y > node[x][1]:
            node[y][1] = y
    else:
        node[x] = [y, y]
res = 0

for key1, value1 in node.items():
    for key2, value2 in node.items():
        manhattan = abs(key1 - key2) + abs(value1[0] - value2[1])
        if res < manhattan:
            res = manhattan

print(res)

Submission status: Runtime Error

Solution code:
n = int(input())

import numpy as np

dots = np.zeros((n,2),dtype=np.int)
for i in range(n):
  x,y = input().split()
  dots[i,:] = int(x),int(y)
  
max_dis=0
x = dots[:,0]
y = dots[:,1]

x_dis_array = np.abs(x - x[:,np.newaxis])
y_dis_array = np.abs(y - y[:,np.newaxis])

dis_array = x_dis_array + y_dis_array

max_dis = dis_array.max()

print(int(max_dis))

Submission status: Runtime Error

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

def dist(A, B):
	return abs(A[0]-B[0]) + abs(A[1]-B[1])

N = INT()
xy = [LIST()+[i] for i in range(N)]

xy1 = [[xy[i][0]+xy[i][1], i] for i in range(N)]
xy1.sort(key=lambda x:x[0])
idx_a = xy1[0][1]
idx_b = xy1[-1][1]
a = xy[idx_a]
b = xy[idx_b]

xy2 = [[-xy[i][0]+xy[i][1], i] for i in range(N)]
xy2.sort(key=lambda x:x[0])
idx_c = xy2[0][1]
idx_d = xy[-1][1]
c = xy[idx_c]
d = xy[idx_d]

print(max(dist(a, b), dist(a, c), dist(a, d), dist(b, c), dist(b, d), dist(c, d)))

Submission status: Runtime Error

Solution code:

n = int(input())
l = list()
for _ in range(n):
	x, y = map(int, input().split())
    l.append((x,y))

max_dist = 0

for i in range(n):
  for j in range(n):
    if i == j:
      continue
	max_dist = min(max_dist, abs(l[i][0]-l[j][0]) + abs(l[i][1]-l[j][1]))     
print(max_dist, end='')

Submission status: Runtime Error

Solution code:
from itertools import permutations
def mahattan([x1,y1],[x2,y2]):
	return(abs(x1-x2)+abs(y1-y2))

N=input()
coors=[]
for i in range(N):
	coors.append([map(int,input().split(" "))])

perm=permutations(coors,2)
most=0
for coor_pair in perm:
	v,w=coor_pair
	most=max(most,mahattan(v,w))
print(most)