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())
coordinate = []
order = []
total = 0
count = 0

for i in range(N):
    order.append(i)
    coordinate.append(list(map(float,input().split())))



for vect in itertools.permutations(order):
    
    count+=1
    individual = 0.0
    for i in range(1,N):
        individual += ((coordinate[vect[i]][0]-coordinate[vect[i-1]][0])**2+(coordinate[vect[i]][1] - coordinate[vect[i-1]][1])**2)**0.5
    total +=individual

print(total/count)

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

N=[x for x in range(n)]

p_list = itertools.permutations(N)
n_num=math.factorial(n)

ans = 0
for i in p_list:
    step = 0
    j_prev = 0
    len = 0
    for j in i:
        if step == 0:
            j_prev=j
            step = 1
            continue
        len += math.sqrt((l[j][0]-l[j_prev][0])**2+(l[j][1]-l[j_prev][1])**2)
        j_prev=j
    ans += len/n_num
print(ans)

Solution (Python):
from collections import deque

def solve(N, X, Y):
    ret = 0
    counter = 0
    stack = deque()
    cities = [i for i in range(N)]
    for city_idx in cities:
        stack.append([0, city_idx, cities[:city_idx] + cities[city_idx + 1:]])

    while stack:
        dist, city_idx, rest = stack.pop()
        if not rest:
            ret += dist
            counter += 1

        for idx, next_city_idx in enumerate(rest):
            stack.append([dist + ((X[city_idx] - X[next_city_idx])**2 + (Y[city_idx] - Y[next_city_idx])**2)**(1/2), next_city_idx, rest[:idx] + rest[idx + 1:]])

    print(ret / counter)

if __name__ == "__main__":
    N = int(input())
    X = []
    Y = []

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

    solve(N, X, Y)

Solution (Python):
import math

n = int(input())

def distance(x1, y1, x2, y2):
    return math.sqrt((x1-x2)**2 + (y1-y2)**2)
distance_sum=0

c=[0]*n
for i in range(n):
    coordinate=list(map(int,input().split()))
    c[i]=coordinate


for i in range(n-1):
    for j in range(i+1,n):
        distance_sum+=distance(c[i][0],c[i][1],c[j][0],c[j][1])
    
distance_sum*=2
distance_sum*=(n-1)
distance_sum=distance_sum/(n*(n-1))

print(distance_sum)

Solution (Python):
import math

N = int(input())
xy = [map(int ,input().split()) for i in range(N)]
x,y = [list(i) for i in zip(*xy)]
d = 0
for i in range(N-1) :
    for j in range(i+1,N) :
        d += math.sqrt( (x[i]-x[j])**2 + (y[i] - y[j])**2 )

print(d*2/N)

Solution (Python):
import math
import itertools

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

sums = []
for li in list(itertools.permutations(range(n))):
    _sum = 0
    for i in range(n):
        if i == n - 1: continue
        dx = abs(xys[li[i]][0] - xys[li[i + 1]][0])
        dy = abs(xys[li[i]][1] - xys[li[i + 1]][1])
        _sum += math.sqrt(dx**2 + dy**2)
    sums.append(_sum)

print(sum(sums) / len(sums))

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

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

Solution (Python):
N = int(input())
X = []
Y = []
sum=0

for _ in range(N):
  x,y=map(int,input().split())
  for i, [x_,y_] in enumerate(zip(X,Y)):
    sum+=((x-x_)**2+(y-y_)**2)**(0.5)
  X.append(x)
  Y.append(y)

print(sum*2/N)

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

path_length = 0
cnt = 0
import itertools
for p in itertools.permutations(x):
    
    cnt += 1
    for (x1,y1), (x2,y2) in zip(p, p[1:]):
        path_length += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** .5

print(path_length/(cnt))

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

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

def dist(a, b):
    x1, y1 = a[0], a[1]
    x2, y2 = b[0], b[1]
    return sqrt((x1 - x2)**2 + (y1 - y2)**2)

ans = 0
for combo in permutations(range(N)):
    temp = 0
    for i in range(1, N):
        temp += dist(towns[combo[i]], towns[combo[i - 1]])
    ans += temp

print(ans / factorial(N))

Solution (Python):
import sys
readline = sys.stdin.buffer.readline

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

import math
def dist(coord1, coord2):
    return math.sqrt((coord1[0] - coord2[0]) ** 2 + (coord1[1] - coord2[1]) ** 2)

from itertools import permutations

sum = 0
count = 0
for p in permutations(XY):
    for i in range(N-1):
        sum += dist(p[i], p[i+1])

    count += 1

print(sum / count)

Solution (Python):

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

from itertools import permutations
a = range(N)
Ps = list(permutations(a))


keiro = []
for P in Ps:
    
    for i in range(N-1):
        keiro.append( ((xy[P[i]][0] - xy[P[i+1]][0])**2 + (xy[P[i]][1] - xy[P[i+1]][1])**2 )**0.5 )
out=sum(keiro)/len(Ps)

print(out)

Solution (Python):
import itertools
n = int(input())
m = []
for i in range(n):
    x,y = map(int,input().split())
    m.append((x,y))
check = list(itertools.permutations([i for i in range(n)]))
ans = 0
for i in check:
    for c,j in enumerate(i):
        if c == n-1:
            continue
        ans += ((m[j][0]-m[i[c+1]][0])**2+(m[j][1]-m[i[c+1]][1])**2)**0.5
for i in range(1,n+1):
    ans/=i
print(ans)

Solution (Python):
import itertools
import math
n = int(input())
a = [ int(x) for x in range(1,n+1)]
jun = list(itertools.permutations(a))
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]


sum = 0
for i in jun:
    for j in range(n-1):
        sum +=  math.sqrt((x[i[j]-1]-x[i[j+1]-1])**2 + (y[i[j]-1]-y[i[j+1]-1])**2)
print(sum/len(jun))

Solution (Python):
import itertools
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
p=list(itertools.permutations(range(n)))
ans=0
for i in p:
    for j in range(n-1):
        ans+=((l[i[j+1]][0]-l[i[j]][0])**2+(l[i[j+1]][1]-l[i[j]][1])**2)**0.5
print(ans/len(p))

Solution (Python):
from itertools import permutations
N = int(input())
comb = list(permutations([i for i in range(0, N)], N))
xy = []
for _ in range(N):
    x, y = map(int, input().split())
    xy.append([x, y])
ans = 0
for c in comb:
    for i in range(0, N-1):
        x = ((xy[c[i]][0] - xy[c[i+1]][0]) ** 2)
        y = ((xy[c[i]][1] - xy[c[i+1]][1]) ** 2)
        ans += (x + y) ** 0.5
print(ans/len(comb))

Solution (Python):
import math
import itertools

n = int(input())
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]
l = [i for i in range(n)]
a = float(0)

k = list(itertools.permutations(l,n))
for i in range(math.factorial(n)):   
    for j in range(n-1):
        a += (((x[k[i][j]]-x[k[i][j+1]]) ** 2) + ((y[k[i][j]]-y[k[i][j+1]]) ** 2)) ** 0.5
        
print(a/math.factorial(n))

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

N = int(input())

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

a = []
for i in range(N):
    a.append(list(map(int, input().split())))
    
total = 0
for i in permutations(a):
    for j in range(N-1):
        total += cal(i[j][0], i[j][1], i[j+1][0], i[j+1][1])
print(total / math.factorial(N))

Solution (Python):
import numpy as np
n=int(input())
sm=0
za=[]
def dis(x,y):
  x=np.array(x)
  y=np.array(y)
  return np.linalg.norm(x-y)
for i in range(n):
  za.append(list(map(int,input().split())))

for i in range(n):
  for j in range(n):
    sm+=dis(za[i],za[j])
print(sm/n)

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)
"""



from itertools import permutations
from math import hypot, factorial

n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
d = lambda x1,y1,x2,y2: ((x1-x2)**2 + (y1-y2)**2)**0.5

x = 0
for i in permutations(a):
	for j in range(n-1):
		x += d(i[j][0],i[j][1], i[j+1][0],i[j+1][1])


print(x / factorial(n))

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

n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
d = lambda x1,y1,x2,y2: ((x1-x2)**2 + (y1-y2)**2)**0.5

x = 0
for i in permutations(a):
	for j in range(n-1):
		x += d(i[j][0],i[j][1], i[j+1][0],i[j+1][1])


print(x / factorial(n))

Solution (Python):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)

from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction





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

    ans = 0
    count = 0
    for now_data in itertools.permutations([i for i in range(num)]):
        for i in range(num - 1):
            now_index = now_data.index(i)
            next_index = now_data.index(i + 1)
            dist = ((data[now_index][0] - data[next_index][0]) ** 2 + (data[now_index][1] - data[next_index][1]) ** 2) ** 0.5
            ans += dist
        count += 1
    ans /= count
    print(ans)





if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import math

n = int(input())
pos = []
for i in range(n):
  pos.append(tuple(map(int, input().split())))
l = list(itertools.permutations(pos))
sum = 0
for i in l:
  for j in range(len(i)-1):
    sum += math.sqrt((i[j][0] - i[j+1][0])**2 + (i[j][1] - i[j+1][1])**2)
print(sum / len(l))

Solution (Python):
import itertools
import math

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

s = 0
c = list(itertools.permutations(p, n))
for v in c:
    for i in range(n - 1):
        s += math.sqrt((v[i + 1][0] - v[i][0]) ** 2 + (v[i + 1][1] - v[i][1]) ** 2)
print(s * 1.0 / len(c))

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

def slove():
    n = int(input())
    P = [tuple(map(int,input().split())) for _ in range(n)]
    
    
    count = 0
    total_distance = 0
    for item in itertools.permutations(range(n)):
        
        count += 1
        for i in range(n-1):
            a = item[i]
            b = item[i+1]

            total_distance += math.sqrt((P[b][0]-P[a][0])**2+(P[b][1]-P[a][1])**2)
    print(total_distance/count)


if __name__ == "__main__":
    slove()

Solution (Python):
import itertools

n = int(input())
X = []
ans = 0
for i in range(n):
  X.append(tuple(map(int,input().split())))
ls = list(itertools.permutations(X))
for v in ls:
  for j in range(len(X)-1):
    ans += ((v[j][0] - v[j+1][0])**2 + (v[j][1] - v[j+1][1])**2)**0.5
print(ans/len(ls))

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

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

N=int(input())
towns=[tuple(map(int,input().split())) for _ in range(N)]
dis_town=[[0]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        dis_town[i][j]=distance(towns[i],towns[j])
combs=list(itertools.permutations(range(N)))
total=0
for comb in combs:
    for i in range(N-1):
        total+=dis_town[comb[i]][comb[i+1]]

print(total/len(combs))

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

N=int(input())
towns=[tuple(map(int,input().split())) for _ in range(N)]
ave=0
for i in range(N-1):
    for j in range(i,N):
        ave+=distance(towns[i],towns[j])
ave=ave/(N*(N-1)/2)
print(ave*(N-1))

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

Solution (Python):
from itertools import permutations
from math import factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def calc(a, b):
    x1, y1 = a
    x2, y2 = b
    return ((x1 - x2)** 2 + (y1 - y2)** 2)** 0.5


n = int(readline())
xy = [list(map(int, readline().split())) for _ in range(n)]
l = [i for i in range(n)]
ans = 0
for v in permutations(l):
    for i in range(n-1):
        ans += calc(xy[v[i]],xy[v[i+1]])

ans /= len(list(permutations(l)))
print(ans)

Solution (Python):
import math
import itertools

n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]
seq = [i for i in range(n)]
p = list(itertools.permutations(seq))
dist = 0
for i in p:
    for j in range(n-1):
        dist += math.sqrt((xy[i[j]][0] - xy[i[j+1]][0])**2 + (xy[i[j]][1] - xy[i[j+1]][1])**2)
print(dist/math.factorial(n))

Solution (Python):
import math

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

ans = 0

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

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

import itertools
li_c=list(itertools.permutations(range(N),2))

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

import math
distance=[]
for j in range(len(li_c)):
    distance.append(math.sqrt((rocation[li_c[j][0]][0]-rocation[li_c[j][1]][0])**2+(rocation[li_c[j][0]][1]-rocation[li_c[j][1]][1])**2))

print(sum(distance)/N)

Solution (Python):
import itertools
import math


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


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

com = list(itertools.combinations(idList, 2))


ans = 0

for i, j in com:
    tar1 = data[i]
    tar2 = data[j]

    add = (tar1[0] - tar2[0]) ** 2 + (tar1[1] - tar2[1]) ** 2
    ans += math.sqrt(add)

ans = ans * 2 / float(n)


print(ans)

Solution (Python):

def main():
    import sys, itertools as ite
    import math
    N = int(sys.stdin.readline())
    XY = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
    
    P = tuple(ite.permutations([i for i in range(N)]))
    
    
    def d_calc(A, B):
        return math.sqrt((A[0]-B[0])**2 + (A[1]-B[1])**2)
    
    ans = 0
    for i in range(len(P)):
        for j in range(N-1):
            ans += d_calc(XY[P[i][j+1]], XY[P[i][j]])
    print(ans/len(P))
  

if __name__=='__main__':
    main()

Solution (Python):
import math
import itertools

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

data=[]
for case in itertools.permutations(range(n)):
  dist = 0.0
  for i in range(n-1):
    x1,y1=plot[case[i]]
    x2,y2=plot[case[i+1]]
    dist += math.sqrt((x1-x2)**2+(y1-y2)**2)
  data.append(dist)
print(sum(data)/len(data))

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

for x1,y1 in a:
    for x2,y2 in a:
        ans += ((x1-x2)**2+(y1-y2)**2)**0.5
print(ans/n)

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

import itertools
import math
seq = range(n)
p=list(itertools.permutations(seq))

dis=0
for index,item in enumerate(p):
  for i in range(n-1):
    dis_tmp = 0
    dis_tmp += ( xy[item[i+1]][0] - xy[item[i]][0] ) ** 2
    dis_tmp += ( xy[item[i+1]][1] - xy[item[i]][1] ) ** 2
    dis += math.sqrt(dis_tmp)
dis /= (len(p))
print(dis)

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

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

average=(total/(math.factorial(N)))
print(average)

Solution (Python):
import itertools

N = int(input())

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

S = 0


route = list(itertools.combinations(P, 2))



for i in route:
  
   S += ((i[0][0] - i[1][0])**2 + (i[0][1] - i[1][1])**2)**0.5
   
print(S*2/N)

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

import itertools
all_route=list(itertools.permutations(xy))

length=0
for route in all_route:
    i=1
    while i<N:
        length+=((route[i][0]-route[i-1][0])**2+(route[i][1]-route[i-1][1])**2)**0.5
        i+=1

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

Solution (Python):
from math import sqrt, factorial

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

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

print(distance/N)

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

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

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

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


print(soukyori * 2 / n)

Solution (Python):
import sys
import numpy as np
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
xy = []
for _ in range(N):
  x,y = map(int, readline().split())
  xy.append((x,y))
sum = 0
for i in range(N):
  for j in range(i+1,N):
    x1,y1 = xy[i]
    x2,y2 = xy[j]
    dist = math.sqrt((x1-x2)**2 + (y1-y2)**2)
    sum += dist
ans = 2*sum/N
print('{:.7f}'.format(ans))

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


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

goukei=0

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


T=[]
for i in range(N):
    T.append(i)


D=list(itertools.permutations(T))
for Z in D:

    for j in range(N-1):
        goukei+=math.sqrt((S[Z[j]][0]-S[Z[j+1]][0])**2+(S[Z[j]][1]-S[Z[j+1]][1])**2)
print(goukei/divide)

Solution (Python):
import itertools

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

distance = 0
for c in itertools.combinations(range(N), 2):
    c1, c2 = c
    distance += ((cities[c1][0] - cities[c2][0]) ** 2 + (cities[c1][1] - cities[c2][1]) ** 2) **0.5

answer = 2 * distance / N

print(answer)

Solution (Python):
import itertools
import math


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

distance = 0
for c in itertools.combinations(range(N), 2):
    c1, c2 = c
    distance += ((cities[c1][0] - cities[c2][0]) ** 2 + (cities[c1][1] - cities[c2][1]) ** 2) **0.5

answer = 2 * distance * (N-1) * math.factorial(N-2) / math.factorial(N)

print(answer)

Solution (Python):

import math
import itertools
N = int(input())
X = [0] * N
Y = [0] * N
L = [n for n in range(N)]

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

dist = 0
cnt = 0
for i in itertools.permutations(L, N):
    cnt += 1
    for n in range(1,N):
        dist += math.sqrt( (X[i[n]]-X[i[n-1]]) ** 2 + (Y[i[n]]-Y[i[n-1]]) ** 2 )
print(dist / cnt)

Solution (Python):
import math
from itertools import permutations

N = int(input())
town_index = [i for i in range(N)]
town = []
sum_length = 0
for i in range(N):
    x, y = map(int, input().split())
    town.append([x, y])

all_routes = list(permutations(town_index))
for root in all_routes:
    length = 0
    for i in range(1, N):
        length += math.sqrt((town[root[i-1]][0] - town[root[i]][0]) ** 2 + (town[root[i-1]][1] - town[root[i]][1]) ** 2)
    sum_length += length

print(sum_length / len(all_routes))

Solution (Python):
import math
from itertools import permutations

N = int(input())
town_index = [i for i in range(N)]
town = []
sum_length = 0
for i in range(N):
    x, y = map(int, input().split())
    town.append([x, y])

all_routes = list(permutations(town_index))
for root in all_routes:
    length = 0
    for i in range(1, N):
        length += math.sqrt((town[root[i-1]][0] - town[root[i]][0]) ** 2 + (town[root[i-1]][1] - town[root[i]][1]) ** 2)
    sum_length += length

print(sum_length / len(all_routes))

Solution (Python):
import itertools

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

ans = 0
cnt = 0
for pat in itertools.permutations(zahyo):
    cnt += 1
    for i in range(len(pat)-1):
        distance = ((pat[i][0]-pat[i+1][0])**2 + (pat[i][1]-pat[i+1][1])**2)**(1/2)
        ans += distance
print(ans/cnt)

Solution (Python):

"""
C - Average Length
https://atcoder.jp/contests/abc145/tasks/abc145_c

"""
import sys


from itertools import permutations
from statistics import mean

def solve(N, points):
    dists = []
    for p in permutations(points):
        x = 0.0
        for a, b in zip(p, p[1:]):
            x += ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5
        dists.append(x)
    return mean(dists)


def main(args):
    N = int(input())
    points = [list(map(int, input().split())) for _ in range(N)]
    ans = solve(N, points)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
import math
N = int(input())
x, y = [], []
for i in range(N):
  tmp = list(map(int, input().split()))
  x.append(tmp[0])
  y.append(tmp[1])
  
num = 1
for i in range(N, 0, -1):
  num *= i
total1 = num*(N-1)
total2 = N*(N-1)/2
b = total1/total2

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

Solution (Python):
import itertools
import math

def calc(xy1, xy2):
    return (math.sqrt((xy1[0]-xy2[0])**2 + (xy1[1]-xy2[1])**2))

N = int(input())

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

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

ans = 0
for i in p_list:
    for j in range(1, len(i)):
        ans += calc(x_y[i[j]], x_y[i[j-1]])

print(ans/math.factorial(N))

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

a = np.zeros((N, 2))
kyori = np.zeros(int(N*(N-1)/2))

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


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

print(2*sum(kyori)*(N-1)*math.factorial(N-2)/math.factorial(N))

Solution (Python):
import itertools
import math

N = int(input())

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

loots = list(itertools.permutations(range(1,N+1)))


goukei = 0
for loot in loots:

    for index, value in enumerate(loot[1:N]):

        goukei += math.sqrt((xys[loot[index]-1][0] - xys[loot[index-1]-1][0]) ** 2 + (xys[loot[index]-1][1] - xys[loot[index-1]-1][1]) ** 2)




print(goukei / len(loots))

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

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

import itertools
import math
per=list(itertools.permutations(xy))

N=math.factorial(n)
ans=0
for i in range(N):
    sum=0
    p=per[i]
    for j in range(n):
        if j!=n-1:
            sum+=distance(p[j][0],p[j][1],p[j+1][0],p[j+1][1])
    ans+=sum
print(ans/N)

Solution (Python):
import math
import itertools
 
N = int(input())
XY = [list(map(int, input().split())) for x in range(N)]
 
P = list(itertools.permutations(XY, N))
 
total = 0
for p in P:
    for i in range(1, N):
        a = p[i - 1]
        b = p[i]
        total += math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
        
ans = total / len(P)
print(ans)

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

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

all_sum = 0

for i in permutations(range(N)):
    for j in range(len(i) - 1):
        all_sum += sqrt((xy[i[j]][0] - xy[i[j + 1]][0]) ** 2 +
                        (xy[i[j]][1] - xy[i[j + 1]][1]) ** 2)


print(all_sum / factorial(N))

Solution (Python):
from math import sqrt, factorial

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

all_sum = 0

for i in range(N):
    xi, yi = xy[i]
    for j in range(i + 1, N):
        xj, yj = xy[j]
        all_sum += sqrt((xi - xj) ** 2 + (yi - yj) ** 2)

fN = factorial(N - 1)

all_sum /= fN * N
all_sum *= fN * 2

print(all_sum)

Solution (Python):
from math import sqrt, factorial

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

all_sum = 0

for i in range(N):
    xi, yi = xy[i]
    for j in range(i + 1, N):
        xj, yj = xy[j]
        all_sum += sqrt((xi - xj) ** 2 + (yi - yj) ** 2)

fN = factorial(N)

all_sum /= fN
all_sum *= factorial(N - 1) * 2

print(all_sum)

Solution (Python):
import math
import itertools

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

P = list(itertools.permutations(XY, N))

total = 0
for p in P:
  for i in range(1, N):
    a = p[i-1]
    b = p[i]
    total += math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)

print(total / len(P))

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

res = 0
cnt = 0
for pair in list(permutations(range(N), N)):
  for i in range(N):
    if i+1 == N: continue
    x,y = pair[i], pair[i+1]
    x_y = math.sqrt( (C[x][0]-C[y][0])**2 + (C[x][1]-C[y][1])**2 )
    res += x_y
  cnt += 1

print(res / cnt)

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

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

ans = 0
for ps in permutations(p, n):
    x1, y1 = ps[0]
    for i in range(n):
        x2, y2 = ps[i]
        ans += hypot(x1-x2, y1-y2)
        x1, y1 = x2, y2
ans /= factorial(n)
print(ans)

Solution (Python):
import itertools
import math
def dist(i, j):
    return math.sqrt((coords[i][0] - coords[j][0]) ** 2 + (coords[i][1] - coords[j][1]) ** 2)

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

ans = []
for item in itertools.permutations(range(n)):
    length = 0
    for i in range(n-1):
        length += dist(item[i], item[i+1])
    ans.append(length)
print(sum(ans) / len(ans))

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

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

def dist(a, b):
   x1, y1 = a
   x2, y2 = b
   return pow((x1-x2) ** 2 + (y1-y2) ** 2, 1/2)

res = 0
for i in range(N):
   for j in range(i+1, N):
      res += dist(coord[i], coord[j]) * 2 / N

print(res)

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

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

def dist(a, b):
   x1, y1 = a
   x2, y2 = b
   return pow((x1-x2) ** 2 + (y1-y2) ** 2, 1/2)

res = 0
div = factorial(N)
idx = [i for i in range(N)]
for line in permutations(idx, N):
   for i in range(N-1):
      res += dist(coord[line[i]], coord[line[i+1]]) / div

print(res)

Solution (Python):
import itertools

n = int(input())
X = []
for _ in range(n):
    X.append(list(map(int, input().split())))
L = 0
count = 0
for xl in itertools.permutations(X):
    l = 0
    pre = []
    for x in xl:
        if len(pre) > 0:
            l += ((x[0] - pre[0]) ** 2 + (x[1] - pre[1]) ** 2) ** (1/2)
        pre = x
    L += l
    count += 1

print(L / count)

Solution (Python):


import itertools
import math

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

lensum=0
for i in itertools.permutations(r):
    for j in range(N-1):
        length=((i[j][0]-i[j+1][0])**2+(i[j][1]-i[j+1][1])**2)**0.5
        lensum+=length
        
print(lensum/math.factorial(N))

Solution (Python):
import itertools
import math

N = int(input())
permutation = list(itertools.permutations([x for x in range(1, N + 1)]))
coordinate = [list(map(int, input().split())) for _ in range(N)]
distances = []

for one_case in permutation:
    sum_dis = 0
    for j in range(N - 1):
        dis = math.sqrt((coordinate[one_case[j] - 1][0] - coordinate[one_case[j + 1] - 1][
            0]) ** 2 + (coordinate[one_case[j] - 1][1] - coordinate[one_case[j + 1] - 1][
            1]) ** 2)
        sum_dis += dis
    distances.append(sum_dis)
print('{:.7f}'.format(sum(distances) / len(permutation)))

Solution (Python):
import itertools
N=int(input())
retu=[i for i in range(N)]
XY=[]
for i in range(N):
    x=list(map(int,input().split()))
    XY.append(x)
permi=list(itertools.permutations(retu))
goukei=0
count=0
for i in permi:
    count+=1
    for k in range(1,N):
        a=XY[i[k - 1]][0]- XY[i[k]][0]
        b=XY[i[k - 1]][1]- XY[i[k]][1]
        goukei+=(a**2+b**2)**0.5
print(goukei/count)

Solution (Python):
import itertools
import numpy as np
N=int(input())
retu=[i for i in range(N)]
XY=[]
for i in range(N):
    x=list(map(int,input().split()))
    XY.append(x)
permi=list(itertools.permutations(retu))
goukei=0
count=0
for i in permi:
    count+=1
    for k in range(1,N):
        a=XY[i[k - 1]][0]- XY[i[k]][0]
        b=XY[i[k - 1]][1]- XY[i[k]][1]
        goukei+=(a**2+b**2)**0.5
print(goukei/count)

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

n = int(input())

towns = []

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

towns = np.array(towns)

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

for i in range(n):
    for j in range(n):
        l[i, j] = np.sum((towns[i] - towns[j])**2) ** 0.5

ans = 0
for order in itertools.permutations(range(n), n):
    now = order[0]
    f = 0
    for i in order[1:]:
        f += l[now, i]
        now = i
    ans += f
print(ans/math.factorial(n))