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):
n = int(input())
*x, = map(int, input().split())
*y, = map(int, input().split())
print(sum([abs(x[i]-y[i]) for i in range(n)]))
print(sum([(x[i]-y[i])**2 for i in range(n)])**0.5)
print(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 = [0,0,0]


for p in range(1,4):
    for i in range(n):
        D[p-1] += abs(x[i] - y[i]) ** p

    D[p-1] = D[p-1] ** (1 / p)


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


print(D[0])
print(D[1])
print(D[2])
print(Dinf)

Solution (Python):
num = int(input())
ab=[]
ab2 = []
ab3 = []

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


for i in range(num):
    ab.append(abs(x[i]-y[i]))
    ab2.append(abs(x[i]-y[i])**2)
    ab3.append(abs(x[i]-y[i])**3)

print("{:.8f}".format(sum(ab)))
print("{:.8f}".format((sum(ab2))**(1/2)))
print("{:.8f}".format((sum(ab3))**(1/3)))
print("{:.8f}".format(max(ab)))

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

for p in range(1, 4):
    
    result = 0
    for i in range(n):
        result += pow(abs(x[i] - y[i]), p)
    result = pow(result, 1/p)
    print(result)

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

Solution (Python):
import math
N = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

a, b, c= 0, 0, 0
d = []

for i in range(N):
    diff = abs(X[i] - Y[i])
    a += diff
    b += (diff)**2
    c += (diff)**3
    d.append(diff)

print('{0:8f}'.format(a))
print('{0:8f}'.format(math.sqrt(b)))
print('{0:8f}'.format(c**(1/3)))
print('{0:8f}'.format(max(d)))

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

s = 0
t = 0
u = 0
v = []

for i in range(n):
	x = abs(a[i]-b[i])
	s += x
	t += x**2
	u += x**3
	v.append(x)

print("{:.10f}".format(s))
print("{:.10f}".format(math.sqrt(t)))
print("{:.10f}".format(u**(1/3)))
print("{:.10f}".format(max(v)))

Solution (Python):
import math


n = int(input())


x = [float(i) for i in input().split()]


y = [float(j) for j in input().split()]


D1 = sum([abs(k - l) for (k, l) in zip(x, y)])
print(D1)


D2 = math.sqrt(sum([abs(k - l)**2 for (k, l) in zip(x, y)]))
print(D2)


D3 = (sum([abs(k - l)**3 for (k, l) in zip(x, y)]))**(1/3)
print(D3)


Dc = max([abs(k - l) for (k, l) in zip(x, y)])
print(Dc)

Solution (Python):
import math

if __name__ =="__main__":

    param = input()

    param = input().split(" ")
    x = [int(a) for a in param]

    param = input().split(" ")
    y = [int(a) for a in param]

    
    d1 = math.pow(sum([math.fabs(xi - yi) for xi, yi in zip(x, y)]), 1/1.0)

    
    d2 = math.pow(sum([math.fabs(xi - yi)**2 for xi, yi in zip(x, y)]), 1/2.0)

    
    d3 = math.pow(sum([math.fabs(xi - yi)**3 for xi, yi in zip(x, y)]), 1/3.0)

    
    dm = max([math.fabs(xi - yi) for xi, yi in zip(x, y)])

    print(d1)
    print(d2)
    print(d3)
    print(dm)

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):
def lp_norm(x, y, p):
    if p == "INF":
        return max([abs(x_i - y_i) for (x_i, y_i) in zip(x, y)])
    else:
        return (sum([abs(x_i - y_i) ** p for (x_i, y_i) in zip(x, y)])) ** (1/p)


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

for i in [1, 2, 3, "INF"]:
    print(lp_norm(x, y, i))

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

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for p in (1,2,3):
    sigma = 0
    for i in range(n):
        sigma += abs(x[i]-y[i])**p
    Dxy = sigma**(1/p)
    print('{:.6f}'.format(Dxy))
max = 0
for i in range(n):
    if max < abs(x[i]-y[i]):
        max = abs(x[i]-y[i])
print('{:.6f}'.format(max))

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

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

abs_dist_lst = [abs(z[0] - z[1]) for z in zip(x, y)]

print(sum(abs_dist_lst))

for p in [2, 3]:
    dist = 0
    for abs_d in abs_dist_lst:
        dist += abs_d ** p
    dist = dist ** (1 / p)
    print(dist)

print(max(abs_dist_lst))

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):
    p1+=abs(x[i]-y[i])
    p2+=abs(x[i]-y[i])**2
    p3+=abs(x[i]-y[i])**3
    pinf=max(pinf,abs(x[i]-y[i]))
p2=math.sqrt(p2)
p3=p3**(1/3)

print(p1)
print(p2)
print(p3)
print(pinf)

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

p1=list(map(int, input().split()))
p2=list(map(int, input().split()))

mhd=0
ecd=0
trd=0
chd=0
for i  in range(n):
    mhd=mhd+abs(p1[i]-p2[i])
    ecd= ecd+abs(p1[i]-p2[i])**2
    trd=trd+abs(p1[i]-p2[i])**3
    chd=max(chd, abs(p1[i]-p2[i]))

print(mhd)
print(ecd**0.5)
print(trd**(1/3))
print(chd)

Solution (Python):
from math import *

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
vv = list(zip(x, y))
da = lambda v, p: pow(sum(map(lambda q: pow(abs(q[0] - q[1]), p), v)), 1 / p)
di = lambda v: max(map(lambda q: abs(q[0] - q[1]), v))
for i in range(3):
    print(da(vv,i+1))
print(di(vv))

Solution (Python):
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
d = [1, 2, 3, 4]
D = [0.0]*5
for i in d:
    if i == 1:
        D[i] = sum((abs(x[j] - y[j]) for j in range(n)))
    elif i == 2:
        D[i] = math.sqrt(sum((x[j] - y[j])**2 for j in range(n)))
    elif i == 3:
        D[i] = (sum(abs(x[j] - y[j])**3 for j in range(n)))**(1.0/3)
    else:
        D[i] = max(abs(x[j] - y[j]) for j in range(n))
    print('%.6f' % D[i])

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x_y = [abs(x[i]-y[i]) for i in range (n)]
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_infinity = max(x_y)
print(f"{p1:.6f}")
print(f"{p2:.6f}")
print(f"{p3:.6f}")
print(f"{p_infinity:.6f}")

Solution (Python):
from math import *
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
doo=max([abs(x[i]-y[i]) for i in range(n)])
d1=d2=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
print(d1)
print(d2**0.5)
print(d3**(1/3))
print(doo)

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

D1 = D2 = D3 = Dc = 0
for xi, yi in zip(x, y):
    D1 += abs(xi-yi)
    D2 += abs(xi-yi)**2
    D3 += abs(xi-yi)**3
    Dc = max(Dc, abs(xi-yi))

D2 = D2**(1/2)
D3 = D3**(1/3)

print("{:.8f}".format(D1))
print("{:.8f}".format(D2))
print("{:.8f}".format(D3))
print("{:.8f}".format(Dc))

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

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

Solution (Python):

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

for i in range(n):
    x[i] = int(x[i])
    y[i] = int(y[i])
    if x[i]>=y[i]:
        dis.append(x[i]-y[i])
    else:
        dis.append(y[i]-x[i])


print(sum(dis))


sum = 0
for elem in dis:
    sum = sum + elem**2
print(sum**(1/2))


sum = 0
for elem in dis:
    sum = sum + elem**3
print(sum**(1/3))


print(max(dis))

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

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

p1 = sum(p)
p2 = sum([ d**2 for d in p ]) ** (1/2)
p3 = sum([ d**3 for d in p ]) ** (1/3)
pinf = max(p)

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

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

a = 0
b = 0
c = 0
d = [0 for j in range(n)]

for i in range(n):
 a += abs(x[i]-y[i])
 b += (x[i]-y[i])**2
 c += abs(x[i]-y[i])**3
 d[i] = abs(x[i]-y[i])

b = b**(1/2)
c = c**(1/3)

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

Solution (Python):
from math import *
from statistics import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    input()
    xx = list(map(int, input().split()))
    yy = list(map(int, input().split()))
    d1=d2=d3=d4=0
    for x,y in zip(xx,yy):
        d=abs(x-y)
        d1+=d
        d2+=d**2
        d3+=d**3
        d4=max(d4,d)
    print(d1)
    print(d2**0.5)
    print(d3**(1/3))
    print(d4)

main()

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

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

print(res)

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

print(res ** (1/2))

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

print(res ** (1/3))

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

print(res)

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

import math

p1 = []
p2 = []
p3 = []

for i in range(n):
    p1.append(abs(X[i] - Y[i]))
    p2.append(p1[i]**2)
    p3.append(p1[i]**3)
    
print(sum(p1))
print(sum(p2)**(1/2))
print(sum(p3)**(1/3))
print(max(p1))

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

for i in range(n):
    t = abs(x[i]-y[i])
    a += t
    b += t**2
    c += t**3
    d.append(t)

print(a)
print(b**(1/2))
print(c**(1/3))
print(max(d))

Solution (Python):
N = int(input())
X = [int(i) for i in input().split()]
Y = [int(i) for i in input().split()]
X_Y = [abs(x-y) for x, y in zip(X, Y)]

for p in [1, 2, 3, 'inf']:
    if p == 'inf':
        d = max(X_Y)
    else:
        d = sum([x_y**p for x_y in X_Y]) ** (1/p)
    
    print(d)

Solution (Python):
import math

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

p1 = p2 = p3 = pinf = 0

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

p2 = math.sqrt(p2)
p3 = math.pow(p3, 1/3.0)

print(p1)
print(p2)
print(p3)
print(pinf)

Solution (Python):
from math import sqrt
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
d1,d2,d3,di=0,0,0,abs(x[0]-y[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
    if di < abs(x[i]-y[i]):
        di=abs(x[i]-y[i])
d2=sqrt(d2)
d3=d3**(1/3)
print(d1,d2,d3,di,sep='\n')

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

m1 = m2 = m3 = mi = 0
for i in range(n):
    m1 += abs(x[i]-y[i])
    m2 += (x[i]-y[i])**2
    m3 += (abs(x[i]-y[i]))**3
    mi = max([abs(x[i]-y[i]), mi])
print(m1)
print(m2**0.5)
print(m3**(1/3))
print(mi)

Solution (Python):
import math

n = int( input() )
x = [ float( val ) for val in input().split( ' ' ) ]
y = [ float( val ) for val in input().split( ' ' ) ]

Dxy = Dxy2 = Dxy3 = Dxyp = 0
for i in range( n ):
	t = abs(x[i]-y[i])
	Dxy += t
	Dxy2 += t**2
	Dxy3 += t**3
	Dxyp = max( Dxyp, t )
print( Dxy )
print( Dxy2**(1/2) )
print( Dxy3**(1/3) )
print( Dxyp )

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

print(sum([abs(x[i]-y[i]) for i in range(n)]))
print(sqrt(sum([(x[i]-y[i])**2 for i in range(n)])))
print(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=[float(k) for k in input().split()]
y=[float(k) for k in input().split()]
for i in range(1,4):
    print((sum([math.fabs(x[k]-y[k])**i for k in range(n)]))**(1/i))
m=-1000000
for k in range(n):
    v=math.fabs(x[k]-y[k])
    if v>m:
        m=v
print(m)

Solution (Python):
dev = int(input())
list_x = [float(i) for i in input().split()]
list_y = [float(i) for i in input().split()]

listabs = []
for vector in zip(list_x, list_y):
    x, y = vector
    listabs.append(abs(x -y))

for p in range(1, 4):
    D = 0
    for vector in listabs:
        D += vector**p
    D = D**(1/p)
    print(D)

print(max(listabs))

Solution (Python):
from math import *
n = int(input())
x = []
y = []
x[:] = map(int,input().split())
y[:] = map(int,input().split())

dxy1 = 0.0
dxy2 = 0.0
dxy3 = 0.0
dxyinf = 0.0

for i in range(0,n):
    dxy1 += abs(x[i]-y[i])
    dxy2 += (x[i]-y[i])**2
    dxy3 += (abs(x[i]-y[i]))**3
    if (dxyinf < abs(x[i]-y[i])):
        dxyinf = abs(x[i]-y[i])
dxy2 = sqrt(dxy2)
dxy3 = pow(dxy3, 1.0/3.0)
print(dxy1)
print(dxy2)
print(dxy3)
print(dxyinf)

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

distance = {
    1: lambda: sum([abs(x[i] - y[i]) for i in range(n)]),
    2: lambda: pow(sum([pow(abs(x[j] - y[j]), 2) for j in range(n)]), 1 / 2),
    3: lambda: pow(sum([pow(abs(x[j] - y[j]), 3) for j in range(n)]), 1 / 3),
    4: lambda: max([abs(x[i] - y[i]) for i in range(n)])
}

print(distance[1]())
print(distance[2]())
print(distance[3]())
print(distance[4]())

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 i in range(1,4):
    D=0
    for d in a:
        D+=d**i
    print(float(D**(1/i)))

print(max(a))

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

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

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

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

Solution (Python):
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
dxy1 = 0
for i in range(n):
    dxy1 += abs(x[i]-y[i])
dxy2 = 0
for i in range(n):
    dxy2 += abs(x[i]-y[i])**2
dxy2 = math.sqrt(dxy2)
dxy3 = 0
for i in range(n):
    dxy3 += abs(x[i]-y[i])**3
dxy3 = dxy3**(1/3)
dxy4 = 0
for i in range(n):
    tmp = abs(x[i]-y[i])
    if dxy4 < tmp:
        dxy4 = tmp
print(dxy1)
print(dxy2)
print(dxy3)
print(dxy4)

Solution (Python):
import math
def Minkowski(r, n, x, y):
    sum_dif = 0
    for i in range(n):
        dif = abs(x[i] - y[i])
        sum_dif += dif ** r
    print(sum_dif ** (1 / r))

def Chebyshev(n, x, y):
    max_dif = 0
    for i in range(n):
        dif = abs(x[i] - y[i])
        max_dif = max(dif, max_dif)
    print(max_dif)

n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
Minkowski(1, n, x, y)
Minkowski(2, n, x, y)
Minkowski(3, n, x, y)
Chebyshev(n, x, y)

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):
    total=0
    for d in c:
        total+=d**p
    ans=total**(1/p)
    print(ans)

print(max(c))

Solution (Python):
import math
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
p1 =0
for i in range(len(x)):
    p1 += abs(x[i]-y[i])
print(p1)
p2=0
for i in range(len(x)):
    p2 += (x[i]-y[i])**2
print(math.sqrt(p2))
p3=0
for i in range(len(x)):
    p3 += abs(x[i]-y[i])**3
print(math.pow(p3,1/3))
pinf=0
for i in range(len(x)):
    if abs(x[i]-y[i]) >= pinf:
        pinf = abs(x[i]-y[i])
print(pinf)

Solution (Python):
import math
n=int(input())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
D=[abs(x-y) for x,y in zip(X,Y)]
p1=sum(D)
p2=math.sqrt(sum(i**2 for i in D))
p3=sum(i**3 for i in D)**(1/3)
pinf=max(D)
print(p1)
print(p2)
print(p3)
print(pinf)

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

def calc_chebyshev_distance(n, x, y):
    max_distance = -1
    for i in range(n):
        distance = abs(x[i] - y[i])
        if distance > max_distance:
            max_distance = distance
    return max_distance

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

d1 = calc_mincowski_distance(n, 1, x, y)
d2 = calc_mincowski_distance(n, 2, x, y)
d3 = calc_mincowski_distance(n, 3, x, y)
d_infinity = calc_chebyshev_distance(n, x, y)

print(d1, d2, d3, d_infinity, sep='\n')

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

D_p1 = 0.0
for i in range(len(x)):
    D_p1 += abs(x[i] - y[i])

D_p2 = 0.0
for i in range(len(x)):
    D_p2 += (x[i]-y[i])**2
D_p2 = D_p2**(1/2)

D_p3 = 0.0
for i in range(len(x)):
    D_p3 += abs((x[i] - y[i]))**3
D_p3 = D_p3**(1/3)

D_pinf = 0.0
inf_list =[]
for i in range(len(x)):
    inf_list.append(abs(x[i]-y[i]))
D_pinf = max(inf_list)

print(D_p1)
print(D_p2)
print(D_p3)
print(D_pinf)

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

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

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

D(1)
D(2)
D(3)
print('{:.6f}'.format(max(z)))

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
def distant(A,B,p):
    count=0
    for i in range(len(A)):
        count +=(abs(A[i]-B[i]))**p
    count=count**(1/p)
    return print("%.10f"%count)
distant(A,B,1)
distant(A,B,2)
distant(A,B,3)

point=0
for i in range(n):
    point=max(point,abs(A[i]-B[i]))
print("%.10f"%point)

Solution (Python):
import math


n = int(input())
x_list = list(map(int, input().split()))
y_list = list(map(int, input().split()))


d1_list = [abs(x-y) for x, y in zip(x_list, y_list)]
d1 = sum(d1_list)


d2_list = [abs((x-y))**2 for x, y in zip(x_list, y_list)]
d2 = math.sqrt(sum(d2_list))


d3_list = [(abs(x-y))**3 for x, y in zip(x_list, y_list)]
d3 = (sum(d3_list))**(1/3)


d4_list = [abs(x-y) for x, y in zip(x_list, y_list)]
d4 = max(d4_list)


print('{:.8f}'.format(d1))
print('{:.8f}'.format(d2))
print('{:.8f}'.format(d3))
print('{:.8f}'.format(d4))

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

for i in range(1,4):
    total = 0
    Dxy = 0   
    for j,k in zip(a,b):
        total += pow(abs(j-k),i)
        Dxy = pow(total,(1/i))
    print(Dxy)

c = []
for j,k in zip(a,b):
    c.append(abs(j-k))
print(max(c))

Solution (Python):
n = int(input())
x = [float(x) for x in input().split()]
y = [float(x) for x in input().split()]
z = [0]*4

for _ in range(n):
    z[0] += abs(x[_] - y[_])
    z[1] += abs(x[_] - y[_])**2
    z[2] += abs(x[_] - y[_])**3
    if abs(x[_] - y[_]) > z[3]:
           z[3] = abs(x[_] - y[_])    

print(z[0])
print(z[1]**0.5)
print(z[2]**(1/3))
print(z[3])

Solution (Python):
def d(p):
    return sum(abs(x[i] - y[i]) ** p for i in range(n)) ** (1 / p)


n = int(input())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
print(d(1), d(2), d(3), max([abs(x[i] - y[i]) for i in range(n)]), sep="\n")

Solution (Python):
n = int(input())
x = [float(i) for i in input().split()]
y = [float(i) for i in input().split()]
num = 1000
print(sum([abs(a - b) for a, b in zip(x, y)]))
print((sum([abs(a - b) ** 2 for a, b in zip(x, y)])) ** (1 / 2))
print((sum([abs(a - b) ** 3 for a, b in zip(x, y)])) ** (1 / 3))
print(max([abs(a - b) for a, b in zip(x, y)]))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d=[]
for i in range(n):
    d.append(abs(a[i]-b[i]))
d1=d2=d3=0
for e in d:
    d1+=e
    d2+=e**2
    d3+=e**3
d2=d2**(1/2)
d3=d3**(1/3)
dinf=max(d)
print('{:7f}'.format(d1))
print('{:7f}'.format(d2))
print('{:7f}'.format(d3))
print('{:7f}'.format(dinf))

Solution (Python):


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

Solution (Python):
import math

def Dxy_p(X,Y,n,p):
    ret=0
    for i in range(n):
        ret += pow(abs(X[i]-Y[i]), p)
    return pow(ret, 1/p)

def Dxy_inf(X,Y,n):
    ret=0
    for i in range(n):
        ret = max(ret, abs(X[i]-Y[i]))
    return ret

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

print(f"{Dxy_p(X,Y,n,1):.6f}")
print(f"{Dxy_p(X,Y,n,2):.6f}")
print(f"{Dxy_p(X,Y,n,3):.6f}")
print(f"{Dxy_inf(X,Y,n):.6f}")

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

d = [0]*4
d[0] = sum(abs(a - b) for a, b in zip(x, y)) 
d[1] = (sum((a - b)**2 for a, b in zip(x, y)))**0.5 
d[2] = (sum(abs(a - b)**3 for a, b in zip(x, y)))**(1/3) 
d[3] = max(abs(a - b) for a, b in zip(x, y)) 

for i in range(4):
    print("%.6f" % d[i])

Solution (Python):
import math
num = int(input())

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



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

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

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

m = []
for i in range(num):
    m.append(abs(x[i]-y[i]))

print(float(max(m)))

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


S = 0
for i in range(n):
	S += abs(x[i]-y[i])
D_1 = S
print("{:.8f}".format(D_1))


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


V = 0
for i in range(n):
	V += abs(x[i]-y[i])**3
D_3 = V**(1/3)
print("{:.8f}".format(D_3))


U = 0
max = 0
for i in range(n):
	if max <= abs(x[i]-y[i]):
		max = abs(x[i]-y[i])
print("{:.8f}".format(max))

Solution (Python):
n=int(input())
X=list(map(float,input().split()))
Y=list(map(float,input().split()))
for p in range(1,4):
    Dxy=float(0)
    for i in range(n):
        Dxy+=abs(X[i]-Y[i])**p
    Dxy=Dxy**(1/p)
    print(Dxy)
Dxy=float(0)
for i in range(n):
    if Dxy<abs(X[i]-Y[i]):Dxy=abs(X[i]-Y[i])
print(Dxy)

Solution (Python):
import math

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

D1=[]
D2=[]
D3=[]
for i in range(n):
    D1.append(abs(x[i]-y[i]))
    D2.append((x[i]-y[i])**2)
    D3.append((abs(x[i]-y[i]))**3)

print(sum(D1))
print(math.sqrt(sum(D2)))
print(math.pow(sum(D3),(1/3)))
print(max(D1))

Solution (Python):
def test():

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

	p_1 = 0
	p_2 = 0
	p_3 = 0
	p_inf = 0

	for i in range(n):
		
		tmp = abs(x_array[i] - y_array[i])
		p_1 += tmp
		p_2 += tmp ** 2
		p_3 += tmp ** 3
		if p_inf < tmp:
			p_inf = tmp

	p_2 = p_2**(1/2)
	p_3 = p_3**(1/3)

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


if __name__ == "__main__":
	test()

Solution (Python):
n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
a = []
p1, p2, p3, p_inf = 0, 0, 0, 0
for i in range(n):
    c = abs(x[i]-y[i])
    p1 += c
    p2 += c ** 2
    p3 += c ** 3
    a.append(c)

p_inf = max(a)

print(p1, p2**(1/2), p3**(1/3), p_inf)

Solution (Python):
n = int(input())
X = [int(_) for _ in input().split()]
Y = [int(_) for _ in input().split()]

d1, d2, d3, d = 0, 0, 0, 0 
for x, y in zip(X, Y):
    d1 += abs(x - y)
    d2 += abs(x - y) ** 2
    d3 += abs(x - y) ** 3
    d = max(d, abs(x - y))

print(d1)
print(d2 ** (1/2))
print(d3 ** (1/3))
print(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):
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):
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):
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):
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())
x=list(map(float,input().split()))
y=list(map(float,input().split()))
for p in range(1,4):
    Dxy=float(0)
    for i in range(n):
        Dxy+=abs(x[i]-y[i])**p
    Dxy=Dxy**(1/p)
    print(f'{Dxy:.6f}')
Dxy=float(0)
for i in range(n):
    if Dxy<abs(x[i]-y[i]):Dxy=abs(x[i]-y[i])
print(f'{Dxy:.6f}')

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):
import math
 
class Vector(object):
    def __init__(self, arr):
        self.arr = arr
 
    def sub(self, vec):
        return Vector([self.arr[i] - vec.arr[i] for i in range(len(self.arr))])
     
    def p_norm(self, p):
        return sum([abs(e) ** p for e in self.arr]) ** (1 / p)
     
    def inf_norm(self):
        return max([abs(e) for e in self.arr])
 
 
n = int(input())
x = Vector([int(e) for e in input().split()])
y = Vector([int(e) for e in input().split()])
z = x.sub(y)
 
print(z.p_norm(1))
print(z.p_norm(2))
print(z.p_norm(3))
print(z.inf_norm())

Solution (Python):
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
 
d1 = 0
d2 = 0
d3 = 0
d = [0] * n
 
for i in range(n) :
  d1 += abs(x[i] - y[i])
print(d1)
   
for j in range(n) :
  d2 += abs(x[j] - y[j]) ** 2
d2 = math.sqrt(d2)
print(d2)
 
for k in range(n) : 
  d3 += abs(x[k] - y[k]) ** 3
d3 = d3 ** (1/3)
print(d3)
 
for l in range(n) :
  d[l] = abs(x[l] - y[l])
di = max(d)  
print(di)

Solution (Python):
lw = []
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for p in range(1, 4):
    r = 0
    q = 0
    for i in range(n):
        z = abs(x[i] - y[i])
        if p == 1:
            if q < z:
                q = z
            if i == n - 1:
                lw.append(q)
        r += pow(z, p)
    print(pow(r, float(1 / p)))
print(lw[0])

Solution (Python):


n = input()
xs = map(float, input().split())
ys = map(float, input().split())
abs_d = [abs(x - y) for (x, y) in zip(xs, ys)]
d = [sum([i ** p for i in abs_d]) ** (1 / p) for p in range(1, 4)]
d.append(max(abs_d))

print(*d, sep='\n')

Solution (Python):
import math
N=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[abs(b[i]-a[i]) for i in range(N)]
print(sum(c))
print(math.sqrt(sum([c[i]**2 for i in range(N)])))
print((sum([c[i]**3 for i in range(N)]))**(1/3))
print(max(c))

Solution (Python):
import math

n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))

def calculate_distance(data1,data2,p):
  if len(data1) != len(data2):
    print("error")
  tmp_sum=0
  for i in range(len(data1)):
    tmp_sum += abs(data2[i]-data1[i]) ** p
  return tmp_sum ** (1/p)


print("{:.5f}".format(calculate_distance(a_list,b_list,1)))


print("{:.5f}".format(calculate_distance(a_list,b_list,2)))


print("{:.5f}".format(calculate_distance(a_list,b_list,3)))


tmp_list=[0]*n
for i in range(n):
  tmp_list[i]=abs(a_list[i]-b_list[i])
print("{:.5f}".format(max(tmp_list)))

Solution (Python):
def minkowski_distance(n, x, y, p):
    if p == float('inf'):
        distance = max([abs(x[i] - y[i]) for i in range(n)])
    else:
        distance = sum([abs(x[i] - y[i]) ** p for i in range(n)]) ** (1 / p)
    return distance

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

f_inf = float('inf')
print(minkowski_distance(n, x, y, 1))
print(minkowski_distance(n, x, y, 2))
print(minkowski_distance(n, x, y, 3))
print(minkowski_distance(n, x, y, f_inf))

Solution (Python):
def distance(x, y, p):
	dist = 0
	for cx, cy in zip(x, y):
		dist += abs(cx - cy) ** p
	return dist ** (1 / p)

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

print(distance(X, Y, 1))
print(distance(X, Y, 2))
print(distance(X, Y, 3))

max_dist = 0
for cx, cy in zip(X, Y):
	max_dist = max(max_dist, abs(cx - cy))
print(max_dist)