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

Solution (Python):
import itertools
N = int(input().strip())
C = [list(map(int, input().strip().split(' '))) for _ in range(N)]
ans = 0
def dist(t1, t2):
  return (((t1[0]-t2[0])**2) + ((t1[1]-t2[1])**2))**0.5

for i,j in itertools.combinations(range(N), 2):
  ans += dist(C[i], C[j])
ans = ans*2/N
print(ans)

Solution (Python):
from itertools import permutations
import math
n = int(input())
l1 = []
l = []
ans = 0
for i in range(n):
    x,y = map(int,input().split())
    l.append(i)
    l1.append((x,y))
per = permutations(l)
for elm in per:
    for i in range(1,len(elm)):
        x=(((l1[elm[i]][0]-l1[elm[i-1]][0])**2)+((l1[elm[i]][1]-l1[elm[i-1]][1])**2))
        ans+=math.sqrt(x)
ans = ans/(math.factorial(n))
print(ans)

Solution (Python):
import itertools
import math

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

dd = 0
patterns = list(itertools.permutations(list(range(n))))
for p in patterns:
    xd = 0
    for i in range(len(p) - 1):
        d = math.sqrt((x[p[i]] - x[p[i + 1]]) * (x[p[i]] - x[p[i + 1]]) + (y[p[i]] - y[p[i + 1]]) * (y[p[i]] - y[p[i + 1]]))
        xd += d
    dd += xd
print(dd / len(patterns))

Solution (Python):
import math
import itertools
N = int(input())
xy_list = []
for i in range(N):
    xy_list.append(list(map(int, input().split())))
distance = 0
count = 0
permutations = itertools.permutations(xy_list)
for permutation in permutations:
    count += 1
    for i in range(len(permutation) - 1):
        xi = permutation[i][0]
        yi = permutation[i][1]
        xj = permutation[i + 1][0]
        yj = permutation[i + 1][1]
        d = math.sqrt((xi - xj) ** 2 + (yi - yj) ** 2)
        distance += d
print(distance / count)

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

xy = []

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

perm = list(itertools.permutations(xy))
cnt = len(perm)



ans = 0
dis = 0

for i in range(cnt):
    for j in range(1, n):
        prevX = perm[i][j-1][0]
        prevY = perm[i][j-1][1]
        x = perm[i][j][0]
        y = perm[i][j][1]
        dis += ((prevX-x)**2 + (prevY-y)**2)**0.5

print(dis/len(perm))

Solution (Python):
import sys
import copy
import math
import bisect
import pprint
import bisect

def dictCount(str):
    dict = {}

if __name__ == '__main__':
    n = int(input())
    s = []
    sum =0
    for i in range(n):
        a = [int(i) for i in input().split()]
        s.append(a)
    for i in range(n):
        for j in range(n):
            if j > i:
                x = s[i][0] -s[j][0]
                y = s[i][1] -s[j][1]
                sum = sum + math.sqrt(x*x + y*y)
    sum = sum*2

    print(sum/n)

Solution (Python):
import math

N = int(input())

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

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

Solution (Python):
import numpy as np
from scipy.spatial import distance

n = int(input())
xy = []
for _ in range(n):
    x, y = map(int, input().split())
    xy.append([x, y])
dist_M = distance.cdist(xy, xy, metric='euclidean')
print(np.sum(dist_M)/(n))

Solution (Python):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
x_y = [list(map(int, input().split())) for _ in range(n)]
avg = 0
d_sum = 0
for i in range(n-1):
  for l in range(i+1,n):
    d = math.sqrt((x_y[i][0]-x_y[l][0])**2 + (x_y[i][1]-x_y[l][1])**2)
    d_sum += d
k = (math.factorial(n) * (n-1))//combinations_count(n, 2)
avg = d_sum*k/math.factorial(n)
print(avg)

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

def distance(p):
    dst = 0
    for i in range(n-1):
        x1 = xval[p[i]]
        y1 = yval[p[i]]
        x2 = xval[p[i+1]]
        y2 = yval[p[i+1]]
        dst += d(x1,y1,x2,y2)
    return dst

def permutation(lst): 
    if len(lst) == 0: 
        return [] 
    if len(lst) == 1: 
        return [lst] 
    l = [] 
    for i in range(len(lst)): 
       m = lst[i] 
       remLst = lst[:i] + lst[i+1:] 
       for p in permutation(remLst): 
           l.append([m] + p) 
    return l 

n = int(input())

xval = []
yval = []

for i in range(n):
    x,y = map(int, input().split())
    xval.append(x)
    yval.append(y)

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

per = permutation(r)

dist = []

for p in per:
    dist.append(distance(p))

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

Solution (Python):
n=int(input())
xy=[[int(i) for i in input().split()] for _ in range(n)]
res=0
for i in range(n):
    for j in range(n):
        if i!=j:
            res+=((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**0.5
print(res/n)

Solution (Python):
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
x, y, r = [], [], []
for i in range(n):
    xi, yi = na()
    for xj, yj in zip(x, y):
        r.append(((xi - xj)**2 + (yi - yj)**2)**0.5)
    x.append(xi)
    y.append(yi)
print((sum(r)/len(r))*(n-1))

Solution (Python):
import itertools

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

def dist(perm):
    d = 0
    x0, y0 = X[perm[0]]
    for i in perm[1:]:
        x1, y1 = X[i]
        d += ((x1-x0)**2 + (y1-y0)**2)**0.5
        x0 = x1
        y0 = y1
    return d

def main():
    d = 0
    perms = list(itertools.permutations(range(N)))
    for perm in perms:
        d += dist(perm)
    return d/len(perms)

print(main())

Solution (Python):
import math
N = int(input())
x = []
y = []
for i in range(N):
  xi, yi = map(float, input().split())
  x.append(xi)
  y.append(yi)

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

print(2 * sum(l) / N)

Solution (Python):
import math
import itertools

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

for v in itertools.permutations(t, n):
    for i in range(len(v)-1):
        x = (v[i+1][0]-v[i][0])**2
        y = (v[i+1][1]-v[i][1])**2
        ans += math.sqrt(x + y)

print(ans/math.factorial(n))

Solution (Python):
import numpy as np
N = int(input())
R = []
for _ in range(N):
    R.append(list(map(int, input().split())))
R = np.array(R)
X = R[:,0].reshape((-1,1))
Y = R[:,1].reshape((-1,1))
dX = X-X.T
dY = Y-Y.T
D = np.sqrt(dX*dX+dY*dY)
sum_D = np.sum(np.sum(D))/N
print(sum_D)

Solution (Python):
import math
import numpy as np
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
d = [[0 for _ in range(N)] for _ in range(N)]
s = 0
for i in range(N):
    for j in range(N):
        if i != j:
            xi,yi = xy[i]
            xj,yj = xy[j]
            d[i][j] = math.sqrt((xj-xi)**2+(yj-yi)**2)
print(np.sum(d)/ N)

Solution (Python):
import itertools
import math
n = int(input())
x = []
y = []
p = []
for i in range(n):
    src = list(map(int, input().split()))
    x.append(src[0])
    y.append(src[1])
    p.append(str(i))

length = 0
for i in itertools.permutations(p):
    for j in range(n - 1):
        pos0 = int(i[j])
        pos1 = int(i[j + 1])
        length += math.sqrt((x[pos1] - x[pos0]) ** 2 +
                            (y[pos1] - y[pos0]) ** 2)
ans = length / math.factorial(n)
print(ans)

Solution (Python):
import math

class Point:
	def __init__(self, x, y):
		self.x = x
		self.y = y

	def distance(self, other):
		return math.sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2)

if __name__ == "__main__":
	N = int(input())
	points = []
	d = 0
	for _ in range(N):
		x, y = map(int, input().split())
		q = Point(x, y)
		for p in points:
			d += q.distance(p)
		points.append(q)
	print(2.0 / float(N) * d)

Solution (Python):
from math import sqrt, factorial

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

    
    distance = list()
    for i in range(n):
        for j in range(n):
            if i is j:
                continue
            distance.append(
                sqrt((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2))

    ans = 0
    for d in distance:
        ans += d * factorial(n-1)

    print(ans / float(factorial(n)))

Solution (Python):
import math
from itertools import permutations

cache = {}

def distance(p1, p2):
    dist = cache.get((p1, p2))
    if dist is not None:
        return dist
    x1, y1 = p1
    x2, y2 = p2
    dist = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
    cache[(p1, p2)] = dist
    return dist

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

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

count = 0
total_dist = 0
for p in permutations(t, len(t)):
    count += 1
    dist = 0
    for i in range(len(t) - 1):
        dist += distance(p[i], p[i + 1])
    total_dist += dist

print(total_dist / count)

Solution (Python):
import math

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

rtot = 0
temp = 1

for i in range(N):
    
    for j in range(N):
        if i == j:
            continue
        rtot += math.sqrt( (xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2 )


ans = rtot / N

print(ans)

Solution (Python):
n=int(input())
data=[]
for i in range(n):
    x,y=map(int,input().split())
    data.append((x,y))
ans=0
for i in range(n):
    for j in range(i+1,n):
        xi,xj,yi,yj=data[i][0],data[j][0],data[i][1],data[j][1]
        ans+=(((xi-xj)**2+(yi-yj)**2)**0.5)
ans*=2

print(ans/n)

Solution (Python):
import math

N=int(input())

t=[]
a=[0]*N

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

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

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
input=lambda :sys.stdin.readline().rstrip()
inputs= sys.stdin.buffer.readlines
INF=float("inf")
MOD=10**9+7



import math




















def main():
	X=[]
	Y=[]
	n=int(input())
	ans=0
	for i in range(n):
		x,y=map(int,input().split())
		X.append(x)
		Y.append(y)
	
	for i in range(n-1):
		for j in range(i+1,n):
			ans+=((X[i]-X[j])**2+(Y[i]-Y[j])**2)**0.5
	
	print(ans*2/n)
	
	
	
	
	
if __name__ == '__main__':
	main()

Solution (Python):
N = int(raw_input())
r=[]
for i in range(N):
    r.append(map(int, raw_input().split()))

ave = 0.0
for i in range(N):
    xi = r[i][0]
    yi = r[i][1]
    for j in range(i, N):
        xj = r[j][0]
        yj = r[j][1]
        rij = ((xi-xj)**2 + (yi-yj)**2)**0.5
        ave = ave + rij

ave = ave*2/N

print ave

Solution (Python):
from itertools import permutations
def dist(a,b):
    return ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5
n = int(input())
coords =[ ]
for _ in range(n):
    coords.append(tuple(int(x) for x in input().split()))
c=0
d = 0
for perm in permutations(range(n), n):
    for i, val in enumerate(perm[1:]):
        d += dist(coords[perm[i]], coords[val])
    c+=1
print(d / c)

Solution (Python):
n = int(input())
x = [0 for i in range(n)]
y = [0 for i in range(n)]

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

ans = 0

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

ans /= n / 2

print(ans)

Solution (Python):
import itertools
import math

n = int(input())

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

p_list = list(itertools.permutations(li, n))

def cal_distance(lis):
    dis = 0
    for i in range(n-1):
        dis += math.sqrt((lis[i+1][0]-lis[i][0])**2 + (lis[i+1][1] - lis[i][1])**2)
    return dis

total_distance = 0
for i in range(len(p_list)):
    total_distance += cal_distance(p_list[i])

print(total_distance/len(p_list))

Solution (Python):

from math import factorial
from itertools import permutations

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

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

sum = 0

for r in permutations(v):
    d = 0
    x1, y1 = r[0]
    for u in r[1:]:
        x2, y2 = u
        d += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
    sum += d

print(sum / factorial(n))

Solution (Python):
import math
n = int(input())
x = []
y = []
for _ in range(n):
    xi, yi = map(int, input().split())
    x.append(xi)
    y.append(yi)
    
total = 0
for i in range(n):
    for j in range(i):
        total += math.sqrt((x[j] - x[i])**2 + (y[j] - y[i])**2)
print(total/(n/2))

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

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

print(d*2/N)

Solution (Python):
from itertools import permutations
import math
n = int(input())
res = []
for i in range(n):
    s = list(map(int,input().split()))
    res.append(s)
perm= permutations(res)
ans = 0
total = 1
for i in range(1,n+1):
    total = total*i
for i in perm:
    k = 0
    for j in range(1,len(i)):
        k+=math.sqrt(((i[j][0]-i[j-1][0])**2)+((i[j][1]-i[j-1][1])**2))
    ans+=(k/total)
print(ans)

Solution (Python):
import numpy as np
import itertools
def fraction(n):
    r = 1
    for i in range(n):
        r *= (i+1)
    return(r)


n=int(input())
x = [0 for _ in range(n)]
y = [0 for _ in range(n)]
d = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
    X,Y = map(int,input().split())
    x[i] = X
    y[i] = Y


for i in range(n):
    for j in range(n):
        d[i][j] = np.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)


seq = range(n)

p = list(itertools.permutations(seq))
a = 0.0
for pp in p:
    for i in range(n-1):
        a += d[pp[i]][pp[i+1]]
print(a/fraction(n))

Solution (Python):
import itertools
import math


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


def main():
    n = int(input())

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

    seq = range(n)
    sum_distance = 0
    for p in itertools.permutations(seq):
        for i in range(n-1):
            sum_distance += distance(towns[p[i]], towns[p[i+1]])
    ans = sum_distance / math.factorial(n)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math

N = int(sys.stdin.readline())
x = []
y = []
for i in range(N):
    tempx, tempy = map(int, sys.stdin.readline().split())
    x.append(tempx)
    y.append(tempy)


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

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


distance = 0
count = 0

for i in range(N-1):
    for j in range(i+1, N):
        distance += ((x[i] - x[j])**2 + (y[i] - y[j])**2) ** (1/2)
        count += 1

print(distance/(count/(N-1)))

Solution (Python):
import itertools
import math

N = int(input())

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

tot = 0
for path in itertools.permutations(towns, N):
    path_length = 0
    for i, (x, y) in enumerate(path[:-1]):
        path_length += math.sqrt(
            (x - path[i + 1][0]) ** 2 + (y - path[i + 1][1]) ** 2
        )
    tot += path_length

print(tot / math.factorial(N))

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

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


def CalDistence(x0, y0, x1, y1):
    return (((x0 - x1) ** 2) + (y0 - y1) ** 2) ** 0.5


AllDistance = 0
for i in range(N):
    for j in range(N):
        if i != j:
            AllDistance += CalDistence(x[i], y[i], x[j], y[j])

print(AllDistance / N)

Solution (Python):
from math import sqrt
from itertools import permutations as per
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
kumi = per(range(N))
ans = []
leng = 0
for p in kumi:
    cnt = 0
    for i in range(1, len(p)):
        cnt += sqrt((xy[p[i-1]][0] - xy[p[i]][0])**2 + (xy[p[i-1]][1] - xy[p[i]][1])**2)
    ans.append(cnt)
    leng += 1
print(sum(ans) / leng)

Solution (Python):
import math

n  = int(input())
ps = []
ds = []
a  = 1
b  = 1

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

for i in range(1, n):
	a *= i
	b *= i

b *= n

for i in range(0, n):
	for j in range(0, n):
		if i != j:
			dx = ps[i][0] - ps[j][0]
			dy = ps[i][1] - ps[j][1]
			ds.append(math.sqrt(dx * dx + dy * dy) * a)

print(sum(ds) / b)

Solution (Python):
import itertools

n = int(input())

route = [list(map(int, input().split())) for _ in range(n)]
results = []
for v in itertools.permutations(route, r=n):
    distance = 0
    for i in range(n - 1):
        start, goal = v[i], v[i + 1]
        distance += ((goal[0] - start[0]) ** 2 + (goal[1] - start[1]) ** 2) ** 0.5
    results.append(distance)
print(sum(results) / len(results))

Solution (Python):
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
length = []
for i in range(N):
    for j in range(i+1, N):
        l = (XY[j][0] - XY[i][0]) ** 2 + (XY[j][1] - XY[i][1]) ** 2
        length.append(l ** (1/2))

if N == 2:
    answer = sum(length)
else:
    answer = sum(length) * (N-1) / ((N-1) * N // 2)
print(answer)

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

N = int(input())
xy = []
sm = 0
for _ in range(N):
    xy.append(list(map(int, input().split())))
for i in range(N):
    now_x = xy[i][0]
    now_y = xy[i][1]
    for j in range(N):
        if j != i:
            sm += math.sqrt((now_x - xy[j][0])**2 + (now_y - xy[j][1])**2)
print(sm / N)

Solution (Python):


from itertools import permutations
from math import sqrt, factorial

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  points = [readInts() for _ in range(N)]

  s = 0
  for r in permutations(points):
    for i in range(N-1):
      x1, y1 = r[i]
      x2, y2 = r[i+1]
      s += sqrt((x2 - x1)**2 + (y2 - y1)**2)
  print(s / factorial(N))

if __name__ == "__main__":
  main()

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

dist = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        dist += (((x[i]-x[j])**2) + ((y[i]-y[j]) ** 2)) ** 0.5
print(dist/n)

Solution (Python):
import itertools
import math


n = int(input())
l = []
for i in range(n):
    l.append([int(_) for _ in input().split()])
ans = 0
for i in list(itertools.permutations(range(n))):
    for j in range(n-1):
        ans += math.sqrt((l[i[j]][0] - l[i[j+1]][0])**2 + (l[i[j]][1] - l[i[j+1]][1])**2)
print(ans/math.factorial(n))

Solution (Python):
import math

n  = int(input())
ps = []
ds = []
a  = 1
b  = 1

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

for i in range(1, n):
	a *= i
	b *= i

b *= n

for i in range(0, n):
	for j in range(0, n):
		if i != j:
			dx = ps[i][0] - ps[j][0]
			dy = ps[i][1] - ps[j][1]
			ds.append(math.sqrt(dx * dx + dy * dy) * a)

print(sum(ds) / b)

Solution (Python):
import itertools

N = int(input())
table = [[0] * N for i in range(N)]
points = []
A = [i for i in range(N)]
ans = 0
count = 0

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

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

for p in itertools.permutations(A,N):
    tmp = 0
    for k in range(N-1):
        tmp += table[p[k]][p[k+1]]
    ans += tmp
    count += 1
print(ans/count)

Solution (Python):
import math

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

def dist(a, b):
  return math.sqrt(dist2(a, b))

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

ans = 0
for i in range(N):
  for j in range(i+1,N):
    ans += dist(coordinates[i], coordinates[j])

print(ans*2/N)

Solution (Python):
import math
import itertools

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

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

ans = 0
n = 0
for p in itertools.permutations(xy, N):
    d = 0
    for i in range(len(p)-1):
        d += get_dist(p[i], p[i+1])
    ans += d
    n += 1

print(ans / n)

Solution (Python):
n,*a=map(int,open(0).read().split())
b=0
for i,j in zip(a[::2],a[1::2]):
    for k,l in zip(a[::2],a[1::2]):
        b+=((i-k)**2+(j-l)**2)**0.5
print(b/n)

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


def main():
    N = int(input())
    A = []
    for _ in range(N):
        x, y = map(int, input().split())
        A.append((x, y))
    ans = 0
    for a in itertools.permutations(range(N)):
        for i in range(len(a)-1):
            dx = A[a[i]][0]-A[a[i+1]][0]
            dy = A[a[i]][1]-A[a[i+1]][1]
            ans += math.sqrt((dx**2) + (dy**2))
    n = 1
    for i in range(1, N+1):
        n *= i
    print(ans/n)


if __name__ == '__main__':
    main()

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

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

ans = 0

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        ans += math.sqrt(math.pow(paths[i][0] - paths[j][0], 2) + math.pow(paths[i][1] - paths[j][1], 2))

mul = 1
for i in range(1, n):
    mul *= i
print(ans/n)

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

s = 1
t = 1
dis = 0

for i in range(1,n+1):
    s *= i

for j in range(1,n):
    t *= j
    
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        dis += ((li[i][0] - li[j][0])**2 + (li[i][1] - li[j][1])**2)**0.5

print(t*dis/s)

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

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

avg = []
for pair in list(permutations(towns)):
    x_prev = None
    y_prev = None
    dist = 0
    for i, (x, y) in enumerate(pair):
        if i > 0:
            dist += np.sqrt((x-x_prev)**2 + (y-y_prev)**2)
        x_prev = x
        y_prev = y
    
    avg.append(dist)

print('{:.10f}'.format(np.mean(avg)))

Solution (Python):
from itertools import permutations
from math import factorial
from scipy.spatial import distance_matrix
import numpy as np

n = int(input())
x = []
for i in range(n):
    x.append(list(map(int, input().split())))
x = np.array(x)
d = distance_matrix(x, x)

res = 0
for path in permutations(range(n)):
    path = list(path)
    res += np.sum(d[path[:-1], path[1:]])
print(res/factorial(n))

Solution (Python):
import itertools
import math
n=int(input())
cal=[[0 for _ in range(n)] for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        d=math.sqrt((p[i][0]-p[j][0])**2+(p[i][1]-p[j][1])**2)
        cal[i][j]=d
    
kumi=list(itertools.permutations([i for i in range(n)]))
total=0
l=len(kumi)
for each in kumi:
    tmp=0
    for i in range(len(each)-1):
        tmp+=cal[each[i]][each[i+1]]
    tmp/=l
    total+=tmp
print(total)

Solution (Python):

import math
import sys
import itertools

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


ans = 0
fact = 1
for i in range(N):
    fact *= (i+1)

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

ans /= fact
print(ans)

Solution (Python):
import math
n = int(raw_input())
d = []
for i in range(n):
    tmp = map(int, raw_input().split())
    d.append(tmp)

ds = []
for i in range(n):
    for j in range(i+1,n):
        x0, y0 = d[i]
        x1, y1 = d[j]
        ds.append(math.sqrt((x0-x1)**2 + (y0-y1)**2))

n_ = 1
for i in range(1,n+1):
    n_ *= i

t = 1
for i in range(1,n):
    t *= i

print sum(map(lambda x: x*t*2,ds)) / n_

Solution (Python):
import math
N = int(input())
cands = [list(map(int, input().split())) for i in range(N)]
def calc_dis(x, y):
  return math.sqrt((x[0]-y[0])**2+(x[1]-y[1])**2)

sums = [[0 for i in range(N)] for i in range(N)]
for i in range(N):
  for j in range(i+1, N):
    sums[i][j] = calc_dis(cands[i], cands[j])

print(sum([sum(s) for s in sums])*2/N)

Solution (Python):
import sys
import itertools
import math
input=sys.stdin.readline
n=int(input())
G=[]
for i in range(n):
    x,y=map(int,input().split())
    G.append((x,y))
l=[i for i in range(n)]
p=itertools.permutations(l,n)
Sum=0
for i in p:
    pre=i[0]
    for j in range(1,n):
        now=i[j]
        Sum+=math.sqrt((G[pre][0]-G[now][0])**2+(G[pre][1]-G[now][1])**2)
        pre=now
ans=Sum/math.factorial(n)
print(ans)

Solution (Python):
N = int(input())
x=[]
y=[]
for i in range(N):
    xi, yi = map(int,input().split())
    x.append(xi)
    y.append(yi)
    
import itertools
total =0
for a,b in itertools.permutations(range(N), 2):
    len_x = (x[a]-x[b])**2
    len_y = (y[a]-y[b])**2
    length = (len_x+len_y)**0.5
    total+=length / N
print(total)

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

cnt=0
for i in permutations(A,n):
    for j in range(1,n):
        cnt +=((i[j-1][0]-i[j][0])**2+(i[j-1][1]-i[j][1])**2)**0.5
print(cnt/factorial(n))

Solution (Python):
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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


def main():
    N = int(input())

    seq = [list(map(int, input().split())) for _ in range(N)]
    arr = list(itertools.permutations(seq))
    l = len(arr)

    k = 0
    for x in arr:
        for i in range(N-1):
            k += kyori(x[i], x[i+1])

    print(k / l)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input()) 
e = [[int(i) for i in input().split()] for i in range(N)] 
import itertools
seq = list(itertools.permutations(e))


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

l = 0
for i in seq:
  for j in range(1,N):
    l += diff(i[j][0],i[j][1],i[j-1][0],i[j-1][1])
print(l/len(seq))

Solution (Python):
import itertools
import math

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

n = []
for i in range(N):
    n.append(i)
    
c = list(itertools.permutations(n))

total = 0
for i in range(len(c)):
    x = xy[c[i][0]][0]
    y = xy[c[i][0]][1]
    dist = 0
    for j in range(1,len(c[i])):
        tmp_x = xy[c[i][j]][0]
        tmp_y = xy[c[i][j]][1]
        dist += math.sqrt((x - tmp_x) ** 2 + (y - tmp_y) ** 2)
        x = tmp_x
        y = tmp_y
    total += dist

print(total/len(c))

Solution (Python):
import math

n  = int(input())
ps = []
ds = []
a  = 1
b  = 1

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

for i in range(1, n):
	a *= i
	b *= i

b *= n

for i in range(0, n):
	for j in range(0, n):
		if i != j:
			dx = ps[i][0] - ps[j][0]
			dy = ps[i][1] - ps[j][1]
			ds.append(math.sqrt(dx * dx + dy * dy) * a)

print(sum(ds) / b)

Solution (Python):
import math
import itertools

ans = 0

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
root = [i for i in range(n)]
roots = list(itertools.permutations(root))
for i in roots:
    for j in range(1, n):
        ans += math.sqrt(((xy[i[j - 1]][0] - xy[i[j]][0]) ** 2 +  (xy[i[j - 1]][1] - xy[i[j]][1]) ** 2))


print(ans / len(roots))

Solution (Python):
import math
from itertools import permutations

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

s = 0
cnt = 0
for a in permutations(p):
    for i in range(1, len(a)):
        s += math.sqrt((a[i-1][0]-a[i][0]) **2 + (a[i-1][1]-a[i][1]) **2)
    cnt +=1
print(s/cnt)

Solution (Python):
import math
import itertools
def length(X,Y,c):
    sum_=0
    for i in range(len(c)-1):
        sum_+=math.sqrt((X[c[i]]-X[c[i+1]])**2 + (Y[c[i]]-Y[c[i+1]])**2)
    
    return sum_
N=int(input())
X=[0]*N
Y=[0]*N
for i in range(N):
    X[i], Y[i] = map(int,input().split())
C = list(itertools.permutations(range(0,N)))
sum_=0
for c in C:
    sum_+=length(X,Y,c)
print(sum_/len(C))

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

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

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

sum = 0
for l1 in li:
  for l2 in li:
    sum += math.sqrt((l1[0]-l2[0]) ** 2 + (l1[1]-l2[1]) ** 2)/N

print(sum)

Solution (Python):
import itertools

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

sum_length = 0
for i, j in itertools.product(coordinates, coordinates):
    sum_length += pow((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2, 1/2)

average_length = sum_length / n
print(average_length)