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

Solution (Python):
import itertools
import math

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

ans = 0
kazu_list = list(itertools.permutations(range(n)))
for nums in kazu_list:
    for i,num in enumerate(nums):
        if i < n-1:
            next_num = nums[i+1]
            ans += math.sqrt(pow((axis[num][0]-axis[next_num][0]),2) + pow((axis[num][1]-axis[next_num][1]),2))
print(ans/len(kazu_list))

Solution (Python):
import math
import itertools


N=int(input())
XY=[[None for _ in range(2)] for _ in range(N+1)]

for i in range(N):
    XY[i+1]=list(map(int,input().split()))

l = [_ for _ in range(1,N+1)]
p = itertools.permutations(l, N)
patern=math.factorial(N)

sums=0

for i in p:
    for j in range(N-1):
        sums+=math.sqrt((XY[i[j]][0]-XY[i[j+1]][0])**2 + (XY[i[j]][1] - XY[i[j+1]][1])**2) 

print(sums/patern)

Solution (Python):
from math import sqrt

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

total = 0.0
for i in range(N-1):
  for j in range(i+1, N):
    total += sqrt((P[i][0]-P[j][0])**2 + (P[i][1]-P[j][1])**2)

print(total * 2 / N)

Solution (Python):
import math
n=int(input())
l=[[int(i) for i in input().split()] for j in range(n)]
d=[]
for i in range(n):
  for j in range(i):
    d.append(((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)**0.5)
total=[]
print(sum(d)*(n-1)/len(d))

Solution (Python):
import itertools
N=int(input())
r= [[int(i) for i in input().split()] for i in range(N)]
l=list(itertools.permutations(range(N)))
ans=[]
for i in range(len(l)):
    length_list=[]
    for j in range(N-1):
        length_list.append(((r[l[i][j]][0]-r[l[i][j+1]][0])**2+(r[l[i][j]][1]-r[l[i][j+1]][1])**2)**0.5)
    ans.append(sum(length_list))
print(sum(ans)/len(l))

Solution (Python):
from sys import stdin
import itertools
N = int(stdin.readline().rstrip())
input = []
for i in range(N):
    input.append([int(x) for x in stdin.readline().rstrip().split()])

dist = 0
for ir in list(itertools.permutations(range(N))):
    now_dist = 0
    for i in range(len(ir) - 1):
        x = ir[i]
        y = ir[i + 1]
        now_dist += ((input[x][0] - input[y][0]) ** 2 + (input[x][1] - input[y][1]) ** 2) ** (1 / 2)
    dist += now_dist
output = dist / len(list(itertools.permutations(range(N))))
print(output)

Solution (Python):
import math


def combi(a, b):
    ans = math.factorial(a) / (math.factorial(a - b) * math.factorial(b))
    ans = int(ans)
    return ans


N=int(input())

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

kai=(math.factorial(N)*(N-1))//combi(N,2)

a=0

for i in range(N):
    for j in range(i+1,N):
        temp=((p[i][0]-p[j][0])**2+(p[i][1]-p[j][1])**2)**0.5
        a+=temp*kai

print(a/math.factorial(N))

Solution (Python):
import itertools

N = int(input())

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

results = 0
count = 0
for items in itertools.permutations(cities):
  count += 1
  length = 0
  for i in range(1, len(items)):
    length += ((items[i][1] - items[i-1][1])**2 + (items[i][0] - items[i-1][0])**2)**0.5
  results += length
print(results/count)

Solution (Python):
import numpy as np
n = int(input())
p = []
ex = [1]
for i in range(8):
    ex.append(ex[i]*(i+1))

for i in range(n):
    p.append(list(map(int,input().split())))
l = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
    for j in range(n):
        l[i][j] = np.sqrt((p[i][0]-p[j][0])**2+(p[i][1]-p[j][1])**2)
su = 0
ne = 1
for i in range(n):
    su = su + sum(l[i]) -l[i][i]
    ne = ne*(i+1)
print(ex[n-1]*2*(su/2)/ne)

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

sum = 0

def dist(x_1, y_1, x_2, y_2):
  return ((x_2 - x_1)**2 + (y_2 - y_1)**2)**0.5

for i in range(n):
  for j in range(i+1, n):
    sum += dist(x[i][0], x[i][1], x[j][0], x[j][1])
    
print(sum*2/n)

Solution (Python):
import itertools
import math

N = int(input())
X = [[0, 0] for i in range(N)]
for i in range(N):
	X[i][0],X[i][1] = map(int, input().split())	

Ns = 1
for i in range(1, N+1):
	Ns = Ns*i

L = [i for i in range(N)]

sum = 0
for V in itertools.permutations(L, N):
	for i in range(N-1):
		sq = (X[V[i]][0] - X[V[i+1]][0])**2 + (X[V[i]][1] - X[V[i+1]][1])**2
		sum += (sq)**0.5

print(sum/Ns)

Solution (Python):
import math,itertools
def distance(i,j):
	return math.sqrt(math.pow(i[0]-j[0],2)+math.pow(i[1]-j[1],2))
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
city = []
for i in range(n):
	city.append([int(p) for p in input().split(' ')])


dists = [distance(c[0],c[1]) for c in itertools.combinations(city,2)]
t = math.factorial(n)/2*(n-1)/combinations_count(n,2)

res = sum([d*t for d in dists])/(math.factorial(n)/2)
print(res)

Solution (Python):
import itertools
import math
N = int(input())
A = []
for i in range(N):
    B = [int(i) for i in input().split()]
    A.append(B)
C = []
for i in range(N):
    C.append(i)
X = list(itertools.combinations(C,2))
LENGEs = []
for i in X:
    Y = A[i[0]]
    Z = A[i[1]]
    lenge = math.sqrt((Y[0] - Z[0]) ** 2 + (Y[1] - Z[1]) ** 2)
    LENGEs.append(lenge)
M = 0
for i in LENGEs:
    M += i
ans = (N-1 ) * (M / len(LENGEs))

print(ans)

Solution (Python):
N = int(input())
ans = 0
t = []
for i in range(N):
    x,y = map(int,input().split())
    for j in range(i):
        a,b = t[j]
        ans += ((x-a)**2 + (y-b)**2)**0.5
    t.append((x,y))
ans = ans*2
ans = ans/N
print(ans)

Solution (Python):
import itertools
from math import sqrt

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

ite = list(itertools.permutations(data))
sum_num = 0
for D in ite:
	tmp = D[0]
	for i in range(1, N):
		sum_num += sqrt((tmp[0] - D[i][0]) ** 2 + (tmp[1] - D[i][1]) ** 2)
		tmp = D[i]

print(sum_num/len(ite))

Solution (Python):
from itertools import permutations as perm
n = int(input())
XY = [list(map(int,input().split())) for _ in range(n)]
ans = 0
for i in range(n):
	for j in range(n):
		if i == j:continue
		ab = XY[i]
		cd = XY[j]
		ans += ((ab[0]-cd[0])**2+(ab[1]-cd[1])**2)**0.5

print(ans/n)

Solution (Python):
import math

N = int(input())
xy = [list(map(int, input().split(' '))) for i in range(N)]
'''
dist = []
for i in range(N):
    dist.append([])
    for j in range(N):
        if i == j:
            dist[i].append(0)
            continue
        dist_x = (xy[i][0] - xy[j][0]) ** 2
        dist_y = (xy[i][1] - xy[j][1]) ** 2
        dist[i].append((dist_x + dist_y) ** 0.5)
print(*dist, sep='\n')
'''
sum = 0
bias = 2 * math.factorial(N-1)
for i in range(N-1):
    for j in range(i + 1, N):
        dist_x = (xy[i][0] - xy[j][0]) ** 2
        dist_y = (xy[i][1] - xy[j][1]) ** 2
        
        sum += ((dist_x + dist_y) ** 0.5) * bias
print(sum/math.factorial(N))

Solution (Python):
N = int(input())
X = []
Y = []
for i in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
Sum = 0.0
for i in range(N):
    for j in range(N-i-1):
        Sum += ((X[i]-X[j+i+1])**2+(Y[i]-Y[j+i+1])**2)**0.5

print(Sum*2/N)

Solution (Python):
N = int(input())
xy = [list(map(float,input().split()))for i in range(N)]
sum = 0
for i in range(N-1):
    for j in range(i+1,N):
        a = (xy[i][0]-xy[j][0])**2
        b = (xy[i][1]-xy[j][1])**2
        sum+= (a+b)**0.5
print(sum*2/N)

Solution (Python):

N = int(input())

x =[]
y =[]
for i in range(N):
    x1, y1 = map(int,input().split())
    x.append(x1)
    y.append(y1)
    

NN = [[0] * N for _ in range(N) ]
ans = 0
for i in range(N):
    for j in range(i,N):
        ans += (((x[i] - x[j]) ** 2 +(y[i] - y[j]) ** 2) ** (1/2)) * 2 
ans = ans / N

print(ans)

Solution (Python):
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
ans = 0

def solve(p, L):
    
    if p and len(L) == 1:
        return ((L[0][0] - p[0])**2 + (L[0][1] - p[1])**2) ** 0.5
    result = 0
    for i in range(len(L)):
        result += solve(L[i], L[:i] + L[i+1:]) 
        if p:
            result += ( ((L[i][0] - p[0])**2 + (L[i][1] - p[1])**2) ** 0.5 ) * factorial(len(L)-1)
    return result

def factorial(n):
    a = 1
    for i in range(2, n+1):
        a *= i
    return a

ans = solve(None, xy)

M = factorial(N)
print(ans / M)

Solution (Python):

N = int(input())
A = [[int(j) for j in input().split()] for i in range(N)]

length = []

l = 0
for i in A:
    for j in A:
        if i == j:
            continue
        l += (((j[0] - i[0])**2 + (j[1] - i[1])**2)**0.5)
        for k in A:
            if j == k or i == k:
                continue
            l += (((k[0] - j[0])**2 + (k[1] - j[1])**2)**0.5)
        length.append(l)
        l = 0

print(sum(length)/len(length))

Solution (Python):
import itertools

N = int(input())
point = []
length = 0
average = 0

for _ in range(N):
    point.append(list(map(int, input().split())))
    
combo = list(itertools.permutations(point, N))

for i in combo:
    for j in range(N - 1):
        average += ((i[j][0] - i[j+1][0])**2 + (i[j][1] - i[j+1][1])**2)**0.5
        
print(average / len(combo))

Solution (Python):
import math

len=0
N = int(input())
P = [list(map(int,input().split())) for i in range(N)]
for i in range(N-1):
  for j in range(i+1,N):
    len+=math.sqrt((P[i][0]-P[j][0])**2+(P[i][1]-P[j][1])**2)
    
print(2*len*math.factorial(N-1)/math.factorial(N))

Solution (Python):
import math
N=int(input())
p=[list(map(int,input().split())) for _ in range(N)]
s=0
for i in range(N):
    for j in range(i+1,N):
        s+=((p[i][0]-p[j][0])**2+(p[i][1]-p[j][1])**2)**0.5
print(s*2*math.factorial(N-1)/math.factorial(N))

Solution (Python):
import math
N = int(input())
xlist = []
dist = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
    x,y = map(int, input().split())
    xlist.append([x,y])
ans = 0

for j in range(N):
    x1 = xlist[j][0]
    y1 = xlist[j][1]
    for k in range(j+1,N):
        x2 = xlist[k][0]
        y2 = xlist[k][1]
        di = math.sqrt((x1-x2)**2 + (y1-y2)**2)
        dist[j][k] = di

ans = 0


for i in range(N):
    ans += sum(dist[i])

ans = 2 *ans /N 

print(ans)

Solution (Python):
import itertools
import math

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

sums = 0.0
for perm in list(itertools.permutations(list(range(N)))):
    bef = perm[0]
    for i in perm[1:]:
        itoj = math.sqrt((xy[bef][0] - xy[i][0])**2 + (xy[bef][1] - xy[i][1])**2)
        sums += itoj
print(sums/math.factorial(N))

Solution (Python):
import math
import itertools
N=int(input())
kai=math.factorial(N)
li=[list(map(int,input().split())) for _ in range(N)]
a=0
for v in itertools.permutations(li,2):
    x=(v[0][0]-v[1][0])**2
    y=(v[0][1]-v[1][1])**2
    a+=math.sqrt(x+y)
print(a/N)

Solution (Python):
import itertools
import math
n = int(input())
x = []
y = []

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

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

d_ave = 0
for p in itertools.permutations(range(n)):
    d = 0
    nx = x[p[0]]
    ny = y[p[0]]
    for i in p:
        d += math.sqrt((nx-x[i])**2+(ny-y[i])**2)
        nx = x[i]
        ny = y[i]
    d_ave += d
print(d_ave / bikkuri(n))

Solution (Python):
import math
n = int(input())
xy = [list(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.sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)
print(s*2/n)

Solution (Python):
import itertools
import math

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

    l = range(N)
    cnt = 0
    total = 0
    for v in itertools.permutations(l):
        sum = 0
        for i in range(N-1):
            idx1 = v[i]
            idx2 = v[i+1]
            sum += math.sqrt( (X[idx1]-X[idx2]) ** 2 + (Y[idx1]-Y[idx2]) ** 2)
        total += sum
        cnt += 1

    print(total/cnt)

if __name__ == '__main__':
    main()

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

import math

road=0
for i in range(N):
  for j in range(N):
    distance=(A[i][0]-A[j][0])**2+(A[i][1]-A[j][1])**2
    road+=math.sqrt(distance)/2
    
path=2/N
print(road*path)

Solution (Python):
import math
import itertools



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


comb = list(itertools.permutations(range(N), 2))



dis = []
for i,j in comb:
    x = machi[i][0] - machi[j][0]
    y = machi[i][1] - machi[j][1]

    di = math.sqrt(abs(x**2+y**2))
    dis.append(di)

print(sum(dis)/N)

Solution (Python):
from itertools import permutations
from math import sqrt

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

for order in permutations(range(n), n):
    curX, curY = towns[order[0]]
    length = 0
    for o in range(1, n):
        nextTown = towns[order[o]]
        length += sqrt((nextTown[0] - curX) ** 2 + (nextTown[1] - curY) ** 2 )
        curX, curY = nextTown
    path_length_list.append(length)

ans = sum(path_length_list) / len(path_length_list)
print(ans)

Solution (Python):
import math

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

dis = 0

for i in range(N):
    for j in range(N):
        dis += math.sqrt((X[i]-X[j])**2 + (Y[i]-Y[j])**2)

print(dis / N)

Solution (Python):
import math
n = int(input())
l = []
for i in range(n):
	t = input().split(" ")
	x = int(t[0])
	y = int(t[1])
	l.append([x, y])
d = 0
for i in range(n):
	for j in range(n):
		d += math.sqrt((l[i][0] - l[j][0]) * (l[i][0] - l[j][0]) + (l[i][1] - l[j][1]) *  (l[i][1] - l[j][1]))
a = d / n
print(a)

Solution (Python):
from itertools import permutations
from math import sqrt

n=int(input())
permlist = list(permutations(range(n)))


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

lengths = 0.0
for p in permlist:
    length = 0.0
    for _ in range(len(p)-1):
        i = p[_]
        j = p[_+1]
        
        length += sqrt( (x[i]-x[j])**2 + (y[i]-y[j])**2 )
    
    lengths += length

print(lengths/len(permlist))

Solution (Python):
import math
N=int(input())
X = [[int(i) for i in input().split()] for _ in range(N)]
 
v = 0
for i in range(N):
    for j in range(i+1, N):
        yz = [(y - z)**2 for y, z in zip(X[i], X[j])]
        v += math.sqrt(sum(yz))
print(2*v/N)

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

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

result = 0.0
sz = 0

for item in itertools.permutations(range(n)):
    sz += 1
    ct = 0
    for i in item:
        if ct == 0:
            prev = i
            ct += 1
            continue
        result += math.sqrt(math.pow(x[i][0]-x[prev][0], 2) + math.pow(x[i][1]-x[prev][1], 2))
        prev = i

print(result/sz)

Solution (Python):
from itertools import permutations
from math import sqrt, factorial
n = int(input())
cities = [list(map(int, input().split())) for _ in range(n)]

ans = 0

for p in permutations(range(n)):
    for c1, c2 in zip(p, p[1:]):
        x1, y1 = cities[c1]
        x2, y2 = cities[c2]
        d = sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
        ans += d
print(ans / factorial(n))

Solution (Python):
import math
N = int(input())
C = [list(map(int,input().split())) for _ in range(N)]


D = 0
for i in range(N-1):
    for j in range(i+1,N):
        x1 = C[i][0]
        y1 = C[i][1]
        x2 = C[j][0]
        y2 = C[j][1]
        D += math.sqrt( (x1-x2)**2 + (y1-y2)**2 )

print(2*D/N)

Solution (Python):
import math

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

ans = 0

for i in range(n):
    for j in range(n):
        length = math.sqrt((li[i][0] - li[j][0]) ** 2 + (li[i][1] - li[j][1]) ** 2)
        ans += length

ans = (math.factorial(n-1) * ans) / math.factorial(n)
print(ans)

Solution (Python):
from math import sqrt
n = int(input())
a = list()
sum = 0
for i in range(n):
    x, y = map(int, input().split())
    a.append((x, y))
for i in range(n):
    for j in range(i + 1, n):
        v1, v2 = a[i], a[j]
        sum += sqrt((v1[0] - v2[0]) ** 2 + (v1[1] - v2[1]) ** 2)
print(sum*2/n)

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

list1 = [list(map(int,input().split())) for i in range(n) ]
list2 = list(itertools.permutations(range(n)))
ans = 0.0
count = 0.0
i = 0
while True:
    if i >= math.factorial(n):
        break
    for j in range(n-1):
        try:
            a = (list1[list2[i][j+1]][0] - list1[list2[i][j]][0])**2
        except ZeroDivisionError:
            a = 0
        try:
            b = (list1[list2[i][j+1]][1] - list1[list2[i][j]][1])**2
        except ZeroDivisionError:
            b = 0
        count += math.sqrt(a+b)
    ans += count
    count = 0
    i += 1

print(ans*(n-1)/(math.factorial(n)*(n-1)))

Solution (Python):
import math

a=int(input())
b=[]
d=0.0
cnt=0

for i in range(a):
    b.append(list(map(int , input().split())))

for i in range(a-1):
    for j in range(i+1, a, 1):
        cx=(b[i][0]-b[j][0])
        cy=(b[i][1]-b[j][1])
        cz=math.sqrt(cx*cx+cy*cy)
        d+=cz
        cnt+=1

print(d/cnt*(a-1))

Solution (Python):
n=int(input())
a=[[int(i) for i in input().split()] for m in range(n)]
import itertools
import math
p=list(itertools.permutations(range(n),n))
total=0
for i in p:
    tmp=0
    for j in range(n-1):
        x=(a[i[j]][0]-a[i[j+1]][0])**2+(a[i[j]][1]-a[i[j+1]][1])**2
        x=x**0.5
        tmp+=x
    total+=tmp
print(total/math.factorial(n))

Solution (Python):

import sys

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

def rsum_nC2(N):
    ret=0
    for i in range(N):
        for j in range(N):
            if i==j:
                continue
            ret+=r(i,j)
    return ret/N/(N-1)

def solve(N: int, x: "List[int]", y: "List[int]"):
    print(rsum_nC2(N)*(N-1))

    return

x = [int()] * (8)  
y = [int()] * (8)  
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()

Solution (Python):
import math

n = int(input())

p = []

g = 1

for i in range(n):
    g *= (i+1)
    x, y = map(int, input().split())
    p.append((x, y))

d = [[0]*n for _ in range(n)]

for i in range(n):
    for j in range(n):
        dd = math.sqrt(pow(p[i][0]-p[j][0], 2)+pow(p[i][1]-p[j][1], 2))
        d[i][j] = dd
        d[j][i] = dd


def hoge(s, i, dd):
    if not s:
        return dd
    sum_ = 0
    for ss in s:
        v = s.copy()
        v.remove(ss)
        sum_ += hoge(v, ss, dd+d[i][ss])
    return sum_


res = 0
for ii in range(n):
    c = set(range(n))
    c.remove(ii)
    res += hoge(c, ii, 0)

print(res/g)

Solution (Python):
import math

n = int(input())

x = [0,0,0,0,0,0,0,0,0,0,0]
y = [0,0,0,0,0,0,0,0,0,0,0]
f = [0,0,0,0,0,0,0,0,0,0,0]

def distance(x1, y1, x2, y2):
	ff = float((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
	return math.sqrt(ff)

total = 0
num = 0

def dfs(now, pre, dis):
	global total 
	global num

	if (now == n+1):
		total += dis
		num += 1
		return 
	if (now == 1):
		for i in range(1, n+1):
			f[i] = 1
			dfs(now+1, i, dis)
			f[i] = 0
	else:		
		for i in range(1, n+1):
			if f[i] == 0:
				f[i] = 1
				dfs(now+1, i, dis+distance(x[pre], y[pre], x[i], y[i]))
				f[i] = 0




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




dfs(1, 0, 0)


print(round(total/num, 10))

Solution (Python):
import math
N=int(input())
xy=[]
nagasas=[]
for i in range(N):
  x = list(map(int, input().split()))
  xy.append(x)

for i in range(N-1):
  for j in range(i+1, N):
    kari=(xy[i][0]-xy[j][0])*(xy[i][0]-xy[j][0])+(xy[i][1]-xy[j][1])*(xy[i][1]-xy[j][1])
    nagasa=math.sqrt(kari)
    nagasas.append(nagasa)
wa=sum(nagasas)
n_kumiawase=N*(N-1)/2
kumiawase=math.factorial(N)
n_set=kumiawase/n_kumiawase
kotae=wa*n_set*(N-1)/kumiawase
print(kotae)

Solution (Python):
import sys
from collections import *
from heapq import *
from fractions import gcd
import itertools
import math

sys.setrecursionlimit(10**6)

def InMap(): return list(map(int, input().split(' ')))
def In(): return int(input())
def InS(): return input()

N = In()
pos = []
for i in range(N):
    pos.append(InMap())

Res = 0
for v in itertools.permutations(pos, N):
    tmp = 0
    for i in range(N - 1):
        tmp += math.sqrt((v[i][0] - v[i+1][0])**2 + (v[i][1] - v[i+1][1])**2)
    Res += tmp
print(Res / float(math.factorial(N)))
exit()

Solution (Python):

import numpy as np
import itertools as it
N = int(input())
pos = []
for n in range(N):
    pos.append(tuple([int(x) for x in input().split()]))
per = list(it.permutations(pos))

distance = 0
for p in range(len(per)):
    for n in range(len(per[p])-1):
        distance += np.sqrt((per[p][n][0]-per[p][n+1][0])**2 + (per[p][n][1]-per[p][n+1][1])**2)
distance = distance / len(per)

print(distance)

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

import itertools
import numpy as np
import math

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

Sum_N = 0

for i in range(len(p)):

    Sum = 0

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

    Sum_N += Sum

print(Sum_N / len(p))

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

edge = []
X,Y = map(int,input().split())
x = [X]
y = [Y]

for j in range(n-1):
    a,b = map(int,input().split())
    for ex,ey in zip(x,y):
        edge.append(((a-ex)**2+(b-ey)**2)**0.5)
    x.append(a)
    y.append(b)

me = sum(edge)/len(edge)
print(me*(n-1))

Solution (Python):
import math

N = int(input())
route = math.factorial(N)
town = []
d = 0.0

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

for t in town:
  for tt in town:
    d += math.sqrt((tt[0]-t[0])**2 + (tt[1]-t[1])**2) * (route / N)

print(d / route)

Solution (Python):
import sys
import numpy as np
from math import factorial, sqrt
from itertools import permutations
read = sys.stdin.read
readline = sys.stdin.readline

N = int(readline())
xy = np.array(read().split(), np.int64).reshape(N, 2)
distance = [[0.0] * N for _ in range(N)]

for i in range(N - 1):
    for j in range(i + 1, N):
        tmp = sqrt(np.sum((xy[i] - xy[j]) ** 2))
        distance[j][i] = tmp
        distance[i][j] = tmp

answer = 0
for i in permutations(range(N)):
    for j in range(N - 1):
        answer += distance[i[j]][i[j + 1]]

print(answer / factorial(N))

Solution (Python):
from itertools import permutations
import math
def rangeT(a,b):
    return (math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2 ))

n=int(input())

X=[[0]*2 for _ in range(n)]

for i in range(n):
    X[i]=[int(x) for x in input().split()]

total=0
for perm in permutations(range(n)):
    for i,j in zip(perm,perm[1:]):
        total += rangeT(X[i],X[j])

print(total/math.factorial(n))

Solution (Python):
from itertools import permutations, combinations
from math import sqrt, factorial

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

l = [[0 for _ in range(n)] for _ in range(n)]



for i, j in combinations(range(n), 2):
    
    dist = (d[i][0] - d[j][0]) ** 2 + (d[i][1] - d[j][1]) ** 2
    dist = sqrt(dist)
    
    
    l[i][j] = dist
    l[j][i] = dist




s = 0
for p in permutations(range(n)):
    
    for k in range(len(p) - 1):
        s += l[p[k]][p[k + 1]]

print(s / factorial(n))

Solution (Python):
import itertools
import math

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


patterns = list(itertools.permutations([i for i in range(n)], n))


def calc_length(i, j):
    xi, yi = i
    xj, yj = j

    return math.sqrt((xi - xj) ** 2 + (yi - yj)**2)

def calc_length_many(pattern):
    num = 0
    
    for k in range(len(pattern) -1):
        i = xys[pattern[k]]
        j = xys[pattern[k+1]]
        num += calc_length(i, j)
    return num
ans = 0

for i in range(len(patterns)):
    
    ans += calc_length_many(patterns[i])

print(ans / len(patterns))

Solution (Python):
from itertools import permutations
from decimal import *
import math

def main():
    N = int(input())
    X = [] 
    for i in range(N):
        x, y = map(int, input().split())
        X.append((x,y))

    ans = 0

    for A in permutations(X):
        tmp = 0
        i = 0
        pre_x = 0
        pre_y = 0
        for x, y in A:
            if i == 0:
                pre_x = x
                pre_y = y
                i += 1
            else:
                tmp = (x - pre_x) ** 2 + (y - pre_y) ** 2
                ans += tmp ** 0.5
                i += 1 
    
    ans = Decimal(ans) / Decimal(math.factorial(N))
    print(ans)




  

if __name__ == "__main__":
    main()

Solution (Python):
import math

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

def culc(L,R):
    return math.sqrt((L[0]-R[0])**2+(L[1]-R[1])**2)

sum=0
for j in range(1,N):
    for k in range(j):
        sum+=culc(P[j],P[k])


ans=2*sum/N
print(ans)

Solution (Python):
N=int(input())
a=list(range(N))
b=list(range(N))
for i in range(N):
 a[i],b[i]=map(int,input().split())
c=0
for i in range(N):
 for j in range(N):
  c+=((a[i]-a[j])**2+(b[i]-b[j])**2)**0.5
d=c/N
print(d)

Solution (Python):
n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
l = [[0]*n for i in range(n)]
for i in range(n):
    for j in range(n):
        l[i][j] = ((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2)**0.5
a = 0
for i in range(n):
    a += sum(l[i][i:])
print(a/n*2)

Solution (Python):

import math
import itertools
n = int(input())
n_list = [x+1 for x in range(n)]
num = math.factorial(n)
n_per = list(itertools.permutations(n_list))
p_list = []
for i in range(n):
    x,y = map(int, input().split())
    p_list.append([x, y])
p_sum = 0
for keiro in n_per:
    p_min_sum = 0
    
    for p_n in range(n-1):
        
        
        p_1 = math.sqrt((p_list[keiro[p_n]-1][0] - p_list[keiro[p_n + 1] - 1][0])**2 + (p_list[keiro[p_n]-1][1] - p_list[keiro[p_n + 1] - 1][1])**2)
        p_min_sum += p_1
    p_sum += p_min_sum
print(p_sum / num)

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

from itertools import permutations
import math
l_sum = 0
dic={}
lx = list(range(0,N))

for k,i in enumerate(xy):
  l = []
  for j in xy:
    length = ((i[0]-j[0])**2 + (i[1]-j[1])**2)**(1/2)
    l.append(length)
    
  dic[k]=l
  
p = list(permutations(lx,N))
for i in p:
  for j in range(N-1):
    l_sum += dic[i[j]][i[j+1]]
    
print(l_sum/math.factorial(N))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n = INT()
    lis = [LIST() for _ in range(n)]
    ans = 0
    
    for i in range(n):
        for j in range(i, n):
            ans += sqrt((lis[i][0] - lis[j][0]) ** 2 + (lis[i][1] - lis[j][1]) ** 2)
    m = factorial(n)
    ans *= 2 * factorial(n-1)
    
    print(ans/m)

if  __name__=='__main__':
    main()

Solution (Python):
import itertools

n=int(input())
ls=[list(map(int,input().split(' '))) for i in range(n)]

def get_distance(a,b):
    return ((a[0]-b[0])**2+(a[1]-b[1])**2)**(1/2)

routes=list(itertools.permutations(range(n), n))
sum=0

for i in routes:
    for j in range(n-1):
        sum+=get_distance(ls[i[j]],ls[i[j+1]])
print(sum/len(routes))

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

ans = 0
for i in range(n):
    for j in range(n):
        if i == j:
            pass
        else:
            ans += ((maps[i][0]-maps[j][0])**2 + (maps[i][1]-maps[j][1])**2) **(1/2)
			
num = 1
for k in range(1,n+1):
    num *= k
print(ans/n)

Solution (Python):
import itertools
import math

N = int(input())
P = []

for _ in range(N):
    P.append(list(map(int, input().split())))

lists = itertools.permutations(range(N))

ans = 0
for l in lists:
    for i, x in enumerate(l):
        
        if i == 0:
            pre = P[x]
            continue

        temp = (P[x][0] - pre[0])**2 + (P[x][1] - pre[1])**2
        ans += math.sqrt(temp)
        pre = P[x]

print(ans / math.factorial(N))

Solution (Python):
import math

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

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

b = 0
for i in range(1,n):
    b += i

print(total*(n-1)/b)

Solution (Python):
N=int(input())
T=[list(map(int,input().split())) for i in range(N)]
X=0
c=1
for i in range(N):
  for j in range(N):
    X=X+((abs(T[i][0]-T[j][0]))**2+(abs(T[i][1]-T[j][1]))**2)**0.5
for r in range(1,N+1):
  c=c*r
print(X/N)

Solution (Python):
N=int(input())
z=[]
for  i in range(N):
    z.append(list(map(int,input().split())))
s=0
for i in range(N):
    for j in range(N):
        if i<j:
            s +=((z[i][0]-z[j][0])**2+(z[i][1]-z[j][1])**2)**0.5
print(2*s/N)