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=[int(X) for X in input().split()]
y=[int(Y) for Y in input().split()]
p1,p2,p3,p=0,0,0,[]
for i in range(n):
    p1+=abs(x[i]-y[i])
print(f'{p1:.5f}')
for i in range(n):
    p2+=(abs(x[i]-y[i]))**2
print(f'{p2**(1/2):.5f}')
for i in range(n):
    p3+=(abs(x[i]-y[i]))**3
print(f'{p3**(1/3):.5f}')
for i in range(n):
    p.append(abs(x[i]-y[i]))
print(f'{max(p):.5f}')

Solution (Python):
import math

S = list(map(int, open(0).read().split()))
N = S[0]
X = S[1:1+N]
Y = S[N+1:]

def calc(p):
    s = 0
    xy = [abs(X[i] - Y[i]) for i in range(N)]
    if p == 1:
        return sum(xy)
    elif p == 2:
        return sum([x ** 2 for x in xy]) ** 0.5
    elif p == 3:
        return sum([x ** 3 for x in xy]) ** (1/3)
    elif p == -1:
        return max(xy)

def show(x):
    print("{:.6f}".format(x))

show(calc(1))
show(calc(2))
show(calc(3))
show(calc(-1))

Solution (Python):
import math

n=int(input())
L=list(input().split())
M=list(input().split())

A=0
B=0
D=0
N=[]

for i in range(n):
    a=float(L[i])
    b=float(M[i])
    
    if a>b:
        A+=a-b
        D+=(a-b)**3
        N.append(a-b)
    else:
        A+=b-a
        D+=(b-a)**3
        N.append(b-a)
        
    B+=(a-b)**2
    C=math.sqrt(B)
    
    E=D**(1/3)

print(A)
print(C)
print(E)
print(max(N))

Solution (Python):
import math
n=int(input())
x=[float(a) for a in input().split()]
y=[float(b) for b in input().split()]
p=[float(1),float(2),float(3),math.inf]
for j in range(3):
    lst=[]
    for i in range(n):
        if x[i]>=y[i]:
            s=(x[i]-y[i])**(p[j])
        else:
            s=(y[i]-x[i])**(p[j])
        lst.append(s)
    t=sum(lst)
    print(f'{t**(1/p[j]):10.8f}')
lst1=[]
for k in range(n):
    if x[k]>=y[k]:
        u=x[k]-y[k]
    else:
        u=y[k]-x[k]
    lst1.append(u)
print(f'{max(lst1):10.8f}')

Solution (Python):
import math
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p=[1,2,3,math.inf]
p1=0
p2=0
p3=0
p4=0
 

for i in range(n):
    p1+=(abs(a[i]-b[i]))
print("{:10f}".format(p1))
 

q=0
for i in range(n):
    q+=((abs(a[i]-b[i]))**2)
    p2=math.sqrt(q)
print("{:10f}".format(p2))
 

q=0
for i in range(n):
    q+=((abs(a[i]-b[i]))**3)
    p3=q**(1/3)
print("{:10f}".format(p3))
 

q=0
for i in range(n):
    q=(abs(a[i]-b[i]))
    if q>p4:
        p4=q 
print("{:10f}".format(p4))

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

D1 = 0
d2 = 0
d3 = 0
dm =[]
for i in range(n):
    D1 += abs(x[i]-y[i])
    d2 += (abs(x[i]-y[i]))**2
    d3 += (abs(x[i]-y[i]))**3
    m = abs(x[i]-y[i])
    dm.append(m)
    
D2 = math.sqrt(d2)
D3 = d3 ** (1/3)
Dm = max(dm) 

print(f'{D1:.06f}')
print(f'{D2:.06f}')
print(f'{D3:.06f}')
print(f'{Dm:.06f}')

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



def resolve():
    _ = int(input())
    xv = list(map(float, input().split()))
    yv = list(map(float, input().split()))

    
    

    
    for p in range(1, 4):
        k = sum([abs(x - y) ** p for x, y in zip(xv, yv)]) ** (1 / p)
        print("{0:.6f}".format(k))
    
    print("{0:.6f}".format(max([abs(x - y) for x, y in zip(xv, yv)])))


resolve()

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
D1=[]
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.pow(d2,1/2):.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):
    D1.append(abs(x[i]-y[i]))
print(f'{max(D1):.6f}')

Solution (Python):
p = [1, 2, 3, float("inf")]
sum_p = [0, 0, 0, 0] 
n = int(input())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
for i in range(n):
    
    diff = abs(x[i] - y[i])
    if sum_p[3] < diff:
        sum_p[3] = diff  
    sum_p[0] += diff ** p[0]
    sum_p[1] += diff ** p[1]
    sum_p[2] += diff ** p[2]

for i in range(len(sum_p)):
    if i < 3:
        print("{:.8f}".format(sum_p[i] ** (1/p[i])))
    else:
        print("{:.8f}".format(sum_p[i]))

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

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

D1=0
D2=0
D3=0
Dinf=max(l)

for i in range(n):
  D1+=l[i]
  D2+=l[i]**2
  D3+=l[i]**3
  
D2=D2**(1/2)
D3=D3**(1/3)

print(D1)
print(D2)
print(D3)
print(Dinf)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
work=[abs(x[i]-y[i]) for i in range(n)]

p1=sum(work)
p2=(sum([x**2 for x in work]))**0.5
p3=(sum([x**3 for x in work]))**(1/3)
p_inf=max(work)

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

Solution (Python):
import math

n = int(input())
x_lst = map(int, input().split())
y_lst = map(int, input().split())

xy_lst = list(zip(x_lst, y_lst))

p1 = 0
p2 = 0
p3 = 0
p4 = []
for x, y in xy_lst:
    
    p1 += abs(x - y)
    
    p2 += (abs(x - y)) ** 2
    p3 += (abs(x - y)) ** 3
    
    p4.append(abs(x - y))
print(p1)
print(math.sqrt(p2))
print(math.pow(p3, 1 / 3))
print(max(p4))

Solution (Python):
import math
n = int(input())
x = list(map(float,input().split()))
y = list(map(float,input().split()))
a = 0
b = 0
c = 0
d = [0 for i in range(n)]
for i in range(n):
    a += abs(x[i]-y[i])
    b += abs(x[i]-y[i])**2
    c += abs(x[i]-y[i])**3
    d[i] = abs(x[i]-y[i])
b = math.sqrt(b)
c = c**(1/3)
print('{:.6f}'.format(a))
print('{:.6f}'.format(b))
print('{:.6f}'.format(c))
print('{:.6f}'.format(max(d)))

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
for i in range(1, 4):
    D = 0
    for j in range(n):
        D += abs(X[j] - Y[j])**(i)
    print(D**(1/i))
print(max(abs(X[i] - Y[i]) for i in range(n)))

Solution (Python):
import math
n = int(input())
a = [float(x) for x in list(input().split())]
b = [float(x) for x in list(input().split())]

result = 0
for aa, bb in zip(a, b):
    result += abs(aa - bb)
print(round(result, 6))

result = 0
for aa, bb in zip(a, b):
    result += abs(aa - bb) ** 2
print(round(math.sqrt(result), 8))

result = 0
for aa, bb in zip(a, b):
    result += abs(aa - bb) ** 3
print(round(math.pow(result, 1/3), 8))

result = []
for aa, bb in zip(a, b):
    result.append(abs(aa - bb))
print(max(result))

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

import sys
input=sys.stdin.readline

def main():
    n = int(input())
    x=[]
    y=[]
    x=list(map(int,input().split()))
    y=list(map(int,input().split()))
    ans=0
    ans_list=[]
    for i in range(1,4):
        for x_value,y_value in zip(x,y):
            ans+=abs(x_value-y_value)**i
            ans_list.append(abs(x_value-y_value))
        print("{:.6f}".format(ans**(1/i)))
        ans=0
    print("{:.6f}".format(max(ans_list)))
    
if __name__=="__main__":
    main()

Solution (Python):
import math

n = int(input())
x_buf = input().split()
y_buf = input().split()

x = []
y = []
for i in range(n):
    x.append(int(x_buf[i]))
    y.append(int(y_buf[i]))

sum1 = 0
sum2 = 0
sum3 = 0
sum_inf = 0
max_inf = 0
for i in range(n):
    sum1 += abs(x[i] - y[i])
    sum2 += abs(x[i] - y[i]) ** 2
    sum3 += abs(x[i] - y[i]) ** 3
    sum_inf = abs(x[i] - y[i])
    if max_inf < sum_inf:
        max_inf = sum_inf

d1 = sum1
d2 = math.sqrt(sum2)
d3 = sum3 ** (1/3)
d4 = max_inf

print(d1)
print(d2)
print(d3)
print(d4)

Solution (Python):
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
ab = [math.fabs(x[i]-y[i]) for i in range(n)]
p_1, p_2, p_3 = 0, 0, 0
for i in range(n):
    p_1 += ab[i]
for i in range(n):
    p_2 += ab[i]**2
p_2 = math.sqrt(p_2)
for i in range(n):
    p_3 += ab[i]**3
p_3 = p_3**(1/3)
p_inf = max(ab)
print(p_1)
print(p_2)
print(p_3)
print(p_inf)

Solution (Python):
n = int(input())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
P = []
P_1 = 0
P_2 = 0
P_3 = 0
P_m = 0

for i in range(n):
    if X[i] > Y[i]:
        P.append(X[i]-Y[i])
    else:
        P.append(Y[i]-X[i])

for i in range(n):
    P_1 += P[i]
    P_2 += P[i]**2
    P_3 += P[i]**3
P_2 = P_2**(1/2)
P_3 = P_3**(1/3)
P_m = max(abs(x-y) for x,y in zip(X,Y))

print('{:.6f}'.format(P_1))
print('{:.6f}'.format(P_2))
print('{:.6f}'.format(P_3))
print('{:.6f}'.format(P_m))

Solution (Python):
import math


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

d1 = []
d2 = []
d3 = []
for i, j in zip(x, y):
    d1.append(abs(i - j))
    d2.append(abs(i - j)**2)
    d3.append(abs(i - j)**3)

print(sum(d1))
print(math.sqrt(sum(d2)))
print(sum(d3)**(1/3))
print(max(d1))

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

x_y = []
for x, y in zip(X,Y):
    x_y.append(abs(x-y))

d1 = sum(x_y)
d2 = 0
for xy in x_y:
    d2 += xy ** 2
d2 = d2 ** (1/2)
d3 = 0
for xy in x_y:
    d3 += xy ** 3
d3 = d3 ** (1/3)
d4 = max(x_y)

print(d1)
print(d2)
print(d3)
print(d4)

Solution (Python):
import math

N = int(input())
v1 = [int(i) for i in input().strip().split()]
v2 = [int(i) for i in input().strip().split()]


m1 = 0
for i in range(N):
    m1 += abs(v1[i] - v2[i])

print(float(m1))


m2 = 0
for i in range(N):
    m2 += (v1[i] - v2[i]) ** 2

m2 = math.sqrt(m2)

print(float(m2))


m3 = 0
for i in range(N):
    m3 += abs(v1[i] - v2[i]) ** 3

m3 = m3 ** (1 / 3)

print(float(m3))


m4 = 0
for i in range(N):
    m4 = max(abs(v1[i]-v2[i]), m4)

print(float(m4))

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(int,input().split()))
B=list(map(int,input().split()))

for i in range(1,4):
    cnt=0
    for j in range(n):
        cnt+=abs(A[j]-B[j])**i
    print(cnt**(1/i))
cnt=0
for j in range(n):
    cnt=max(cnt,abs(A[j]-B[j]))
print(cnt)

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

Solution (Python):
import math

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

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

print(sum)

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

print(math.sqrt(sum))

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

print(sum ** (1/3))

check = 0
for i in range(n):
    if check < abs(x[i] - y[i]):
        check = abs(x[i] - y[i])

print(check)

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

a=0
for i in range(n):
    a+=abs(x[i]-y[i])
print('{:.6f}'.format(a))

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

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

d=[]
for i in range(n):
    d.append(abs(x[i]-y[i]))
print('{:.6f}'.format(max(d)))

Solution (Python):
num = int(input())
xs  = [int(n) for n in input().split()]
ys  = [int(n) for n in input().split()]

def calc_distance(xs, ys, p):
    sums = sum([abs(x-y) ** p for x,y in zip(xs, ys)])
    return sums ** (1.0 / p)

for index in range(1,4):
    print(calc_distance(xs, ys, index))

print(max(abs(x-y) for x,y in zip(xs,ys)))

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

d = [0.0 for i in range(3)]
var = 0
for i in range(n):
    temp = abs(x[i]-y[i])
    if var < temp:
        var = temp
    for j in range(3):
        d[j]+=temp**(j+1)

for i in range(3):
    print(d[i]**(1/(i+1)))
print(float(var))

Solution (Python):
n = int(input())
x = [int(n) for n in input().split()]
y = [int(n) for n in input().split()]
for p in range(1, 4):
    print((sum([abs(a-b)**p for a, b in zip(x, y)])**(1/p)))
print(max([abs(a-b) for a,b in zip(x, y)]))

Solution (Python):
import math
if __name__ == '__main__':
    def manh(x, y):
        d = 0
        for i, j in zip(x, y):
            d += abs(int(i)-int(j))
        return d

    def uqurid(x, y):
        d = 0
        for i, j in zip(x, y):
            d += abs(int(i)-int(j))**2
        return math.sqrt(d)

    def minco(x, y):
        p = 3
        d = 0
        for i, j in zip(x, y):
            d += abs(int(i)-int(j))**p
        return d**(1/p)

    def ebis(x, y):
        d = 0
        for i, j in zip(x, y):
            d = max(d, abs(int(i)-int(j)))
        return d

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

    print(manh(x, y))
    print(uqurid(x, y))
    print(minco(x, y))
    print(ebis(x, y))

Solution (Python):
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
e = []
def kome(p):
    c = 0
    for i in range(n):
        c = c + (abs(a[i] - b[i]) ** p)
        e.append(abs(a[i] - b[i]))
    d = c ** (1 / p)
    return d
    
print(kome(1))
print(kome(2))
print(kome(3))
print(float(max(e)))

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):
    if x[i]>y[i]:
        k=x[i]-y[i]
        p1+=k
        p2+=k**2
        p3+=k**3
        p4=max(p4,k)
        
    else:
        k=y[i]-x[i]
        p1+=k
        p2+=k**2
        p3+=k**3
        p4=max(p4,k)

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

print(p1,p2,p3,p4, sep="\n")

Solution (Python):
def main():
    n = int(input())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    for answer in calc(n, x, y):
        print("{:.6f}".format(answer))


def calc(n, x, y):
    ret = []
    patterns = [1, 2, 3]
    for pattern in patterns:
        sum = 0
        for i in range(0, n):
            sum += (abs(x[i] - y[i])) ** pattern
        ret.append(sum ** (1 / pattern))

    last = 0
    for i in range(0, n):
        last = max(last, abs(x[i] - y[i]))
    ret.append(last)

    return ret


if __name__ == "__main__":
    main()

Solution (Python):
import math
N = int(input())
X = list(map(float, input().split()))
Y = list(map(float, input().split()))
S = [abs(x-y) for x,y in zip(X, Y)]
SS = [s**2 for s in S]
SSS = [s**3 for s in S]
print(sum(S))
print(pow(sum(SS), 1/2))
print(pow(sum(SSS), 1/3))
print(max(S))

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

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

c=[abs(x[i]-y[i]) for i in range(n)]
print(f'{max(c):.6f}')

Solution (Python):
import math
n = int(input())
v1 = map(float, input().split())
v2 = map(float, input().split())

v = [abs(x - y) for (x,y) in zip(v1, v2)]

d1 = sum(v)
d2 = math.sqrt(sum([x**2 for x in v]))
d3 = math.pow(sum([x**3 for x in v]), 1.0/3.0)
d4 = max(v)

print(d1)
print(d2)
print(d3)
print(d4)

Solution (Python):
import math



n = int(input())

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

p1 = 0
p2 = 0
p3 = 0
p4 = []
for i in range(n):
    p1 += math.pow(abs(x[i]-y[i]),1)

for i in range(n):
    p2 += math.pow(abs(x[i]-y[i]),2)

for i in range(n):
    p3 += math.pow(abs(x[i]-y[i]),3)
for i in range(n):
    p4.append(abs(x[i]-y[i]))

print(p1)
print(math.sqrt(p2))
print(math.pow((p3),1/3))
print(max(p4))

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
dmax = 0
for i in range(n):
  d1 += abs(x[i] - y[i])
  d2 += abs(x[i] - y[i])**2
  d3 += abs(x[i] - y[i])**3
  if dmax < abs(x[i] - y[i]):
    dmax = abs(x[i] - y[i])
print(d1)
print(math.sqrt(d2))
print(d3**(1.0/3.0))
print(dmax)

Solution (Python):
from math import sqrt

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
p_1 = 0
p_2 = 0
p_3 = 0
p_inf = 0
for i, j in zip(x, y):
    p_1 += abs(i - j)
    p_2 += (i - j) ** 2
    p_3 += abs((i - j)) ** 3
    p_inf = max(p_inf, abs(i - j))

print(p_1)
print(sqrt(p_2))
print(p_3 ** (1 / 3))
print(p_inf)

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

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

d1 = d2 = d3 = d4 = 0
l = []
for a, b in zip(a, b):
    d1 += math.pow(abs(a - b), 1)
    d2 += math.pow(abs(a - b), 2)
    d3 += math.pow(abs(a - b), 3)
    l.append(abs(a-b))

d1 = math.pow(d1, 1)
d2 = math.pow(d2, 1/2)
d3 = math.pow(d3, 1/3)
d4 = max(l)
print(d1)
print(d2)
print(d3)
print(d4)

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


def calc_dist_mink(list_x, list_y, p):
    list_xy = [abs(list_x[i] - list_y[i]) for i in range(len(list_x))]
    list_xy_p = [i ** p for i in list_xy]
    ans = sum(list_xy_p) ** (1 / p)
    return(ans)

list_ans = []
ans_1 = calc_dist_mink(X, Y, 1)
list_ans.append(ans_1)

ans_2 = calc_dist_mink(X, Y, 2)
list_ans.append(ans_2)

ans_3 = calc_dist_mink(X, Y, 3)
list_ans.append(ans_3)

ans_4 = max([abs(X[i] - Y[i]) for i in range(N)])
list_ans.append(ans_4)

for ans in list_ans:
    print(f"{ans:.5f}")

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

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

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

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

d = []
p = float('inf')
for i in range(n):
    d.append(abs(x[i] - y[i]))
print('{:.8f}'.format(max(d)))

Solution (Python):
import math

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

delta = []
for i in range(n):
  dif = abs(x[i]-y[i])
  delta.append(dif)

dp1 = sum(delta)
print(dp1)

dp2 = 0.0
for i in range(n):
  dp2 += delta[i]**2
dp2 = math.sqrt(dp2)
print(dp2)

dp3 = 0.0
for i in range(n):
  dp3 += delta[i]**3
dp3 = math.pow(dp3,1/3)
print(dp3)

dpe = 0.0
for i in range(n):
  dpe = max(dpe,delta[i])
print(dpe)

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 = list(map(int, input().split()))
y_list = list(map(int, input().split()))
list_sa = [abs(x_list[i] - y_list[i]) for i in range(n)]
list_sa2 = [pow(i, 2) for i in list_sa]
list_sa3 = [pow(i, 3) for i in list_sa]
print(sum(list_sa))
print(pow(sum(list_sa2), 1/2))
print(pow(sum(list_sa3), 1/3))
print(max(list_sa))

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])
print('{:.7f}'.format(d1))

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

d3 = 0
for i in range(n):
    d3 += abs(x[i]-y[i])**3
print('{:.7f}'.format(d3**0.3333333333))

di = []
for i in range(n):
    di.append(abs(x[i]-y[i]))
print('{:.7f}'.format(max(di)))

Solution (Python):



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


D=[]
for j in range(n):
    d=abs(X[j]-Y[j])
    D.append(d)
print('{:.05f}'.format(sum(D)))

E=[]
for i in range(n):
    e=D[i]**2
    E.append(e)
A=sum(E)**(1/2)
print('{:.05f}'.format(A))

F=[]
for i in range(n):
    f=D[i]**3
    F.append(f)
B=sum(F)**(1/3)
print('{:.05f}'.format(B))

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

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 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):
def p(t):
    print(f'{t:.6f}')

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

D1=0
D2=0
D3=0
D4=0

for i in range(n):
    d=x[i]-y[i]
    if d<0:
        d=-d
    
    D1+=d
    D2+=d**2
    D3+=d**3
    if d>D4:
        D4=d
        
p(D1)
p(D2**(1/2))
p(D3**(1/3))
p(D4)

Solution (Python):

S = []
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
for i in range(1,4):
    s = 0
    for j in range(n):
        a = abs(x[j] - y[j])
        S.append(a)
        s += a ** i
    D = s ** (1/i)
    print('{:.06f}'.format(D))
print('{:.06f}'.format(max(S)))

Solution (Python):
from math import sqrt, pow
from operator import sub


def sub_(t):
    return abs(sub(*t))


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

print(sum(map(sub_, zip(x, y))))
print(sqrt(sum(map(lambda t: sub_(t) ** 2, zip(x, y)))))
print(pow(sum(map(lambda t: sub_(t) ** 3, zip(x, y))), 1/3))
print(max(map(sub_, 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):



import math

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


print(sum([abs(i-j) for i, j in zip(x, y)]))

print(math.sqrt(sum([(i-j)**2 for i, j in zip(x, y)])))

print((sum([abs(i-j)**3 for i, j in zip(x, y)]))**(1.0/3.0))



print(max([abs(i-j) for i, j in zip(x, y)]))

Solution (Python):

from sys import stdin
import math

n = int(stdin.readline().rstrip())
lx = list(map(int, stdin.readline().split()))
ly = list(map(int, stdin.readline().split()))

s1=s2=s3=max_x_y = 0
for i in range(n):
    x_y = abs(lx[i] - ly[i])
    
    s1+=x_y
    
    s2 += math.pow(x_y,2)
    
    s3 += math.pow(x_y, 3)
    
    if max_x_y < x_y:
        max_x_y = x_y
else:
    
    print("{0:.8f}".format(s1))
    
    d2 = math.sqrt(s2)
    print("{0:.8f}".format(d2))
    
    d3 = math.pow(s3, 1.0 / 3.0)
    print("{0:.8f}".format(d3))
    
    print(max_x_y)

Solution (Python):

n = int(input())
x = list(map(float,input().split()))
y = list(map(float,input().split()))
xy = [0 for i in range(n)]; xy2 = [0 for i in range(n)]; xy3 = [0 for i in range(n)]

for  i in range(n):
    xy[i] = x[i]-y[i]
    if xy[i]<0:
        xy[i] *= -1
    xy2[i] = xy[i]**2
    xy3[i] = xy[i]**3
    
print("{0:.6f}\n{1:.6f}\n{2:.6f}\n{3:.6f}".format(sum(xy),(sum(xy2)**(1/2)),(sum(xy3)**(1/3)),max(xy)))

Solution (Python):
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 += (abs(X[i]-Y[i]))**2
p2 = p2 ** 0.5

p3 = 0
for i in range(n):
    p3 += (abs(X[i]-Y[i]))**3
p3 = p3 ** (1/3)


p4 = 0
for i in range(n):
    if p4 < abs(X[i]-Y[i]):
        p4 = abs(X[i]-Y[i])
    
print(p1)
print(p2)
print(p3)
print(p4)

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

z = 0
for i in range(len(x)):
    z += abs(x[i]-y[i])
print(z)

z = 0
for i in range(len(x)):
    z += (abs(x[i]-y[i]))**2
print(z**0.5)

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

z1 = 0
z2 = 0
for i in range(len(x)):
    z1 = abs(x[i]-y[i])
    if z1 > z2:
        z2 = z1
print(z2)

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

for j in range(1,4):
    D=0
    for i in range(n):
        D+=(abs(a[i]-b[i]))**j
    D**=1/j
    print('{:.6f}'.format(D))
lst=[]
for k in range(n):
    lst.append(abs(a[k]-b[k]))
print('{:.6f}'.format(max(lst)))

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

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

ans1 = 0
ans2 = 0
ans3 = 0
ansx = []

for x in range(n):
    ans1 += abs(X[x]-Y[x])
    ans2 += abs(X[x]-Y[x])**2
    ans3 += abs(X[x]-Y[x])**3
    ansx.append(abs(X[x]-Y[x]))
print(ans1,ans2**0.5,ans3**(1.0/3),max(ansx), sep = "\n")

Solution (Python):
import math
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
L1,L2,L3 = 0.0,0.0,0.0
L = []
for i in range(n):
    L1 += abs(x[i]-y[i])
    L2 += (x[i]-y[i])**2
    L3 += abs(x[i]-y[i])**3
    L .append(abs(x[i]-y[i]))
print(L1)
print(math.sqrt(L2))
print(math.pow(L3, 1.0/3.0))    
print(max(L))

Solution (Python):
import sys
import math

input = sys.stdin.readline

def main():
    n = int(input().rstrip())
    x = list(map(int, input().rstrip().split()))
    y = list(map(int, input().rstrip().split()))
    
    d1, d2, d3 = 0, 0, 0
    temp_y = y
    
    for i in range(n):
        d1 += math.fabs(x[i] - y[i])
        d2 += math.fabs(x[i] - y[i]) ** 2
        d3 += math.fabs(x[i] - y[i]) ** 3
        temp_y[i] = math.fabs(x[i] - y[i])
    
    print(d1)
    print(math.sqrt(d2))
    print(d3**(1/3))
    print(max(temp_y))
    
if __name__ == "__main__":
    main()

Solution (Python):
import math

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

sum1 = 0
sum2 = 0
sum3 = 0
inf = 0
for i in range(n):
    tmp = abs(x[i] - y[i])
    sum1 += tmp
    sum2 += tmp ** 2
    sum3 += tmp ** 3
    inf = max(inf, tmp)
print("{:.6f}".format(sum1))
print("{:.6f}".format(sum2 ** (1 / 2)))
print("{:.6f}".format(sum3 ** (1 / 3)))
print("{:.6f}".format(inf))

Solution (Python):
import math

def lp_norm(x,y,p):
    if p==float("inf"):
        z=[]
        for i in range(len(x)):
            z.append(abs(x[i]-y[i]))
        return max(z)
        
    else:
        z=[]
        for i in range(len(x)):
            z.append(math.pow(abs(x[i]-y[i]),p))
            
        s=sum(z)
            
        return math.pow(s,1.0/p)
        

def run():
    
    n=input()
    x=list(map(float,input().split()))
    y=list(map(float,input().split()))
    
    p=float("inf")
    print(f"{lp_norm(x,y,1.0)}")
    print(f"{lp_norm(x,y,2.0)}")
    print(f"{lp_norm(x,y,3.0)}")
    print(f"{lp_norm(x,y,p)}")
        
run()

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

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

din = [0,0,0,0]

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

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

p1 = 0
p2 = 0
p3 = 0
p8 = []

for idx in range(n):
    s = abs(xx[idx]-yy[idx])
    p1 += s
    p2 += s**2
    p3 += s**3
    p8.append(s)

print(p1)
print(p2**(1/2))
print(p3**(1/3))
print(max(p8))

Solution (Python):


num=int(input())
b1=[int(x) for x in input().split(' ')]
b2=[int(x) for x in input().split(' ')]



def c_minchov(x,y,p):
	b1,b2=x,y
	fsum=0
	for i in range(len(b1)):
		fsum+=abs(b1[i]-b2[i])**p
	res=fsum**(1/p)
	return res

def c_chebichev(x,y):
	b1,b2=x,y
	dis=[abs(b1[i]- b2[i]) for i in range(len(b1))]

	res= max(dis)
	return res


p1=c_minchov(b1,b2,1)
p2=c_minchov(b1,b2,2)
p3=c_minchov(b1,b2,3)
p4=c_chebichev(b1,b2)
print("{:.6f}".format(p1))
print("{:.6f}".format(p2))
print("{:.6f}".format(p3))
print("{:.6f}".format(p4))

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


d1 = 0
r = []
for i in range(n):
    d = abs(x[i] - y[i])
    d1 += d
    r.append(d)


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


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


d_inf = max(r)

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

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):
import math
def minkowskiDistance(p, x, y):
    distance, sum = 0, 0
    for i, j in zip(x, y):
        sum += math.fabs(i- j) ** p
    distance = math.pow(sum, 1 / p)
    return distance
def chebyshevDistance(x, y):
    distance = []
    for i, j in zip(x, y):
        distance.append(math.fabs(i - j))
    return max(distance)

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

print(minkowskiDistance(1, x, y))
print(minkowskiDistance(2, x, y))
print(minkowskiDistance(3, x, y))
print((chebyshevDistance(x, y)))

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

def D(x,y,p):
    s = 0
    for i in range(n):
        s += abs(x[i]-y[i])**p
    return s**(1/p)
mugen = []
for k in range(n):
    mugen.append(abs(x[k]-y[k]))

l = [1,2,3]
a = []
for j in l :
    a.append(D(x,y,j))
a.append(max(mugen))
print(*a)