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):
from itertools import permutations
import math
n = int(input())
perm = permutations(range(n)) 
a = []
b = []
r = []
for i in range(n):
	x,y = map(int,input().split())
	a.append(x)
	b.append(y)
for i in perm:
	x,y = a[i[0]],b[i[0]]
	res = 0
	for j in i[1:]:
		res += math.sqrt((a[j]-x)*(a[j]-x)+(b[j]-y)*(b[j]-y))
	r.append(res)
print(sum(r)/len(r))

Solution (Python):
import itertools
import math

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

l = list(range(N))
a = []

for i in itertools.permutations(l, N):
  a.append(list(i))
  
D = 0

for i in range(math.factorial(N)):
  d = 0
  for j in range(N-1):
    d += math.sqrt((xy[a[i][j]][0]-xy[a[i][j+1]][0])**2 + (xy[a[i][j]][1]-xy[a[i][j+1]][1])**2)
  else:
    D += d
    
print(D / math.factorial(N))

Solution (Python):


import sys, math
sys.setrecursionlimit(300000)


def solve(N: int, x: "List[int]", y: "List[int]"):
    ret = 0
    total = 0
    for i in range(N):
        for j in range(i + 1, N):
            total += math.sqrt((x[j] - x[i]) ** 2 + (y[j] - y[i]) ** 2)
    comb = N * (N - 1) // 2
    perm = 1
    for i in range(1, N + 1):
        perm *= i
    ret = total * ((N - 1) * perm // comb)
    ret /= perm
    print(ret)
    return

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))
    solve(N, x, y)

if __name__ == '__main__':
    main()

Solution (Python):
from math import sqrt
from math import factorial
 
n = int(input())
t = []
for i in range(n):
  t.append(list(map(int,input().split())))
l = [[0]*n for j in range(n)]
for k in range(n):
  for m in range(n):
      l[k][m] = sqrt((t[k][0]-t[m][0])**2+(t[k][1]-t[m][1])**2)
ans = 0
for i in range(n):
  s = sum(l[i])
  ans += s*factorial(n-1)
z = ans/factorial(n)
print(z)

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

for v in itertools.permutations(xy, N):
    p.append(v)

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

print(ans / len(p))

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

aaa = 0
for i in range(N):
    for k in range(N):
        aaa += ((x[i] - x[k])**2+(y[i] - y[k])**2)**0.5
print(aaa/N)

Solution (Python):
import math
import itertools
n = int(input())
x = [0]*n
y = [0]*n
town =[[0 for _ in range(2)]for _ in range(n)]
dist = [[0 for _ in range(n)]for _ in range(n)]
comb = [[0 for _ in range(n)]for _ in range(n)]
ans = 0
for i in range(n):
	x[i],y[i] = map(int,input().split())
	town[i] = (x[i],y[i])




for i in range(n):
	for j in range(n):
		if i!=j:
			dist[i][j] = math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
			dist[j][i] = dist[i][j]
for i in range(n):
	for j in range(n):
		ans += dist[i][j]

print(ans/n)

Solution (Python):
import math

n = int(input())
town = [list(map(int, input().split())) for _ in range(n)]
sum = 0
for i in range(n-1):
    for j in range(i + 1, n):
        x1, y1 = town[i]
        x2, y2 = town[j]
        sum += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

print(2*sum/n)

Solution (Python):
import itertools
import math


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

    sum_length = 0.0
    sum_count = 0

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

    print(sum_length/sum_count)

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

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

for i in range(n):
    for j in range(n):
        L.append(((li[i][0]-li[j][0])**2 + (li[i][1]-li[j][1])**2)**0.5)
    
print(sum(L)/n)

Solution (Python):


import numpy as np
import math

N = int(input())

loc = []
for _ in range(N):
    line = input().split(" ")
    loc.append([ int(line[0]), int(line[1]) ])

loc = np.array(loc)

if(N==2):
    print(np.linalg.norm(loc[0]-loc[1]))
else: 
    
    mat = np.zeros((N,N))
    for i in range(N):
        for j in range(i, N):
            mat[i][j] = np.linalg.norm(loc[i]-loc[j])
            
    for i in range(N):
        for j in range(0, i):
            mat[i][j] = mat[j][i]
      
    mat = mat * (N-1) * math.factorial(N-2)
    print(np.sum(mat) / math.factorial(N))

Solution (Python):
import math

N = int(input())
D = []
for i in range(N):
    D.append(list(map(int, input().split())))
s = 0
while len(D) > 1:
    a = D[0]
    for d in D[1:]:
        s += ((a[0] - d[0]) ** 2 + (a[1] - d[1]) ** 2) ** 0.5
    D = D[1:]
print((s * (math.factorial(N - 1) * 2)) / (math.factorial(N)))

Solution (Python):
import itertools

if __name__ == '__main__':

    n = int(input())
 

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

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

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

    p_list = list(itertools.permutations(p))

    total = 0
    for i in range(len(p_list)):
        sum = 0
    
        for j in range(n-1):
            x1,y1 = int(town[p_list[i][j]][0]), int(town[p_list[i][j]][1])
            x2,y2 = int(town[p_list[i][j+1]][0]), int(town[p_list[i][j+1]][1])
    
            sum = sum + ((x2-x1)**2+(y2-y1)**2)**0.5
       

        total = total + sum
       

    
    print(total/float(len(p_list)))

Solution (Python):
import numpy as np
from scipy.spatial import distance
from scipy.sparse.csgraph import floyd_warshall
n = int(input())
xy = np.zeros((n, 2))
for i in range(n):
    xy[i, 0], xy[i, 1] = (int(x) for x in input().split())
c = distance.cdist(xy, xy, metric='euclidean')
cost = floyd_warshall(c)
print(np.sum(c)/n)

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

l_s = 0

for i in range(N):
    for j in range(N):
        l_s += (((X[i]-X[j])**2) + ((Y[i]-Y[j])**2)) **(0.5)
ans = l_s / N
print(ans)

Solution (Python):
import itertools
import math
import numpy as np
z = []
N = int(input())
for i in range(N):
  z.append(list(map(int,input().split(' '))))
d = 0  
x = []
p = list(itertools.permutations(z, N))

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

  

print(sum(x)/len(x))

Solution (Python):
def dist(a,b,c,d):
  return ((a-c)**2+(b-d)**2)**(1/2)
N=int(input())
m=0
z=[list(map(int,input().split())) for _ in range(N)]
for i in range(N):
  for j in range(i+1,N):
    m+=dist(z[i][0],z[i][1],z[j][0],z[j][1])
print(float(2*m/N))

Solution (Python):
N = int(input())
data = []
sum = 0
x = 0
y = 1
for i in range(N):
    data.append( list(map(int,input().split())))
for i in range(N):
    for j in range(N):
        if(i==j):
            continue
        sum+=((data[i][x]-data[j][x])**2+(data[i][y]-data[j][y])**2)**0.5

print(sum/N)

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

Solution (Python):
def main():
    N = int(input())
    xy = [[0,0] for _ in range(N)]
    for a in xy:
        a[0], a[1] = map(int, input().split())
    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)


if __name__ =='__main__': main()

Solution (Python):
n=int(input())
XY=[tuple(map(int,input().split())) for _ in range(n)]
dist=0
for i in range(n):
    for j in range(i+1,n):
        dist+=((XY[i][0]-XY[j][0])**2+(XY[i][1]-XY[j][1])**2)**0.5
dist*=2/n
print(dist)

Solution (Python):
n=int(input())
xy=[]
for _ in range(n):
	x,y=map(int,input().split())
	xy.append([x,y])
ans=0
for i in range(n):
	for j in range(n):
		ans+=((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**0.5
print(ans/n)

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


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


def main():
    N = int(input())
    town_list = [tuple(map(int, input().split())) for _ in range(N)]
    ans_list = []

    a = permutations(town_list, len(town_list))

    for v in a:
        tmp = 0
        for i in range(len(v) - 1):
            tmp += calc_dist(v[i], v[i + 1])
        ans_list.append(tmp)

    print(sum(ans_list) / len(ans_list))


if __name__ == "__main__":
    main()

Solution (Python):
import math
import itertools

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





def root(xi, yi, xj, yj):
    return math.sqrt((xi - xj) ** 2 + (yi - yj) **2)




















l = x



m = 0
for i in itertools.permutations(l, len(l)):
    k = 0
    for j in range(len(i) -1):
        k += root(*(i[j] + i[j+1]))
    m += k
print(m/math.factorial(len(l)))

Solution (Python):

import math
import copy

def calc_distance(town1, town2):
    distance_pow = (town1[0] - town2[0])**2 + (town1[1] - town2[1])**2
    distance = math.sqrt(distance_pow)
    return distance

def calc(L, done_towns, todo_towns):
    sum = 0
    if len(todo_towns) == 1:
        done_towns.append(todo_towns[0])
        distance = 0
        while(len(done_towns) >= 2):
            first_town = done_towns.pop(0)
            second_town = done_towns[0]
            min_town = min(first_town, second_town)
            max_town = max(first_town, second_town)
            distance += L[min_town*10 + max_town]
        return distance

    for town in todo_towns:
        new_done_towns = copy.copy(done_towns)
        new_todo_towns = copy.copy(todo_towns)
        new_done_towns.append(town)
        new_todo_towns.remove(town)
        sum += calc(L, new_done_towns, new_todo_towns)

    return sum

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

L = [0] * 78


for i in range(N):
    for j in range(i+1, N):
        L[i*10 + j] = calc_distance(town_points[i], town_points[j])

sum_distance = calc(L, [], list(range(N)))
N_factorial = math.factorial(N)
average_distance = sum_distance / N_factorial

print(average_distance)

Solution (Python):
import itertools
import math
N = int(input())
A =[0]*N
B =[0]*N
su =0
count=0
for i in range(N):
  A[i],B[i] =map(int, input().split())
for i in itertools.permutations(range(N)):
  count +=1
  for j in range(1,len(i)):
    su += math.sqrt((A[i[j]]-A[i[j-1]])**2+(B[i[j] ]-B[i[j-1]])**2)
print(su/count)

Solution (Python):
import itertools

def calculate_distance(o, n):
    return ((o[0]-n[0])**2 + (o[1]-n[1])**2)**0.5

n = int(input())
position = []
distance_list = []

for _ in range(n):
    position.append(list(map(int, input().split())))


for target in itertools.permutations(position):
    old = target[0]
    distance = 0
    for new in target:
        distance += calculate_distance(old, new)
    distance_list.append(distance)

print(sum(distance_list)/len(distance_list))

Solution (Python):
import math

num = int(input())
co = []

for i in range(num):
    co.append(list(map(int, input().split())))


pat = math.factorial(num)

num -= 1
dis = 0

for i in range(num):
    for j in range(num):
        dis += math.sqrt((co[i][0]-co[j+i+1][0])**2 + (co[i][1]-co[j+i+1][1])**2)
        if num == j+i+1: break

dis *= 2/(num+1)

print(dis)

Solution (Python):
n = int(input())
x = [list(map(int, input().split())) for i in range(n)]
def kaijo(a):
    s = 1
    for i in range(2,a+1):
        s = s * i
    return(s)
l = []
for i in range(n):
    for j in range(n):
        if not i == j:
            l.append(((x[i][0]-x[j][0])**2+(x[i][1]-x[j][1])**2)**0.5)
print(sum(l)*kaijo(n-1)/kaijo(n))

Solution (Python):
import math

N = int(input())
P = [list(map(int,input().split())) for i in range(N)]
p = P
r = 0
n = (N*(N-1))/2
s = N * (N -1)

while len(p) != 1:
    for i in range(len(p)-1):
        r = r + math.sqrt(pow((p[0][0]-p[i+1][0]),2) + (pow((p[0][1]-p[i+1][1]),2)))
    p = p[1:len(p)]

print((r*((s*2)/N))/s)

Solution (Python):
import math

N = int(input())

cors = []
for i in range(N):

    xy = input().split()
    cors.append(xy)

sumnum = 0

n = 0
for i in range(N):

    for j in range(i,N):
        if i == j:
            continue
        else:
            n = n+1
            
            xi = int(cors[i][0])
            xj = int(cors[j][0])
            yi = int(cors[i][1])
            yj = int(cors[j][1])
            sumnum = sumnum + math.sqrt((xj-xi)*(xj-xi)+(yj-yi)*(yj-yi))
print(sumnum/n*(N-1))

Solution (Python):
n=int(input())
a=[]
b=[]
for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(n):
    for j in range(n):
        b.append(((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)**0.5)
print((sum(b)/(len(b)-n))*(n-1))

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

entHai = []

def newHai(preHai, hai):
    global entHai
    if len(hai) == 1:
        entHai.append(preHai+hai)

    
    for h in hai:
        narr = [na for na in hai if na != h]
        
        narr = newHai(preHai + [h], narr)
        

newHai([], list(range(N)))

keiroSum = 0
for eh in entHai:
    
    for nn in range(1, N):
        xi, yi = xy[eh[nn-1]]
        xj, yj = xy[eh[nn]]
        keiroSum += pow((xi-xj)**2 + (yi-yj)**2, 0.5)

print(keiroSum/len(entHai))

Solution (Python):
import math
import itertools

n = input()
n = int(n)
nlist = []
for i in range(0,n):
    nlist.append(input().split())


njunretu = []
for i in range(0,n):
    njunretu.append(i)


jlist = list(itertools.permutations(njunretu,n))

result = 0
for i in range(0,len(jlist)):
    for j in range(0,n-1):
        f = jlist[i][j]
        l = jlist[i][j+1]
        result += math.sqrt(((int(nlist[f][0]) - int(nlist[l][0]))**2) + ((int(nlist[f][1]) - int(nlist[l][1]))**2))

print(result / len(jlist))

Solution (Python):
n=int(input())
city=[]
for i in range(n):
  l = list(map(lambda x: int(x),input().split()))
  
  city.append(l)
  


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

x = n*(n-1)/2

def fac(n):
  if n==1:
    return 1
  else:
    return n*fac(n-1)



if x==1:
  print(dist)
else:
  print(dist*2/n)

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

Solution (Python):
import math
import itertools
n = int(input())
lis = [list(map(int, input().split())) for i in range(n)]
dislis = []
for i in range(n):
    dislis.append([])
    for j in range(n):
        dislis[i].append(math.sqrt((lis[i][0]-lis[j][0])**2 + (lis[i][1]-lis[j][1])**2))

lenlis = []
cnt = 0
for v in itertools.permutations(range(n+1)[1:], n):
    cnt += 1
    lenlis.append([])
    for i in range(len(v)):
        if i != len(v)-2:
            lenlis[cnt-1].append(dislis[v[i-1]-1][v[i]-1])
anslis = []
cntcnt = 0
for i in lenlis:
    anslis.append(sum(lenlis[cntcnt]))
    cntcnt += 1
print(sum(anslis)/len(anslis))

Solution (Python):
N = int(input())
a = [input() for i in range(N)]
an_list = []

for i in range(N):
    for j in reversed(range(N)):
        b, c = [int(x) for x in a[i].split()]
        d, f = [int(x) for x in a[j].split()]
        an_list.append((((b - d) ** 2 + (c - f) ** 2) ** 0.5))

print(sum(an_list)/N)

Solution (Python):
import math
import itertools

N = int(input())

pos = list()

for i in range(N):
    pos.append(tuple(map(int, input().split())))

dists = dict()
for i in range(N):
    for j in range(i+1, N):
        dists[(i, j)] = math.sqrt(
            (pos[i][0]-pos[j][0])**2+(pos[i][1]-pos[j][1])**2)

total = 0
num = 0

for i in itertools.permutations(range(N)):
    num += 1
    pre = None
    for j in i:
        if pre is None:
            pre = j
            continue
        if pre > j:
            f = j
            t = pre
        else:
            t = j
            f = pre
        total += dists[(f, t)]

print(total/num)

Solution (Python):

n = int(input())
x = [0]*n
y = [0]*n
kyori = 0
for i in range(n):
    x[i],y[i] = map(int,input().split())
import math
for j in range(n):
    for k in range(n):
        kyori += math.sqrt((x[j]-x[k])**2+(y[j]-y[k])**2)
print(kyori/n)

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


k=math.factorial(N) 
w=0
for i in range(0,N):
    w=w+(N-i-1)

t=(k*(N-1))/(w)

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

Solution (Python):


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

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

d = 0
for g in range(n):
    for h in range(g+1, n):
        d += dist(xy[g], xy[h])

       
print(2*d/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 = [0] * n
y = [0] * n

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


sum = 0
c = 0

for i in range(n):
    for j in range(i):
        sum += math.sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)
        c += 1

if n == 2:
    print(sum)
else:
    print(sum * 2 / n )

Solution (Python):
import itertools
import math

n = int(input())
towns = []
indexs = []
for i in range(n):
    tmp = input().split(' ')
    x = int(tmp[0])
    y = int(tmp[1])
    towns.append([x,y])
    indexs.append(i)

sum = 0
c = 0
for index in itertools.permutations(indexs):
    c = c + 1
    for k in range(len(index)-1):
        i = towns[index[k]]
        j = towns[index[k+1]]
        sum = sum + math.sqrt(pow((i[0] - j[0]),2) + pow((i[1] - j[1]), 2))
print(sum/c)

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

Solution (Python):
N=int(input())
XY=[list(map(int,input().split())) for i in range(N)]
value=0
for i in range(N):
    for m in range(i+1,N):
        x0,y0,x1,y1=XY[i][0],XY[i][1],XY[m][0],XY[m][1]
        value+=(((x0-x1)**2+(y0-y1)**2)**0.5)
print(value*2/N)

Solution (Python):
import itertools
import math

n=int(input())

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

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

bl={}
for i in range(n):
    bl[i]=0
l=[0]*n

ans_pl=[]




def qpl(index):
    global l
    if index==n:
        ans_pl.append(list(l))
        return
    for i in range(n):
        if bl[i]==0:
            l[index]=i
            bl[i]=1
            qpl(index+1)
            bl[i]=0
qpl(0)



    




summ=0
for i in range(len(ans_pl)):
    ll=ans_pl[i]
    pre_x,pre_y=d[ll[0]][0],d[ll[0]][1]
    for j in range(1,n):
        x,y=d[ll[j]][0],d[ll[j]][1]
        summ+=((x-pre_x)**2+(y-pre_y)**2)**0.5
        pre_x,pre_y=x,y

print(summ/len(ans_pl))

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

for i, nowX in enumerate(itertools.permutations(x,N)):
    for j in range(N-1):
        sumX[i] += dis[nowX[j]][nowX[j+1]]

result = sum(sumX)/(math.factorial(N))
print(result)

Solution (Python):
import math

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

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

ans = S / N
print(ans)

Solution (Python):
import math
n=int(input())
l=list()
for _ in range(n):
  a,b=map(int,input().split())
  l.append([a,b])
su=0
for i in range(n):
  for j in range(n):
    if i!=j:
      su+=math.sqrt((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)
      

print(su/n)

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

count = 0
for i in range(n-1):
    for j in range(n-i-1):
        
        count += ((list[i][0]-list[i+j+1][0])**2+(list[i][1]-list[i+j+1][1])**2)**0.5



nc2 = n*(n-1)//2

print(count*(n-1)/nc2)

Solution (Python):
import math
N = int(input())
x = []
y = []
for i in range(N):
    tx,ty=map(int,input().split())
    x.append(tx)
    y.append(ty)
sumv = 0
for i in range(N):
    for k in range(N-i-1):
        dis = math.sqrt((y[i]-y[N-k-1])**2+(x[i]-x[N-k-1])**2)
        sumv += dis
print(2/N*sumv)

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

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

Solution (Python):
import math

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

dis=[0]*(int(0.5*(N-1)*N))
k=0
for i in range(0,N-1):
    for j in range(i+1,N):
        dis[k]=math.sqrt((int(zahyo[i][0])-int(zahyo[j][0]))*(int(zahyo[i][0])-int(zahyo[j][0]))+(int(zahyo[i][1])-int(zahyo[j][1]))*(int(zahyo[i][1])-int(zahyo[j][1])))
        k+=1

add=0
ans=0
for i in range(0,int((N*(N-1))/2)):
    add+=dis[i]

ans=add*math.factorial(N-1)*2

print(ans/math.factorial(N))

Solution (Python):
from itertools import permutations

def c():
    n = int(input())
    points = []
    paths = permutations(range(n), n)

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

    dist = [[float('inf') for _ in range(n)] for _ in range(n)]

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

    sum_length = 0
    count = 0
    for path in paths:
        count += 1
        for i in range(1, len(path)):
            sum_length += dist[path[i-1]][path[i]]

    print(sum_length / count)

if __name__ == '__main__':
    c()

Solution (Python):
n = int(input())
x = []
y = []
for i in range(n):
    xx, yy = map(int, input().split())
    x.append(xx)
    y.append(yy)
import sys
sys.setrecursionlimit(2000)
import math

def dfs(v, r, visited):
    visited[v] = 1
    global ans
    for i in range(n):
        if visited[i] == 0:
            r += math.sqrt((x[i] - x[v]) ** 2 + (y[i] - y[v]) ** 2)
            dfs(i, r, visited)
            visited[i] = 0
            r -= math.sqrt((x[i] - x[v]) ** 2 + (y[i] - y[v]) ** 2)
        elif visited == [1] * n:
            ans += r
            return
ans = 0
for i in range(n):
    visited = [0 for _ in range(n)]  
    dfs(i, 0, visited)
div = 1
for i in range(1, n+1):
    div *= i
print(ans / div )

Solution (Python):

from itertools import combinations
from math import factorial
from scipy.misc import comb

N = int(input())

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

len_all = 0
for i, j in combinations(range(N), 2):
    len_all += ((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
one_ave = len_all / comb(N,2)

print(one_ave*(N-1))

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

Solution (Python):
import sys
import math
from statistics import mean
from functools import reduce, lru_cache
from itertools import permutations


@lru_cache()
def distance(p1, p2):
    return math.sqrt(sum([(a - b) ** 2 for a, b in zip(p1, p2)]))


def distances(arr):
    return [distance(arr[i], arr[i+1]) for i in range(len(arr)-1)]


def main(n: int, points: list):
    ret = []
    for x in permutations(points):
        ret.append(sum(distances(x)))

    print(mean(ret))


if __name__ == '__main__':
    n = int(input())
    a = [input() for i in range(n)]

    points = [s.split(' ') for s in a]

    main(
        n,
        [(int(p[0]), int(p[1])) for p in points]
    )

Solution (Python):
import sys
read = sys.stdin.buffer.read

def main():
    import numpy as np
    import math
    *ns, = map(int, read().split())
    n, s = ns[0], ns[1:]
    s = np.array(s).reshape([len(s)//2,2])
    ds = np.array([])
    for i in range(n):
        for j in range(i+1, n):
            xyi, xyj = s[i], s[j]
            ds = np.append(ds, ((xyi[0]-xyj[0])**2+(xyi[1]-xyj[1])**2)**0.5)
    p = math.factorial(n)
    p2 = p*(n-1)//len(ds)
    print(sum(ds*p2)/p)

if __name__ == "__main__":
    main()

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

x = []
y = []

sm = 0

for _ in range(n):

    tmp_x, tmp_y = map(int, input().split())
    
    if len(x)>0:
        for i in range(_):
            diff = ((tmp_x - x[i])**2 + (tmp_y - y[i])**2)**0.5
            sm += diff       
    x.append(tmp_x)
    y.append(tmp_y)

print (2*sm/n)

Solution (Python):
import math

N=int(input())
townX=[]
townY=[]
for j in range(N):
  x,y=map(int,input().split())
  townX.append(x)
  townY.append(y)



dist =0
if N==2:
  print(math.sqrt( (townX[0]-townX[1])**2 +(townY[0]-townY[1])**2 ))
else:
 for i in range(N-1):
   for j in range(i+1,N):
    dist += math.sqrt( (townX[i]-townX[j])**2 +(townY[i]-townY[j])**2 )
      
 dist=((N*(N-1)/2) -(N-2)*(N-1)/2)*dist    
 print(2*dist/(N*(N-1)))

Solution (Python):
import itertools
import math

N = int(input())

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

P = list(itertools.permutations(XY,r = N))

D = math.factorial(N)

area = 0

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

Solution (Python):
import itertools as it

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

s = ''
for i in range(n):
    s += str(i)
g = 0.0
for sb in it.permutations(s, n):
    tmpli = list(sb)
    for j in range(n-1):
        length_x = abs(xp[int(tmpli[j])]-xp[int(tmpli[j+1])])
        length_y = abs(yp[int(tmpli[j])]-yp[int(tmpli[j+1])])
        length_t = (length_x*length_x + length_y*length_y)**0.5
        g += length_t
print(g/fibn)

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

x_dis_list = []
y_dis_list = []
for i in range(n - 1):
    for j in range(i + 1, n):
        x_dis = (x[i] - x[j]) ** 2
        y_dis = (y[i] - y[j]) ** 2
        x_dis_list.append(x_dis)
        y_dis_list.append(y_dis)

tmp = 0
tmp_only = 0
if n == 2:
    tmp_only = math.sqrt(x_dis_list[0] + y_dis_list[0])
else:
    for i in range(len(x_dis_list)):
        tmp += math.sqrt(x_dis_list[i] + y_dis_list[i])

if n == 2:
    print(tmp_only)
else:
    print((2* tmp / n))

Solution (Python):
import sys
import math
import copy
import itertools
from functools import lru_cache


def pythagorean(x1, x2, y1, y2):
    z = (x1 - x2) ** 2 + (y1 - y2) ** 2
    if z > 0:
        return math.sqrt(z)
    else:
        return 0
















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

summ = 0
for v in itertools.permutations(range(n)):
    noww = 0
    for nn in range(1, n):

        noww += pythagorean(x[v[nn -1]], x[v[nn]], y[v[nn -1]], y[v[nn]])
    summ += noww

print(summ / math.factorial(n))

Solution (Python):
import math
import itertools


N = int(input())
xy = []
for i in range(N):
    xy.append(list(map(int, input().split())))
    
length = 0
for positions in itertools.permutations(xy, N):
    ahead = positions[0]
    for pos in positions[1:]:
        length += ((ahead[0] - pos[0]) ** 2 + (ahead[1] - pos[1]) ** 2) ** 0.5
        ahead = pos
print(length / math.factorial(N))