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 sys

input = sys.stdin.buffer.readline






from itertools import permutations
import math


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

	nsum=math.factorial(n)

	ans=0
	tmp=0

	for i in permutations(range(n),n):
		tmp=0
		for j in range(n-1):
			x0=li[i[j]][0]
			x1=li[i[j+1]][0]
			y0=li[i[j]][1]
			y1=li[i[j+1]][1]
			tmp+=((x0-x1)**2+(y0-y1)**2)**0.5
		ans+=tmp/nsum
	print(ans)


if __name__ == "__main__":
	main()

Solution (Python):
import sys

input = sys.stdin.buffer.readline






from itertools import permutations
import math


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

	nsum=math.factorial(n)

	ans=0
	tmp=0

	for i in permutations(range(n),n):
		tmp=0
		for j in range(n-1):
			x0=li[i[j]][0]
			x1=li[i[j+1]][0]
			y0=li[i[j]][1]
			y1=li[i[j+1]][1]
			tmp+=((x0-x1)**2+(y0-y1)**2)**0.5
		ans+=tmp/nsum
	print(ans)


if __name__ == "__main__":
	main()

Solution (Python):
from math import sqrt
n = int(input())
xy = [[int(i) for i in input().split()] for _ in range(n)]
def d(a, b):
    return sqrt((a[0] - b[0])** 2 + (a[1] - b[1])** 2)

s = 0
for i in range(n):
    for j in range(i + 1, n):
        s += d(xy[i], xy[j])
s /= n / 2
print(s)

Solution (Python):
import math
import itertools
def main():
    n = int(input())
    x = []
    y = []
    for i in range(n):
        xx,yy = map(int, input().split())
        x.append(xx)
        y.append(yy)
    ans = 0.0
    dist = [[0.0] * n for i in range(n)]
    for i in range(n):
        for j in range(i+1,n):
            dist[i][j] = cal_dist(x[i],y[i],x[j],y[j])
            dist[j][i] = dist[i][j]
    r = []
    for i in range(n):
        r.append(i)
    cnt = 0
    for perm in itertools.permutations(r,n):
        p = list(perm)
        cnt += 1
        for i in range(1,n):
            ans += dist[p[i-1]][p[i]]

    ans /= cnt
    print(ans)



def cal_dist(x1,y1,x2,y2):
    a = x1 -x2
    b = y1 - y2
    retval = a ** 2 + b ** 2
    return math.sqrt(retval)

if __name__ == '__main__':
    main()

Solution (Python):
import math

n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
d = 0
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)
print(d / n)

Solution (Python):
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 += ((a[i][0]-a[j][0])**2 + (a[i][1]-a[j][1])**2)**0.5
print(ans/n)

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

for l in list(permutations(xy)):
    d=0.0
    for i in range(len(l)-1):
        d+=((l[i+1][0]-l[i][0])**2+(l[i+1][1]-l[i][1])**2)**0.5
    dist.append(d)
print(sum(dist)/len(dist))

Solution (Python):
import itertools
import math

N = int(input())

d = {}
for i in range(N):
    d[i+1] = list(map(int, input().split()))

pattern = itertools.permutations(range(1,N+1),  N)

ans = 0

for p in pattern:
    before = ()
    count = 0
    for place in p:
        if before:
            count += math.sqrt((d[before][0] - d[place][0])**2 + (d[before][1] - d[place][1])**2)
        before = place
    ans += count

ans /= math.factorial(N)

print(ans)

Solution (Python):
import math
import itertools

N = int(input())

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

ans = 0
for i in itertools.permutations(range(0, N), N):
	for j in range(1, N):
		ans += ((x[i[j]] - x[i[j - 1]]) ** 2 + (y[i[j]] - y[i[j - 1]]) ** 2) ** 0.5

print(ans / math.factorial(N))

Solution (Python):
import math

N=int(input())
X=[]
Y=[]
for i in range(N):
	x,y=map(int,input().split())
	X.append(x)
	Y.append(y)
L=[]
for i in range(N-1):
	for j in range(i,N):
		l=math.sqrt(((X[i]-X[j])**2)+((Y[i]-Y[j])**2))
		L.append(l)
ans=sum(L)*(2/N)
print(ans)

Solution (Python):
import math

N=int(input())
X=[]
Y=[]
for i in range(N):
	x,y=map(int,input().split())
	X.append(x)
	Y.append(y)
L=[]
for i in range(N-1):
	for j in range(i,N):
		l=math.sqrt(((X[i]-X[j])**2)+((Y[i]-Y[j])**2))
		L.append(l)
kai=(math.factorial(N))
ans=sum(L)*((kai*2)/N)/kai
print(ans)

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

import itertools
import math
pe=itertools.permutations(range(n))
pe=list(pe)
ans=0

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

Solution (Python):
import math
from itertools import permutations

def f(i, j):
  return ((XY[i][0] - XY[j][0]) ** 2 + (XY[i][1] - XY[j][1]) ** 2) ** .5

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

ptn = permutations(range(n))

diff = 0
for p in ptn:
  diff += sum([f(i, j) for i, j in zip(p, p[1:])])
ans = diff / math.factorial(n)

print(ans)

Solution (Python):
import itertools as it
n=int(input())
xy_li=[list(map(int,input().split())) for i in range(n)]
li=[i for i in range(n)]
pattern=list(it.permutations(li))

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

print(ans/len(pattern))

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

import itertools
import math

f = [1]*n

for i in range(1, n):
	f[i]= f[i-1]*(i+1)
    
permutations_lis = itertools.permutations(xy)

total_d = 0
for one_case in permutations_lis: 
  x_cur = None
  y_cur = None
  d = 0
  for x, y in one_case:
    
    if x_cur is None:
      x_cur = x
      y_cur = y
    else:
      d += math.sqrt((x_cur-x)**2 + (y_cur-y)**2)
      
      x_cur, y_cur = x, y
      
  total_d += d
      
print(total_d/f[n-1])

Solution (Python):


from itertools import permutations

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

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


for p in P:
    for i in range(n-1):
        cnt+=dst(p[i][0],p[i+1][0],p[i][1],p[i+1][1])

print(cnt/len(P))

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

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

ans = 0
for i in range(len(route)):
  for j in range(N-1):
    a = route[i][j]
    b = route[i][j + 1]
    X = (xy[a][0] - xy[b][0]) ** 2
    Y = (xy[a][1] - xy[b][1]) ** 2
    ans += (X + Y) ** 0.5
print(ans / len(route))

Solution (Python):
import itertools
def d(x,y):
    return ((x[0]-y[0])**2+(x[1]-y[1])**2) ** 0.5

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

c = 0
for p in itertools.permutations(range(N)):
    c += 1
    for i in range(N-1):

        r += d(X[p[i]], X[p[i+1]])
print(r/c)

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

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

Solution (Python):

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

ans = 0
tmp = list(itertools.permutations(range(n)))
for i in range(len(tmp)):
    for j in range(len(tmp[i]) - 1):
        tmp2 = tmp[i][j + 1]
        tmp3 = tmp[i][j]
        ans += pow((pow(xy[tmp2][0] - xy[tmp3][0], 2) + pow(xy[tmp2][1] - xy[tmp3][1], 2)), 0.5)
ans /= len(tmp)
print(ans)

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
XY = [tuple(map(int,input().split())) for i in range(n)]
for jun in itertools.permutations(range(n),n):
  cost = 0
  for i in range(1,n):
    cost += math.sqrt((XY[jun[i]][0]-XY[jun[i-1]][0])**2+(XY[jun[i]][1]-XY[jun[i-1]][1])**2)
  ans += cost
print(ans/math.factorial(n))

Solution (Python):
from itertools import permutations
n = int(input())
x,y=[],[]
for i in range(n):
    X,Y=map(int,input().split())
    x.append(X)
    y.append(Y)
kaijo=1
for i in range(1,n+1):
    kaijo *= i
t = [i for i in range(1,n+1)]
ans=0

for i in list(permutations(t)):
    for j in range(n-1):
        
        i = list(i)
        ans+=((x[i[j]-1]-x[i[j+1]-1])**2+(y[i[j]-1]-y[i[j+1]-1])**2)**0.5
print(ans/kaijo)

Solution (Python):
import itertools
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
ln = [i for i in range(n)]
ans = 0
c = 0
for i in itertools.permutations(ln):
    c += 1
    for j in range(len(i)-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/c)

Solution (Python):
from math import sqrt

if __name__ == "__main__":
    n = int(input())
    xy = list()
    for i in range(n):
        xy.append(list(map(int, input().split())))

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

    print(ans/n)

Solution (Python):
import itertools
import math
n = int(input())
loc = []
for i in range(n):
    x,y = map(int,input().split())
    loc.append([x,y])
p = list(itertools.permutations(loc, n))
ans = 0
for i in range(len(p)):
    cnt = 0
    for j in range(n-1):
        a = p[i][j]
        b = p[i][j+1]
        cnt += ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5
    ans += cnt
print(ans/math.factorial(n))

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

import itertools
import math

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

Solution (Python):
import math
from itertools import permutations

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

ret = 0
cnt = 0
for i in permutations(xy):
    for j in range(N-1):
        x = (i[j][0] - i[j+1][0]) ** 2
        y = (i[j][1] - i[j+1][1]) ** 2
        ret += math.sqrt(x+y)
    cnt += 1
print(ret/cnt)

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 fractions import gcd
from bisect import bisect, bisect_right, bisect_left

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


A = [n for n in range(N)]
ans = 0
for i in list(combinations(A, 2)):
    l, r = i
    a, b = L[r], L[l]
    c = (a[0] - b[0]) ** 2
    d = (a[1] - b[1]) ** 2
    ans += sqrt(c + d)

print(ans/ N * 2)

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

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

from itertools import permutations

states = list(permutations(list(range(N))))

ans = 0
for state in states:
    dist = 0
    for i,n in enumerate(state):
        if i == 0:
            prev = xy[n]
            continue
        now = xy[n]
        dist += pow(pow(prev[0]-now[0], 2)+pow(prev[1]-now[1],2),.5)
        prev = now
    ans += dist

ans /= len(states)
print(ans)

Solution (Python):
from itertools import permutations
from math import factorial
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
x, y = zip(*XY)


def f(x, y): return (x ** 2 + y ** 2)**0.5


ans = 0
for p in permutations(range(N)):
    for s, t in zip(p[:-1], p[1:]):
        dx = x[t] - x[s]
        dy = y[t] - y[s]
        ans += f(dx, dy)

print(ans/factorial(N))

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
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 fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
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 = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
ans = 0
xy = [LIST() for _ in range(n)]
arr = list(permutations(list(range(n)), n))
ans = 0
for i in range(len(arr)):
    for j in range(len(arr[i]) - 1):
        ans += sqrt((xy[arr[i][j]][0] - xy[arr[i][j + 1]][0]) ** 2 + (xy[arr[i][j]][1] - xy[arr[i][j + 1]][1]) ** 2)
ans /= len(arr)
print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.buffer.readline
    from itertools import permutations
    from math import hypot
    N = int(input())
    XY = [[int(i) for i in input().split()] for j in range(N)]
    ans = 0
    for p in permutations(range(N)):
        for i in range(N-1):
            ans += hypot(XY[p[i+1]][0] - XY[p[i]][0],
                         XY[p[i+1]][1] - XY[p[i]][1])
    for i in range(1, N+1):
        ans /= i
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from itertools import permutations
from itertools import combinations

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


dist ={}
for i,j in combinations(range(1,N+1),2):
    xi = xy_list[i-1][0]
    yi = xy_list[i-1][1]

    xj = xy_list[j-1][0]
    yj = xy_list[j-1][1]
    
    key = tuple(sorted( (i,j) ))
    dist[key] = ( (xi-xj)**2 + (yi-yj)**2 )**(1/2)


dist_all=[]
for p in permutations(range(1,N+1)):
    dist_sub=0 
    for i in range(len(p)-1):
        key = tuple(sorted( (p[i],p[i+1]) ))
        dist_sub += dist[key]
    
    dist_all.append(dist_sub)


ans = sum(dist_all) / len(dist_all)
print(Decimal(str(ans)).quantize(Decimal('1E-10'), rounding=ROUND_HALF_UP))

Solution (Python):

import sys
from itertools import permutations

def solve(N: int, x: "List[int]", y: "List[int]"):
    def d(xy1_xy2):
        xy1, xy2 = xy1_xy2
        return ((xy1[0] - xy2[0]) ** 2 + (xy1[1] - xy2[1]) ** 2) ** 0.5

    acc = [sum(map(d, zip(perm, perm[1:]))) for perm in map(tuple, permutations(zip(x, y)))]
    return sum(acc) / len(acc)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    x = [int()] * (N)  
    y = [int()] * (N)  
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    print(solve(N, x, y))

if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import numpy as np

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

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

permutations_lis = itertools.permutations(range(n))
dis_list = []
for case in permutations_lis:
    dis_sum = 0
    for i in range(n-1):
        dis_sum += dis(coor[case[i]], coor[case[i+1]])
    dis_list.append(dis_sum)

print(np.mean(dis_list))

Solution (Python):
import itertools
n = int(input())
xy = []
for i in range(n):
    xy.append(list(map(int, input().split())))
per = list(itertools.permutations([i for i in range(n)]))
dist = 0
for i in per:
    for j in range(len(i)-1):
        xi = xy[i[j]][0]
        yi = xy[i[j]][1]
        xj = xy[i[j+1]][0]
        yj = xy[i[j+1]][1]
        dist += ((xi - xj) ** 2 + (yi - yj) ** 2) ** 0.5
dist /= len(per)
print(dist)

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

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

    perms = list(itertools.permutations(range(N), N))
    l = 0
    for v in perms:
        for i in range(N-1):
            xi, yi = cities[v[i]]
            xj, yj = cities[v[i+1]]

            l += ((xi - xj) ** 2 + (yi - yj) ** 2) ** 0.5

    ans = l / len(perms)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import itertools
from math import sqrt, factorial
N = int(input())
city_list = []
for i in range(N):
    city = list(map(int, input().split()))
    city_list.append(city)
num = [i for i in range(N)]
length = 0
for i in itertools.permutations(num):
    for j in range(N-1):
        length += sqrt((city_list[i[j]][0]-city_list[i[j+1]][0])**2+(city_list[i[j]][1]-city_list[i[j+1]][1])**2)
print(length/factorial(N))

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

for i in range(N):
    for j in range(i + 1):
        sum_dist += (
            (points[j][0] - points[i][0]) ** 2 + (points[j][1] - points[i][1]) ** 2
        ) ** 0.5
print(sum_dist * 2 / N)

Solution (Python):
import itertools

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

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

for pattern in patterns:
    tmp_dist = 0
    for i in range(N - 1):
        x, y = points[pattern[i]]
        nx, ny = points[pattern[i + 1]]
        tmp_dist += ((nx - x) ** 2 + (ny - y) ** 2) ** 0.5
    sum_dist += tmp_dist

print(sum_dist / len(patterns))

Solution (Python):
N = int(input())
p = [list(map(int, input().split())) for _ in range(N)]
table = [[0] * N for _ in range(N)]
for i in range(N-1):
  for j in range(i+1, N):
    table[i][j] = table[j][i] = ((p[i][0] - p[j][0]) ** 2 + (p[i][1] - p[j][1]) ** 2) ** 0.5

dist = 0
cnt = 0
import itertools
for permutation in itertools.permutations(list(range(N))):
  i = 0
  while i < N - 1:
    dist += table[permutation[i]][permutation[i+1]]
    i += 1
  cnt += 1
print(dist / cnt)

Solution (Python):


import itertools
import math

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


paths = list(map(list, itertools.permutations(range(N), N)))


dists = []
for path in paths:
    dist = 0
    for i, v in enumerate(path):
        town = towns[v]
        if i != N - 1:
            town_next = towns[path[i+1]]
            
            
            
            x1, y1 = town[0], town[1]
            x2, y2 = town_next[0], town_next[1]
            dist += math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
    dists.append(dist)


print(sum(dists)/len(dists))

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

res = 0

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


print(res*2/N)

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

ans = 0

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

for v in itertools.permutations(num):
    
    for i in range(n-1):
        ans += d(info[v[i]][1], info[v[i+1]][1], info[v[i]][2], info[v[i+1]][2])

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

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

Solution (Python):
import itertools
import math

def dist(i, j):
    return math.sqrt((locations[i][0] - locations[j][0]) ** 2 \
        + (locations[i][1] - locations[j][1]) ** 2)

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

dists = []
for item in itertools.permutations(range(n)):
    tmp = 0
    for i in range(n-1):
        tmp += dist(item[i], item[i+1])
    dists.append(tmp)

print(sum(dists) / len(dists))

Solution (Python):










import math
import numpy as np
import statistics
import string
import sys
from array import array
from collections import deque

def intinput():
    return int(input())
def listintinput():
    return list(map(int, input().split()))
def splitintinput():
    return map(int, input().split())
def factorialsurplus(x, y, z):  
    ret = 1
    for i in range(x, y + 1):
        ret = (ret * i) % z
    return (ret)
def isprime(x):
    if x == 1:
        return False
    if x == 2:
        return True
    sq = int(math.sqrt(x))
    for i in range(2,sq+1):
        if x % i == 0:
            return False
    return True
def hcfnaive(a,b):
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

N = intinput()
ans = 0
tmp = []
sum = 0
for i in range(N):
    a = np.array(listintinput())
    for j in tmp:
       sum += np.linalg.norm(a-j)
    tmp.append(a)

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

Solution (Python):
import math

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

D=[]
for i in range(n-1):
    for j in range(i+1,n):
        D.append(math.sqrt((M[i][0]-M[j][0])**2+(M[i][1]-M[j][1])**2))

print(sum(D)*2/n)

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

N = int(input())
point = defaultdict(list)
for i in range(1, N+1):
    x, y = list(map(int, input().split()))
    point[i] = [x, y]

res = 0
for permutation in permutations(range(1, N+1)):
    for i in range(1, N):
        nx, pre = permutation[i], permutation[i-1]
        res += sqrt( pow((point[nx][0] - point[pre][0]), 2) + pow((point[nx][1] - point[pre][1]), 2) )

print(res / factorial(N))

Solution (Python):
import sys
input = sys.stdin.readline
from bisect import bisect_left

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

if __name__ == '__main__':
    main()

Solution (Python):
import itertools

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()

A = [tuple(int(i) for i in input().split()) for _ in range(n)]

memo = [[-1]*n for i in range(n)]
keiro_sum = 0

cnt = 0
for i in itertools.permutations(range(n)):
    cnt += 1
    one_root = 0
    for j in range(1,n):
        if(memo[i[j-1]][i[j]] == -1):
            distance = ((A[i[j]][0] - A[i[j-1]][0])**2 + (A[i[j]][1] - A[i[j-1]][1])**2)**0.5
            memo[i[j]][i[j-1]] = distance
            memo[i[j-1]][i[j]] = distance
        else:
            distance = memo[i[j-1]][i[j]]
        one_root += distance

    keiro_sum += one_root

print(keiro_sum/cnt)

Solution (Python):
import itertools
import math

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

next_p = itertools.permutations(a)
total = 0
for p in next_p:
  for i in range(n - 1):
    temp = (p[i][0] - p[i + 1][0]) ** 2 + (p[i][1] - p[i + 1][1]) ** 2
    total += math.sqrt(temp)


ans = total / math.factorial(n)
print(ans)

Solution (Python):

from itertools import permutations
import math


def submit():
    n = int(input())
    positions = {i: tuple(map(int, input().split())) for i in range(n)}
    cities = [i for i in range(n)]
    
    dists = {}
    for i in cities[:-1]:
        for j in cities[i + 1:]:
            pi = positions[i]
            pj = positions[j]
            d = math.sqrt((pi[0] - pj[0]) ** 2 + (pi[1] - pj[1]) ** 2)
            dists[(i, j)] = d
            dists[(j, i)] = d

    path_count = 0
    path_sum = 0
    for p in permutations(cities):
        d = 0
        for i in range(n - 1):
            d += dists[(p[i], p[i + 1])]
        path_sum += d
        path_count += 1

    print(path_sum / path_count)


if __name__ == "__main__":
    submit()

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

L=0
for i in range(N-1):
    for j in range(i+1,N):
        L += ((p[i][0]-p[j][0])**2 + (p[i][1]-p[j][1])**2 )**0.5
print(2*L/N)

Solution (Python):
import math

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

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

print(2*L/N)

Solution (Python):
import itertools

n = int(input())
x = [[0,0] for i in range(n)]
max = 1
for i in range(n) :
  x[i][0],x[i][1] = map(int,input().split())
  max = max*(i+1)

ans = 0
for t in itertools.permutations(x):
    for i in range(n-1) :
      ans += ((t[i][0]-t[i+1][0])**2+(t[i][1]-t[i+1][1])**2)**0.5

print(ans/max)

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



import numpy as np



n = int(input())

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


routes = list(permus(range(0,n)))

res = 0
for rout in routes:
    for i,town in enumerate(rout):
        if i == 0:
            continue
        else:
            xi = lists[rout[i]][0]
            yi = lists[rout[i]][1]
            xj = lists[rout[i-1]][0]
            yj = lists[rout[i-1]][1]
            res += sqrt((xi -xj)**2 + (yi-yj)**2)

ans = res/len(routes)

print("{:.10f}".format(ans))

Solution (Python):
import itertools
import math

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

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

conut=[i for i in range(N)]
conb=itertools.permutations(conut, N)
total=0
for n,c in enumerate(conb):
    for i in range(N-1):
        n1=c[i]
        n2=c[i+1]
        h=math.sqrt((x[n1]-x[n2])**2 + (y[n1]-y[n2])**2)
        total+=h

print(total/(n+1))

Solution (Python):
def resolve():
    import math
    n = int(input())
    distance = [list(map(int, input().split())) for i in range(n)]
    c =[[0]*n for i in range(n)]
    for i in range(n):
        for j in range(n):
            dix = (distance[i][0] - distance[j][0]) **2
            diy = (distance[i][1] - distance[j][1]) **2
            c[i][j] = (dix+diy)**0.5
    sumc = 0
    for i in range(n):
        sumc += sum(c[i])
    print(sumc/n)
resolve()

Solution (Python):
import math

n = int(input())
s_amount = 0

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

Solution (Python):
import itertools

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



distances = []
for i in range(8):
    distances.append([0. for j in range(8)])

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


order_cnt = 0
sum_distance = 0.0
for order in itertools.permutations(range(n)):
    
    current_distance = 0
    for i in range(len(order) - 1):
        current_distance += distances[order[i]][order[i + 1]]
    
    order_cnt += 1
    sum_distance += current_distance

print(sum_distance / order_cnt)

Solution (Python):
import itertools

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

fact = [1] * (N + 1)
for i in range(1, N + 1):
    fact[i] = fact[i-1] * i


def L2norm(i, j):
    X = XY[i][0] - XY[j][0]
    Y = XY[i][1] - XY[j][1]
    return (X**2 + Y**2) ** (1/2)


dist = [[0] * N for i in range(N)]
for i in range(N):
    for j in range(i, N):
        r = L2norm(i, j)
        dist[i][j] = r
        dist[j][i] = r

ans = 0
stock = 0
for perm in itertools.permutations(range(N), N):
    cur = 0
    for i in range(N-1):
        cur += dist[perm[i]][perm[i+1]]
    ans += cur
print(ans/fact[N])

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

N = int(input())
x, y = [], []
dist = []

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

for i in permutations(range(N)):
    d = 0
    for j in range(len(i) - 1):
        d += sqrt((x[i[j]] - x[i[j + 1]])**2 + (y[i[j]] - y[i[j + 1]])**2)
    dist.append(d)

print(sum(dist) / len(dist))

Solution (Python):
import numpy as np
import itertools

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

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


distance_list = []
for route in itertools.permutations(range(n)):
    total = 0
    for j in range(len(route) - 1):
        d = calc_distance(data[route[j]], data[route[j+1]])
        
        total += d
    distance_list.append(total)

print(np.mean(distance_list))