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 numpy as np
import math
import itertools
N = int(input())
data = [list(map(int,input().split())) for _ in range(N)]
length_list = []
arr = np.arange(1,N+1)
list_arr = arr.tolist()
for v in itertools.permutations(list_arr,N):
    S = 0
    for i in range(N-1):
        S += np.sqrt((data[v[i]-1][0]-data[v[i+1]-1][0])**2+(data[v[i]-1][1]-data[v[i+1]-1][1])**2)
    length_list.append(S)
ave = sum(length_list)/math.factorial(N)
print(ave)

Solution (Python):

import math
import itertools
n=int(input())  
i=0
lst = []
while i < n: 
    a,b=map(int, input().split())  
    lst.append([a,b])
    i+=1

conp=[]
for i,j in itertools.combinations(lst, 2):
    conp.append(math.sqrt((i[0]-j[0])*(i[0]-j[0])+(i[1]-j[1])*(i[1]-j[1])))

length_sum = sum(float(i) for i in conp)
print(math.factorial(n-1) * 2 * length_sum/math.factorial(n))

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

dict = {}
for i in range(n):
    for j in range(n):
        if i < j:
            dict[str(i)+str(j)] = math.sqrt((x[i] - x[j])**2 + (y[i]- y[j])**2)




sumation = 0




















for kei,length in dict.items():
    sumation += (n-1) * math.factorial(n-2)*length*2
print(sumation/math.factorial(n))

Solution (Python):
import numpy as np
N=int(input())
a=[0]*N
b=[0]*N
s=0
for i in range(N):
    a[i], b[i] = map(int, input().split())
for i in range(N):
  for j in range(N):
    vec=[a[i]-a[j], b[i]-b[j]]
    s+=np.linalg.norm(vec)
print(s/N)

Solution (Python):
N = int(input()) 
A = [] 
import itertools
import math
for i in range(N): 
    A.append(list(map(int, input().split()))) 
B = 0 
C = 0
for i in itertools.permutations(range(N)):
    B +=1
    a0 = A[i[0]]
    for j in range(N-1):
        a1 = A[i[j+1]]
        r = (a1[1]-a0[1])**2+(a1[0]-a0[0])**2
        C += math.sqrt(r)
        a0 = a1
print ( C / B )

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

kaburi = (N-1)*2*math.factorial(N-2)
fac_N = math.factorial(N)
length *= kaburi
print(length/fac_N)

Solution (Python):
import math
from itertools import permutations
def distance(a,b):
    return math.sqrt(abs(a[0]-b[0])**2 + abs(a[1]-b[1])**2)
N = int(input())
cords = []
for i in range(N):
    a,b = map(int, input().split())
    cords += [[a,b]]

d = [[0 for i in range(N)] for i in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        d[i][j] = d[j][i] = distance(cords[i],cords[j])

whole = math.factorial(N)
distance = 0
ps = permutations([i for i in range(N)])
for perm in ps:
    dis = 0
    
    for way in range(1,len(perm)):
        
        dis += d[perm[way-1]][perm[way]]
    
    distance += dis / whole
print(distance)

Solution (Python):
import math as m

N = int(input())
li = [list(map(int, input().split())) for _ in range(N)]
xs,ys = list(zip(*li))

ans = 0
for i in range(N):
    for j in range(N):
        ans += m.sqrt((xs[i]-xs[j])**2 + (ys[i]-ys[j])**2)

print(ans/N)

Solution (Python):
from itertools import permutations
import math

n = int(input())

x = []
y = []
v = []

for i in range(n):
    v.append(i)
    x1, y1 = map(int, input().split())
    x.append(x1)
    y.append(y1)

ans = 0
cnt = 0

for i in list(permutations(v)):
    for f in range(1, n):
        ans += math.sqrt((x[i[f - 1]] - x[i[f]])*(x[i[f - 1]] - x[i[f]]) + (y[i[f - 1]] - y[i[f]])*(y[i[f - 1]] - y[i[f]]))
    cnt += 1

ans /= cnt
print(ans)

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

dist = 0

for i in range(n):
    for j  in range(n):
        dist += ((ls_p[i][0] - ls_p[j][0])**2 + (ls_p[i][1] - ls_p[j][1])**2)**(1/2)

print(dist/n)

Solution (Python):
import math
N = int(input())
XY = [[int(i) for i in input().split()] for i in range(N)]

sum_distance = 0
for i in range(N-1):
    for j in range(i, N):
        dist = (XY[i][0] - XY[j][0])**2 + (XY[i][1]-XY[j][1])**2
        dist = dist ** 0.5
        sum_distance += dist
        
ans = (sum_distance * math.factorial(N-1)*2) / math.factorial(N)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(1000000)

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

sumAll = 0
def func(src, nxt, visited, sum):
    global sumAll
    visited |= 1<<nxt
    d = ((P[src][0]-P[nxt][0])**2 + (P[src][1]-P[nxt][1])**2)**0.5
    if visited == (1<<N) - 1:
        sumAll += sum + d
        return
    for i in range(N):
        if not visited>>i&1:
            func(nxt, i, visited, sum+d)

for i in range(N):
    func(i, i, 0, 0)

while N > 1:
    sumAll /= N
    N -= 1

print(sumAll)

Solution (Python):
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def powd(x, n, m):
  ans = 1
  while(n > 0):
    if(bin(n & 1) == bin(1)):
      ans = (ans*x)%m
    x = x*x % m
    n = n >> 1 
  return ans




n = int(input())
city = []
for i in range(n):
    city.append(list(map(int, input().split())))
ans=0
for i in range(n):
    for j in range(n-1-i):
        ans += ((city[i][0]-city[j+i+1][0])**2 + (city[i][1] - city[j+i+1][1])**2)**0.5
        
com=[1 for i in range(12)]
 
for ii in range(10):
    i = ii+1
    com[i+1] = (com[i]*(i+1))

ans *= com[n-1]
ans /= com[n]
print(ans*2)

Solution (Python):
import math
a = int(input())
t = [list(map(int, input().split())) for i in range(a)]
x = 0
for i in range(a):
    for j in range(a):
        x = x + ((t[i][0]-t[j][0])**2 +(t[i][1]-t[j][1])**2)**0.5
print(x*math.factorial(a-1)/(math.factorial(a)))

Solution (Python):

import itertools
import math



N = int(input())



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



K = 0
C = list(itertools.combinations(list(range(N)),2))
for c in C :
    
    k = (T[c[0]][0] - T[c[1]][0]) * (T[c[0]][0] - T[c[1]][0]) + (T[c[0]][1] - T[c[1]][1]) * (T[c[0]][1] - T[c[1]][1])
    k = math.sqrt(k)
    K += k

kaisu = (N - 1) * math.factorial(N) / len(C)

print(K * kaisu  / math.factorial(N))

Solution (Python):
import math

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

m = 0
for list_i in list_1:
    for list_j in list_1:
        if list_i != list_j:
            d = math.sqrt((list_j[0]-list_i[0])**2 + (list_j[1]-list_i[1])**2)
            m += d

average = m / N
print(average)

Solution (Python):
import sys
import math

n = int(input())
x = [0] * n
y = [0] * n

def init():
    global x, y
    for i in range(n):
        ss = sys.stdin.readline()
        cord = ss.split(' ')
        x[i] = int(cord[0])
        y[i] = int(cord[1])

a = [0] * n
used = [False] * n
m = 0
count = 0
def dist():
    global x, y, n
    sum = 0.0
    for i in range(n - 1):
        i0 = a[i]
        i1 = a[i + 1]
        sum += math.sqrt((x[i0] - x[i1]) ** 2 + (y[i0] - y[i1]) ** 2)
    return sum
def work(i):
    global m, count
    if i >= n:
        m += dist()
        count += 1
    else:
        for k in range(n):
            if not used[k]:
                used[k] = True
                a[i] = k
                work(i + 1)
                used[k] = False
        
init()
work(0)
print m / count

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

k=0
m=math.factorial(n)
for i in range(n):
    for j in range(i,n):
        k+=((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)**0.5
p=k*2*((n-1)*(math.factorial(n-2)))
print(p/m)

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

def d(X1, X2):
    return ((X1[0] - X2[0]) ** 2 + (X1[1] - X2[1]) ** 2) ** 0.5

sum = 0
for i in range(N):
    for j in range(i):
        sum += d(X[i], X[j])

ans = sum * 2 / N
print(ans)

Solution (Python):
import numpy as np
n = int(input())
x = [list(map(int, input().split())) for _ in range(n)]

positions = np.array(x)
tmp_index = np.arange(positions.shape[0])
xx, yy = np.meshgrid(tmp_index, tmp_index)
distances = np.linalg.norm(positions[xx]-positions[yy], axis=2)

num = np.sum(distances)
print(num/n)

Solution (Python):
import math
from itertools import permutations
n=int(input())
p=[]
for i in range(n):
    x,y=map(int,input().split())
    p.append([x,y])
s=list(permutations(p))
a=[]
for c in s:
    l=[]
    for d in range(n-1):
        xi=c[d][0]
        xj=c[d+1][0]
        yi=c[d][1]
        yj=c[d+1][1]
        t1=(xi-xj)**2
        t2=(yi-yj)**2
        l.append(math.sqrt(t1+t2))
    a.append(sum(l))
print(sum(a)/len(a))

Solution (Python):
import math,itertools
n = int(input())
x = []
y = []
l = []
d = []
s = []
for i in range(n):
  a,b = map(int,input().split())
  x.append(a)
  y.append(b)
  l.append(i+1)
for j in itertools.permutations(l):
  for k in range(len(j)-1):
    d.append(math.sqrt((x[j[k]-1]-x[j[k+1]-1])**2+(y[j[k]-1]-y[j[k+1]-1])**2))
  s.append(sum(d))
  d = []
print(
sum(s)/math.factorial(n))

Solution (Python):
import math
import numpy as np

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

count = 0

for a in range(N):
    x[a],y[a] = (int(num) for num in input().split())
    
for b in range(N):    
    for c in range(N):
        count += np.sqrt((x[b]-x[c])*(x[b]-x[c]) + (y[b]-y[c])*(y[b]-y[c]))
        
ans = count * int(math.factorial(N-1)) / int(math.factorial(N))
print(ans)

Solution (Python):
import math

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

m = 0
for list_i in list_1:
    for list_j in list_1:
        if list_i != list_j:
            d = math.sqrt((list_j[0]-list_i[0])**2 + (list_j[1]-list_i[1])**2)
            m += d

average = m / N
print(average)

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


def calc(prev: list, _next: list):
    return sqrt((prev[0] - _next[0]) ** 2 + (prev[1] - _next[1]) ** 2)


def main(n: int, x_y: list):
    length = []

    for p in permutations(range(n), n):
        
        

        i = 0
        while i < len(p) - 1:
            length.append(calc(x_y[p[i]], x_y[p[i + 1]]))
            i += 1

    print("{:.10f}".format(sum(length) / factorial(n)))

if __name__ == "__main__":
    n = int(input())
    x_y = [list(map(int, input().split())) for _ in range(n)]

    main(n, x_y)

Solution (Python):
import math
import itertools
X=[]
Y=[]
L=0
N=int(input())
Perm=list(itertools.permutations(range(N)))
for i in range(N):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
for p in Perm:
    for j in range(N-1):
        L+=math.sqrt(abs(X[p[j]]-X[p[j+1]])**2 + abs(Y[p[j]]-Y[p[j+1]])**2)
print(L/math.factorial(N))

Solution (Python):
import math

n=int(input())
listx=[]
listy=[]

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



listl=[]
if n==2:
	ans=((listx[1]-listx[0])**2+(listy[1]-listy[0])**2)**0.5



else:
	for i in range(n-1):
		for j in range(i+1,n):
			l=((listx[i]-listx[j])**2+(listy[i]-listy[j])**2)**0.5
			listl.append(l)
	ll=sum(listl)	
	ans=2*ll/n

print(ans)

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

for i in itertools.permutations(length): 

   result = []
   for i1 in range(len(i)-1):
       result.append(math.sqrt((x[i[i1]][0]-x[i[i1+1]][0])**2 + (x[i[i1]][1]-x[i[i1+1]][1]) **2))


   ans.append(sum(result))

print(sum(ans)/len(ans))

Solution (Python):
import math

N = int(input().strip())
A = [list(map(int, input().strip().split())) for i in range(N)]
d = [[-1 for i in range(N)] for j in range(N)]
for i in range(N):
    ax = A[i][0]
    ay = A[i][1]
    for j in range(i+1,N):
        bx = A[j][0]
        by = A[j][1]

        tmp = math.sqrt((ax-bx)**2 + (ay-by)**2)
        d[i][j] = tmp
        d[j][i] = tmp

total = 0
for i in range(N):
    for j in range(i+1,N):
        total += d[i][j]


def func(check, k, town, to):
    if k == N:
        return to
    t = 0
    for i in range(N):
        if i == town or check[i] :
            continue
        
        check[i] = True
        t += func(check, k+1, i, to + d[town][i])
        check[i] = False
    return t
check = [False] * N
total = 0
for i in range(N):
    
    check[i] = True
    total += func(check, 1, i, 0)
    check[i] = False
print(total/math.factorial(N))

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

itl_L = list(itertools.permutations(L))

lens = 0

for elem in itl_L:
  
  for i in range(len(elem)-1):
    
    length = math.sqrt((elem[i][0]-elem[i+1][0])**2 +
                       (elem[i][1]-elem[i+1][1])**2
                      )
    
    lens += length
print(lens/len(itl_L))

Solution (Python):
N = int(input())
P = [0 for i in range(N)]
for i in range(N):
    x,y = map(int,input().split())
    P[i] = [x,y]
ans = 0
def cal(a,b):
    res = (a[0] - b[0])** 2 + (a[1]-b[1])**2
    return res ** 0.5
for i in range(N):
    for j in range(N):
        if i != j :
            ans += cal(P[i],P[j])

ans /= N
print(ans)

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

import math

def get_distance(r1, r2):
  return math.sqrt((r1[0]-r2[0])*(r1[0]-r2[0])+(r1[1]-r2[1])*(r1[1]-r2[1]))

idx = [i for i in range(N)]
import itertools
p = itertools.permutations(idx, N)

total_distance = 0.0
count = 0

for order in p:
  for i in range(N-1):
    total_distance += get_distance(r[order[i]], r[order[i+1]])
print(total_distance/math.factorial(N))

Solution (Python):
import math

n=int(input())

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

sum = 0
for i in range(1,n):
    sum += i 

kazu = math.factorial(n)*(n-1)
tori = kazu/sum

dis = 0
for i in range(n-1):
    for j in range(i, n-1):
        dis += math.sqrt((x[j+1]-x[i])*(x[j+1]-x[i]) + (y[j+1]-y[i])*(y[j+1]-y[i]))
    
print(round(dis*tori/math.factorial(n),10))

Solution (Python):
import itertools
import math

N = int(input())
XY = []
for i in range(N):
    x, y = map(int, input().split())
    XY.append([x, y])
p = list(itertools.permutations(list(range(N))))
dist = []
for i in p:
    d = 0
    for j in range(0, len(i)-1):
        d += math.sqrt((XY[i[j]][0]-XY[i[j+1]][0])**2+(XY[i[j]][1]-XY[i[j+1]][1])**2)
    dist.append(d)
print(sum(dist)/len(p))

Solution (Python):
from math import sqrt

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

dp = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j:
            pass
        elif i > j:
            dp[i][j] = dp[j][i]
        else:
            dp[i][j] = sqrt((XY[i][0]-XY[j][0])**2 + (XY[i][1]-XY[j][1])**2)

ans = 0
for i in range(N):
    for j in range(N):
        ans += dp[i][j]
print(ans/N)

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

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

ans=7641.9817824387

def add(s,i):
    global dp
    if i==n:
        pass
    elif s==i:
        add(s,i+1)
    else:
        dp[s][i]=(((a[i][0]-a[s][0])**2)+(a[i][1]-a[s][1])**2)**0.5
        add(s,i+1)

cnt=1
for i in range(n):
    add(i,0)
    cnt*=i+1

for i in range(n):
    res+=sum(dp[i])
    
abc=1
for i in range(n-1):
    abc*=i+1

print(res*abc/cnt)

Solution (Python):
import math
n = int(input())
x = []
y = []
sum = 0
for i in range(n):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
for i in range(n):
    for j in  range(n):
        sum += math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
average  = (math.factorial(n)/n)*sum/(math.factorial(n))
print(average)

Solution (Python):
import itertools,math,statistics
N = int(input())
town = []
for p in range(N):
    q = list(map(int, input().split()))
    town.append(q)
perm = itertools.permutations(town)
c = []
for i in list(perm):
    b = 0
    for j in range(N-1):
        a = math.sqrt((i[j][0]-i[j+1][0])**2 + (i[j][1]-i[j+1][1])**2)
        b += a
    c.append(b)
print(statistics.mean(c))

Solution (Python):
import math

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

def bfs(flg, cp, tot):
	if flg.count(0) == 0:
		return tot

	ans = 0
	for np in [i for i in range(N) if flg[i] == 0]:
		d = ((x[cp]-x[np])**2 + (y[cp]-y[np])**2) ** (1/2)
		flg[np] = 1
		ans += bfs(flg, np, tot+d)
		flg[np] = 0

	return ans

flg = [0] * N

A = 0

for i in range(N):
	flg[i] = 1
	A += bfs(flg,i,0)
	flg[i] = 0

for i in range(1,N+1):
	A /= i

print(A)

Solution (Python):
import math
import itertools
subete=1
n=int(input())
ichi=[]
for i in range(n):
	ichi.append(list(map(int,input().split())))
for i in range(1,n+1):
	subete=subete*i
route=[]
for i in itertools.permutations(range(n)):
	route.append(i)
gokei=0
for i in range(len(route)):
	kari=0
	for j in range(1,n):
		kari+=math.sqrt((ichi[route[i][j]][0]-ichi[route[i][j-1]][0])**2+(ichi[route[i][j]][1]-ichi[route[i][j-1]][1])**2)
	gokei+=kari
print(gokei/(subete))

Solution (Python):
from math import sqrt
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
count = 1
summary = 0
for i in range(N):
    
    for j in range(N):
        if i == j:
            continue
        
        summary += sqrt(((xy[i][0] - xy[j][0]) ** 2) + ((xy[i][1] - xy[j][1]) ** 2))

print((summary / N))

Solution (Python):
import numpy

N = int(input())
X = numpy.zeros(N)
Y = numpy.zeros(N)

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

diff_X = (X[None, :] - X[:, None]) ** 2
diff_Y = (Y[None, :] - Y[:, None]) ** 2

distances = (diff_X + diff_Y) ** .5
print(distances.mean() * N)

Solution (Python):
import itertools

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

ans = list(itertools.permutations(range(n),n))

def sqrt(a,b,c,d):
    return(((c-a)**2+(d-b)**2)**0.5)

tot = 0
for aa in ans:
    for i in range(n-1):
        tot += sqrt(x[aa[i]],y[aa[i]],x[aa[i+1]],y[aa[i+1]])
print(tot/len(ans))

Solution (Python):
import math
import itertools
n = int(input())
p_n = [list(map(int, input().split()))for i in range(n)]
l = list(itertools.permutations(range(n), n))
r = []
for _l in l:
    _r = []
    for i in range(len(_l)-1):
        _r.append(math.sqrt(((p_n[_l[i]][0]-p_n[_l[i+1]][0])**2)+((p_n[_l[i]][1]-p_n[_l[i+1]][1])**2)))
    r.append(sum(_r))

print(sum(r)/len(r))

Solution (Python):
import math

N = int(input())
dot = [0] * N
for i in range(len(dot)):
    dot[i] = input().split(" ")
    dot[i][0] = int(dot[i][0])
    dot[i][1] = int(dot[i][1])

ans = 1
for i in range(len(dot)-1):
    ans = ans  * (i + 1)

length = 0
for i in range(len(dot)):
    for j in range(len(dot)):
        x = (dot[i][0] - dot[j][0])
        y = (dot[i][1] - dot[j][1])
        length = length + math.sqrt(x*x + y*y)

print(length/N)

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

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

A = list(itertools.permutations(A))

sum = 0

for i in A:
    for j in range(N):
        if j+1==N:
            break
        sum = sum + (((i[j][0]-i[j+1][0])**2+(i[j][1]-i[j+1][1])**2)**0.5).real

print((sum/math.factorial(N)).real)

Solution (Python):
import itertools as it
import math

a = int(input())
b = []
for i in range(a):
  var0 = input().split()
  var0 = [int(i) for i in var0]
  b.append(var0)
li = list(it.permutations(b))
result = []
for i in li:
  re = []
  for j in range(a - 1):
    re.append(math.sqrt((i[j + 1][0] - i[j][0]) * (i[j + 1][0] - i[j][0]) + (i[j + 1][1] - i[j][1]) * (i[j + 1][1] - i[j][1])))
  result.append(sum(re))
print(sum(result) / len(result))

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

Solution (Python):
import numpy, itertools

N = int(input())
points = []

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

total = 0
for p1, p2 in itertools.combinations(points,2):
    q1 = numpy.array(p1)
    q2 = numpy.array(p2)
    total += numpy.linalg.norm(q1 - q2)

print(total * 2.0 / N)

Solution (Python):
import math

cityNum = int(input())
city = [[0] * 2 for i in range(cityNum)]
for i in range(cityNum):
  city[i][0], city[i][1] = map(int, input().split())
if cityNum == 2:
  mulTimes = 2
  divNum = 2
else:   
  mulTimes = math.factorial(cityNum - 1) * 2
  divNum = math.factorial(cityNum)
total = 0.0
for i in range(cityNum-1):
  j = i + 1
  while j < cityNum:
    length = math.sqrt((city[i][0] - city[j][0]) ** 2 + (city[i][1] - city[j][1]) ** 2)
    total = total + length * mulTimes
    j = j + 1
ans = total / divNum
print(ans)

Solution (Python):




def I(): return int(input())


def IsIl(): return list(map(lambda x: int(x), input().split()))


def InIl(n): return [input() for i in range(n)]


def IsIt(): return map(lambda x: int(x), input().split())


def InIl(n): return map(input() for i in range(n))


def SsSl(): return list(map(lambda x: x, input()))




def SSd():
    from collections import defaultdict
    A = input() 
    dd=defaultdict(int)
    for a in A:
        dd[a]+=1
    return dd

import math

n = I()
lis = []
for i in range(n):
    tup = IsIl()
    lis.append(tup)

sum = 0.0
for i in range(n):
    [x1,y1] = lis[i]
    for j in range(n):
        [x2,y2] = lis[j]
        sum += ((x1-x2)**2 + (y1-y2)**2)**0.5
print(sum/n)

Solution (Python):
import math
import itertools
N = int(input())
x = [0]*N
y = [0]*N
s = 0
for i in range(N):
  x[i],y[i] = (int(z) for z in input().split())
for i in itertools.permutations(range(N)):
  towns = list(i)
  for t in range(len(towns)-1):
    s += math.sqrt((x[towns[t+1]]-x[towns[t]])**2+(y[towns[t+1]]-y[towns[t]])**2)
print(s/math.factorial(N))

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

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

distance = [[0]*n for _ in range(n)]
    
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
        distance[i][j] = d
        distance[j][i] = d

print(sum(map(sum, distance)) / n )

Solution (Python):
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
print(ans*2/n)

Solution (Python):
import math

n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
dist = [[0 for _ in range(n-1)] for _ in range(n)]
ans = 0

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)
        dist[i].append(d)
    ans += sum(dist[i]) * math.factorial(n-1)

print(ans / math.factorial(n))

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

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

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


result=0.0

import itertools
no=[]
for i in range(n):
  no.append([i])

junjo=[]
for i in itertools.permutations(no):
  temp=[]
  for item in i:
    temp.append(item[0])
  junjo.append(temp)
  


result=0.0

count=0
for item in junjo:
  i=0
  
  temp=0
  while i < n-1:
    start=item[i]
    end=item[i+1]
    
    temp+=((zahyo[start][0]-zahyo[end][0])**2+(zahyo[start][1]-zahyo[end][1])**2)**(1/2)
    
    i+=1
  
  result+=temp
  count+=1
  
print(result/count)

Solution (Python):
import itertools, math

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

j = list(range(n))
total = 0
c = 0
for v in itertools.permutations(j, n):
    for k in range(n - 1):
        a, b = v[k], v[k + 1]
        total += math.sqrt(((x[b] - x[a]) ** 2) + ((y[b] - y[a]) ** 2))
    c += 1

ave = total / c
print(ave)

Solution (Python):
n = int(input())
s = 0
x = []
y = []
if n == 2:
  l = 1
elif n == 3:
  l = 3
else:
  l = n*(n-1)/2
for i in range(0,n):
	a, b = map(int, input().split())
	x.append(a)
	y.append(b)
for i in range(0,n):
	for j in range(i,n):
		s += ((x[i] - x[j])**2 + (y[i] - y[j])**2)**(1/2)
ans = (n - 1)*s/l
print(ans)

Solution (Python):
import itertools,math

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

perm = list(itertools.permutations(xy,N))
length = len(perm)
total = 0.00000

for i in range(length):
    for j in range(len(perm[0])-1):
        total += math.sqrt((perm[i][j][0] - perm[i][j+1][0]) ** 2 + (perm[i][j][1] - perm[i][j+1][1]) ** 2)

print(total / length)

Solution (Python):
N = int(input())
Mylist = []
ANSlist = []
for i in range(N):
    a, b = map(int, input().split())
    Mylist.append([a,b])

for i in range(N):
    for j in range(i,N):
        length = ((abs(Mylist[i][1]-Mylist[j][1]))**2 + (abs(Mylist[i][0]-Mylist[j][0]))**2)**(1/2)
        ANSlist.append(length)

way = N*(N-1)
anotherway = 2*(N-1)
print(anotherway*sum(ANSlist)/way)

Solution (Python):
import itertools
import math
N = int(input())
C = [i for i in range(N)]
X = [list(map(int,input().split())) for i in range(N)]
A = 0
B = list(itertools.permutations(C,N))
for i in range(len(B)):
    for j in range(N - 1):
        a = B[i][j]
        b = B[i][j+1]
        A += ((X[a][0] - X[b][0]) ** 2 + (X[a][1] - X[b][1]) ** 2) ** 0.5
print(A/math.factorial(N))

Solution (Python):
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math


N = int(stdin.readline().rstrip())
X = []
Y = []
for el in range(N):
    tmp = [int(s) for s in stdin.readline().rstrip().split()]
    X.append(tmp[0])
    Y.append(tmp[1])

patt = math.factorial(N) / 2
noUseRootNum = patt-math.factorial(N-1)
diss = []
for k in range(N):
    for l in range(N):
        if (k >= l):
            continue
        diss.append(((X[k]-X[l])**2+(Y[k]-Y[l])**2)**0.5)


res = 0
for el in diss:
    res += el*(patt - noUseRootNum)
print(res/patt)

Solution (Python):


import math
n = int(input())
x_list = []
y_list = []
N = 1
m = 2
d_sum = 0
for i in range(2, n + 1):
    N *= i
    m *= (i - 1)
for i in range(0, n):
    x, y = map(int, input().split())
    x_list.append(x)
    y_list.append(y)

for i in range(0, n - 1):
    for j in range(i + 1, n):
        d_sum += m * math.sqrt((x_list[i] - x_list[j])**2 + (y_list[i] - y_list[j])**2)
print(d_sum / N)

Solution (Python):
import math

def factorial(n):
    if n==1:
        return n
    else:
        return n*factorial(n-1)
    
def calc_dist(city_a, city_b):
    x_a, y_a = city_a
    x_b, y_b = city_b
    return (math.sqrt((x_b - x_a)**2 + (y_b - y_a)**2))

        
n = int(input())
fact = factorial(n)
fact_n_1 = factorial(n-1)
cities = []
for i in range(n):
    x,y = list(map(int,input().split()))
    cities.append([x,y])
    
distance_sum = 0
count=0
for i in range(n):
    for j in range(n-1-i):
        distance_sum += calc_dist(cities[j+i+1], cities[i]) * fact_n_1 * 2
        
print(distance_sum/fact)

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

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

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





a = [i for i in range(N)]
b = list(itertools.permutations(a))

e = []
for i in range(len(b)):
    c = 0
    for j in range(len(b[i]) - 1):
        row = b[i][j]
        column = b[i][j+1]
        if d[row][column] != 0:
            c += d[row][column]
            continue
        dx = xy[row][0] - xy[column][0]
        dy = xy[row][1] - xy[column][1]
        d[row][column] = math.sqrt(dx ** 2 + dy ** 2)
        c += d[row][column]
    e.append(c)
ans = sum(e)/len(e)
print(ans)

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

X = []
Y = []

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

total = 0

for i in range(0 , N-1):
    for j in range(i+1 , N):
        total += ((X[i]-X[j])**2 + (Y[i]-Y[j])**2)**(1/2)

average = 2 / N * total

print(average)

Solution (Python):


import numpy as np
import itertools

N = int(input())
xs = np.zeros(N)
ys = np.zeros(N)
for i in range(N):
  xs[i], ys[i] = map(int, input().split())

lenMat = np.zeros((N, N))
for j in range(N):
  for i in range(N):
    lenMat[j,i] = np.sqrt((xs[i]-xs[j])**2 + (ys[i]-ys[j])**2)

sumVal = 0.0     
count = 0

seq = np.arange(N)
for lst in list(itertools.permutations(seq)):
    
    count += 1
    for i in range(N-1):
	    sumVal += lenMat[lst[i], lst[i+1]] 

print(sumVal/count)