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

Solution (Python):
import itertools
import math
L=0
M=0
N=int(input())
p=[list(map(int,input().split())) for i in range(N)]
for seq in itertools.permutations(range(N),N):
    tmp=0
    for i in range(N-1):
        x1,y1=p[seq[i]]
        x2,y2=p[seq[i+1]]
        tmp+=math.sqrt((x1-x2)**2+(y1-y2)**2)
    L+=tmp
    M+=1
print(L/M)

Solution (Python):
import itertools
import math

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

for i in range(N):
	x,y = map(int,input().split())
	X.append(x)
	Y.append(y)
	
def des(i, j):
	return math.sqrt( (X[i] - X[j]) ** 2.0 + (Y[i] - Y[j]) ** 2.0)
	
s = 0
for c in itertools.combinations(range(N), 2):
	s += des(c[0],c[1])
	
print(s*2 / N)

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

import itertools
import math

allx = list(itertools.permutations(x,2))
ally = list(itertools.permutations(y,2))


anslist = []

for (a,b) in zip(allx,ally):
    anslist.append(math.sqrt(pow(a[0] - a[1],2) + pow(b[0] - b[1],2)))

nn = n - 1
lastans = sum(anslist) * nn / len(anslist)

print(lastans)

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

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


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


def chker(xylist):
    now = xylist[0]
    remain = xylist[1:]
    pathsum = 0

    while remain:
        for item in remain:
            pathsum += distance(now, item)

        now, remain = remain[0], remain[1:]

    return pathsum


print(chker(_xylist) * 2 / _n)

Solution (Python):
from itertools import permutations
import math

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

ans = cnt = 0
for perm in permutations(range(n)):
    dist = 0
    for i in range(1, n):
        dist += math.sqrt((p[perm[i]][0] - p[perm[i - 1]][0])**2 +
                          (p[perm[i]][1] - p[perm[i - 1]][1])**2)

    
    ans += dist
    cnt += 1

ans /= cnt
print(ans)

Solution (Python):
l=map(int,open(0).read().split()[1:]);*z,=zip(l,l);print(sum(((a-x)**2+(b-y)**2)**.5for a,b in z for x,y in z)/len(z))

Solution (Python):
l=map(int,open(0).read().split()[1:]);*z,=zip(l,l);print(sum(((a-x)**2+(b-y)**2)**.5for a,b in z for x,y in z)/len(z))

Solution (Python):
import itertools
import math

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

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

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

s = 0
for c in itertools.combinations(range(N), 2):
    s += des(c[0], c[1])

print(s*2 / N)

Solution (Python):
n=int(input());x=[list(map(int,input().split()))for i in range(n)];a=0
for s in x:
 for t in x:a+=((s[0]-t[0])**2+(s[1]-t[1])**2)**.5
print(a/n)

Solution (Python):
N = int(input())
X = []
Y = []
Nex = 1

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


L = 0

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

if N == 2:
    print(L)
else:
    ans = 2*L/N
    print(ans)

Solution (Python):
N = int(input())
D = [list(map(int, input().split())) for i in range(N)]
Q = []
f = [1]
for i in range(N):
  f.append(f[i] * (i+1))
for i in range(N-1):
  for j in range(i+1, N):
    Q.append(((D[i][0] - D[j][0]) ** 2 + (D[i][1] - D[j][1]) ** 2) ** (1/2))
S = sum(Q) * (2 * f[N-1])
print(S / f[N])

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

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

Solution (Python):
import  math
n=int(input())
def dist(xi,yi,xj,yj):
    tmp= math.sqrt((xi-xj)**2+(yi-yj)**2)
    return tmp
tw=[]
for i in range(n):
    q,r=map(int,input().split())
    tw.append([q,r])
ans=0
for i in range(0,n-1):
    for j in range(i+1,n):
        f=dist(tw[i][0],tw[i][1],tw[j][0],tw[j][1])
        ans+=f
print(2*ans/n)

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

for p in itertools.permutations(list(range(n))):
	
	for i,j in zip(p,p[1:]):
		ans += math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
	count += 1
ans = ans/count

print(ans)

Solution (Python):
import itertools as z;n=int(input());p=list(z.combinations([list(map(int, input().split())) for i in range(n)],2));a=0
for c,d in p:a+=((c[0]-d[0])**2+(c[1]-d[1])**2)**0.5
print(a*(n-1)/len(p))

Solution (Python):
n=int(input())
xy=[]
for i in range(n):
    xy.append([int(j) for j in input().split()])
ans=0
import itertools
for l in itertools.permutations("01234567"[:n]): 
    for i in range(n-1):
        x=xy[int(l[int(i)])][0]-xy[int(l[int(i+1)])][0]
        y=xy[int(l[int(i)])][1]-xy[int(l[int(i+1)])][1]
        ans+=((x)**2+(y)**2)**0.5
import math
print(ans/(math.factorial(n)))

Solution (Python):
from math import sqrt
inpl = lambda: list(map(int,input().split()))
N = int(input())
xy = [inpl() for _ in range(N)]
def distance(i,j): return sqrt(sum((xy[i][k]-xy[j][k])**2 for k in range(2)))
S = sum(distance(i,j) for i in range(N-1) for j in range(i,N))
print(2*S/N)

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

pair = list(combinations(xy,2))

ans = 0
for p in pair:
    ans += ((p[0][0]-p[1][0])**2 + (p[0][1]-p[1][1])**2)**0.5
print(ans*(n-1)/len(pair))

Solution (Python):
N = int(input())
L = []
for _ in range(N):
    l = list(map(int,input().split()))
    L.append(l)
from itertools import permutations


permu_list = list(permutations(L,N))
ans = 0
for x in permu_list:
    for i in range(len(L)-1):
        l1 = x[i]
        l2 = x[i+1]
        length = ((l1[0] - l2[0])**2 + (l2[1] - l1[1]) ** 2)**(1/2)
        ans += length
print(ans/len(permu_list))

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

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

root = list(permutations(xy,n))

ans = 0
for r in root:
    a = 0
    for i in range(n-1):
        a += ((r[i+1][0]-r[i][0])**2 + (r[i+1][1]-r[i][1])**2)**0.5
    ans += a
print(ans/factorial(n))

Solution (Python):
import numpy as np
import math
 
def length(x,y):
    return np.sqrt(x**2+y**2)

N = int(input())
xy = []
for i in range(N):
    xyi = map(int,input().split())
    xy.append(np.array(list(xyi)))

L=0
for i in range(N):
    for j in range(N):
        d = xy[i] - xy[j]
        l = float(length(d[0],d[1]))
        L += l * math.factorial(N-1)
nn = math.factorial(N)
ans = L/nn
print(ans)

Solution (Python):


from math import sqrt


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

s = 0

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

print(s*2/n)

Solution (Python):
import sys
from math import sqrt
read = sys.stdin.read

N, *xy = map(int, read().split())
x = xy[::2]; y = xy[1::2]

distance = []

for i in range(N - 1):
    for j in range(i + 1, N):
        distance.append(sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2))

print(sum(distance) / N * 2)

Solution (Python):
def main():
    N = int(input())
    cities = [list(map(int, input().split())) for _ in range(N)]
    distances = [distance(cities[i], cities[j]) for i in range(N) for j in range(N)]
    total_distances = sum(distances)
    print((total_distances) / N)


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


if __name__ == "__main__":
    main()

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

Solution (Python):
import numpy as np
import math

N = int(input())

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

for i in range(N-1):
    for j in range(i+1, N):
        ans += np.sqrt((A[i][0]-A[j][0])**2+(A[i][1]-A[j][1])**2)
        
f = math.factorial(N)
ans *= 2/N

print(ans)

Solution (Python):
import itertools

def calc_dist(visit1, visit2):
    return ((xy[visit1][0] - xy[visit2][0])**2 + (xy[visit1][1] - xy[visit2][1])**2)** 0.5

n = int(input())
xy = [[int(_) for _ in input().split()] for _ in range(n)]

dist = 0
count = 0
visit_list = [i for i in range(n)]
for visit_order in itertools.permutations(visit_list):
    for i in range(n-1):
        dist += calc_dist(visit_order[i], visit_order[i+1])
    count += 1

print(dist/count)

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

Solution (Python):
import itertools
import math
N = int(input())
count = 0
f = []
ans = 0
def ai(i, j):
    return (math.sqrt((i[0] - j[0])** 2 + (i[1] - j[1])** 2))
for i in range(N):
    f += [list(map(int, input().split()))]
for i in itertools.permutations(range(N)):
    count += 1
    for j in range(N-1):
        ans += ai(f[i[j]], f[i[j + 1]])
print(ans/count)

Solution (Python):
import itertools
import math

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

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

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

s = 0
for c in itertools.combinations(range(N), 2):
    s += des(c[0], c[1])

print(s*2 / N)

Solution (Python):
n = int(input())
t = [list(map(int, input().split())) for _ in range(n)]
d = 0
for i in range(n - 1):
    for j in range(i, n):
        d += (((t[i][0] - t[j][0]) ** 2 + (t[i][1] - t[j][1]) ** 2)
              ** 0.5)

print(d*2/n)

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

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

    x[i],y[i] = map(int,input().split())

sum = 0
for i in range(n):
    for j in range(n):
        if i != j:
            sum += pow(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2),0.5)
            
sum = sum / (n * (n - 1)) * (n - 1)
print(sum)

Solution (Python):
n=int(input())
towns=[None]*n
for i in range(n):
  x,y=map(int,input().split())
  towns[i]=[x,y]
routes=0
import math
for i in range(len(towns)):
  for j in range(i+1,len(towns)):
    routes+=math.sqrt((towns[i][0]-towns[j][0])**2+(towns[i][1]-towns[j][1])**2)


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

Solution (Python):
import numpy as np

n = int(input())
x = np.array([input().split() for _ in range(n)], dtype=np.int)
norm2 = np.sum(x * x, axis=1)
dist = -2. * x.dot(x.T) + norm2
dist = np.sqrt(dist.T + norm2)
print(dist.sum() / n)

Solution (Python):
import math
n = int(input())
ar = []

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

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

print(sum_ / n)

Solution (Python):
import itertools
import math
n=int(input())
xys=[list(map(int,input().split())) for _ in [0]*n]
rs=0
l=lambda xy1,xy2:math.sqrt((xy1[0]-xy2[0])**2+(xy1[1]-xy2[1])**2)
f=0
for p in itertools.permutations(range(n), n):
  f+=1
  r=0
  for i in range(n-1):
    r+=l(xys[p[i+1]], xys[p[i]])
  rs+=r
print(rs/f)

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

for i in itertools.permutations(length): 

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


   ans.append(sum(result))

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

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

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

import itertools
import math

allx = list(itertools.permutations(x,2))
ally = list(itertools.permutations(y,2))


anslist = []

for (a,b) in zip(allx,ally):
    anslist.append(math.sqrt(pow(a[0] - a[1],2) + pow(b[0] - b[1],2)))

nn = n - 1
lastans = sum(anslist) * nn / len(anslist)

print(lastans)

Solution (Python):
from collections import namedtuple
from math import sqrt

Coordinates = namedtuple('Coordinates', 'idx x y')


def calc_dist(a: Coordinates, b: Coordinates) -> float:
    return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2))


n = int(input())

Coods = []
for idx in range(n):
    x, y = map(int, input().split())
    Coods.append(Coordinates(idx=idx, x=x, y=y))

ret = 0
for a in Coods:
    for b_idx in range(a.idx + 1, n):
        if a.idx == b_idx:
            continue
        b = Coods[b_idx]
        ret += calc_dist(a, b)
ret *= 2 / n
print(ret)

Solution (Python):
import math

n = int(input())
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 += math.sqrt(pow((x[i]-x[j]),2) + pow((y[i]-y[j]),2))
        
print(sum/n)

Solution (Python):

from math import sqrt
import numpy as np
N = int(input())
length = np.zeros(int(N * (N - 1) / 2))
point = [0] * N
for i in range(N):
    x, y = map(int, input().split())
    point[i] = (x, y)
    
k = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        length[k] = sqrt((point[i][0] - point[j][0]) ** 2 + (point[i][1] - point[j][1]) ** 2)
        k += 1
        
print(length.sum() * 2 / N)

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 math
N = int(input())
X = [0] * N
Y = [0] * N
for i in range(N):
    X[i], Y[i]  = map(int, input().split())

SUM = 0
CNT = math.factorial(N)
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        else:
            SUM = SUM + math.sqrt((X[i] - X[j])**2 + (Y[i] - Y[j])**2)

print(SUM/N)

Solution (Python):
import numpy as np
 
N = int(input())
A = [input().split() for _ in range(N)]

XY = np.array(sum(A, []),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
ans = dist_mat.sum() / N
print(ans)

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



List = list(range(n))
n_list = list(permutations(List,n))



length = 0
LENGTH = 0
for i in range(len(n_list)):
    for j in range(len(n_list[i])):
        if j+1 != n:
            length += math.sqrt((a[n_list[i][j]][0]-a[n_list[i][j+1]][0])**2+(a[n_list[i][j]][1]-a[n_list[i][j+1]][1])**2)
            
    
    LENGTH += length
print(length/len(n_list))

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

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

Solution (Python):
import itertools

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

perm = list(itertools.permutations(list(range(n))))
m = len(perm)
ans = 0
for p in perm:
    tmp = 0
    limit = len(p)
    for pi in range(limit - 1):
        a = (table[p[pi]][0] - table[p[pi + 1]][0]) ** 2
        b = (table[p[pi]][1] - table[p[pi + 1]][1]) ** 2
        g = (a + b) ** 0.5
        tmp += g
    ans += tmp

print(ans / m)

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

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

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

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
xy = [inpl() for i in range(n)]
cnt = 0
for i in itertools.permutations(xy):
    for j in range(n-1):
        cnt += math.sqrt(abs(i[j+1][0] - i[j][0])**2+abs(i[j+1][1] - i[j][1])**2)
print(cnt/math.factorial(n))

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

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

from math import sqrt,factorial
from itertools import permutations

ans = 0

for zz in permutations(z):
  for i in range(n-1):
    ans += sqrt((zz[i][0] - zz[i+1][0]) ** 2 + (zz[i][1] - zz[i+1][1]) ** 2)

print(ans/factorial(n))

Solution (Python):
import math

N = int(input())

fact_n = math.factorial(N)

towns = []

for i in range(N):
    a, b = map(int, input().split())
    towns.append((a, b))

ans = 0


for i in range(N):
    for j in range(N-i-1):
        town_a = towns[i]
        town_b = towns[j+i+1]
        dist = math.sqrt((town_a[0] - town_b[0])**2 + (town_a[1] - town_b[1])**2)
        ans += 2 * math.factorial(N-1) * dist

ans = ans / fact_n


print(ans)

Solution (Python):
n,*L=map(int,open(0).read().split());r=range(0,2*n,2);print(sum(((L[i]-L[j])**2+(L[i+1]-L[j+1])**2)**.5for i in r for j in r)/n)

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

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

key = [[0]*n for i in range(n)]

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

ans = ans * 2 / n
print(ans)

Solution (Python):
N=int(input())
T=[list(map(int,input().split())) for i in range(N)]
X=0
c=1
for i in range(N):
  for j in range(N):
    X=X+((abs(T[i][0]-T[j][0]))**2+(abs(T[i][1]-T[j][1]))**2)**0.5
print(X/N)

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

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


def fac(n):
    ans = 1
    while n > 1:
        ans *= n
        n -= 1

    return ans


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


def chker(xylist):
    now = xylist[0]
    remain = xylist[1:]
    pathsum = 0

    while remain:
        for item in remain:
            pathsum += distance(now, item)

        now, remain = remain[0], remain[1:]

    return pathsum


print(chker(_xylist) * 2 / _n)

Solution (Python):
import itertools

n = int(input())
s = [0]*n
for i in range(n):
    s[i] = list(int(x) for x in input().split())

key = [[False]*n for i in range(n)]

for i in range(n):
    for j in range(i+1, n):
        key[i][j] = ((s[i][0]-s[j][0])**2+(s[i][1]-s[j][1])**2)**0.5
ans = 0
key_permnutation = list(int(x) for x in range(n))
for key_list in itertools.permutations(key_permnutation):
    for i in range(n-1):
        p, q = key_list[i], key_list[i+1]
        p, q = min([p, q]), max([p, q])
        ans += key[p][q]

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

Solution (Python):

import sys
import pprint
import math

def solve(arrb, arra):
    ret = 0
    len_arrb = len(arrb)
    if len_arrb == 0:
        return dist_all(arra)
    for i in range(len_arrb):
        arrb_t = arrb[:]
        pop_arrb = arrb_t.pop(i)
        ret += solve(arrb_t, arra + [pop_arrb])
    return ret

def dist_all(arr):
    sum_dist = 0
    for i in range(len(arr) - 1):
        sum_dist += dist(arr[i], arr[i + 1])
    return sum_dist

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

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

print(solve(xy, []) / math.factorial(n))

Solution (Python):
from itertools import combinations
from math import hypot

N, *XY = map(int, open(0).read().split())

print("{:.9f}".format(sum(hypot(ax - bx, ay - by) for (ax, ay), (bx, by) in combinations(zip(*[iter(XY)] * 2), 2)) * 2 / N))

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())
at=[]
for i in range(N):
    for j in range(N):
        ea = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
        at.append(ea)
da = 0
for ag in at:
    da += ag
avg = da * math.factorial(N - 1) / math.factorial(N)
print(avg)

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

Solution (Python):
import itertools
N=int(input())
xy=[0]*N

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

perm = list(itertools.permutations(range(N),N))

ans=0
for p in perm:
    for i,_ in enumerate(p[1:]):
        xi = xy[p[i-1]][0]
        xj = xy[p[i]][0]
        yi = xy[p[i-1]][1]
        yj = xy[p[i]][1]
        result = ((xi-xj)**2 + (yi-yj)**2) ** (1/2)
        ans+=result

print(ans/len(perm))

Solution (Python):
import math

N = int(input())
xs = []
ys = []
for i in range(N):
    x, y = map(int, input().split())
    xs.append(x)
    ys.append(y)
ans = 0
for i in range(N):
    for j in range(i):
        ans += 2 * math.sqrt((xs[i] - xs[j]) ** 2 + (ys[i] - ys[j]) ** 2)
ans /= N
print(ans)

Solution (Python):
import math

N = int(input())
x = list()
y = list()
sum = 0

def dist(i,j):
    dx = x[i] - x[j]
    dy = y[i] - y[j]
    return math.sqrt(dx*dx + dy*dy)

if __name__ == '__main__':
    for i in range(N):
        x_i,y_i = map(int,input().split())
        x.append(x_i)
        y.append(y_i)

    for i in range(N):
        for j in range(N):
            sum += dist(i,j)

    print(sum/N)

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

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

Solution (Python):
import math
import itertools

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

dist = [[0 for a in range(N)] for b in range(N)]

def calcdist(i, j):
  if i > j:
    return dist[j][i]
  else:
    return dist[i][j]

for i in range(N):
  for j in range(i, N):
    if i != j:
      x_i = XY[i][0]
      y_i = XY[i][1]
      x_j = XY[j][0]
      y_j = XY[j][1]
      dist[i][j] = math.sqrt((x_i-x_j)**2 + (y_i-y_j)**2)

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

total = 0
for a in permlist:
  for b in range(len(a)-1):
    total += calcdist(a[b], a[b+1])
print(total/math.factorial(N))

Solution (Python):
import itertools
import math
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
ans=0
it=list(itertools.permutations(range(n),n))
for i in it:
    tmpx=l[i[0]][0]
    tmpy=l[i[0]][1]
    tmp=0
    for j in i[1:]:
        tmp+=math.sqrt((tmpx-l[j][0])**2+(tmpy-l[j][1])**2)
        tmpx=l[j][0]
        tmpy=l[j][1]
    ans+=tmp
print(ans/math.factorial(n))

Solution (Python):
import math

def main():
  n = int(input())
  cities = []
  for i in range(0, n):
    inputs = input().split(" ")
    cities.append([int(inputs[0]), int(inputs[1])])
  
  result = 0
  for i in range(0, n-1):
    for j in range(i+1, n):
      result += distance(cities[i], cities[j])
  
  print(result*factorial(n-1)*2/factorial(n))

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

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

main()

Solution (Python):
import math

def perms(n, li, result):
	li_l = len(li)
	result_l = len(result)
	if n == 0:
		return result
	if result_l == 0:
		for elem in li:
			result.append(str(elem))
		n -= 1
	else:
		for elem in li:
			for r in result[:result_l]:
				flag = True
				
				for r_e in r:
					if str(elem) == r_e:
						flag = False
						break
				if flag:
					r += str(elem)
					result.append(r)
				
		result = result[result_l:]
		n -= 1
	return perms(n, li,result)

def total(N, result, towns):
	total_dist = 0
	for elem in result:
		for ind in range(N-1):
			total_dist += dist(towns[int(elem[ind])], towns[int(elem[ind+1])])
	return total_dist

def dist(p1, p2):
	x1, y1 = p1
	x2, y2 = p2
	return math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))


if __name__ == '__main__':
  N = int(input())
  li = list(range(N))
  result = []
  towns = []
  for n in range(N):
  	x, y = map(float, input().split())
  	towns.append((x,y))
  result = perms(N, li, result)
  total_dist = total(N, result, towns)
  print(total_dist/len(result))

Solution (Python):

from itertools import permutations
from math import sqrt

def calc(x0, y0, x1, y1):
    return sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2)

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

for l in ll:
    tmp = 0
    x0, y0 = X[l[0]], Y[l[0]]
    for j in range(1, N):
        x1, y1 = X[l[j]], Y[l[j]]
        tmp += calc(x0, y0, x1, y1)
        x0, y0 = x1, y1
    ls.append(tmp)
    
print(sum(ls) / len(ll))

Solution (Python):


import math
import itertools

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

if __name__ == "__main__":
    N = int(input())
    point = []
    for i in range(N):
        tmpx,tmpy = list(map(int,input().split()))
        point.append([tmpx,tmpy])
    sumlist = []
    for target in itertools.permutations(point):
        tmpsum = 0
        for i in range(1,len(target)):
            tmpsum = tmpsum + calcdis(target[i-1],target[i])
        sumlist.append(tmpsum)

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

Solution (Python):
from itertools import permutations
import math

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

ans = cnt = 0
for perm in permutations(range(n)):
    dist = 0
    for i in range(1, n):
        dist += math.sqrt((p[perm[i]][0] - p[perm[i - 1]][0])**2 +
                          (p[perm[i]][1] - p[perm[i - 1]][1])**2)

    
    ans += dist
    cnt += 1

ans /= cnt
print(ans)

Solution (Python):
def kyori(a, b, c, d):
    x = (int(a) - int(b)) ** 2
    y = (int(c) - int(d)) ** 2
    z = (x + y) ** 0.5
    return z

n = int(input())
city_list = [0]*n
total_kyori = 0.0

for i in range(n):
  city_list[i] = input().split(' ')

for j in range(n):
  for k in range(n):
    ret_kyori = kyori(city_list[j][0], city_list[k][0], city_list[j][1], city_list[k][1])
    total_kyori += ret_kyori

ret_value = total_kyori / n
print(ret_value)

Solution (Python):
import math

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

Solution (Python):
import math

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


distance_sum = 0
for i in range(N):
    for j in range(N):
        distance_sum += math.sqrt((points[i][0] - points[j][0]) ** 2 + (points[i][1] - points[j][1]) ** 2)
distance_sum /= 2







routes_num = math.factorial(N)
two_points_combi_num = math.factorial(N) / math.factorial(N - 2) / math.factorial(2)
duplicate_count = (two_points_combi_num - (N - 1)) / two_points_combi_num * routes_num
result = distance_sum * (routes_num - duplicate_count) / routes_num
print(result)

Solution (Python):



import sys
import math
import itertools

input = sys.stdin.readline


def main():
    N = int(input())
    t = [[int(i) for i in input().split()] for _ in range(N)]

    div = math.factorial(N)
    ans = 0
    l = [i for i in range(N)]
    for ary in itertools.permutations(l):
        s = 0
        for i in range(len(ary)-1):
            a = ary[i]
            b = ary[i+1]
            s += math.sqrt((t[a][0]-t[b][0])**2+(t[a][1]-t[b][1])**2)
        ans += s
    print(ans/div)


if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import math

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

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

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

tmp =0

for j in itertools.combinations(s,2):
    tmp += distance(j[0],j[1])

print(tmp*2/n)

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

ans = sum/N
print(ans)