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):
N = int(input())
XYS = [list(map(int, input().split())) for _ in range(N)]
s = 0
def perm(ns):
    acc = []
    def fill(ms, remains):
        if remains:
            for m in remains:
                fill(ms + [m], [x for x in remains if x != m])
        else:
            acc.append(ms)
    fill([], ns)
    return acc

s = 0
for indexes in perm(list(range(N))):
    xys = [XYS[i] for i in indexes]
    x0, y0 = xys[0]
    for x1, y1 in xys:
        s += ((x0 - x1)**2 + (y0 - y1)**2) ** 0.5
        x0 = x1
        y0 = y1

nf = 1
for i in range(1, N+1):
    nf *= i
ans = s / nf

print(ans)

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

def rec(prefix, remains):
    if remains:
        for xy in remains:
            for xys in rec(prefix + [xy], [x for x in remains if x != xy]):
                yield xys
    else:
        yield prefix

s = 0
for xys in rec([], XYS):
    prev = xys.pop(0)
    for xy in xys:
        v = math.sqrt(((xy[0] - prev[0])**2) + ((xy[1] - prev[1])**2))
        prev = xy
        s += v

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

Solution (Python):
N = int(input())
A = [tuple(map(int, input().split())) for _ in range(N)]
ans = []
for i in range(len(A)-1):
    for k in range(i+1,len(A)):
        ans.append((((A[i][0]-A[k][0])**2)+(A[i][1]-A[k][1])**2)**0.5)
print(sum(ans)*2/N)

Solution (Python):
N = int(input())
A = [tuple(map(int, input().split())) for _ in range(N)]
ans = []
import numpy as np
for i in range(len(A)-1):
    for k in range(i+1,len(A)):
        ans.append(np.sqrt(((A[i][0]-A[k][0])**2)+(A[i][1]-A[k][1])**2))
print(sum(ans)*2/N)

Solution (Python):
N = int(input())
A = [tuple(map(int, input().split())) for _ in range(N)]
ans = []
import numpy as np
import itertools
for zyun in itertools.permutations(range(N)):
    cnt = 0
    for k in range(len(zyun)-1):
        cnt += np.sqrt((A[zyun[k+1]][0]-A[zyun[k]][0])**2+(A[zyun[k+1]][1]-A[zyun[k]][1])**2 )
    ans.append(cnt)
print(sum(ans) / len(ans))

Solution (Python):
import math
import itertools
N = int(input())
X = []
Y = []
num = []
for i in range(N):
  x,y = map(int,input().split())
  X.append(x)
  Y.append(y)
  num.append(i)
p = itertools.permutations(num, N)
count_sum = 0
for i in p:
  count=0
  for j,k in enumerate(i):
    if j<N-1:
      count+=math.sqrt((X[k]-X[i[j+1]])**2+(Y[k]-Y[i[j+1]])**2)
  count_sum+=count
      
print(count_sum/math.factorial(N))

Solution (Python):
from math import sqrt
from itertools import permutations
N=int(input())
xy=[list(map(int,input().split())) for _ in range(N)]
ans=0
cnt=0
for i in permutations(range(N)):
  d=0
  for j in range(N-1):
    dx=xy[i[j+1]][0]-xy[i[j]][0]
    dy=xy[i[j+1]][1]-xy[i[j]][1]
    d+=sqrt(dx**2+dy**2)
  ans+=d
  cnt+=1
print(ans/cnt)

Solution (Python):
import itertools

n=int(input())
l=[int(i) for i in range(n)]
ans=chk=p=0
w=[]
for i in range(n):
    x,y=map(int,input().split())
    w.append((x,y))
for i in list(itertools.permutations(l,n)):
    chk=0
    for j in range(n-1):
        chk+=((w[i[j]][0]-w[i[j+1]][0])**2+(w[i[j]][1]-w[i[j+1]][1])**2)**0.5
    ans+=chk
    p+=1

print(ans/p)

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

def mapt(fn, *args):
    return tuple(map(fn, *args))

n = int(input())
cities = [mapt(int, input().split(" ")) for i in range(n)]
list1 = list(permutations(range(1, n+1), n))


def some(index1, index2):
    index1 -= 1
    index2 -= 1
    x1, y1 = cities[index1]
    x2, y2 = cities[index2]
    r = math.sqrt((x1-x2)**2 +(y1-y2)**2)
    
    return r

ans = 0
for row in list1:
    for i in range(n-1):
        
        ans += some(*row[i:i+2])
    
print(ans/len(list1))

Solution (Python):
import math
from itertools import permutations 
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
ans_ = 0
count = 0
sum_list = list(permutations(range(N), N))
for nums in sum_list:
    for i in range(len(nums)-1):
        x1, y1 = xy[nums[i]]
        x2, y2 = xy[nums[i+1]]
        ans_ += math.sqrt((x1-x2)**2+(y1-y2)**2)
    count += 1
print(ans_ / count)

Solution (Python):
from itertools import permutations
from math import sqrt, factorial
n = int(input())
lst = [None]

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

ans = 0

for per in permutations(list(range(1,n+1))):
    lenth = 0
    for i in range(0,n-1):
        x1,y1 = lst[per[i]]
        x2,y2 = lst[per[i+1]]
        lenth += sqrt((x2-x1)**2 + (y2-y1)**2)
    ans += lenth

ans /= factorial(n)

print(ans)

Solution (Python):
import itertools
import math
import statistics


def main():
    N = int(input())
    city_lst = [list(map(int, input().split())) for _ in range(N)]
    d_lst = [0] * math.factorial(N)

    for i, route in enumerate(itertools.permutations(range(N))):
        for j in range(len(route) - 1):
            d = math.sqrt((city_lst[route[j + 1]][0] - city_lst[route[j]][0])
                          ** 2 + (city_lst[route[j + 1]][1] - city_lst[route[j]][1]) ** 2)
            d_lst[i] += d

    print(f"{statistics.mean(d_lst):.10f}")


if __name__ == "__main__":
    main()

Solution (Python):
from itertools import permutations
import math
n = int(input())
A = []
for _ in range(n):
    x,y = map(int,input().split())
    A.append([x,y])
tmp = 0
cnt = 0
for L in permutations(A):
    cnt += 1
    for i in range(1,len(L)):
            tmp += math.sqrt((L[i][0]-L[i-1][0])**2+(L[i][1]-L[i-1][1])**2)
print(tmp/cnt)

Solution (Python):
import sys
input=sys.stdin.readline
import math
from collections import defaultdict,deque
from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

t=ii()
lol=[]
for i in range(t):
    a,b=ml()
    lol.append([a,b])
yo=0    
cnt=0
for i in list(permutations(lol)):
    for j in range(1,len(i)):
        x=i[j][0]-i[j-1][0]
        y=i[j][1]-i[j-1][1]
        yo+=math.sqrt(x*x+y*y)
    cnt+=1
print(yo/cnt)

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

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7


N = int(input())

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

p = [i for i in range(N)]
pp = list(itertools.permutations(p))

ans = 0
for ppp in pp:
    for i in range(1,N):
        ans += math.sqrt((x[ppp[i-1]][0]-x[ppp[i]][0])**2 + (x[ppp[i-1]][1]-x[ppp[i]][1])**2)

print(ans / math.factorial(N))

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


sum=0
for S in permutations(range(N)):
    tmp=0
    for i in range(N-1):
        tmp+= sqrt((L[S[i]][0]-L[S[i+1]][0])**2 + (L[S[i]][1]-L[S[i+1]][1])**2)
    sum+=tmp
print(sum/factorial(N))

Solution (Python):


n=int(input())
from itertools import permutations
per=[i for i in range(n)]
per=list(permutations(per,n))


fac=[[0] for i in range(10)]
fac[0]=1
fac[1]=1
for i in range(2,10):
  fac[i]=i*fac[i-1]


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


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

ans=0
for i in per:
  for j in range(1,n):
    ans=ans+diff(xy[i[j]],xy[i[j-1]])


print(ans/fac[n])

Solution (Python):
n=int(input())
city=[list(map(int,input().split())) for _ in range(n)]
length=[]
for i in range(n-1):
    for j in range(i+1,n):
        len=((city[i][0]-city[j][0])**2+(city[i][1]-city[j][1])**2)
        length.append(len**(0.5))
ans=sum(length)*2/n
print("{:.7f}".format(ans))

Solution (Python):
def rec(num, string, total, xy_list, n):
    x, y = xy_list[num]
    if string:
        pre_one = int(string[-1])
        pre_x, pre_y = xy_list[pre_one]
        distance = ((x - pre_x)**2 + (y - pre_y)**2)**0.5
        total+=distance
    string+=str(num)

    if len(string)==n:
        return total

    all_total = 0
    ret_list = [i for i in range(n) if str(i) not in string]
    for one in ret_list:
        all_total+=rec(one, string, total, xy_list, n)
    return all_total

def main():
    n = int(input())
    xy_list = []
    k = 1
    for i in range(n):
        x, y = list(map(int, input().split(" ")))
        xy_list.append((x, y))
        k*=(i+1)

    all_total = 0
    for i in range(n):
        all_total+=rec(i, "", 0, xy_list, n)
    print(all_total/k)

if __name__=="__main__":
    main()

Solution (Python):
import math
N = int(input())
x = [0] * N 
y = [0] * N 
for i in range(N):
    X,Y = map(int,input().split())
    x[i] = X 
    y[i] = Y
    
total = 0
cnt = 0
def dfs(now,rest):
    global total,cnt
    for next in rest:
        
        total += math.sqrt((x[now]-x[next])**2 + (y[now]-y[next])**2) * factorial(len(rest)-1)
        rest2 = rest.copy()
        rest2.remove(next)
        dfs(next,rest2)
    return 

def factorial(N):
    if N == 1 or N == 0:
        return 1
    else:
        return N * factorial(N-1)
        
for i in range(N):
    A = [j for j in range(N)]
    A.remove(i)
    dfs(i,A)
    



print(total / factorial(N))

Solution (Python):
N = int(input())
pos = []
for _ in range(N):
    x,y = [int(v) for v in input().split()]
    pos.append((x,y))

path = []
def dfs(state):
    if len(state) == N:
        path.append(state)
        return
    for i in range(N):
        if i not in state:
            nstate = state[:]
            nstate.append(i)
            dfs(nstate)

dfs([])
ans = 0
for p in path:
    n = p[0]
    tmp = 0
    for nn in p[1:]:
        tmp += (abs(pos[n][0] - pos[nn][0]) ** 2 + abs(pos[n][1] - pos[nn][1]) ** 2) ** (1/2)
    ans += (tmp / len(path))
print(ans)

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

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

print(mean(ans))

Solution (Python):
import math

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

a = []
for i in range(n-1):
    for j in range(i, n):
        a.append(((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**(1/2))
print(2*math.factorial(n-1)*sum(a)/math.factorial(n))

Solution (Python):
import numpy as np

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
XY = np.array(xy).flatten()

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

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

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

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

Solution (Python):
import itertools
import numpy as np

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

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

routes = list(itertools.permutations(range(N), N))
ans = []

for route in routes:
    dist = 0
    for i in range(1, N):
        dist += distance(X[route[i]], X[route[i-1]], Y[route[i]], Y[route[i-1]])
    ans.append(dist)

print(np.mean(ans))

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

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

dis = []
for i in range(n - 1):
    for j in range(i + 1, n):
        dis.append(((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])** 2) ** (1 / 2))

print(2 * math.factorial(n - 1) * sum(dis) / math.factorial(n))

Solution (Python):
import math

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

dis = []
for i in range(n-1):
    for j in range(i+1, n):
        dis.append(((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**(1/2))
print(2*math.factorial(n-1)*sum(dis)/(math.factorial(n)))

Solution (Python):
import itertools

n=int(input())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])

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

ans = 0
count = 0
for v in itertools.permutations(memo, n):
    count += 1
    tmp_root = 0
    for i in range(1, n):
        tmp_root += ((ab[v[i-1]][0]-ab[v[i]][0])**2+(ab[v[i-1]][1]-ab[v[i]][1])**2)**0.5
    ans += tmp_root

print(ans/count)

Solution (Python):



def main():
    from itertools import permutations
    from math import sqrt

    n = int(input())
    x = [0 for _ in range(n)]
    y = [0 for _ in range(n)]

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

    path = list(permutations(range(n)))
    path_count = len(path)
    length = 0

    for p in path:
        for i, j in zip(p, p[1:]):
            length += sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)

    print(length / path_count)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
L = []

for _ in range(N):
    L.append(list(map(int,input().split())))

ans = 0

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) ** 0.5

ans *= 2 / N

print(ans)

Solution (Python):
from itertools import permutations
import math
def dist(x,y):
    return ((x[0]-y[0])**2+(x[1]-y[1])**2)**0.5

N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
A = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
    for j in range(N):
        A[i][j] = dist(X[i],X[j])
tot = 0
for x in permutations(range(N),N):
    cnt = 0
    for i in range(1,N):
        cnt += A[x[i-1]][x[i]]
    tot += cnt
print(tot/math.factorial(N))

Solution (Python):
import itertools
from math import sqrt
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
ans = 0
cnt = 0
for v in itertools.permutations(list(range(n))):
    for i in range(n-1):
        x = (xy[v[i]][0]-xy[v[i+1]][0]) ** 2
        y = (xy[v[i]][1]-xy[v[i+1]][1]) ** 2
        ans += sqrt(x+y)
    cnt += 1
print(ans/cnt)

Solution (Python):
import itertools

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

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

ans = 0
div = fact(n)
for lst in itertools.permutations(range(n), n):
    start = xy[lst[0]]
    for pos in lst:
        dx = start[0] - xy[pos][0]
        dy = start[1] - xy[pos][1]
        d = (dx ** 2 + dy ** 2) ** 0.5
        ans += d / div
print(ans)

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

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

ll = list(range(0,n))
perml = list(permutations(ll, n))

val = 0
for perm in perml:
    prev_x = 0
    prev_y = 0
    for i,p in enumerate(perm):
        x,y = xyl[p]
        if i == 0:
            prev_x = x
            prev_y = y
        else:
            val += sqrt( (prev_x-x)**2 + (prev_y-y)**2 )
            prev_x = x
            prev_y = y
    
ans = val/len(perml)
print(ans)

Solution (Python):
import math

n = int(input())
d = [[0] * n for _ in range(n)]
p = []
for i in range(n):
    p.append(tuple(map(int, input().split())))

s = 0
for i in range(n):
    xi, yi = p[i]
    for j in range(i+1, n):
        xj, yj = p[j]
        s += math.sqrt((xi - xj) ** 2 + (yi - yj) ** 2)
s = s * 2 / n
print(s)

Solution (Python):
import math

def cal(n):
    if n == 1:
        return 0
    else:
        return (n-1)+cal(n-1)
n = int(input())
x = [None]*n
y = [None]*n
total = 0
for i in range(n):
    x[i], y[i] = map(int, input().split())

for i in range(n):
    for j in range(n):
        total += math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
total = total/2
ans = total*(n-1)/cal(n)

print(ans)

Solution (Python):
import math
import itertools

n = int(input())
l = list(range(n))

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

ans = 0 
def clc_distandce(a,b):
    [x1, y1] = a
    [x2, y2] = b
    dist = math.sqrt((a[0] - b[0])**2 + (a[1]-b[1])**2)
    return dist


for i in itertools.permutations(l,n):
    
    
    for k in range(1,n):
        dist = clc_distandce(pos_list[list(i)[k]],pos_list[list(i)[k-1]])
        ans += dist
    
    
    
print(ans/math.factorial(n))

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

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

def calc(a,b):
    [x1, y1] = a
    [x2, y2] = b
    return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))

sum = 0
for i in permutations(range(n)):
    distance = 0
    for j in range(1, n):
        distance = calc(xy[i[j]], xy[i[j-1]])
        sum += distance
print(sum/factorial(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):
    for j in range(n):
        if i!=j:
            s+=((x[i]-x[j])**2+(y[i]-y[j])**2)**(1/2)
print(s/n)

Solution (Python):
import itertools as it

n = int(input())
lst = []
for i in range(n):
	x, y = list(map(int, input().split()))
	lst.append([x, y])
perm = list(it.permutations(lst))

cost = []
for i in perm:
	temp = 0
	for j in range(len(i)-1):
		temp += (((i[j][0] - i[j+1][0])**2) + ((i[j][1] - i[j+1][1])**2))**0.5
	cost.append(temp)

print(sum(cost) / len(cost))

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

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

def calc(a, b):
    [x1, y1] = a
    [x2, y2] = b
    return sqrt(pow(x1 - x2, 2) + pow(y1 -y2, 2))
ans = 0
for order in permutations(range(N)):
    tmp = 0
    for i in range(1, N):
        tmp += calc(l[order[i]], l[order[i-1]])
    ans += tmp
print(ans/factorial(N))

Solution (Python):
import math
N = int(input())
x = []
y = []
for i in range(N):
  tmp = input().split(" ")
  x.append(int(tmp[0]))
  y.append(int(tmp[1]))

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

print(d/N)

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

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

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

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

s = 0 
for p in path:
    before = [lst[p[0]][0], lst[p[0]][1]]
    for i in range(1, N):
        s += sqrt((lst[p[i]][0] - before[0])**2 + (lst[p[i]][1] - before[1])**2)
        before[0] = lst[p[i]][0]
        before[1] = lst[p[i]][1]


n = 1
for i in range(1, N+1):
    n *= i

print(s/n)

Solution (Python):
import sys
import math
import itertools
import collections

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N = NI()
    xy = [NLI() for _ in range(N)]
    
    ls = [p for p in range(N)]
    p_list = list(itertools.permutations(ls))
    
    full_course = ["" for _ in range(len(p_list))]
    
    for k in range(len(p_list)):
        distance = 0
        for l in range(N-1):
            departure = p_list[k][l] 
            goal = p_list[k][l+1]
            Xd = xy[departure][0]
            Yd = xy[departure][1]
            Xg = xy[goal][0]
            Yg = xy[goal][1]
            distance += ((Xd-Xg)**2 + (Yd-Yg)**2)**(1/2)
        full_course[k] = distance

    print(sum(full_course)/len(p_list))


if __name__ == '__main__':
    main()

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

N = int(input())
town = {}
route = permutations(range(0,N))

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

Sum = 0

for v in route:
    for i in range(N-1):
        Sum += ((town[v[i+1]][0] - town[v[i]][0])**2 + (town[v[i+1]][1] - town[v[i]][1])**2)**(0.5)

ans = Sum/factorial(N)

print(ans)

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

Solution (Python):
from collections import deque
import math
N = int(input())
x = [0] * N
y = [0] * N
al = 1
l = 0
for i in range(N):
    al *= (i+1)
    x[i], y[i] = map(int, input().split())

que = deque()
for i in range(N):
    que.append([i])
while que:
    seq = que.popleft()
    if len(seq) == N:
        for i in range(N-1):
            l += math.sqrt((x[seq[i+1]]-x[seq[i]]) ** 2 + (y[seq[i+1]]-y[seq[i]]) ** 2)
    else:
        for i in range(N):
            if i in seq:
                continue
            seq_next = seq + [i]
            que.append(seq_next)

print(l / al)

Solution (Python):
import math
import itertools

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

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

cnt = 0

for a in itertools.permutations(range(n)):
  for j in range(n-1):
    cnt += ((data[a[j+1]][0]-data[a[j]][0])**2 + (data[a[j+1]][1]-data[a[j]][1])**2)**0.5

print(cnt / math.factorial(n))

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

cnt = list(itertools.permutations(xy))
ans = []
for c in cnt:
    ky = []
    for n in range(N-1):
        k = ((c[n][0]-c[n+1][0])**2+(c[n][1]-c[n+1][1])**2)**(1/2)
        ky.append(k)
    ans.append(sum(ky))
print(sum(ans)/len(ans))

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

import math
import itertools
count = math.factorial(N)
line = 0
for pp in itertools.permutations(points, N):
	i = 0
	while i < N - 1:
		i1, i2 = pp[i], pp[i + 1]
		t = ((XY[i1][0] - XY[i2][0]) ** 2 + (XY[i1][1] - XY[i2][1]) ** 2) ** 0.5 
		line += t
		i += 1
ans = line / count
print(ans)

Solution (Python):
import itertools

n = int(input())

x_list = []
y_list = []
cnt = 0
distance = 0

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

for a in itertools.permutations(range(n)): 
    cnt += 1
    for i in range(len(a)-1):
        
        distance += ((x_list[a[i]]-x_list[a[i+1]])**(2) + (y_list[a[i]]-y_list[a[i+1]])**(2))**(1/2)
ans = distance/cnt
print(ans)

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

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

Solution (Python):
import copy
import math
import time
import statistics
import math
import itertools


def get_int():
    return int(input())

def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

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

def get_string_char_list():
    return list(str(input()))




'''
while (idx < n) and ():

    idx += 1
'''

def main():
    start = time.time()
    n = get_int()
    a = []
    ans = 0
    for i in range(n):
        a.append(get_int_list())

    count = 0
    for keiro in itertools.permutations(a):
        count += 1
        nagasa = 0
        for i in range(1,n):
            nagasa += math.sqrt((keiro[i][0] - keiro[i-1][0]) ** 2 + (keiro[i][1] - keiro[i-1][1]) **2)
        ans += nagasa
    print(ans / count)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import permutations as P
from math import sqrt as r

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
ans_sum = 0
town = list(P(list(range(N)), N))
Q = len(town)

for town in town:
    d = 0
    for i in range(N - 1):
        X = xy[town[i]][0] - xy[town[i + 1]][0]
        Y = xy[town[i]][1] - xy[town[i + 1]][1]
        d += r(X**2 + Y**2)
    
    ans_sum += d

print(ans_sum/Q)

Solution (Python):
from itertools import combinations

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

Solution (Python):
def resolve():
    import itertools
    import math
    def distance(i, j):
        return math.sqrt((i[0]-j[0])**2+(i[1]-j[1])**2)

    n = int(input())
    l = list(range(n))
    X_Y = []
    for i in range(n):
        X_Y.append(list(map(int, input().split())))
    p_list = list(itertools.permutations(l, n))
    total = 0
    for p in p_list:
        p_t = 0
        for index in range(n-1):
            p_t += distance(X_Y[p[index]], X_Y[p[index+1]])
        total += p_t
    print(total/len(p_list))
resolve()

Solution (Python):
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
print(sum(((xi-xj)**2 + (yi-yj)**2) **0.5 for xi,yi in xy for xj,yj in xy) / N)

Solution (Python):
import itertools
import math
n = int(input())
x = [0]
y = [0]
for i in range(1,n+1):
    a,b = map(int,input().split())
    x.append(a)
    y.append(b)
    
num_list = [int(i) for i in range(1,n+1)]
keiro = []
for v in itertools.permutations(num_list, n):
    keiro.append(list(v))
kensu = math.factorial(n)


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

Solution (Python):
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
all_order=[]
def dfs(a):
  if len(a)==n:
    all_order.append(a)
  else:
    for i in range(n):
      if i in a:continue
      dfs(a+[i])
dfs([])
ans=0
for od in all_order:
  x,y=xy[od[0]]
  for i in od[1:]:
    nx,ny=xy[i]
    ans+=((x-nx)**2+(y-ny)**2)**0.5
    x,y=nx,ny
print(ans/len(all_order))

Solution (Python):
import itertools
import math

def dist(c1, c2):
    dist = math.sqrt((c2[0]-c1[0])**2 + (c2[1]-c1[1])**2)
    return dist

def solve():
    N = int(input())
    c = []
    for _ in range(N):
        x_tmp, y_tmp = list(map(int, input().split()))
        c.append([x_tmp, y_tmp])
    l = [i for i in range(N)]

    sum_dist = 0
    ave_dist = 0
    for p in itertools.permutations(l):
        for i in range(len(p)-1):
            sum_dist += dist(c[p[i]], c[p[i+1]])
    ave_dist = sum_dist/len(list(itertools.permutations(l)))
    print(ave_dist)

if __name__ == "__main__":
    solve()

Solution (Python):
import itertools

N = int(input())
dots = [tuple(map(int, input().split())) for _ in range(N)]
total_distance = 0
total_count = 0

for route in itertools.permutations(dots):
    for i in range(len(route)-1):
        x1, y1 = route[i]
        x2, y2 = route[i+1]

        total_distance += ((x2 - x1)**2 + (y2 - y1)**2)**0.5
    
    total_count += 1

ans = total_distance / total_count
print(ans)

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

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

D = []
for i in range(n):
    for j in range(i+1,n):
        D.append(((X[i]-X[j])**2+(Y[i]-Y[j])**2)**0.5)


ans = sum(D)*2/n
print(ans)

Solution (Python):
N=int(input())
lis=[tuple(map(int,input().split())) for _ in range(N)]
import itertools,math
p = itertools.permutations(list(range(N)))
sm=0

for v in p:
    
    for k in range(N-1):
        xi,yi=lis[v[k]]
        xj,yj=lis[v[k+1]]
        
        sm+=((xi-xj)**2+(yi-yj)**2)**(1/2)
print(sm/math.factorial(N))

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

Solution (Python):
import itertools
import math

n = int(input())

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

l = range(n)

d_list =[]

for v in itertools.permutations(l):
    d = 0
    for i in range(n-1):
        f = v[i]
        t = v[i+1]
        d += math.sqrt((xy[t][0] - xy[f][0]) ** 2 + (xy[t][1] - xy[f][1]) ** 2)
    d_list.append(d)

print(sum(d_list) / math.factorial(n))