Problem:
Distance II Your task is to calculate the distance between two $n$ dimensional vectors $x = \{x_1, x_2, ..., x_n\}$ and $y = \{y_1, y_2, ..., y_n\}$. The Minkowski's distance defined below is a metric which is a generalization of both the Manhattan distance and the Euclidean distance. \[
D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)^{\frac{1}{p}}
\] It can be the Manhattan distance \[
D_{xy} = |x_1 - y_1| + |x_2 - y_2| + ... + |x_n - y_n|
\] where $p = 1 $.  It can be the Euclidean distance \[
D_{xy} = \sqrt{(|x_1 - y_1|)^{2} + (|x_2 - y_2|)^{2} + ... + (|x_n - y_n|)^{2}}
\] where $p = 2 $.  Also, it can be the Chebyshev distance  \[
D_{xy} = max_{i=1}^n (|x_i - y_i|)
\]  where $p = \infty$ Write a program which reads two $n$ dimensional vectors $x$ and $y$, and calculates Minkowski's distance where $p = 1, 2, 3, \infty$ respectively. Input In the first line, an integer $n$ is given. In the second and third line, $x = \{x_1, x_2, ... x_n\}$ and $y = \{y_1, y_2, ... y_n\}$ are given respectively. The elements in $x$ and $y$ are given in integers. Output Print the distance where $p = 1, 2, 3$ and $\infty$ in a line respectively.
The output should not contain an absolute error greater than 10 -5 . Constraints  $1 \leq n \leq 100$  $0 \leq x_i, y_i \leq 1000$  Sample Input 3
1 2 3
2 0 4 Sample Output 4.000000
2.449490
2.154435
2.000000

Solution (Python):


import math

def intinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    n = int(input())
    x = intinput()
    y = intinput()
    sum_1 = 0
    sum_2 = 0
    sum_3 = 0
    MD_INFTY = 0
    for i in range(n):
        MD_INFTY = max(MD_INFTY, abs(x[i] - y[i]))
        sum_1 += abs(x[i] - y[i])
        sum_2 += abs(x[i] - y[i]) ** 2
        sum_3 += abs(x[i] - y[i]) ** 3
    MD_1 = sum_1
    MD_2 = math.sqrt(sum_2)
    MD_3 = sum_3 ** (1 / 3)
    print(MD_1); print(MD_2); print(MD_3); print(float(MD_INFTY))

if __name__ == "__main__":
    main()

Solution (Python):
import math
n = int(input())
x, y = [int(e) for e in input().split()], [int(e) for e in input().split()]
total_1 = total_2 = total_3 = total_max = 0
for x1, y1 in zip(x, y):
    total_1 += abs(x1 - y1)
    total_2 += (x1 - y1)**2
    total_3 += (abs(x1 - y1))**3
    if total_max < abs(x1 - y1):
        total_max = abs(x1 - y1)
print("{0:.5f}".format(total_1))
print("{0:.5f}".format(math.sqrt(total_2)))
print("{0:.5f}".format(math.pow(total_3, 1.0/3.0)))
print("{0:.5f}".format(total_max))

Solution (Python):
n = int(input())
x, y = [list(map(float,input().split()))for i in range(2)]
print("%.6f"%sum([abs(x[i]-y[i])for i in range(n)]))
print("%.6f"%pow(sum([abs(x[i]-y[i])**2 for i in range(n)]), 1/2))
print("%.6f"%pow(sum([abs(x[i]-y[i])**3 for i in range(n)]), 1/3))
print(*max([abs(x[i]-y[i])] for i in range(n)))

Solution (Python):
import math
n = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
D = [abs(X[i]-Y[i]) for i in range(n)]
for p in [1, 2, 3, -1]:
    if p == -1:
        print(max(D))
    else:
        print(math.pow(sum([math.pow(D[i],p) for i in range(n)]),1/p))

Solution (Python):
import math

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

ans1 = 0
ans2 = 0
ans3 = 0
ans4 = 0

for i in range(n):
	a = math.fabs(x[i] - y[i])
	ans1 += a
	ans2 += a**2
	ans3 += a**3
	ans4 = max(ans4, a) 

print(ans1)
print(ans2**(1./2.))
print(ans3**(1./3.))
print(ans4)

Solution (Python):
import math

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

ans1 = 0
ans2 = 0
ans3 = 0
ans4 = 0

for i in range(n):
	a = math.fabs(x[i] - y[i])
	ans1 += a
	ans2 += a**2
	ans3 += a**3
	ans4 = max(ans4, a) 

print(ans1)
print(ans2**(1./2.))
print(ans3**(1./3.))
print(ans4)

Solution (Python):
import math

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

ans1 = ans2 = ans3 = 0
ans4 = -1

for i in range(n):
	a = math.fabs(x[i] - y[i])
	ans1 += a
	ans2 += a**2
	ans3 += a**3
	ans4 = max(ans4, a) 

print(ans1)
print(ans2**(1./2.))
print(ans3**(1./3.))
print(ans4)

Solution (Python):
import math
def mink(x,y,p):
    return (sum([math.fabs(_x - _y)**p for _x, _y in zip(x,y)]))**(1/p)
def mink_i(x,y):
    return max([math.fabs(_x - _y) for _x, _y in zip(x,y)])
n = int(input())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
print(mink(x,y,1))
print(mink(x,y,2))
print(mink(x,y,3))
print(mink_i(x,y))

Solution (Python):
dim = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

d1 = [abs(x - y) for x, y in zip(a, b)]
print(sum(d1))

d2 = [(x - y)**2 for x, y in zip(a, b)]
print(pow(sum(d2), 1/2))

d3 = [(abs(x - y))**3 for x, y in zip(a, b)]
print(pow(sum(d3), 1/3))

print(max(d1))

Solution (Python):
import itertools
n = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
Z = list(itertools.product(X,Y))
Z = Z[::len(X)+1]
def fn(p):
    D = 0
    for z in Z:
        D += abs(z[0]-z[1])**p
    else:
        print(D**(1/p))
fn(1)
fn(2)
fn(3)
MA = []
for z in Z:
    MA.append(abs(z[0]-z[1]))
print(max(MA))

Solution (Python):


dimension = int(input())
vectors = [[float(i) for i in input().rstrip().split()] for j in range(2)]
x = vectors[0]
y = vectors[1]

absoluteValues = [abs(x[k] - y[k]) for k in range(dimension)]



def mink(a):
    totalValue = 0
    for i in range(dimension):
        totalValue += absoluteValues[i] ** a
    distance = totalValue ** (1 / a)
    return distance


def chev():
    maxValue = 0
    for i in range(dimension):
        
        if absoluteValues[i] > maxValue:
            maxValue = absoluteValues[i]
    print(maxValue)


for i in range(1, 3 + 1):
    dist = mink(i)
    print(dist)
chev()

Solution (Python):
import math
n = int(input())
xlist = list(map(float, input().split()))
ylist = list(map(float, input().split()))

print(sum(abs(xlist[i] - ylist[i]) for i in range(n)))
print(pow(sum(abs(xlist[i] - ylist[i]) ** 2 for i in range(n)),0.5))
print(pow(sum(abs(xlist[i] - ylist[i]) ** 3 for i in range(n)),1/3))
print(max(abs(xlist[i] - ylist[i])for i in range(n)))

Solution (Python):
import math

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(sum([abs(a[i] - b[i]) for i in range(n)]))
print(pow(sum([abs(a[i] - b[i]) **2 for i in range(n)]), 1/2))
print(pow(sum([abs(a[i] - b[i]) **3 for i in range(n)]), 1/3))
print(max([abs(a[i] - b[i]) for i in range(n)]))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

a = [abs(x[i] - y[i]) for i in range(n)]

for p in range(1, 4):
  ans = 0
  for d in a:
    ans += d ** p
  print('{:.10f}'.format(ans ** (1/p)))
print('{:.10f}'.format(max(a)))

Solution (Python):
def Dis(X,Y,p):
    D = 0
    for x, y in zip(X, Y):
        dis = abs(x - y) ** p
        D += dis 
    result = D ** (1/p)
    print(result)
def Dis_Che(X, Y):
    print(max(abs(x-y) for x, y in zip(X, Y)))

n = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

for p in range(1,4):
    Dis(X, Y, p)
Dis_Che(X,Y)

Solution (Python):
import math
n=int(input())
x=list(map(int, input().split()))
y=list(map(int, input().split()))

p=[0]*3
Max=0
for i in range(3):
    for j in range(n):
        p[i]+=abs(x[j]-y[j])**(i+1)
        if abs(x[j]-y[j])>Max:
            Max=abs(x[j]-y[j])
            
    print('{:.5f}'.format(p[i]**(1/(i+1))))
print('{:.5f}'.format(Max))

Solution (Python):


n = int(input())
X = [int(x) for x in input().split()]
Y = [int(y) for y in input().split()]

d1 = 0
d2 = 0
d3 = 0
Di = []

for i in range(n) :
    d1 += abs(X[i] - Y[i])
print(f"{d1:.6f}")

for i in range(n) :
    d2 += abs(X[i] - Y[i]) ** 2
print(f"{(d2)**(1/2):.6f}")

for i in range(n) :
    d3 += abs(X[i] - Y[i]) ** 3
print(f"{(d3)**(1/3):.6f}")
    
for i in range(n) :
    Di.append(abs(X[i] - Y[i]))
print(f"{max(Di):.6f}")

Solution (Python):
def Distance(X,Y,p):
    s=0
    for x,y in zip(X,Y):
        s+=abs(x-y)**p
    print(s**(1/p))
    
n=int(input())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))

for p in range(1,4):
    Distance(X,Y,p)
print(max(abs(x-y) for x,y in zip(X,Y)))

Solution (Python):
n = int(input())
a = list(map(float, input().split()))
b = list(map(float, input().split()))

c = [abs(a[i] - b[i]) for i in range(n)]

for k in range(1, 4):
    ans = 0
    for d in c:
        ans += d ** k
    print("{:.6f}".format(ans ** (1/k)))
    
print("{:.6f}".format(max(c)))

Solution (Python):
input()
d=[abs(s-t)for s,t in zip(*[list(map(int,input().split()))for _ in'12'])]
f=lambda n:sum(s**n for s in d)**(1/n)
print(f(1),f(2),f(3),max(d),sep='\n')

Solution (Python):
n=int(input())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
for p in range(1,4):
	print("{0:.6f}".format(sum([abs(a-b)**p for a,b in zip(X,Y)])**(1/p)))
print("{0:.6f}".format(max([abs(a-b) for a,b in zip(X,Y)])))

Solution (Python):
import math
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
D=[0,0,0,0]
p=[1,2,3]
for k in range(4):
    if k==3:
        D[k]=max(abs(x[i]-y[i])for i in range(n))
    else:
        D[k]=math.pow(sum(abs((x[i]-y[i])**p[k])for i in range(n)),1/p[k])
    print("{:.6f}".format(D[k]))

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

x=list(map(int,input().split()))
y=list(map(int,input().split()))
p=[0]*4

for i in range(n):
    p[0]+=abs(x[i]-y[i])
    p[1]+=abs(x[i]-y[i])**2
    p[2]+=abs(x[i]-y[i])**3
    p[3]=max(p[3],abs(x[i]-y[i]))
p[1]=p[1]**(1/2)
p[2]=p[2]**(1/3)
for i in range(4):
    print("{0:.5f}".format(p[i]))

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
p1,p2,p3 = 0,0,0
pin = []
for i in range(n):
	p1 += abs(x[i] - y[i])
	p2 += abs(x[i] - y[i])**2
	p3 += abs(x[i] - y[i])**3
	pin.append(abs(x[i] - y[i]))
p2 = p2**(1/2)
p3 = p3**(1/3)
pinf = max(pin)
print(p1)
print(p2)
print(p3)
print(pinf)

Solution (Python):
mark_list=[1,2,3,'∞']
n=int(input())
element_x=[int(i) for i in input().split()]
element_y=[int(l) for l in input().split()]
for p in mark_list:
    if p==1:
        m_distance=0
        for o in range(n):
            x=element_x[o]
            y=element_y[o]
            m_distance+=abs(x-y)
        print(m_distance)
    if p==2:
        y_distance=0
        y_distance2=0
        for m in range(n):
            x=element_x[m]
            y=element_y[m]
            y_distance2+=pow(abs(x-y),2)
        y_distance=pow(y_distance2,0.5)
        print(y_distance)
    if p==3:
        third_distance=0
        third_distance2=0
        for q in range(n):
            x=element_x[q]
            y=element_y[q]
            third_distance2+=pow(abs(x-y),3)
        third_distance=pow(third_distance2,1/3)
        print(third_distance)
    if p=='∞':
        c_distance=0
        difference=0
        for r in range(n):
            x=element_x[r]
            y=element_y[r]
            difference=abs(x-y)
            if difference>c_distance:
                c_distance=difference
        print(c_distance)

Solution (Python):
n = int(input())
xi = list(map(int, input().split()))
yi = list(map(int, input().split()))
for i in [1,2,3,0]:
	a = 0
	for j in range(0,n):
		if i == 0 :
			if a <= abs(yi[j]-xi[j]):
				a = abs(yi[j]-xi[j])
		else:
			a = a + abs(yi[j]-xi[j])**i
	if i == 0:
		print(a)
	else:
		print(a**(1/i))

Solution (Python):
def dist(p, X, Y):
    s = 0
    for x, y in zip(X, Y):
        s += abs(x - y)**p
    return s**(1/p)
N = int(input())
*X, = map(int, input().split())
*Y, = map(int, input().split())
print(dist(1, X, Y))
print(dist(2, X, Y))
print(dist(3, X, Y))
print(max(abs(x - y) for x, y in zip(X, Y)))

Solution (Python):



n=int(input())
a=list(map(float,input().split()))
b=list(map(float,input().split()))

c=[abs(a[i]-b[i]) for i in range(n)]  
for p in range(1,4):
    ans=0
    for d in c:
        ans+=d**p
    print("{:.6f}".format(ans**(1/p)))

print("{:.6f}".format(max(c)))

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
a = [0]*4
for i in range(n):
    a[0] += abs(x[i]-y[i])
    a[1] += abs(x[i]-y[i])**2
    a[2] += abs(x[i]-y[i])**3
    a[3] = max(a[3],abs(x[i]-y[i]))
a[1] = a[1]**(1/2)
a[2] = a[2]**(1/3)
for i in range(4):
    print('%f' % a[i])

Solution (Python):
import math
n=int(input())
X=[int(x) for x in input().split()]
Y=[int(y) for y in input().split()]
d1=0
d2=0
d3=0
D=[]
for i in range(n):
    d1+=abs(X[i]-Y[i])
print(f'{d1:.6f}')
for i in range(n):
    d2+=abs(X[i]-Y[i])**2
print(f'{math.sqrt(d2):.6f}')
for i in range(n):
    d3+=abs(X[i]-Y[i])**3
print(f'{d3**(1/3):.6f}')
for i in range(n):
    D.append(abs(X[i]-Y[i]))
print(f"{max(D):.6f}")

Solution (Python):
import math
n=int(input())
x=[int(0) for i in range(n)]
y=[int(0) for i in range(n)]
x[:]=(int(a) for a in input().split())
y[:]=(int(a) for a in input().split())
p1=0
p2=0
p3=0
px=0
for i in range(n):
  p1+=abs(x[i]-y[i])
  p2+=abs(x[i]-y[i])**2
  p3+=abs(x[i]-y[i])**3
  if px<abs(x[i]-y[i]):
    px=abs(x[i]-y[i])

p2=math.sqrt(p2)
p3=p3**(1/3)

print('{:.05f}'.format(p1))
print('{:.05f}'.format(p2))
print('{:.05f}'.format(p3))
print('{:.05f}'.format(px))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))

A=0
B=0
C=0
z=[]
for i in range(n):
    A+=abs(x[i]-y[i])
    B+=(x[i]-y[i])*(x[i]-y[i])
    C+=(abs(x[i]-y[i]))**3
    z.append(abs(x[i]-y[i]))
D=max(z)

    
B=B**(1/2)
C=C**(1/3)

print(A)
print(B)
print(C)
print(D)

Solution (Python):
import math
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
z,a,b=[],0,0
for i in range(n):
    z.append(abs(x[i]-y[i]))
for i in range(n):
    a+=(z[i]**2)
    b+=(z[i]**3)
a=math.sqrt(a)
b=math.pow(b,1.0/3.0)
print('{:.6f}\n{:.6f}\n{:.6f}\n{:.6f}'.format(sum(z),a,b,max(z)))

Solution (Python):



n = int(input())

X = list(map(int, input().split()))
Y = list(map(int, input().split()))

D1 = 0
D2 = 0
D3 = 0
max = 0
for i in range(n):
   diff = abs(X[i] - Y[i])
   D1 += diff
   D2 += diff**2
   D3 += diff**3
   if diff > max:
      max = diff

print('{:.6f}'.format(D1))
print(D2**(1 / 2))
print(D3**(1.0 / 3.0))
print('{:.6f}'.format(max))

Solution (Python):


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

for i in range(1, 4):
    nums = [(abs(a - b)) ** i for a, b in zip(A,B)]
    print(sum(nums) ** (1/i))
    if i == 1:
        ans = max(nums)
print(ans)

Solution (Python):
def dist(A_lst, B_lst, p):
    s = 0
    for a, b in zip(A_lst, B_lst):
        s += abs(a - b) ** p
    return s ** (1 / p)
    
    
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
print("{:.6f}".format(dist(A, B, 1)))
print("{:.6f}".format(dist(A, B, 2)))
print("{:.6f}".format(dist(A, B, 3)))
chebyshev = max(abs(a - b) for a, b in zip(A, B))
print("{:.6f}".format(chebyshev))

Solution (Python):
import math
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
d=0
for i in range(n):
  d += max(x[i],y[i])-min(x[i],y[i])
print(float(d))

d=0
for i in range(n):
  d+=(x[i]-y[i])**2
print(math.sqrt(d))

d=0
for i in range(n):
  d+=(max(x[i],y[i])-min(x[i],y[i]))**3
print(math.pow(d,1/3))

d=[]
for i in range(n):
  d.append(max(x[i],y[i])-min(x[i],y[i]))
print(float(max(d)))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans += abs(x[i] - y[i])
print(ans)
ans = 0
for i in range(n):
    ans += (x[i] - y[i])**2
print(ans**(1/2))
ans = 0
for i in range(n):
    ans += (abs(x[i] - y[i]))**3
print(ans**(1/3))
ans = 0
for i in range(n):
    ans = max(ans, abs(x[i] - y[i]))
print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

p1 = 0
p2b = 0
p3b = 0
pn = 0
for i in range(n):
  p1 += abs(x[i] - y[i])
  p2b += abs((x[i] - y[i]) ** 2)
  p3b += abs(((x[i] - y[i]) ** 3))

p2 = p2b ** 0.5
p3 = p3b ** (1 / 3)
pn = max([abs(x[i] - y[i]) for i in range(n)])

print("{:.10f}".format(p1)) 
print(p2)
print(p3)
print("{:.10f}".format(pn))

Solution (Python):
def dist(x,y,p):
    d = 0
    for i in range(len(x)):
        d += abs(x[i]-y[i])**p
    d = d**(1/p)
    return d

n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
print('{0:.6f}'.format(dist(x,y,1)))
print('{0:.6f}'.format(dist(x,y,2)))
print('{0:.6f}'.format(dist(x,y,3)))
print('{}'.format(max([abs(x[i]-y[i])for i in range(n)])))

Solution (Python):
def minkovsky(A,B,n = 0):
    C = [abs(a - b) for a , b in zip(A,B)]
    if n == 0:
        return max(C)
    else:
        d = 0
        for c in C:
            d += c ** n
        d = d ** (1 / n)
        return d
            
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

print(minkovsky(A,B,1))
print(minkovsky(A,B,2))
print(minkovsky(A,B,3))
print(minkovsky(A,B))

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
i = 0
p1 = 0
p2 = 0
p3 = 0
p4 = 0
for _ in range(n):
    if x[i] > y[i]:
        p1 = (x[i] - y[i]) + p1
    else:
        p1 = (y[i] - x[i]) + p1
    i = i + 1
print('{:.8f}'.format(p1))

i = 0
for _ in range(n):
    p2 = ((x[i] - y[i]))**2 + p2
    i = i + 1
print('{:.8f}'.format(p2**(1/2)))

i = 0
for _ in range(n):
    if x[i] > y[i]:
        p3 = ((x[i] - y[i]))**3 + p3
    else:
        p3 = ((y[i] - x[i]))**3 + p3
    i = i + 1
print('{:.8f}'.format(p3**(1/3)))

i = 0
M = 0
for _ in range(n):
    if x[i] > y[i]:
        p4 = x[i] - y[i]
        if M < p4:
            M = p4
    else:
        p4 = y[i] - x[i]
        if M < p4:
            M = p4
    i = i + 1
print('{:.8f}'.format(M))

Solution (Python):
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
manhattan = 0
euclid = 0
euclid2 = 0
chebishef = 0

for i, j in zip(x, y):
    tmp = abs(i - j)
    manhattan += tmp
    euclid += tmp * tmp
    euclid2 += tmp * tmp * tmp
    chebishef = max(chebishef, tmp)

print(manhattan)
print(math.sqrt(euclid))
print(math.pow(euclid2, 1 / 3))
print(chebishef)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
d = [abs(x[i] - y[i]) for i in range(n)]
for i in range(1,4):
    print('{0:f}'.format(sum(j ** i for j in d) ** (1 / i)))
print('{0:f}'.format(max(d)))

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

ans,num = [],0
for i in range(n):
    num += abs(x[i] - y[i])
ans += num,

num = 0
for i in range(n):
    num += (x[i] - y[i])**2
num **= 1/2
ans += num,

num = 0
for i in range(n):
    num += (abs(x[i] - y[i]))**3
num **= 1/3
ans += num,

num = []
for i in range(n):
    num += abs(x[i] - y[i]),
num = max(num)
ans += num,

print(*ans, sep = "\n")

Solution (Python):
from math import pow,fabs

N = int(input())
X = list(map(float,input().split()))
Y = list(map(float,input().split()))

def distance(length,x,y,n):
    D = 0
    for i in range(length):
        D += fabs(x[i]-y[i]) ** n
    return pow(D,1.0/n)

def che_distance(length,x,y):
    D = 0
    for i in range(length):
        if D < fabs(x[i]-y[i]):
            D = fabs(x[i]-y[i])
    return D

p1 = distance(N,X,Y,1)
p2 = distance(N,X,Y,2)
p3 = distance(N,X,Y,3)
pinf = che_distance(N,X,Y)

print("{}\n{}\n{}\n{}".format(p1,p2,p3,pinf))

Solution (Python):

import math
n=int(input())
x_v=list(map(int,input().split()))
y_v=list(map(int,input().split()))

p=1
while(p<5):
    d=0
    if(p==4):
        my_list=[]
        for i in range(n):
            my_list.append(abs(x_v[i]-y_v[i]))
        d=max(my_list)
        print(d)
    else:
        for i in range(n):
            d+=abs(x_v[i]-y_v[i])**p
        d=pow(d,1/p)
        print(d)
    p+=1

Solution (Python):
N = int(input())
x = input().split()
y = input().split()

x = [int(j) for j in x]
y = [int(z) for z in y]
d1 = 0
d2 = 0
d4 = []
d3 = 0
for i in range(N):
    d1 += abs(x[i]- y[i])
    d2 += (x[i]-y[i])**2
    d3 += abs(x[i]-y[i])**3
    d4.append(abs(x[i]- y[i]))
d2_root = d2**0.5
d3_root = d3**(1/3)
print('{:.08f}'.format(d1))
print('{:.08f}'.format(d2_root))
print('{:.08f}'.format(d3_root))
print('{:.08f}'.format(max(d4)))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))

y=list(map(int,input().split()))
z=[0]*n
a=0
b=0
c=0
d=0
for i in range(n):
    a=a+abs(x[i]-y[i])
    b=b+(x[i]-y[i])**2
    c=c+abs(x[i]-y[i])**3
    z[i]=abs(x[i]-y[i])
print(f'{a:.10f}')
b=b**(1/2)
print(f'{b:.10f}')
c=c**(1/3)
print(f'{c:.10f}')
print(f'{max(z):.10f}')

Solution (Python):



import math


def main():
    n = int(input())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    d1 = 0
    d2 = 0
    d3 = 0
    dn = 0
    for i in range(n):
        d1 += abs(x[i] - y[i])
        d2 += (x[i] - y[i])**2
        d3 += abs(x[i] - y[i])**3
        dn = max(dn, abs(x[i] - y[i]))

    d2 = math.sqrt(d2)
    d3 = math.pow(d3, 1/3)
    print(f"{d1:.5f}")
    print(f"{d2:.5f}")
    print(f"{d3:.5f}")
    print(f"{dn:.5f}")


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

diff = []
total1 = 0
total2 = 0
total3 = 0

for i in range(n):
    diff.append(abs(X[i] - Y[i]))
    total1 += diff[i]
    total2 += diff[i] ** 2
    total3 += diff[i] ** 3

print("{0:.6f}" . format(total1))
print("{0:.6f}" . format(total2 ** 0.5))
print("{0:.6f}" . format(total3 ** (1 / 3)))
print("{0:.6f}" . format(max(diff)))

Solution (Python):
n = int(input())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
ds = [abs(x - y) for x, y in zip(xs, ys)]
for i in range(1, 4):
    ans = 0
    for d in ds:
        ans += d**i
    print(ans**(1/i))
print(max(ds))

Solution (Python):
def minko_n(x,y,n):
    D = 0
    for i in range(len(x)):
        D += (abs(x[i]-y[i]))**n
    return D**(1/n)

def minko_f(x,y):
    l = []
    for i in range(len(x)):
        l.append(abs(x[i]-y[i]))
    return max(l)

n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

print(minko_n(x,y,1))
print(minko_n(x,y,2))
print(minko_n(x,y,3))
print(minko_f(x,y))

Solution (Python):
def Distance(X,Y,p):
    s=0
    for x,y in zip(X,Y):
        s+=abs(x-y)**p
    print(s**(1/p))

n=int(input())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))

for p in range(1,4):
    Distance(X,Y,p)
print(max(abs(x-y) for x,y in zip(X,Y)))

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
temp = list(map(lambda x, y: abs(x-y), X, Y))
result = []
for i in [1,2,3]:
    print(sum(list(map(lambda x: x**i, temp)))**(1/i))
print(max(temp))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
print(sum([abs(x-y) for x, y  in zip(x, y)]))
print(sum([abs(x - y) ** 2 for x, y  in zip(x, y)]) ** (1/2) )
print(sum([abs(x - y) ** 3 for x, y  in zip(x, y)]) ** (1/3) )
print(max([abs(x-y) for x, y  in zip(x, y)]))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
d= [abs(x[i] - y[i]) for i in range(n)]
for i in range(1, 4):
    a = 0
    for j in d:
        a += j**i
    print("{:.6f}".format(a**(1/i)))
print("{:.6f}".format(max(d)))

Solution (Python):
n = int(input())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
for p in range(1,4):
    print("{0:.6f}".format(sum([abs(a-b)**p for a,b in zip(X,Y)])**(1/p)))
print("{0:.6f}".format(max([abs(a-b) for a,b in zip(X,Y)])))

Solution (Python):
import math
n = int(input())
x_list = list(map(int,input().split()))
y_list = list(map(int,input().split()))
def distance(X,Y,N):
    t= 0
    for i  in range(len(X)):
        z = (abs(X[i] - Y[i]))**N
        t += z
    return math.pow(t,1/N)    
def chebi(X,Y):
    abs_list= []
    for i in range(len(X)):
        abs_list.append(abs(X[i]-Y[i]))
    return max(abs_list)
print(distance(x_list,y_list,1))
print(distance(x_list,y_list,2))
print(distance(x_list,y_list,3))
print(chebi(x_list,y_list))

Solution (Python):
n = int(input())
x, y = [list(map(int, input().split())) for _ in range(2)]
print(sum([abs(x[i] - y[i]) for i in range(n)]))
print(pow(sum([(x[i] - y[i]) ** 2 for i in range(n)]), 1/2))
print(pow(sum([abs(x[i] - y[i]) ** 3 for i in range(n)]), 1/3))
print(max([abs(x[i] - y[i]) for i in range(n)]))

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
C = [abs(X[i] - Y[i]) for i in range(n)]
D = []
def distance(X, Y):  
  for k in range(1, 4):
    d = 0
    for j in range(len(X)):
      d += C[j] ** k
    d = d ** (1 / k)
    D.append(d)
  D.append(max(C))
  return D

distance(X, Y)
for i in range(4):
  print('{:.08f}'.format(D[i]))

Solution (Python):
import math as ma

n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

d = [int(0)]*4 
tmp = int(0)
tmp2 = int(0)
tmp3 = [int(0)]*n

for i in range(n):
    d[0] += abs(x[i]-y[i])
    tmp += (x[i]-y[i])**2
    tmp2 += (abs(x[i]-y[i]))**3
    tmp3[i] = abs(x[i]-y[i])

d[1] = ma.sqrt(tmp)
d[2] = (tmp2)**(1/3)
d[3] = max(tmp3)

for i in range(4):
    print(d[i])

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

p1 = p2 = p3 = p4 = 0

for i in range(n):
    p1 += abs(x[i] - y[i])
    p2 += abs(x[i] - y[i]) ** 2
    p3 += abs(x[i] - y[i]) ** 3
    p4 = max(p4, abs(x[i] - y[i]))

p2 = p2 ** (1 / 2)
p3 = p3 ** (1 / 3)

print("%f\n%f\n%f\n%f\n" % (p1, p2, p3, p4))

Solution (Python):
import math
n=int(input())
a=[]
for i  in range(2):
    s = list(map(int, input().split()))
    a.append(s)
d1=0
for i in range(n):
    d1+=abs(a[0][i-1]-a[1][i-1])
print(format(d1, '.6f'))
d2_1=0
for i in range(n):
    d2_1+=(abs(a[0][i-1]-a[1][i-1]))**2
d2=math.sqrt(d2_1)
print(format(d2, '.6f'))
d3_1=0
for i in range(n):
    d3_1+=(abs(a[0][i-1]-a[1][i-1]))**3
d3=(d3_1)**(1/3)
print(format(d3, '.6f'))
dn=0
for i in range(n):
    dn=max(abs(a[0][i-1]-a[1][i-1]),dn)
print(format(dn, '.6f'))

Solution (Python):
def Distance(X,Y,p):
    s=0
    for x,y in zip(X,Y):
        s+=abs(x-y)**p
    print(s**(1/p))
    
n=int(input())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))

for p in range(1,4):
    Distance(X,Y,p)
print(max(abs(x-y) for x,y in zip(X,Y)))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

p = [0] * 3
Max = 0
for i in range(3) :
    for j in range(n) :
        p[i] += abs(x[j] - y[j]) ** (i+1)
        if abs(x[j] - y[j]) > Max :
            Max = abs(x[j] - y[j])
            
    print('{:.5f}'.format(p[i] ** (1/(i+1))))
print('{:.5f}'.format(Max))

Solution (Python):
n = int(input())
tbl = [[0 for i in range(n)] for j in range(5)]
for i in range(2):
    a = list(map(int,input().split()))
    for j in range(n):
        tbl[i][j] = a[j]
D_1 = 0
d_2 = 0
d_3 = 0
for k in range(n):
    tbl[2][k] = abs(tbl[0][k]-tbl[1][k])
    tbl[3][k] = (abs(tbl[0][k]-tbl[1][k]))**2
    tbl[4][k] = (abs(tbl[0][k]-tbl[1][k]))**3
    D_1 += tbl[2][k]
    d_2 += tbl[3][k]
    d_3 += tbl[4][k]
M = max(tbl[2])
print(f'{D_1:.6f}')
print(f'{(d_2)**(1/2):.6f}')
print(f'{(d_3)**(1/3):.6f}')
print(f'{M:.6f}')

Solution (Python):
n = int(input())
x = list(map(int, input().split())) 
y = list(map(int, input().split()))
c = [abs(x[i]-y[i]) for i in range(n)]
for p in range(1, 4):
  ans = 0
  for s in c:
    ans += s**p
  print("{:.6f}".format(ans**(1/p)))
print("{:.6f}".format(max(c)))

Solution (Python):
n = int(input())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))

for p in range(1,5):
    if p != 4:
        D = 0.0
        for i in range(n):
            D += ((abs(X[i]-Y[i]))**p)
        D = D**(1/p)
        print("{:.6f}".format(D))
    else:
        print("{:.6f}".format(max(abs(x-y)for x,y in zip(X,Y))))

Solution (Python):


n = int(input())
x = map(int, input().split())
y = map(int, input().split())

x_y = [abs(xi - yi) for xi, yi in zip(x, y)]
p1 = sum(x_y)
p2 = sum(i ** 2 for i in x_y) ** (1/2)
p3 = sum(i ** 3 for i in x_y) ** (1/3)
p_inf = max(x_y)

print(p1)
print(p2)
print(p3)
print(p_inf)

Solution (Python):
n = int(input())
a = list(map(float, input().split()))
b = list(map(float, input().split()))

c = [abs(a[i] - b[i]) for i in range(n)]

for p in range(1, 4):
    ans = 0
    for d in c:
        ans += d ** p
    print("{:.6f}".format(ans ** (1 / p)))

print("{:.6f}".format(max(c)))

Solution (Python):
import math
n=int(input())
x=list(map(int,input().split(" ")))
y=list(map(int,input().split(" ")))

def minkowski(x,y,p):
    tmp=[math.fabs(x[i]-y[i])**p for i in range(len(x))]
    return sum(tmp)**(1/p)

ans=[minkowski(x,y,i) for i in range(1,4)]
ans.append(max([math.fabs(x[i]-y[i])for i in range(len(x))]))
for i in ans:
    print(i)

Solution (Python):



n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
p = [0]*4

for i in range(n):
    p[0] += abs(x[i] - y[i])
    p[1] += abs(x[i] - y[i])**2
    p[2] += abs(x[i] - y[i])**3
    p[3] = max(p[3], abs(x[i] - y[i]))
p[1] = p[1]**(1/2)
p[2] = p[2]**(1/3)
for i in range(4):
    print("{0:.5f}".format(p[i]))

Solution (Python):
import math

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
p_1, p_2, p_3, p_infinit = 0, 0, 0, 0
dis_list = []
for i in range(n):
    dis_list.append(abs(x[i] - y[i]))
    sum_d = abs(x[i] - y[i])
    p_1 += sum_d
    p_2 += sum_d ** 2
    p_3 += sum_d ** 3
p_2 = math.sqrt(p_2)
p_3 = p_3 ** (1 / 3)

print(p_1)
print(p_2)
print(p_3)
print(max(dis_list))

Solution (Python):
import math
n = int(input())
x = [int(i) for i in input().split()]
y = [int(j) for j in input().split()]
Manhattan = sum([abs(x[m]-y[m]) for m in range(n)])
Euclidean = math.sqrt(sum([(x[e]-y[e])**2 for e in range(n)]))
p_3 = (sum([(abs(x[c]-y[c]))**3 for c in range(n)]))**(1/3)
Chebyshev = max([abs(x[m]-y[m]) for m in range(n)])
print(Manhattan)
print(Euclidean)
print(p_3)
print(Chebyshev)

Solution (Python):
n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))

def minc_dis(n, x, y, p):
    sum = 0
    for i in range(n):
        sum = sum + (abs(x[i] - y[i])) ** p
    return sum ** (1/p)

def cheb_dis(n, x, y):
    dis = 0
    for i in range(n):
        dif = abs(x[i] - y[i])
        if dis < dif:
            dis = dif
    return dis

for p in range(1 , 4):
    print(minc_dis(n, x, y, p))

print(cheb_dis(n, x, y))

Solution (Python):
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
xy = []
for i in range(n):
    xy.append(abs(x[i] - y[i]))
D = [0, 0, 0, 0]
D[0] = sum(xy)
D2 = 0
for xyi in xy:
    D2 += xyi ** 2
D[1] = math.sqrt(D2)
D3 = 0
for xyi in xy:
    D3 += xyi ** 3
D[2] = math.pow(D3, 1.0/3.0)
D[3] = max(xy)
for d in D:
    print(d)

Solution (Python):
n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
list=[]
for j in range(3):
   D=0
   for i in range(n):
      if x[i]<y[i]:
         d = (y[i]-x[i])
      else:
         d = (x[i]-y[i])
      list.append(d)
      D += (d**(j+1))
   print(f"{D**(1/(j+1)):.6f}") 
print(f"{max(list):.6f}")