Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

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



Sample input:
3
1 2 3
2 0 4


Sample output:
4.000000
2.449490
2.154435
2.000000

Submission status: Accepted

Solution code:
import math

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

p1 = sum([math.fabs(x[i]-y[i]) for i in range(n)])
p2 = math.sqrt(sum([math.fabs(x[i]-y[i])**2 for i in range(n)]))
p3 = math.pow(sum([math.fabs(x[i]-y[i])**3 for i in range(n)]), 1/3)
pp = max([math.fabs(x[i]-y[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))

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
dxy = [abs(a - b) for a, b in zip(x, y)]
D = [sum([n ** p for n in dxy]) ** (1 / p) for p in range(1, 4)]
D.append(max(dxy))
for d in D:
    print("{:.5f}".format(d))

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
##절대값 내장함수 abs!
for k in range(1,4):
    print('{0:.6f}'.format(pow(sum(abs((x[i] - y[i])**k)for i in range(n)),1/k)))

print('{0:.6f}'.format(max(abs((x[i] - y[i]))for i in range(n))))
## p =infinity 인경우에는 수학적으로 생각하면 차의 절대값의 최대값이 답임

Submission status: Accepted

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

print("{0:.6f}".format(sum([math.fabs(x[i]-y[i]) for i in range(n)])))
print("{0:.6f}".format(math.sqrt(sum([math.fabs(x[i]-y[i])**2 for i in range(n)]))))
print("{0:.6f}".format(math.pow(sum([math.fabs(x[i]-y[i])**3 for i in range(n)]), 1/3)))
print("{0:.6f}".format(max([math.fabs(x[i]-y[i]) for i in range(n)])))

Submission status: Accepted

Solution code:
import math


loops = int(input())
x_vec = list(map(int, input().split()))
y_vec = list(map(int, input().split()))

manhattan = sum([abs(x_vec[i] - y_vec[i]) for i in range(len(x_vec))])
euclid = math.sqrt(sum([(abs(x_vec[i] - y_vec[i])) ** 2 for i in range(len(x_vec))]))
pequalthree = math.pow(sum([(abs(x_vec[i] - y_vec[i])) ** 3 for i in range(len(x_vec))]), 1.0/3.0)
chebyshev = max([abs(x_vec[i] - y_vec[i]) for i in range(len(x_vec))])

print(manhattan)
print(euclid)
print(pequalthree)
print(chebyshev)

Submission status: Accepted

Solution code:
def pN(n, x, y, N):
	result = list()
	for i in range(n):
		result.append(abs(x[i] - y[i]) ** N)
	return (sum(result) ** (1 / N))

def pMax(n, x, y):
	result = list()
	for i in range(n):
		result.append(abs(x[i] - y[i]))
	return max(result)

n = int(input())
x = [int(x) for x in input().split()]
y = [int(y) for y in input().split()]
print('%.8f' % pN(n, x, y, 1))
print('%.8f' % pN(n, x, y, 2))
print('%.8f' % pN(n, x, y, 3))
print('%.8f' % pMax(n, x, y))

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
d1, d2, d3, di = 0, 0, 0, 0
for i in range(n):
  d1 += abs(x[i]-y[i])
  d2 += (x[i]-y[i])**2
  d3 += abs((x[i]-y[i]))**3
  di = max(di, abs(x[i]-y[i]))
print(d1)
print(d2**0.5)
print(d3**(1/3))
print(di)

Submission status: Accepted

Solution code:
n = int(input())
X = [float(i) for i in input().split(' ')]
Y = [float(i) for i in input().split(' ')]
d1, d2, d3, di = 0,0,0,0
for x,y in zip(X,Y):
	d1 += abs(x-y)
	d2 += pow(abs(x-y), 2)
	d3 += pow(abs(x-y), 3)
	if di < abs(x-y): di = abs(x-y)
print(d1)
print(pow(d2, 1/2))
print(pow(d3, 1/3))
print(di)

Submission status: Accepted

Solution code:
import math
num = int(input())
data1 = []
data2 = []
tmp = []
tmp = input().split()
data1 = [float(tmp[i]) for i in range(num)]
tmp = input().split()
data2 = [float(tmp[i]) for i in range(num)]
print(sum( abs(data1[i] - data2[i]) for i in range(num) ))
print(math.sqrt( sum(pow( data1[i] -data2[i] ,2 ) for i in range(num))))
print(pow( sum(pow( abs(data1[i] -data2[i]) ,3 ) for i in range(num)) ,1/3 ))
print(max( abs(data1[i] - data2[i]) for i in range(num) ))

Submission status: Runtime Error

Solution code:
import math
class Triangle(object):
    def __init__(self, a, b, C):
        self.a = a
        self.b = b
        self.C = math.radians(C)
    
    def getArea(self):
        return((self.a * self.getHeight()) / 2)

    def getPerimeter(self):
        return(self.a + self.b + math.sqrt(self.a ** 2 + self.b ** 2 - 2 * self.a * self.b * math.cos(self.C)))
    
    def getHeight(self):
        return(self.b * math.sin(self.C))

tri = Triangle(*[int(i) for i in input().split()])
print(tri.getArea())
print(tri.getPerimeter())
print(tri.getHeight())

Submission status: Runtime Error

Solution code:
import math

input()

vx = [int(i) for i in input().split()]
vy = [int(i) for i in input().split()]

Dxy = []
for p in range(1, 4):
    Dxy.append(sum([abs(xv[i] - vy[i]) ** p for i in range(len(vx))]) ** (1 / p))

Dxy.append(max([abs(vx[i] - vy[i]) for i in range(len(vx))]))

for res in Dxy:
    print('{0:5f}'.format(res))

Submission status: Runtime Error

Solution code:
def manhattan(xs, ys):
    d = sum([abs(x-y) for x, y in zip(xs, ys)])
    return d

def euclid(xs, ys):
    return math.sqrt(sum([(x-y)**2 for x, y in zip(xs, ys)]))

def chev(xs, ys):
    return max([abs(x-y) for x, y in zip(xs, ys)])

def norm():
    n = int(input())
    xs = list(map(int, input().split()))
    ys = list(map(int, input().split()))
    print(manhattan(xs, ys), euclid(xs, ys), chev(xs, ys))

norm()

Submission status: Runtime Error

Solution code:
def manhattan(xs, ys):
    return sum([abs(x-y) for x, y in zip(xs, ys)])

def euclid(xs, ys):
    return math.sqrt(sum([(x-y)**2 for x, y in zip(xs, ys)]))

def l3(xs, ys):
    return (sum([(x-y)*** for x, y in zip(xs, ys)]))**(1/3)

def chev(xs, ys):
    return max([abs(x-y) for x, y in zip(xs, ys)])

def norm():
    n = int(input())
    xs = list(map(int, input().split()))
    ys = list(map(int, input().split()))
    print(manhattan(xs, ys))
    print(euclid(xs, ys))
    print(l3(xs, ys))
    print(chev(xs, ys))

norm()

Submission status: Runtime Error

Solution code:
    n = int(input())
    xs = list(map(int, input().split()))
    ys = list(map(int, input().split()))
    print(manhattan(xs, ys))
    print(euclid(xs, ys))
    print(l3(xs, ys))
    print(chev(xs, ys))

norm()

Submission status: Runtime Error

Solution code:
n = int(input())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
print(manhattan(xs, ys))
print(euclid(xs, ys))
print(l3(xs, ys))
print(chev(xs, ys))

norm()

Submission status: Runtime Error

Solution code:
n = int(input())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

norm()

Submission status: Runtime Error

Solution code:
n = int(input())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

print(sum([abs(x-y) for x, y in zip(xs, ys)]))
print(math.sqrt(sum([(x-y)**2 for x, y in zip(xs, ys)])))
print((sum([(x-y)*** for x, y in zip(xs, ys)]))**(1/3))
print(max([abs(x-y) for x, y in zip(xs, ys)]))

Submission status: Runtime Error

Solution code:
n = int(input())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

print(sum([abs(x-y) for x, y in zip(xs, ys)]))
print(math.sqrt(sum([(x-y)**2 for x, y in zip(xs, ys)])))
print((sum([(x-y)**3 for x, y in zip(xs, ys)]))**(1/3))
print(max([abs(x-y) for x, y in zip(xs, ys)]))

Submission status: Runtime Error

Solution code:
inf = float('inf')

def distance(p,n,x,y):
    D = 0.0
    s = []
    for i in range(0,n):
        s.append(x[i]-y[i])
        if s[i]<0.0:
            s[i]*=-1.0
        D += s[i]**p 
        
    if p==inf:
        return max(s)
    else:
        return D**(1.0/p)

if __name__ == '__main__':
    n = int(input())
    x = []
    y = []

    for i in range(0,n):
        x.append(int(input()))
    for i in range(0,n):
        y.append(int(input()))
        
    print float(distance(1,n,x,y))
    print float(distance(2,n,x,y))
    print float(distance(3,n,x,y))
    print float(distance(inf,n,x,y))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 10 11:31:39 2015

@author: Ryuhei
"""

inf = float('inf')

def distance(p,n,x,y):
    D = 0
    s = []
    for i in range(0,n):
        s.append(x[i]-y[i])
        if s[i]<0.0:
            s[i]*=-1.0
        D += s[i]**p 
        
    if p==inf:
        return max(s)
    else:
        return D**(1.0/p)

if __name__ == '__main__':
    n = int(input())
    x = []
    y = []

    for i in range(0,n):
        x.append(int(input()))
    for i in range(0,n):
        y.append(int(input()))
        
    print float(distance(1,n,x,y))
    print float(distance(2,n,x,y))
    print float(distance(3,n,x,y))
    print float(distance(inf,n,x,y))

Submission status: Runtime Error

Solution code:
import math
n = int(input)
A = list(map(int, input().split()))
B = list(map(int, input().split()))

for p in range(1, 4):
    D = []
    for count in range(n):
        D.append((math.fabs(A[count] - B[count]))** p)
    if p == 1:
        di = max(D)
    d = (sum(D)) ** (1/p)
    print('%.06f' %d)
print('%.06f' % di)

Submission status: Runtime Error

Solution code:
n=int(input())
vector1=[int(x) for x in input().split()]
vector2=[int(x) for x in input().split()]
for i in range(1,4):
print("{0:.8f}".format(sum([abs(a-b)**p for a,b in zip(vector1,vector2)])**(1/p)))
print("{0:.8f}".format(max([abs(a-b) for a,b in zip(vector1,vector2)])))

Submission status: Runtime Error

Solution code:
n=int(input())
vector1=[int(x) for x in input().split()]
vector2=[int(x) for x in input().split()]
for i in range(1,4):
    print("{0:.8f}".format(sum([abs(a-b)**p for a,b in zip(vector1,vector2)])**(1/p)))
    print("{0:.8f}".format(max([abs(a-b) for a,b in zip(vector1,vector2)])))

Submission status: Runtime Error

Solution code:
n=int(input())
vector1=[int(x) for x in input().split()]
vector2=[int(x) for x in input().split()]
for i in range(1,4):
    print("{0:.8f}".format(sum([abs(a-b)**p for a,b in zip(vector1,vector2)])**(1/i)))
    print("{0:.8f}".format(max([abs(a-b) for a,b in zip(vector1,vector2)])))

Submission status: Runtime Error

Solution code:
import math
n = int(input())
x = list(map(int, raw_input().split()))
y = list(map(int, raw_input().split()))
t1 = t2 = t3 = ti = 0.0
for a, b in zip(x, y):
	d1 = abs(a - b)
	ti = max(ti, d1)
	t1 += d1
	t2 += d1**2
	t3 += d1**3
print(t1)
print(math.sqrt(t2))
print(t3 ** (1.0/3))
print(ti)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
p1, p2, p3, p4 = 0, 0, 0, 0
hyp = 0
for i in range(n):
    p1 += math.fabs(a1[i] -a2[i])
    p2 += (a1[i]-a2[i])**2
    p3 += math.fabs((a1[i]-a2[i])**3)
    hyp = math.fabs(a1[i] -a2[i]) 
    if hyp > p4:
        p4 = hyp

p2 = math.sqrt(p2)
p3 = math.exp(math.log(p3)/3)
print(p1)
print(p2)
print(p3)
print(p4)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
x, y = [list(map(int, input().split())) for _ in range(2)]
for p in (1,2,3,math.inf):
    if p == math.inf:
        print(max(abs(x-y) for x, y in zip(x,y)))
    else:
        print(math.pow(sum(abs(x-y) ** p for x, y in zip(x,y)), 1.0 / p))

Submission status: Runtime Error

Solution code:
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 += math.fabs(x[i]-y[i])**p
 print(sum**(1/p))

sum = 0
for i in range(n):
 sum += math.fabs(x[[i]-y[i])**math.inf
print(sum**(1/math.inf))

Submission status: Runtime Error

Solution code:
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 += math.fabs(x[i]-y[i])**p
 print(sum**(1/p))

a = []
for i in range(n):
 a.append(math.fabs(x[i]-y[i]))
a = a.sort()
print(a[n])

Submission status: Runtime Error

Solution code:
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 += math.fabs(x[i]-y[i])**p
 print(sum**(1/p))

a = []
for i in range(n):
 a.append(math.fabs(x[i]-y[i]))
a = a.sort()
print(a[n-1])

Submission status: Runtime Error

Solution code:
import math


def calc_minkowski_distance(data_x, data_y, types):
    # ???????´???????????¨???????map???????????¬??????????????????????????¨????????¨????????§?¶???????????????????????????§????????????????????????
    distance = list(map(lambda x, y:abs(x - y), data_x, data_y))

    results = []
    for t in types:
        if t == math.inf:
            results.append(max(distance))
        else:
            temp = map(lambda x:math.pow(x, t), distance)
            total = sum(temp)
            results.append(math.pow(total, 1.0/t))
    return results


if __name__ == '__main__':
    # ??????????????\???
    # data_x = [1, 2, 3]
    # data_y = [2, 0, 4]
    num = int(input())
    data_x = [int(x) for x in input().split(' ')]
    data_y = [int(x) for x in input().split(' ')]

    # ???????????????
    types = [1, 2, 3, math.inf]
    results = calc_minkowski_distance(data_x, data_y, types)

    # ???????????¨???
    for r in results:
        print('{0:.6f}'.format(r))

Submission status: Runtime Error

Solution code:
import math


def calc_minkowski_distance(data_x, data_y, types):
    # ???????´???????????¨???????map???????????¬??????????????????????????¨????????¨????????§?¶???????????????????????????§????????????????????????
    distance = list(map(lambda x, y:abs(x - y), data_x, data_y))

    results = []
    for t in types:
        if t == math.inf:
            results.append(max(distance))
        else:
            temp = map(lambda x:math.pow(x, t), distance)
            total = sum(temp)
            results.append(math.pow(total, 1.0/t))
    return results


if __name__ == '__main__':
    # ??????????????\???
    # data_x = [1, 2, 3]
    # data_y = [2, 0, 4]
    num = int(input())
    data_x = [int(x) for x in input().split(' ')]
    data_y = [int(x) for x in input().split(' ')]

    # ???????????????
    types = [1, 2, 3, math.inf]
    results = calc_minkowski_distance(data_x, data_y, types)

    # ???????????¨???
    for r in results:
        print('{0:.8f}'.format(r))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import sys
import collections
import math
import unittest


def calculate_minkowski_distances():
    lines = sys.stdin.readlines()[1:]
    data = []
    for line in lines:
        data.append([ float(value) for value in line.rstrip().split() ])

    for exponent in (1, 2, 3, math.inf):
        print(minkowski_distance(*data, exponent))

def minkowski_distance(vector_x, vector_y, exponent):
    abs_xy = [ abs(pair[0] - pair[1]) for pair in zip(vector_x, vector_y) ]

    m_dis = 0
    if math.isinf(exponent) :
        m_dis = max(abs_xy)
    elif exponent == 0 :
        m_dis = nan
    else :
        m_dis = ( sum([ elem**exponent for elem in abs_xy ])**(1/exponent) )
    
    return m_dis
    
def __input_error():
    print("input error")
    return -1

class __TestValueClass(unittest.TestCase):
    def testEqual(self, func, tuples, eff_digit = math.nan, print_success = False):
        self.testFunction(self.assertEqual,func,tuples,eff_digit,print_success)
    
    def testFunction(self,assertfunc,func,tuples,eff_digit,print_success):
        #tuples[index] = ([*arguments of func], compared value)
        for item in tuples:
            try:
                if isinstance(item[0], collections.Iterable):
                    value = func(*item[0])
                else:
                    value = func(item[0])
                
                if math.isnan(eff_digit) :
                    assertfunc(value,item[1])
                else :
                    format_str = "{0:."+str(eff_digit)+"g}"
                    assertfunc(format_str.format(value),format_str.format(item[1]))
                    
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                print("arguments".ljust(swidth)+":",item[0])
                print("compared value".ljust(swidth)+":",item[1])
                print("message".ljust(swidth)+":")
                print(msg)
                sys.exit()
        if print_success :
            print(func.__name__,": succeeded")

#test
if __name__ == "__main__" :

    test = __TestValueClass()
    vec_x = [1, 2, 3]
    vec_y = [2, 0, 4]
    test.testEqual(minkowski_distance, [([vec_x, vec_y, 1], 4),         ([vec_x, vec_y, 2], 2.449490)], eff_digit = 5)
    test.testEqual(minkowski_distance, [([vec_x, vec_y, 3], 2.154435),  ([vec_x, vec_y, math.inf], 2)], eff_digit = 5)#, print_success = True)

    calculate_minkowski_distances()

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import sys
import collections
import math
import unittest


def calculate_minkowski_distances():
    lines = sys.stdin.readlines()[1:]
    data = []
    for line in lines:
        data.append([ float(value) for value in line.rstrip().split() ])

    for exponent in (1, 2, 3, math.inf):
        print(minkowski_distance(*data, exponent))

def minkowski_distance(vector_x, vector_y, exponent):
    abs_xy = [ abs(pair[0] - pair[1]) for pair in zip(vector_x, vector_y) ]

    m_dis = 0
    if math.isinf(exponent) :
        m_dis = max(abs_xy)
    elif exponent == 0 :
        m_dis = nan
    else :
        m_dis = ( sum([ elem**exponent for elem in abs_xy ])**(1/exponent) )
    
    return m_dis
    
def __input_error():
    print("input error")
    return -1

class __TestValueClass(unittest.TestCase):
    def testEqual(self, func, tuples, eff_digit = math.nan, print_success = False):
        self.testFunction(self.assertEqual,func,tuples,eff_digit,print_success)
    
    def testFunction(self,assertfunc,func,tuples,eff_digit,print_success):
        #tuples[index] = ([*arguments of func], compared value)
        for item in tuples:
            try:
                if isinstance(item[0], collections.Iterable):
                    value = func(*item[0])
                else:
                    value = func(item[0])
                
                if math.isnan(eff_digit) :
                    assertfunc(value,item[1])
                else :
                    format_str = "{0:."+str(eff_digit)+"g}"
                    assertfunc(format_str.format(value),format_str.format(item[1]))
                    
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                print("arguments".ljust(swidth)+":",item[0])
                print("compared value".ljust(swidth)+":",item[1])
                print("message".ljust(swidth)+":")
                print(msg)
                sys.exit()
        if print_success :
            print(func.__name__,": succeeded")

#test
if __name__ == "__main__" :

    test = __TestValueClass()
    vec_x = [1, 2, 3]
    vec_y = [2, 0, 4]
#    test.testEqual(minkowski_distance, [([vec_x, vec_y, 1], 4),         ([vec_x, vec_y, 2], 2.449490)], eff_digit = 5)
#    test.testEqual(minkowski_distance, [([vec_x, vec_y, 3], 2.154435),  ([vec_x, vec_y, math.inf], 2)], eff_digit = 5)#, print_success = True)

    calculate_minkowski_distances()

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !

import sys
import math

def calculate_minkowski_distances():
    lines = sys.stdin.readlines()[1:]
    data = []
    for line in lines:
        data.append([ float(value) for value in line.rstrip().split() ])

    for exponent in (1, 2, 3, math.inf):
        print(minkowski_distance(*data, exponent))

def minkowski_distance(vector_x, vector_y, exponent):
    abs_xy = [ abs(pair[0] - pair[1]) for pair in zip(vector_x, vector_y) ]

    m_dis = 0
    if math.isinf(exponent) :
        m_dis = max(abs_xy)
    elif exponent == 0 :
        m_dis = nan
    else :
        m_dis = ( sum([ elem**exponent for elem in abs_xy ])**(1/exponent) )
    
    return m_dis

#test
if __name__ == "__main__" :
    calculate_minkowski_distances()

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import sys
import collections
import math
import unittest


def calculate_minkowski_distances():
    _ = input()
    data = []
    for i in range(2):
        data.append([float(value) for value in input().rstrip().split()])
#    lines = sys.stdin.readlines()[1:]
#    for line in lines:
#        data.append([ float(value) for value in line.rstrip().split() ])

    for exponent in (1, 2, 3, math.inf):
        print(minkowski_distance(*data, exponent))

def minkowski_distance(vector_x, vector_y, exponent):
    abs_xy = [ abs(pair[0] - pair[1]) for pair in zip(vector_x, vector_y) ]

    m_dis = 0
    if math.isinf(exponent) :
        m_dis = max(abs_xy)
    elif exponent == 0 :
        m_dis = nan
    else :
        m_dis = ( sum([ elem**exponent for elem in abs_xy ])**(1/exponent) )
    
    return m_dis
'''
def __input_error():
    print("input error")
    return -1

class __TestValueClass(unittest.TestCase):
    def testEqual(self, func, tuples, eff_digit = math.nan, print_success = False):
        self.testFunction(self.assertEqual,func,tuples,eff_digit,print_success)
    
    def testFunction(self,assertfunc,func,tuples,eff_digit,print_success):
        #tuples[index] = ([*arguments of func], compared value)
        for item in tuples:
            try:
                if isinstance(item[0], collections.Iterable):
                    value = func(*item[0])
                else:
                    value = func(item[0])
                
                if math.isnan(eff_digit) :
                    assertfunc(value,item[1])
                else :
                    format_str = "{0:."+str(eff_digit)+"g}"
                    assertfunc(format_str.format(value),format_str.format(item[1]))
                    
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                print("arguments".ljust(swidth)+":",item[0])
                print("compared value".ljust(swidth)+":",item[1])
                print("message".ljust(swidth)+":")
                print(msg)
                sys.exit()
        if print_success :
            print(func.__name__,": succeeded")
'''
#test
if __name__ == "__main__" :

#    test = __TestValueClass()
#    vec_x = [1, 2, 3]
#    vec_y = [2, 0, 4]
#    test.testEqual(minkowski_distance, [([vec_x, vec_y, 1], 4),         ([vec_x, vec_y, 2], 2.449490)], eff_digit = 5)
#    test.testEqual(minkowski_distance, [([vec_x, vec_y, 3], 2.154435),  ([vec_x, vec_y, math.inf], 2)], eff_digit = 5)#, print_success = True)

    
    calculate_minkowski_distances()

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import math

def calculate_minkowski_distances():
    _ = input()
    data = []
    for i in range(2):
        data.append([float(value) for value in input().rstrip().split()])

    for exponent in (1, 2, 3, math.inf):
        print(minkowski_distance(*data, exponent))

def minkowski_distance(vector_x, vector_y, exponent):
    abs_xy = [ abs(pair[0] - pair[1]) for pair in zip(vector_x, vector_y) ]

    m_dis = 0
    if math.isinf(exponent) :
        m_dis = max(abs_xy)
    elif exponent == 0 :
        m_dis = nan
    else :
        m_dis = ( sum([ elem**exponent for elem in abs_xy ])**(1/exponent) )
    
    return m_dis

if __name__ == "__main__" :
    calculate_minkowski_distances()

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import sys
import collections
import math
import unittest


def calculate_minkowski_distances():
    _ = input()
    data = []
    for i in range(2):
        data.append([float(value) for value in input().rstrip().split()])
#    lines = sys.stdin.readlines()[1:]
#    for line in lines:
#        data.append([ float(value) for value in line.rstrip().split() ])

    for exponent in (1, 2, 3, math.inf):
        print("{0:.6f}".format(minkowski_distance(*data, exponent)))

def minkowski_distance(vector_x, vector_y, exponent):
    abs_xy = [ abs(pair[0] - pair[1]) for pair in zip(vector_x, vector_y) ]

    m_dis = 0
    if math.isinf(exponent) :
        m_dis = max(abs_xy)
    elif exponent == 0 :
        m_dis = nan
    else :
        m_dis = ( sum([ elem**exponent for elem in abs_xy ])**(1/exponent) )
    
    return m_dis
'''
def __input_error():
    print("input error")
    return -1

class __TestValueClass(unittest.TestCase):
    def testEqual(self, func, tuples, eff_digit = math.nan, print_success = False):
        self.testFunction(self.assertEqual,func,tuples,eff_digit,print_success)
    
    def testFunction(self,assertfunc,func,tuples,eff_digit,print_success):
        #tuples[index] = ([*arguments of func], compared value)
        for item in tuples:
            try:
                if isinstance(item[0], collections.Iterable):
                    value = func(*item[0])
                else:
                    value = func(item[0])
                
                if math.isnan(eff_digit) :
                    assertfunc(value,item[1])
                else :
                    format_str = "{0:."+str(eff_digit)+"g}"
                    assertfunc(format_str.format(value),format_str.format(item[1]))
                    
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                print("arguments".ljust(swidth)+":",item[0])
                print("compared value".ljust(swidth)+":",item[1])
                print("message".ljust(swidth)+":")
                print(msg)
                sys.exit()
        if print_success :
            print(func.__name__,": succeeded")
'''
#test
if __name__ == "__main__" :

#    test = __TestValueClass()
#    vec_x = [1, 2, 3]
#    vec_y = [2, 0, 4]
#    test.testEqual(minkowski_distance, [([vec_x, vec_y, 1], 4),         ([vec_x, vec_y, 2], 2.449490)], eff_digit = 5)
#    test.testEqual(minkowski_distance, [([vec_x, vec_y, 3], 2.154435),  ([vec_x, vec_y, math.inf], 2)], eff_digit = 5)#, print_success = True)

    
    calculate_minkowski_distances()

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import math

def calculate_minkowski_distances():
    _ = input()
    data = []
    for i in range(2):
        data.append([float(value) for value in input().rstrip().split()])
    for exponent in (1, 2, 3, math.inf):
        print("{0:.6f}".format(minkowski_distance(*data, exponent)))

def minkowski_distance(vector_x, vector_y, exponent):
    abs_xy = [ abs(pair[0] - pair[1]) for pair in zip(vector_x, vector_y) ]

    m_dis = 0
    if math.isinf(exponent) :
        m_dis = max(abs_xy)
    elif exponent == 0 :
        m_dis = nan
    else :
        m_dis = ( sum([ elem**exponent for elem in abs_xy ])**(1/exponent) )
    
    return m_dis

#test
if __name__ == "__main__" :
   
    calculate_minkowski_distances()

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import sys
import collections
#import math
import unittest

def calculate_minkowski_distances():
    _ = input()
    data = []
    for i in range(2):
        data.append([float(value) for value in input().rstrip().split()])
#    lines = sys.stdin.readlines()[1:]
#    for line in lines:
#        data.append([ float(value) for value in line.rstrip().split() ])

    for exponent in (1, 2, 3, float("inf")):
        print("{0:.6f}".format(minkowski_distance(*data, exponent)))

def minkowski_distance(vector_x, vector_y, exponent):
    abs_xy = [ abs(pair[0] - pair[1]) for pair in zip(vector_x, vector_y) ]

    m_dis = 0
    if exponent == float("inf") :
        m_dis = max(abs_xy)
    elif exponent == 0 :
        m_dis = nan
    else :
        m_dis = ( sum([ elem**exponent for elem in abs_xy ])**(1/exponent) )
    
    return m_dis
'''
def __input_error():
    print("input error")
    return -1

class __TestValueClass(unittest.TestCase):
    def testEqual(self, func, tuples, eff_digit = math.nan, print_success = False):
        self.testFunction(self.assertEqual,func,tuples,eff_digit,print_success)
    
    def testFunction(self,assertfunc,func,tuples,eff_digit,print_success):
        #tuples[index] = ([*arguments of func], compared value)
        for item in tuples:
            try:
                if isinstance(item[0], collections.Iterable):
                    value = func(*item[0])
                else:
                    value = func(item[0])
                
                if math.isnan(eff_digit) :
                    assertfunc(value,item[1])
                else :
                    format_str = "{0:."+str(eff_digit)+"g}"
                    assertfunc(format_str.format(value),format_str.format(item[1]))
                    
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                print("arguments".ljust(swidth)+":",item[0])
                print("compared value".ljust(swidth)+":",item[1])
                print("message".ljust(swidth)+":")
                print(msg)
                sys.exit()
        if print_success :
            print(func.__name__,": succeeded")
'''
#test
if __name__ == "__main__" :

#    test = __TestValueClass()
#    vec_x = [1, 2, 3]
#    vec_y = [2, 0, 4]
#    test.testEqual(minkowski_distance, [([vec_x, vec_y, 1], 4),         ([vec_x, vec_y, 2], 2.449490)], eff_digit = 5)
#    test.testEqual(minkowski_distance, [([vec_x, vec_y, 3], 2.154435),  ([vec_x, vec_y, math.inf], 2)], eff_digit = 5)#, print_success = True)

    
    calculate_minkowski_distances()