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

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


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


ans = cnt = 0
for perm in permutations(range(n)):
    cand = 0
    for i in range(n - 1):
        cand += dist(perm[i], perm[i + 1])
    ans += cand
    cnt += 1

ans /= cnt
print(ans)

Solution (Python):
from itertools import permutations
from math import sqrt, fsum
N = int(input())
towns = [tuple(map(int, input().split())) for _ in range(N)]

ds = []
n = 0
for rt in permutations(towns, N):
    for i in range(1, N):
        x1, y1 = rt[i-1]
        x2, y2 = rt[i]
        d = sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
        ds.append(d)
    n += 1
ans = fsum(ds) / n
print(ans)

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

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

dist = 0
for order in itertools.permutations(range(N), N):
    for i in range(1, len(order)):
        dist += np.sqrt((X[order[i]] - X[order[i - 1]])**2 +
                        (Y[order[i]] - Y[order[i - 1]])**2)
ans = dist / math.factorial(N)
print(ans)

Solution (Python):
import itertools
import math
n = int(input())
xy = [[int(j) for j in input().split()] for i in range(n)]
x = [i[0] for i in xy]
y = [i[1] for i in xy]
sum = 0
ps = list(itertools.permutations(range(n), n))
for i in ps:
    for j in range(len(i)-1):
        tmp = math.sqrt((x[i[j]] - x[i[j+1]]) ** 2 + (y[i[j]] - y[i[j+1]]) ** 2)
        sum += tmp
print(sum / len(ps))

Solution (Python):
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))



from itertools import permutations
from math import factorial

def main():
	n=II()
	li=[TI() for _ in range(n)]
	ans=0
	for p in permutations(range(n),n):
		tmp=0
		px=py=1001
		for i in p:
			x,y=li[i][0],li[i][1]
			if px==1001:
				px,py=x,y
			else:
				tmp+=((px-x)**2+(py-y)**2)**0.5
				px,py=x,y
		ans+=tmp

	ans/=factorial(n)
	print(ans)

if __name__ == "__main__":
	main()

Solution (Python):
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))



from itertools import permutations
from math import factorial

def main():
	n=II()
	li=[TI() for _ in range(n)]
	ans=0
	for p in permutations(range(n),n):
		tmp=0
		px=py=1001
		for i in p:
			x,y=li[i][0],li[i][1]
			if px==1001:
				px,py=x,y
			else:
				tmp+=((px-x)**2+(py-y)**2)**0.5
				px,py=x,y
		ans+=tmp

	ans/=factorial(n)
	print(ans)

if __name__ == "__main__":
	main()

Solution (Python):
import math

n = int(input())

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

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

print(distance_sum * (n-1) / (n * (n-1) // 2) )

Solution (Python):
import math
n=int(input())
xy=[input().split(" ") for i in range(n)]

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

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

N = int(input())

town = [list(map(int, input().split())) for _ in range(N)]
lis = [x for x in range(N)]
roots = list(itertools.permutations(lis))
sum_dis = 0

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

print(sum_dis / len(roots))

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

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

Solution (Python):
import fractions
import math
import itertools

def distance_measure(n,*args):
    distance_x = 0
    distance_y = 0
    distance_xy = 0
    distance = 0
    for i in range(n-1):
   
        distance_x = (args[0][i+1][0]-args[0][i][0])**2
        distance_y = (args[0][i+1][1]-args[0][i][1])**2
        distance_xy += math.sqrt(distance_x+distance_y)
    distance += distance_xy 
   
    return distance
    


if __name__ =="__main__":
    n = int(input())
    all_dist = 0
    
    g = [0]*n
    for i in range (n):
        x,y = map(int,input().split())
        g[i] = x,y
    
    
    for i in itertools.permutations(g,n):
        
        distance = distance_measure(n,i)
        all_dist += distance

    ave_dist = all_dist/math.factorial(n)
    print(ave_dist)

Solution (Python):
from itertools import combinations
n = int(input())
p = []
for _ in range(n):
    p.append(list(map(int, input().split())))
dis = 0
for i, j in combinations([i for i in range(n)], 2):
    dis += ((p[i][0]-p[j][0])**2 + (p[i][1]-p[j][1])**2)**(1/2)
print(dis/n*2)

Solution (Python):
from itertools import permutations


def dist(points,a,b):
    x = ((points[a][0]-points[b][0])**2+(points[a][1]-points[b][1])**2)**0.5
    return x

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

    points = [ [int(j) for j in input().split()]  for i in range(N)]
    score =0
    count =0
    for route in permutations(range(N),N):
        
        for a,b in zip(route,route[1:]):
            score += dist(points,a,b)

        count +=1

    print(score/count)




if __name__ == "__main__":
    resolve()

Solution (Python):
import sys
import math

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

total = 0
factorial = 1
for i in range(n):
    factorial *= n-i

fa = factorial / ((n))
for i in range(n):
    for j in range(i+1,n):
        xi = corrdinate[i][0]
        xj = corrdinate[j][0]
        yi = corrdinate[i][1]
        yj = corrdinate[j][1]
        total += math.sqrt( (xi - xj)**2 + (yi - yj)**2 ) * 2 * fa

print(total / (factorial ) )

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

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools
from math import sqrt

n = int(readline())
xy = [list(map(int, readline().split())) for i in range(n)]
memo = [i for i in range(n)]
z = list(itertools.permutations(memo))
ans = 0
for i in range(len(z)):
    for j in range(n - 1):
        ans += sqrt((xy[z[i][j]][0] - xy[z[i][j + 1]][0]) ** 2 + (xy[z[i][j]][1] - xy[z[i][j + 1]][1]) ** 2)
print(ans / len(z))

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

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

L=0

for j in range(N):
  for k in range(N):
    if j >= k:
      continue
    L += math.sqrt((xi[j]-xi[k])**2 + (yi[j]-yi[k])**2)
    
print(2*L/N)

Solution (Python):
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect



import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial, log, log10, log2
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

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

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

import math
length = 0
for i in range(N-1):
    for j in range(i+1,N):
        length += math.sqrt((X[i]-X[j])**2+(Y[i]-Y[j])**2)

C = N*(N-1)/2

print((N-1)*length/C)

Solution (Python):
import sys
import math

def input():
    return sys.stdin.readline().rstrip('\n')

N = int(input())
X = []
Y = []

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

def distance(i,j):
    return math.sqrt((X[i]-X[j])*(X[i]-X[j]) + (Y[i]-Y[j])*(Y[i]-Y[j]))

distance_sum = 0

for i in range(N):
    for j in range(N):
        distance_sum += distance(i,j)

print(distance_sum/N)

Solution (Python):
import itertools
import math

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

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

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

print(ans / fact(N))

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


dist_list = []
for v in itertools.combinations(point,2):
    dist = math.sqrt((K[v[0]][0] - K[v[1]][0])**2 + (K[v[0]][1] - K[v[1]][1])**2)
    dist_list.append([list(v),dist])

sum = 0
for v in itertools.permutations(point,N):
    for i in range(N-1):
        p1,p2 = v[i],v[i+1]

        for item in dist_list:
            if [p1,p2] in item or [p2,p1] in item:
                sum += item[1]
                break
        

ans = sum / math.factorial(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())
ans_sum=0
for i in range(N):
    for j in range(N):
            ans_sum+=math.sqrt((x[j]-x[i])**2+(y[j]-y[i])**2)
print(ans_sum/N)

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

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

list=[]
for i in range(n):
  for j in range(n):
    k=distance(zahyou[i][0],zahyou[j][0],zahyou[i][1],zahyou[j][1])
    list.append(k)

s=sum(list)/n
print(s)

Solution (Python):
import math
n=int(input())
l=0

xi=[]
yi=[]

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

for j in range(n):
    for k in range(n):
        if j>=k:
            continue
        l+=math.sqrt((xi[j]-xi[k])**2+(yi[j]-yi[k])**2)

print(l*2/n)

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

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

    ans = []
    def dfs(d, perm):
        if d==N:
            dist = 0
            for i in range(N-1):
                dist += ((xy[perm[i+1]][0]-xy[perm[i]][0])**2+(xy[perm[i+1]][1]-xy[perm[i]][1])**2)**0.5
            ans.append(dist)
        else:
            for i in range(N):
                if i not in perm:
                    dfs(d+1, perm+[i])

    dfs(0, [])
    print(sum(ans)/math.factorial(N))

if __name__ == '__main__':
    resolve()

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

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

    ans = [0]
    p = 1
    for i in range(N):
        p *= i+1
    def dfs(d, perm):
        if d==N:
            dist = 0
            for i in range(N-1):
                dist += ((xy[perm[i+1]][0]-xy[perm[i]][0])**2+(xy[perm[i+1]][1]-xy[perm[i]][1])**2)**0.5
            ans[0] += dist
        else:
            for i in range(N):
                if i not in perm:
                    dfs(d+1, perm+[i])

    dfs(0, [])
    print(ans[0]/p)

if __name__ == '__main__':
    resolve()

Solution (Python):
import math
import numpy as np
from itertools import permutations
n = int(input())
XY = list(tuple(map(int, input().split())) for _ in range(n))

dist = 0
for per in permutations(range(n)):
    for origin, next in zip(per, per[1:]):
        x1, y1 = XY[origin][0], XY[origin][1]
        x2, y2 = XY[next][0], XY[next][1]

        dist += np.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
print(dist / math.factorial(n))

Solution (Python):
import itertools
import math
def getdis(a,b):
  return math.sqrt((b[0] - a[0])**2+(b[1]-a[1])**2)

N = int(input())

city = []
l = [i for i in range(N)]
for i in range(1,N+1):
  x,y = map(int,input().split())
  city.append([x,y])
  
l = list(itertools.permutations(l))
sum_dis = [0]*len(l)
for i in range(len(l)):
  for j in range(N-1):
    sum_dis[i]+=getdis(city[l[i][j]],city[l[i][j+1]])
print(sum(sum_dis)/len(l))

Solution (Python):
x = int(input())
a = [list(map(int,input().split())) for i in range(x)]
ans = 0
for i in range(x):
    for j in range(x):
        if i!=j:
            ans += ((abs(a[i][0]-a[j][0])**2+abs(a[i][1]-a[j][1])**2))**0.5
print(ans/x)

Solution (Python):
x = int(input())
a = [list(map(int,input().split(" "))) for i in range(x)]
ans = 0
for i in range(x):
    for j in range(x):
        if i!=j:
            ans += ((abs(a[i][0]-a[j][0])**2+abs(a[i][1]-a[j][1])**2))**0.5
print(ans/x)

Solution (Python):
N=int(input())
xy=[list(map(int,input().split())) for _ in range(N)]
ans=0
for x1,y1 in xy:
    for x2,y2 in xy:
        ans+=((x2-x1)**2+(y2-y1)**2)**0.5
print(ans/N)

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

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

Solution (Python):
import numpy as np
N = int(input())
R = np.array([list(map(int,input().split())) for i in range(N)])
print(sum(np.linalg.norm(i-j) for i in R for j in R)/N)

Solution (Python):
N=int(input())
XY=[list(map(int,input().split())) for i in range(N)]
sum=0
kaijyo=1
for i in  range(N):
  for j in range(N):
    if i!=j:
      sum+=((XY[i][0]-XY[j][0])**2+(XY[i][1]-XY[j][1])**2)**0.5
    else:
      continue
print(sum/N)

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

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

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


def cal(list, n):
    ret = 0
    for i in range(n-1):
        ret += math.sqrt(((list[i][0]-list[i+1][0])**2)+((list[i][1]-list[i+1][1])**2))
    return(ret)


ans = []
for l in list(itertools.permutations(xy)):
    ans.append(cal(l, N))
print(statistics.mean(ans))

Solution (Python):

import math
n = int(input())
coordinate = []
for _ in range(n):
    x,y = map(int,input().split())
    coordinate.append([x,y])
dist = 0
def culc_dist(x1,y1,x2,y2):
    return (math.sqrt((x1-x2)**2 + (y1-y2)**2))
    
for i in range(n):
    for j in range(n):
        if i != j:
            dist += culc_dist(coordinate[i][0],coordinate[i][1],coordinate[j][0],coordinate[j][1])
dist /= n

print(dist)

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

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


def get_dist(ax,ay, bx, by):
    return sqrt((ax-bx)**2 + (ay-by)**2)

dist_matrix = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        dist_matrix[i][j] = get_dist(xy[i][0], xy[i][1], xy[j][0], xy[j][1])

perm = permutations(list(range(N)), N)
n = 0
paths = []
for v in perm:
    n += 1
    one_path = []
    for k in range(len(v)-1):
        one_path.append([v[k], v[k+1]])
    paths.append(one_path)

d_sum = 0
for p in paths:
    for q in p:
        d_sum += dist_matrix[q[0]][q[1]]

print(d_sum/n)

Solution (Python):
import math
import itertools

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

x = 0
y = 1
d = 0

for p in itertools.permutations(range(n)):
    p = list(p)
    for i in range(n-1):
        d += ((xy[p[i]][x] - xy[p[i+1]][x])**2 + (xy[p[i]][y] - xy[p[i+1]][y])**2)**0.5
        

print(d/math.factorial(n))

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

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

def d(x1, y1, x2, y2):
    x = abs(x1-x2)
    y = abs(y1-y2)
    return (x*x + y*y) ** 0.5

N = i_i()
xy = [i_l() for x in range(N)]
p = itertools.permutations(xy, N)
arr = list(p)

acc = 0
for a in arr:
    tmp = 0
    for i in range(N-1):
        tmp += d(a[i][0], a[i][1], a[i+1][0], a[i+1][1])
    acc += tmp
    tmp = 0

print(acc/ len(arr))

Solution (Python):
import itertools
import math

N = int(input())
x = [0]*N
y = [0]*N
for i in range(N):
    x[i], y[i] = map(int, input().split())
    
a = list(itertools.permutations([i for i in range(1, N+1)]))

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

Solution (Python):
N=int(input())
xy=[list(map(int,input().split())) for _ in range(N)]
ans=0
for x1,y1 in xy:
    for x2,y2 in xy:
        ans+=((x2-x1)**2+(y2-y1)**2)**0.5
print(ans/N)

Solution (Python):
from itertools import permutations
import math

N = int(input())
A = [(0, 0) for x in range(N)]

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

pA = permutations(A)

route_count = 0
sum_route_length = 0
for route in pA:
    route_count += 1
    for i in range(1, len(route)):
        distance = math.sqrt(pow(route[i-1][0] - route[i][0], 2) + pow(route[i-1][1] - route[i][1], 2))
        sum_route_length += distance

average = sum_route_length / route_count

print(average)

Solution (Python):
import itertools

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

city_number = [i for i in range(n)]
permutations_city_number = itertools.permutations(city_number)

sum_distance = 0
cnt = 0

for city in permutations_city_number:
    memo = 0
    for x in city:
        if memo == 0:
            city1 = x
            memo = 1
        sum_distance += ((city_distance[city1][0] - city_distance[x][0]) ** 2 + (city_distance[city1][1] - city_distance[x][1]) ** 2) ** 0.5
    cnt += 1

print(sum_distance/cnt)

Solution (Python):
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
def dfs(v, cost, xy):
  if len(v)==0:
    return cost
  x1, y1 = xy
  res = 0
  for i, v_ in enumerate(v):
    x2, y2 = v_
    res += dfs(v[:i]+v[i+1:], cost+((x1-x2)**2 + (y1-y2)**2)**0.5, v_)
  return res

res = 0
p = 1
for i, xy_ in enumerate(xy):
  res += dfs(xy[:i]+xy[i+1:], 0, xy_)
  p *= (i+1)
print(res/p)

Solution (Python):
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
XY = np.array([lr() for _ in range(N)])
X = XY[:, 0]; Y = XY[:, 1]
diff_X = X[:, None] - X[None, :]
diff_Y = Y[:, None] - Y[None, :]
path = (diff_X ** 2 + diff_Y ** 2) ** .5
answer = path.sum() / N
print(answer)

Solution (Python):
import sys
import math

N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, sys.stdin.readline().split())
    X.append(x)
    Y.append(y)
    
sum = 0

for i in range(N - 1):
    for j in range(i, N):
        sum += math.sqrt((X[i] - X[j]) ** 2 + (Y[i] - Y[j]) ** 2)

ans = sum / (N / 2)

print(ans)

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

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

n=2/N
ans=total*n
print(ans)

Solution (Python):
import sys
import math

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
answer = 0

XY = [lr() for _ in range(N)]
for i in range(N):
    for j in range(i+1, N):
        x1, y1 = XY[i]
        x2, y2 = XY[j]
        length = ((x1-x2) ** 2 + (y1-y2) ** 2) ** .5
        answer += length

answer *= 2 / N
print(answer)

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

ans=0
for x1,y1 in xy:
    for x2,y2 in xy:
        ans+=((x2-x1)**2+(y2-y1)**2)**0.5 

print(ans/n)

Solution (Python):

N = int(input())
x = []
c=0
for i in range(N):
    x1=[int(i) for i in input().split()]
    x.append(x1)
for i in range(N):
    for m in range(N):
        if i!=m:
            c+=((x[i][0]-x[m][0])**2+(x[i][1]-x[m][1])**2)**0.5
print(c/N)

Solution (Python):
import math
N=int(input())
a=[]
A=0
for _ in range(N):
    x,y=map(int,input().split())
    a.append((x,y))
b=math.factorial(N)*2//N
for i in range(N):
    for j in range(i+1,N):
        route=math.sqrt((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)
        A+=b*route
c=math.factorial(N)
print(A/c)

Solution (Python):
x=int(input())
a= [ list(map(int,input().split(" "))) for i in range(x)]
ans=0
for i in range(x):
	for j in range(x):
		if i!=j:
			ans=ans+((abs(a[i][0]-a[j][0])**2+abs(a[i][1]-a[j][1])**2))**0.5
print(ans/x)

Solution (Python):
import numpy as np
n = int(input())
xy = []
def kaijou(n):
    if n > 1:
        return n*(kaijou(n-1))
    else:
        return 1
for i in range(n):
    tmp = list(map(int,input().split()))
    xy.append(tmp)
ans = 0
num = 0
for i in range(len(xy)):
    for j in range(i+1,len(xy)):
        ans += np.sqrt((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)
        
print(ans*kaijou(n-1)*2/kaijou(n))

Solution (Python):
from itertools import permutations as perm
import math

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

for root in list(perm(range(N))):
    for i in range(1, N):
        ans += math.sqrt((coo[root[i]][0]-coo[root[i-1]][0])**2+(coo[root[i]][1]-coo[root[i-1]][1])**2)

print(ans/math.factorial(N))

Solution (Python):
import math;n = int(input());l = [list(map(int,input().split())) for i in range(n)];dist = 0
for x1,y1 in l:
  for x2,y2 in l:dist += math.sqrt((x1-x2)**2 + (y1-y2)**2)
print(dist/n)

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


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

allen = 0
for i in zahyou:
    for j in zahyou:
        allen += distance(int(i[0]),int(j[0]),int(i[1]),int(j[1]))

ans = float(allen/n)
print(ans)

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

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

import math
sum=0  
for j in range(n):
  q=c[j][0];w=c[j][1]
  for k in range(j):
    sum+=math.sqrt((c[k][0]-q)**2+(c[k][1]-w)**2)
    
print(float(sum*2/n))

Solution (Python):
import math
n = int(input())
coo = [list(map(int,input().split())) for i in range(n)]
s = sum([math.sqrt(((coo[i][0]-coo[j][0])**2 + (coo[i][1]-coo[j][1])**2)*(math.factorial(n-1))**2) for i in range(n) for j in range(n) if i != j])
print(s/math.factorial(n))

Solution (Python):
import math
from itertools import permutations, combinations,combinations_with_replacement,product
n = int(input())
p = [[0,0] for i in range(n)]
a = [i for i in range(n)]
a = list(permutations(a))
ans = 0
kai = math.factorial(n)

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

for i in range(kai):
    for j in range(n-1):
        ans += ((p[a[i][j]][0]-p[a[i][j+1]][0])**2+(p[a[i][j]][1]-p[a[i][j+1]][1])**2)**0.5

print(ans/kai)

Solution (Python):
import math
def distance(x1,x2,y1,y2):
  d=math.sqrt((x1-x2)**2+(y1-y2)**2)
  return d
count=int(input())
zahyou=[]
for i in range(count):
  a=input().split(" ")
  zahyou.append(a)

lenth=0
for i in zahyou:
  for j in zahyou:
    lenth=lenth+distance(int(i[0]),int(j[0]),int(i[1]),int(j[1]))
print(lenth/count)

Solution (Python):


import itertools


def calc_dist(p1, p2):
    x_delta = p1[0] - p2[0]
    y_delta = p1[1] - p2[1]
    return (x_delta ** 2 + y_delta ** 2) ** (1/2)


if __name__ == "__main__":
    N = int(input())
    A = []
    for _ in range(N):
        x, y = map(int, input().split())
        A.append((x, y))

    dist_list = []
    for permutated in itertools.permutations(A):
        dist = 0
        for i in range(1, len(permutated)):
            dist += calc_dist(permutated[i], permutated[i-1])
        dist_list.append(dist)

    print(sum(dist_list) / len(dist_list))

Solution (Python):
from itertools import permutations

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

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

ans = []
for v in permutations(range(N), N):
    tmp = 0
    for i in range(N - 1):
        tmp += dist[v[i]][v[i + 1]]
    ans.append(tmp)

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

Solution (Python):
import itertools
import math
n = int(input())
x,y = [0]*n,[0]*n
for i in range(n):
  x[i],y[i] = map(int,input().split())
lis = [x for x in range(n)]
permutation_lis = itertools.permutations(lis)
ans = 0
div = math.factorial(n)
def eucleid_dist(a,b):
  return  math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)
for path in permutation_lis:
  dist = 0
  for i in range(n-1):
    a = (x[path[i+1]],y[path[i+1]])
    b = (x[path[i]],y[path[i]])
    dist += eucleid_dist(a,b)
  ans += dist/div
print(ans)

Solution (Python):
from math import fsum, sqrt
from itertools import permutations
N = int(input())
towns = [tuple(map(int, input().split())) for _ in range(N)]
distances = []
num = 0
for rt in permutations(range(N), N):
    num += 1
    for i in range(1, N):
        x1, y1 = towns[rt[i-1]]
        x2, y2 = towns[rt[i]]
        distance = sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
        distances.append(distance)
print(fsum(distances) / num)

Solution (Python):
from itertools import permutations

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

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

perm = permutations(range(N), N)
d_list = []
for p in perm:
    d = 0
    for i in range(N - 1):
        d += calc_distance(P[p[i]], P[p[i+1]])
    d_list.append(d)
print(sum(d_list) / len(d_list))

Solution (Python):
import math

def main():

    N = int(input())

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

    total = 0
    for i in range(N):
        x1, y1 = pts[i]
        for j in range(i + 1, N):
            x2, y2 = pts[j]

            dx = x2 - x1
            dy = y2 - y1
            distSq = dx * dx + dy * dy

            total += math.sqrt(distSq)

    print(total * 2 / N)


main()

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

decimal.getcontext().prec = 16

cache = {}


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


N = int(input())

P = [None] * N
for i in range(N):
  P[i] = tuple(map(int, input().split()))

total = 0
count = 0
for points in permutations(P, len(P)):
  it = iter(points)
  last = next(it)
  for p in it:
    total += distance(p, last)
    last = p
  count += 1

print(total / count)

Solution (Python):
import itertools

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


def gen(routes):
    for v in routes:
        for i,  move in enumerate(v):
            if i < n-1:
                d = ((v[i][0] - v[i + 1][0]) ** 2 +
                     (v[i][1] - v[i + 1][1]) ** 2) ** 0.5
                yield d


print(sum(gen(routes)) / len(routes))