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
N = int(input())
xy_list = [list(map(int, input().split())) for _ in range(N)]

ans = 0
num = 0
for xy in itertools.permutations(xy_list):
    ans_pre = 0
    for i in range(N-1):
        ans_pre += ((xy[i][0]-xy[i+1][0])**2 + (xy[i][1]-xy[i+1][1])**2)**(0.5)
    num += 1
    ans += ans_pre
print(ans/num)

Solution (Python):
n = int(input())
xyn = []
for _ in range(n):
    x, y = map(int, input().split())
    xyn.append([x,y])
import itertools
ls = list(itertools.permutations(range(1, n+1)))


leng=0

for i in ls:
    for j in range(len(i)-1):
        z=i[j]
        a=i[j+1]
        leng += ((xyn[z-1][0]-xyn[a-1][0])**2+(xyn[z-1][1]-xyn[a-1][1])**2)**0.5

ans = leng/len(ls)
print(ans)

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

d = 0
for x, y in l:
    for z, w in l:
        d += ((x-z)**2+(y-w)**2)**0.5
print(d/n)

Solution (Python):
from itertools import permutations
import math

n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
m = math.factorial(n)
p = list(permutations(l))
d = 0

for i in range(m):
    for j in range(n-1):
        x = p[i][j][0] - p[i][j-1][0]
        y = p[i][j][1] - p[i][j-1][1]
        d += math.sqrt(x**2 + y**2)

print(d/m)

Solution (Python):
import numpy as np

def distance(x1, x2):
    return np.sqrt((x1[0] - x2[0])**2 + (x1[1] - x2[1])**2)

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

N_exs = [0, 1, 2, 6, 24, 120, 720, 5040, 40320]

for _ in range(N):
    A, B = map(int, input().split())
    X.append([A, B])

total = 0
for i in range(N):
    for j in range(N-1, i, -1):
        if i == j:
            continue
        total += distance(X[i], X[j])

num = int((N * N - N) / 2)


ans = total * (N-1) / num

print(ans)

Solution (Python):
from collections import defaultdict
from itertools import permutations as p

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
xy = [readInts() for i in range(n)]
l = list(p(list(range(0,n))))
length = len(l)
sumDis = 0
for i in l:
	for j in range(n-1):
		sumDis += ((xy[i[j+1]][0]-xy[i[j]][0])**2+(xy[i[j+1]][1]-xy[i[j]][1])**2)**0.5

print(sumDis/length)

Solution (Python):
from collections import defaultdict
from itertools import permutations as p

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
xy = [readInts() for i in range(n)]
l = p(list(range(0,n)))
length = len(list(p(list(range(0,n)))))
sumDis = 0
for i in l:
	for j in range(n-1):
		sumDis += ((xy[i[j+1]][0]-xy[i[j]][0])**2+(xy[i[j+1]][1]-xy[i[j]][1])**2)**0.5

print(sumDis/length)

Solution (Python):
import itertools
def Cal_Dist(i,j):
    a=((i[0]-j[0])**2+(i[1]-j[1])**2)**0.5
    return a

N=int(input())

town=[[0]*2 for i in range(N)]
for i in range (N):
    xy=list(map(int,input().split()))
    town[i]=xy
R=list(itertools.permutations(range(N)))

distance=[]


for k in range(len(R)):
    temp_town=[]
    for h in range(N):
        temp_town.append(town[R[k][h]])
    
    temp_distance=[]
    for i in range (N-1):
        distance_sections=Cal_Dist(temp_town[i],temp_town[i+1])
        temp_distance.append(distance_sections)
    else:
        distance.append(sum(temp_distance))
        



print(sum(distance)/len(R))

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_all = 0
for i in range(N):
  for j in range(i+1, N):
    sum_all += float((X[j]-X[i])**2 + (Y[j]-Y[i])**2) ** (1/2)
    
div = N/2
print(sum_all/div)

Solution (Python):








def solve(N, XY):
    from math import sqrt, factorial
    road_map = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            road_map[i][j] = sqrt((XY[i][0] - XY[j][0]) ** 2 + (XY[i][1] - XY[j][1]) ** 2)

    def dfs(now_town, visited, distance):
        visited[now_town] = 1
        if sum(visited) == N:
            return distance
        d = 0
        for i in range(N):
            if visited[i] == 0:
                d += dfs(i, visited.copy(), distance + road_map[now_town][i])
        return d

    sum_distance = 0
    for i in range(N):
        sum_distance += dfs(i, [0] * N, 0)

    print(sum_distance / factorial(N))


if __name__ == '__main__':
    
    N = int(input())
    XY = []
    for _ in range(N):
        XY.append([int(i) for i in input().split()])
    solve(N, XY)

Solution (Python):
import math
import itertools

N = int(input())
position = [list(map(int, input().split())) for _ in range(N)]
town = list(range(N))
distance =list2 = [[0 for i in range(N)] for j in range(N)]
average = 0

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

for order in itertools.permutations(town, N):
  for i in range(N-1):
    average += distance[order[i]][order[i+1]]
average /= math.factorial(N)

print(average)

Solution (Python):
import itertools
import math
n = int(input())
x,y = [],[]
for _ in range(n):
  a,b = map(int,input().split())
  x.append(a)
  y.append(b)

pat = itertools.permutations(range(n),n)
distsum = 0
for k in pat:
  dist = 0
  for i in range(n-1):
    dist += ((x[k[i+1]]-x[k[i]])**2+(y[k[i+1]]-y[k[i]])**2)**(1/2)
  distsum += dist
print(distsum/math.factorial(n))

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

ans = 0
count = 0
for i in permutations(range(n), n):
  for j in range(n-1):
    ans += ((xy[i[j]][0] - xy[i[j+1]][0])**2 + (xy[i[j]][1] - xy[i[j+1]][1])**2)**0.5
  count += 1

print(ans/count)

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

Solution (Python):
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        x1,y1=xy[i]
        x2,y2=xy[j]
        ans+=((x1-x2)**2+(y1-y2)**2)**(1/2)
ans/=n/2
print(ans)

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

Solution (Python):
N = int(input())
xy = []
for n in range(N):
    x, y = [int(s) for s in input().split(' ')]
    xy.append((x, y))
total = 0
pattern = 1
for n in range(N):
    pattern *= (1 + n)
    for m in range(n + 1, N):
        x0, y0 = xy[n]
        x1, y1 = xy[m]
        total += ((x0 - x1) ** 2 + (y0 - y1) ** 2) ** 0.5
print(total * pattern / N * 2 / pattern)

Solution (Python):
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
stock = []
for i in range(n):
	x, y = [int(j) for j in input().split()]
	lengths = []
	for xx, yy, _ in stock:
		lengths.append(((x - xx) * (x - xx) + (y - yy) * (y - yy)) ** 0.5)
	stock.append((x, y, lengths))

sum_length = 0
n_appear_by = math.factorial(n) * (n - 1) / n
for _, _, ls in stock:
	for l in ls:
		sum_length += l
print(sum_length * (n - 1) / combinations_count(n, 2))

Solution (Python):
import os, sys, re, math

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

for i in range(N):
    XY.append([int(n) for n in input().split()])

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

S = [0, 0, 1, 3, 6, 10, 15, 21, 28]
T = math.factorial(N)
m = T * (N - 1) // S[N] // 2

print(m * V / T)

Solution (Python):
import itertools
import math

N = int(input())

loc = [[int(s) for s in input().split()] for _ in range(N)]

dist = [[0] * N for _ in range(N)]

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

d_cnt = 0
cnt = 0
for per in itertools.permutations(list(range(N)), N):
    for i, j in zip(per, per[1:]):
        d_cnt += dist[i][j]
    cnt += 1

print(d_cnt / cnt)

Solution (Python):
import os, sys, re, math

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

for i in range(N):
    XY.append([int(n) for n in input().split()])

d = []
for i in range(N):
    dd = []
    for j in range(N):
        if i == j:
            dd.append(0)
        else:
            v = math.sqrt((XY[i][0] - XY[j][0]) ** 2 + (XY[i][1] - XY[j][1]) ** 2)
            dd.append(v)
    d.append(dd)

S = [0, 0, 1, 3, 6, 10, 15, 21, 28]
T = math.factorial(N)
m = T * (N - 1) // S[N] // 2

print(m * sum([sum(dd) for dd in d]) / T)

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

temp = 0.0
for i in range(n):
    for j in range(n):
        temp += (((xys[i][0] - xys[j][0]) ** 2 + (xys[i][1] - xys[j][1]) ** 2) ** 0.5)
print(temp / n)

Solution (Python):
import math

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
print(sum(math.hypot(xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]) for i in range(n) for j in range(n)) / n)

Solution (Python):
import math
import itertools

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

path_len = 0
path = []

s = [i for i in range(n)]
paths = list(itertools.permutations(s))
path_lens = []

for path in paths:
    path_len = 0
    for i in range(len(path)-1):
        path_len += float(math.sqrt((x[path[i]]-x[path[i+1]])**2 +
                                    (y[path[i]]-y[path[i+1]])**2))
    path_lens.append(path_len)

print(sum(path_lens) / len(paths))

Solution (Python):
from itertools import permutations
import math
N = int(input())
xy = [tuple(map(int,input().split())) for _ in range(N)]
city = list(permutations(xy))
all_len = 0
for i in city:
  sum_len = 0
  for j in range(1,N):
    sum_len += ((i[j][0]-i[j-1][0])**2 +(i[j][1]-i[j-1][1])**2)**0.5
  all_len += sum_len
print(all_len/len(city))

Solution (Python):
from itertools import combinations

N = int(input())
town = [tuple(map(int,input().split())) for _ in range(N)]
all_len = 0

for x, y in combinations(town,2):
  all_len += ((x[0]-y[0])**2 + (x[1]-y[1])**2)**0.5

result = (all_len*2)/N
print(result)

Solution (Python):


from itertools import combinations
n = int(input())
town = []
for i in range(n):
    x, y = map(int,input().split())
    town.append((x,y))

ans = 0
for i, j in combinations(town, 2):
    
    ans += ((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2) ** (0.5)
print(2 * ans / n)

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

from math import factorial
from math import sqrt
ans=0

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

num=factorial(N-1)*2
for i in range(N-1):
  for j in range(i+1,N):
    ans+=num*d(x[i],x[j],y[i],y[j])
print(ans/factorial(N))

Solution (Python):
from itertools import permutations
N = int(input())
position = []
for p in range(N):
    position.append(list(map(int,input().split())))

D = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(i+1,N):
        dist=(position[i][0]-position[j][0])**2
        dist+=(position[i][1]-position[j][1])**2
        dist=dist**(1/2)
        D[i][j] = dist
        D[j][i] = dist

dist=[]
for p in permutations(range(N),N):
    dist_temp=0
    for p_idx in range(1,len(p)):
        p_start = p[p_idx-1]
        p_end = p[p_idx]
        dist_temp+=D[p_start][p_end]
    dist.append(dist_temp)
        
print(sum(dist)/len(dist))

Solution (Python):
import itertools
import math
N = int(input())
XY = [list(map(int,input().split())) for i in range(N)]
L = 0
for i in list(itertools.permutations(XY)):
    distance = 0
    for n in range(N-1):
        distance += math.sqrt((i[n+1][0]-i[n][0])**2 + (i[n+1][1]-i[n][1])**2)
    L += distance
print(L/math.factorial(N))

Solution (Python):
import itertools

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

def fact(n):
    ans=1
    for i in range(n):
        ans*=(i+1)
    return ans

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

ls=list(itertools.permutations(range(n)))
ans=0
for l in ls:
   for i in range(n-1):
       ans+=dist(d[l[i]][0],d[l[i]][1],d[l[i+1]][0],d[l[i+1]][1])
ans/=fact(n)
print(ans)

Solution (Python):
from itertools import permutations
n= int(input())
ls = []
for i in range(n):
    a = list(map(int,input().split()))
    ls.append(a)
ans = []
for i in permutations(ls,n):
    
    result = 0
    for j in range(n-1):
        result += (((i[j][0]-i[j+1][0])**2+(i[j][1]-i[j+1][1])**2)**(1/2))
    ans.append(result)

ans = (1/len(ans))*sum(ans)
print(ans)

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    sm = 0
    pl = []
    for i in range(n):
        x,y = map(int,ipt().split())
        pl.append((x,y))
    nm = 0
    for i in range(n):
        xi,yi = pl[i]
        for j in range(i+1,n):
            xj,yj = pl[j]
            sm += math.sqrt((xj-xi)**2+(yj-yi)**2)
            nm += 1
    print(sm/nm*(n-1))



    return

if __name__ == '__main__':
    main()

Solution (Python):
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  

N = I()
xy = [LI() for i in range(N)]

sum = 0  
for i in range(N):
    for j in range(N):
        sum += ((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)**.5

print(sum/N)

Solution (Python):
import itertools
import numpy as np

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

lst = np.arange(1,N+1)
perm = list(itertools.permutations(lst))

ans = 0
lenperm = len(perm)
for k in range(lenperm):
  for p in range(N-1):
    x1 = x[perm[k][p+1]-1]
    y1 = y[perm[k][p+1]-1]
    x0 = x[perm[k][p]-1]
    y0 = y[perm[k][p]-1]
    tans = np.sqrt((x1-x0)**2 + (y1-y0)**2)
    ans += tans

print(ans / lenperm)

Solution (Python):
import numpy as np
def factorial(n):
  if (n==1):
    return 1
  return n*factorial(n-1)

n = int(input())
x = []
y = []
for i in range(n):
  x_, y_ = list(map(int, input().split()))
  x.append(x_)
  y.append(y_)
val = 0
for i in range(n):
  for j in range(i+1, n):
    val += np.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)

ans = val/factorial(n) * factorial(n-1) * 2
print(ans)

Solution (Python):
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
 
from itertools import permutations
from math import sqrt
 
paths = list(permutations(range(N), N))
l = len(paths)
total = 0
for path in paths:
    tmp = 0
    x, y = xy[path[0]][0], xy[path[0]][1]
    for p in path[1:]:
        px, py = xy[p][0], xy[p][1]
        tmp += sqrt((px-x)**2 + (py-y)**2)
    total += tmp
print(total / l)

Solution (Python):
n=int(input())
c=[[*map(int,input().split())] for _ in range(n)]
print(sum(((x-z)**2+(y-w)**2)**0.5 for x,y in c for z,w in c)/n)

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

Solution (Python):
from itertools import permutations
N = int(input())
ls = []
for i in range(N):
    ls.append([int(j) for j in input().split()])
arr = list(range(N))
ans = 0
num = 0
for x in permutations(arr, N):
    num += 1
    for y, z in zip(x, x[1:]):
        ans += ((ls[y][0] - ls[z][0])**2 + (ls[y][1] - ls[z][1])**2)**(1/2)
print(ans/num)

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

from itertools import permutations
from math import sqrt

paths = list(permutations(range(N), N))
l = len(paths)
total = 0
for path in paths:
    tmp = 0
    x, y = xy[path[0]][0], xy[path[0]][1]
    for p in path[1:]:
        px, py = xy[p][0], xy[p][1]
        tmp += sqrt((px-x)**2 + (py-y)**2)
    total += tmp
print(total / l)

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

import itertools
d=len(list(itertools.permutations(l)))
cnt=0
fin=0
for v in itertools.permutations(l):
  chk=0
  for z in range(len(v)-1):
    chk+=((v[z][0]-v[z+1][0])**2+(v[z][1]-v[z+1][1])**2)**0.5
  fin+=chk
print(fin/d)

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

def factorial(n):
    if n == 0:
        return 1
    else:
        a = 1
        for i in range(n):
            a *= n - i
        return a

def distance(a, b):
    l = ((a[0] - b[0])**2 + (a[1] - b[1])**2) ** 0.5
    return l

suml = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        suml += distance(xy[i], xy[j])

ave = (suml * 2 * factorial(n - 1)) / factorial(n)
print(ave)

Solution (Python):
import numpy as np
N = int(input())
Cord = np.zeros((N,2),dtype=int)
for T in range(0,N):
    Cord[T] = np.array([int(x) for x in input().split()])
Dist = 0
for T in range(0,N):
    for TT in range(T+1,N):
        Dist += np.linalg.norm(Cord[T,:]-Cord[TT,:])
print(Dist*2/N)

Solution (Python):
N = int(input())
pos = [list(map(int, input().split(" "))) for i in range(N)]
ans=0
for i in range(N):
  for j in range(N):
    x_dist = (pos[i][0]-pos[j][0])**2
    y_dist = (pos[i][1]-pos[j][1])**2
    dist = (x_dist+y_dist)**0.5
    ans+=dist
print(ans/N)

Solution (Python):
from itertools import permutations as perm
n = int(input())
cities = [list(map(int, input().split())) for _ in range(n)]
perms = list(range(n))
res=[]
for p in perm(perms):
    tmp=0
    for i in range(1,n):
       tmp+=((cities[p[i]][0]-cities[p[i-1]][0])**2+(cities[p[i]][1]-cities[p[i-1]][1])**2)**(1/2)
    res.append(tmp)
print(sum(res)/len(res))

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

import itertools
perm = list(itertools.permutations(range(n)))
d = 0
for v in perm:
  lx,ly = p[v[0]]
  for v2 in v[1:]:
    x,y=p[v2]
    d += ((x-lx)**2+(y-ly)**2)**0.5
print(d/len(perm))

Solution (Python):
import sys
import itertools

import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

import math
def calc():
    total = 0
    for i in range(1, N):
        x1, y1 = towns[i]
        x2, y2 = towns[i - 1]
        l = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
        total += l
    return total

ans = 0
def g(n):
    global ans
    if n == N:
        ans += calc()
        return
    for i in range(n, N):
        towns[i], towns[n] = towns[n], towns[i]
        g(n + 1)
        towns[i], towns[n] = towns[n], towns[i]

g(0)
print(ans / f(N))

Solution (Python):


from fractions import gcd

from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
import math

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

ret = 0
coms = permutations(range(N), N)

ct = 0
for com in coms:
    pt = pos[com[0]]
    for i in com[1:]:
        n = pos[i]
        ret += math.sqrt((pt[0]-n[0])**2 + (pt[1] - n[1])**2)
        pt = n
    ct += 1

print(ret / ct)

Solution (Python):
import itertools
import math

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

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

Solution (Python):
from itertools import permutations
n=int(input())
x=list(permutations([list(map(int,input().split())) for _ in range(n)]))
c=0.0
for i in x:
  a=i[0][0]
  b=i[0][1]
  for j in i[1:]:
    c+=((j[0]-a)**2+(j[1]-b)**2)**.5
    a=j[0]
    b=j[1]
print(c/len(x))

Solution (Python):
import math
from itertools import permutations


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

    dist = []
    for i in range(n):
        d = []
        for j in range(n):
            if i == j:
                d.append(0.0)
                continue
            x1, y1 = xy[i]
            x2, y2 = xy[j]
            d.append(math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2))
        dist.append(d)

    avg = 0
    perms = list(permutations(range(n)))
    for i in perms:
        d = 0
        for j in range(n)[:-1]:
            d += dist[i[j]][i[j + 1]]
        avg += d / len(perms)
    print(avg)


if __name__ == '__main__':
    main()

Solution (Python):
import math
import itertools

N = int(input())
x, y = [], []
for _ in range(N):
  a, b = map(int, input().split())
  x.append(a)
  y.append(b)
  
ans = 0
for r in itertools.permutations([i for i in range(N)]):
  for i in range(1, N):
    ans += math.sqrt((x[r[i]]-x[r[i-1]])**2 + (y[r[i]]-y[r[i-1]])**2)
ans /= math.factorial(N)
print(ans)

Solution (Python):
from itertools import permutations
import math

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


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

point = 0

for i in permutations(li):
    for j in range(1,n):
        point += length(i[j-1][0],i[j-1][1],i[j][0],i[j][1])

print(point/math.factorial(n))

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

for x1,y1 in xy:
    for x2,y2 in xy:
        X = x1-x2
        Y = y1-y2
        ans += (X**2+Y**2)**0.5

print(ans/n)

Solution (Python):
from math import factorial

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

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

print(cnt * 2 * factorial(N - 1) / factorial(N))

Solution (Python):
import sys
import itertools
import math
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    loc = [list(map(int,input().split())) for _ in range(n)]
    arr = list(itertools.permutations(loc))
    p = math.factorial(n)
    dis = 0
    for i in range(p):
        for j in range(n-1):
            dis += math.sqrt((arr[i][j+1][1]-arr[i][j][1])**2+(arr[i][j+1][0]-arr[i][j][0])**2)
    print(dis/p)
    
    
if __name__ == '__main__':
    main()

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

Solution (Python):
import itertools
import math
from statistics import mean

N = int(input())
towns = []
for i in range(N):
    xi,yi=map(int,input().split())
    towns.append([xi,yi])
order=[int(x) for x in range(N)]
root_time=[]
for one_order in itertools.permutations(order):
    root_t=0
    for i in range(len(one_order)-1):
        root_t += math.sqrt((towns[one_order[i]][0]-towns[one_order[i+1]][0])**2+(towns[one_order[i]][1]-towns[one_order[i+1]][1])**2)
    root_time.append(root_t)

print(mean(root_time))

Solution (Python):


import itertools
import math
n=int(input())
data=[]
for i in range(n):
  point=list(map(int,input().split()))
  data.append(point)
length=0
lis=[ x for x in range(n) ]
permutation=itertools.permutations(lis)
ansbig=0
for one_case in permutation:
  alldistance=0
  for k in range(n-1) :
    xk=data[one_case[k]][0]
    yk=data[one_case[k]][1]
    xknext=data[one_case[k+1]][0]
    yknext=data[one_case[k+1]][1]
    distance=((xk-xknext)**2+(yk-yknext)**2)**(1/2)
    alldistance+=distance
  ansbig+=alldistance
  
print(ansbig/math.factorial(n))

Solution (Python):



import itertools
import math

n = int(input())
xy_l = [[int(x) for x in input().split()] for y in range(n)]

per = itertools.permutations(list(range(n)))
num = math.factorial(n)
ans = 0
for order in per:
    _sum = 0
    for i in range(n-1):
        _sum += ((xy_l[order[i]][0] - xy_l[order[i+1]][0])**2
                 + (xy_l[order[i]][1] - xy_l[order[i+1]][1])**2)**0.5
    ans += _sum
print(ans/num)

Solution (Python):
from itertools import permutations
N=int(input())
town=[]
for i in range(N):
    x,y=map(int,input().split())
    town.append((x,y))

ans=0
for i,j in permutations(town,2):
    ans+=(((i[0]-j[0])**2+(i[1]-j[1])**2)**0.5)
print(ans/N)

Solution (Python):
import itertools
import math
n = int(input())
d = {}
for i in range(n):
  d[i] = list(map(int, input().split()))

p = [i for i in range(n)]
q = list(itertools.permutations(p, n))
arr = []
for i in range(len(q)):
  dis = 0
  for j in range(1, n):
    start = d[q[i][j - 1]]
    stop = d[q[i][j]]
    dis += math.sqrt((start[0] - stop[0]) ** 2 + (start[1] - stop[1]) ** 2)
  arr.append(dis)
ans = sum(arr) / len(q)
print(ans)

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

ans = 0
for p in itertools.permutations([i for i in range(N)]):
    for i,v in enumerate(p):
        x,y = position[v]
        if i == 0:
            nowx = x
            nowy = y
        else:
            ans += ((x-nowx)**2+(y-nowy)**2)**0.5
            nowx = x
            nowy = y

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

print(ans/pattern)

Solution (Python):
from math import sqrt
n=int(input())
x=[]
y=[]
for _ in range(n):
  a,b=map(int,input().split())
  x.append(a)
  y.append(b)

dist=0

for i in range(n-1):
  for j in range(i+1,n):
    d=(x[i]-x[j])**2+(y[i]-y[j])**2
    dist+=sqrt(d)
print(dist*2/n)

Solution (Python):
from itertools import permutations
N = int(input())
point = []
dist_sum = 0
per = 0

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

for p in permutations(point, N):
    for i in range(N - 1):
        dist_sum += ((p[i][0] - p[i + 1][0])**2 + (p[i][1] - p[i + 1][1])**2)**0.5
    per += 1

print(dist_sum / per)

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

ans = 0
l = list(permutations(xy,N))
for i in l:
  for j in range(N-1):
    ans += ((i[j][0] - i[j+1][0])**2 + (i[j][1] - i[j+1][1])**2)**0.5
print(ans/len(l))

Solution (Python):
import math
import itertools


def dist(x, y):
    return math.sqrt((y[1] - x[1]) ** 2 + (y[0] - x[0]) ** 2)


if __name__ == "__main__":
    N = int(input())

    towns = []
    for _ in range(N):
        x, y = [int(x) for x in input().split(" ")]
        towns.append((x, y))
    dists = []
    for route in itertools.permutations(range(N)):

        d = 0
        for i in range(N - 1):
            from_ = route[i]
            to = route[i + 1]
            d += dist(towns[from_], towns[to])
        dists.append(d)
    print(sum(dists) / len(dists))

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

def readinput():
    n=int(input())
    xyList=[]
    for _ in range(n):
        x,y=list(map(int,input().split()))
        xyList.append((x,y))
    return n,xyList

def main(n,xyList):
    sum=0.0
    factn=0
    for tup in permutations(range(n)):
        
        factn+=1
        x0=xyList[tup[0]][0]
        y0=xyList[tup[0]][1]
        for i in tup:
            x=xyList[i][0]
            y=xyList[i][1]
            sum+=sqrt((x-x0)**2+(y-y0)**2)
            x0=x
            y0=y
    ans=sum/factn
    return ans

if __name__=='__main__':
    n,xyList=readinput()
    
    ans=main(n,xyList)
    print(ans)

Solution (Python):
import itertools
n=int(input())
plot=[list(map(int,input().split())) for _ in range(n)]
lis=[]
for i in range(n):
    lis.append(i)

p=list(itertools.permutations(lis,n))


cnt=0
for j in range(len(p)):
    dis=0
    for k in range(n-1):
        dis+=((plot[p[j][k+1]][1]-plot[p[j][k]][1])**2+(plot[p[j][k+1]][0]-plot[p[j][k]][0])**2)**.5
    cnt+=dis
    
print(cnt/len(p))

Solution (Python):
import itertools
import math
N = int(input())
x_y = {i : list(map(int, input().split())) for i in range(N)}
P = list(itertools.permutations(range(N)))
tmp = 0
for p in P:
    for n in range(N-1):
        
        tmp += math.sqrt((x_y[p[n]][0] - x_y[p[n+1]][0])**2 + (x_y[p[n]][1] - x_y[p[n+1]][1])**2)

print(tmp/len(P))

Solution (Python):
import itertools
import math
N = int(input())
x_y = {i : list(map(int, input().split())) for i in range(N)}
P = list(itertools.permutations(range(N)))
tmp = 0
for p in P:
    for n in range(N-1):
        
        tmp += math.sqrt((x_y[p[n]][0] - x_y[p[n+1]][0])**2 + (x_y[p[n]][1] - x_y[p[n+1]][1])**2)

print(tmp/len(P))

Solution (Python):
from itertools import permutations
from math import sqrt
n = int(input())
town = []
for i in range(n):
    town_i = list(map(int,input().split()))
    town.append(town_i)

cnt = 0
length = 0
for j in permutations(range(n)):
    x,y = town[j[0]][0],town[j[0]][1]
    for k in range(1,n):
        length += sqrt((x-town[j[k]][0])**2+(y-town[j[k]][1])**2)
        x = town[j[k]][0]
        y = town[j[k]][1]
    cnt += 1

print(length/cnt)