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
N = int(input())

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

T = itertools.combinations(town, 2)
d_sum = 0
for t in T:
    xi = t[0][1]
    yi = t[0][2]
    xj = t[1][1]
    yj = t[1][2]
    d = ((xi - xj)**2 + (yi - yj)**2)**0.5
    d_sum += d

print(d_sum*2/N)

Solution (Python):
from itertools import permutations as perm


def euclidean_distance(list1, list2):
    x_norm = (list1[0] - list2[0]) ** 2
    y_norm = (list1[1] - list2[1]) ** 2
    return (x_norm + y_norm) ** 0.5


def main():
    n = int(input())
    xys = [list(map(int, input().split())) for _ in range(n)]

    orders = list(perm([xys[i] for i in range(n)], n))
    order_num = len(orders)
    ans = 0
    for order in orders:
        for i in range(n-1):
            ans += euclidean_distance(order[i], order[i+1])

    print(ans/order_num)


if __name__ == "__main__":
    main()

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

Solution (Python):

import math
from decimal import Decimal
from itertools import permutations


def inp():
    return(int(input()))



def inlist():
    return(list(map(int, input().split())))



def instr():
    s = input()
    return(list(s[:len(s)]))



def invr():
    return(map(int, input().split()))


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


N = inp()
points = []
p = []
for i in range(N):
    p.append(i)
    points.append(inlist())
D = [[0 for i in range(N)] for j in range(100)]
c = 0
for i in range(N-1):
    for j in range(i+1, N):
        x1, y1 = points[i]
        x2, y2 = points[j]
        
        d = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
        D[i][j] = d
        D[j][i] = d

permut = list(permutations(p))

res = 0
for pt in permut:
    for i in range(N-1):
        res += D[pt[i]][pt[i+1]]
print(res / fact(N))

Solution (Python):

def main():
    import sys, math
    import itertools as ite
    N = int(sys.stdin.readline())
    L = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
    
    
    A = list(ite.permutations([i for i in range(N)]))
    
    ans = 0
    for a in A:
        for i in range(N-1):
            ans += math.sqrt((L[a[i]][0]- L[a[i+1]][0])**2 + (L[a[i]][1]- L[a[i+1]][1])**2)
    print(ans/len(A))
            





if __name__=='__main__':
    main()

Solution (Python):
from itertools import permutations

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

def dist(a, b):
  dx = x[a] - x[b]
  dy = y[a] - y[b]
  return (dx**2 + dy**2)**0.5

ans = 0
np = [x for x in range(n)]
p = list(permutations(np))
for a in p:
  memo = 0
  for i in range(n-1):
    memo += dist(a[i],a[i+1])
  ans += memo
print(ans / len(p))

Solution (Python):
from itertools import permutations

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

def dist(a, b):
  dx = x[a] - x[b]
  dy = y[a] - y[b]
  return (dx**2 + dy**2)**0.5

ans = 0
np = [x for x in range(n)]
p = list(permutations(np))
for a in p:
  memo = 0
  for i in range(n-1):
    memo += dist(a[i],a[i+1])
  ans += memo
print(ans / len(p))

Solution (Python):
import itertools
from math import sqrt,factorial
n=int(input())
x=[]
y=[]
for i in range(n):
    xi,yi=map(int,input().split())
    x.append(xi)
    y.append(yi)
lis = [x for x in range(n)] 
ans=0
permutations_lis = itertools.permutations(lis)

for one_case in permutations_lis: 
  for i in range(n-1):
      xi=x[one_case[i]]
      yi=y[one_case[i]]
      xj=x[one_case[i+1]]
      yj=y[one_case[i+1]]
      ans+=sqrt((xi-xj)**2+(yi-yj)**2)
ans=ans/factorial(n)
print(ans)

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

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

dist_sum = 0
for route in permutations(range(n), n):
    for j in range(1, n):
        dist = (x[route[j]] - x[route[j - 1]]) ** 2
        dist += (y[route[j]] - y[route[j - 1]]) ** 2
        dist = dist ** 0.5
        dist_sum += dist
ans = dist_sum / factorial(n)
print(ans)

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

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

dist_sum = 0
for route in permutations(range(n), n):
    for j in range(1, n):
        dist = (x[route[j]] - x[route[j - 1]]) ** 2
        dist += (y[route[j]] - y[route[j - 1]]) ** 2
        dist = dist ** 0.5
        dist_sum += dist
ans = dist_sum / factorial(n)
print(ans)

Solution (Python):
from itertools import permutations

n = int(input())
box = []
for _ in range(n):
    x,y = map(int,input().split())
    box.append([x,y])
ans = 0
ans_box = list(permutations(range(n)))
cnt = len(ans_box)
for i in range(cnt):
    for j in range(n-1):
        ans += (((box[ans_box[i][j+1]][0] - box[ans_box[i][j]][0]) ** 2 + (box[ans_box[i][j+1]][1] - box[ans_box[i][j]][1]) ** 2 ) ** 0.5)

print(ans/cnt)

Solution (Python):

n = int(input())
coor = [] 
dis_ij = []

for i in range(n):
    x,y = map(int, input().split())
    coor.append((x,y))
    
def dis_2point(s,k):
    return ((s[0] -k[0])**2 + (s[1] - k[1])**2)**0.5

for i in range(n):
    for j in range(i):
        dis_ij.append(dis_2point(coor[i], coor[j]))
print(sum(dis_ij) * 2/n)

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

xy = [list(map(int,input().split()))for i in range(N)]
res = 0
for i in range(N):
    for j in range(N):
        res = res + ((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**(1/2)

print(res/N)

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

ans = 0
count = 0
for i in range(n-1):
    for j in range(i+1,n):
        d=math.sqrt( (x[i]-x[j])**2 + (y[i]-y[j])**2 )
        ans += d
        count += 1


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

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

def dfs(s):
    pass

n = int(input())
v = []
x = 0
for _ in range(n):
    v.append(tuple(map(int,input().split())))
for t in permutations(v):
    z = 0
    for i in range(n-1):
        ti = t[i]
        tn = t[i+1]
        z+=sqrt((abs(ti[0]-tn[0])**2)+(abs(ti[1]-tn[1])**2))
    x+=z
print(x/factorial(n))

Solution (Python):





N = int(input())

X=[]
Y=[]
for _ in range(N):
    xi,yi = map(int,input().split())
    X.append(xi)
    Y.append(yi)
XY = [[x,y] for x,y in zip(X,Y)]
import itertools

All = itertools.permutations(XY)
distance = 0
import math
for j,xy in enumerate(All):
    for i,xiyi in enumerate(xy):
        if i == 0:
            start = xiyi
            continue
        now = xiyi
        distance += math.sqrt((start[0]-now[0])**2+(start[1]-now[1])**2)
        start = now
    num = j
print(distance/(num+1))

Solution (Python):

import itertools
import math


def distance(t1, t2):
    return(math.hypot(t1[0] - t2[0], t1[1] - t2[1]))


def main():

    n = int(input())
    town = (tuple(map(int, input().split())) for _ in range(n))
    ans = 0

    for item in itertools.permutations(town, r=2):
        
        ans += distance(*item)

    print(ans / n)


if __name__ == "__main__":
    main()

Solution (Python):
import itertools

N = int(input())
XY = []

zerotoN = ""
for i in range(0,N):
    zerotoN += str(i)
keiro_list = list(itertools.permutations(zerotoN))

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

all_sum = 0

for keiro in keiro_list:
    for i in range(N-1):
        x1 = XY[int(keiro[i])][0]
        y1 = XY[int(keiro[i])][1]
        x2 = XY[int(keiro[i+1])][0]
        y2 = XY[int(keiro[i+1])][1]
        all_sum += ((x1-x2)**2 + (y1-y2)**2)**0.5

keiro_num = len(keiro_list)
print(all_sum/keiro_num)

Solution (Python):
import itertools
import math
ans = 0
l = []

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

for i in itertools.permutations(xy, n):
    l.append(i)
    for j in range(n - 1):
        ans += math.sqrt((i[j + 1][0] - i[j][0]) ** 2 +\
        (i[j + 1][1] - i[j][1]) ** 2)

ans /= len(l)
print(ans)

Solution (Python):
import itertools

n = int(input())

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

total = 0

for x1, y1 in xy:
    for x2, y2 in xy:
        total += ((x1 - x2)**2 + (y1 - y2)**2)**(1/2)
    
print(total/n)

Solution (Python):
from itertools import combinations

n = int(input())
D = []
ans = 0
for i in range(n):
    x,y = map(int,input().split())
    D.append((x,y))
for i,j in combinations(range(1,n+1),r=2):
    p,q = D[i-1]
    r,s = D[j-1]
    ans += ((p-r)**2+(q-s)**2)**(0.5)
print(2*ans/n)

Solution (Python):
import itertools as it
import math
from statistics import mean
N=int(input())
X=[list(map(int,input().split())) for i in range(N)]
A=[]
for i in list(it.permutations(X,N)):
    B=[]
    for j in range(N-1):
        B.append(math.sqrt((i[j][0]-i[j+1][0])**2+(i[j][1]-i[j+1][1])**2))
    A.append(sum(B))
print(mean(A))

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

ans=tot/math.factorial(n)
print(ans)

Solution (Python):
import itertools
import math

N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
d = 0
lis = [x for x in range(N)] 
 
permutations_lis = itertools.permutations(lis)

for one_case in permutations_lis:
    i = 0
    for num in one_case:
        if i == 0:
            a = num
            i += 1
            continue

        x = ((xy[num][0])-(xy[a][0]))**2
        y = ((xy[num][1])-(xy[a][1]))**2
        d += (x + y) **(1/2)

        a = num

print(d / math.factorial(N))

Solution (Python):
import itertools
import math

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

l = []
for i in range(n):
  l.append(i)

sum = 0
for v in itertools.permutations(l):
  for i in range(n - 1):
    sum += ((grid[v[i]][0] - grid[v[i + 1]][0]) ** 2 + 
                 (grid[v[i]][1] - grid[v[i + 1]][1]) ** 2) ** (1 / 2)

print(sum / math.factorial(n))

Solution (Python):

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

Solution (Python):
from copy import deepcopy
import math
import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())
x, y = [], []
for _ in range(n):
    xi, yi = list(map(int, input().split()))
    x.append(xi)
    y.append(yi)


def dfs(memo, prex, prey, step, res_):
    global res, counter
    if step == n:
        res += res_
        counter += 1
        return
    for i in range(n):
        if step == 0:
            temp_memo = deepcopy(memo)
            temp_memo[i] = 1
            dfs(temp_memo, x[i], y[i], step + 1, res_)
        else:
            if memo[i]:
                pass
            else:
                temp_memo = deepcopy(memo)
                temp_memo[i] = 1
                dfs(temp_memo, x[i], y[i], step + 1, res_ +
                    (((x[i] - prex) ** 2 + (y[i] - prey) ** 2) ** 0.5))


res = 0
counter = 0
dfs([0 for _ in range(n)], 0, 0, 0, 0)
print(res/counter)

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

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

    def dist(c1, c2):
        return hypot(c1[0] - c2[0], c1[1] - c2[1])

    ans = 0
    for perm in permutations(cities, r=2):
        ans += dist(*perm)
    ans /= N

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import permutations
import math

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

N = int(input())
town = [list(map(int, input().split())) for i in range(N)]
p_town = list(permutations(town, N))
d = [0]*(len(p_town))


for i in range(len(p_town)):
  for j in range(N-1):
    dick = p_town[i][j] + p_town[i][j+1]
    d[i] += dist(*dick)


avg = sum(d)/len(d)
print(avg)

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

Solution (Python):
from itertools import permutations


N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i, xys in enumerate(permutations(XY), 1):
    last = xys[0]
    dist = 0
    for xy in xys[1:]:
        dist += ((xy[0] - last[0]) ** 2 + (xy[1] - last[1]) ** 2) ** 0.5
    ans += dist
print(ans / i)

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())
num = [x for x in range(n)]
permutation = itertools.permutations(num)
total = 0
for turn in permutation:
    for j in range(n - 1):
        total += math.sqrt((x[turn[j + 1]] - x[turn[j]]) ** 2 + (y[turn[j+1]] - y[turn[j]]) ** 2)
ans = total / math.factorial(n)
print(ans)

Solution (Python):
import itertools


N = int(input())

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

S = 0


route = list(itertools.combinations(P, 2))

for i in route:
   
   S += ((i[0][0] - i[1][0])**2 + (i[0][1] - i[1][1])**2)**0.5
   
print(S*2/N)

Solution (Python):
import itertools
import math

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


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


for i in itertools.permutations(m, n):
    for j in range(n-1):
        l += f(i[j], i[j+1])

print(l / math.factorial(n))

Solution (Python):
import itertools


N = int(input())

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

S = 0


route = list(itertools.combinations(P, 2))

for i in route:
   
   S += ((i[0][0] - i[1][0])**2 + (i[0][1] - i[1][1])**2)**0.5
   
print(S*2/N)

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

P = []

S = 0

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


for i in range(N-1):
   for j in range(i+1,N):
       
       S += ((P[i][0] - P[j][0])**2 + (P[i][1] - P[j][1])**2)**0.5
       
print(S*(2/N))

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

P = []

S = 0

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


for i in range(N-1):
   for j in range(N-1-i):
       
       S += (((P[i][0] - P[i+j+1][0])**2 + (P[i][1] - P[i+j+1][1])**2)**0.5)*2
       
print(S/N)

Solution (Python):
import math
from itertools import permutations
def inp():return map(int,input().split())
n=int(input())
cd=[[] for _  in range(n+1)]
s=0
for i in range(1,n+1):
    x,y=inp()
    cd[i].append(x)
    cd[i].append(y)

def add(A,n):
    length = 0
    for i in range(n - 1):
        length += math.sqrt((abs(cd[A[i]][0] - cd[A[i + 1]][0])) ** 2 + (abs(cd[A[i]][1] - cd[A[i + 1]][1]))**2)
    return (length)

def num(n):
    p=1
    for i in range(2,n+1):
        p=p*i
    return p


for x in permutations(range(1,n+1),n):
    s=s+add(x,n)
print(s/num(n))

Solution (Python):
N, *_XY = open(0).read().split()
N = int(N)
XY = list(zip(*[map(int, iter(_XY))]*2))

import itertools
import numpy as np

routes = list(itertools.permutations(XY, N))

memo = {}
d_list = []

for r in routes:
    d = 0
    for i in range(N-1):
        if (r[i], r[i+1]) in memo.keys():
            d += memo[(r[i], r[i+1])]
        elif (r[i+1], r[i]) in memo.keys():
            d += memo[(r[i+1], r[i])]
        else:
            memo[(r[i], r[i+1])] = np.linalg.norm(np.array(r[i]) - np.array(r[i+1]))
            d += memo[(r[i], r[i+1])]
    d_list.append(d)

print(np.mean(d_list))

Solution (Python):
import math

N = int(input())
root = [list(map(int,input().split())) for i in range(N)]
way = []
for i in range(N-1):
    for j in range(i+1,N):
        way.append(math.sqrt((root[i][0]-root[j][0])**2 + (root[i][1]-root[j][1])**2))
ans = sum(way) * (math.factorial(N-1)*2)
print(ans/math.factorial(N))

Solution (Python):

import itertools
import math
n = int(input())
adress = []
dstnc = []
for i in range(n):
    adress.append(list(map(int, input().split())))
p = list(itertools.permutations(adress))
for route in p:
    s = 0
    state = route[0]
    for i in range(1,n):
        s += ((state[0] - route[i][0])**2 + (state[1] - route[i][1])**2)**(1/2)
        state = route[i]
    dstnc.append(s)
print(sum(dstnc)/math.factorial(n))

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


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


sum_kyori = 0
for i in range(math.factorial(N)):
    kyori = 0

    for j in range(1,N):
        
        x_ = (xy[permi[i][j]][0] - xy[permi[i][j-1]][0])**2 
        y_ = (xy[permi[i][j]][1] - xy[permi[i][j-1]][1])**2
        kyori += math.sqrt(x_ + y_)
    sum_kyori += kyori

ans=(float(sum_kyori/math.factorial(N)))
print(ans)

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):
import math

N = int(input())
x = []
y = []

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

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

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

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

ans = 0
num = 0
for ps in permutations(range(N)):
    dist = 0
    for i in range(N-1):
        dist += hypot(xs[ps[i]]-xs[ps[i+1]], ys[ps[i]]-ys[ps[i+1]])
    ans += dist
    num += 1

print(ans/num)

Solution (Python):
import itertools
import math

n = int(input())
X = [[] for _ in range(n)]
Y = [[] for _ in range(n)]

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

Dist = [0 for _ in range(math.factorial(n))]
for i, S in enumerate(itertools.permutations(range(n))):
    for j in range(len(S) - 1):
        Dist[i] += ((X[S[j+1]] - X[S[j]])**2 + (Y[S[j+1]] - Y[S[j]])**2)**(1/2)
print(sum(Dist)/len(Dist))

Solution (Python):
import math

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

for i in range(N-1):
    for j in range(i+1,N):
        
        x=A[i][0]
        y=A[i][1]
        a=A[j][0]
        b=A[j][1]
        tmp=((x-a)**2+(y-b)**2)**0.5
        R.append(tmp)

x=math.factorial(N)
a=(N-1)*x/(len(R))
c=sum(R)
print(c*a/x)

Solution (Python):
import math

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

for i in range(N-1):
    for j in range(i+1,N):
        
        x=A[i][0]
        y=A[i][1]
        a=A[j][0]
        b=A[j][1]
        tmp=((x-a)**2+(y-b)**2)**0.5
        R.append(tmp)

x=math.factorial(N)
a=(N-1)*x/(len(R))
c=sum(R)
print(c*a/x)

Solution (Python):
import itertools
import math
n = int(input())
dis = [[0] * 2 for i in range(n)]
for i in range(n):
    dis[i][0],dis[i][1] = list(map(int,input().split()))
b= [0] * n
for i in range(n):
    b[i] = i + 1
p = list(itertools.combinations(b,2))
ans =0
for i in range(len(p)):
    dist = (dis[p[i][0]-1][0]-dis[p[i][1]-1][0])**2 + (dis[p[i][0]-1][1]-dis[p[i][1]-1][1])**2
    ans += math.sqrt(dist)

print(ans/n * 2)

Solution (Python):


import itertools, math

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

length = 0
length_sum = 0
sum_ = 0

for num, val in enumerate(itertools.permutations(city_list, n)):
    for i in range(len(val) - 1):
        length =  math.sqrt((val[i][0] - val[i + 1][0]) ** 2 +  (val[i][1] - val[i + 1][1]) ** 2)
        length_sum += length
    sum_ += length_sum
    length_sum = 0
    
ans = sum_ / (num + 1)
print(ans)

Solution (Python):
import itertools,math

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

d=0
d_all=[]
for i in itertools.permutations(range(N),N):
    for j in range(N-1):
        d+=math.sqrt((X[i[j+1]]-X[i[j]])**2+(Y[i[j+1]]-Y[i[j]])**2)
    d_all.append(d)
    d=0
print(sum(d_all)/math.factorial(N))

Solution (Python):
import math

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

ans = 0    
for i in range(n):
    for j in range(n):
        tmp = math.sqrt((X[i]-X[j])**2+(Y[i]-Y[j])**2)
        ans += tmp

print(ans/n)

Solution (Python):
import itertools
import math

N=int(input())
X=[]
Y=[]
dist=[ [ 0 for j in range(N) ] for i in range(N) ]
for n in range(N):
  x,y=map(int,input().split())
  X.append(x)
  Y.append(y)

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

l=[ i for i in range(N) ]
P=itertools.permutations(l,N)
ans=0
for p in P:
  p=list(p)
  for i in range(N-1):
    ans+=dist[p[i]][p[i+1]]
print(ans/math.factorial(N))

Solution (Python):
points = [map(int, raw_input().split(' ')) for _ in range(int(raw_input()))]
def distance(u,v):
	return ((u[1] - v[1]) ** 2 + (u[0] - v[0]) ** 2) ** 0.5
c = [0,0]
def permut(i, points, c):
	if i == len(points):
		tot = 0
		for u,v in zip(points, points[1:]): tot += distance(u,v)
		c[0] +=  tot
		c[1] += 1
		return 
	for j in range(i,len(points)):
		points[i], points[j] = points[j], points[i]
		permut(i+1, points,c)
		points[i], points[j] = points[j], points[i]

permut(0, points,c)

print c[0] / float(c[1])

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

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

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

def calc(a, b):
    x1, y1 = a
    x2, y2 = b
    return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))
 
 
n = int(input())
xy = []
for i in range(n):
    xy.append(list(map(int, input().split())))
 
ans = 0
for order in permutations(range(n)):
    tmp = 0
    for i in range(1, n):
        tmp += calc(xy[order[i]], xy[order[i - 1]])
    ans += tmp
ans /= factorial(n)
 
print(ans)

Solution (Python):
import math
import itertools

def main():
    r = [tuple(map(int, input().split())) for _ in range(int(input()))]
    d = 0
    for x in itertools.permutations(r):
        
        for i in range(len(x)-1):
            d += math.sqrt((x[i][0]-x[i+1][0])**2 + (x[i][1]-x[i+1][1])**2)
    print(d/math.factorial(len(r)))
    
if __name__ == '__main__':
    main()

Solution (Python):
import math

n = int(input())

town = []

ans = 0

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

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

Solution (Python):
n=int(input())
k = [list(map(int, input().split())) for i in range(n)]
import math
ans=0
p=(n*(n-1))//2
z=math.factorial(n)
q=z*(n-1)
for i in range(n-1):
    for j in range(i+1,n):
        z=math.sqrt((k[i][0]-k[j][0])**2+((k[i][1]-k[j][1])**2))
        ans+=(q/p)*z

z=math.factorial(n)
print(ans/z)

Solution (Python):
def dist(p1,p2):
    x1, y1 = p1
    x2, y2 = p2
    return ((x2-x1)**2+(y2-y1)**2)**.5

def combi(m,n):
    a=1
    b=1
    for i in range(n):
        a*=m-i
        b*=(i+1)
    return a//b

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

edge=[]
for i in range(n):
    for j in range(i+1,n):
        edge.append(dist(a[i],a[j]))

c = combi(n,2)
ans = sum(edge)*(combi(c-1,n-2))/(combi(c,n-1))
print(ans)

Solution (Python):
from math import sqrt
from itertools import combinations
N = int(input())
points = tuple(tuple(map(int,input().split())) for _ in range(N))
print(sum(sqrt((x1-x2)**2+(y1-y2)**2) for (x1,y1),(x2,y2) in combinations(points,2))*2/N)

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

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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


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

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

    print(2 * ans / N)
    return


if __name__ == '__main__':
    main()

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

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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


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

    dist = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(i + 1, N):
            dist[i][j] = dist[j][i] = distance2(C[i][0], C[i][1], C[j][0], C[j][1])

    ans = 0
    for perm in permutations(range(N)):
        for i in range(N - 1):
            ans += dist[perm[i]][perm[i + 1]]

    print(ans / factorial(N))
    return


if __name__ == '__main__':
    main()

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

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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


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

    dist = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(i + 1, N):
            dist[i][j] = dist[j][i] = distance2(C[i][0], C[i][1], C[j][0], C[j][1])

    ans = 0
    for perm in permutations(range(N)):
        for i in range(N - 1):
            ans += dist[perm[i]][perm[i + 1]]

    print(ans / factorial(N))
    return


if __name__ == '__main__':
    main()

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

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def distance(p, q):
    return sum((px - qx) ** 2.0 for px, qx in zip(p, q)) ** 0.5


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

    dist = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(i + 1, N):
            dist[i][j] = dist[j][i] = distance(C[i], C[j])

    ans = 0
    for perm in permutations(range(N)):
        for i in range(N - 1):
            ans += dist[perm[i]][perm[i + 1]]

    print(ans / factorial(N))
    return


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import permutations
from itertools import combinations
from math import sqrt
from math import factorial
from collections import defaultdict

N = int(input())

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

length = defaultdict(float)
l_sum = 0
res = 0

for a, b in combinations(range(N),2):
    length[(a, b)] = (sqrt( (points[a][0] - points[b][0])**2 + (points[a][1] - points[b][1])**2 ))

for a in permutations(range(N)):
    for i in range(N-1):
        l_sum += length[(min(a[i], a[i+1]), max(a[i], a[i+1]))]

res = l_sum/factorial(N)

print(res)

Solution (Python):
from itertools import permutations
from itertools import combinations
from math import sqrt
from math import factorial
from collections import defaultdict

N = int(input())

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

length = defaultdict(float)
l_sum = 0
res = 0

for a, b in combinations(range(N),2):
    length[(a, b)] = (sqrt( (points[a][0] - points[b][0])**2 + (points[a][1] - points[b][1])**2 ))

for a in permutations(range(N)):
    for i in range(N-1):
        l_sum += length[(min(a[i], a[i+1]), max(a[i], a[i+1]))]

res = l_sum/factorial(N)

print(res)

Solution (Python):
import itertools
import math

n=int(input())
townRoot=list(itertools.permutations([i for i in range(1,n+1)]))
townList=[]
for i in range(n):
    townList.append(tuple([int(i) for i in input().split()]))
sumLenght=0
length=0
for root in townRoot:
    for xy in range(n-1):
        town1=root[xy] -1
        town2=root[xy+1] -1
        length += math.sqrt((townList[town1][0] - townList[town2][0])**2 \
                + (townList[town1][1] - townList[town2][1])**2)
    sumLenght += length
    length = 0
print(sumLenght/len(townRoot))