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 = [];y = []
x = list(map(int,input().split()))
y = list(map(int,input().split()))
d1 = 0
d2 = 0
d3 = 0
dx = -1e9
for i in range(n):
    d1 += abs(x[i]-y[i])
    d2 += (x[i]-y[i])**2
    d3 += (abs(x[i]-y[i]))**3
    dx = max(dx,abs(x[i]-y[i]))

d1 = d1**1
d2 = d2**0.5
d3 = d3**(1/3)
dx = dx
print("%.5f"%d1)
print("%.5f"%d2)
print("%.5f"%d3)
print("%.5f"%dx)

Solution (Python):
import math

n = int(input())

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

d1 = [0 for i in range(n)]
d2 = [0 for i in range(n)]
d3 = [0 for i in range(n)]

for i in range(n):
    d1[i] = abs(a[i] - b[i])
    d2[i] = abs(a[i] - b[i])**2
    d3[i] = abs(a[i] - b[i])**3

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

Solution (Python):
import math
def souhei(n):
	for w in range(n):
		a=list(map(int,input().split()))
		return(a)
n=int(input())
A=souhei(n)
B=souhei(n)
P=[]
for mm in range(1,5):
	del P[:]
	P=[]
	if mm==4:
		for m in range(n):
			P.append(abs(A[m]-B[m]))
			p=max(P)
	else:
		for m in range(n):
			o=(abs(A[m]-B[m]))**mm
			P.append(o)
		p=sum(P)
		p=(p**(1/mm))
	print('{:.5f}'.format(p))

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


D1 = 0
for x, y in zip(X, Y):
  D1 += abs(x-y)
print(D1)


D2 = 0
for x, y in zip(X, Y):
  D2 += (abs(x-y))**2
print(D2**(1/2))


D3 = 0
for x, y in zip(X, Y):
  D3 += (abs(x-y))**3
print(D3**(1/3))  


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

Solution (Python):
n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
d1 = 0  
d2 = 0  
d3 = 0  
dx = 0  

for i in range(n):
    t = x[i] - y[i]
    if t < 0:  
        t *= -1
    d1 += t
    d2 += t ** 2
    d3 += t ** 3
    if dx < t:
        dx = t
d2 = d2 ** (1.0 / 2.0)
d3 = d3 ** (1.0 / 3.0)
print(d1)
print(d2)
print(d3)
print(dx)

Solution (Python):
n = int(input())
X = list(map(float,input().split()))
Y = list(map(float,input().split()))
D = [abs(X[i]-Y[i]) for i in range(len(X))]
print(sum(D))
print((sum([ele**2 for ele in D]))**(1/2))
print((sum([ele**3 for ele in D]))**(1/3))
print(max(D))

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

for p in range(1,4):
    print("{0:.6f}".format(sum([abs(a-b)**p for a,b in zip(X,Y)])**(1/p)))

print("{0:.6f}".format(max([abs(a-b) for a,b in zip(X,Y)])))

Solution (Python):
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 = 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):
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 = 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()))
distance=[0 for _ in range(N)]
for i in range(N):
    distance[i]=abs(x[i]-y[i])
for i in range(1,5):
    P=0
    for j in range(N):
        P+=distance[j]**i
    if i<4:
        print(P**(1/i))
    else:
        print(max(distance))

Solution (Python):

import math

if __name__ == '__main__':

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

    
	d1 = 0
	for x1,y1 in zip(X,Y):
		d1 += abs(x1-y1)

	print('{:.6f}'.format(d1))

    
	d2_tmp = 0
	for x2,y2 in zip(X,Y):
		d2_tmp += abs(x2-y2)**2
	d2 = math.sqrt(d2_tmp)
	print('{:.6f}'.format(d2))

	
	d3_tmp = 0
	for x3,y3 in zip(X,Y):
		d3_tmp += abs(x3-y3)**3
	d3 = d3_tmp ** (1/3)
	print('{:.6f}'.format(d3))

	
	d8 = -1
	for x8,y8 in zip(X,Y):
		d8 = max(d8,abs(x8-y8))

	print('{:.6f}'.format(d8))

Solution (Python):
import math
def dist(p, x, y):
    s = 0
    for i, j in zip(x, y):
        s += abs(i - j) ** p
    return s ** (1 / p)

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
print(dist(1, x, y))
print(dist(2, x, y))
print(dist(3, x, y))
print(max(abs(i-j) for i, j in zip(x, y)))

Solution (Python):
def distance_p(x_values: list, y_values: list, p: int) -> float:
    return sum(map(lambda x, y: abs(x - y) ** p, x_values, y_values)) ** (1 / p)


def distance_chebyshev(x_values: list, y_values: list) -> float:
    return max(map(lambda x, y: abs(x - y), x_values, y_values))


if __name__ == "__main__":
    elem_num = int(input())
    x_values = list(map(lambda x: float(x), input().split()))
    y_values = list(map(lambda x: float(x), input().split()))
    print(f"{distance_p(x_values, y_values, 1)}")
    print(f"{distance_p(x_values, y_values, 2)}")
    print(f"{distance_p(x_values, y_values, 3)}")
    print(f"{distance_chebyshev(x_values, y_values)}")

Solution (Python):






import sys
import math


class mymath:
    
    pi = 3.14159265358979323846264338

    
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()


class output:
    
    def list(self, l):
        l = list(l)
        
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()






















def get_input():
    N = []
    while True:
        try:
            N.append(input())
        except EOFError:
            break
    return N

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

for i in range(1,4):
    P = 0
    for j in range(N):
        P += (math.fabs(X[j]-Y[j]))**i
    P = P**(1/i)
    print(P)

P4 = []
for i in range(N):
    P4.append(math.fabs(X[i]-Y[i]))
print(max(P4))

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

Solution (Python):
n = int(input())
x, y = [list(map(int, input().split())) for _ in range(2)]

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

Solution (Python):
import sys

n = int(sys.stdin.readline())
x = list(map(int, sys.stdin.readline().split()))
y = list(map(int, sys.stdin.readline().split()))
absxy = [abs(x[i]-y[i]) for i in range(n)]

for dim in range(1,4):
    total = sum( (absxy[i]**dim for i in range(n)) )
    print(round(total**(1/dim), 6))
    
print(float(max(absxy)))

Solution (Python):
from math import pow


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

d1 = d2 = d3 = dm = 0
for i in range(n):
    diff = abs(x[i] - y[i])
    d1 += diff
    d2 += diff ** 2
    d3 += diff ** 3
    dm = diff if dm < diff else dm

print("{:.5f}\n{:.5f}\n{:.5f}\n{:.5f}".format(d1, pow(d2, 1 / 2), pow(d3, 1 / 3), dm))

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):
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
p1,p2,p3=0,0,0
Dxy=[0]*(n+1)
for i in range(n):
    Dxy[i]=abs(x[i]-y[i])
    p1+=Dxy[i]
    p2+=Dxy[i]**2
    p3+=Dxy[i]**3
p2**=0.5
p3**=(1/3)
print(p1,p2,p3,max(Dxy),sep='\n')

Solution (Python):
import math



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

d1=0
d2=0
d3=0
dd=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 	dd < abs(x[i]-y[i]):
		dd=abs(x[i]-y[i])

print(d1)
print(d2**0.5)
print(d3**(1/3))
print(dd)

Solution (Python):
n = int(input())
x = list(map(float,input().split()))
y = list(map(float,input().split()))
D = []
p1 = 0
p2 = 0
p3 = 0
pi = 0
pimax = 0

for i in range(n):
    p1 = p1 + abs(x[i]-y[i])
    p2 = p2 + pow(abs(x[i]-y[i]),2)
    p3 = p3 + pow(abs(x[i]-y[i]),3)
    pi = abs(x[i] - y[i])
    if pimax < pi:
        pimax = pi
D.append(p1)
D.append(pow(p2,1/2))
D.append(pow(p3,1/3))
D.append(pimax)

for i in D:
    print(i)

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

d = lambda a, b, n: sum([abs(x - y) ** n for x, y in zip(a, b)]) ** (1/n)
print(d(a, b, 1))
print(d(a, b, 2))
print(d(a, b, 3))
print(max([abs(x - y) for x, y in zip(a, b)]))

Solution (Python):
import math
n = input()
x = list(map(int, input().split()))
y = list(map(int, input().split()))
d1=0
d2=0
d3=0
d_inf=0
for i in range(len(x)):
    d1 += abs(x[i]-y[i])
    d2 += ((x[i]-y[i])**2)
    d3 += abs((x[i]-y[i])**3)
    if abs(x[i]-y[i]) >= d_inf:
        d_inf = abs(x[i]-y[i])
print(d1)
print(math.sqrt(d2))
print(d3**(1/3.0))
print(d_inf)

Solution (Python):
import math
n = int(input())
li1 = [int(i) for i in input().split()]
li2 = [int(i) for i in input().split()]
D1 = 0
D2 = 0
d2 = 0
D3 = 0
d3 = 0
D8 = 0
li = []
for i in range(n):
    D1 += abs(li1[i]-li2[i])
    d2 += (li1[i]-li2[i])**2
    D2 = math.sqrt(d2)
    d3 += (abs(li1[i]-li2[i]))**3
    D3 = d3**(1/3)
    li.append(abs(li1[i]-li2[i]))
    D8 = max(li)
print(D1)
print(D2)
print(D3)
print(D8)

Solution (Python):
import math
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(sum((abs(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()))
s1=0
s2=0
s3=0
s4=[]
for i in range(n):
  s1 += abs(X[i]-Y[i])
  s2 += (abs(X[i]-Y[i])**2)
  s3 += (abs(X[i]-Y[i])**3)
  s4.append(abs(X[i]-Y[i]))

s4max = max(s4)
  
print('{:.6f}'.format(s1))
print('{:.6f}'.format(math.sqrt(s2)))
print('{:.6f}'.format(math.pow(s3,1/3)))
print('{:.6f}'.format(s4max))

Solution (Python):
import math

n=int(input())
X=input().split()
Y=input().split()
x=[0 for i in range(n)]
y=[0 for i in range(n)]
for i in range(n):
    x[i]=int(X[i])
for i in range(n):
    y[i]=int(Y[i])
sum_1=0
for i in range(n):
    sum_1=sum_1+abs(x[i]-y[i])
D_1=sum_1

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

sum_3=0
for i in range(n):
    sum_3=sum_3+abs(x[i]-y[i])**3
D_3=sum_3**(1/3)
Abs=[abs(x[i]-y[i]) for i in range(n)]
max=max(Abs)
print(f"{D_1} {D_2} {D_3} {max}")

Solution (Python):
import math
n=int(input())
x=list(map(float,input().split()))
y=list(map(float,input().split()))
M=0
Y=0
T=0
Cn=[]

for i in range(n):
  z=abs(x[i]-y[i])
  M+=z
  Y+=z**2
  T+=z**3
  Cn.append(z)
  
Y=math.sqrt(Y)
T=T**(1/3)
C=max(Cn)

print(f"{M:.6f}")
print(f"{Y:.6f}")
print(f"{T:.6f}")
print(f"{C:.6f}")

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

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

p1 = sum(math.fabs(a[i]-b[i]) for i in range(n))
p2 = math.sqrt(sum([math.fabs(a[i]-b[i])**2 for i in range(n)]))
p3 = math.pow(sum([math.fabs(a[i]-b[i])**3 for i in range(n)]), 1/3)
pp = max([math.fabs(a[i]-b[i]) for i in range(n)])

print('{0:6f}'.format(p1))
print('{0:6f}'.format(p2))
print('{0:6f}'.format(p3))
print('{0:6f}'.format(pp))

Solution (Python):
import decimal
from operator import sub



n = int(input())

vector_x = list(map(decimal.Decimal, input().split()))
vector_y = list(map(decimal.Decimal, input().split()))



d1 = decimal.Decimal("0")
d2 = decimal.Decimal("0")
d3 = decimal.Decimal("0")

for i in range(n):
    d1 += abs(vector_x[i] - vector_y[i])

    d2 += abs(vector_x[i] - vector_y[i]) ** decimal.Decimal("2")

    d3 += abs(vector_x[i] - vector_y[i]) ** decimal.Decimal("3")


d2 = pow(d2, decimal.Decimal("1") / decimal.Decimal("2"))
d3 = pow(d3, decimal.Decimal("1") / decimal.Decimal("3"))



vector_sub = map(abs, map(sub, vector_x, vector_y))
dinf = max(vector_sub)



for answer in [d1, d2, d3, dinf]:
    print(answer)

Solution (Python):
def get_minkowski_distance(a, b, p):
    """
    get Minkowski's distance
    a : int list
    b : int list
    p : int
    """
    s = 0
    res = 0.0

    if p == 0:
        l = []
        for x, y in zip(a, b):
            l.append(abs(x - y))
        res = max(l) 

    else:
        for x, y in zip(a, b):
            s += abs(x - y) ** p

        res = round((s ** (1/p)), 6)

    return res

if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    print(get_minkowski_distance(a, b, 1))
    print(get_minkowski_distance(a, b, 2))
    print(get_minkowski_distance(a, b, 3))
    print(get_minkowski_distance(a, b, 0))

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

Solution (Python):


import math

def dist1(data1, data2):
    leng = 0
    for a, b in zip(data1, data2):
        leng += abs(a-b)

    return leng

def dist2(data1, data2):
    leng = 0
    for a,b in zip(data1, data2):
        leng += abs(a-b)**2.0
    
    return (math.sqrt(leng))

def distn(data1, data2, n):
    leng = 0
    for a,b in zip(data1, data2):
        leng += abs(a-b) ** n

    return (pow(leng, 1/n))

def distlm(data1, data2):
    leng = 0
    for a,b in zip(data1, data2):
        ab = abs(a-b)
        leng = leng if leng > ab else ab
    return leng

leng = input()
datax =list(map(float, input().split()))
datay =list(map(float, input().split()))

print ( distn(datax, datay, 1))
print ( distn(datax, datay, 2))
print ( distn(datax, datay, 3))
print ( distlm(datax, datay))

Solution (Python):


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


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


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


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


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

Solution (Python):
import math
data_dim = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
D_1=0
D_2=0
D_3=0
D_inf=0

for i in range(data_dim):
    D_1 += abs(x[i]-y[i])
    D_2 += abs(x[i]-y[i])**2
    D_3 += abs(x[i]-y[i])**3
    D_inf = max(D_inf,abs(x[i]-y[i]))

print("%f"%(D_1))
print("%f"%(math.sqrt(D_2)))
print("%f"%(math.pow(D_3,1/3)))
print("%f"%(D_inf))

Solution (Python):


import math

def minkowski (x_list, y_list, p):
    """ ミンコフスキー距離 """
    
    
    if p != math.inf:
        a = 0
        for x, y in zip(x_list, y_list):
            a += abs(x - y)** p
        return float(math.pow(a, 1 / p))
    
    
    else:
        d = 0
        for x, y in zip(x_list, y_list):
            if d < abs(x - y):
                d = abs(x - y)
        return float(d)

def main():
    n = int(input())
    x_list = list(map(int, input().split()))
    y_list = list(map(int, input().split()))
    p_list = [1, 2, 3, math.inf]
    
    for p in p_list:
        print(f"{minkowski(x_list, y_list, p):.6f}")

if __name__ == "__main__":
    main()

Solution (Python):
import math
n = int(input())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
table = []
three = 0

Manhattan = 0
Euclid = 0
Chebyshev = 0
for i in range(n):
    Manhattan += abs(X[i] - Y[i])
for i in range(n):
    tmp = abs(X[i] - Y[i])
    Euclid += tmp**2

Euclid_r = math.sqrt(Euclid)
for i in range(n):
    table.append(abs(X[i] - Y[i]))

Chebyshev = max(table)

for i in range(n):
    three += abs(X[i] - Y[i])**3

three_r = math.pow(three,1/3)

print(Manhattan)
print(Euclid_r)
print(three_r)
print(Chebyshev)

Solution (Python):
def minkowski_dist(vx, vy, p):
    if p == float("inf"):
        return max([abs(x - y) for x, y in zip(vx, vy)])
    else:
        return sum([abs(x - y)**p for x, y in zip(vx, vy)])**(1 / p)


n = int(input())
vx = [int(c) for c in input().split()]
vy = [int(c) for c in input().split()]
for p in [1, 2, 3, float("inf")]:
    print("%.6f" % minkowski_dist(vx, vy, p))

Solution (Python):
import math
dimension = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for i in range(3):
    d_xy = 0
    b = 0
    for j in range(dimension):
        a = math.fabs(x[j]-y[j]) ** (i+1)
        b += a
    d_xy = b ** (1/(i+1))
    print(d_xy)
distance = []
for k in range(dimension):
    distance.append(math.fabs(x[k]-y[k]))
print(max(distance))

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):
if __name__ == '__main__':
	n = int(input())
	x = [float(s) for s in input().split()]
	y = [float(s) for s in input().split()]

	
	tmp = 0
	for i in range(n):
		tmp += abs(x[i]-y[i])
	print("%.10f" % (tmp))
	
	
	tmp = 0
	for i in range(n):
		tmp += (abs(x[i]-y[i]))**2
	print("%.10f" % (tmp**0.5))

	
	tmp = 0
	for i in range(n):
		tmp += (abs(x[i]-y[i]))**3
	print("%0.10f" % (tmp**(1/3)))

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

Solution (Python):
import math

n = int(input())
x = list(int(x) for x in input().split())
y = list(int(x) for x in input().split())

d = []
d2 = []
d3 = []
for i in range(n):
  d.append(abs(x[i] - y[i]))
  d2.append(abs(x[i] - y[i]) ** 2)
  d3.append(abs(x[i] - y[i]) ** 3)
  
print(sum(d))
print(sum(d2) ** (1/2))
print(sum(d3) ** (1/3))
print(max(d))

Solution (Python):
def Minkowski(x,y,n,p):
    s = 0
    for i in range(n):
        s += abs(x[i] - y[i])**p
    
    D = s**(1/p)
    print("{:.9}".format(D))
    
    return D

def Minkowski_inf(x,y,n):
    ma = 0

    for i in range(n):
        m = abs(x[i]-y[i])
        if(ma < m):
            ma = m
    
    D = ma
    print("{}".format(D))

    return D


n = int(input())

    
x = [int(i) for i in input().split(" ")]
y = [int(i) for i in input().split(" ")]
    
Minkowski(x,y,n,1)
Minkowski(x,y,n,2)
Minkowski(x,y,n,3)
Minkowski_inf(x,y,n)

Solution (Python):
import math

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for num in range(1, 4):
    z = []
    for X, Y in zip(x, y):
        z.append(abs((X - Y))**num)
    print((sum(z))**(1 / num))
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()))
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):
input()
x = list(map(float, input().split()))
y = list(map(float, input().split()))
manhattan = 0
euclidian = 0
minkowski3 = 0
chebyshev = 0
for i in range(len(x)):
    manhattan += abs(x[i]-y[i])
    euclidian += (x[i]-y[i])**2
    minkowski3 += abs(x[i]-y[i])**3
    chebyshev = max(chebyshev, abs(x[i]-y[i]))
euclidian = euclidian ** 0.5
minkowski3 = minkowski3 ** (1/3)
print(manhattan, euclidian, minkowski3, chebyshev, sep=('\n'))

Solution (Python):
input()
v = lambda: map(int,input().split())
d = [abs(x-y) for x,y in zip(v(),v())]
print(
	sum(d),
	sum(a**2 for a in d)**(1/2),
	sum(a**3 for a in d)**(1/3),
	max(d),
	sep='\n')

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

Solution (Python):
import math

n = int(input())

x = input().split()

y = input().split()

Manhattan = 0.0

Euclidean = 0.0

Chebyshev = 0.0

Minkowski = 0.0

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

  Euclidean += math.pow((int(x[i])- int(y[i])), 2.0)

  Chebyshev += math.pow(abs(int(x[i])- int(y[i])), 3.0)

  if Minkowski < abs((int(x[i])- int(y[i]))): Minkowski = abs(int(x[i])-int(y[i])) 

Euclidean = math.sqrt(Euclidean)
Chebyshev = Chebyshev**(1/3)
  
print("%.8f"%Manhattan)
print("%.8f"%Euclidean)
print("%.8f"%Chebyshev)
print("%.8f"%Minkowski)

Solution (Python):
import math

n = int(input())

a = 0
b = 0
c = 0
d = 0
max = -9999999999

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

for i in range(n):
    if x[i] - y[i] < 0:
        a += y[i] - x[i]
    else:
        a += x[i] - y[i]

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

c = math.sqrt(b)

for i in range(n):
    if x[i] - y[i] > 0:
        d += (x[i] - y[i]) ** 3
    else:
        d += (y[i] - x[i]) ** 3

e = d ** (1 / 3)

for i in range(n):
    if x[i] - y[i] < 0:
        if y[i] - x[i] > max:
            max = y[i] - x[i]
    else:
        if x[i] - y[i] > max:
            max = x[i] - y[i]

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

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

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

m_d = 0
y_d = 0
u_d = 0

mmm = [0]*n
md = 0
for i in range(n):
    
    md = abs(x[i]-y[i])
    m_d += md
    y_d += md**2
    u_d += md**3
    mmm[i] = md



print(m_d)
print(y_d**0.5)
print(u_d**(1/3))
print(max(mmm))

Solution (Python):
n = int(input())
x_l = list(map(int, input().split()))
y_l = list(map(int, input().split()))
p1 = sum(abs(x_l[i]-y_l[i]) for i in range(n))
p2 = (sum(abs(x_l[i]-y_l[i])**2 for i in range(n)))**0.5
p3 = (sum(abs(x_l[i]-y_l[i])**3 for i in range(n)))**(1/3)
p_max = max(abs(x_l[i]-y_l[i]) for i in range(n))
print(p1, p2, p3, p_max)

Solution (Python):
import math

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("%.6f"%(Dxy))

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

n = int(input())


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


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



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


Dxy = 0
s1 = 0
for i in range(n):
    s1 += (x[i]-y[i])**2
Dxy = s1**(1/2)
print(Dxy)


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


Dxy = 0
s1 = 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_datas = list(map(int, input().split()))
y_datas = list(map(int, input().split()))
length = len(x_datas)



D1 = 0
for i in range(length):
    D1 += math.fabs(x_datas[i] - y_datas[i])
print(D1)



D2_sum = 0
for i in range(length):
    D2_sum += math.fabs(x_datas[i] - y_datas[i]) ** 2
    D2 = math.sqrt(D2_sum)
print(D2)


D3_sum = 0
for i in range(length):
    D3_sum += math.fabs(x_datas[i] - y_datas[i]) ** 3
    D3 = pow(D3_sum, 1/3)
print(D3)



D4 = []
for i in range(length):
    D4.append(math.fabs(x_datas[i] - y_datas[i]))
print(max(D4))

Solution (Python):
import math

def dist(x,y,N,M):
    sum = 0
    for n in range(N):
        sum += abs(x[n]-y[n])**M
    sum = sum**(1/M)
    
    return sum
    
def dist_inf(x,y,N):
    return max([abs(x[n]-y[n]) for n in range(N)])


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

print(dist(x,y,N,1))
print(dist(x,y,N,2))
print(dist(x,y,N,3))
print(dist_inf(x,y,N))

Solution (Python):
import math

N=int(input())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
    
for j in range(1,4):
    sum=0
    for i in range(N):
        sum+=(abs(X[i]-Y[i]))**j
    D=math.pow(sum,1/j)
    print(D)
    
dist=0
for i in range(N):
    kyori=abs(X[i]-Y[i])
    if dist<=kyori:
        dist=float(kyori)
print(dist)

Solution (Python):
n = input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(1, 5):
    if i==4: print(max(list(map(lambda x,y: abs(x-y), a, b))))
    else: print(sum(list(map(lambda x,y: abs(x-y)**i, a, b)))**(1/i))

Solution (Python):
import math


n = int(input())

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


x_y_1 = [abs(x[i] - y[i]) for i in range(n)]
D_1 = sum(x_y_1)
print(float(D_1))

x_y_2 = [abs(x[i] - y[i])**2 for i in range(n)]
D = sum(x_y_2)
D_2 = pow(D, 1/2)
print(D_2)


x_y_3 = [abs(x[i] - y[i])**3 for i in range(n)]
D = sum(x_y_3)
D_3 = pow(D, 1/3)
print(D_3)


D_inf = max(x_y_1)
print(float(D_inf))

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
for i in range(1,4):
    a = 0
    for j in range(n):
        if x[j] - y[j] < 0:
            a += (y[j] - x[j]) ** i
        else:
            a += (x[j] - y[j]) ** i
    a = a ** (1/i)
    print(a)
b = 0
for k in range(n):
    c = x[k] - y[k]
    if c < 0:
        c = c * -1
    if b < c:
        b = c
print(b)

Solution (Python):
import math
num = int(input())
x = [int(_) for _ in input().split()]
y = [int(_) for _ in input().split()]
p1 = p2 = p3 = pe = max_num= 0
for i in range(num):
    p1 += abs(x[i]-y[i])
    p2 += math.pow(abs(x[i]-y[i]),2)
    p3 += math.pow(abs(x[i]-y[i]),3)
    if max_num < abs(x[i]-y[i]):
        max_num = abs(x[i] - y[i])
else:
    p2 = math.sqrt(p2)
    p3 = math.pow(p3,1/3)
    pe = max_num
print("%f\n%f\n%f\n%f" %(p1,p2, p3,pe))

Solution (Python):
from math import sqrt

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

def f1(x, y):
    return sum([abs(t[0] - t[1]) for t in zip(x, y)])
    
def f2(x, y):
    return sqrt(sum([pow(t[0] - t[1], 2) for t in zip(x, y)]))

def f3(x, y):
    return pow(sum([ pow(abs(t[0] - t[1]), 3) for t in zip(x, y)]), 1.0 / 3.0)
    
def f4(x, f):
    return max([abs(t[0] - t[1]) for t in zip(x, y)])
    
print(f1(x, y))
print(f2(x, y))
print(f3(x, y))
print(f4(x, y))

Solution (Python):
from math import sqrt

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

def f1(x, y):
    return sum([ abs(t[0] - t[1]) for t in zip(x, y) ])

def f2(x, y):
    return sqrt(sum([ pow(t[0] - t[1], 2) for t in zip(x, y) ]))

def f3(x, y):
    return pow(sum([ pow(abs(t[0] - t[1]), 3) for t in zip(x, y) ]), 1.0 / 3.0)

def f4(x, y):
    return max([abs(t[0] - t[1]) for t in zip(x, y)])

print(f1(x, y))
print(f2(x, y))
print(f3(x, y))
print(f4(x, y))

Solution (Python):
import math

n = int(input())

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

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

d1 = float(sum(dist))
d2 = 0.0
d3 = 0.0
for i in range(n):
  d2 += dist[i]**2
  d3 += dist[i]**3
d2 = float(math.sqrt(d2))
d3 = float(d3**(1.0/3.0))
d_inf = float(max(dist))

print("{:.6f}".format(d1))
print("{:.6f}".format(d2))
print("{:.6f}".format(d3))
print("{:.6f}".format(d_inf))

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