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
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
p1=0; p2=0; p3=0; pinf=0
for i in range(n):
    u=abs(x[i]-y[i])
    p1+=u
    p2+=pow(u,2)
    p3+=pow(u,3)
    if pinf<u:
        pinf=u
p2=math.sqrt(p2)
p3=pow(p3,1/3)
print("{0:.6f}".format(p1))
print("{0:.6f}".format(p2))
print("{0:.6f}".format(p3))
print("{0:.6f}".format(pinf))

Solution (Python):
import math

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

m = [abs(x[i] - y[i]) for i in range(n)]
m_d = sum(m)

m2 = [abs(x[i] - y[i]) ** 2 for i in range(n)]
m_u= math.sqrt(sum(m2))

m3=[abs(x[i] - y[i]) ** 3 for i in range(n)]
m_3= (sum(m3))**(1/3)

mi= [abs(x[i] - y[i]) for i in range(n)]
m_c=max(mi)

print('{:.6f}'.format(m_d))
print('{:.6f}'.format(m_u))
print('{:.6f}'.format(m_3))
print('{:.6f}'.format(m_c))

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

now_1 = 0
for i in range(n):
    now_1 += float(abs(x[i]-y[i]))
print("{:.10}".format(now_1))

now_2 = 0
for i in range(n):
    now_2 += float(abs(x[i]-y[i])**2)
print("{:.10}".format(now_2**0.5))

now_3 = 0
for i in range(n):
    now_3 += float(abs(x[i]-y[i])**3)
print("{:.10}".format(now_3**(1/3)))

ls = []
for i in range(n):
    ls.append(float(abs(x[i]-y[i])))
print("{:.10}".format(max(ls)))

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

x = list(map(float,input().split()))
y = list(map(float,input().split()))
D = []

sm = 0.0

for i in range(n):
    D.append(abs(x[i]-y[i]))
print('{:.08f}'.format(sum(D)))

for i in range(n):
    sm +=(x[i]-y[i])**2
print('{:.08f}'.format(sm**0.5))

sm = 0.0
for i in range(n):
    sm +=abs(x[i]-y[i])**3

print('{:.08f}'.format(sm**(1.0/3.0)))

print('{:.08f}'.format(max(D)))

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

def dist(x,y,p):
    val = 0
    for xi,yi in zip(x,y):
        val += (abs(xi-yi))**p
    return val**(1/p)
    
def cheb(x,y):
    val = 0
    for xi,yi in zip(x,y):
        val_tmp = abs(xi-yi)
        if val_tmp>val:
            val = val_tmp
    return val
    
print(dist(X,Y,p=1))
print(dist(X,Y,p=2))
print(dist(X,Y,p=3))
print(cheb(X,Y))

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

D1 = 0
for i in range(n):
    D1 += abs(x[i] - y[i])
D2 = 0
for i in range(n):
    D2 += (x[i] - y[i]) ** 2
D2 = math.sqrt(D2)
D3 = 0
for i in range(n):
    D3 += (abs(x[i] - y[i])) ** 3
D3 = math.pow(D3, 1.0/3.0)
Dinf = []
for i in range(n):
    Dinf.append(abs(x[i]- y[i]))
Dinf = max(Dinf)

print(format(D1, '.6f'))
print(format(D2, '.6f'))
print(format(D3, '.6f'))
print(format(Dinf, '.6f'))

Solution (Python):
import math

n = int(input())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
D = 0
z = []


for i in range(n):
    D += abs(x[i] - y[i])
print(D)

D = 0

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

D = 0

for i in range(n):
    D += (abs(x[i] - y[i])) ** 3
D = D ** (1/3)
print(D)


for i in range(n):
    z.append(abs(x[i] - y[i]))
print(max(z))

Solution (Python):
def resolve():
    n = int(input())
    x = [int(i) for i in input().split()]
    y = [int(i) for i in input().split()]
    D1 = 0
    D2 = 0
    D3 = 0
    D4 = 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 = max(D4, abs(x[i] - y[i]))
    D2 = D2**(1 / 2)
    D3 = D3**(1 / 3)
    print(D1 / 1)
    print(D2 / 1)
    print(D3 / 1)
    print(D4 / 1)


resolve()

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

n_dis = [0 for _ in range(3)]
elem_dis = [abs(x[i]-y[i]) for i in range(n)]

for p in range(3):
    for i in range(n):
        n_dis[p] += elem_dis[i]**(p+1)
    n_dis[p] = n_dis[p]**(1/(p+1))
    print(n_dis[p])
    
index = [i for i, j in enumerate(elem_dis) if j == max(elem_dis) ]
print(elem_dis[index[0]])

Solution (Python):
num = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

s = [0 for i in range(4)]
for i in range(num):
	s[0] += abs(A[i] - B[i])
	s[1] += abs(A[i] - B[i])**2
	s[2] += abs(A[i] - B[i])**3
	s[3] = max(s[3], abs(A[i] - B[i]))
s[1] = s[1]**(1/2)
s[2] = s[2]**(1/3)
for i in range(4):
	print(f"{s[i]}")

Solution (Python):
import math

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

d1 = d2 = d3 = dinf = 0.0
for i in range(n):
    di = abs(int(x[i]) - int(y[i]))
    d1 += di
    d2 += di ** 2
    d3 += di ** 3
    if di > dinf:
        dinf = di

d2 = math.sqrt(d2)
d3 = math.pow(d3, 1/3)
print(d1, d2, d3, dinf, sep='\n')

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

man = 0
euc = 0
euc3 = 0
che = 0
for i in range(n):
    man += abs(x[i]-y[i])
    euc += abs(x[i]-y[i])**2
    euc3 += abs(x[i]-y[i])**3
    che = max(che, abs(x[i]-y[i]))

print(man)
print(euc**0.5)
print(euc3**(1/3))
print(che)

Solution (Python):
a = int(input())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
D1,D2,D3,D00 = 0., 0., 0., 0.
for i in range(a):
    D1 += abs(x[i] - y[i])
    D2 += abs(x[i] - y[i])**2
    D3 += abs(x[i] - y[i])**3
    if D00 < abs(x[i] - y[i]):
        D00 = abs(x[i] - y[i])
print(D1)
print(D2**(1/2))
print(D3**(1/3))
print(D00)

Solution (Python):
from typing import List


def minkowski():
    num_elements = int(input())
    x_list: List[int] = list(map(int, input().split()))
    y_list: List[int] = list(map(int, input().split()))

    for p in range(1, 4):  
        sum_error = 0
        for i in range(num_elements):
            sum_error += abs(x_list[i] - y_list[i]) ** p
            sum_dist = sum_error ** (1 / p)
        print(f"{sum_dist:.6f}")

    max_dist = 0  
    for i in range(num_elements):
        dist = abs(x_list[i] - y_list[i])
        if dist > max_dist:
            max_dist = dist
    print(f"{max_dist:.6f}")


if __name__ == "__main__":
    minkowski()

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 = [int(x) for x in input().split()]
y = [int(y) for y in input().split()]

man = 0
for i in range(n):
    man += math.sqrt((x[i]-y[i])**2)
print(f'{man:.6f}')

euc = 0
for i in range(n):
    euc += (x[i]-y[i])**2
Euc = math.sqrt(euc)
print(f'{Euc:.6f}')

n3 = 0
for i in range(n):
    n3 += (math.sqrt((x[i]-y[i])**2))**3
N3 = n3**(1/3)
print(f'{N3:.6f}')

che = []
for i in range(n):
    che.append(math.sqrt((x[i]-y[i])**2))
Che = max(che)
print(f'{Che:.6f}')

Solution (Python):
n = int(input())
x_list = list(map(int, input().split()))
y_list = list(map(int, input().split()))
Dxy1, Dxy2, Dxy3 = 0, 0, 0
Dxyinf_list = []

for x, y in zip(x_list, y_list):
    Dxy1 += abs(x-y)
    Dxy2 += (abs(x-y))**2
    Dxy3 += (abs(x-y))**3
    Dxyinf_list.append(abs(x-y))

Dxy2 = Dxy2**(1/2)
Dxy3 = Dxy3**(1/3)
Dxyinf = max(Dxyinf_list)

print('{0:.6f}'.format(Dxy1))
print('{0:.6f}'.format(Dxy2))
print('{0:.6f}'.format(Dxy3))
print('{0:.6f}'.format(Dxyinf))

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

def MDD(p,x,y):
    ans=0
    for i,j in zip(x,y):
        ans+=abs(i-j)**p
    ans=ans**(1/p)
    print(ans)
MDD(1,x,y)
MDD(2,x,y)
MDD(3,x,y)
print(max(abs(i-j) for i,j in zip(x,y)))

Solution (Python):
import math

n = int(input())
xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))

f_inf = float('inf')



for p in range(1,5):
    sum1 = 0
    for i in range(n):
        tmp = abs(xlist[i] - ylist[i])**p
        sum1 += tmp
    
    if p == 4:
        maax = 0
        for i in range(n):
            maax = max(abs(xlist[i] - ylist[i]), maax)
        print(maax)
    else:
        print(sum1**(1/p))

Solution (Python):
n = int(input())
vector_x = [int(x) for x in input().split()]
vector_y = [int(y) for y in input().split()]

distance_m = 0
distance_u = 0
distance_p3 = 0
distance_mic = 0

for i in range(n):
    distance_m += abs(vector_x[i] - vector_y[i])
    distance_u += abs(vector_x[i] - vector_y[i]) ** 2
    distance_p3 += abs(vector_x[i] - vector_y[i]) ** 3
    if distance_mic < abs(vector_x[i] - vector_y[i]):
        distance_mic = abs(vector_x[i] - vector_y[i])

print(distance_m)
print(distance_u ** (1/2))
print(distance_p3 ** (1/3))
print(float(distance_mic))

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

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

dim_list = [1,2,3,float('inf')]

for dim in dim_list:
    D = [0]*n
    if dim == float('inf'):
        for i in range(n): 
            D[i] = abs(x[i] - y[i])
        print("{:.6f}".format(max(D)))
    else:
        for i in range(n):
            D[i] = abs(x[i] - y[i])**dim
        
        print("{:.6f}".format(sum(D)**(1/dim)))

Solution (Python):
n=int(input())
x_arr=map(float,input().split())
y_arr=map(float,input().split())

r1,r2,r3,rm=0,0,0,0

for x,y in zip(x_arr, y_arr):
    tmp=abs(x-y)
    r1 += tmp
    r2 += tmp**2
    r3 += tmp**3
    rm = max(rm, tmp)

print(r1)
print(r2**(0.5))
print(r3**(1/3))
print(rm)

Solution (Python):
def Dxy(a,b,dim):

    if dim == 'inf':
        c=[abs(x-y) for (x,y) in zip(a,b)]
        result = max(c) 
        return result
    else:
        sum = 0.0 
        for i in range(n):
            tmp = abs(a[i]-b[i])
            sum += pow(tmp,dim)
        result = pow(sum,1.0/dim)
        return result

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

print(f'{Dxy(x,y,1):6f}')
print(f'{Dxy(x,y,2):6f}')
print(f'{Dxy(x,y,3):6f}')
print(f'{Dxy(x,y,"inf"):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):
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):
subabs = lambda x, y: [abs(i - j) for i, j in zip(x, y)]
minkowski = lambda arr, p: sum(a ** p for a in arr) ** (1 / p)

_ = input()
x = map(float, input().split())
y = map(float, input().split())
subs = subabs(x, y)

print("{:.8f}".format(minkowski(subs, 1)))
print("{:.8f}".format(minkowski(subs, 2)))
print("{:.8f}".format(minkowski(subs, 3)))
print("{:.8f}".format(max(subs)))

Solution (Python):
from math import sqrt

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

p_1 = sum([abs(x[i]-y[i]) for i in range(n)])
p_2 = sqrt(sum([abs(x[i]-y[i])**2 for i in range(n)]))
p_3 = pow(sum([abs(x[i]-y[i])**3 for i in range(n)]), 1.0/3.0)
p_inf = max([abs(x[i]-y[i]) for i in range(n)])
print(p_1)
print(p_2)
print(p_3)
print(p_inf)

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

d1, d2, d3, dx = 0, 0, 0, 0
for i in range(n):
    d1 += abs(x_array[i] - y_array[i])
    d2 += (x_array[i] - y_array[i])**2
    d3 += abs(x_array[i] - y_array[i])**3
    d = abs(x_array[i] - y_array[i])
    if d > dx:
        dx = d
print(d1)
print(d2**0.5)
print(d3**(1/3))
print(dx)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
d = [0] * 4

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

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

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


for t in range(3):
    temp = [abs(a-b)**(t+1) for (a,b) in zip(x,y)]
    print(sum(temp)**(1/(1+t)))


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

Solution (Python):
import math

num = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
xy = [abs(i - j) for i,j in zip(x, y)] 
for i in range(3):
  result = 0
  p = i + 1
  for j in xy:
    result += j ** p
  result = math.pow(result, 1 / p)
  print(result)
result = 0
print(max(xy))

Solution (Python):
import math
n = int(input())
s = list(map(int,input().split()))
t = list(map(int,input().split()))
L=[]
for i in range(n):
   L.append(abs(s[i]-t[i]))
d1 = sum(L)
d2 = math.sqrt(sum(map(lambda x: x**2,L)))
d3 =math.pow(sum(map(lambda x: x**3,L)),(1.0/3.0))
dinf=max(L)
print('{:.5f}\n{:.5f}\n{:.5f}\n{:.5f}'.format(d1,d2,d3,dinf))

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


def func(p):
    sum_num = 0
    for i in range(n):
        sum_num += abs(x[i] - y[i]) ** p
    print(f'{sum_num ** (1 / p):.5f}')


func(1)
func(2)
func(3)
print(f'{max(abs(x_i - y_i) for x_i, y_i in zip(x, y)):.5f}')

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

d1=0
d2=0
d3=0
d9=0
for i in range(n):
    if x[i]>y[i]:
        d=x[i]-y[i]
    else:
        d=y[i]-x[i]
    d1+=d

for i in range(n):
    d=(x[i]-y[i])**2
    d2+=d
d2=d2**(1/2)

for i in range(n):
    if x[i]>y[i]:
        d=(x[i]-y[i])**3
    else:
        d=(y[i]-x[i])**3
    d3+=d
d3=d3**(1/3)
z=[]
for i in range(n):
    if x[i]>y[i]:
        d=x[i]-y[i]
    else:
        d=y[i]-x[i]
    z.append(d)
d9=max(z)

print(f'{d1:.6f}')
print(f'{d2:.6f}')
print(f'{d3:.6f}')
print(f'{d9:.6f}')

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, 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(ans ** (1 / p))

print(max(c))

Solution (Python):
import math
import itertools
import sys

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

  p1 = 0
  p2 = 0
  p3 = 0
  pf = 0

  for i in range(n):
    p1 += math.sqrt((X[i] - Y[i]) ** 2)
    p2 += (X[i] - Y[i]) ** 2
    p3 += (math.sqrt((X[i] - Y[i]) ** 2)) ** 3
    if pf < math.sqrt((X[i] - Y[i]) ** 2):
      pf = math.sqrt((X[i] - Y[i]) ** 2)

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

  print(p1,p2,p3,pf, sep='\n')

if __name__ == '__main__':
  main()

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

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

Solution (Python):
from math import sqrt

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


def dxy(p):
    l = [(abs(x[i]-y[i]))**p for i in range(n)]
    sum_l = sum(l)
    return sum_l ** (1/p)

for p in range(1, 4):
    print(dxy(p))

ls = [abs(x[i]-y[i]) for i in range(n)]
print(max(ls))

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

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

for i in range(N):
    abs_xy.append(abs(x[i] - y[i]))

abs_xy_2 = [abs_xy[i] ** 2 for i in range(N)]
abs_xy_3 = [abs_xy[i] ** 3 for i in range(N)]

print(sum(abs_xy))
print(sum(abs_xy_2) ** (1 / 2))
print(sum(abs_xy_3) ** (1 / 3))
print(max(abs_xy))

Solution (Python):
import math

n = int(input())
x = input().split()
x_list = [int(xi) for xi in x]
y = input().split()
y_list = [int(yi) for yi in y]
dm, de, d3, dc = 0, 0, 0, 0
d = []

i = 0
while n > i:
    d.append(abs(x_list[i] - y_list[i]))
    dm += d[i]
    i += 1

i = 0
while n > i:
    de += (x_list[i] - y_list[i]) ** 2
    i += 1
de = math.sqrt(de)

i = 0
while n > i:
    d3 += abs(x_list[i] - y_list[i]) ** 3
    i += 1
d3 = d3 ** (1/3)

print(dm)
print(de)
print(d3)
print(max(d))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d1 = 0
d2sqr = 0
d3cube = 0
d_inf = 0

for i in range(n):
    d1 += abs(a[i] - b[i])
    d2sqr += (a[i] - b[i]) ** 2
    d3cube += abs(a[i] - b[i]) ** 3
    d_inf = max(d_inf, abs(a[i] - b[i]))

d2 = d2sqr ** (1/2)
d3 = d3cube ** (1/3)

print(d1)
print(d2)
print(d3)
print(d_inf)

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

p1,p2,p3,p4 = 0,0,0,0
for i,j in zip(x,y):
    p1 += abs(i-j)
    p2 += abs(i-j)**2
    p3 += abs(i-j)**3
    p4 = abs(i-j) if p4 < abs(i-j) else p4

print(p1)
print(p2**0.5)
print(p3**(1/3))
print(float(p4))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
sum1 = 0
sum2 = 0
sum3 = 0
sum8 = 0
for i in range(n):
    d = abs(x[i]-y[i])
    sum1 += d
    sum2 += d**2
    sum3 += d**3
    if sum8 < d:
        sum8 = d
print(sum1)
print(sum2**0.5)
print(sum3**(1/3))
print(sum8)

Solution (Python):
import math



def D1(x,y):
    d1 = 0
    for i in range(len(x)):
        d1 +=  abs(x[i] - y[i])
    return d1

def D2(x,y):
    d2 = 0
    for i in range(len(x)):
        d2 +=  abs(x[i] - y[i]) ** 2
    return d2 ** (1/2)

def D3(x,y):
    d3 = 0
    for i in range(len(x)):
        d3 +=  abs(x[i] - y[i]) ** 3
    return d3 ** (1/3)

def Dmax(x,y):
    dmax = 0
    for i in range(len(x)):
        if dmax <= abs(x[i] - y[i]):
            dmax = abs(x[i] - y[i])
    return dmax

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

print(D1(x,y))
print(D2(x,y))
print(D3(x,y))
print(Dmax(x,y))

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
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"{math.sqrt(d2):.6f}")

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

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

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

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

Solution (Python):
import math

n = int(input())

x = list(map(float, input().split()))
y = list(map(float, input().split()))


p_1 = 0
for i in range(n):
    p_1 += math.fabs(x[i] - y[i])


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


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


prep = []
for i in range(n):
    prep.append(math.fabs(x[i] - y[i]))
p_inf = max(prep)

print('{:.6f}'.format(p_1))
print('{:.6f}'.format(p_2))
print('{:.6f}'.format(p_3))
print('{:.6f}'.format(p_inf))

Solution (Python):

import math

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

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

p2 = 0
for i in range(n):
    p2 += (x[i] - y[i]) ** 2

p2 = math.sqrt(p2)

p3 = 0
for i in range(n):
    p3 += abs((x[i] - y[i])) ** 3

p3 = math.pow(p3, 1.0/3.0)

px = 0
l = list()
for i in range(n):
    l.append(abs(x[i] - y[i]))
    px = max(l)

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

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


for p in range(1, 4):
    D = 0
    for i in range(n):
        D += abs((x[i] - y[i]))**p
    ans = math.pow(D, 1/p)
    print(f"{ans:.6f}")

l = []
for i in range(n):
    l.append(abs((x[i] - y[i])))
print(max(l))

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

d1 = 0
d2 = 0
d3 = 0
d = []
for i in range(n):
    d1 += abs(float(x[i]) - float(y[i])) **1
    d2 += abs(float(x[i]) - float(y[i])) **2
    d3 += abs(float(x[i]) - float(y[i])) **3
    d.append(abs(float(x[i]) - float(y[i])))

print('{}'.format(d1))
print('{}'.format(d2**(1/2)))
print('{}'.format(d3**(1/3)))
print('{}'.format(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 += (abs(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 = []
for i in range(n):
    ans.append(abs(x[i]-y[i]))
print (max(ans))

Solution (Python):
def minkowski(xlst,ylst,p):
  d = list()
  for i in range(len(xlst)):
    d.append((abs(xlst[i] - ylst[i]))**p)
  D = sum(d) ** (1/p)
  return D

def mugen(xlst,ylst):
  d = list()
  for i in range(len(xlst)):
    d.append((abs(xlst[i] - ylst[i])))
  m = max(d)
  D = m
  return D

n = int(input())
xl = list(map(int,input().split()))
yl = list(map(int,input().split()))

D1 = minkowski(xl, yl, 1)
D2 = minkowski(xl, yl, 2)
D3 = minkowski(xl, yl, 3)
Dm = mugen(xl, yl)

print(D1)
print(D2)
print(D3)
print(Dm)

Solution (Python):
import math

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


print(sum(list(map(lambda x,y:abs(x-y),x,y))))

print(math.sqrt(sum(list(map(lambda x,y:(x-y)**2,x,y)))))

print(math.pow(sum(list(map(lambda x,y:abs(x-y)**3,x,y))),1/3))

print(max(list(map(lambda x,y:abs(x-y),x,y))))

Solution (Python):
n = int(input())
x = [float(i) for i in input().split()]
y = [float(i) for i in input().split()]

man_x_y = sum(abs(x[i]-y[i]) for i in range(n)) 
euk2_x_y = (sum((x[i]-y[i])**2 for i in range(n)))**(1/2)
euk3_x_y = (sum((abs(x[i]-y[i]))**3 for i in range(n)))**(1/3)

che_x_y = max(abs(x[i]-y[i]) for i in range(n)) 
print(man_x_y)
print(euk2_x_y)
print(euk3_x_y)
print(che_x_y)

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

def calc(X, Y, p):
    count = 0
    for x, y in zip(X, Y):
        a = abs(x - y)
        count += a ** p
    return count ** (1 / p)

print(calc(X, Y, 1))
print(calc(X, Y, 2))
print(calc(X, Y, 3))
print(max(abs(x - y) for x, y in zip(X, Y)))

Solution (Python):
import functools


if __name__ == "__main__":
    n = int(input())

    xs = list(map(int, input().split()))
    ys = list(map(int, input().split()))

    diffs = list(map(lambda x, y: abs(x - y), xs, ys))

    manhattan_distance = functools.reduce(lambda acc, diff: acc + diff, diffs, 0.0)
    euclidean_distance = (functools.reduce(lambda acc, diff: acc + (diff ** 2), diffs, 0.0))**(1 / 2)
    minkowski_distance_p3 = (functools.reduce(lambda acc, diff: acc + (diff ** 3), diffs, 0.0))**(1 / 3)
    chebyshev_distance = max(diffs)

    print(manhattan_distance)
    print(euclidean_distance)
    print(minkowski_distance_p3)
    print(chebyshev_distance)

Solution (Python):
n = int(input())
x_list = list(map(int, input().split()))
y_list = list(map(int, input().split()))
d = [abs(x - y) for x, y in zip(x_list, y_list)]

for i in range(1, 4):
    print(sum([j ** i for j in d]) ** (1 / i))
    
print(max(d))

Solution (Python):
N = int(input())
X = [float(x) for x in input().split()]
Y = [float(y) for y in input().split()]

for p in range(1, 4):
    print(sum(map(lambda x, y: abs(x - y) ** p, X, Y)) ** (1 / p))
print(max(map(lambda x, y: abs(x - y), X, Y)))

Solution (Python):
import math
n = int(input())
x = [0]*n
y = [0]*n
x = list(map(float,input().split()))
y = list(map(float,input().split()))
dist1 = 0
dist2 = 0
dist3 = 0
diste = 0
for i in range(n):
    dist1 += abs(x[i]-y[i])
    dist2 += abs(x[i]-y[i])**2
    dist3 += abs(x[i]-y[i])**3
    diste = max(diste,abs(x[i]-y[i]))
print(str(dist1))
print(str(dist2**(1/2)))
print(str(dist3**(1/3)))
print(str(diste))

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

def distance(X,Y,p):
    l = []
    sum = 0
    
    for xi, yi in zip(X,Y):
        d = abs(xi-yi)
        l.append(d)
        if p != 'inf':
            sum+=d**p
    
    if p == 'inf':
        D = max(l)
    else:
        D = round(sum**(1/p),5)
        
    print(D)
    
P = [1,2,3,'inf']
for p in P:
    distance(X,Y,p)

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

dif = [abs(a[i]-b[i]) for i in range(n)]
dif2 = [x**2 for x in dif]
dif3 = [x**3 for x in dif]

print(sum(dif))
print((sum(dif2))**(1/2))
print((sum(dif3))**(1/3))
print(max(dif))

Solution (Python):
import math
n = int(input())
x = [float(f) for f in input().split()]
y = [float(f) for f in input().split()]
L1 = 0
for i in range(n):
    L1 += abs(x[i] - y[i])
L2 = 0
for i in range(n):
    L2 += abs(x[i] - y[i])**2
L2 = pow(L2, 1.0/2.0)
L3 = 0
for i in range(n):
    L3 += abs(x[i] - y[i])**3
L3 = pow(L3, 1.0/3.0)
Linf = 0
for i in range(n):
    Linf = max(Linf, abs(x[i] - y[i]))
print(L1)
print(L2)
print(L3)
print(Linf)

Solution (Python):
import math

n = int(input())
xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))
d1 = sum([abs(x - y) for x, y in zip(xlist, ylist)])
d2 = sum([abs(x - y)**2 for x, y in zip(xlist, ylist)])**0.50
d3 = sum([abs(x - y)**3 for x, y in zip(xlist, ylist)])**(1/3)
dinf = max([abs(x - y) for x, y in zip(xlist, ylist)])
print(d1)
print(d2)
print(d3)
print(dinf)

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

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

d1,d2,d3,dinf= 0,0,0,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
    
    dinf = max(abs(X[i]-Y[i]),dinf)

print(d1)
print(d2**(1/2))
print(d3**(1/3))
print(dinf)

Solution (Python):
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
d_one = 0
d_two = 0
d_three = 0
d_inf = [0]*n


for i in range(n):
    d_one += abs(x[i]-y[i])
    d_two += abs(x[i] - y[i]) ** 2
    d_three += abs(x[i] - y[i]) ** 3
    d_inf[i] = abs(x[i] - y[i]) 
    
print(d_one)
print(math.sqrt(d_two))
print(math.pow(d_three, 1.0 / 3.0))
print(max(d_inf))

Solution (Python):
n = int(input())
x_v = list(map(int, input().split(" ")))
y_v = list(map(int, input().split(" ")))

def mincos(x_v, y_v, p):
    wa = 0
    for i in range(n):
        sa = x_v[i] - y_v[i]
        if x_v[i] - y_v[i] < 0:
            sa = y_v[i] - x_v[i]
        wa += sa**p
    return wa**(1/p)
list=[]
print(float(mincos(x_v, y_v, 1)))
print(float(mincos(x_v, y_v, 2)))
print(float(mincos(x_v, y_v, 3)))
for i in range(n):
    sa = x_v[i] - y_v[i]
    if x_v[i] - y_v[i] < 0:
        sa = y_v[i] - x_v[i]
    list.append(sa)
print(max(list))

Solution (Python):
n = int(input())
xi = [int(x) for x in input().split()]
yi = [int(y) for y in input().split()]
ans1 = ans2 = ans3 = ansm = 0
for i in range(n):
    sa = abs(xi[i]-yi[i])
    ans1 += sa
    ans2 += sa**2
    ans3 += sa**3
    if ansm < sa:
        ansm = sa
print(ans1,ans2**(1/2),ans3**(1/3),ansm, end='\n')

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


def distance(x, y, p):
    dist = sum([abs(x_ - y_)**p for x_, y_ in zip(x, y)]) ** (1/p)
    return dist


manhattan = distance(x, y, 1)
euclid = distance(x, y, 2)
minkowski = distance(x, y, 3)
chebyshev = max([abs(x_ - y_) for x_, y_ in zip(x, y)])

print(manhattan)
print(euclid)
print(minkowski)
print(chebyshev)

Solution (Python):
import math

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

r_1 = 0
r_2 = 0
r_3 = 0
r_inf = 0

for i in range(n):
    r_1 += abs(x[i]-y[i]) 
print(r_1)

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

for i in range(n):
    r_3 += abs(x[i]-y[i])**3
r_3 = math.pow(r_3, (1.0/3.0))
print(r_3)

for i in range(n):
    r_inf = max(abs(x[i]-y[i]), r_inf)
print(r_inf)

Solution (Python):
import math

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

print(sum(map(lambda v: math.fabs(v[0] - v[1]), zip(x, y))))
print(sum(map(lambda v: math.fabs((v[0] - v[1]) ** 2), zip(x, y))) ** (1/2))
print(sum(map(lambda v: math.fabs((v[0] - v[1]) ** 3), zip(x, y))) ** (1/3))
print(max(map(lambda v: math.fabs(v[0] - v[1]), zip(x, y))))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
def d(a,b):
    if a>b:
        return a-b
    else:
        return b-a
d1=0
d2=0
d3=0
dinf=0
for i in range(n):
    d1+=d(x[i],y[i])
    d2+=(d(x[i],y[i]))**2
    d3+=(d(x[i],y[i]))**3
d2=d2**(1/2)
d3=d3**(1/3)
dinf=d(x[0],y[0])
for i in range(n):
    if dinf<d(x[i],y[i]):
        dinf=d(x[i],y[i])
print(round(d1,6))
print(round(d2,6))
print(round(d3,6))
print(round(dinf,6))

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

abs_xy = [abs(i-j) for i,j in zip(x,y)]

print(sum(abs_xy))
print((sum(d**2 for d in abs_xy)) ** 0.5)
print((sum(d**3 for d in abs_xy)) ** (1/3))
print(max(abs_xy))

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')