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())
L = []
for i in range(N):
    X, Y = map(int, input().split())
    L.append((X, Y))

total = 0
cnt = 0
for l in itertools.permutations(L):
    cnt += 1
    for i in range(1, N):
        total += math.sqrt((l[i][0]-l[i-1][0])**2 + (l[i][1]-l[i-1][1])**2)

print(total/cnt)

Solution (Python):
from itertools import permutations

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

perms = permutations(list(range(n)))
ans = 0
length = 0
for perm in perms:
    length += 1
    cur_i = 0
    tmp = 0
    for i in range(1, n):
        x = t[perm[cur_i]][0] - t[perm[i]][0]
        x = x**2
        y = t[perm[cur_i]][1] - t[perm[i]][1]
        y = y**2
        tmp += (x + y)**0.5
        cur_i = i
    ans += tmp
print(ans / length)

Solution (Python):
from itertools import permutations
N = int(input())
P = [tuple(map(int, input().split())) for _ in range(N)]
r = []
for pp in permutations(P):
    t = 0
    for i in range(1, N):
        t += ((pp[i][0]-pp[i-1][0])**2 + (pp[i][1]-pp[i-1][1])**2)**(0.5)
    r.append(t)
print(sum(r)/len(r))

Solution (Python):
def dist(x0, y0, x1, y1):
    from math import sqrt
    return sqrt((x1-x0)**2 + (y1-y0)**2)

from itertools import permutations

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

dsum = 0
for i, j in permutations(points, 2):
    dsum += dist(*i, *j)
print(dsum/N)

Solution (Python):
import itertools

n = int(input())
twn = [list(map(int, input().split())) for _ in range(n)]
twnst = list(itertools.permutations(twn))
dstttl = 0
for i in twnst:
    for j in range(0, len(i) - 1):
        dstttl += (abs(i[j][0] - i[j+1][0])**2 + abs(i[j][1] - i[j+1][1])**2)**0.5
print(dstttl / len(twnst))

Solution (Python):
import math

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

count = N * (N - 1) // 2
t = 0.0

for i in range(N):
    for j in range(i + 1, N):
        x1 = XY[i][0]
        y1 = XY[i][1]
        x2 = XY[j][0]
        y2 = XY[j][1]

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

print(t / count * (N - 1))

Solution (Python):
import math
N = int(input())
P = [tuple(map(int, input().split())) for _ in range(N)]
DONE = (1 << N) - 1

ds = []
todo = [(0, i, (1 << i)) for i in range(N)]
while todo:
    d, i, state = todo.pop()
    x, y = P[i]
    for ni in range(N):
        if state & (1 << ni):
            continue
        nx, ny = P[ni]
        nd = d + math.sqrt((x - nx) ** 2 + (y - ny) ** 2)
        nstate = state | (1 << ni)
        if nstate == DONE:
            ds.append(nd)
        else:
            todo.append((nd, ni, nstate))
ans = math.fsum(ds) / len(ds)
print(ans)

Solution (Python):
from itertools import permutations as per
n=int(input())
ans=[]
l=list(per(list(range(1,n+1))))
xy=[[] for i in range(n+1)]
for i in range(n):
    x,y=map(int,input().split())
    xy[i+1].append(x)
    xy[i+1].append(y)
def f(x):
    m=1
    while x>0:
        m*=x
        x=x-1
    return m
for i in range(f(n)):
    dis=0
    for j in range(n-1):
        dis+=((xy[l[i][j]][0]-xy[l[i][j+1]][0])**2+(xy[l[i][j]][1]-xy[l[i][j+1]][1])**2)**(0.5)
    ans.append(dis)
print(sum(ans)/f(n))

Solution (Python):
import math
N = int(input())
xy = []
length = 0
for i in range(N):
    x, y = map(int, input().split())
    if i!=0:
        for j in xy:
            length+=math.sqrt((x-j[0])**2+(y-j[1])**2)
    
    
    xy.append([x, y])
    
            
print(length*2/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 product, combinations,permutations
from copy import deepcopy
import sys
from math import sqrt
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    N = int(input())
    xy = []
    for _ in range(N):
        x, y = map(int, input().split())
        xy.append([x, y])
    
    visit_perm = list(range(N))
    sum_dist = 0
    cnt = 0
    for v in permutations(visit_perm):
        cnt += 1
        prev = -1
        for i, p in enumerate(v):
            if i==0:
                prev = [xy[p][0], xy[p][1]]
            else:
                sum_dist += sqrt((xy[p][0]-prev[0])**2+(xy[p][1]-prev[1])**2)
    print(sum_dist/cnt)

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

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

print(sum(l)/N)

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

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

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

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

p_list = itertools.permutations(lis)

s = 0

for one_case in p_list:
    prev = 0
    for i in range(n):
        if i == 0:
            prev = one_case[0]
        else:
            s += np.sqrt((xy[one_case[i]][0] - xy[prev][0])**2 + (xy[one_case[i]][1] - xy[prev][1])**2)
            prev = one_case[i]
print(s/math.factorial(n))

Solution (Python):
def dist (s1,s2):
    x1=s1[0]
    y1=s1[1]
    x2=s2[0]
    y2=s2[1]
    a=(x1-x2)**2+(y1-y2)**2
    return pow(a,0.5)
arr=[]
n=int(input())
for _ in range(n):
    inp=list(map(int,input().split()))
    arr.append((inp[0],inp[1]))
ans=0
for i in range(len(arr)):
    for j in range(len(arr)):
        ans+=dist(arr[i],arr[j])
print (ans/n)

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

Solution (Python):
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools

def main():
    n = int(input())
    path = list(itertools.permutations(list(range(n))))
    path_len = len(path)
    place = [list(map(int, input().split())) for i in range(n)]
    ans = 0
    for i in path:
        q = 0
        for k in range(n-1):
            q += ( (place[i[k+1]][0] - place[i[k]][0])**2 + (place[i[k+1]][1] - place[i[k]][1])**2 )**(1/2)
        ans += q
    print(ans/path_len)


if __name__=="__main__":
    main()

Solution (Python):
import math
import itertools

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

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

result = dis/math.factorial(n)

print(result)

Solution (Python):
import sys
import collections
import bisect


def main():
    n = int(input())
    under = 1
    for i in range(1, n + 1):
        under *= i

    xyList = [list(map(int, input().split())) for _ in range(n)]
    xyListSum = 0
    for xn in range(1, n):
        for yn in range(xn + 1, n + 1):
            leng = ((xyList[xn-1][0] - xyList[yn-1][0]) **
                    2 + (xyList[xn - 1][1] - xyList[yn - 1][1]) ** 2) ** 0.5
            xyListSum += leng * 2
    print(xyListSum / n)


if __name__ == '__main__':
    main()

Solution (Python):
import itertools

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


dist = 0
f = 0
for v in itertools.permutations(l, n):
    f += 1
    for i in range(1, n):
        x1, y1 = v[i-1]
        x2, y2 = v[i]
        dist += ((x1-x2)**2 + (y1-y2)**2)**0.5
res = round(dist/f, 10)
print(res)

Solution (Python):
class Town:
  def __init__(self,x,y):
    self.x = x
    self.y = y

from itertools import permutations

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

roots = list(permutations(towns))

distances = 0
for root in roots:
  distance = 0
  for i in range(len(root) - 1 ):
    start = root[i]
    end = root[i + 1]
    distance += ((start.x - end.x) ** 2 + (start.y - end.y) ** 2) ** (1 / 2)
  distances += distance

average = distances / len(roots)
print(average)

Solution (Python):
import itertools
import math
N=int(input())
z=[]
for _ in range(N):
    z.append(list(map(int,input().split())))
sum=0
for per in itertools.permutations(list(range(N))):
    for i in range(N-1):
        sum+=math.sqrt((z[per[i]][0]-z[per[i+1]][0])**2+(z[per[i]][1]-z[per[i+1]][1])**2)
ans=sum/math.factorial(N)
print(ans)

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

Solution (Python):
def main():
    from itertools import permutations
    from math import hypot

    N = int(input())

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

    ans = 0
    for perm in permutations(xys, r=2):
        x1, y1 = perm[0]
        x2, y2 = perm[1]
        d = hypot(x2 - x1, y2 - y1)
        ans += d
    ans /= N

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import math

n = int(input())

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

pmt = list(itertools.permutations(range(0, n)))

dis_sum = 0

for i in pmt:
    dis = 0
    for j in range(n-1):
        x1, y1 = location[i[j]]
        x2, y2 = location[i[j+1]]
        dis += math.sqrt((x1-x2)**2 + (y1-y2)**2)
    dis_sum += dis

print(dis_sum/len(pmt))

Solution (Python):
from itertools import combinations
N = int(input())
P = [tuple(map(int,input().split())) for _ in range(N)]

total = sum(((x0-x1)**2+(y0-y1)**2)**(1/2) for (x0,y0),(x1,y1) in combinations(P,2))

print(2*total/N)

Solution (Python):



import sys
readline = sys.stdin.readline

N = int(readline())
town = [None] * N
for i in range(N):
  town[i] = tuple(map(int,readline().split()))

from collections import defaultdict
dist = defaultdict(float)

for i in range(N - 1):
  for j in range(i + 1, N):
    ix,iy = town[i]
    jx,jy = town[j]
    dist[(i,j)] = ((ix - jx) ** 2 + (iy - jy) ** 2) ** 0.5
    

ans = 0
import itertools
for perm in itertools.permutations(range(N)):
  d = 0
  for i in range(1, len(perm)):
    a,b = perm[i - 1],perm[i]
    if a > b:
      a,b = b,a
    d += dist[(a, b)]
  ans += d
  
pat = 1
for i in range(2, N + 1):
  pat *= i
print(ans / pat)

Solution (Python):
import itertools

N = int(input())
data = [[int(e) for e in input().split(" ")] for _ in range(N)]

ans = 0
cnt = 0
for path in itertools.permutations([i for i in range(N)]):
    dis = 0
    cnt += 1
    for i in range(N - 1):
        u = path[i]
        v = path[i + 1]

        dis += ((data[u][0] - data[v][0]) ** 2 +
                (data[u][1] - data[v][1]) ** 2)**(1 / 2)

    ans += dis

ans /= cnt
print(ans)

Solution (Python):
import itertools


def length(a, b):
    x = (a[0] - b[0])**2
    y = (a[1] - b[1])**2
    
    return (x + y)**(1/2)

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

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

parms = list(itertools.permutations(machi, N))
ans = 0

for parm in parms:
    temp = 0
    for i in range(len(parm)-1):
        a = parm[i]
        b = parm[i+1]
        temp += length(zahyo[a], zahyo[b])
        
    ans += temp / len(parms)
    
print(ans)

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

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

Solution (Python):
import itertools

n=int(input())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])

narabi = [0+i for i in range(n)]

ans = 0
count = 0
for v in itertools.permutations(narabi, n):
    count += 1
    tmp_len = 0
    for i in range(1,n):
        x, y = abs(ab[v[i-1]][0]-ab[v[i]][0])**2, abs(ab[v[i-1]][1]-ab[v[i]][1])**2
        tmp_len += (x + y)**0.5
    ans += tmp_len

print(ans/count)

Solution (Python):
from itertools import permutations

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

s = 0
c = 0
for perm in permutations(range(N), N):
    c += 1
    for i in range(N-1):
        s += abs(points[perm[i]] - points[perm[i+1]])

print(s / c)

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())
P=[list(map(int,input().split())) for i in range(n)]
dist=0
for i in range(n-1):
    for j in range(i+1,n):
        dist+=((P[i][0]-P[j][0])**2+(P[i][1]-P[j][1])**2)**0.5
print(2*dist/n)

Solution (Python):
from itertools import permutations
from math import factorial
N = int(input())
data = []
for _ in range(N):
    x, y = map(int, input().split())
    data.append((x,y))
res = 0
for a in permutations(data,N):
    x0, y0 = a[0]
    for x, y in a[1:]:
        res += ((x-x0)**2 + (y-y0)**2)**(0.5)
        x0, y0 = x, y

print(res/factorial(N))

Solution (Python):


import math
import itertools


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


def get_distance(i: int, j: int) -> float:
    return math.sqrt(math.pow(x[i] - x[j], 2) + math.pow(y[i] - y[j], 2))

ans = 0
for path in itertools.permutations(range(N), N):
    distance = 0
    for i in range(N - 1):
        distance += get_distance(path[i], path[i + 1])
    ans += distance
ans /= math.factorial(N)


print(ans)

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

Solution (Python):
import itertools
import math

N = int(input())
xy = []
for _ in range(N):
    xi, yi = map(int, input().split())
    xy.append([xi, yi])



sum_dist = 0


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

ans = sum_dist / math.factorial(N)
print(ans)

Solution (Python):
N = int(input())
x = [0]*N
y = [0]*N
dist = [[0]*N]*N
ans = 0

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

for i in range(N):
  for j in range(N):
    dist[i][j]=((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
    ans += dist[i][j]

print(ans/N)

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

dist = 0
for i in ls:

    p0 = i[0]-1
    for j in range(1,len(i)):
        p1 = i[j]-1
        dist += ((x[p0]-x[p1])**2 + (y[p0]-y[p1])**2)**0.5
        p0=p1
        
    
        

print(dist/(len(ls)))

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

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

print(dist/n)

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

import itertools
pattern = itertools.permutations(xy, n)

import numpy as np

distances = []
for p in pattern:
    distance = 0
    for i, (x, y) in enumerate(p):
        if i == 0:
            base = (x, y)
            continue
    
        b_x, b_y = base
        d2 = (b_x - x) ** 2 + (b_y - y) ** 2
        d = np.sqrt(d2)
        distance += d
    
        base = (x, y)

    distances.append(distance)

print(np.mean(distances))

Solution (Python):
import itertools

N = int(input())
l = []
kyori = []

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

for i in itertools.combinations(l,2):
    t = ((i[0][0]-i[1][0])**2 + (i[0][1] - i[1][1])**2)**0.5
    kyori.append(t)

print((N-1)*sum(kyori)/len(kyori))

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

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

def dist_calc(i,j):
  return sqrt(pow(position[i][0]-position[j][0],2)
              +pow(position[i][1]-position[j][1],2))

ans = 0
mean = 0
for tmp in permutations(range(n)):
  for j in range(n-1):
    ans += dist_calc(tmp[j],tmp[j+1])
  mean += 1
print(ans/mean)

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


total_distance = 0
list_keiro = []
for team in itertools.permutations(range(n)):
    list_keiro.append(team)

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

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

print(total_distance / len(list_keiro))

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

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

N = I()

_XY = [LI() for _ in range(N)]

XY = np.array(_XY)





def calcdis(p1,p2):
    return np.linalg.norm(p2-p1)

ans = []
for i in range(N):
    tmp = 0
    for j in range(N):
        if not i==j:
            
            tmp += calcdis(XY[i],XY[j])
    ans.append(tmp)
print(np.average(ans))

Solution (Python):
import itertools

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


cnt=0
ans=0
num=[i for i in range(n)]
for i in itertools.permutations(num,n):
    cnt+=1
    for j in range(n-1):
        ans+=((l[i[j]][0]-l[i[j+1]][0])**2+(l[i[j]][1]-l[i[j+1]][1])**2)**0.5
print(ans/cnt)

Solution (Python):
n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]
from itertools import permutations
count = 0
dist = 0
for l in list(permutations(xy)):
    tmp = 0
    for i in range(len(l)-1):
        tmp += ((l[i+1][0]-l[i][0])**2+(l[i+1][1]-l[i][1])**2)**0.5
    dist += tmp
    count += 1

print(dist/count)

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


def calc_distance(i, j):
    return sqrt(pow((positions[i][0] - positions[j][0]), 2) + pow((positions[i][1] - positions[j][1]), 2))


ans = 0
count = 0
for tmp in permutations(range(n)):
    for i in range(len(tmp) - 1):
        ans += calc_distance(tmp[i], tmp[i + 1])
    count += 1

print(ans / count)

Solution (Python):
import itertools

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

town_name = []
for i in range(n):
    tmp_str_town_name = str(i)
    town_name.append(tmp_str_town_name)

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

distance = 0
for i in range(len(p)):
    one_path = p[i]
    for j in range(n - 1):
        l = int(one_path[j])
        r = int(one_path[j + 1])
        lx, ly = town_map[l]
        rx, ry = town_map[r]
        distance += ((rx - lx)**2 + (ry - ly)**2) ** (1/2)

print(distance / len(p))

Solution (Python):
import itertools

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

town_name = []
for i in range(n):
    tmp_str_town_name = str(i)
    town_name.append(tmp_str_town_name)

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

distance = 0
for i in range(len(p)):
    one_path = p[i]
    for j in range(n - 1):
        l = int(one_path[j])
        r = int(one_path[j + 1])
        lx, ly = town_map[l]
        rx, ry = town_map[r]
        distance += ((rx - lx)**2 + (ry - ly)**2) ** (1/2)

print(distance / len(p))

Solution (Python):
from itertools import permutations
import math

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

sum_roots = 0
for points in permutations(XY):
    for point_idx in range(1, N):
        before_x = points[point_idx-1][0]
        before_y = points[point_idx-1][1]
        x = points[point_idx][0]
        y = points[point_idx][1]
        sum_roots += math.sqrt((x-before_x) ** 2 + (y-before_y)**2)

print(sum_roots/math.factorial(N))

Solution (Python):
import itertools
def distance(a,b):
    return ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5
n = int(input())
a = [tuple(map(int,input().split())) for _ in range(n)]
l = []
for m in list(itertools.permutations(a)):
    d = 0
    for i in range(n-1):
        d += distance(m[i],m[i+1])
    l.append(d)
print(sum(l)/len(l))

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

Solution (Python):
import itertools

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


cases = list(itertools.permutations(list(range(n))))

length = 0
for case in cases:
  for i in range(n - 1):
    pos_1 = case[i]
    pos_2 = case[i + 1]
    position_1 = lst[pos_1]
    position_2 = lst[pos_2]
    
    length += ((position_1[0] - position_2[0]) ** 2 + (position_1[1] - position_2[1]) ** 2) ** 0.5
length = length / len(cases)
print(length)

Solution (Python):







































































global FLAG_LOG
FLAG_LOG = False


def log(value):
    
    
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    
    N = int(lines[0])
    
    
    
    
    
    
    valueses = list()
    for i in range(N):
        valueses.append(list(map(int, lines[i+1].split())))

    su = 0

    for i in range(N):
        for j in range(i+1, N):
            log(f'i=[{i}], j=[{j}]')
            xi, yi = valueses[i]
            xj, yj = valueses[j]
            distance = ((xi-xj)**2 + (yi-yj)**2) ** 0.5
            log(f'distance=[{distance}]')
            su += distance

    result = su / N * 2

    return [result]



def get_input_lines():
    line = input()
    N = int(line)
    lines = list()
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines



def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3', '0 0', '1 0', '0 1']
        lines_export = [2.2761423749]
    if pattern == 2:
        lines_input = ['2', '-879 981', '-866 890']
        lines_export = [91.9238815543]
    if pattern == 3:
        lines_input = ['8', '-406 10', '512 859', '494 362', '-955 -475', '128 553', '-986 -885', '763 77', '449 310']
        lines_export = [7641.9817824387]
    return lines_input, lines_export



def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode



def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    
    
    
    
    
    
    
    
    
    
    



if __name__ == '__main__':
    main()

Solution (Python):
def resolve():
    import itertools
    import math
    N = int(input())
    X = []
    Y = []
    for _ in range(N):
        x, y = map(int, input().split())
        X.append(x)
        Y.append(y)
    ans = 0
    ichi = 0
    for i in itertools.permutations(range(1, N+1)):
        count = 0
        for p in range(N-1):
            count += math.sqrt((X[i[p+1]-1]-X[i[p]-1])**2+(Y[i[p+1]-1]-Y[i[p]-1])**2)
        ans += count
        ichi += 1
    print(ans/ichi)
resolve()

Solution (Python):
import itertools

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

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

path = list(itertools.permutations(s, len(s)))

ans = 0

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

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
xy = inpll(n)

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

print(sum / len(l))

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


l = [list(map(int, input().split())) for i in range(n)]
total = 0
townnum = [i for i in range(n)]
for v in itertools.permutations(townnum):
    for j in range(1, n):
        cur = l[v[j]]
        bef = l[v[j-1]]
        total += math.sqrt((cur[0]-bef[0])**2+(cur[1]-bef[1])**2)
ans = total/math.factorial(n)
print('{:.9f}'.format(ans))

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

Solution (Python):
import math

N=int(input())
X=[0 for _ in range(N)]
Y=[0 for _ in range(N)]
for i in range(N):
  X[i],Y[i] = map(int, input().split())
s=0
for i in range(N):
  for j in range(N):
    if not i==j:
      s+=math.sqrt((X[i]-X[j])**2 + (Y[i]-Y[j])**2)*math.factorial(N-1)
print(s/math.factorial(N))

Solution (Python):
from itertools import permutations
from math import factorial
n = int(input())
t = [list(map(int, input().split())) for i in range(n)]
ans = 0
for p in permutations(range(n), n):
    ans += sum(((t[p[i]][0] - t[p[i + 1]][0])**2 + (t[p[i]][1] - t[p[i + 1]][1])**2)**0.5 for i in range(n - 1))
print(ans / factorial(n))

Solution (Python):
import math
from itertools import permutations

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

ave = 0

for p in permutations(coor, n):
    for i in range(n-1):
        ave += math.sqrt((p[i][0] - p[i+1][0])**2 + (p[i][1] - p[i+1][1])**2)

ans = ave/math.factorial(n)

print(ans)

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

Solution (Python):
import math
from itertools import combinations

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

roots = list(combinations(range(0,N),2))

sum_r = 0
for t, nt in roots:
  sum_r += math.sqrt((xy[t][0] - xy[nt][0])**2 + (xy[t][1] - xy[nt][1])**2)
  
res = 2*sum_r/N
print(res)

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

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

Solution (Python):
N=int(input())
xy=[list(map(int,input().split())) for i in range(N)]
print(sum(((xi-xj)**2+(yi-yj)**2)**.5 for xi,yi in xy for xj,yj in xy)/N)

Solution (Python):
import numpy as np
import statistics
N = int(input())
XY = np.array([tuple(map(int, input().split())) for i in range(N)])
ans = 0
for i in range(N):
    av = statistics.mean([np.linalg.norm(XY[i]-XY[j]) for j in range(N)])
    ans += av
print(ans)

Solution (Python):
import itertools
import math

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

res = 0
cnt = 0
for pattern in itertools.permutations(cities, len(cities)):
    cnt += 1
    for i in range(n - 1):
        res += math.sqrt(
            (dots[pattern[i]][0] - dots[pattern[i + 1]][0]) ** 2
            + (dots[pattern[i]][1] - dots[pattern[i + 1]][1]) ** 2)

print(res / cnt)

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

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