Problem:


Score : 300 points

Problem Statement

There are N towns in a coordinate plane. Town i is located at coordinates (x_i, y_i). The distance between Town i and Town j is \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2}.

There are N! possible paths to visit all of these towns once. Let the length of a path be the distance covered when we start at the first town in the path, visit the second, third, \dots, towns, and arrive at the last town (assume that we travel in a straight line from a town to another). Compute the average length of these N! paths.

Constraints

2 \leq N \leq 8

-1000 \leq x_i \leq 1000

-1000 \leq y_i \leq 1000

\left(x_i, y_i\right) \neq \left(x_j, y_j\right) (if i \neq j)

(Added 21:12 JST) All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the average length of the paths.
Your output will be judges as correct when the absolute difference from the judge's output is at most 10^{-6}.

Sample Input 1

3
0 0
1 0
0 1

Sample Output 1

2.2761423749

There are six paths to visit the towns: 1 → 2 → 3, 1 → 3 → 2, 2 → 1 → 3, 2 → 3 → 1, 3 → 1 → 2, and 3 → 2 → 1.

The length of the path 1 → 2 → 3 is \sqrt{\left(0-1\right)^2+\left(0-0\right)^2} + \sqrt{\left(1-0\right)^2+\left(0-1\right)^2} = 1+\sqrt{2}.

By calculating the lengths of the other paths in this way, we see that the average length of all routes is:

\frac{\left(1+\sqrt{2}\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)}{6} = 2.276142...

Sample Input 2

2
-879 981
-866 890

Sample Output 2

91.9238815543

There are two paths to visit the towns: 1 → 2 and 2 → 1. These paths have the same length.

Sample Input 3

8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310

Sample Output 3

7641.9817824387



Sample input:
3
0 0
1 0
0 1


Sample output:
2.2761423749

Submission status: Runtime Error

Solution code:
n=int(input())
p=[list(map(int,input().split()))]
ans=0
den=1
for i in range(n):
  ans+=(p[i][0]**2+p[i][1]**2)**0.5
  den*=i
print(ans/den)

Submission status: Runtime Error

Solution code:
def dist(a, b):
    return ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5

def kaizyou(n):
    if n == 0:
        return 1
    else:
        a = n * kaizyou(n-1)
        return a

def alldist(lst, m):
    if len(lst) == 2:
        return dist(lst[0], lst[1])
    else:
        tmp = lst[m]
        del lst[m]
        for i in range(len(lst)):
            sum = dist(tmp, lst[i]) + alldist(lst, i)
        return sum

N = int(input())
lst = []
judge = 0
for i in range(N):
    lst += [tuple(map(int, input().split()))]
    if N >= 2 and N <= 8 and lst[-1][0] < -1000 or lst[-1][0] > 1000 or lst[-1][1] < -1000 or lst[-1][1] > 1000:
        judge = -1
        break
if judge == 0:
    sum = 0
    for j in range(N):
        sum += alldist(lst, j)
    print(sum / kaizyou(N))

Submission status: Runtime Error

Solution code:
import math
mod = 10**9 + 7
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)
X, Y = map(int,input().split())
if (X+Y) % 3 != 0:
    print(0)
    exit()
n = (2*Y-X)//3
m = (2*X-Y)//3
print(C(n+m,m) % mod)

Submission status: Runtime Error

Solution code:
def kaizyou(n):
    if n == 0:
        return 1
    else:
        a = n * kaizyou(n-1)
        return a
      
def dist(a, b):
    return ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5
  
def alldist(lst, m):
    if len(lst) == 2:
        return dist(lst[0], lst[1])
    else:
        tmp = lst[m]
        del lst[m]
        for i in len(lst):
            sum = dist(tmp, lst[i]) + alldist(lst, i)
        return sum

N = int(input())
lst = []
judge = 0
if N >= 2 and N <= 8:
  for i in range(N):
    lst += [tuple(map(int, input().split()))]
    if lst[-1][0] < -1000 or lst[-1][0] > 1000 or lst[-1][1] < -1000 or lst[-1][1] > 1000:
        judge = -1
        break
  if judge == 0:
    sum = 0
    for i in range(N):
        sum += alldist(lst, i)
    print(sum / kaizyou(N))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
x = np.array([input().split() for _ in range(n)], dtype=np.int)
norm2 = np.sum(x * x, axis=1)
dist = -2. * x @ x.T + norm2
dist = np.sqrt(dist.T + norm2)
print(dist.sum() / (n - 1))

Submission status: Runtime Error

Solution code:
n,*L=map(int,open(0).read().split());r=range(0,2*n,2);print(sum(((L[i]-L[j])**2+(L[i+1]-L[j+1])**2)**.5for i in r for j in r))/n)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
t = []
for i in range(N):
  t.append(list(map(int,input().split())))
at = []
for i in range(N):
    for j in range(N):
        ea = math.sqrt((t[i][0] - t[j][0])**2 + (y[i][1] - y[j][1])**2)
        at.append(ea)
da = 0
for ag in at:
    da += ag
avg = da * math.factorial(N - 1) / math.factorial(N)
print(avg)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
t = []
for i in range(n):
  t.append(list(map(int,input().split())))
at = []
for i in range(N):
    for j in range(N):
        ea = math.sqrt((t[i][0] - t[j][0])**2 + (y[i][1] - y[j][1])**2)
        at.append(ea)
da = 0
for ag in at:
    da += ag
avg = da * math.factorial(N - 1) / math.factorial(N)
print(avg)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
xy = [[0,0] for _ in range(N)]
for a in xy:
    a[0], a[1] = map(int, input().split())
x=xy[:,0]
y=xy[:,1]
at = []
for i in range(N):
    for j in range(N):
        ea = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
        at.append(ea)
da = 0
for ag in at:
    da += ag
avg = da * math.factorial(N - 1) / math.factorial(N)
print(avg)

Submission status: Runtime Error

Solution code:
import itertools
import math
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
ans=0
it=list(itertools.permutations(range(8),8))
for i in it:
    tmpx=l[i[0]][0]
    tmpy=l[i[0]][1]
    tmp=0
    for j in i[1:]:
        tmp+=math.sqrt((tmpx-l[j][0])**2+(tmpy-l[j][1])**2)
        tmpx=l[j][0]
        tmpy=l[j][1]
    ans+=tmp
print(ans/math.factorial(n))

Submission status: Runtime Error

Solution code:
import math
N = int(input())
xy = [[0,0] for _ in range(N)]
for a in xy:
    a[0], a[1] = map(int, input().split())
x=a[0]
y=a[1]
at = []
for i in range(N):
    for j in range(N):
        ea = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
        at.append(ea)
da = 0
for ag in at:
    da += ag
avg = da * math.factorial(N - 1) / math.factorial(N)
print(avg)

Submission status: Runtime Error

Solution code:
# C
N = int(input())
x = [0]*N
y = [0]*N
for i in range(N):
    x[i],y[i] = map(int,input().split())
sum = 0
for i in range(N):
    for j in range(N):
        sum += math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)

ans = sum/N
print(ans)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
xy = [[0, 0] for _ in range(N)]
for a in xy:
    a[0], a[1] = map(int, input().split())
x = a[0]
y = a[1]

at = []
for i in range(N):
    for j in range(N):
        Da = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
        at.append(Da)
da = 0
for ag in at:
    da += ag
avg = da * math.factorial(N - 1) / math.factorial(N)
print(avg)

Submission status: Runtime Error

Solution code:
N=int(input())
for i in range(N):
    x, y = map(int, input().split())
    
count=0
for i in range(N-1):
  for j in range(i+1,N):
    count= count + ((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5

print(count*2/N)

Submission status: Runtime Error

Solution code:
import math
import numpy as np
N = int(input())
xy = [[0, 0] for _ in range(N)]
for a in xy:
    a[0], a[1] = map(int, input().split())
x = a[0]
y = a[1]

da = np.zeros([N, N])

for i in range(N):
    for j in range(N):
        Da = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
        da[i][j] = Da
avg = np.sum(da) * math.factorial(N - 1) / math.factorial(N)
print(avg)

Submission status: Runtime Error

Solution code:
N = int(input())
x = []
y = []
for i in range(N):
    x[i], y[i] = map(int, (input().split( )))

aaa = 0
for i in range(N):
    for k in range(N):
        aaa += ((x[i] - x[k])**2+(y[i] - y[k])**2)**0.5
print(aaa/N)

Submission status: Runtime Error

Solution code:
import math
import numpy as np
N = int(input())
xy = [[0,0] for _ in range(N)]
for a in xy:
    a[0], a[1] = map(int, input().split())
x=a[0]
y=a[1]



da = np.zeros([N, N])

for i in range(N):
    for j in range(N):
        Da = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
        da[i][j] = Da
avg = np.sum(da) * math.factorial(N-1) / math.factorial(N)
print(avg)

Submission status: Runtime Error

Solution code:
import math
import numpy as np
N = int(input())
xy = [[0,0] for _ in range(N)]
for a in xy:
    a[0], a[1] = map(int, input().split())
x=a[0]
y=a[1]

def distance(x, y, i, j):
    d = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
    return d

da = np.zeros([N, N])
for i in range(N):
    for j in range(N):
        Da = distance(x, y, i, j)
        da[i][j] = Da
avg = da.sum() * math.factorial(N-1) / math.factorial(N)
print(avg)

Submission status: Runtime Error

Solution code:
N = int(input())
xy = [[0,0] for _ in range(N)]
for a in xy:
    a[0], a[1] = map(int, input().split())
x=a[0]
y=a[1]
import math
import numpy as np


def distance(x, y, i, j):
    d = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
    return d

da = np.zeros([N, N])
for i in range(N):
    for j in range(N):
        Da = distance(x, y, i, j)
        da[i][j] = Da
avg = da.sum() * math.factorial(N-1) / math.factorial(N)
print(avg)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
from scipy.special import comb

n = int(input())
x = []
y = []
for i in range(n):
    x_i, y_i = map(int, input().split())
    x.append(x_i)
    y.append(y_i)

d = np.zeros((n,n))

s = 0
for j in range(n):
    for i in range(j+1,n):
        #d[j][i] = np.sqrt((x[j]-x[i])**2 + (y[j]-y[i])**2)
        s += np.sqrt((x[j]-x[i])**2 + (y[j]-y[i])**2)

#N = int(math.factorial(n)/2)
#N = int(math.factorial(4)/2)
#N = int(comb(n, 2, exact=True) / 2)
N = n + (n * (n-3) / 2)
#print('N : ', N)
C1 = comb(N, n-1, exact=True)
#print('C1 : ',C1)
C2 = comb(N-1, N - (n-1)-1, exact=True)
#print('C2 : ',C2)
D = C1 - C2
#print('D : ',D)
print(2*D*s/math.factorial(n))

Submission status: Runtime Error

Solution code:
N=int(input())

import itertools
r=0
lista=[input() for a in range(N)]

for lista in itertools.permutations(lista):
    for i in range(N-1):
        r=r+((((int((lista[i+1])[:1]))-int((lista[i])[:1]))**2)+(((int((lista[i+1])[-1:]))-int((lista[i])[-1:]))**2))**(1/2)

import math
print(r/math.factorial(N))

Submission status: Runtime Error

Solution code:
import math
N=int(input())
P = [list(map(int, input().split())) for i in range(N)]

xs=P[0][0]
ys=P[0][1]
for j in range(0,N):
	for i in range(1,N):
  		d =+ math.sqrt(pow((P[i][0]-P[j][0]),(P[i][0]-P[j][0]))+pow((P[i][1]-P[j][1]),(P[i][1]-P[j][1])))
 
print(d/N)

Submission status: Runtime Error

Solution code:
def main():
    # map(int, input().split())
    # l = list(map(int, input().split()))
    N = int(input())
    x = [0]*N
    y = [0]*N
    for i in range(N):
        x[i], y[i] = map(int, input().split())
    d = [[0]*N for i in range(N)]
    for i in range(N):
        for j in range(N):
            d[i][j] = math.sqrt((x[i] - x[j])**2 + (y[i]-y[j])**2)
    num_sum = math.factorial(N)

    def DFS(cur, i, j, P):
        P |= (1 << j)
        print(bin(P))
        print(i, j)
        if cur == N:
            return d[i][j]
        elif cur == 1:
            return sum([DFS(cur+1, j, k, P) for k in range(N) if (1 << (k)) & P == 0])
        else:
            return sum([(d[i][j] + DFS(cur+1, j, k, P)) for k in range(N) if (1 << (k)) & P == 0])

    print(sum([DFS(1, -1, i, 0) for i in range(N)]) / num_sum)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10**6)
input=sys.stdin.readline

def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p


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

if (X+Y)%3 != 0:
    print(0)
    sys.exit()

val = [X,Y]
val_min = min(val)

val_min_sho = int(val_min/3)

X_henkan = X - 3*val_min_sho
Y_henkan = Y - 3*val_min_sho
if (X_henkan == 0 and Y_henkan == 0):
    n = (val_min_sho)*2
    n_2 = int(n/2)
    print(comb(n,n_2,10**9+7))
elif Y_henkan != 0 and (X_henkan / Y_henkan == 2):
    n = (val_min_sho)*2 + Y_henkan
    n_2 = val_min_sho
    print(comb(n,n_2,10**9+7))
elif X_henkan != 0 and (Y_henkan / X_henkan == 2):
    n = (val_min_sho)*2 + X_henkan
    n_2 = val_min_sho
    print(comb(n,n_2,10**9+7))
else:
    print(0)

Submission status: Runtime Error

Solution code:
N = int(input())
x = []
y = []
for i in range(N):
    x[i], y[i] = map(int, (input().split(" ")))
roop = []
import itertools
for i in itertools.permutations(range(N), r=2):
    roop.append(i)
aaa = 0
for i in roop:
    aaa += ((x[i[0]] - x[i[1]])**2+(y[i[0]] - y[i[1]])**2)**0.5
print(aaa/N)

Submission status: Runtime Error

Solution code:
N=int(input())

x = [0 for i in range(M)]
y = [0 for i in range(M)]

for i in range(N):
    x[i], y[i]= map(int, input().split())
import math
import numpy as np


def distance(x, y, i, j):
    d = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
    return d

da = np.zeros([N, N])
for i in range(N):
    for j in range(N):
        Da = distance(x, y, i, j)
        da[i][j] = Da
avg = da.sum() * math.factorial(N-1) / math.factorial(N)
print(avg)

Submission status: Runtime Error

Solution code:
N = int(input())
x = []
y = []
for i in range(N):
    x[i], y[i] = map(int, (input().split( )))
roop = []
import itertools
for i in itertools.permutations(range(N), r=2):
    roop.append(i)
aaa = 0
for i in roop:
    aaa += ((x[i[0]] - x[i[1]])**2+(y[i[0]] - y[i[1]])**2)**0.5
print(aaa/N)

Submission status: Runtime Error

Solution code:
N=int(input())

x = [0 for i in range(M)]
y = [0 for i in range(M)]

for i in range(N):
    X[i], Y[i], Z[i] = map(int, input().split())
import math
import numpy as np


def distance(x, y, i, j):
    d = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
    return d

da = np.zeros([N, N])
for i in range(N):
    for j in range(N):
        Da = distance(x, y, i, j)
        da[i][j] = Da
avg = da.sum() * math.factorial(N-1) / math.factorial(N)
print(avg)

Submission status: Runtime Error

Solution code:
import sys
import math
s = []
length = int(input()[0])
a = [list(map(int, input().split())) for i in range(1, length+1)]

def calcDistance(c1, c2):
  return math.sqrt((c2[0]-c1[0]) + (c2[1]-c2[0]))
distance = 0

for i, value in enumerate(a):
  if i == 0: continue
  distance += calcDistance(a[i-1], value)
print(distance)

Submission status: Runtime Error

Solution code:
import math
N=int(input())
P = [list(map(int, input().split())) for i in range(N)]

xs=P[0][0]
ys=P[0][1]
for i in range(1,N):
  d =+ math.sqrt(pow((P[i][0]-xs),(P[i][0]-xs))+pow((P[i][1]-ys),(P[i][1]-ys)))
 
print(d/N)

Submission status: Runtime Error

Solution code:
N=int(input())

import itertools
r=0
lista=[input() for a in range(N)]

for lista in itertools.permutations(lista):
    for i in range(N-1):
        r=r+((((int((lista[i+1])[:1]))-int((lista[i])[:1]))**2)+(((int((lista[i+1])[-1:]))-int((lista[i])[-1:]))**2))**(1/2)

import math
print(r/math.factorial(N)

Submission status: Runtime Error

Solution code:
import math
import itertools

N = int(input())
x = [0] * N
y = [0] * N

for n in range(N):
    x[n], y[n] = map(int, input().split())


# print(x)
# print(y)

def root(xi, yi, xj, yj):
    return math.sqrt((xi - xj) ** 2 + (yi - yj) **2)

# print(root(1, 0, 0, 0))
# print(root(0, 0, 0, 1))


# a = root(4, 3, 6, 2)
# print(a)



# x1 = (-406, 10)
# x2 = ( 512, 859)
# x3 = ( 494, 362)
# x4 = (-955, -475)
# x5 = ( 128, 553)
# x6 = (-986, -885)
# x7 = ( 763, 77)
# x8 = ( 449, 310)
#

l = x +y
# l = [x1, x2, x3, x4, x5, x6, x7, x8]
m = 0
for i in itertools.permutations(l, len(l)):
    k = 0
    for j in range(len(i) -1):
        k += root(*(i[j] + i[j+1]))
    m += k
print(m/math.factorial(len(l)))

Submission status: Runtime Error

Solution code:
from itertools import permutations
from itertools import combinations
import math
from scipy.special import comb

n = int(input())
l = []
d = []
result = 0
for i in range(n):
    l.append(list(map(int, input().split())))
for con in list(combinations(l,2)):
    d.append(math.sqrt((con[0][0] - con[1][0]) ** 2 + (con[0][1] - con[1][1]) ** 2))
for j in list(permutations(d,n-1))):
    result = sum(j)
print(j/math.factorial(n))

Submission status: Runtime Error

Solution code:

N = int(input())
P = [list(map(int,input().split())) for i in range(N)]

import itertools
import math
order = range(N)
sum_list=[]
for v in itertools.permutations(order):
    distance =[]
    for i in range(N):
          distance.append(math.sqrt((P[v[i+1]][0]-P[v[i]][0])**2+(P[v[i+1]][1]-P[v[i]][1])**2))
    sum_list.append(sum(distance))
ave = sum(sum_list)/len(sum_list)
print(ave)

Submission status: Runtime Error

Solution code:
def kyori(a,b,c,d):
    x = (int(a) - int(b)) ** 0.5
    y = (int(c) - int(d)) ** 0.5
    z = x + y
    return z

n = int(input())
city_list = [0]*n
total_kyori = 0.0

for i in range(n):
  city_list[i] = input().split()

for j in range(n):
  for k in range(n):
    total_kyori += kyori(j[0], k[0], j[1], k[1])

print(total_kyori/n*(n-1))

Submission status: Runtime Error

Solution code:
N=int(input())
P = [list(map(int, input().split())) for i in range(N)]

xs=P[0][0]
ys=P[0][1]
for i in range(1,N):
  d += math.sqrt(pow((P[i][0]-xs),(P[i][0]-xs))+pow((P[i][1]-ys),(P[i][1]-ys)))
 
print(d)

Submission status: Runtime Error

Solution code:
N = int(input())
P = [list(map(int,input().split())) for i in range(N)]

import itertools
import math
order = range(N)
sum_list=[]
for v in itertools.permutations(order):
    distance =[]
    for i in range(N):
          distance.append(math.sqrt((P[v[i+1]][0]-P[v[i]][0])**2+(P[v[i+1]][1]-P[v[i]][1])**2))
    sum_list.append(sum(distance))
ave = sum(sum_list)/len(sum_list)
return(ave)

Submission status: Runtime Error

Solution code:
N = int(input())
x = []
y = []
for i in range(N):
    x[i], y[i] = map(int, (input().split()))
roop = []
import itertools
for i in itertools.permutations(range(N), r=2):
    roop.append(i)
aaa = 0
for i in roop:
    aaa += ((x[i[0]] - x[i[1]])**2+(y[i[0]] - y[i[1]])**2)**0.5
print(aaa/N)

Submission status: Runtime Error

Solution code:
import math
import itertools

N = int(input())
x = [0] * N
y = [0] * N

for n in range(N):
    x[n], y[n] = map(int, input().split())


def root(xi, yi, xj, yj):
    return math.sqrt((xi - xj) ** 2 + (yi - yj) **2)

# print(root(1, 0, 0, 0))
# print(root(0, 0, 0, 1))


# a = root(4, 3, 6, 2)
# print(a)



# x1 = (-406, 10)
# x2 = ( 512, 859)
# x3 = ( 494, 362)
# x4 = (-955, -475)
# x5 = ( 128, 553)
# x6 = (-986, -885)
# x7 = ( 763, 77)
# x8 = ( 449, 310)
#

# l = [x1, x2, x3, x4, x5, x6, x7, x8]
m = 0
for i in itertools.permutations(l, len(l)):
    k = 0
    for j in range(len(i) -1):
        k += root(*(i[j] + i[j+1]))
    m += k
print(m/math.factorial(len(l)))

Submission status: Runtime Error

Solution code:
N=int(input())
x,y=map(int,input().split())
import math
import numpy as np


def distance(x, y, i, j):
    d = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
    return d

da = np.zeros([N, N])
for i in range(N):
    for j in range(N):
        Da = distance(x, y, i, j)
        da[i][j] = Da
avg = da.sum() * math.factorial(N-1) / math.factorial(N)
print(avg)

Submission status: Runtime Error

Solution code:
import itertools

if __name__ == '__main__':

    n = int(input())
    town =[input() for i in range(n)]

    p = [i for i in range(n)]
  

    p_list = list(itertools.permutations(p))

    total = 0
    for i in range(len(p_list)):
        sum = 0
    
        for j in range(n-1):
            x1,y1 = int(town[p_list[i][j]][0]), int(town[p_list[i][j]][2])
            x2,y2 = int(town[p_list[i][j+1]][0]), int(town[p_list[i][j+1]][2])
    
            sum = sum + ((x2-x1)**2+(y2-y1)**2)**0.5
       

        total = total + sum
       

    
    print(total/float(len(p_list)))

Submission status: Runtime Error

Solution code:
import sys
import math
import itertools

n = int(sys.stdin.readline())
total = math.factorial(n)
res = 0
acc = 0
lines = []

for i in range(n):
    lines.append(sys.stdin.readline().rstrip('\n'))
for y in itertools.combinations(lines, 2):
    acc += ((int(y[0][0]) - int(y[1][0]))**2) + \
        ((int(y[0][1]) - int(y[1][1]))**2)
    acc += math.sqrt(acc)

res = acc/total
print(res)

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools
from statistics import mean
n = int(input())
lis = [list(map(int, input().split())) for i in range(n)]
dislis = []
for i in range(n):
    dislis.append([])
    for j in range(n):
        dislis[i].append(np.sqrt((lis[i][0]-lis[j][0])**2 + (lis[i][1]-lis[j][1])**2))

lenlis = []
cnt = 0
for v in itertools.permutations(range(n+1)[1:], n):
    cnt += 1
    lenlis.append([])
    for i in range(len(v)):
        if i != len(v)-2:
            lenlis[cnt-1].append(dislis[v[i-1]-1][v[i]-1])
anslis = []
cntcnt = 0
for i in lenlis:
    anslis.append(sum(lenlis[cntcnt]))
    cntcnt += 1
print(mean(anslis))

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools
from statistics import mean
n = int(input())
lis = [list(map(int, input().split())) for i in range(n)]
dislis = []
for i in range(n):
    dislis.append([])
    for j in range(n):
        dislis[i].append(np.sqrt((lis[i][0]-lis[j][0])**2 + (lis[i][1]-lis[j][1])**2))

lenlis = []
cnt = 0
for v in itertools.permutations(range(n+1)[1:], n):
    cnt += 1
    lenlis.append([])
    for i in range(len(v)):
        if i != len(v)-2:
            lenlis[cnt-1].append(dislis[v[i-1]-1][v[i]-1])
# for i in dislis:
#     print(i)
anslis = []
cntcnt = 0
for i in lenlis:
    anslis.append(sum(lenlis[cntcnt]))
    cntcnt += 1
print(mean(anslis))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import math
sys.setrecursionlimit(100000000)
N = int(input())

points = [0]*N
for i in range(N):
    x, y = map(int, input().split())
    points[i] = [x, y]

lengthes = take_lengthes(points)
print(lengthes.mean() )


#get lengthe of two points
def get_interval(p, q):
    interval = 0
    for i in range(len(p)):
        interval += (p[i] - q[i])*(p[i] - q[i])

    return math.sqrt(interval)


#get sum of lengthes
def take_lengthes(points):
    if len(points)==2:
        return np.array(get_interval(points[0], points[1]))

    lengthes_exclude_1 = take_lengthes(points[0:])
    lengthes = np.array([])
    for i in range(1,len(points)):
        lengthes = np.append(lengthes, lengthes_exclude_1 + get_interval(points[0], points[i]))

    return lengthes

Submission status: Runtime Error

Solution code:
import itertools

if __name__ == '__main__':

    n = int(input())
    town =[input() for i in range(n)]

    p = [i for i in range(n)]
  

    p_list = list(itertools.permutations(p))

    distance = []

    total = 0
    for i in range(len(p_list)):
        sum = 0
    
        for j in range(n-1):
            x1,y1 = int(town[p_list[i][j]][0]), int(town[p_list[i][j]][2])
            x2,y2 = int(town[p_list[i][j+1]][0]), int(town[p_list[i][j+1]][2])
    
            sum = sum + ((x2-x1)**2+(y2-y1)**2)**0.5
       

        total = total + sum
       
	print(total/len(p_list))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import math
sys.setrecursionlimit(100000)
N = int(input())

points = [0]*N
for i in range(N):
    x, y = map(int, input().split())
    points[i] = [x, y]

lengthes = take_lengthes(points)
print(lengthes.mean() )


#get lengthe of two points
def get_interval(p, q):
    interval = 0
    for i in range(len(p)):
        interval += (p[i] - q[i])*(p[i] - q[i])

    return math.sqrt(interval)


#get sum of lengthes
def take_lengthes(points):
    if len(points)==2:
        return np.array(get_interval(points[0], points[1]))

    lengthes_exclude_1 = take_lengthes(points[0:])
    lengthes = np.array([])
    for i in range(1,len(points)):
        lengthes = np.append(lengthes, lengthes_exclude_1 + get_interval(points[0], points[i]))

    return lengthes

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import math

N = int(input())

points = [0]*N
for i in range(N):
    x, y = map(int, input().split())
    points[i] = [x, y]

lengthes = take_lengthes(points)
print(lengthes.mean() )


#get lengthe of two points
def get_interval(p, q):
    interval = 0
    for i in range(len(p)):
        interval += (p[i] - q[i])*(p[i] - q[i])

    return math.sqrt(interval)


#get sum of lengthes
def take_lengthes(points):
    if len(points)==2:
        return np.array(get_interval(points[0], points[1]))

    lengthes_exclude_1 = take_lengthes(points[0:])
    lengthes = np.array([])
    for i in range(1,len(points)):
        lengthes = np.append(lengthes, lengthes_exclude_1 + get_interval(points[0], points[i]))

    return lengthes

Submission status: Runtime Error

Solution code:
import sys
import math
from statistics import mean
from functools import reduce, lru_cache
from itertools import permutations


@lru_cache()
def distance(p1, p2):
    return math.sqrt(sum([(a - b) ** 2 for a, b in zip(p1, p2)]))


def distances(arr):
    return [distance(arr[i], arr[i+1]) for i in range(len(arr)-1)]


def main(n: int, points: list):
    ret = []
    for x in permutations(points):
        ret.append(sum(distances(x)))

    print(mean(ret))


if __name__ == '__main__':
    a = []
    while True:
        l = input()
        if l:
            a.append(l)
        else:
            break

    args = '\n'.join(a)
    points = [s.split(' ') for s in a[1:]]

    main(
        int(a[0]),
        [(int(p[0]), int(p[1])) for p in points]
    )

Submission status: Runtime Error

Solution code:
from math import sqrt
from math import factorial
n = int(input())
t = []
for i in range(n):
  t.append(list(map(int,input().split())))
l = [[0]*n for j in range(n)]
for k in range(n):
  for m in range(n):
    if k != m:
      d = sqrt((t[k][0]-t[m][0])**2+(t[k][1]-t[m][1])**2)
      l[k][m] = d
print(int(sum(l)*factorial(n-2)*2/n))

Submission status: Runtime Error

Solution code:
import sys
import math
a = []
def calcDistance(c1, c2):
  return math.sqrt((c2[0]-c1[0]) + (c2[1]^c1[1]))
a = [l.split() for l in sys.stdin]
distance = 0
for i in range(a):
  if i == 0: continue
  distance += calcDistance(a[i], a[i-1])
print(distance)

Submission status: Runtime Error

Solution code:
import sys
import math
from statistics import mean
from functools import reduce, lru_cache
from itertools import permutations


@lru_cache()
def distance(p1, p2):
    return math.sqrt(sum([(a - b) ** 2 for a, b in zip(p1, p2)]))


def distances(arr):
    return [distance(arr[i], arr[i+1]) for i in range(len(arr)-1)]


def main(n: int, points: list):
    ret = []
    for x in permutations(points):
        ret.append(mean(distances(x)))

    print(mean(ret))


if __name__ == '__main__':
    a = []
    while True:
        l = input()
        if l:
            a.append(l)
        else:
            break

    args = '\n'.join(a)
    points = [s.split(' ') for s in a[1:]]

    main(
        int(a[0]),
        [(int(p[0]), int(p[1])) for p in points]
    )

Submission status: Runtime Error

Solution code:
N = int(input())
p = list()
l = 0

for n in range(0, N):
  p.append(list(map(int, input().split())))

for i in range(0, len(p)):
  for j in range(i+1, len(p)):
    l += math.sqrt((p[i][0] - p[j][0])**2 + (p[i][1] - p[j][1])**2)

n = math.factorial(N)
m = 2 * math.factorial(N-1)
print(l * m / n)

Submission status: Runtime Error

Solution code:
import math
from itertools import combinations, permutations

def dist(x1, y1, x2, y2):
    return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** .5


n = int(input())
xy = [[int(i) for i in input().split()] for _ in range(n)]
edges = list(range(n))
memo = {}
res = 0
for p in permutations(edges):
    for i, a in enumerate(p[1:], start=1):
        b = p[i - 1]
        if (a, b) in memo:
            res += memo[a, b]
        else:
            d = dist(*xy[a], *xy[b])
            memo[a, b] = d
            memo[b, a] = d
            res += d
print(res / math.factorial(n))

Submission status: Runtime Error

Solution code:
kk

Submission status: Runtime Error

Solution code:
import math
import numpy as np
a = int(input())
t = [list(map(int, input().split())) for i in range(a)]
x = 0
for i in range(a):
    for j in range(a):
        x = x + np.sqrt((t[i][0]-t[j][0])**2 +(t[i][1]-t[j][1])**2)
print(x*math.factorial(a-1)/(math.factorial(a)))

Submission status: Runtime Error

Solution code:
import math

n=int(input())
listx=[]
listy=[]

for i in range(n):
  x,y = map(int,input().split())
  listx.append(x)
  listy.append(y)

%print(listx)
%print(listy)
listl=[]
if n==2:
	ans=((listx[1]-listx[0])**2+(listy[1]-listy[0])**2)**0.5



else:
	for i in range(n-1):
		for j in range(i+1,n):
			l=((listx[i]-listx[j])**2+(listy[i]-listy[j])**2)**0.5
			listl.append(l)
	ll=sum(listl)	
	ans=2*ll/n

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
list_1 = []
for i in range(N):
    list_1.append(list(map(int, input().split())))

m = 0
for list_i in list_1:
    for list_j in list_1:
        if list_i != list_j:
            d = math.sqrt((list_j[0]-list_i[0])**2 + (list_j[1]-list_i[1])**2)
            m += d

average = m / N
print(average)

Submission status: Runtime Error

Solution code:
import numpy as np
N=int(input())
a=[0]*N
b=[0]*N
s=0
for i in range(N):
    a[i], b[i] = map(int, input().split())
for i in range(N):
  for j in range(j):
    vec=[a[i]-a[j] b[i]-b[j]]
    s+=sqrt(np.linalg.norm(vec))
print(s/N)

Submission status: Runtime Error

Solution code:
N = int(input())
x = []
y = []
for i in range(N):
    x[i], y[i] = map(int, (input().split()))

roop = []
import itertools

for i in itertools.permutations(range(N)):
    roop.append(i)
aaa = 0
for i in roop:
    for l in i:
        aaa += ((x[l] - x[l+1])**2+(y[l] - y[l+1])**2)**0.5
print(aaa/N)

Submission status: Runtime Error

Solution code:
import sys
import itertools
import numpy as np

lines = sys.stdin.readlines()

N = int(lines[0].rstrip())
perms = list(itertools.permutations(range(N)))
combs = list(itertools.combinations(range(N), 2))

arr_2d = np.zeros((N,2))
arr_dist_memo = np.zeros((len(combs),len(combs)))
arr_dist_ave = np.zeros(len(perms))

for i, line in enumerate(lines[1:]):
    x, y = map(int,line.split(' '))
    arr_2d[i, 0] = x
    arr_2d[i, 1] = y

for i,j in combs:
    arr_dist_memo[i, j] = np.linalg.norm(arr_2d[i] - arr_2d[j])

for index, l in enumerate(perms):
    for i, j  in zip(range(N-1), range(1, N)):
        arr_dist_ave[index] += arr_dist_memo[l[i],l[j]]

print(np.mean(arr_dist_ave)*2)

Submission status: Runtime Error

Solution code:
print("2.2761423749)

Submission status: Runtime Error

Solution code:
N=int(input())
a=[input() for i in range(N)]
b=list(a)
xi,yi=map(int,b.split())
print(xi,yi)

Submission status: Runtime Error

Solution code:
import math
N=int(input())
x=[]
y=[]
M=0
for i in range(0,N):
    F=input()
    [v,s]=list(map(int,F.split(' ')))
    x.append(v)
    y.append(s)
def dis(x,y,x2,y2):
    return math.sqrt((x-x2)**2+(y-y2)**2)
for i in N:
    for j in range(0,N):
        M=M+dis(x[i],y[i],x[j],y[j])
print(M/math.factorial(N))