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 math

n = int(input())
town = [[0, 0]] * n
ans = 0
keiro = 0
keiro_count = 0

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



for i in range(n):
  for j in range(i+1, n):
    town1 = town[i]
    town2 = town[j]
    x = (town2[0] - town1[0]) ** 2
    y = (town2[1] - town1[1]) ** 2
    d = math.sqrt( x + y )
    
    keiro += (d * 2) * (n - 1)
    keiro_count += 2





ans = keiro / keiro_count
print(round(ans, 10))

Solution (Python):
import itertools

n=int(input())
xlist=[]
ylist=[]
z=[]
kyori=0
for i in range(n):
  a=[]
  a=list(map(int,input().split()))
  xlist.append(a[0])
  ylist.append(a[1])
  z.append(i)
for v in itertools.permutations(z):
  for i in range(1,n):
    kyori += ((xlist[v[i-1]]-xlist[v[i]])**2+(ylist[v[i-1]]-ylist[v[i]])**2)**0.5
print(kyori/len(list(itertools.permutations(z))))

Solution (Python):
import sys
sys.setrecursionlimit(int(1e6))

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

import itertools
seq = list(itertools.permutations(range(N)))
ds = [0] * N
route_d = [0] * len(seq)
dists = {}
k = 0
for route in seq:
    d = 0
    i = route[0]
    for j in route[1:]:
        vec = (i, j) if (i < j) else (j, i)
        if not (vec in dists):
            import math
            dx = xy[j][0] - xy[i][0]
            dy = xy[j][1] - xy[i][1]
            dists[vec] = math.sqrt(dx**2 + dy**2)
        d += dists[vec]
        i = j
    route_d[k] = d
    k += 1

ans = sum(route_d) / len(route_d)

print(ans)

Solution (Python):
import itertools
import math

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

target = list(itertools.permutations(point))
distance = 0

for i in range(len(target)):
	
	for j in range(len(target[i])-1):
		cul = (target[i][j][0] - target[i][j+1][0])**2 + (target[i][j][1] - target[i][j+1][1])**2
		distance += math.sqrt(cul)
print(distance/len(target))

Solution (Python):
import math

l = []
n = int(input())
for i in range(n):
  x1, x2 = map(int,input().split())
  l.append([x1, x2])

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

f = math.factorial(n-1)
f_ = math.factorial(n)
sum = 2 * f * sum(r)
print(sum/f_)

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

N = int(input())
towns = [tuple([int(i) for i in input().split()]) for _ in range(N)]

total = 0

for root in permutations(towns):
    ri = iter(root)
    pre = next(ri)
    for t in ri:
        total += sqrt(sum((t[i] - pre[i])**2 for i in (0, 1)))
        pre = t

print(total/factorial(N))

Solution (Python):
import itertools
import math
n = int(input())
x1 = []
y1 = []
for i in range(n):
    x, y = map(int, input().split())
    x1.append(x)
    y1.append(y)
l = [i for i in range(n)]
l = list(itertools.permutations(l))
ans = []
for i in l:
    c = 0
    for x in range(1, len(i)):
        x2 = i[x-1]
        x3 = i[x]
        c += math.sqrt((x1[x2] - x1[x3])**2 + (y1[x2] - y1[x3]) ** 2) 
    ans.append(c)
print(sum(ans)*2/(len(l)*2))

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

Solution (Python):
import math
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
ans = 0
for i in range(N):
    for j in range(N):
        if i != j:
            a = math.pow(xy[j][0] - xy[i][0],2) + math.pow(xy[j][1] - xy[i][1],2)
            ans += math.sqrt(a)

print(ans/N)

Solution (Python):
import math

n = input()
n = int(n)

points = []

for i in range(int(n)):
  p = input().split(" ")
  points.append((int(p[0]),int(p[1])))
  
sum = 0
for i in range(n):
  for j in range(n):
    dx = points[i][0] - points[j][0]
    dy = points[i][1] - points[j][1]
    sum += math.sqrt(dx*dx+dy*dy)
   
print(sum/( n ))

Solution (Python):
import math

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

ans = 0
cities = [x for x in range(N)]
for i in range(N):
	tmp = 0
	cities.remove(i)
	for j in cities:
		tmp += math.sqrt((x[i][0]-x[j][0])**2+(x[i][1]-x[j][1])**2) * math.factorial(N-1) * 2
	ans += tmp
	
print(ans/math.factorial(N))

Solution (Python):
import math
n = int(input())
coo = []
sum = 0
con = 0
for i in range(n):
    coo.append(tuple(map(int, input().split())))

for i in range(n-1):
    for j in range(i+1, n):
        sum += math.sqrt((coo[i][0]-coo[j][0])**2+(coo[i][1]-coo[j][1])**2)
        con += 1
fact = math.factorial(n)
num = fact*(n-1)/con
print(sum*num/fact)

Solution (Python):
import math

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

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

print(c/n*2)

Solution (Python):
import math
N = int(input())
data =[]
point = 0
for i in range(N):
    data.append([int(j) for j in input().split()])

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

print(point*2/N)

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

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

Solution (Python):
import numpy as np
n = int(input())
lst = []
count = 0

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

for i in range(n):
    for j in range(i+1,n):
        count += np.linalg.norm(lst[i]-lst[j])

print(count*2/n)

Solution (Python):
import itertools
import math
n = int(input())
x = []
y = []
for i in range(n):
  sam1, sam2= input().split()
  x.append(int(sam1))
  y.append(int(sam2))
    
a = list(itertools.permutations(range(n)))
kyori = 0
for i in a:
  for j in range(n-1):
    p = int(i[j])
    q = int(i[j+1])
    dx = x[p] - x[q]
    dy = y[p] - y[q]
    tmp = math.sqrt(dx * dx + dy * dy)
    kyori = kyori + tmp
print(kyori / len(a))

Solution (Python):

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

tmp = 0
for i in range(N):
    for j in range(N):
        if i == j:
            pass
        else:
            tmp += (((A[i][0]-A[j][0])**2)+((A[i][1]-A[j][1])**2))**0.5
tmp = tmp* math.factorial(N-1)

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

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

Solution (Python):
import math

n=int(input())

pos=[]
for _ in range(n):
    x,y=map(int,input().split())
    pos.append((x,y))
    
sum_diff=0
for i in range(n-1):
    for j in range(i+1,n):
        sum_diff+=math.sqrt((pos[i][0]-pos[j][0])**2+(pos[i][1]-pos[j][1])**2)*2*(n-2+1)*math.factorial(n-2)
    
print(sum_diff / math.factorial(n))

Solution (Python):
def cal(a,b):
    d=((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5
    return d
import math
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
ans=0
nk=math.factorial(n)
for i in range(n):
    for j in range(n):
        ans+=cal(l[i],l[j])
print((n-1)*ans/(n*(n-1)))

Solution (Python):
import itertools,math

N = int(input())

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

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

total_sum = 0
for j in jyunretsu:
    previous_town_number = None
    sum = 0
    for count, town_number in enumerate(j):
        if count == 0:
            previous_town_number = town_number
            continue

        sum += math.sqrt((town_list[town_number][0]-town_list[previous_town_number][0])**2 + (town_list[town_number][1]-town_list[previous_town_number][1])**2)
        previous_town_number = town_number

    total_sum += sum

print(total_sum/len(jyunretsu))

Solution (Python):
from sys import stdin

from math import sqrt
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return [x for x in mi()]
def si(): return stdin.readline()
def dis(x, y, p, q):
    return sqrt((x-p)**2+(y-q)**2)
a=[]
s=0
n=ii()
fn=1
for i in range(1, n+1):
    fn*=i
fn//=2
for _ in range(n):
    x, y=mi()
    a.append([x, y])
for i in range(n-1):
    for j in range(i+1, n):
        s+=dis(a[i][0], a[i][1], a[j][0], a[j][1])
        
print(2*s/n)

Solution (Python):
import numpy as np
import math
import itertools
values = []
n = int(input())
towns = [list(map(int,input().split())) for _ in range(n)]
num_root = math.factorial(n)
for root in itertools.permutations(towns):
  for i in range(n - 1):
    level = (root[i][0] - root[i + 1][0])**2 + (root[i][1] - root[i + 1][1])**2
    values.append(math.sqrt(level))
print(sum(values)/num_root)

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

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

Solution (Python):
import os
import math

n = int(input())
x = []
y = []
ans = 0
for i in range(n):
    a,b = (int(x) for x in input().split())
    x.append(a)
    y.append(b)

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

for j in range(n):
    for k in range(j+1,n):
        ans += 2*d(x[j],y[j],x[k],y[k])
print(ans/n)

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

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

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

def dis(s):
  ans = 0
  for i in range(len(s)-1):
    ans += np.sqrt((p[s[i]][0] - p[s[i+1]][0])**2 + (p[s[i]][1] - p[s[i+1]][1])**2)
  return ans

ans = sum([dis(x) for x in s])/math.factorial(N)
print(ans)

Solution (Python):
import math
import itertools

n = int(input())
l = []
ll = []
for i in range(n):
    l.append(list(map(int, input().split())))
for v in itertools.permutations(l, n):
    ll.append(list(v))

ans = 0
for j in ll:
    for k in range(n-1):
        a = j[k]
        b = j[k+1]
        aa = pow((b[0] - a[0]),2)
        bb = pow((b[1] - a[1]),2)
        ans+=pow(aa+bb, 1/2)
print(ans/len(ll))

Solution (Python):
import math
from itertools import permutations
N = int(input())
A = [tuple(map(int, input().split())) for _ in range(N)]
P = list(permutations(A))
ans = 0
count = 0
for p in P:  
  count += 1
  for i in range(1,len(p)):
    ans += math.sqrt((p[i-1][0]-p[i][0])**2 + (p[i-1][1]-p[i][1])**2)        
print(ans/count)

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


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


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

ans = d / xxx(N)
print(ans)

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

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

print(total/N*2)

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

import numpy as np

N = int(readline())
XY = np.array(read().split(),np.int64)

X = XY[::2]; Y = XY[1::2]

dx = X[:,None] - X[None,:]
dy = Y[:,None] - Y[None,:]

dist_mat = (dx * dx + dy * dy) ** .5

answer = dist_mat.sum() / N
print(answer)

Solution (Python):
import itertools

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

Permutations = (list(itertools.permutations(City)))

def route(l):
    Ans=[]
    for i in range(len(l)-1):
        L = ((l[i+1][0]-l[i][0])**2+(l[i+1][1]-l[i][1])**2)**.5
        Ans.append(L)
    return sum(Ans)

Length_list=[]

for i in Permutations:
    Length_list.append(route(i))



print(sum(Length_list)/len(Length_list))

Solution (Python):
import math
from itertools import permutations
n = int(input())
x = []
for _ in range(n):
    x.append(list(map(int , input().split())))
p = permutations(x)
ans = 0
for i in p:
    dist = 0
    for k in range(1 , n):
        dist += math.sqrt((i[k][0] - i[k-1][0]) ** 2 + (i[k][1] - i[k-1][1]) ** 2)

    ans += dist
print(ans / len(list(permutations(x))))

Solution (Python):
import numpy as np
import math
N = int(input())
data = {}
total = 1
for i in range(N):
  a_, b_ = map(int, input().split(" "))
  data[i] = np.array([a_,b_])
  total *= (i+1)

distance = 0.
for i in range(N):
  if i == 0:
    continue
  for j in range(i):
    distance += np.linalg.norm(data[i]-data[j])

param = 2 * (math.factorial(N) - math.factorial(N-1))/(N-1)
print(distance * param / total)

Solution (Python):
import math
from itertools import permutations, combinations,combinations_with_replacement,product
def length(x,y,p,q):
    ans= math.sqrt((x-p)**2+(y-q)**2)
    return ans
N=int(input())
S= [list(map(int, input().split())) for i in range(N)]
S_list=list(permutations(S))
leng_sum=0
for i in S_list:
    for j in range(N-1):
        x1=i[j][0]
        y1=i[j][1]
        x2=i[j+1][0]
        y2=i[j+1][1]
        leng_sum=leng_sum+length(x1,y1,x2,y2)
print(leng_sum/math.factorial(N))

Solution (Python):

import sys
def input():
    return sys.stdin.readline().rstrip()

import math

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

    s = 0
    for i in range(N-1):
        for j in range(i+1,N):
            s += math.hypot(Ps[i][0]-Ps[j][0], Ps[i][1]-Ps[j][1])

    print(s*2/N)
    


if __name__ == '__main__':
    main()

Solution (Python):
import math
import itertools
n = int(input())
nn = math.factorial(n)
X = []
Y = []
for _ in range(n):
  x, y = map(int, input().split())
  X.append(x)
  Y.append(y)
xx = list(itertools.permutations(X, n))
yy = list(itertools.permutations(Y, n))
c = 0
for k in range(nn):
  s = 0
  for i in range(n-1):
    s += math.sqrt((xx[k][i] - xx[k][i+1])**2 + (yy[k][i] - yy[k][i+1])**2)
  c += s
print(c/nn)

Solution (Python):
import itertools
import numpy as np
N = int(input())
xy = np.array([list(map(int, input().split())) for i in range(N)])
p = itertools.permutations(range(N))
print(np.mean([np.linalg.norm(xy[list(p_i)[:-1]]-xy[list(p_i)[1:]], axis=1).sum() for p_i in p]))

Solution (Python):
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
goukei=0
for i in range(n):
  for k in range(i+1,n):
    goukei+=((l[i][0]-l[k][0])**2+(l[i][1]-l[k][1])**2)**0.5
goukei*=2
print(goukei/n)

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

def calc_distance(x1,y1,x2,y2):
  distance_2 = (x1 - x2)**2 + (y1 - y2)**2
  distance = distance_2**0.5
  return distance

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

distance_list = []
distance_sum = 0
for i in range(N):
  
  for j in range(N):
    distance_sum += calc_distance(x_list[i],y_list[i],x_list[j],y_list[j])
    

ans = distance_sum / N 
print(ans)

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

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

def dist(a, b):
    return ((d[a][0]- d[b][0])**2 + (d[a][1]- d[b][1])**2 )**(1/2)
ls = list(range(n))
total = 0
for perm in permutations(ls):
    for i in range(n-1):
        total += dist(perm[i], perm[i+1])

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

Solution (Python):
import itertools
import math
N = int(input())
P = [list(map(int,input().split())) for i in range(N)]
lisN =  [i for i in range(N)]
length = 0
count = 0
for v in itertools.permutations(lisN, N):
    length_here = 0
    for k in range(N-1):
      Pam = P[v[k]]
      Ppm = P[v[k+1]]
      length_here += math.sqrt((Ppm[0] - Pam[0])**2 + (Ppm[1] - Pam[1])**2)

    length += length_here
    count += 1
print(length/count)

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

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

def kaijou(x):
  if x==1:
    return x
  return x*kaijou(x-1)

N=kaijou(n)
NN=kaijou(n-1)

for i in range(n):
  for j in range(n):
    if i!=j :
      D.append(math.sqrt((d[i][0]-d[j][0])**2+ (d[i][1]-d[j][1])**2))
print(sum(D)*(NN)/N)

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

N = int(input())

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


def calc_dist(bef, aft):
    dist = np.sqrt((bef[0] - aft[0])**2 + (bef[1] - aft[1])**2)
    return dist

total_dist = 0
for one_root in itertools.permutations(area_list, N):
    for i in range(N-1):
        tmp_dist = calc_dist(one_root[i], one_root[i+1])
        total_dist += tmp_dist

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

Solution (Python):

import sys
import itertools
input = sys.stdin.readline


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

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

    towns_id = list(range(n))
    all_lengh = []
    for v in itertools.permutations(towns_id):
        l = 0
        for i in range(n-1):
            l += matrix[v[i]][v[i+1]]
        all_lengh.append(l)

    result = sum(all_lengh) / len(all_lengh)
    print(result)


if __name__ == '__main__':
    main()

Solution (Python):
import itertools

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

def calc(i, j):
    return ((towns[i][0] - towns[j][0])**2 + (towns[i][1] - towns[j][1])**2)**0.5

l = list(range(n))
p = list(itertools.permutations(l, n))

total = 0
for p_ in p:
    for i in range(n-1):
        total += calc(p_[i], p_[i+1])

res = total / len(p)

print(res)

Solution (Python):
import numpy as np
import math
n = int(input())
distlist = []
for i in range(n):
    distlist.append(np.array(list(map(int,input().split()))))

distsum = 0
for i in range(n):
    for j in range(i,n):
        distsum += np.linalg.norm(distlist[i]-distlist[j])
        
n_kaizyo = math.factorial(n)
n1_kaizyo = math.factorial(n-1)

ans = (distsum*2*n1_kaizyo)/n_kaizyo

print(ans)

Solution (Python):
a = input()

a = int(a)

city_list = []

total_dist = 0

from itertools import permutations
import math

for i in range (a):
    x, y = input().split()
    x = int(x)
    y = int(y)
    city_list.append([x, y])

perms = (permutations(city_list))

divisor = 0

for cities in list(perms):
    divisor += 1
    for j in range(1, len(cities),):
        total_dist = total_dist + math.sqrt((cities[j][0] - cities[j-1][0])**2 + (cities[j][1] - cities[j-1][1])**2)


print(total_dist/divisor)

Solution (Python):
import math
from math import factorial

n = int(input())
X, Y = [],[]
for i in range(n):
  x, y = map(int, input().split())
  X.append(x)
  Y.append(y)
D = [[0] * n for _ in range(n)]
def ncr(n,r):
  return factorial(n) / factorial(r) / factorial(n - r)

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

for i in range(n):
  for j in range(i+1,n):
    D[i][j] = getD(X[i],Y[i],X[j],Y[j])
sum = 0
mt = factorial(n-1) * 2
for i in range(n):
  for j in range(i+1,n):
    sum += D[i][j] * mt
ans = sum / factorial(n)
print(ans)

Solution (Python):
import itertools
import math

def main():
    N = int(input())
    X = []
    Y = []
    ans = 0

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

    for i in itertools.permutations(range(N)):
        for j in range(len(i)-1):

            ans += math.sqrt((X[i[j+1]]-X[i[j]])**2 + (Y[i[j+1]]-Y[i[j]])**2)

    print(ans/math.factorial(N))

if __name__ == '__main__':
    main()

Solution (Python):
from math import factorial as f
from math import sqrt as sq

n = int(input())
l = []
s = 0
for i in range(n):
	x, y = map(int, input().split())
	l.append([x, y])
p = 0
for i in range(n):
	for j in range(n):
		if i != j:
			s += (sq((l[i][0] - l[j][0])**2 + (l[i][1] - l[j][1])**2) * (n - 1))
		p += 1
print(s / (n * (n - 1)))

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

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
a =0 
for i in range(N-1):
  a+=combinations_count(N-2,i)*math.factorial(i)*math.factorial(N-2-i)
a *= 2
ans = 0
for i in range(N):
  for j in range(N):
    if i < j:
      x2 = (XY[i][0] - XY[j][0])**2
      y2 = (XY[i][1] - XY[j][1])**2
      ans +=  math.sqrt(x2+y2)  * a
print(ans/math.factorial(N))

Solution (Python):


import itertools
import sys


def dist(A, B):
    return((A[0] - B[0]) ** 2 + (A[1] - B[1]) ** 2) ** 0.5


n = int(input())

position = []
for _ in range(n):
    position.append(list(map(int, sys.stdin.readline().strip().split())))

distance = []
count = 0
for i in itertools.permutations(range(n)):
    for j in range(n - 1):
        distance.append(dist(position[i[j]], position[i[j + 1]]))
    count += 1



print(sum(distance) / count)

Solution (Python):
N = int(input()) 
x = []
y = []

a = 1

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


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

count = 0
d = 0
for i in range(N):
    for j in range(N):
        if i == j:
            break

        d += distance(x[i], y[i], x[j], y[j])

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

Solution (Python):
import numpy as np
import math
n = int(input())
xy = [[int(i) for i in input().split()] for i in range(n)]
sum = 0
for i in range(n):
    for j in range(n):
        leng = ((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)**0.5
        sum += math.factorial(n-1)*leng

print(sum/math.factorial(n))

Solution (Python):
import itertools
import math

n = int(input())
x_y = list(input().split() for i in range(n))
all = list(itertools.permutations(x_y))
l = 0
for i in all:
    for j in range(n-1):
        tmp = math.sqrt(math.pow(int(i[j][0])-int(i[j+1][0]), 2) + math.pow(int(i[j][1])-int(i[j+1][1]), 2))
        l += tmp

print(l/len(all))

Solution (Python):
import math

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

def dist(x,y):
  return math.sqrt((x[0]-y[0])**2 + (x[1]-y[1])**2)

ans = 0
for i in range(N):
  for j in range(N):
    if j==i:
      continue
    ans += dist(S[i],S[j])
ans = ans / N

print(ans)

Solution (Python):
import numpy as np
import math
N=int(input())
M=N*(N-1)//2
X=np.array([list(map(int,input().split())) for _ in range(N)])
L=0
for i in range(N-1):
    for j in range(i+1,N):
        l=((X[i][0]-X[j][0])**2+(X[i][1]-X[j][1])**2)
        L+=np.sqrt(l)
print(L*2/N)

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

Solution (Python):

import sys
from math import sqrt

def _s(): return sys.stdin.readline().strip()

def _i(): return int(sys.stdin.readline().strip())
def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]

def g(a):
    if len(a)==1:
        yield a
    else:
        for i in range(len(a)):
            ai = a[i]
            for aa in g(a[:i]+a[i+1:]):
                yield [ ai ] + aa
        

n = _i()
xy = [ _ia() for _ in range(n) ]

s = 0
c = 0
for a in g(xy):
    dist = 0
    prev = None
    for nxt in a:
        if prev:
            dist += sqrt( (prev[0]-nxt[0])**2 + (prev[1]-nxt[1])**2 )
        prev = nxt
    s += dist
    c +=1

print(s/c)

Solution (Python):
import math,itertools

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

dis = [[0.0 for i in range(N)] for j in range(N)]
for i in range(N):
    for j in range(i+1,N):
        dis[i][j] = math.sqrt( (x[i]-x[j])**2 + (y[i]-y[j])**2 )
        dis[j][i] = dis[i][j]

sum = 0
for n in itertools.permutations(range(N)):
    for i in range(N-1):
        sum += dis[n[i]][n[i+1]]

print(sum/math.factorial(N))

Solution (Python):
import math


class Solution:
    def solve(self, n: int, points: list) -> int:

        s = 0.

        for i in range(n):
            p = points[i]
            for j in range(i+1, n):
                q = points[j]
                s += math.sqrt((p[0]-q[0])**2 + (p[1] - q[1])**2)

        return 2 * s / n


if __name__ == '__main__':

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

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

    
    solution = Solution()
    print(solution.solve(n, points))

Solution (Python):
import itertools
import math

N = int(input())
Cities = []
for _ in range(N):
  x, y = map(int,input().split())
  Cities.append([x, y])
seq = [i for i in range(N)]  
patterns = list(itertools.permutations(seq))
records = [0,0]

for item in patterns:
  for i in range(N-1):
    A = (Cities[item[i+1]][0] - Cities[item[i]][0])**2
    B = (Cities[item[i+1]][1] - Cities[item[i]][1])**2
    length = math.sqrt(A+B)
    records[0] += length
  records[1] += 1 
Answer = records[0]/records[1] 

print(Answer)

Solution (Python):
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): 
    return int(input())
def inpm(): 
    return map(int,input().split())
def inpl(): 
    return list(map(int, input().split()))
def inpls(): 
    return list(input().split())
def inplm(n): 
    return list(int(input()) for _ in range(n))
def inpll(n): 
    return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
    if k == 0:x.sort(key=lambda y:y[1,n])
    else:x.sort(reversed=True, key=lambda y:y[1,n])
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a=inp()
        a-=1
        g[i].append(a)
        g[a].append(i)
    return n,g
def graphm():
    n,m=inpm()
    g=[[] for _ in range(n)]
    for _ in range(m):
        a,b,w=inpm()
        a-=1
        b-=1
        g[a].append((b,w))
        g[b].append((a,w))
    return n,m,g

def dijkstra(s,n,g): 
    s -= 1
    que = []
    d = [10**15 for _ in range(n)]
    d[s] = 0
    heappush( que,(0,s) )
    while len(que)>0:
        p =  heappop(que)
        v = p[1]
        if d[v] < p[0]:
            continue
        for i in range(len(g[v])):
            edge = g[v][i]
            if d[edge[0]] > d[v] + edge[1]:
                d[edge[0]] = d[v] + edge[1]
                heappush( que,(d[edge[0]] , edge[0]) )
    return d

def main():
    n=inp()
    x=[]
    y=[]
    for _ in range(n):
        a,b=inpm()
        x.append(a)
        y.append(b)
    cnt=0
    for i in range(n-1):
        for j in range(i+1,n):
            cnt+=( (x[i]-x[j])**2 + (y[i]-y[j])**2 )**(1/2)
    com=1
    for i in range(1,n+1):
        com*=i
    s=(n*(n-1))//2
    print( (cnt*(n-1))/(s) )


if __name__ == "__main__":
    main()

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

Solution (Python):
import math
import itertools
a=[]
ans=0
n=int(input())
m=1
for i in range(1,n+1):
  m*=i
for i in range(n):
    x,y=map(int,input().split())
    a.append([x,y])
for t in itertools.permutations(range(n),n):
  for i in range(n-1):
    ans+=math.sqrt((a[t[i]][0]-a[t[i+1]][0])**2+(a[t[i]][1]-a[t[i+1]][1])**2)
ans=ans/m
print(ans)

Solution (Python):
b=int(input())
a=[]
aa=[]
n=0
i=0
while i<b:
    for x in input().split(" "):
        aa.append(float(x))
    a.append(aa)
    aa=[]
    i+=1
i=0
while i<b:
    j=0
    while j<b:
        if j!=i:
            n+=((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)**0.5
        j+=1
    i+=1
print(n/b)