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):
def resolve():
    N = int(input())
    XY = []
    for _ in range(N):
        XY.append(list(map(int, input().split())))
    import itertools
    import math
    total = 0
    for order in itertools.permutations(list(range(N))):
        posx, posy = XY[order[0]]
        dist = 0
        for i in range(1, N):
            nxtx, nxty = XY[order[i]]
            dist += math.sqrt((nxtx-posx)**2+(nxty-posy)**2)
            posx, posy = nxtx, nxty
        total += dist
    print(total/math.factorial(N))
    

    
if '__main__' == __name__:
    resolve()

Solution (Python):
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from itertools import permutations
import math
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


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

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

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


if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import math

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

lis = [x for x in range(N)]
permutations_lis = itertools.permutations(lis)

dis = 0
for one_case in permutations_lis:
    for i in range(1,N):
        dis += ((ls2[one_case[i]][0]-ls2[one_case[i-1]][0])**2+(ls2[one_case[i]][1]-ls2[one_case[i-1]][1])**2)**(1/2)
    
print(dis/(math.factorial(N)))

Solution (Python):
N=int(input())
x=[0]*N
y=[0]*N
for i in range(N):
  x[i],y[i]=map(int,input().split())
answer=0
kaijou=1
junretu=0
for i in range(2,N+1):
  kaijou*=i
junretu=int(N*(N-1)/2)
a=int(kaijou*(N-1)/(junretu*2))

for i in range(N):
  for j in range(N):
    if i!=j:
      answer+=((x[i]-x[j])**2+(y[i]-y[j])**2)**(1/2)
print((answer*a)/kaijou)

Solution (Python):
N=int(input())
X=[list(map(int,input().split())) for i in range(N)]
print(2/N*sum([sum([(l-m)**2for l,m in zip(X[i],X[j])])**0.5for j in range(N) for i in range(N) if i<j ]))

Solution (Python):
import itertools
import math

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

A = list(itertools.permutations(list(range(n))))
ans = 0
for a in A:
    for i in range(len(a)-1):
        ans += math.sqrt((D[a[i]][0]-D[a[i+1]][0])**2+(D[a[i]][1]-D[a[i+1]][1])**2)

print(ans/len(A))

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

l = [i for i in range(N)]
ssum = 0
for v in itertools.permutations(l):
  distance = 0
  pre = X[v[0]]
  for n in v:
    distance += math.sqrt((pre[0]-X[n][0])**2+(pre[1]-X[n][1])**2)
    pre = X[n]
  ssum += distance

print(ssum/math.factorial(N))

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

Solution (Python):
import itertools

N=int(input())
XY=[list(map(int, input().split())) for _ in range(N)]
ans=0
NP=list(itertools.permutations([i for i in range(N)],N))

temp=0

for np in NP:
	for i in range(0,len(np)-1):
		temp+=((XY[np[i]][0]-XY[np[i+1]][0])**2+(XY[np[i]][1]-XY[np[i+1]][1])**2)**.5
	ans+=temp
	temp=0

print(ans/len(NP))

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

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

from itertools import permutations
ans = 0
num = 0
for p in permutations(range(n)):
    val = 0
    prv = p[0]
    for i in p[1:]:
        val += ((xy[i][0]-xy[prv][0])**2 + (xy[i][1]-xy[prv][1])**2) ** 0.5
        prv = i
    ans += val
    num += 1
print(ans/num)

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

Solution (Python):
import itertools
import math
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    town = [LI() for _ in range(n)]
    way = list(itertools.permutations(range(n), n))
    ans = 0
    for w in way:
        for i in range(n-1):
            x1 = town[w[i]][0]
            y1 = town[w[i]][1]
            x2 = town[w[i+1]][0]
            y2 = town[w[i+1]][1]
            ans += math.sqrt((x1-x2)**2 + (y1-y2)**2)
    ans /= len(way)
    print(ans)

if __name__ == '__main__':
    main()

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

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

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

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

cal_dist = lambda x,y: sqrt((x[0]-y[0])**2+(x[1]-y[1])**2)

def calc_total(route):
  total=0
  for i in range(1,len(route)):
    total+=cal_dist(X[route[i]],X[route[i-1]])
  return total

SUM=0
for p in permutations(range(N)):
  SUM += calc_total(p)

print(SUM/factorial(N))

Solution (Python):
import math

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

Solution (Python):
import itertools
n=int(input())
a=[]
for i in range(n):
  x,y=map(int,input().split())
  a.append((x,y))
num=0
count=0
for i in itertools.permutations(range(n),n):
  s=list(i)
  num+=1
  for j in range(n-1):
    count+=((a[s[j+1]][0]-a[s[j]][0])**2+(a[s[j+1]][1]-a[s[j]][1])**2)**(0.5)
print(count/num)

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

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

order_num = 1
order = list(itertools.permutations(range(n)))
for i in range(1,n+1) :
    order_num *= i

dist_list = []
for i in range(order_num) :
    total = 0
    for j in range(n-1) :
        prev = order[i][j]
        next = order[i][j+1]
        total += dist(city[next], city[prev])
    dist_list.append(total)
print(sum(dist_list)/order_num)

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

Solution (Python):
from itertools import permutations
from math import factorial as fact
N = int(input())
towns = [list(map(int, input().split())) for _ in range(N)]
acc = 0
for p in permutations(range(N), N):
    for i in range(N - 1):
        t1, t2 = towns[p[i]], towns[p[i + 1]]
        acc += ((t1[0] - t2[0]) ** 2 + (t1[1] - t2[1]) ** 2) ** .5
print(acc / fact(N))

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

Solution (Python):
import math

n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n):
  for j in range(i+1, n):
    cnt += math.sqrt((a[i][0] - a[j][0]) ** 2 + (a[i][1] - a[j][1]) ** 2)
print(cnt * 2 / n)

Solution (Python):
n=int(input())
xy=[]

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

import itertools

l=list(itertools.permutations(range(0,n)))
cnt=0
sum=0

while True:
    if len(l)==0:
        break
    temp=l.pop(0)
    for i in range(n-1):
        sum+=((xy[temp[i]][0]-xy[temp[i+1]][0])**2+(xy[temp[i]][1]-xy[temp[i+1]][1])**2)**(1/2)
    cnt+=1

print(sum/cnt)

Solution (Python):
import itertools
import math

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

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

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

goukei = 0

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





for i in range(len(jr)):
  for j in range(N-1):
    goukei += dist(x[jr[i][j]], y[jr[i][j]], x[jr[i][j+1]], y[jr[i][j+1]])
print(goukei/len(jr))

Solution (Python):
from itertools import permutations

def dist(x0, y0, x1, y1):
    ans = ((x0 - x1) ** 2 + (y0 - y1) ** 2) ** (0.5)
    return ans

def resolve():
    N = int(input())
    x, y, = [], []
    for i in range(N):
        x_tmp, y_tmp = list(map(int, input().split()))
        x.append(x_tmp)
        y.append(y_tmp)
    ans = 0
    ls = list(permutations(list(range(N)), N))
    for l in ls:
        for i in range(len(l)-1):
            ans += dist(x[l[i]], y[l[i]], x[l[i+1]], y[l[i+1]])

    print(ans / len(ls))
    return

resolve()

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


import itertools
import  math
lis = list(itertools.permutations(range(n),n))

al=0
for elem in lis:
    [al := al + math.sqrt( (x[elem[i]]-x[elem[i+1]])**2 +  (y[elem[i]]-y[elem[i+1]])**2) for i in range(n-1)]

print(al/len(lis))

Solution (Python):
import itertools

n = int(input())

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

total = 0
num = [i for i in range(n)]
for v in itertools.permutations(num, n):
    d = 0
    for i in range(n-1):
        cf, ct = v[i], v[i+1]
        d += ((x[ct] - x[cf])**2 + (y[ct] - y[cf])**2)**0.5
    total += d
for i in range(n, 1, -1):
    total /= i
print(total)

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

l = []

for i in range(n):
    ans = 0
    for j,k in s:
        a = s[i][0] - j
        b = s[i][1] - k
        ans += numpy.sqrt(a**2 + b**2)
    l.append(ans)

print(sum(l)/n)

Solution (Python):
import math
import itertools

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

N = int(input())
Cord = []
ls = list(itertools.permutations(range(N)))
for _ in range(N):
    Cord.append(tuple(map(int,input().split())))
ans = 0
for l in ls:
    for i in range(N-1):
        ans+=distance(Cord[l[i]],Cord[l[i+1]])
print(ans/len(ls))

Solution (Python):

import itertools
import math

N = int(input())
zahyo = []
for _ in range(N):
    zahyo.append(tuple(map(int, input().split(" "))))


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

dis = 0
for jyun in itertools.permutations(range(N)):
    for i in range(N-1):
       dis += distance(zahyo[jyun[i]], zahyo[jyun[i+1]])
print(dis / math.factorial(N))

Solution (Python):
import math
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
tot = 0

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

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


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

  sum_ = 0
  for order in itertools.permutations(range(N)):
    for i in range(1, N):
      xi, yi = xy[order[i]][0], xy[order[i]][1]
      xj, yj = xy[order[i-1]][0], xy[order[i-1]][1]
      sum_ += math.sqrt((xi-xj)**2 + (yi-yj)**2)

  print(sum_ / math.factorial(N))


if(__name__ == '__main__'):
  main()

Solution (Python):
import math

n = int(input())
x = []
y = []
for i in range(n):
  a,b = map(int,input().split())
  x.append(a)
  y.append(b)
total = 1
for i in range(1,n+1):
  total*=i
  
length = []
for i in range(n-1):
  for s in range(1,n):
    if i<s:
      length.append(math.sqrt((x[i]-x[s])**2+(y[i]-y[s])**2))

h = (n-1)/len(length)
if n==2:
  print(sum(length))
else:
  print(h*sum(length))

Solution (Python):
from itertools import permutations

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

per_loop = permutations(range(n))
d = 0
cnt = 0
for t in per_loop:
    for i in range(1, n):
        d += ((x[t[i]]-x[t[i-1]])**2 + (y[t[i]]-y[t[i-1]])**2)**(0.5)
    cnt += 1

print(d / cnt)

Solution (Python):
import itertools
import math

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

p = itertools.permutations(xy, N)
ans = 0
for v in p:
    for i in range(N-1):
        ans += math.sqrt((v[i][0]-v[i+1][0])**2 + (v[i][1]-v[i+1][1])**2)
ans /= math.factorial(N)
print(ans)

Solution (Python):
n=int(input())
xy=[]
for i in range(n):
  xy_=list(map(int,input().split()))
  xy.append(xy_)
  
from itertools import permutations
import math
s=list(permutations(range(n)))
ans=0
for i in s:
  sum_r=0
  for j in range(n-1):
    r=math.sqrt((xy[i[j+1]][0]-xy[i[j]][0])**2+(xy[i[j+1]][1]-xy[i[j]][1])**2)
    sum_r+=r
    
  ans+=sum_r
  
  
print(ans/len(s))

Solution (Python):
import itertools
import math
n = int(input())                    
l = [list(map(int,input().split())) for i in range(n)]
x,y = [list(i) for i in zip(*l)]    
l = list(range(n))                  
z = list(itertools.permutations(l)) 
m = math.factorial(n)               
t = 0                               

for i in range(m):
    for j in range(n - 1):
        t += math.sqrt((x[z[i][j]] - x[z[i][j+1]]) ** 2 + (y[z[i][j]] - y[z[i][j+1]]) ** 2)

print(t / m)

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

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

total = 0
for pattern in permutations(xy):
    dis = 0
    for j in range(n - 1):
        dis += sqrt((pattern[j][0] - pattern[j + 1][0]) ** 2 + (pattern[j][1] - pattern[j + 1][1]) ** 2)
    total += dis

ans = total / len(list(permutations(xy)))
print(ans)

Solution (Python):
import itertools
import math

N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]
cnt = 0
tot = 0
for ptn in itertools.permutations(XY):
    now = ptn[0]
    cnt += 1
    for nex in ptn[1:]:
        tot += math.sqrt(pow(now[0]-nex[0], 2)+pow(now[1]-nex[1], 2))
        now = nex
print(tot/cnt)

Solution (Python):
import itertools
import math

N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]
cnt = 0
tot = 0
for arr in itertools.permutations(range(N)):
    now = XY[arr[0]]
    cnt += 1
    for i in arr[1:]:
        nex = XY[i]
        tot += math.sqrt(pow(now[0]-nex[0], 2)+pow(now[1]-nex[1], 2))
print(tot/cnt)

Solution (Python):
import numpy as np
n= int(input())
m = np.zeros((n,2))
sum1 = 0
count =0
for i in range(n):
    m[i] = list(map(int,input().split()))
for j in range(n):
    for k in range(j+1,n):
        sum1 = sum1 + ((m[j][0] - m[k][0])**2 + (m[j][1]-m[k][1])**2)**(1/2)
        count +=1

ans = 0

mul =1
for l in range(n):
    mul *= n-l
po =0
if n ==2:
    po = 1
elif n ==3:
    po =2
else:
    for m in range(n):
        po += m

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

Solution (Python):
import sys
import time
import math
import itertools as it
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()


N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
	x[i], y[i] = map(int, input().split()) 
ls = [i for i in range(N)]
ans = 0
cnt = 0
for pm in it.permutations(ls):
	cnt += 1
	sm = 0
	for i, j in zip(pm, pm[1:]):
		sm += ((x[i]-x[j])**2 + (y[i]-y[j])**2)**0.5
	ans += sm
print(ans/cnt)


ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)

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

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

print(d * (n - 1) / cnt)

Solution (Python):
import math

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

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

sum_dist = 0
cnt = 0
for i in range(N):
    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)
        cnt += 1

print(sum_dist * (N-1) / cnt)

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

ans=0
nn=math.factorial(n)*2/n
for y in range(0,n-1):
  for z in range(y+1,n):
    p=a[y][0]
    q=a[y][1]
    s=a[z][0]
    t=a[z][1]
    u=(p-s)*(p-s)+(q-t)*(q-t)
    r=math.sqrt(u)
    
    ans+=r*nn
    
print(ans/math.factorial(n))

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

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

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

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

ave = sum(map(sum, dist))/((n**2-n)//2)

print(ave*(n-1))

Solution (Python):
import math

N=int(input())
x=[0]*N; y=[0]*N;
for i in range(N):
  x[i],y[i]=map(int,input().split())
count=[0]*N
for j in range(N):
  for k in range(N):
    if(k!=j):
      count[j]+=math.sqrt((x[j]-x[k])**2+(y[j]-y[k])**2)
res=0
for l in range(N):
  res+=count[l]
print(res/N)

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


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


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    c = [0] * n
    for i in range(n):
        x, y = map(int, input().split())
        c[i] = (x, y)
    ans = 0
    for p in permutations(range(n)):
        for i in range(1, n):
            ans += distance(*c[p[i]], *c[p[i - 1]])
    ans /= math.factorial(n)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from itertools import permutations
import math
from functools import lru_cache


@lru_cache(maxsize=None)
def distance(x1, y1, x2, y2):
    return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    c = [0] * n
    for i in range(n):
        x, y = map(int, input().split())
        c[i] = (x, y)
    ans = 0
    for p in permutations(range(n)):
        for i in range(1, n):
            ans += distance(*c[p[i]], *c[p[i - 1]])
    ans /= math.factorial(n)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import itertools, math
N = int(input())
T = [list(map(int, input().split())) for i in range(N)]
d = 0
for l in itertools.permutations(range(N), N):
    for i in range(N - 1):
        d += math.sqrt((T[l[i]][0] - T[l[i + 1]][0]) ** 2 
        + (T[l[i]][1] - T[l[i + 1]][1]) ** 2)
print(d / math.factorial(N))

Solution (Python):


import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")

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

    ans = 0
    for i in range(N):
        xi,yi = XY[i]
        for j in range(i+1,N):
            xj,yj = XY[j]
            ans += ((xi-xj)**2 + (yi-yj)**2)**.5
    
    print(ans*2/N)

if __name__ == "__main__":
    main()

Solution (Python):
import math
from itertools import permutations
N = int(input())
C = [list(map(int, input().split())) for _ in range(N)]
perm = list(permutations(range(N)))
d = 0
for p in perm:
    for i in range(N - 1):
        d += math.sqrt((C[p[i]][0] - C[p[i + 1]][0]) ** 2 + (C[p[i]][1] - C[p[i + 1]][1]) ** 2)
print(d / len(perm))

Solution (Python):
from itertools import permutations 
s=""
n=int(input())
p=[]
for i in range(n):
    h,m=list(map(int,input().split()))
    p.append([h,m])
for i in range(n):
    s+=str(i+1)
a=[''.join(p) for p in permutations(s)] 
k=0
l=len(a)
import math
for i in range(l):
    z=0
    for j in range(n-1):
        x=int(a[i][j])-1
        y=int(a[i][j+1])-1
        z+=math.sqrt((p[x][0]-p[y][0])**2+(p[x][1]-p[y][1])**2)
    k+=z
        
print(k/l)

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    XY = [il() for _ in range(N)]

    ret = 0
    for x1, y1 in XY:
        for x2, y2 in XY:
            ret += calcTwoPointDistance(x1, y1, x2, y2)
    print(ret/N)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
from collections import defaultdict, deque
from itertools import permutations

n = int(input())
s, ps = [tuple(map(int, input().split())) for i in range(n)], list(permutations([i for i in range(1, n + 1)]))

def dist(i, j):
    x, y = s[i][0] - s[j][0], s[i][1] - s[j][1]
    return (x ** 2 + y ** 2) ** 0.5

print(sum(sum(dist(p[i]-1, p[i+1]-1) for i in range(n-1)) for p in ps) / len(ps))

Solution (Python):
import math

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

num_nodes = n * (n - 1)
num_node_sel_total = math.factorial(n) * (n - 1)
num_node_sel = num_node_sel_total / num_nodes

ans = 0
for src in range(n):
    for dst in range(n):
        if src != dst:
            (src_x, src_y) = pts[src]
            (dst_x, dst_y) = pts[dst]
            d = math.sqrt((dst_x - src_x) ** 2 + (dst_y - src_y) ** 2)
            ans += d * num_node_sel
print(ans/math.factorial(n))

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

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

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

A = np.array(A)

L = list(it.permutations(range(0,N)))

distance = 0

for i in range (0, len(L)):
    for j in range (1, N):
        distance+=math.sqrt((A[L[i][j]][1]-A[L[i][j-1]][1])**2+(A[L[i][j]][0]-A[L[i][j-1]][0])**2)

print(distance/math.factorial(N))

Solution (Python):







import itertools
import math

import sys

def input(): return sys.stdin.readline().rstrip()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]

def OutH(lst, deli=' '): print(deli.join(map(str, lst)))
def OutV(lst): print('\n'.join(map(str, lst)))

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)


N = iIn()
XY = iInLD(N)

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

ssum = 0
for i in range(len(lst)):
    for j in range(1,N):
        pre_x = XY[lst[i][j-1]][0]
        pre_y = XY[lst[i][j-1]][1]
        post_x = XY[lst[i][j]][0]
        post_y = XY[lst[i][j]][1]
        ssum += ((post_x - pre_x)**2 + (post_y - pre_y)**2)**0.5

ans = ssum / len(lst) * 1.0
print(ans)

Solution (Python):
from itertools import permutations
N = int(input())
cc = []
dd = []
for i in range(N):
  aa = list(map(int,input().split()))
  cc.append(aa)
  dd.append(i)
ee = []
for i in permutations(dd):
  add = 0
  count = 0
  for j,k in enumerate(i):
    add += ((cc[k][0]-cc[i[j+1]][0])**2 + (cc[k][1]-cc[i[j+1]][1])**2)**0.5
    count += 1
    if count == N-1:
      break
  ee.append(add)
ff = 1
for i in range(1,N+1):
  ff *= i
print(sum(ee)/ff)

Solution (Python):
import sys

input = sys.stdin.readline

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


def main():
    ans = 0
    N = int(input())
    l = [list(map(int, input().split())) for _ in range(N)]
    r = []
    for i in range(N-1):
        for j in range(i+1, N):
            r.append(calc(l[i], l[j]))
    ans = sum(r)*2/N
    print(f'{ans:.8f}')

if __name__ == '__main__':
    main()

Solution (Python):
import itertools

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
citys = [i for i in range(n)]
roots = list(itertools.permutations(citys))

sum = 0
for root in roots:
    for i in range(n-1):
        sum += ((xy[root[i]][0] - xy[root[i+1]][0])**2 + (xy[root[i]][1] - xy[root[i+1]][1])**2)**(0.5)


print(sum/len(roots))

Solution (Python):
import itertools
n=int(input())
xy=[list(map(int,input().split())) for i in range(n)]
factorial=list(itertools.permutations(list(range(n))))
result=[]
for i in range(len(factorial)):
    distance=0
    for j in range(n-1):
        distance+=((xy[factorial[i][j+1]][0]-xy[factorial[i][j]][0])**2+(xy[factorial[i][j+1]][1]-xy[factorial[i][j]][1])**2)**(1/2)
    result.append(distance)
print(sum(result)/len(result))

Solution (Python):
import sys
import math
import itertools
import statistics
n=int(input())
xy=[]
for _ in range(n):
    xy.append(list(map(int,input().split())))
lis=list(range(n))
per_lis = itertools.permutations(lis)
dis_lis=[]
for one_case in per_lis:
    dis=0
    for i in range(n-1):
        ind=one_case[i]
        stx=xy[ind][0]
        sty=xy[ind][1]
        inde=one_case[i+1]
        gox=xy[inde][0]
        goy=xy[inde][1]
        
        X = (stx-gox)**2
        Y = (sty-goy)**2

        dis += math.sqrt(X+Y)
    dis_lis.append(dis)
print(statistics.mean(dis_lis))

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

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
basho = [LI() for _ in range(N)]
keiros = list(itertools.permutations(range(1,N+1)))
nagasa = []

for keiro in keiros:
    
    diff = 0
    for i in range(1,len(keiro)):
        
        diff += (((basho[keiro[i]-1][0] - basho[keiro[i-1]-1][0]) ** 2) + ((basho[keiro[i]-1][1] - basho[keiro[i-1]-1][1]) ** 2)) ** 0.5
        
    nagasa.append(diff)

num = np.array(nagasa)
print(np.average(num))

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

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
basho = [LI() for _ in range(N)]
keiros = list(itertools.permutations(range(1,N+1)))
nagasa = []

for keiro in keiros:
    
    diff = 0
    for i in range(1,len(keiro)):
        
        diff += (((basho[keiro[i]-1][0] - basho[keiro[i-1]-1][0]) ** 2) + ((basho[keiro[i]-1][1] - basho[keiro[i-1]-1][1]) ** 2)) ** 0.5
        
    nagasa.append(diff)

num = np.array(nagasa)
print(np.average(num))

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


def TotalDis(L):
    D = 0
    for i in range(len(L) - 1):
        Xi, Yi = L[i]
        Xj, Yj = L[i+1]
        D += math.sqrt((Xj-Xi)**2 + (Yj-Yi)**2)
    return D


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

SumDis = 0
for l in itertools.permutations(P):
    SumDis += TotalDis(l)
ans = SumDis/math.factorial(N)

print(ans)

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

def dist(A,B):
    p=A[0]-B[0]
    q=A[1]-B[1]
    return sqrt(p*p+q*q)

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

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

T=permutations(P,N)

D=0
for H in T:
    S=0
    for k in range(N-1):
        S+=dist(H[k],H[k+1])
    D+=S
print(D/f(N))

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

Solution (Python):
import itertools
import math
import copy
n = int(input())
x_y= [list(map(int,input().split())) for X in range(n)]


n_sum = math.factorial(n)

n_list = list(itertools.permutations(x_y,n))
ans = 0

for i in range(len(n_list)):
	
	
	tmp = copy.copy(n_list[i])
	for j in range(n-1):
		ans += math.sqrt((tmp[j][0] - tmp[j+1][0])**2 + ((tmp)[j][1] - tmp[j+1][1])**2)
print('{:.10f}'.format((ans/n_sum)))