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

Solution (Python):
import numpy as np

def main():
    N = int(input())
    x = []
    for i in range(N):
        x.append(list(map(int, input().split())))
    X = np.array(x)
    j = 0
    for i in range(N-1):
        for k in range(i+1, N):
            j += np.linalg.norm(X[i] - X[k], ord=2)

    print(2*j/N) 

if __name__ == "__main__":
    main()

Solution (Python):
import itertools
import math

n = int(input())
l =[]
for i in range(n):
    x,y = map(int,input().split())
    l.append((x,y))
d = [[0]*n for i in range(n)]
for i in range(n-1):
    for j in range(n):
        xy = math.sqrt((l[i][0]-l[j][0])**2 + (l[i][1]-l[j][1])**2)
        d[i][j] = xy
        d[j][i] = xy
t = (i for i in range(n))
p = list(itertools.permutations(t))
sum = 0
nn = math.factorial(n)
for i in p:
    for j in range(n-1):
        sum += d[i[j]][i[j+1]]
ans = sum / nn
print(ans)

Solution (Python):
import math
n=int(input())
A=[]
sum=0
for i in range(n):
  a,s=(int(x) for x in input().split()) 
  A.append((a,s))
for i in A:
  for i2 in A:
    sum+=math.sqrt((i[0]-i2[0])**2+(i[1]-i2[1])**2)
print(sum/n)

Solution (Python):
import math
 
def factorial(n):
    if n == 0:
        return 1.0
    else:
        return n*factorial(n-1)
 
 
n = int(raw_input())
k = n
arr = []
while(k > 0):
    x, y = map(int, raw_input().split())
    arr.append((x, y))
    k -= 1
 
total = 0.0
for i in range(n):
    x1 = arr[i][0]
    x2 = arr[i][1]
    for j in range(i+1, n, 1):
        y1 = arr[j][0]
        y2 = arr[j][1]
        dist = (x1-y1)*(x1-y1) + (x2-y2)*(x2-y2)
        dist = float(math.sqrt(dist))
        dist = dist * float((factorial(n-1)*2))
        total += dist * float(1/factorial(n))
 
print total

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    C=[0]*n
    for i in range(n):
        x,y=map(int,input().split())
        C[i]=complex(x,y)

    from itertools import product
    S=sum(abs(C[i]-C[j]) for i,j in product(range(n),repeat=2))
    print(S/n)
resolve()

Solution (Python):
import math

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

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

sum = 0
fact = math.factorial(N-1)
for i in range(0, N):
  for j in range(0, N):
    if i == j:
      continue
    else:
      sum += distance(x_y_list[i], x_y_list[j]) * fact

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

Solution (Python):
import math

lst = []
n = int(input())
dis_sum = 0
for i in range(n):
  a,b = map(int,input().split())
  lst.append([a,b])
for i in lst:
  for j in lst:
    x = abs(j[0]-i[0])
    y = abs(j[1]-i[1])
    dis_sum += math.sqrt(x**2 + y**2) 
print(dis_sum / n)

Solution (Python):
N = int(input())
L=[[int(j) for j in input().split()] for i in range(N)]
from math import factorial, sqrt
from itertools import permutations
S = 0
def k(a, b):
    return sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)
for l in permutations(L):
    S += sum([k(l[i], l[i+1]) for i in range(N-1)])

print(S/factorial(N))

Solution (Python):



from itertools import permutations

def main():
    n = int(input())
    town = [tuple(map(int,input().split())) for i in range(n)]
    p = [i for i in range(n)]

    distsum = 0
    count = 0
    for p2 in permutations(p):
        for i in range(1,n):
            d1 = town[p2[i]]
            d2 = town[p2[i-1]]
            distsum += ((d1[0]-d2[0]) ** 2 + (d1[1]-d2[1]) ** 2) ** 0.5
        count += 1

    print(distsum / count)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
L=[[int(j) for j in input().split()] for i in range(N)]
from math import factorial, sqrt
S = 0

def solve(L, r):
    global S
    if len(L) == 0:
        for i in range(N-1):
            x, y = r[i]
            x2, y2 = r[i+1]
            S += sqrt((x - x2)**2 + (y - y2)**2)
    for i, v in enumerate(L):
        if len(L) == N:
            solve(L[:i] + L[i+1:], [v])
        else:
            solve(L[:i] + L[i+1:], r + [v])

solve(L, [])
print(S/factorial(N))

Solution (Python):
import math
from sys import exit, stdin
N = int(stdin.readline().rstrip())
xy = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]

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

Solution (Python):
import math as ma

n = int(input())
m = [list(map(int, input().split())) for i in range(n)]
t = [[0 for j in range(n) ] for i in range(n)]
ans = 0

for i in range(n):
    for j in range(n):
        if i == j or t[i][j] > 0:
            pass
        else:
            x = m[i][0] - m[j][0]
            y = m[i][1] - m[j][1]
            l = x**2 + y**2
            t[i][j] = ma.sqrt(l)
            t[j][i] = ma.sqrt(l)
    ans += sum(t[i])    

print(ans/n)

Solution (Python):
n=int(input())
c=1
for i in range(1,n+1):
    c *=i
a=[]
b=[]
for i in range(n):
    x,y=map(int,input().split())
    a.append(x)
    b.append(y)
d=[]
for i in range(n):
    for j in range(i+1,n):
        k=((a[i]-a[j])**2+(b[i]-b[j])**2)**0.5
        d.append(k)

total=c/n*2*sum(d)
print(total/c)

Solution (Python):
import math
import itertools

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

for pattern in list(itertools.permutations(range(n))):
    dist = 0
    for i in range(len(pattern)-1):
        dist += math.sqrt((town_list[pattern[i]][0]-town_list[pattern[i+1]][0])**2 + (town_list[pattern[i]][1]-town_list[pattern[i+1]][1])**2)
    ave_list.append(dist)

print(sum(ave_list)/len(ave_list))

Solution (Python):
import numpy as np
import itertools

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

grid = np.zeros((n, n))
for i in range(n):
    for j in range(n):
        grid[i][j] = ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** 0.5

sum = 0
cnt = 0

for i in itertools.permutations(np.arange(n)):
    cnt += 1
    dist = 0
    for j in range(n - 1):
        dist += grid[i[j]][i[j + 1]]
    sum += dist
print(sum / cnt)

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

kyori = []
kyori2 = []
kyori3 = []
sumation = 0
for i in range(N):
    
    kyori.append(list(map(int,input().split())))


x_distance = 0
y_distance = 0
for i in range(0,N):
    for j in range(i+1,N):
        x_distance = (kyori[i][0]-kyori[j][0])**2
        y_distance = (kyori[i][1]-kyori[j][1])**2
        
        Kyorixy = math.sqrt(x_distance + y_distance)
        kyori2.append(Kyorixy)
if len(kyori2) == 1:
    print(kyori2[0])
else:
  goukei = sum(kyori2)*2/N
  print(goukei)

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

sum = 0
for i in range(n):
  for j in range(i, n):
    x = abs(position[i][0] - position[j][0])
    y = abs(position[i][1] - position[j][1])
    sum += math.sqrt(x*x + y*y)

print(sum*2/n)

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

Solution (Python):
import itertools
import math

N = int(input())
Fac = math.factorial(N)
x = []
y = []
X = []
Y = []
leng = []
tmp = 0
for i in range(N):
    tmp = list(map(int,input().split()))
    x.append(tmp[0])
    y.append(tmp[1])
for i in itertools.permutations(x):
    X.append(i)
for i in itertools.permutations(y):
    Y.append(i)
for i in range(Fac):
    try:
        leng.append(((((X[i][0]-X[i][1]) ** 2) + ((Y[i][0]-Y[i][1]) ** 2)) ** 0.5))
    except:
        pass
tmp = 0
for i in range(Fac):
    tmp += leng[i]
tmp *= (N-1)
ans = tmp / Fac
print(ans)

Solution (Python):
import itertools
import math

N = int(input())
Fac = math.factorial(N)
x = []
y = []
X = []
Y = []
leng = []
tmp = 0
for i in range(N):
    tmp = list(map(int,input().split()))
    x.append(tmp[0])
    y.append(tmp[1])
for i in itertools.permutations(x):
    X.append(i)
for i in itertools.permutations(y):
    Y.append(i)
for i in range(Fac):
    try:
        leng.append(((((X[i][0]-X[i][1]) ** 2) + ((Y[i][0]-Y[i][1]) ** 2)) ** 0.5))
    except:
        pass
tmp = 0
for i in range(Fac):
    tmp += leng[i]
tmp *= (N-1)
ans = tmp / Fac
print(ans)

Solution (Python):
from itertools import permutations
import math

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

dists_sum = 0
for order in permutations(range(N)):
    for i in range(1, N):
        cp, cn = order[i - 1], order[i]
        dists_sum += math.hypot(X[cn] - X[cp], Y[cn] - Y[cp])
print(dists_sum / math.factorial(N))

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, x: "List[int]", y: "List[int]"):
    from math import sqrt
    def distance(x1: float, y1: float, x2: float, y2: float):
        return sqrt((x2-x1)**2 + (y2-y1)**2)

    ans = []
    import itertools
    for i in itertools.permutations(list(range(N)), N):
        t = 0
        for j in range(1,N):
            t += distance(x[i[j-1]], y[i[j-1]], x[i[j]], y[i[j]])
        ans.append(t)

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



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    x = [int()] * (N)  
    y = [int()] * (N)  
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()

Solution (Python):
import itertools

n = int(input())
path = list(itertools.permutations(set(range(n))))

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


def dist(x, y):
    return (x ** 2 + y ** 2) ** 0.5


check = list()
for p in path:
    for i in range(len(p) - 1):
        total += dist(town[p[i]][0] - town[p[i + 1]][0], town[p[i]][1] - town[p[i + 1]][1])

print(total / len(path))

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

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

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

import itertools, math

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

tmp = [i for i in range(n)]
pairs = list(itertools.combinations(tmp, 2))
ds = {}
for a, b in pairs:
  d = math.sqrt((lst[a][0] - lst[b][0]) ** 2 + (lst[a][1] - lst[b][1]) ** 2)
  if not a in ds:
    ds[a] = {}
    ds[a][b] = d
  else:
    ds[a][b] = d

cands = list(itertools.permutations(tmp, n))
result = 0
for cand in cands:
  res = 0
  for i, elem in enumerate(cand[:-1]):
    if elem in ds and cand[i+1] in ds[elem]:
      res += ds[elem][cand[i+1]]
    else:
      res += ds[cand[i+1]][elem]
  result += res
print(result / len(cands))

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

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

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

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

Solution (Python):

def perm(N):
    ans = 1
    for i in range(2, N+1):
        ans *= i
    return ans

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
distance_list = []
for i in range(N-1):
    for k in range(i+1, N):
        distance_list.append(((xy[i][0] - xy[k][0]) ** 2 + (xy[i][1] - xy[k][1]) ** 2) ** 0.5)

tmp = sum(distance_list)
cnt = perm(N-1) * 2

print(tmp * cnt / perm(N))

Solution (Python):
def main():
    global visited, adj, sets
    print = out.append
    ''' Cook your dish here! '''
    q = get_int()
    points = []
    res = 0
    for _ in range(q):
        pt = get_list()
        for i in points:
            res += ((pt[0]-i[0])**2+(pt[1]-i[1])**2)**(1/2)
        points.append(pt)
    print(2*res/q)


''' Coded with love at India by Satyam Kumar '''
import sys

input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()

print(*out, sep='\n')

Solution (Python):
def main():
    global visited, adj, sets
    print = out.append
    ''' Cook your dish here! '''
    q = get_int()
    points = []
    res = 0
    for _ in range(q):
        pt = get_list()
        for i in points:
            res += ((pt[0]-i[0])**2+(pt[1]-i[1])**2)**(1/2)
        points.append(pt)
    print(2*res/q)


''' Coded with love at India by Satyam Kumar '''
import sys, threading, math
from collections import defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()

print(*out, sep='\n')

Solution (Python):
N=int(input())
lxy=[]
for i in range(N):
    lxy.append(list(map(int,input().split())))
def dij(l1,l2):
    return ((l1[0]-l2[0])**2+(l1[1]-l2[1])**2)**0.5
dsum=0
for i in range(N):
    for j in range(i+1,N):
        dsum+=dij(lxy[i],lxy[j])
print(2*dsum/N)

Solution (Python):
def abc145_c():    
    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):
            ans += ((xy[i][0] - xy[j][0])** 2 + (xy[i][1] - xy[j][1])** 2)**0.5
    print(ans / n)
    
if __name__ == '__main__':
    abc145_c()

Solution (Python):

import itertools
import math
N = int(input())
x, y = [0]*N, [0]*N
l = list(range(N))

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




dis = 0
comb = list(itertools.permutations(l))

'''p[, r]で
長さrのタプル列、重複なしのあらゆる並びを表す
今回はリストlの重複なしの並び替え順序を新たなリストに収納している
並び方を計算しリストに収納しているイメージ
l[0,1,2]
l[0,2,1]これにもリスト番号が0,1,2と割り振られている
これが全通り入っている
これ作った人はすごい
自分も早く理解したい
'''
for i in range(0, len(comb)):
  for j in range(0, N-1):
    dis += math.sqrt((x[comb[i][j]]-x[comb[i][j+1]])**2 + (y[comb[i][j]]-y[comb[i][j+1]])**2)
'''
各経路の距離を足していき全距離分を経路数
で割れば平均距離が出るので各経路ごとの距離は
不必要と判断されている。
'''
print(dis/len(comb))

Solution (Python):
import itertools,math
def dist(x,y):
    return ((x[0]-y[0])**2 + (x[1]-y[1])**2)**(1/2)
n = int(input())
data = [list(map(int,input().split()))for i in range(n)]
ans = 0
for v in itertools.permutations(data):
    for i in range(1,n):
        ans += dist(v[i],v[i-1])

print(ans/math.factorial(n))

Solution (Python):
N=int(input())
lxy=[]
for i in range(N):
    lxy.append(list(map(int,input().split())))
def fac(n):
    ans=1
    for i in range(1,n+1):
        ans*=i
    return ans
def dij(l1,l2):
    return ((l1[0]-l2[0])**2+(l1[1]-l2[1])**2)**0.5

dsum=0
for i in range(N):
    for j in range(i+1,N):
        dsum+=dij(lxy[i],lxy[j])
print(2*dsum/N)

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

n = int(input())

li = []
for _ in range(n):
    i, j = map(int, input().split())
    li.append(np.array([i, j]))

li2 = permutations(li)

re = []
for a in li2:
    dis = 0 
    for (x1,y1),(x2,y2) in zip(a,a[1:]): 
        x = x1-x2
        y = y1-y2
        dis += math.sqrt(x * x + y * y)
    re.append(dis)

print(np.average(re))

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

n = int(input())

li = []
for _ in range(n):
    i, j = map(int, input().split())
    li.append(np.array([i, j]))

li2 = permutations(li)

re = []
for a in li2:
    dis = 0 
    for (x1,y1),(x2,y2) in zip(a,a[1:]):
        dis += math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
    re.append(dis)

print(np.average(re))

Solution (Python):
n=int(input())
d=[]
for i in range(0,n):
   a=[int(x) for x in input().split()] 
   d.append(a)
dis=0


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

Solution (Python):
import itertools

def kyori(xi, yi, xj, yj):
    return ((xi-xj)**2 + (yi-yj)**2)**0.5

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

lst = list(range(n))
p = itertools.permutations(lst)
goukei = 0
cnt = 0
for kumi in p:
    cnt += 1
    for i in range(n-1):
        goukei += kyori(x[kumi[i]], y[kumi[i]], x[kumi[i+1]], y[kumi[i+1]])

print(goukei/cnt)

Solution (Python):
import math
from itertools import permutations
N = int(input())
coodinate = [list(map(int,input().split())) for _ in range(N)]
f_N = math.factorial(N)
SumDistance = 0
for val in permutations(coodinate):
    for i in range(len(val) - 1):
        SumDistance += ((val[i+1][0] - val[i][0]) ** 2 + (val[i+1][1] - val[i][1]) ** 2) ** (1 / 2)
print(SumDistance / math.factorial(N))

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

n = int(input())
cnt = 0
dis = 0

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

for a in permutations(li):
    cnt += 1
    for (x1,y1),(x2,y2) in zip(a,a[1:]):
        dis += hypot(x1-x2, y1-y2)

print(dis/cnt)

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

n = int(input())
cnt = 0
dis = 0

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

ptn = list(range(n))

for a in permutations(ptn):
    cnt += 1
    for i, j in zip(a,a[1:]):
        x1, y1 = li[i]
        x2, y2 = li[j]
        dis += hypot(x1-x2, y1-y2)

print(dis/cnt)

Solution (Python):
import numpy as np
from itertools import permutations
from math import hypot

n = int(input())
cnt = 0
dis = 0

li = []
for _ in range(n):
    i, j = map(int, input().split())
    li.append(np.array([i, j]))

ptn = list(range(n))

for a in permutations(ptn):
    cnt += 1
    for i, j in zip(a,a[1:]):
        x1, y1 = li[i]
        x2, y2 = li[j]
        dis += hypot(x1-x2, y1-y2)

print(dis/cnt)

Solution (Python):
import numpy as np
from itertools import permutations
from math import hypot

n = int(input())
k = 0
dis = 0

li = []
for _ in range(n):
    i, j = map(int, input().split())
    li.append(np.array([i, j]))

li2 = permutations(li)

re = []
for a in li2:
    k += 1
    for (x1,y1),(x2,y2) in zip(a,a[1:]):
        dis += hypot(x1-x2, y1-y2)

print(dis/k)

Solution (Python):
import math
N = int(input())
x = [0 for i in range(N)]
y = [0 for i in range(N)]
for i in range(N):
    x[i], y[i] = map(int, input().split())
kaijo = 1
for i in range(1,N+1):
    kaijo *= i
kaisu = kaijo * (N-1)
hen = N * (N-1) // 2
wa = 0
for i in range(N):
    for j in range(i+1,N):
        kyori = math.sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)
        wa += kyori * kaisu / hen
print(wa / kaijo)

Solution (Python):
import numpy as np
from itertools import permutations
from math import hypot

n = int(input())

li = []
for _ in range(n):
    i, j = map(int, input().split())
    li.append(np.array([i, j]))

li2 = permutations(li)

re = []
for a in li2:
    dis = 0 
    for (x1,y1),(x2,y2) in zip(a,a[1:]):
        dis += hypot(x1-x2, y1-y2)
    re.append(dis)

print(np.average(re))

Solution (Python):
from itertools import permutations

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





path_length = 0
pxy = permutations(xy)
c = 0

for p in pxy:
    c += 1
    for (x1, y1), (x2, y2) in zip(p, p[1:]):
        path_length += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
ans = path_length / c

print(ans)

Solution (Python):
n = int(input())
xy = [[int(i) for i in input().split()] for i in range(n)]
import itertools
l = [int(i) for i in range(n)]
path_length = 0
for p in list(itertools.permutations(xy)):
    for (x1,y1),(x2,y2) in zip(p,p[1:]):
        path_length += ((x1-x2)**2 + (y1-y2)**2)**0.5
print(path_length / len(list(itertools.permutations(l))))

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

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

print(s * 2 / n)

Solution (Python):


n=int(raw_input())
l=[]
for i in range(n):
 x,y=map(int,raw_input().split())
 l.append([x,y])
res=0
for i in range(n):
 for j in range(n):
  res+=((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)**0.5
print res/n

Solution (Python):
import numpy as np
from itertools import permutations

N = int(input())
P = np.array([input().split() for _ in range(N)], dtype=int)

MAP = P.reshape(N,1,2) - P.reshape(1,N,2)
MAP = (MAP[:,:,0]**2 + MAP[:,:,1]**2)**0.5

total = 0
n_cnt = 0

for rt in permutations(range(N)):
  n_cnt += 1
  total += MAP[rt[:-1], rt[1:]].sum()

print(total / n_cnt)

Solution (Python):
import sys
import math
from itertools import permutations
input = sys.stdin.readline

def main():
    N = int(input())
    xy = [list(map(int, input().split())) for i in range(N)]
    d = [[0] * N for i in range(N)]

    for i in range(N):
        for j in range(i+1, N):
            t = math.sqrt((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2)
            d[i][j] = t
            d[j][i] = t
    
    ans = 0
    count = 0
    for p in permutations(range(N)):
        count += 1
        for i in range(N-1):
            ans += d[p[i]][p[i+1]]
    print(ans / count)



if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
x = []
y = []
for i in range(N):
    a,b = map(int, (input().split()))
    x.append(a)
    y.append(b)
aaa = 0
for i in range(N):
    for k in range(N):
        aaa += ((x[i] - x[k])**2+(y[i] - y[k])**2)**0.5
print(aaa/N)

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

def lengs(inp):
    x=0.0;y=0.0;S=0.0
    for i in range(N):
        J=math.sqrt((inp[i][0]-x)**2+(inp[i][1]-y)**2)
        x=float(inp[i][0]);y=float(inp[i][1])
        if i!=0:S+=J
    return S

J=[]
for i in range(N):
    j=input().split()
    J.append([float(j[0]),float(j[1])])
Js=list(itertools.permutations(J))
S=0.0
for Ja in Js:
    S+=lengs(Ja)
S=S/len(Js)
print(S)

Solution (Python):
import itertools
import math

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

def dis(p):
  d = 0
  for i in range(len(p)-1):
    d += ((p[i][0] - p[i+1][0]) ** 2 + (p[i][1] - p[i+1][1]) ** 2) ** 0.5
  return d

perm = itertools.permutations(p, N)
d = 0
for l in perm:
  
  d += dis(l)
  
print(d / math.factorial(N))

Solution (Python):
from itertools import permutations
from math import hypot
N = int(input())
XY = [tuple(map(int,input().split())) for i in range(N)]

tmp = n = 0
for ptn in permutations(XY):
    n += 1
    for (x1,y1),(x2,y2) in zip(ptn,ptn[1:]):
        tmp += hypot(x1-x2, y1-y2)
print(tmp / n)

Solution (Python):
n,*z=[list(map(int,t.split()))for t in open(0)];print(sum(((a-x)**2+(b-y)**2)**.5for a,b in z for x,y in z)/n[0])

Solution (Python):
import itertools
import math
N = int(input())
x, y = [0]*N, [0]*N
l = list(range(N))

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

dis = 0
comb = list(itertools.permutations(l))
for i in range(0, len(comb)):
  for j in range(0, N-1):
    dis += math.sqrt((x[comb[i][j]]-x[comb[i][j+1]])**2 + (y[comb[i][j]]-y[comb[i][j+1]])**2)

print(dis/len(comb))

Solution (Python):
N = int(input())
XY = [tuple(float(s) for s in input().split(' ')) for _ in range(N)]

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

    count += 1
    total += length
mean = total/count

print(mean * (N-1))

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

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

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


def dist(x, y):
    return ((p[x][0] - p[y][0]) ** 2 + (p[x][1] - p[y][1]) ** 2) ** 0.5


for i in range(N - 1):
    for j in range(i + 1, N):
        ans += dist(i, j) * 2 / N

print(ans)

Solution (Python):
import math

n = int(input())

z = math.factorial(n-2)*(n-1)*2
total = 0
p = []

for _ in range(n):
	x, y = map(int, input().split())
	
	for a, b in p:
		d = ((x-a)**2 + (y-b)**2)**0.5
		total += z*d
		
	p.append((x,y))
	
print(total/math.factorial(n))

Solution (Python):
def c_average_length():
    N = int(input())
    Positions = [[int(i) for i in input().split()] for j in range(N)]

    ans = 0.0
    for i in range(N):
        for j in range(i + 1, N):
            ans += ((Positions[i][0] - Positions[j][0])**2 +
                    (Positions[i][1] - Positions[j][1])**2)**0.5
    return ans * 2 / N

print(c_average_length())

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

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

def length(c1, c2):
  return math.sqrt((c1[0]-c2[0])**2 + (c1[1]-c2[1])**2)
 
A = list()
for i in list(permutations(range(len(c)))):
  L = 0
  for j in range(len(i)-1):
    L += length(c[i[j]], c[i[j+1]])
  A.append(L)
  
print(np.mean(A))

Solution (Python):
def permu(lis,n,prog):
  if len(lis)==1:
    result.append(prog+[lis[0]])
    n+=5
  
  else:
    for i in range(n):
      lx = lis.copy()
      x = lx[i]
      lx.remove(x)
      permu(lx,n-1,prog + [x])
      
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
import math
l_sum = 0
dic={}
lx = list(range(0,N))
 
for k,i in enumerate(xy):
  l = []
  for j in xy:
    length = ((i[0]-j[0])**2 + (i[1]-j[1])**2)**(1/2)
    l.append(length)
    
  dic[k]=l
  
  

result = []
permu(lx,N,[])
for i in result:
  for j in range(N-1):
    l_sum += dic[i[j]][i[j+1]]
    
print(l_sum/math.factorial(N))

Solution (Python):
import math

towns = int(input()) 
total_between_town = 0 
x_axis = [] 
y_axis = [] 


for i in range(towns):
  str = input()
  x_axis.append(int((str.split())[0]))
  y_axis.append(int((str.split())[1]))


for i in range(towns):
  for j in range(i + 1, towns):
    len = math.sqrt((x_axis[i]- x_axis[j]) ** 2 + (y_axis[i]- y_axis[j]) ** 2)
    total_between_town = total_between_town + len


route = math.factorial(towns) 
pairs = int(towns * (towns - 1) // 2) 
total_length = total_between_town * (towns - 1) * route / pairs 
average_length = total_length / route 


print(average_length)

Solution (Python):
from itertools import permutations
def fuctorial(n):
    if n <= 1:
        return 1
    else:
        return n * fuctorial(n - 1)


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


indice = list(range(N))
indices = permutations(indice, N)
res = 0
for ic in indices:
    for i in range(1, N):
        x1, y1 = zahyou[ic[i - 1]]
        x2, y2 = zahyou[ic[i]]
        res += ((x1 - x2)**2 + (y1 - y2)**2)**0.5


print(res/fuctorial(N))

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

Point = namedtuple('Point', ['x', 'y'])


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

    ans = 0
    cnt = 0

    for perm in permutations(range(n)):
        dist = 0
        for i in range(1, n):
            p1 = points[perm[i-1]]
            p2 = points[perm[i]]
            dist += sqrt(
                ((p1.x - p2.x) ** 2) + ((p1.y - p2.y) ** 2))
        ans += dist
        cnt += 1

    ans = ans / cnt
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):


import sys
from itertools import permutations
from math import hypot

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
XY = []
for i in range(N):
    x, y = MAP()
    XY.append((x, y))

sm = cnt = 0
for perm in permutations(XY):
    dist = 0
    prev = (0, 0)
    for i, (x, y) in enumerate(perm):
        if i == 0:
            prev = (x, y)
        else:
            x2, y2 = prev
            dist += hypot(x-x2, y-y2)
    sm += dist
    cnt += 1
print(sm/cnt)