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

Solution code:
import itertools
import math
import numpy as np

def min_start(a, b):
    if a < b:
        return b, a
    return a, b

def main():
    N = int(input())
    point = list()
    length = list()
    for _ in range(N):
        point.append([int(x) for x in input().split()])
    point = np.array(point)

    for a in range(N):
        temp = list()
        for b in range(a, N):
            temp.append(np.linalg.norm(point[b]-point[a]))
        length.append(temp.copy())
    ans = 0
    for route in itertools.permutations([x for x in range(N)]):
        temp = 0
        for i in range(1, N):
            a = route[i - i]
            b = route[i]
            if a > b:
                ans += length[b][a-b]
            else:
                ans += length[a][b-a]
            
    print(ans / math.factorial(N))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
import itertools
n = int(input())
pos_lis = []
for i in range(n):
  x, y = map(int,input().split())
  pos_lis.append({'pos':(x,y)})
for k in range(n-1):
  x1 = pos_lis[k]['pos'][0]
  y1 = pos_lis[k]['pos'][1]
  for l in range(k+1,n):
    x2 = pos_lis[l]['pos'][0]
    y2 = pos_lis[l]['pos'][1]
    leng = math.sqrt((x1-x2)**2 + (y1-y2)**2)
    pos_lis[k][l] = leng
    pos_lis[l][k] = leng
numbers = list(range(n))
p = list(itertools.permutations(numbers, n))
len_sum = []
for j in range(len(p)):
	len_sum.append(sum([pos_lis[p[j][t]][p[j][t+1]] for t in range(n-1)]))
ans = sum(len_sum) / len(p)
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math
N = int(input())
S = [list(map(int, input().split())) for i in range(N)]
perm = list(itertools.permutations([i for i in range(1, N + 1)]))
#perm = [list(perm[i]) for i in range(perm)]
sum_d = 0
for i in range(len(perm)):
  #perm[i] = list(perm[i])
  for j in range(1, N):
    #print(i, end="")
    #print(math.sqrt((S[perm[i][j] - 1][0] - S[perm[i][j - 1] - 1][0]) ** 2 + (S[perm[i][j] - 1][1] - S[perm[i][j - 1] - 1][1]) ** 2))
    sum_d += math.sqrt((S[perm[i][j] - 1][0] - S[perm[i][j - 1] - 1][0]) ** 2 + (S[perm[i][j] - 1][1] - S[perm[i][j - 1] - 1][1]) ** 2)

print(sum_d / len(perm))

Submission status: Accepted

Solution code:
import math
import itertools
def r(retu,N):#組み合わせ,数
    first=retu[0]
    length=0
    n=0
    for i in retu:
        if n==0:
            n+=1
            continue
        length+=math.sqrt((i[0]-first[0])**2+(i[1]-first[1])**2)
        first=i

    #length=math.sqrt((back[0]-front[0])**2+(back[1]-front[1])**2)
    return length

N=int(input())
S=[[int(i) for i in input().split()] for i in range(N)]
K=[]
kumi=0
for i in itertools.permutations(S):
    length=r(i,N)
    K.append(length)
    kumi+=1

print(sum(K)/kumi)

Submission status: Accepted

Solution code:
n=int(input())
x=[]
y=[]
t=float(0)
m=int(0)
for i in range(n):
    a, b = map(int, input().split())
    x.append(a)
    y.append(b)

for i in range(n-1):

    for k in range(i+1, n):
        t += (((x[i]-x[k])**2) + ((y[i]-y[k])**2))**(1/2)
        m +=1


ave=float(t/m*(n-1))

print('{:.9g}'.format(ave))

Submission status: Accepted

Solution code:
import math
n = int(input())
y = []
for i in range(n):
    a = list(map(int, input().split()))
    y.append(a)

q = 1
for j in range(n):
    q *= (j+1)

ans = 0
for k in range(n):
    for l in range(n):
        c = (y[k][0] - y[l][0]) ** 2 + (y[k][1] - y[l][1]) ** 2
        d = math.sqrt(c)
        ans += d


print(ans / n)

Submission status: Accepted

Solution code:
import math

def distance(a, b):
  return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)

n = int(input())
towns = []
for i in range(n):
  towns.append(list(map(int, input().split())))

distanceSum = 0
for i in range(len(towns)):
  for j in range(i + 1, len(towns)):
    distanceSum += distance(towns[i], towns[j])

print(distanceSum * (math.factorial(n- 1) * 2) / math.factorial(n))

Submission status: Accepted

Solution code:
import math


def averageLength():
    def calc(a, b):
        return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)

    N = int(input())
    x = []
    for _ in range(N):
        x.append(list(map(int, input().split())))

    d = 0
    for i in range(N):
        for j in range(i, N):
            d += calc(x[i], x[j])

    N_fac = math.factorial(N)
    a = 0 if N < 2 else math.factorial(N-2) * (N-1) * 2

    print(d * a / N_fac)


averageLength()

Submission status: Accepted

Solution code:
import itertools

def calc_dist(x, y):
	return ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) ** 0.5

n = int(input())
cities = [list(map(int, input().split())) for _ in range(n)]

d = {}

for i in range(n):
	for j in range(n):
		d[(i, j)] = calc_dist(cities[i], cities[j])

ans = 0
cnt = 0
for x in itertools.permutations(range(n)):
	cnt += 1
	for i in range(n - 1):
		ans += calc_dist(cities[x[i + 1]], cities[x[i]])
	#print(x)
print(ans / cnt)

Submission status: Accepted

Solution code:
N = int(input())
inputbox =[0]*N
X = [0]*N
Y = [0]*N
for i in range(0,N):
    inputbox[i] = input()

for j in range(N):
    a = inputbox[j]
    b = a.split()
    X[j]=float(b[0])
    Y[j]=float(b[1])

sum = 0
for s in range (N):
    for t in range (N):
        kyori = ((X[s]-X[t])**2+(Y[s]-Y[t])**2)**(1/2)
        sum = sum + kyori
ans = sum/N
print(ans)

Submission status: Accepted

Solution code:
def kai(a):
    if a == 1:
        return 1
    else:
        return a*kai(a-1)

def L(i, j, x, y):
    return ((x[i] - x[j])**2 + (y[i] - y[j])**2)**0.5

N  = int(input())
x = [0]*N
y = [0]*N
k = kai(N)
l = 0
for n in range(N):
    x[n], y[n] = map(int, input().split())

for X in range(N):
    for Y in range(N):
        if X <= Y:
            continue
        else:
            l += L(X, Y, x, y)
           

bi = ((N - 1) * k)/((N * (N - 1))/2)



print((l * bi)/k)

Submission status: Accepted

Solution code:
import itertools
import math

n = int(input())
xy = []
for _ in range(n):
    a = input().split()
    a[0] = int(a[0])
    a[1] = int(a[1])
    xy.append((a))

res = 0
for i in list(itertools.permutations(list(range(n)))):
    for j in range(len(i)-1):
        x1 = xy[i[j]][0]
        y1 = xy[i[j]][1]
        x2 = xy[i[j+1]][0]
        y2 = xy[i[j+1]][1]
        res += math.sqrt((x1-x2)**2 + (y1-y2)**2)

res /= math.factorial(n)

print(res)

Submission status: Accepted

Solution code:
import math

n = int(input())
town = [[0, 0]] * n
ans = 0
keiro = 0
keiro_count = 0

for i in range(n):
  x, y = map(int, input().split(' '))
  town[i] = [x, y]
# print(n)
# print(town)

for i in range(n):
  for j in range(i+1, n):
    town1 = town[i]
    town2 = town[j]
    x = (town2[0] - town1[0]) ** 2
    y = (town2[1] - town1[1]) ** 2
    d = math.sqrt( x + y )
    # print(d)
    keiro += (d * 2) * (n - 1)
    keiro_count += 2

# print('======================')
# print(keiro)
# print(keiro_count)

ans = keiro / keiro_count
print(round(ans, 10))

Submission status: Accepted

Solution code:
import itertools

n=int(input())
xlist=[]
ylist=[]
z=[]
kyori=0
for i in range(n):
  a=[]
  a=list(map(int,input().split()))
  xlist.append(a[0])
  ylist.append(a[1])
  z.append(i)
for v in itertools.permutations(z):
  for i in range(1,n):
    kyori += ((xlist[v[i-1]]-xlist[v[i]])**2+(ylist[v[i-1]]-ylist[v[i]])**2)**0.5
print(kyori/len(list(itertools.permutations(z))))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(int(1e6))

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

import itertools
seq = list(itertools.permutations(range(N)))
ds = [0] * N
route_d = [0] * len(seq)
dists = {}
k = 0
for route in seq:
    d = 0
    i = route[0]
    for j in route[1:]:
        vec = (i, j) if (i < j) else (j, i)
        if not (vec in dists):
            import math
            dx = xy[j][0] - xy[i][0]
            dy = xy[j][1] - xy[i][1]
            dists[vec] = math.sqrt(dx**2 + dy**2)
        d += dists[vec]
        i = j
    route_d[k] = d
    k += 1

ans = sum(route_d) / len(route_d)

print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
point = list()
for i in range(N):
	point.append(list(map(int,input().split())))

target = list(itertools.permutations(point))
distance = 0
# 全てのパターンを調べる
for i in range(len(target)):
	# 距離を求める	
	for j in range(len(target[i])-1):
		cul = (target[i][j][0] - target[i][j+1][0])**2 + (target[i][j][1] - target[i][j+1][1])**2
		distance += math.sqrt(cul)
print(distance/len(target))

Submission status: Accepted

Solution code:
import math

l = []
n = int(input())
for i in range(n):
  x1, x2 = map(int,input().split())
  l.append([x1, x2])

r = []
for i in range(n):
  for j in range(i+1,n):
    r_ = math.sqrt((l[i][0]-l[j][0])**2 + (l[i][1]-l[j][1])**2)
    r.append(r_)

f = math.factorial(n-1)
f_ = math.factorial(n)
sum = 2 * f * sum(r)
print(sum/f_)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import sqrt, factorial

N = int(input())
towns = [tuple([int(i) for i in input().split()]) for _ in range(N)]

total = 0

for root in permutations(towns):
    ri = iter(root)
    pre = next(ri)
    for t in ri:
        total += sqrt(sum((t[i] - pre[i])**2 for i in (0, 1)))
        pre = t

print(total/factorial(N))

Submission status: Accepted

Solution code:
import itertools
import math
n = int(input())
x1 = []
y1 = []
for i in range(n):
    x, y = map(int, input().split())
    x1.append(x)
    y1.append(y)
l = [i for i in range(n)]
l = list(itertools.permutations(l))
ans = []
for i in l:
    c = 0
    for x in range(1, len(i)):
        x2 = i[x-1]
        x3 = i[x]
        c += math.sqrt((x1[x2] - x1[x3])**2 + (y1[x2] - y1[x3]) ** 2) 
    ans.append(c)
print(sum(ans)*2/(len(l)*2))

Submission status: Accepted

Solution code:
n = int(input())
xy_lis = []
for i in range(n):
    xy_lis.append(list(map(int, input().split())))
dis_sum = 0
for i in range(n):
    for j in range(i):
        dis_sum += ((xy_lis[i][0] - xy_lis[j][0]) ** 2 + (xy_lis[i][1] - xy_lis[j][1]) ** 2) ** (1 / 2)
print(dis_sum * 2 / n)

Submission status: Accepted

Solution code:
import math
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
ans = 0
for i in range(N):
    for j in range(N):
        if i != j:
            a = math.pow(xy[j][0] - xy[i][0],2) + math.pow(xy[j][1] - xy[i][1],2)
            ans += math.sqrt(a)

print(ans/N)

Submission status: Accepted

Solution code:
import math

n = input()
n = int(n)

points = []

for i in range(int(n)):
  p = input().split(" ")
  points.append((int(p[0]),int(p[1])))
  
sum = 0
for i in range(n):
  for j in range(n):
    dx = points[i][0] - points[j][0]
    dy = points[i][1] - points[j][1]
    sum += math.sqrt(dx*dx+dy*dy)
   
print(sum/( n ))

Submission status: Accepted

Solution code:
import math

N = int(input())
x = list()
for i in range(N):
	x.append(list(map(int, input().split())))

ans = 0
cities = [x for x in range(N)]
for i in range(N):
	tmp = 0
	cities.remove(i)
	for j in cities:
		tmp += math.sqrt((x[i][0]-x[j][0])**2+(x[i][1]-x[j][1])**2) * math.factorial(N-1) * 2
	ans += tmp
	
print(ans/math.factorial(N))

Submission status: Accepted

Solution code:
import math
n = int(input())
coo = []
sum = 0
con = 0
for i in range(n):
    coo.append(tuple(map(int, input().split())))

for i in range(n-1):
    for j in range(i+1, n):
        sum += math.sqrt((coo[i][0]-coo[j][0])**2+(coo[i][1]-coo[j][1])**2)
        con += 1
fact = math.factorial(n)
num = fact*(n-1)/con
print(sum*num/fact)

Submission status: Accepted

Solution code:
import math

n=int(input())
L=[list(map(int,input().split())) for _ in range(n)]

c=0
for i in range(n):
    for j in range(i+1,n):
        c+=math.sqrt((L[i][0]-L[j][0])**2+(L[i][1]-L[j][1])**2)

print(c/n*2)

Submission status: Accepted

Solution code:
import math
N = int(input())
data =[]
point = 0
for i in range(N):
    data.append([int(j) for j in input().split()])
#print(data)
    
for i in range(N):
    for j in range(i+1,N):
        point+= math.sqrt((data[i][0]-data[j][0])**2 + (data[i][1]-data[j][1])**2)
        #print(point)

print(point*2/N)

Submission status: Accepted

Solution code:
import math
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
ans=0

for i in range(n):
    for j in range(i+1,n):
        ans+=math.sqrt((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)
ans=(ans/n)*2
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
lst = []
count = 0

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

for i in range(n):
    for j in range(i+1,n):
        count += np.linalg.norm(lst[i]-lst[j])

print(count*2/n)

Submission status: Accepted

Solution code:
import itertools
import math
n = int(input())
x = []
y = []
for i in range(n):
  sam1, sam2= input().split()
  x.append(int(sam1))
  y.append(int(sam2))
    
a = list(itertools.permutations(range(n)))
kyori = 0
for i in a:
  for j in range(n-1):
    p = int(i[j])
    q = int(i[j+1])
    dx = x[p] - x[q]
    dy = y[p] - y[q]
    tmp = math.sqrt(dx * dx + dy * dy)
    kyori = kyori + tmp
print(kyori / len(a))

Submission status: Accepted

Solution code:
# C - Average Length
import math
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]

tmp = 0
for i in range(N):
    for j in range(N):
        if i == j:
            pass
        else:
            tmp += (((A[i][0]-A[j][0])**2)+((A[i][1]-A[j][1])**2))**0.5
tmp = tmp* math.factorial(N-1)

ans = tmp/math.factorial(N)
print(ans)

Submission status: Accepted

Solution code:
import math
N=int(input())
Z=[[],[]]
A=[]
kaijo=1
sum=0
for i in range(1,N+1):
    kaijo=kaijo*i
for i in range(N):
    x,y=map(int,input().split())
    Z[0].append(x)
    Z[1].append(y)
for i in range(N-1):
    for j in range(i+1,N):
        A.append(math.sqrt((Z[0][i]-Z[0][j])**2+(Z[1][i]-Z[1][j])**2))
for i in range(len(A)):
    sum+=A[i]*kaijo*2
print(sum/(kaijo*N))

Submission status: Accepted

Solution code:
import math

n=int(input())

pos=[]
for _ in range(n):
    x,y=map(int,input().split())
    pos.append((x,y))
    
sum_diff=0
for i in range(n-1):
    for j in range(i+1,n):
        sum_diff+=math.sqrt((pos[i][0]-pos[j][0])**2+(pos[i][1]-pos[j][1])**2)*2*(n-2+1)*math.factorial(n-2)
    
print(sum_diff / math.factorial(n))

Submission status: Accepted

Solution code:
def cal(a,b):
    d=((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5
    return d
import math
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
ans=0
nk=math.factorial(n)
for i in range(n):
    for j in range(n):
        ans+=cal(l[i],l[j])
print((n-1)*ans/(n*(n-1)))

Submission status: Accepted

Solution code:
import itertools,math

N = int(input())

town_list = []
for i in range(N):
    town_list.append(list(map(lambda x: int(x), input().split())))

jyunretsu = list(itertools.permutations(range(N)))

total_sum = 0
for j in jyunretsu:
    previous_town_number = None
    sum = 0
    for count, town_number in enumerate(j):
        if count == 0:
            previous_town_number = town_number
            continue

        sum += math.sqrt((town_list[town_number][0]-town_list[previous_town_number][0])**2 + (town_list[town_number][1]-town_list[previous_town_number][1])**2)
        previous_town_number = town_number

    total_sum += sum

print(total_sum/len(jyunretsu))

Submission status: Accepted

Solution code:
from sys import stdin
#from collections import deque
from math import sqrt
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return [x for x in mi()]
def si(): return stdin.readline()
def dis(x, y, p, q):
    return sqrt((x-p)**2+(y-q)**2)
a=[]
s=0
n=ii()
fn=1
for i in range(1, n+1):
    fn*=i
fn//=2
for _ in range(n):
    x, y=mi()
    a.append([x, y])
for i in range(n-1):
    for j in range(i+1, n):
        s+=dis(a[i][0], a[i][1], a[j][0], a[j][1])
        #print(s)
print(2*s/n)

Submission status: Accepted

Solution code:
import numpy as np
import math
import itertools
values = []
n = int(input())
towns = [list(map(int,input().split())) for _ in range(n)]
num_root = math.factorial(n)
for root in itertools.permutations(towns):
  for i in range(n - 1):
    level = (root[i][0] - root[i + 1][0])**2 + (root[i][1] - root[i + 1][1])**2
    values.append(math.sqrt(level))
print(sum(values)/num_root)

Submission status: Accepted

Solution code:
n = int(input())
x, y = [], []
for i in range(n):
    tmp = [int(x) for x in input().split()]
    x.append(tmp[0])
    y.append(tmp[1])

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

Submission status: Accepted

Solution code:
import os
import math

n = int(input())
x = []
y = []
ans = 0
for i in range(n):
    a,b = (int(x) for x in input().split())
    x.append(a)
    y.append(b)

def d(x1,y1,x2,y2):
    return (((x1-x2)**2+(y1-y2)**2)**0.5)

for j in range(n):
    for k in range(j+1,n):
        ans += 2*d(x[j],y[j],x[k],y[k])
print(ans/n)

Submission status: Accepted

Solution code:
import itertools
import numpy as np
import math
N = int(input())

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

s = list(itertools.permutations(range(N)))

def dis(s):
  ans = 0
  for i in range(len(s)-1):
    ans += np.sqrt((p[s[i]][0] - p[s[i+1]][0])**2 + (p[s[i]][1] - p[s[i+1]][1])**2)
  return ans

ans = sum([dis(x) for x in s])/math.factorial(N)
print(ans)

Submission status: Accepted

Solution code:
import math
import itertools

n = int(input())
l = []
ll = []
for i in range(n):
    l.append(list(map(int, input().split())))
for v in itertools.permutations(l, n):
    ll.append(list(v))

ans = 0
for j in ll:
    for k in range(n-1):
        a = j[k]
        b = j[k+1]
        aa = pow((b[0] - a[0]),2)
        bb = pow((b[1] - a[1]),2)
        ans+=pow(aa+bb, 1/2)
print(ans/len(ll))

Submission status: Accepted

Solution code:
import math
from itertools import permutations
N = int(input())
A = [tuple(map(int, input().split())) for _ in range(N)]
P = list(permutations(A))
ans = 0
count = 0
for p in P:  
  count += 1
  for i in range(1,len(p)):
    ans += math.sqrt((p[i-1][0]-p[i][0])**2 + (p[i-1][1]-p[i][1])**2)        
print(ans/count)

Submission status: Accepted

Solution code:
N = int(input())
xy = [tuple(map(int, input().split())) for _ in range(N)]


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


d = 0
for i in range(N-1):
    for j in range(i+1, N):
        d += xxx(N - 1) * 2 * ((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2) ** 0.5

ans = d / xxx(N)
print(ans)

Submission status: Accepted

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

total=0
for i in range(N):
    for (j) in range(i+1,N):
        total+=math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)

print(total/N*2)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
XY = np.array(read().split(),np.int64)

X = XY[::2]; Y = XY[1::2]

dx = X[:,None] - X[None,:]
dy = Y[:,None] - Y[None,:]

dist_mat = (dx * dx + dy * dy) ** .5

answer = dist_mat.sum() / N
print(answer)

Submission status: Accepted

Solution code:
import itertools

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

Permutations = (list(itertools.permutations(City)))

def route(l):
    Ans=[]
    for i in range(len(l)-1):
        L = ((l[i+1][0]-l[i][0])**2+(l[i+1][1]-l[i][1])**2)**.5
        Ans.append(L)
    return sum(Ans)

Length_list=[]

for i in Permutations:
    Length_list.append(route(i))



print(sum(Length_list)/len(Length_list))

Submission status: Accepted

Solution code:
import math
from itertools import permutations
n = int(input())
x = []
for _ in range(n):
    x.append(list(map(int , input().split())))
p = permutations(x)
ans = 0
for i in p:
    dist = 0
    for k in range(1 , n):
        dist += math.sqrt((i[k][0] - i[k-1][0]) ** 2 + (i[k][1] - i[k-1][1]) ** 2)

    ans += dist
print(ans / len(list(permutations(x))))

Submission status: Accepted

Solution code:
import numpy as np
import math
N = int(input())
data = {}
total = 1
for i in range(N):
  a_, b_ = map(int, input().split(" "))
  data[i] = np.array([a_,b_])
  total *= (i+1)

distance = 0.
for i in range(N):
  if i == 0:
    continue
  for j in range(i):
    distance += np.linalg.norm(data[i]-data[j])

param = 2 * (math.factorial(N) - math.factorial(N-1))/(N-1)
print(distance * param / total)

Submission status: Accepted

Solution code:
import math
from itertools import permutations, combinations,combinations_with_replacement,product
def length(x,y,p,q):
    ans= math.sqrt((x-p)**2+(y-q)**2)
    return ans
N=int(input())
S= [list(map(int, input().split())) for i in range(N)]
S_list=list(permutations(S))
leng_sum=0
for i in S_list:
    for j in range(N-1):
        x1=i[j][0]
        y1=i[j][1]
        x2=i[j+1][0]
        y2=i[j+1][1]
        leng_sum=leng_sum+length(x1,y1,x2,y2)
print(leng_sum/math.factorial(N))

Submission status: Accepted

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

import math

def main():
    N=int(input())
    Ps=[tuple(map(int, input().split())) for _ in range(N)]

    s = 0
    for i in range(N-1):
        for j in range(i+1,N):
            s += math.hypot(Ps[i][0]-Ps[j][0], Ps[i][1]-Ps[j][1])

    print(s*2/N)
    

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc145","c",main)

Submission status: Accepted

Solution code:
import math
import itertools
n = int(input())
nn = math.factorial(n)
X = []
Y = []
for _ in range(n):
  x, y = map(int, input().split())
  X.append(x)
  Y.append(y)
xx = list(itertools.permutations(X, n))
yy = list(itertools.permutations(Y, n))
c = 0
for k in range(nn):
  s = 0
  for i in range(n-1):
    s += math.sqrt((xx[k][i] - xx[k][i+1])**2 + (yy[k][i] - yy[k][i+1])**2)
  c += s
print(c/nn)

Submission status: Accepted

Solution code:
import itertools
import numpy as np
N = int(input())
xy = np.array([list(map(int, input().split())) for i in range(N)])
p = itertools.permutations(range(N))
print(np.mean([np.linalg.norm(xy[list(p_i)[:-1]]-xy[list(p_i)[1:]], axis=1).sum() for p_i in p]))

Submission status: Accepted

Solution code:
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
goukei=0
for i in range(n):
  for k in range(i+1,n):
    goukei+=((l[i][0]-l[k][0])**2+(l[i][1]-l[k][1])**2)**0.5
goukei*=2
print(goukei/n)

Submission status: Accepted

Solution code:
N = int(input())
x_list = []
y_list = []
import math

def calc_distance(x1,y1,x2,y2):
  distance_2 = (x1 - x2)**2 + (y1 - y2)**2
  distance = distance_2**0.5
  return distance

for i in range(N):
  x,y = map(int,input().split())
  x_list.append(x)
  y_list.append(y)

distance_list = []
distance_sum = 0
for i in range(N):
  #distance_list.append([])
  for j in range(N):
    distance_sum += calc_distance(x_list[i],y_list[i],x_list[j],y_list[j])
    #distance_list[i].append(calc_distance(x_list[i],y_list[i],x_list[j],y_list[j]))

ans = distance_sum / N 
print(ans)

Submission status: Accepted

Solution code:
from math import factorial
from itertools import permutations

n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]

def dist(a, b):
    return ((d[a][0]- d[b][0])**2 + (d[a][1]- d[b][1])**2 )**(1/2)
ls = list(range(n))
total = 0
for perm in permutations(ls):
    for i in range(n-1):
        total += dist(perm[i], perm[i+1])

ans = total/factorial(n)
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math
N = int(input())
P = [list(map(int,input().split())) for i in range(N)]
lisN =  [i for i in range(N)]
length = 0
count = 0
for v in itertools.permutations(lisN, N):
    length_here = 0
    for k in range(N-1):
      Pam = P[v[k]]
      Ppm = P[v[k+1]]
      length_here += math.sqrt((Ppm[0] - Pam[0])**2 + (Ppm[1] - Pam[1])**2)

    length += length_here
    count += 1
print(length/count)

Submission status: Accepted

Solution code:
n = int(input())
n_step = 1
nm2_step = 1
for i in range(1,n+1):
    n_step *= i
for i in range(1,n-1):
    nm2_step *= i
point = []
dist_array = []
for i in range(n):
    point.append(list(map(int,input().split())))
for i in range(0,n-1):
    for j in range(i+1,n):
        dist = ((point[i][0] - point[j][0])**2 +
                (point[i][1] - point[j][1])**2) ** 0.5
        dist_array.append(dist)
print(sum(dist_array) * 2 * (n-1) * nm2_step / n_step)

Submission status: Accepted

Solution code:
import math
n=int(input())
d=[list(map(int,input().split())) for i in range(n)]
D=[]
ans=[]

def kaijou(x):
  if x==1:
    return x
  return x*kaijou(x-1)

N=kaijou(n)
NN=kaijou(n-1)

for i in range(n):
  for j in range(n):
    if i!=j :
      D.append(math.sqrt((d[i][0]-d[j][0])**2+ (d[i][1]-d[j][1])**2))
print(sum(D)*(NN)/N)

Submission status: Accepted

Solution code:
import itertools
import numpy as np
import math

N = int(input())

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


def calc_dist(bef, aft):
    dist = np.sqrt((bef[0] - aft[0])**2 + (bef[1] - aft[1])**2)
    return dist

total_dist = 0
for one_root in itertools.permutations(area_list, N):
    for i in range(N-1):
        tmp_dist = calc_dist(one_root[i], one_root[i+1])
        total_dist += tmp_dist

ans = total_dist / math.factorial(N) 
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools
input = sys.stdin.readline


def main():
    n = int(input())
    towns = []
    for _ in range(n):
        x, y = map(int, input().split())
        towns.append((x, y))

    matrix = [[0] * n for i in range(n)]
    for i in range(n - 1):
        for j in range(i + 1, n):
            l = ((towns[i][0] - towns[j][0]) ** 2 +
                 (towns[i][1] - towns[j][1]) ** 2) ** 0.5
            matrix[i][j] = l
            matrix[j][i] = l

    towns_id = list(range(n))
    all_lengh = []
    for v in itertools.permutations(towns_id):
        l = 0
        for i in range(n-1):
            l += matrix[v[i]][v[i+1]]
        all_lengh.append(l)

    result = sum(all_lengh) / len(all_lengh)
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

n = int(input())
towns = [tuple(map(int, input().split())) for _ in range(n)]

def calc(i, j):
    return ((towns[i][0] - towns[j][0])**2 + (towns[i][1] - towns[j][1])**2)**0.5

l = list(range(n))
p = list(itertools.permutations(l, n))

total = 0
for p_ in p:
    for i in range(n-1):
        total += calc(p_[i], p_[i+1])

res = total / len(p)

print(res)

Submission status: Accepted

Solution code:
import numpy as np
import math
n = int(input())
distlist = []
for i in range(n):
    distlist.append(np.array(list(map(int,input().split()))))

distsum = 0
for i in range(n):
    for j in range(i,n):
        distsum += np.linalg.norm(distlist[i]-distlist[j])
        
n_kaizyo = math.factorial(n)
n1_kaizyo = math.factorial(n-1)

ans = (distsum*2*n1_kaizyo)/n_kaizyo

print(ans)

Submission status: Accepted

Solution code:
a = input()

a = int(a)

city_list = []

total_dist = 0

from itertools import permutations
import math

for i in range (a):
    x, y = input().split()
    x = int(x)
    y = int(y)
    city_list.append([x, y])

perms = (permutations(city_list))

divisor = 0

for cities in list(perms):
    divisor += 1
    for j in range(1, len(cities),):
        total_dist = total_dist + math.sqrt((cities[j][0] - cities[j-1][0])**2 + (cities[j][1] - cities[j-1][1])**2)


print(total_dist/divisor)

Submission status: Accepted

Solution code:
import math
from math import factorial

n = int(input())
X, Y = [],[]
for i in range(n):
  x, y = map(int, input().split())
  X.append(x)
  Y.append(y)
D = [[0] * n for _ in range(n)]
def ncr(n,r):
  return factorial(n) / factorial(r) / factorial(n - r)

def getD(x1, y1, x2, y2):
  return math.sqrt((x1-x2)**2 + (y1-y2)**2)

for i in range(n):
  for j in range(i+1,n):
    D[i][j] = getD(X[i],Y[i],X[j],Y[j])
sum = 0
mt = factorial(n-1) * 2
for i in range(n):
  for j in range(i+1,n):
    sum += D[i][j] * mt
ans = sum / factorial(n)
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

def main():
    N = int(input())
    X = []
    Y = []
    ans = 0

    for i in range(N):
        x, y = map(int, input().split())
        X.append(x)
        Y.append(y) 

    for i in itertools.permutations(range(N)):
        for j in range(len(i)-1):

            ans += math.sqrt((X[i[j+1]]-X[i[j]])**2 + (Y[i[j+1]]-Y[i[j]])**2)

    print(ans/math.factorial(N))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import factorial as f
from math import sqrt as sq

n = int(input())
l = []
s = 0
for i in range(n):
	x, y = map(int, input().split())
	l.append([x, y])
p = 0
for i in range(n):
	for j in range(n):
		if i != j:
			s += (sq((l[i][0] - l[j][0])**2 + (l[i][1] - l[j][1])**2) * (n - 1))
		p += 1
print(s / (n * (n - 1)))

Submission status: Accepted

Solution code:
n = int(input())
import math
coordinates = [list(map(int, input().split())) for i in range(n)]
dis = []
for i in range(n-1):
    for j in range(i+1,n):
        d = math.sqrt((coordinates[i][0]-coordinates[j][0])**2 + (coordinates[i][1]-coordinates[j][1])**2)
        dis.append(d)
        dis.append(d)
print(sum(dis)/n)