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):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    X = [0]*N
    Y = [0]*N
    for i in range(N):
        X[i], Y[i] = map(int, input().split())
    
    r = [[0]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            r[i][j] = math.sqrt((X[i] - X[j])**2 + (Y[i] - Y[j])**2)

    ans = 0
    for route in itertools.permutations([i for i in range(N)]):
        for i in range(N-1):
            ans += r[route[i]][route[i+1]]
    ans /= math.factorial(N)

    print(ans)
        

if __name__ == '__main__':
    main()

Solution (Python):
import itertools as it
n = int(input())
towns = []
for i in range(n):
    towns.append(list(map(int,input().split())))
ans = 0
count = 0
for ts in it.permutations(towns):
    for i in range(len(ts)-1):
        ans += ((ts[i][0]-ts[i+1][0])**2+(ts[i][1]-ts[i+1][1])**2)**0.5
    count += 1
print(ans/count)

Solution (Python):
import itertools
N = int(input())
num = [i for i in range(N)]
lst = [list(map(int,input().split())) for i in range(N)]
routes = list(itertools.permutations(num))
sum_route = 0
for route in routes:
  for i in range(len(route) - 1):
    x1 = lst[route[i]][0]
    y1 = lst[route[i]][1]
    x2 = lst[route[i+1]][0]
    y2 = lst[route[i+1]][1]
    sum_route += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
print(sum_route / len(routes))

Solution (Python):
import itertools
import math

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

path = 0
for c1, c2 in itertools.product(L, L):
    path += math.sqrt((c1[0]-c2[0])**2 + (c1[1]-c2[1])**2)

print(path/N)

Solution (Python):
fact = [1]
for i in range(1,14):
    fact.append(fact[-1]*i)
n = int(input())
def dist(a,b):
    return ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5
a = []
for i in range(n):
    x,y = map(int,input().split())
    a.append([x,y])
ans = 0;
for i in a:
    for j in a:
        ans+=(dist(i,j)*fact[n-1])
print(ans/fact[n])

Solution (Python):
import itertools
import math

N=int(input())

town=[]
result=0
count=0

for i in range(N):
    town.append([int(x) for x in input().split()])

tag=list(itertools.permutations(town))

for val in tag:
    
    for i in range(0,len(val)-1):
        
        
        buf=pow(val[i][0]-val[i+1][0],2)
        tmp=pow(val[i][1]-val[i+1][1],2)
        
        
        result+=(math.sqrt(buf+tmp))

print(result/math.factorial(N))

Solution (Python):
from itertools import permutations

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

num = 0
path_length = 0
for p in permutations(XY):
    num += 1
    for (x1, y1), (x2, y2) in zip(p, p[1:]):
        path_length += ((x1-x2)**2 +(y1-y2)**2)**0.5

print(path_length/num)

Solution (Python):

from itertools import permutations
N = int(input())

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

perm = list(permutations(towns))

def calc_l2(p_next, p):
    return ((p_next[0] - p[0])**2 + (p_next[1] - p[1])**2) ** 0.5

l2_norm = 0
for p in perm:
    for i in range(len(p) - 1):
        l2_norm += calc_l2(p[i+1], p[i])

print(l2_norm/len(perm))

Solution (Python):
import itertools
import math

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

path = itertools.permutations([i for i in range(n)])

ans = []
for town in list(path):
    total = 0
    for i in range(n-1):
        total += math.sqrt((p[town[i]][0]-p[town[i+1]][0])**2 + (p[town[i]][1]-p[town[i+1]][1])**2)
    ans.append(total)

print(sum(ans)/math.factorial(n))

Solution (Python):
import math
import itertools
N = int(input())
town = [list(map(int, input().split())) for _ in range(N)]
path = []
for p in itertools.permutations(town):
    path.append(sum([math.sqrt((p[i+1][0]-p[i][0])**2 + (p[i+1][1]-p[i][1])**2) for i in range(len(p)-1)]))

print(sum(path)/len(path))

Solution (Python):
import numpy as np
import itertools
import math
N = int(input())
place = np.zeros((N, 2))
for i in range(N):
  x, y = map(int, input().split())
  place[i,:] = [x,y]
length = np.zeros((N, N))
for i in range(N):
  a = np.array(place[i,:])
  for j in range(i,N):
    b = np.array(place[j,:])
    length[j,i] = length[i,j] = np.linalg.norm(b-a)

s = np.zeros(math.factorial(N))
for i,order in enumerate(list(itertools.permutations(list(range(N))))):
  for j in range(N-1):
    s[i] += length[order[j], order[j+1]]
    
print(np.mean(s))

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

dis=0
a=0
for x in itertools.permutations(L):
    for i in range(n-1):
        dis+=math.sqrt((x[i][0]-x[i+1][0])**2+(x[i][1]-x[i+1][1])**2)
    a+=1

print(dis/a)

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

dis=0
a=0
for x in itertools.permutations(L):
    for i in range(n-1):
        dis+=math.sqrt((x[i][0]-x[i+1][0])**2+(x[i][1]-x[i+1][1])**2)
    a+=1

print(dis/a)

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


def dist(t1, t2):
    return ((t1[0] - t2[0])**2+(t1[1] - t2[1])**2)**0.5


N = int(input())
l_cities = [None] * N

for i in range(N):
    l_cities[i] = tuple(map(int, input().split()))

perm_l = permutations(list(range(N)))

summ = 0

for l_p in perm_l:
    for i in range(1, N):
        summ += dist(l_cities[l_p[i-1]], l_cities[l_p[i]])
    
avg_mean = summ / factorial(N)
print(avg_mean)

Solution (Python):
from itertools import permutations
import math

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


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



paths = list(permutations(paths))
avg = 0
for path in paths:
    for i in range(len(path) - 1):
        avg += distance(path[i], path[i+1])

print(avg / len(paths))

Solution (Python):
import math

N = int(input())

towns = []
townx = []
towny = []

for i in range(N):
    x, y = map(int, input().split(' '))
    townx.append(x)
    towny.append(y)

distances = [[math.sqrt((townx[i] - townx[j]) ** 2 + (towny[i] - towny[j]) ** 2) for j in range(N)] for i in range(N)]

fact = math.factorial(N)
res = sum([sum(distance) for distance in distances])

print(res/N)

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 math
dim = 0
count = 0
for n in itertools.permutations(range(N)):
    count += 1
    for num in range(1,N):
        x_dim = pow((x[n[num-1]]-x[n[num]]), 2)
        y_dim = pow((y[n[num-1]]-y[n[num]]), 2)
        dim += math.sqrt(x_dim + y_dim)

print(dim/count)

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

Solution (Python):
import numpy as np

N = int(input())
a = []
x = []
y = []
count = 0

def factorial(n):
    if n<2:
        return 1
    else:
        return(n*factorial(n-1))

for i in range(N):
    a.append(list(map(int,input().split())))    
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        count += np.sqrt((a[i][0] - a[j][0])**2 + (a[i][1] - a[j][1])**2)
b = factorial(N)
print(count/N)

Solution (Python):
n = int(input())
A = []
for _ in range(n):
    x, y = map(int, input().split())
    A.append([x, y])
import itertools, math
tmp = 0
l = len(list(itertools.permutations(A, n)))
for x in itertools.permutations(A, n):
    for i in range(1, n):
        xi, xj, yi, yj = x[i-1][0], x[i][0], x[i-1][1], x[i][1]
        tmp += math.sqrt(((xi - xj) ** 2) + ((yi - yj) ** 2))
print(tmp / l)

Solution (Python):
import numpy as np
N = int(input())
AllList = list(range(0, N))


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


count = 0
for i in range(0, N):
    for q in range(0, N):
        if i == q:
            continue
        Distance[i][q] = np.sqrt((Coord[i][0] - Coord[q][0]) ** 2 + (Coord[i][1] - Coord[q][1]) ** 2)
        count += Distance[i][q]
count = count / N
print(count)

Solution (Python):
import itertools
import numpy as np

N = int(input())
l = []
for i in range(N):
	l.append(list(map(int,input().split())))
    
r = 0
for i,j in itertools.product(l,l):
	r += np.sqrt((i[0]-j[0])**2 + (i[1]-j[1])**2)

print(r/N)

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

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

print(2 * t / n)

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

A=[input().split() for i in range(N)]
x=0
y=1
L=0
num=0
import itertools
import math
citylist=[0]*N

for j in range(N):
  citylist[j]=j

Plist=list(itertools.permutations(citylist))

for l in range(math.factorial(N)):
  L=0
  for k in range(N-1):
    L+=((int(A[Plist[l][k]][x])-int(A[Plist[l][k+1]][x]))**2+(int(A[Plist[l][k]][y])-int(A[Plist[l][k+1]][y]))**2)**(1/2)
  num+=L
  
print(num/math.factorial(N))

Solution (Python):
def n_n(n):
  c = 1
  for i in range(1,n+1):
    c = c * i
  return c
import itertools as itr
N = int(input())
n = n_n(N)

rr=[]
xy = [[0,0]] * (N)
for i in range(N):
  xy[i] = list(map(int,input().split()))
  
all = list(itr.permutations(xy))
for line in all:
  r = [0] * (N+1)
  x = [0]*(N+1)
  y = [0]*(N+1)
  for i in range(N-1):
    x[i+1] = line[i+1][0] - line[i][0]
    y[i+1] = line[i+1][1] - line[i][1]
    r[i+1] = (x[i+1]**2 + y[i+1]**2)**(1/2)
  rr.append(sum(i for i in r))
print(sum(i for i in rr)/n)

Solution (Python):
import math

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

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

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

ans = 0

for i in range(n):
    for j in range(i+1,n):
        ans += dis[i][j] * math.factorial(n-1) * 2

print(ans/math.factorial(n))

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

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

total = 0
for i in range(N):
    for k in range(N):
        total += kyori(x[i], y[i], x[k], y[k])

total = total / N
print(total)

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

Solution (Python):
import math
import itertools

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

li=list(range(N))
co=[]
sum=0

for i in itertools.permutations(li,N):
    co.append(list(i))

for i in range(len(co)):
    for j in range(N-1):
        sum+=((xy[co[i][j]][0]-xy[co[i][j+1]][0])**2+(xy[co[i][j]][1]-xy[co[i][j+1]][1])**2)**(1/2)
print(sum/len(co))

Solution (Python):
import itertools
import math

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


total = 0
for perm in itertools.permutations(points):
    for i in range(n - 1):
        p1 = perm[i]
        p2 = perm[i + 1]
        dist = math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
        total += dist

avg = total / math.factorial(n)


print(avg)

Solution (Python):
import math


def main():
    N = int(input())
    xy_list = [list(map(int, input().split())) for i in range(N)]

    sum = 0

    for i, xy1 in enumerate(xy_list):
        for j, xy2 in enumerate(xy_list):
            if i == j:
                continue

            x1 = xy1[0]
            x2 = xy2[0]
            y1 = xy1[1]
            y2 = xy2[1]

            sum += math.sqrt((x1-x2)**2 + (y1-y2)**2)

    print(sum/N)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
l=list()
a=0
for i in range(N):
    l.append(list(map(int,input().split())))
    for _ in l:
        a+=((_[0]-l[-1][0])**2+(_[1]-l[-1][1])**2)**(1/2)
print(2*a/N)

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

ans = 0
for i in xy:
    for j in xy:
        ans += ((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2) ** 0.5

print(ans/n)

Solution (Python):
n = int(input())
X = []
Y = []
for _ in range(n):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    
dist = 0
import math 
for j in range(n):
    for k in range(n):
        dist += math.sqrt((X[j]-X[k])**2+(Y[j]-Y[k])**2)
        
print(dist/n)

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

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

l = []
for i in range(n):
    l.append(i)

p = list(permutations(l))
ave = 0
cnt = 0
for i in p:
    j = 0
    while (j < n - 1):
        ave += sqrt(pow(x[i[j]] - x[i[j + 1]], 2) + pow(y[i[j]] - y[i[j + 1]], 2))
        j += 1
    cnt += 1

res = ave / cnt
print(res)

Solution (Python):
import math as m
import itertools as it

N = int(input())
xy = [[int(i) for i in input().split()] for j in range(N)]
sum_dis = 0
num = 0
for i in it.permutations(xy):
    for jth in range(len(i) - 1):
        sum_dis += m.sqrt(
            (i[jth][0] - i[jth + 1][0]) ** 2 + (i[jth][1] - i[jth + 1][1]) ** 2
        )
    num += 1
print(sum_dis / num)

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

ans = 0
for p in itertools.permutations(xy, n):
    for i in range(n-1):
        ans += math.sqrt((p[i][0]-p[i+1][0])**2 + (p[i][1]-p[i+1][1])**2)
print(ans/math.factorial(n))

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 math

def root_length(x0, y0, x1, y1):
    return math.sqrt((x1-x0)**2 + (y1-y0)**2)
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        ans += root_length(x[i],y[i],x[j],y[j])
ans *= 2 /N 
print(ans)

Solution (Python):
import math
import itertools

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

rr = list(itertools.permutations(route, N))

total = 0
for r in rr:
    for i in range(len(r) - 1):
        x = (r[i][0] - r[i+1][0]) ** 2
        y = (r[i][1] - r[i+1][1]) ** 2
        f = math.sqrt(x + y)
        total += f

print(total/len(rr))

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




ans = 0

for j in range(N):
    for k in range(N):
        if(j == k):
            continue
        disx = x[k] - x[j]
        disy = y[k] - y[j]
        ans += ((disx ** 2) + (disy ** 2))**0.5

print(ans/N)

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

Solution (Python):
import math

n = int(input())
x = []
y = []


arr = [i for i in range(1,n)]
for i in range(n):
  a,b = map(int,input().split())
  x.append(a)
  y.append(b)
  
count = 0
for i in range(n-1):
  for j in range(i+1,n):
    count += math.sqrt(((x[i]-x[j])**2)+((y[i]-y[j])**2))

print(count / n * 2)

Solution (Python):
def solve(points) -> float:
  def all_shuffled(xs):
    if len(xs) == 0:
      return [[]]

    ret = []
    for i in range(len(xs)):
      ret += [[xs[i]] + shuffled for shuffled in all_shuffled(xs[0: i] + xs[i + 1: ])]
    return ret

  n = len(points)

  factorial_n = 1
  for i in range(1, n + 1):
    factorial_n *= i

  dist_sum = 0.0
  for ps in all_shuffled(points):
    for i in range(n - 1):
      xi, yi = ps[i]
      xj, yj = ps[i + 1]
      dist_sum += ((xi - xj) ** 2 + (yi - yj) ** 2) ** (1/2)

  return dist_sum / factorial_n


n = int(input().strip())
points = []
for i in range(n):
  l = input().strip()
  x, y = l.split()
  points.append((int(x), int(y)))

print(solve(points))

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

ans=0
def dist(p1,p2):
	return ((p1[0]-p2[0])**2+(p1[1]-p2[1])**2)**0.5

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

Solution (Python):
import math
from itertools import permutations

n = int(input())

verts = []

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

def get_dist(x0, y0, x1, y1):
	return math.sqrt(pow(x1 - x0, 2) + pow(y1 - y0, 2))

avg_dist = 0
den = 0
for permutation in permutations(verts, n):
	dist = 0
	
	for i in range(1, len(permutation)):
		x1, y1 = permutation[i]
		x0, y0 = permutation[i-1]
		dist += get_dist(x0, y0, x1, y1)
	avg_dist += dist
	den += 1
print('%.10f'%(avg_dist/den))

Solution (Python):
import itertools
import math

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

combi = itertools.combinations(range(N), 2)


def dist(combi):
    t0 = towns[combi[0]]
    t1 = towns[combi[1]]
    d = math.sqrt((t0[0] - t1[0]) ** 2 + (t0[1] - t1[1]) ** 2)
    return d


dist_list = {}
for c in combi:
    key = '{0[0]}_{0[1]}'.format(sorted(c))
    dist_list[key] = dist(c)

def total_dist(perm):
    d = 0
    for p in zip(perm[:-1], perm[1:]):
        key = '{0[0]}_{0[1]}'.format(sorted(p))
        d += dist_list[key]
    return d


perm = itertools.permutations(range(N), N)

result = 0
count = 0
for p in perm:
    count += 1
    result += total_dist(p)

result /= count
print(result)

Solution (Python):
import math
n=int(input())
z=[list(map(int,input().split())) for _ in range(n)]
s=0
for i in range(n):
  for j in range(n):
    if i!=j:
      s+=math.sqrt((z[i][0]-z[j][0])**2+(z[i][1]-z[j][1])**2)
print(s/n)

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

sum_distance = 0

for i in range(n):
  for j in range(n):
    sum_distance += math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
    
print(sum_distance/n)

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok



def main():
    N=ii()
    P = tuple(tuple(mis()) for _ in range(N))
    ans = 0
    def length(prv, nex):
        if prv is None:
            return 0
        else:
            return ((P[nex][0]-P[prv][0])**2 + (P[nex][1]-P[prv][1])**2) ** 0.5

    def rec(bf, val, prev):
        nonlocal ans
        if bf == 2**N-1:
            ans += val
        else:
            for i in range(N):
                b = 1 << i
                if not bf & b:
                    rec(bf | b, val + length(prev, i), i)

    rec(0, 0, None)

    for i in range(1, N+1):
        ans /= i
    
    print(ans)

main()

Solution (Python):

N = int(input())
 
paths = []
 
for _ in range(N):
    x, y = map(int, input().split())
    paths.append((x, y))
 
all_path_len = 0
 
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        xa, ya = paths[i]
        xb, yb = paths[j]
        all_path_len += ((xa - xb) ** 2 + (ya - yb) ** 2) ** 0.5
 
ans = all_path_len / N
 
print(ans)

Solution (Python):
import sys
import itertools
import math

sys.setrecursionlimit(10**7)
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

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

pall = 0
for pat in pattern:
    for i in range(N-1):
        currp = xy[pat[i]]
        nextp = xy[pat[i+1]]
        dist = math.sqrt(
            (currp[0] - nextp[0])**2
          + (currp[1] - nextp[1])**2
            )
        pall += dist

print(pall/(len(pattern)))

Solution (Python):
from itertools import permutations
 
n = int(input())
n_ = 1
for i in range(n):
    n_ *= i+1
c = [tuple(map(int,input().split())) for _ in range(n)]
tot = 0
 
def dis(c,x,y):
  x1,y1 = c[x]
  x2,y2 = c[y]
  return ((x1-x2)**2 + (y1-y2)**2)**.5
 
for l in permutations(range(n)):
    d = 0
    cur = l[0]
    for x in l:
        d += dis(c,cur,x)
        cur = x
    tot += d/n_
print(tot)

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

towns=list(range(n))
now=1
kaijou=[]
for i in range(1,9):
    now*=i
    kaijou.append(now)

from itertools import permutations
import math
for root in permutations(towns,n):
    ans+=sum([math.sqrt( ( x[root[i]]-x[root[i-1]])**2 +( y[root[i]]-y[root[i-1]])**2 ) for i in range(1,n)])
print(ans/kaijou[n-1] )

Solution (Python):
from itertools import permutations


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


n = int(input())
xy_array = [[int(x) for x in input().split()] for y in range(n)]
p = permutations([x for x in range(n)])

sum_distance = 0
for order in p:
    for index in range(n - 1):
        x1 = xy_array[order[index]][0]
        x2 = xy_array[order[index + 1]][0]
        y1 = xy_array[order[index]][1]
        y2 = xy_array[order[index + 1]][1]
        sum_distance += calc_distance(x1, y1, x2, y2)
tmp = 1
for i in range(2, n + 1):
    tmp *= i
print(sum_distance / tmp)

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

paths = []

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

all_path_len = 0

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        xa, ya = paths[i]
        xb, yb = paths[j]
        all_path_len += ((xa - xb) ** 2 + (ya - yb) ** 2) ** 0.5

ans = all_path_len / N

print(ans)

Solution (Python):
import itertools
import math

N = int(input())
T = [[]*2]*N
for i in range(N):
  T[i] = list(map(int, input().split()))

L = 0
for i in itertools.permutations(T):
  for n in range(N-1):
    L = L + math.sqrt((i[n][0]-i[n+1][0])**2+(i[n][1]-i[n+1][1])**2)

print(L/math.factorial(N))

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

Solution (Python):

import math

n = int(input())
points = []
combi_num = 1
for i in range(n):
    p = list(map(int, input().split()))
    points.append(p)
    combi_num *= i


total = 0
for i in range(n):
    for j in range(n):
        if i != j:
            k = math.sqrt((points[i][0]-points[j][0])*(points[i][0]-points[j][0]) + (points[i][1]-points[j][1])*(points[i][1]-points[j][1]))
            total += k
print(total/n)

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

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

dists = [[0] * n for _ in range(n)]
for i in range(n):
	for j in range(n):
		dists[i][j] = ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** (1 / 2)

ans = sum([sum(d) for d in dists]) / n
print(ans)

Solution (Python):
from itertools import permutations
from math import factorial
from math import sqrt
n=int(input())
l=[]
def distance(x,y):
  a=sqrt((x[0]-y[0])**2+(x[1]-y[1])**2)
  return a
def dist(l):
  d=0
  for i in range(1,n):
    d+=distance(l[i],l[i-1])
  return d
for i in range(n):
  l.append(list(map(int, input().split())))
x=list(permutations(l))
avg=0
for i in x:
    avg+=dist(i)
print(avg/factorial(n))

Solution (Python):
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import fractions
from functools import reduce
from operator import mul
import bisect
import sys
import logging
import heapq
import itertools

logging.basicConfig(level=logging.ERROR)

input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	n = int(input())
	xy = [list(map(int,input().split())) for _ in range(n)]
	s = 0
	for i in range(n):
		for j in range(n):
			if(i==j): continue
			s+=math.sqrt((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)
	print(s/n)

def factorization(n):
	if n<2:
		return []

	arr = []
	temp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if temp%i==0:
			cnt=0
			while temp%i==0:
				cnt+=1
				temp //= i
			arr.append([i, cnt])

	if temp!=1:
		arr.append([temp, 1])

	if arr==[]:
		arr.append([n, 1])

	return arr

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(numbers):
	return reduce(fractions.gcd, numbers)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

class PriorityQueue():
	def __init__(self):
		self.queue = []
	def push(self,i):
		heapq.heappush(self.queue,-i)
	def pop(self):
		return -1 * heapq.heappop(self.queue)
	def sum(self):
		return -sum(self.queue)

main()

Solution (Python):
import math

def factorical(n):
    if n == 1:
        return n
    return n * factorical(n-1)

n = int(input())
a = []
for i in range(n):
  t = list(map(int,input().split()))
  a.append(t)
tot=0
mul = factorical(n-1)
for i in range(n):
  for j in range(n):
    tot += (math.sqrt((a[i][0]-a[j][0])**2 + (a[i][1]-a[j][1])**2))*mul
print(tot/(mul*n))

Solution (Python):
import itertools

n = int(input())
route = [x for x in range(n)]
t = [list(map(int,input().split())) for _ in range(n)]
route_list =  list(itertools.permutations(route,n))
l = len(route_list)
ans = 0

for i in range(l):
    for k in range(n - 1):
        now = route_list[i][k]
        nex = route_list[i][k + 1]
        ans += ((t[now][0] - t[nex][0]) ** 2 + (t[now][1] - t[nex][1]) ** 2) ** 0.5

print(ans / l)

Solution (Python):
import math
N=int(input())
ans=0
X=[0]*N
Y=[0]*N
leng=[]
for i in range(N):
    x,y=map(int,input().split())
    X[i]=x
    Y[i]=y
for i in range(N):
    for j in range(N):
        leng.append(((X[i]-X[j])**2+(Y[i]-Y[j])**2)**0.5)
ans=sum(leng)/N
print(ans)

Solution (Python):
n=int(input())
xy=[]
for _ in range(n):
	x,y=map(int,input().split())
	xy.append([x,y])
ans=0
for i in range(n):
	for j in range(n):
		ans+=((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**0.5
print(ans/n)

Solution (Python):
import itertools
import math

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

d = 0
for root in itertools.permutations(range(N)):
  for i in range(N-1):
    d_x = x[root[i+1]][0] - x[root[i]][0]
    d_y = x[root[i+1]][1] - x[root[i]][1]
    d   += math.sqrt(d_x**2 + d_y**2)

print(d / math.factorial(N))

Solution (Python):
import itertools
import numpy as np

num = int(input())
x = []
y = []
for i in range(num):
  x_N, y_N = map(int, input().split())
  x.append(x_N)
  y.append(y_N)

index = [str(i) for i in range(num)]
index_permut = list(itertools.permutations(index))

distance_all = 0
for l in index_permut:
  distance = 0
  index = list(map(int, l))

  for pos in range(num-1):
    x_diff = (x[index[pos+1]] - x[index[pos]]) ** 2
    y_diff = (y[index[pos+1]] - y[index[pos]]) ** 2
    distance += np.sqrt(x_diff + y_diff)

  distance_all += distance
res = distance_all / len(index_permut)
print(res)

Solution (Python):
import itertools
import numpy as np
import math

L = []
A = 0
t = 0
N = int(input())
for i in range(N):
    x, y = list(map(int, input().split()))
    L.append([x, y])

K = np.array(L)
for i in itertools.permutations(L):
    np.array(i)
    for k in range(N-1):
        u = math.sqrt((i[k][0]-i[k+1][0])**2+(i[k][1]-i[k+1][1])**2)
        A = A + u
    t += 1
B = A/t
print(B)