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

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

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

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

Solution (Python):
def distance(x, y, p):
    length = len(x)
    if p == -1:
        return max(abs(x[i] - y[i]) for i in range(length))
    return sum([abs(i - j)**p for i, j in zip(x, y)])**(1/p)

n = int(input())
x = [*map(int, input().split())]
y = [*map(int, input().split())]
P = (1, 2, 3, -1)
for p in P:
    print('%f' % distance(x, y, p))

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

def Dp(x,y,n,p):
    i = 0
    ans = 0
    for i in range(n):
        ans += (math.fabs(x[i]-y[i]))**p
        i+=1
    return ans**(1/p)

def Dp_inf(x,y,n):
    i = 0
    ans = 0
    for i in range(n):
        if ans < math.fabs(x[i]-y[i]):
            ans = math.fabs(x[i]-y[i])
    return ans

for j in range(3):
    print(Dp(x,y,n,j+1))

print(Dp_inf(x,y,n))

Solution (Python):
import math

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

for i in range(n):
  distance[0] += math.fabs(x[i] - y[i])
  distance[1] += (x[i] - y[i])**2
  distance[2] += math.fabs((x[i] - y[i])**3)
  distance[3] = max(distance[3],math.fabs(x[i] - y[i]))

distance[1] = math.sqrt(distance[1])
distance[2] = distance[2]**(1/3)

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

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, 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**0.5)


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


ma = 0
for i in range(n):
    tmp = abs(x[i]-y[i])
    if tmp > ma: ma = tmp
print(ma)

Solution (Python):


def minkowski(x_list, y_list, p):
    tmp_ans = 0
    for i in range(len(x_list)):
        tmp = abs(x_list[i] - y_list[i])**p
        tmp_ans += tmp
    tmp_ans = tmp_ans**(1/p)
    return tmp_ans

def minkowski_max(x_list, y_list):
    tmp_ans = 0
    for i in range(len(x_list)):
        tmp = abs(x_list[i] - y_list[i])
        tmp_ans = max(tmp_ans, tmp)
    return tmp_ans


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


print(minkowski(x_list, y_list, 1))
print(minkowski(x_list, y_list, 2))
print(minkowski(x_list, y_list, 3))
print(minkowski_max(x_list, y_list))

Solution (Python):
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
d = [abs(a-b) for (a,b) in zip(x,y)]
print(sum(d))
s = 0
for i in range(n):
    s += (x[i]-y[i])**2
print(math.sqrt(s))
s = 0
for i in range(n):
    s += abs(x[i]-y[i])**3
print(s**(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()]
l=[]
for a,b in zip(x,y):
    l.append(abs(a-b))
print("{:.6f}".format(sum(l)))
print("{:.6f}".format(sum([s**2 for s in l])**.5))
print("{:.6f}".format(sum([s**3 for s in l])**(1/3)))
print("{:.6f}".format(max(l)))

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

def dist(x, y, p):
    tmp = 0
    lst = []
    for x, y in zip(x, y):
        tmp += (abs(x-y))**p
        lst.append((abs(x-y)))
    if p==0:
        return max(lst)
    return tmp**(1/p)


print(dist(x, y, 1))
print(dist(x, y, 2))
print(dist(x, y, 3))
print(dist(x, y, 0))

Solution (Python):

def dist(list_x,list_y,p):
    sum = 0
    for i in range(len(list_x)):
        sum += abs(list_x[i]-list_y[i])**p
    return print(sum**(1/p))


def infi(list_x,list_y):
    sum=[]
    for i in range(len(list_x)):
        sum.append(abs(list_x[i]-list_y[i]))
    return print(max(sum))


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

dist(x,y,p=1)
dist(x,y,p=2)
dist(x,y,p=3)
infi(x,y)

Solution (Python):
n = int(input())
x = [float(i) for i in input().split()]
y = [float(i) for i in 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**0.5)

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

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

Solution (Python):
def dis(A,B,d):
    res = 0.0
    for i in range(len(A)):
        res += abs(A[i]-B[i])**d
    return res**(1.0/d)

def main():
    n = int(input())
    A = list(map(float,input().split()))
    B = list(map(float,input().split()))
    print(dis(A,B,1.0))
    print(dis(A,B,2.0))
    print(dis(A,B,3.0))
    res = 0.0
    for i in range(n):res = max(res,abs(A[i]-B[i]))
    print(res)



if __name__ == '__main__':
    main()

Solution (Python):
import math

def distance(p,x,y):
    ans = 0
    for i in range(len(x)):
        ans += (abs(x[i]-y[i])**p)
    return pow(ans,1/p)

def chebyshev(x,y):
    return max(abs(x[i]-y[i]) for i in range(len(x)))

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

print(distance(1,x,y))
print(distance(2,x,y))
print(distance(3,x,y))
print(chebyshev(x,y))

Solution (Python):
import math
f_inf = float("inf")
num = int(input())
s = input().rstrip().split(' ')
t = input().rstrip().split(' ')
d1 = 0
d2 = 0
d3 = 0
dinf = 0
for i in range(num):
  d1 = d1 + abs(int(s[i]) - int(t[i]))
  d2 = d2 + (int(s[i]) - int(t[i])) ** 2
  d3 = d3 + (abs(int(s[i]) - int(t[i]))) ** 3
  if abs(int(s[i]) - int(t[i])) > dinf:
    dinf = abs(int(s[i]) - int(t[i]))

d2 = math.sqrt(d2)
d3 = d3 ** (1/3)
print(d1)
print(d2)
print(d3)
print(dinf)

Solution (Python):
n = int(input())
xi = list(map(int,input().split()))
yi = list(map(int,input().split()))
dxy = [abs(a-b) for (a,b) in zip(xi,yi)]
for p in range(1,4):
    print (sum(map(lambda t: t**p,dxy))**(1/p))
print (max(dxy))

Solution (Python):
def distance(x, y, p):
    return sum([abs(i - j) ** p for i, j in zip(x, y)]) ** (1 / p)

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

[print('{:f}'.format(distance(x, y, _))) for _ in range(1, 4)]
print('{:f}'.format(max([abs(i - j) for i, j in zip(x, y)])))

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

print(sum([abs(z) for z in [y - x for x, y in zip(x, y)]]))
print(sum([(y - x) ** 2 for x, y in zip(x, y)]) ** 0.5)
print(sum([abs(z) for z in [(y - x) ** 3 for x, y in zip(x, y)]]) ** (1/3))
print(max([abs(z) for z in [y - x for x, y in zip(x, y)]]))

Solution (Python):

n = int(input())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
D1, D2, D3, Dinf = 0, 0, 0, 0


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


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


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


for i in range(n):
    d = abs(x[i]-y[i])
    if d > Dinf:
        Dinf = d


print(D1, D2, D3, Dinf, sep='\n')

Solution (Python):

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

for i in range(1,4):
    ans = 0
    for j in range(n):
        ans += abs(x[j] - y[j]) ** i
    else:
        ans **= 1/i
        print(ans)
        
max_d = 0
for i in range(n):
    max_d = max(max_d, abs(x[i]-y[i]))
ans = max_d

print(ans)

Solution (Python):
import math
import copy
from copy import deepcopy
import sys
import fractions

from functools import reduce
import statistics
import decimal
import heapq
import collections
import itertools
from operator import mul

sys.setrecursionlimit(100001)







def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList



def getInputListF():
    outputData = []
    inputData = input().split()
    outputData = [float(n) for n in inputData]

    return outputData

def calcDis(a, b, num):
    ans = 0
    for i in range(len(a)):
        ans += abs(a[i]-b[i])**num
    ans = ans**(1/num)
    return ans

def calcChebi(a, b):
    ans = 0
    for i in range(len(a)):
        ans = max(ans, abs(a[i]-b[i]))
    return ans

n = int(input())
d1 = getInputListF()
d2 = getInputListF()

print(calcDis(d1, d2, 1))
print(calcDis(d1, d2, 2))
print(calcDis(d1, d2, 3))
print(calcChebi(d1, d2))

Solution (Python):
import math
input()
a=[int(item) for item in input().split()]
b=[int(item) for item in input().split()]

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

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

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

chebyshev=max([abs(x-y) for x,y in zip(a,b)])
print("{}\n{}\n{}\n{}".format(manhattan,eucrid,sono3,chebyshev))

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

print(sum([abs(an[i] - bn[i]) for i in range(n)]))
print(sum([abs(an[i] - bn[i])**2 for i in range(n)])**(1/2))
print(sum([abs(an[i] - bn[i])**3 for i in range(n)])**(1/3))
print(max([float(abs(an[i] - bn[i])) for i in range(n)]))

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

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    x_y = [abs(i - j) for i, j in zip(x, y)]
    
    for p in range(1, 4):
        tmp = 0
        for i in range(N):
            tmp += pow(x_y[i], p)
        print(pow(tmp, 1/p))
    print(max(x_y))




if __name__ == "__main__":
    main()

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

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

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

Solution (Python):

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

p_1 = sum((abs(x[i]-y[i])) for i in range(N))

p_2 = math.sqrt(sum(((x[i]-y[i])**2 for i in range(N))))

p_3 = (sum(abs(x[i]-y[i])**3 for i in range(N)))**(1/3)

p_m = max(abs(x[i]-y[i]) for i in range(N))

print(p_1)
print(p_2)
print(p_3)
print(p_m)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
for p in range(1,4):
    tmp = 0
    for x, y in zip(X, Y):
        tmp += abs(x-y)**p
    print(tmp**(1/p))
M = 0
for x, y in zip(X, Y):
     M = max(M, abs(x-y))
print(M)

Solution (Python):

def dist(X, Y, p):
    d = sum([abs(x - y)**p for x, y in zip(X, Y)])
    return d**(1/p)


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

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

Solution (Python):
import math

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

ans = []
Chebyshev = 0
for i in range(1,4):
  Minkowski = 0
  for x, y in zip(x_list, y_list):
    Minkowski += abs(x - y) ** (i)
    Chebyshev = max(Chebyshev, abs(x - y))
  ans.append(Minkowski ** (1/i))
ans.append(Chebyshev)
for out in ans:
  print(float(out))

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=[]
for i in range(n):
	t=abs(x[i]-y[i])
	p1+=t
for i in range(n):
	t=(abs(x[i]-y[i]))**2
	p2+=t
p2=math.sqrt(p2)
for i in range(n):
	t=(abs(x[i]-y[i]))**3
	p3+=t
p3=p3**(1/3)
for i in range(n):
	pinf.append(abs(x[i]-y[i]))
p4=max(pinf)
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()))
lop = []
p1 = 0
p2 = 0
p3 = 0
pm = 0
for i in range(n):
    p1 += float((abs(x[i]-y[i])))
    
for i in range(n):
    p2 += abs((x[i]-y[i]))**2
    
for i in range(n):
    p3 += (abs((x[i]-y[i])))**3
    
for i in range(n):
    lop.append(float((abs(x[i]-y[i]))))
    
print(p1)
print(p2**(1/2))
print(p3**(1/3))
print(max(lop))

Solution (Python):
import math

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

D1 = 0
D2t = 0
D3t = 0
Di = []

for i in range(n):
    D1 += abs(x[i] - y[i])
    D2t += abs(x[i] - y[i]) ** 2
    D3t += abs(x[i] - y[i]) ** 3
    Di.append(abs(x[i] - y[i]))

print("{:f}".format(D1))
print("{:f}".format(math.sqrt(D2t)))
print("{:f}".format(D3t ** (1/3)))
print("{:f}".format(max(Di)))

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

result1 = 0
for i in range(n):
    tmp = x[i] - y[i]
    if tmp > 0:
        result1 += tmp
    else:
        result1 -= tmp
        
result2 = 0
for i in range(n):
    tmp = x[i] - y[i]
    tmp = tmp**2
    result2 += tmp
result2 = math.sqrt(result2)

result3 = 0
for i in range(n):
    tmp = x[i] - y[i]
    tmp = tmp**3
    if tmp > 0:
        result3 += tmp
    else:
        result3 -= tmp
result3 = math.pow(result3, 1.0/3.0)

result4 = 0        
for i in range(n):
    tmp = x[i] - y[i]
    tmp = tmp**2
    tmp = math.sqrt(tmp)
    if tmp > result4:
        result4 = tmp
        
print(result1)
print(result2)
print(result3)
print(result4)

Solution (Python):
import math
d=int(input())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
p_1=[abs(x-y) for x,y in zip(X,Y)]
print(round(sum(p_1),8))
p_2=[abs(x-y)**2 for x,y in zip(X,Y)]
print(round(math.sqrt(sum(p_2)),8))
p_3=[abs(x-y)**3 for x,y in zip(X,Y)]
print(round(math.pow(sum(p_3),1.0/3.0),8))
p_4=max(p_1)
print(round(p_4,8))

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

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

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

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

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

print(max(p4))

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

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

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

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

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

print("{:10f}".format(D1))
print("{:10f}".format(D2))
print("{:10f}".format(D3))
print("{:10f}".format(Dinf))

Solution (Python):
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 = []
for i in range(n):
    p_1 += abs(x[i]-y[i])
    p_2 += abs(x[i]-y[i])**2
    p_3 += abs(x[i]-y[i])**3
    p_inf.append(abs(x[i]-y[i]))
print(format(float(p_1),".5f"))
print(format(float(p_2**(1/2)),".5f"))
print(format(float(p_3**(1/3)),".5f"))
print(format(float(max(p_inf)),".5f"))

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

Solution (Python):
import math


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


def Euclidean(x, y):
    n = len(x)
    D = 0
    for i in range(n):
        D += (x[i] - y[i]) ** 2
    return math.sqrt(D)


def Tri(x, y):
    n = len(x)
    D = 0
    for i in range(n):
        D += abs(x[i] - y[i]) ** 3
    return math.pow(D, 1.0 / 3.0)


def Chebyshev(x, y):
    n = len(x)
    D = 0
    for i in range(n):
        D = max(D, abs(x[i] - y[i]))
    return D


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

print(Manhattan(x, y))
print(Euclidean(x, y))
print(Tri(x, y))
print(Chebyshev(x, y))

Solution (Python):
import math

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

for p in range(1, 4):
    sum = 0
    for i in range(n):
        sum += abs(x[i] - y[i]) ** p
    print('{:.10f}'.format(math.pow(sum, 1/p)))
ans = 0
for i in range(n):
    ans = max(ans, abs(x[i] - y[i]))
print(ans)

Solution (Python):
import math

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


def mink(p):
    return math.pow(sum([
        math.pow(math.fabs(xs[i] - ys[i]), p)
        for i in range(n)
    ]), 1 / p)


def mink_inf():
    return max([math.fabs(xs[i] - ys[i]) for i in range(n)])


def float_print(v):
    print('{:.5f}'.format(v))


float_print(mink(1))
float_print(mink(2))
float_print(mink(3))
float_print(mink_inf())

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([x**2 for x in x_y]) ** (1/2)
p3 = sum([x**3 for x in x_y]) ** (1/3)
pn = max(x_y)
print(p1)
print(p2)
print(p3)
print(pn)

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

ans[1] = ans[1]**(1/2)
ans[2] = ans[2]**(1/3)

for i in ans:
	print(i)

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

Solution (Python):
import sys
import itertools
import math



read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())

A = [int(x) for x in readline().split()]
B = [int(x) for x in readline().split()]

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

for i, j in zip(A, B):
    ans1 += abs(i - j)
    ans2 += (i - j) ** 2
    ans3 += (abs(i - j)) ** 3
    ans4 = max(ans4, abs(i - j))
print(ans1 * 1.0, ans2 ** .5, ans3 ** (1 / 3), ans4 * 1.0, sep='\n')

Solution (Python):
def calc_distance(left, right, p):
    return sum(list(map(lambda x, y: abs(x - y) ** p, left, right))) ** (1 / p)


n = int(input())
v1 = list(map(lambda x: float(x), input().split()))
v2 = list(map(lambda x: float(x), input().split()))
for i in range(1, 4):
    print("{:f}".format(calc_distance(v1, v2, i)))
print("{:f}".format(max(list(map(lambda x, y: abs(x - y), v1, v2)))))

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

d1 = 0.0
d2 = 0.0
d3 = 0.0
dinf = 0.0

for i in range(n):
    d1 += abs(x[i] - y[i])
    d2 += (x[i] - y[i]) ** 2.0
    d3 += abs(x[i] - y[i]) ** 3.0
    dinf = max(dinf, abs(x[i] - y[i]))

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

print("{:.10f}".format(d1))
print("{:.10f}".format(d2))
print("{:.10f}".format(d3))
print("{:.10f}".format(dinf))

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

manhattan = 0
euclidean = 0
p3 = 0
chebyshev = []
for i in range(n) :
    manhattan += abs(x[i] - y[i])
    euclidean += abs(x[i] - y[i]) ** 2
    p3 += abs(x[i] - y[i]) ** 3
    chebyshev.append(abs(x[i] - y[i]))

euclidean = math.sqrt(euclidean)
p3 = p3 ** (1/3)
chebyshev = max(chebyshev)

print(manhattan)
print(euclidean)
print(p3)
print(chebyshev)

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

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

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

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

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

Solution (Python):
n = int(input())
infinity = float("inf")

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

p = [1, 2, 3, infinity]

for i in p:
    if i != infinity:
        total = 0
        for X, Y in zip(x, y):
            total += (abs(X - Y)) ** i
        D = total ** (1/i)
        print(D)
    else:
        d = list()
        for X, Y in zip(x, y):
            d.append(abs(X - Y))
        print(max(d))

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

sum1 = 0
sum2 = 0
sum3 = 0
dif = []
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
    dif += [abs(x[i] - y[i])]
print("%f" %sum1)
print("%f" %(sum2)**(1/2))
print("%f" %(sum3)**(1/3))
print("%f" %max(dif))

Solution (Python):
import math

ans = []
n = int(input())
xn = list(map(float,input().split()))
yn = list(map(float,input().split()))

def man(xx):
    sum = 0
    for i in range(n):
        sum += (abs(xn[i] - yn[i]))**xx
    return sum**(1/xx)

def che():
    sum = 0
    for i in range(n):
        tmp = (abs(xn[i] - yn[i]))
        if tmp > sum:
            sum = tmp
    return sum


for i in range(1,4):
    print(man(i))
print(che())

Solution (Python):
n=input()
x=map(float,raw_input().split())
y=map(float,raw_input().split())
d1=0
for i in range(n):
    d1+=abs(x[i]-y[i])
d2=0
for i in range(n):
    d2+=abs(x[i]-y[i])**2
d2=d2**(0.5)
d3=0
for i in range(n):
    d3+=abs(x[i]-y[i])**3
d3=d3**(0.3333333333333)
dinf=0
for i in range(n):
    if dinf<abs(x[i]-y[i]):
        dinf=abs(x[i]-y[i])

print d1
print d2
print d3
print dinf

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

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

d_max = 0

for j in range(n):
    d_max = max(abs(x[j] - y[j]), d_max)

print(d_max)

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

p1, p2, p3, pm = 0, 0, 0, 0
for _x, _y in zip(x, y):
    p1 += abs(_x-_y)
    p2 += abs(_x-_y)**2
    p3 += abs(_x-_y)**3
    pm = max(pm, abs(_x-_y))

print("{:.6f}".format(p1))
print("{:.6f}".format(p2**0.5))
print("{:.6f}".format(p3**(1/3)))
print("{:.6f}".format(pm))

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

d1, d2, d3, dinf = 0, 0, 0, 0
for i in range(n):
    d1 += abs(xl[i] - yl[i])
    d2 += (xl[i] - yl[i])**2
    d3 += (abs(xl[i] - yl[i]))**3
    dinf_ = abs(xl[i] - yl[i])
    if dinf_ > dinf:
        dinf = dinf_

print('{}\n{}\n{}\n{}'.format(d1, d2**(1/2), d3**(1/3), dinf))

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
d4=0

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

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

d3=d3**(1/3)

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

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

Solution (Python):
import math

def dis(n, x1, x2, d):
    dist = 0
    for i in range(n):
        dist += (abs(x1[i] - x2[i]))**d
    
    dist = pow(dist, 1/d)
    
    return dist

def chev(n, x1, x2):
    d = []
    for i in range(n):
        d.append(abs(x2[i]-x1[i]))
    
    return max(d)

n = int(input())
x1 = list(map(int, input().split()))
x2 = list(map(int, input().split()))

for i in range(1,4):
    print('%.5f'%dis(n,x1, x2, i))

print('%.5f'%chev(n, x1, x2))

Solution (Python):
n=int(input())
lis=list(map(int,input().split()))
lis2=list(map(int,input().split()))
abslis=[0 for i in range(n)]

for i in range(n):
    abslis[i]=abs(lis[i]-lis2[i])

print("{:.6f}".format(sum(abslis)))
summ=0
for i in range(n):
    summ+=abslis[i]**2
summ**=0.5
print("{:.6f}".format(summ))
summ=0
for i in range(n):
    summ+=abslis[i]**3
summ**=(1/3)
print("{:.6f}".format(summ))
print("{:.6f}".format(max(abslis)))

Solution (Python):
import math

def disp(p,x,y,n):
    if p==0:
        max=0
        for i in range(n):
            if max<abs(x[i]-y[i]):
                max=abs(x[i]-y[i])
        return max
    else:
        sum=0
        for i in range(n):
            sum+=(abs(x[i]-y[i]))**p
        return (sum**(1/p))
    
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
for p in range(1,4):
    print(disp(p,x,y,n))
print(disp(0,x,y,n))

Solution (Python):
import math

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

answer = []


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

    answer.append(result ** (1 / p))


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

answer.append(result)

[print("{:.6f}".format(answer[i])) for i in range(len(answer))]

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

D = [0 for x in range(3)]
for pi in range(3):
 S = 0
 for ni in range(n):
  S = S + abs(x[ni]-y[ni])**(pi+1)
 D[pi] = S**(1/(pi+1))
 print(D[pi])
Dinf = -math.inf
for ni in range(n):
 Dinf = Dinf if Dinf>abs(x[ni]-y[ni]) else abs(x[ni]-y[ni])
print(Dinf)

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

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

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

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

Solution (Python):
import math

n = int(input())
xlist = input().split()
xlist = [int(s) for s in xlist]
ylist = input().split()
ylist = [int(s) for s in ylist]
zlist = [abs(xlist[x] - ylist[x]) for x in range(n)]

ans1 = 0
ans2 = 0
ans3 = 0
for x in range(n):
    ans1 += abs(xlist[x] - ylist[x])
    ans2 += abs(xlist[x] - ylist[x])**2
    ans3 += abs(xlist[x] - ylist[x])**3
print(ans1)    
print(math.sqrt(ans2))
print(ans3**(1/3))
print(max(zlist))

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

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

print(sum(b))
print(sum([i ** 2 for i in b]) ** (1 / 2))
print(sum([i ** 3 for i in b]) ** (1 / 3))
print(max(b))

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

def minkowski(p, X, Y):
    s = 0
    for x, y in zip(X, Y):
        s += abs(x - y)**p
    return s**(1/p)
def chebyshev(X, Y):
    return max(abs(x - y) for x, y in zip(X, Y))


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


print(f"{minkowski(1, X, Y):.8f}")
print(f"{minkowski(2, X, Y):.8f}")
print(f"{minkowski(3, X, Y):.8f}")
print(f"{chebyshev(X, Y):.8f}")

Solution (Python):
import math

n = int(input())
x = [int(e) for e in input().split()]
y = [int(e) for e in input().split()]
D1=0
D2=0
D3=0
Di=abs(x[0]-y[0])
for i in range(n):
    D1 = D1 + (abs(x[i]-y[i]))
    D2 = D2 + (abs(x[i]-y[i]))**2
    D3 = D3 + (abs(x[i]-y[i]))**3
    if abs(x[i]-y[i]) > Di:
        Di = abs(x[i]-y[i])
print(D1)
print(math.sqrt(D2))
print(D3**(1/3))
print(Di)

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):
    tmp = abs(X[i] - Y[i])
    p1 += tmp
    p2 += tmp ** 2
    p3 += tmp ** 3
    pinf = max(pinf, abs(X[i] - Y[i]))
p2 = p2 ** (1/2)
p3 = p3 ** (1/3)
print(p1)
print(p2)
print(p3)
print(pinf)