Problem:
 Score : 300 points    Problem Statement There are N towns in a coordinate plane. Town i is located at coordinates ( x_i , y_i ). The distance between Town i and Town j is \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2} .  There are N! possible paths to visit all of these towns once. Let the length of a path be the distance covered when we start at the first town in the path, visit the second, third, \dots , towns, and arrive at the last town (assume that we travel in a straight line from a town to another). Compute the average length of these N! paths.      Constraints  2 \leq N \leq 8  -1000 \leq x_i \leq 1000  -1000 \leq y_i \leq 1000  \left(x_i, y_i\right) \neq \left(x_j, y_j\right) (if i \neq j )  (Added 21:12 JST) All values in input are integers.         Input Input is given from Standard Input in the following format:  N  x_1  y_1  :  x_N  y_N       Output Print the average length of the paths.
Your output will be judges as correct when the absolute difference from the judge's output is at most 10^{-6} .        Sample Input 1 3
0 0
1 0
0 1      Sample Output 1 2.2761423749  There are six paths to visit the towns: 1 → 2 → 3 , 1 → 3 → 2 , 2 → 1 → 3 , 2 → 3 → 1 , 3 → 1 → 2 , and 3 → 2 → 1 .  The length of the path 1 → 2 → 3 is \sqrt{\left(0-1\right)^2+\left(0-0\right)^2} + \sqrt{\left(1-0\right)^2+\left(0-1\right)^2} = 1+\sqrt{2} .  By calculating the lengths of the other paths in this way, we see that the average length of all routes is:  \frac{\left(1+\sqrt{2}\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)}{6} = 2.276142...       Sample Input 2 2
-879 981
-866 890      Sample Output 2 91.9238815543  There are two paths to visit the towns: 1 → 2 and 2 → 1 . These paths have the same length.       Sample Input 3 8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310      Sample Output 3 7641.9817824387

Solution (Python):
import itertools
import math
n=int(input())
empty_list=[]
a=[i for i in range(n)]
permutations_list=[list(b) for b in itertools.permutations(a)]
coordinate_list=[list(map(int,input().split())) for _ in range(n)]
for i in range(math.factorial(n)):
  for j in range(n-1):
    empty_list.append(math.sqrt((coordinate_list[(permutations_list[i][j]-1)][0]-coordinate_list[(permutations_list[i][j+1]-1)][0])**2+(coordinate_list[(permutations_list[i][j]-1)][1]-coordinate_list[(permutations_list[i][j+1]-1)][1])**2))
b=int(math.factorial(n))
c=sum(empty_list)
print(c*(n-1)/((n-1)*b))

Solution (Python):
import itertools

n = int(input())
lis = []
keep = [0, 1, 2, 3, 4, 5, 6, 7, 8]
keep = list(itertools.permutations(keep[:n]))
for i in range(n):
    s = list(map(int, input().split()))
    lis.append(s)
ans = 0
re_ans = 0
for j in range(len(keep)):
    for k in range(n - 1):
        ans = ((lis[keep[j][k]][0] - lis[keep[j][k + 1]][0])**2 +
               (lis[keep[j][k]][1] - lis[keep[j][k + 1]][1])**2)**(1 / 2)
        re_ans += ans
print(re_ans / len(keep))

Solution (Python):
import itertools

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

nums = [i for i in range(N)] 
numlist = list(itertools.permutations(nums))
L = []
for n in numlist:
  l = 0
  for i in range(N - 1):
    d = (XY[n[i]][0] - XY[n[i + 1]][0]) **2 + (XY[n[i]][1] - XY[n[i + 1]][1]) ** 2
    l += d ** (1/2)
  L.append(l)  
print(sum(L)/len(L))

Solution (Python):
import itertools, math

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

sum = 0

pathes = list(itertools.permutations(range(N), N))

for path in pathes:
    prev_x, prev_y = (x[path[0]], y[path[0]])
    for i in path:
        sum += ((x[i]-prev_x)**2 + (y[i]-prev_y)**2)**0.5
        prev_x, prev_y = (x[i], y[i])

print(sum / math.factorial(N))

Solution (Python):
from itertools import permutations as pm
n = int(input())
p = [tuple(map(int,input().split())) for _ in range(n)]
def dist(i,j):
    return ((p[i][0]-p[j][0])**2 + (p[i][1]-p[j][1])**2)**(0.5)
ans = 0
m = 0
for l in pm(range(n),n):
    m += 1
    s = 0
    for i in range(n-1):
        s += dist(l[i],l[i+1])
    ans += s
print(ans/m)

Solution (Python):
import itertools
import math
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
c=itertools.combinations(range(n),2)
lng=0
for a,b in c:
    x1,y1=l[a][0],l[a][1]
    x2,y2=l[b][0],l[b][1]
    lng+=((x2-x1)**2+(y2-y1)**2)**0.5
p=math.factorial(n-1)
print(lng*(p*2)/(p*n))

Solution (Python):
import sys
import itertools
import math

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    X = [0] * N
    Y = [0] * N

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

    load = list(itertools.permutations(range(N), N))

    

    ans = 0
    for l in load:
        for i in range(N - 1):
            s = l[i]
            g = l[i + 1]
            ans += math.sqrt(pow(X[s] - X[g], 2) + pow(Y[s] - Y[g], 2))

    ans /= len(load)
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

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

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

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

def mkdistancelist(N):
    List = list(map(str, [i for i in range(N)]))
    return list(itertools.combinations(List, 2))

def mkmap(N):
    placelist = []
    for i in range(N):
        place = list(map(int, input().split()))
        placelist.append(place)
    return placelist

def caldis(N):
    pairs = mkdistancelist(N)
    placelist = mkmap(N)
    dic = {}
    for pair in pairs:
        label = "".join(pair)
        dic[label] = distance(placelist[int(pair[0])], placelist[int(pair[1])])
    return dic

def mkwayslist(N):
    List = list(map(str, [i for i in range(N)]))
    return list(itertools.permutations(List, N))
            
def mknumdic(ways):
    numdic = {}
    for way in ways:
        for l in range(N-1):    
            tup = sorted((way[l], way[l+1]))
            tup = tup[0] + tup[1]
            if numdic.get(tup) == None:
                numdic[tup] = 1
            else:
                numdic[tup] = numdic[tup] + 1
    return numdic


N = int(input())
dic = caldis(N)
ways = mkwayslist(N)
numdic = mknumdic(ways)

av = np.average(np.array(list(dic.values())))
ans = av * (N-1)
print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
 
N = int(readline())
XY = np.array(read().split(),np.int64)
 
X = XY[::2]; Y = XY[1::2]
 
dx = X[:,None] - X[None,:]
dy = Y[:,None] - Y[None,:]
 
dist_mat = (dx * dx + dy * dy) ** .5
 
answer = dist_mat.sum() / N
print(answer)

Solution (Python):

import sys
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def dist(p, q):
    xdist = p[0] - q[0]
    ydist = p[1] - q[1]
    return (xdist**2 + ydist**2)**0.5


def main():
    N = int(readline())
    ps = [list(map(int, x.split())) for x in readlines()]
    total_dist = 0
    for p, q in itertools.combinations(ps, 2):
        total_dist += dist(p, q)

    ans = total_dist * 2 / N
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import itertools

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

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

dist = 0
n = 0
for route in itertools.permutations(spots, N):
    for i in range(N-1):
        start, goal = route[i], route[i+1]
        dist += ((xy[start][0]-xy[goal][0])**2 + (xy[start][1]-xy[goal][1])**2)**0.5
    n += 1

print(dist / n)

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

def rec(v, length, memo):
    memo[v] = 1

    if -1 not in memo:
        memo[v] = -1
        return length

    length_sum = 0
    for next_v in range(N):
        if memo[next_v] == -1:
            length_sum += rec(next_v, length+((xy[v][0]-xy[next_v][0])**2 + (xy[v][1]-xy[next_v][1])**2) ** 0.5, memo)

    memo[v] = -1
    return length_sum

ans = 0
n = 1
memo = [-1 for i in range(N)]
for i in range(N):
    ans += rec(i, 0, memo)
    n *= i+1

print(ans / n)

Solution (Python):
import math
import itertools


def main():
    N = int(input())
    xy = [list(map(int, input().split()))for _ in range(N)]
    comb = [x for x in range(N)]

    dist = 0

    for iter in itertools.permutations(comb):
        for i in range(1, N):
            dist += math.sqrt(pow(xy[iter[i-1]][0]-xy[iter[i]]
                                  [0], 2)+pow(xy[iter[i-1]][1]-xy[iter[i]][1], 2))

    dist = dist/math.factorial(N)
    print(dist)


if __name__ == '__main__':
    main()

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

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

root = list(permutations(array, N))

ans = 0
for i in range(len(root)):
    go = list(root[i])
    total = 0
    for j in range(1, N):
        total += sqrt(abs(x[go[j]]-x[go[j-1]])**2 + 
                abs(y[go[j]]-y[go[j-1]])**2)
    ans += total
print(ans/len(root))

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

n = int(input())

nf = factorial(n)

xy = []
X = 0
Y = 1

l = [i for i in range(n)]
s = 0

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


for p in permutations(l, n):
    p = list(p)
    for i in range(len(p) - 1):
        s += ((xy[p[i]][X] - xy[p[i+1]][X])**2 + (xy[p[i]][Y] - xy[p[i+1]][Y])**2)**0.5

print(s/nf)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

import itertools
l = [i for i in range(N)] 
bit = list(permutations(l))

cnt = 0
ans = 0
s = 0
for t in bit:
    
    
    for i in range(len(t)-1):
        
        a, b = L[t[i]][0], L[t[i]][1]
        c, d = L[t[i+1]][0], L[t[i+1]][1]
        s += sqrt((a - c) ** 2 + (b - d) ** 2)
    
    
    

ans = s / len(bit)
print(ans)

Solution (Python):
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


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


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
tmp = [None]*n
for i in range(n):
    tmp[i] = [None]*2

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

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

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

ans = 0
for i in itertools.permutations(xy):
    for j in range(len(i)-1):
        ans += math.sqrt((i[j][0] - i[j+1][0])**2 + (i[j][1] - i[j+1][1])**2)

print(ans/math.factorial(n))

Solution (Python):
N = int(input())
XY = [list(map(int, input().split())) for i in range(N)]
s = 0
import math
for i in range(N):
  for j in range(i+1,N):
    s += math.sqrt((XY[i][0]-XY[j][0])**2+(XY[i][1]-XY[j][1])**2)
    

    
ans = s*2/N
print(ans)

Solution (Python):
import itertools

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


ans = 0
lis = [x for x in range(n)]
permutation = itertools.permutations(lis)


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


cnt = 0
for case in permutation:
    cnt += 1
    for i in range(n - 1):
        ans += dist(a[case[i]], a[case[i + 1]])
print(ans / cnt)

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))

import decimal 
import math
D=decimal.Decimal
def resolve():
    N,=pin()
    p=[tupin() for i in range(N)]
    ans=0
    for j in range(N):
        x,y=p[j]
        X,Y=D(x),D(y)
        for k in range(N):
            a,b=p[k]
            A,B=D(a),D(b)
            ans+=math.sqrt((X-A)**2+(Y-B)**2)
    print(float(ans/N))

resolve()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
from math import sqrt, factorial
from itertools import permutations

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

def diff(i, j):
    tmp = (XY[i][0] - XY[j][0]) ** 2 + (XY[i][1] - XY[j][1]) ** 2
    return sqrt(tmp)


ans = 0

for tmp in permutations([i for i in range(N)]):
    score = 0
    for i in range(N - 1):
        score += diff(tmp[i], tmp[i + 1])
    ans += score

print (ans / factorial(N))

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

xy = [list(map(int, input().split())) for _ in range(N)]
Ns = [i for i in range(N)]
from itertools import permutations
from math import factorial, sqrt
ans = 0
for lis in permutations(Ns):
    tmp = 0
    for i in range(1, N):
        x1, y1 = xy[lis[i-1]]
        x2, y2 = xy[lis[i]]
        tmp += sqrt((x2-x1)**2+(y2-y1)**2)
    ans += tmp

print(ans/factorial(N))

Solution (Python):
from itertools import permutations
def dist(x,y):
    return ((x[0]-y[0])**2+(x[1]-y[1])**2)**0.5
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
tot = 0
cnt = 0
for z in permutations(range(N)):
    cnt += 1
    for i in range(1,N):
        tot += dist(X[z[i]],X[z[i-1]])
print(tot/cnt)

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

ans = []
X = 0
for v in itertools.permutations(list(range(n))):
  cnt = 0
  X += 1
  for i in range(n-1):
    x1,y1 = xy[v[0]][0], xy[v[0]][1]
    x2,y2 = xy[v[1]][0], xy[v[1]][1]
    cnt += ((x1-x2)**2 + (y1-y2)**2)**0.5
  ans.append(cnt)
print(sum(ans)/X)

Solution (Python):
N = int(input())
L = [[int(l) for l in input().split()] for _ in range(N)]

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

import math
import itertools
List = [int(i) for i in range(N)]
ans = 0
for P in itertools.permutations(List):
    d = 0
    for j in range(N-1):
        d += f(L[P[j]][0], L[P[j]][1], L[P[j+1]][0], L[P[j+1]][1])
    ans += d
print(ans/math.factorial(N))

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

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

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

ans = T*2/N
print(ans)

Solution (Python):
import sys
from itertools import permutations

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    XY = [list(map(int, input().split())) for _ in range(n)]

    def calc(x1, y1, x2, y2):
        return pow(pow(x1 - x2, 2) + pow(y1 - y2, 2), 0.5)

    dist = 0
    cnt = 0
    for pattern in permutations(list(range(n))):
        cnt += 1
        for i in range(1, n):
            x1, y1 = XY[pattern[i - 1]]
            x2, y2 = XY[pattern[i]]
            dist += calc(x1, y1, x2, y2)

    print(dist / cnt)


if __name__ == '__main__':
    resolve()

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

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

d = 0
import math
for i in range(N):
    for j in range(N):
        d += ((X[i]-X[j])**2+(Y[i]-Y[j])**2)**0.5

ans = d/N
print(ans)

Solution (Python):
N = int(input())
XY = [tuple(map(int,input().split())) for i in range(N)]
import itertools
from math import hypot
sm = k = 0
for ptn in itertools.permutations(XY):
    k += 1
    for (x1,y1),(x2,y2) in zip(ptn,ptn[1:]):
        sm += hypot(x1-x2, y1-y2)
print(sm / k)

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

def main():
    N,*xy = map(int, read().split())

    XY = []
    for x, y in zip(*[iter(xy)]*2):
        XY.append((x, y))

    ans = 0
    n = factorial(N)
    for p in permutations(range(N)):
        tmp = 0
        for i in range(N-1):
            u, v = p[i], p[i+1]
            a, b = XY[u]
            c, d = XY[v]
            dist = sqrt((a - c)**2 + (b - d)**2)
            tmp += dist
        ans += tmp

    ans /= n
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
N=int(input())
X=np.array([list(map(int,input().split())) for i in range(N)])
print(sum(np.linalg.norm(i-j) for i in X for j in X)/N)

Solution (Python):
import math
N = int(input())
A = []
dist = []


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


for i in range(N-1):
    for j in range(i+1,N):
        dist.append(math.sqrt((A[j][0] - A[i][0])**2 + (A[j][1] - A[i][1])**2))
print((sum(dist) * 2) / N)

Solution (Python):
from sys import stdin, setrecursionlimit


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

    sum = 0

    for i in range(n - 1):
        for j in range(i + 1, n):
            xi, yi = xy[i]
            xj, yj = xy[j]
            sum += ((xi - xj) ** 2 + (yi - yj) ** 2) ** 0.5

    print(2 * sum / (n * (n - 1)) * (n - 1))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
from itertools import combinations
import numpy as np
n=int(input())
array=[]
x=[list(map(int,input().split())) for i in range(n)]
cnt=0
for xi, yi in x:
  for xj, yj in x:
    cnt+=((xi-xj)**2+(yi-yj)**2)**0.5
print(cnt/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())

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

print(kyi * 2 / n)

Solution (Python):
import itertools
import math

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


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

print(ans)

Solution (Python):
import itertools
N=int(input())
XY=[]
for i in range(N):
  x,y=map(int,input().split())
  XY+=[[x,y]]
ALL=list(itertools.permutations(XY))
ans=10**9
d=0
for i in ALL:
  for k in range(N-1):
    d2=((i[k][0]-i[k+1][0])**2+(i[k][1]-i[k+1][1])**2)**(1/2)
    d+=d2
ans=d/len(ALL)
print(ans)

Solution (Python):

import math
import itertools

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


s_per = list(itertools.permutations(s))
N = len(s_per)

dist = 0


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


n_sum = 1
for i in range(n):
    n_sum *= (n-i)

print(dist/n_sum)

Solution (Python):
from itertools import permutations as per
from math import sqrt
n=int(input())
x=[]
y=[]
for _ in range(n):
    xx,yy=map(int,input().split())
    x.append(xx)
    y.append(yy)

sum=0
div=0
for jun in per(range(n)):
    div+=1
    for i in range(n-1):
        post=jun[i]
        pre=jun[i+1]

        sum+=sqrt((x[pre]-x[post])**2+(y[pre]-y[post])**2)

print(sum/div)

Solution (Python):
import math
import itertools

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

def kyori(junlist):
    sum=0
    for a in range(1,n):
        i=junlist[a-1]
        j=junlist[a]
        sum+=math.sqrt((xylist[i][0]-xylist[j][0])**2+(xylist[i][1]-xylist[j][1])**2)
    return sum

allsum=0
numlist=[i for i in range(n)]
junbanlist=[]
for v in itertools.permutations(numlist):
    junbanlist.append(list(v))

for jun in junbanlist:
    allsum+=kyori(jun)

print(allsum/math.factorial(n))

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

Solution (Python):
import math
import itertools


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


count = 0
sum_distance = 0
for points in itertools.permutations(point_list):
    x1, y1 = points[0]
    count += 1
    for point in points[1:]:
        x2, y2 = point
        distance = math.sqrt(((x1 - x2) ** 2) + (y1 - y2) ** 2)
        sum_distance += distance
        x1, y1 = x2, y2
    
print(sum_distance / count)

Solution (Python):
n = int(input())
mp_l = [list(map(int,input().split())) for i in range(n)]
div = 1
for i in range(1,n+1):
    div *= i
all_cnt = 0
from itertools import permutations
import math
m_l = [[0]*n for i in range(n)]
def calc(a,b):
    if(m_l[a][b]!=0):
        return m_l[a][b]
    num = (mp_l[a][0]-mp_l[b][0])**2+(mp_l[a][1]-mp_l[b][1])**2
    d = math.sqrt(num)
    m_l[a][b],m_l[b][a] = d,d
    return d

for l in permutations(range(n),n):
    for i in range(n-1):
        all_cnt += calc(l[i],l[i+1])

print(all_cnt/div)

Solution (Python):
n=int(input())
xy=[]
for i in range(n):
    xy.append([int(x) for x in input().split()])

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

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

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

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

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

rl = sys.stdin.readline
n = int(rl())
li = []
for _ in range(n):
  lis = list(map(int, rl().split()))
  li.append(lis)
t = 0
for i in list(itertools.permutations(range(n))):
  for k in range(n-1):
    s = (li[i[k]][0] - li[i[k+1]][0])**2 + (li[i[k]][1] - li[i[k+1]][1])**2
    t += s**0.5
print(t/math.factorial(n))

Solution (Python):
import numpy as np
n=int(input())
x=[0]*n
y=[0]*n
temp=[0]*n
for i in range(0,n):
  x[i],y[i]=map(int,input().split())
for i in range(0,n):
  for j in range(i+1,n):
    X=[abs(x[i]-x[j]),abs(y[i]-y[j])]
    temp.append(np.linalg.norm(X, ord=2))
print(sum(temp)*2/n)

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

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

from itertools import permutations
import math

lst=list(permutations(l))

ans_l=[]
len_l=len(lst)

for l_i in lst:
    tmp_dist=0
    for i in range(n-1):
        tmp_dist+=math.sqrt((xy[l_i[i]][0]-xy[l_i[i+1]][0])**2+(xy[l_i[i]][1]-xy[l_i[i+1]][1])**2)
    ans_l.append(tmp_dist)

print(sum(ans_l)/len_l)

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

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

Solution (Python):
from collections import deque
from itertools import permutations
from math import factorial
N = int(input())
places = [list(map(int, input().split())) for i in range(N)]
total = 0
for p in permutations(places):
  d = deque(p)
  departure = d.popleft()
  while d:
    arrival = d.popleft()
    total += ((departure[0] - arrival[0])**2 + (departure[1] - arrival[1])**2)**0.5
    departure = arrival
print(total / factorial(N))

Solution (Python):
import math

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


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

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

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

Solution (Python):
import math
n = int(input())
l = [list(map(int,input().split())) for _ in range(n)]
kumi= n*(n-1)/2 
keiro = math.factorial(n)
kaisu = keiro*(n-1)/kumi
total = 0

for i in range(n):
    a = 0
    for j in range(i+1,n):
        kyori = ((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)**0.5
        a += kyori*kaisu
    total += a

print(total/keiro)

Solution (Python):
import itertools

def dist(F,G):
  x1=F[0]
  x2=G[0]
  y1=F[1]
  y2=G[1]
  return ((x1-x2)**2+(y1-y2)**2)**0.5

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


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


patterns=itertools.permutations(B)
totlen=0
avelen=0
for lis in patterns:
  for i,l in enumerate(lis[:-1]):
    for j in lis[i+1:]:
      totlen+=dist(A[l],A[j])
      break



avelen=totlen/(paths(N))
print(avelen)

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

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

def calc (a,b,c,d):
    return math.sqrt(((a-b)**2)+((c-d)**2))

total = 0
for v in itertools.permutations(l):
    for i in range(len(v)):
        if i == n-1:
            pass
        else:
            total += calc(town[v[i]][0],town[v[i+1]][0],town[v[i]][1],town[v[i+1]][1])

print (total/math.factorial(n))

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

def distance(x1,x2,y1,y2):
    return math.sqrt(pow(x1-x2,2)+pow(y1-y2,2))
    
total= 0;
l=0
for i in range(n):
    d[i]=i
for b in itertools.permutations(d):
    l+=1
    
    for i in range(n-1):
        total += distance(a[b[i+1]][0],a[b[i]][0],a[b[i+1]][1],a[b[i]][1])
    
     
print(total/l)

Solution (Python):

import itertools
import math

n = int(input())
lis = [x for x in range(1,n+1)]
xy = [list(map(int,input().split())) for i in range(n)]
permutations_lis = itertools.permutations(lis)
l = list(permutations_lis)
ans = 0

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

Solution (Python):
import itertools
import math

n = int(input())
lis = [x for x in range(1,n+1)] 
xy = [list(map(int,input().split())) for i in range(n)]
permutations_lis = itertools.permutations(lis)
l = list(permutations_lis)
ans = 0

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

Solution (Python):
import itertools
import math

n = int(input())
xy = []
z = [k for k in range(n)]
for i in range(n):
    x,y = map(int,input().split())
    xy.append(x)
    xy.append(y)

sum = 0
for j in itertools.permutations(z,n):
    j = list(j)
    for l in range(n-1):
        sum += ((xy[2*(j[l])]-xy[2*(j[l+1])])**2+(xy[2*(j[l])+1]-xy[2*(j[l+1])+1])**2)**0.5

print(sum/math.factorial(n))

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

import math
import itertools

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

per = list(itertools.permutations(list(range(N)), N))

sum = 0
for i in per:
    for j in range(len(list(i))-1):
        x_ = x[i[j]] - x[i[j+1]]
        y_ = y[i[j]] - y[i[j+1]]
        sum += math.sqrt(x_**2 + y_**2)

print(sum / len(per))

Solution (Python):
import itertools
 
N = int(input())
xy = [0] * N
for i in range(N):
  xy[i] = list(map(int, input().split()))
  
lis = [x for x in range(N)] 
permutations_lis = itertools.permutations(lis)

divide = 0
ans = 0
for one_case in permutations_lis: 
  divide += 1
  
  for i in range(len(one_case) - 1):
    
    num = one_case[i]
    num2 = one_case[i + 1]
    ans +=  ((xy[num2][0] - xy[num][0]) ** (2) + (xy[num2][1] - xy[num][1]) ** (2)) ** (1/2)
    

print(ans / divide)

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

Solution (Python):
import itertools
import math

n = int(input())
coordinates = []

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

c = [num for num in range(n)]
pc = 0
dists = []
for p in itertools.permutations(c):
  pc += 1
  
  dist = 0
  for i in range(n-1):
    a = coordinates[p[i]]
    b = coordinates[p[i+1]]
    dist += math.sqrt( ((b[0] - a[0]) ** 2) + ((b[1] - a[1]) ** 2))
  dists.append(dist)
print(sum(dists) / pc)

Solution (Python):
import itertools
import math
n=int(input())
X=[list(map(int,input().split())) for _ in range(n)]
P=[i for i in range(n)]
total=0
for j in itertools.permutations(P,n):
  candi=list(j)
  for k in range(len(candi)-1):
    dis1=(X[candi[k]][0]-X[candi[k+1]][0])**2
    dis2=(X[candi[k]][1]-X[candi[k+1]][1])**2
    total+=(dis1+dis2)**(1/2)
print(total/math.factorial(n))

Solution (Python):
import math

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

dist = 0
from itertools import permutations
for p in permutations(town):
    for i in range(n-1):
         dist += math.sqrt((p[i][0] - p[i+1][0]) **2 + (p[i][1] - p[i+1][1]) **2)
ans = dist / math.factorial(n)
print(ans)
"""
dist = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        dist += math.sqrt((town[i][0] - town[j][0]) **2 + (town[i][1] - town[j][1]) **2)
ans = dist / n
print(ans)
"""