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())
p = [[0 for i in range(2)] for j in range(n)]

for i in range(n):
  p[i][0],p[i][1] = map(int,input().split())


def dis(a,b):
  dis = (a[0]-b[0]) ** 2 + (a[1]-b[1]) **2
  return dis ** (1/2)


perm = [i for i in range(n)]
total = 0 
num = 0
for v in itertools.permutations(perm,n):
  path = 0
  for i in range(n-1):
    path += dis(p[v[i]],p[v[i+1]])
  num += 1
  total += path
print(total/num)

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
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())
def main():
    n = I()
    lst = [None, ]
    for _ in range(n):
        x, y = LI()
        lst.append((x,y))

    per = itertools.permutations(range(1,n+1))
    sm = 0
    oc = math.factorial(n)
    for p in per:
        dist = 0
        before = p[0]
        for place in p[1:]:
            dist += math.sqrt((lst[place][0]-lst[before][0])**2 + (lst[place][1]-lst[before][1])**2)
            before = place
        sm += dist
    ans = sm/oc
    print(ans)
main()

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

def dis(x):
    c=0
    for i in range(N-1):
        aa=arr[x[i]][0]-arr[x[i+1]][0]
        bb=arr[x[i]][1]-arr[x[i+1]][1]
        c+=(aa**2+bb**2)**(0.5)
    return c
 
count=0
ans=0
for i in permutations(range(0,N),N):
    count+=1
    ans+=dis(i)

print(ans/count)

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

Solution (Python):
import itertools
import math

n=int(input())
xy=[[int(i) for i in input().split()] for _ in range(n)]
p = itertools.permutations(range(n),n)

lenlist=[]
for v in p:
    len=0
    for i in range(n-1):
        len +=  ( (xy[v[i+1]][0]-xy[v[i]][0])**2 + (xy[v[i+1]][1]-xy[v[i]][1])**2 )**0.5
    lenlist.append(len)

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

Solution (Python):
import itertools
n = int(input())
s = ([str(_) for _ in range(n)])
l = list(itertools.permutations(s, n))
x = []
y = []
for i in range(n):
    xi,yi = map(int,input().split())
    x.append(xi)
    y.append(yi)
c = 0.0
for j in l:
    for k in range(n-1):
        c += ((x[int(j[k])]-x[int(j[k+1])])**2 + (y[int(j[k])]-y[int(j[k+1])])**2)**0.5
print(c/len(l))

Solution (Python):
import itertools

n = int(input())

town = []

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

cnt = 0
length = 0

for t in itertools.permutations(town):
    for i in range(n-1):
        x = (t[i][0]-t[i+1][0])**2
        y = (t[i][1]-t[i+1][1])**2
        length += (x+y)**0.5
    cnt += 1

print(length/cnt)

Solution (Python):
import itertools
n = int(input())
s = "".join([str(_) for _ in range(n)])
l = list(itertools.permutations(s, n))
x = []
y = []
for i in range(n):
  xi,yi = map(int,input().split())
  x.append(xi)
  y.append(yi)
c = 0.0
for j in l:
  for k in range(n-1):
    c += ((x[int(j[k])]-x[int(j[k+1])])**2 + (y[int(j[k])]-y[int(j[k+1])])**2)**0.5
print(c/len(l))

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

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

from collections import defaultdict
dist = defaultdict(int)

import itertools
for perm in itertools.permutations(range(N), 2):
  x1,y1 = cities[perm[0]]
  x2,y2 = cities[perm[1]]
  dist[perm] = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5

ans = 0
cnt = 0
for perm in itertools.permutations(range(N), N):
  cnt += 1
  for i in range(1 ,len(perm)):
    ans += dist[(perm[i - 1], perm[i])]

print(ans / cnt)

Solution (Python):
import numpy as np
N = int(input())
xy = [list(map(int, input().split(" "))) for i in range(N)]

L = 0
for i in range( N ):
 for j in range( N ):
  a = xy[i][0]-xy[j][0]
  b = xy[i][1]-xy[j][1]
  l = np.sqrt( a**2 +b**2)
  L += l

print(L/N)

Solution (Python):
from itertools import permutations

n = int(input())
v = [list(map(int,input().split())) for i in range(n)]
ans = 0
c = 0
for p in permutations(range(n)):
    c += 1
    arr = [i for i in p]
    for i in range(n-1):
        ans += ((v[arr[i]][0]-v[arr[i+1]][0])**2 + (v[arr[i]][1]-v[arr[i+1]][1])**2)**0.5
ans /= c
print(ans)

Solution (Python):
import math
import itertools
n = int(input())
al = [0] * n
bl = [0] * n
for i in range(n):
    al[i], bl[i] = map(int, input().split())
bunbo = math.factorial(n)
ans = 0
for p in itertools.permutations(list(range(n))):
    for i in range(n-1):
        ans += ((al[p[i+1]]-al[p[i]])**2+(bl[p[i+1]]-bl[p[i]])**2)**0.5
print(ans/bunbo)

Solution (Python):
import itertools
N = int(input())
N_List = [list(map(int,input().split())) for _ in range(N)]
ans = 0
cnt = 0
for Sort_List in itertools.permutations(N_List, N):
    cnt += 1
    cans = 0
    for v in range(1,N):
        cans += ((Sort_List[v][0] - Sort_List[v-1][0])**2 + (Sort_List[v][1] - Sort_List[v-1][1])**2)**0.5
    ans += cans

print(ans/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)

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

def D(a,b):
    a=a-1
    b=b-1
    return ((x[a]-x[b])**2+(y[a]-y[b])**2)**(0.5)

def f(x):
    ans=0
    while x>0:
        ans+=x%2
        x=x//2
    return ans

def r(x):
    ans=1
    for i in range(x):
        ans*=(i+1)
    return ans

dp=[[0]*(n+1) for _ in range(2**n)]
for i in range(1,2**n):
    for j in range(1,n+1):
        for k in range(1,n+1):
            if (i>>(j-1))&1 and not (i>>(k-1)&1):
                dp[i+2**(k-1)][k]+=dp[i][j]+r((f(i)-1))*D(j,k)

print(sum(dp[2**n-1])/p)

Solution (Python):
def f(n):
    if n == 1:
        return 1
    else:
        return n * f(n - 1)

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

total = 0
for i in range(n):
    for j in range(n):
        total += ((X[i] - X[j])**2 + (Y[i] - Y[j])**2)**0.5

print(total/n)

Solution (Python):
import itertools
import math

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

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

ans = 0
for p in itertools.permutations(xy):
  for i in range(n-1):
    ans += dist(*p[i], *p[i+1])

print(ans/math.factorial(n))

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


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

    for p in permutations(range(n), n):
        dist = 0
        for i in range(len(p) - 1):
            dist += (abs(xy[p[i]][0] - xy[p[i + 1]][0]) ** 2 +
                     abs(xy[p[i]][1] - xy[p[i + 1]][1]) ** 2) ** 0.5
        ans += dist

    ans /= factorial(n)

    print(f"{ans:.12f}")


if __name__ == "__main__":
    main()

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

Solution (Python):
from itertools import permutations as p
from math import factorial as f
from math import sqrt as s

def func(x1, x2, y1, y2): return s((x2-x1) ** 2 + (y2-y1) ** 2)

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

total = 0

for l in p(range(1, N+1)):
  for i in range(N-1):
    total += func(xy[l[i]-1][0], xy[l[i+1]-1][0], xy[l[i]-1][1], xy[l[i+1]-1][1])

print(total / f(N))

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

Solution (Python):
N = int(input())
P = []
for i in range(N):
    s = [int(i) for i in input().split()]
    P.append(s)
L = []
for i in range(N-1):
    for j in range(i+1, N):
        l = (P[i][0] - P[j][0])**2 + (P[i][1] - P[j][1])**2
        L.append(l**0.5)
S = sum(L)
print(2*S/N)

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

perm= math.factorial(n)
s = 0

M=[]
for v in itertools.permutations(L, n):
    M.append(list(v))


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

Solution (Python):
import itertools

n = int(input())

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

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

p_list = list(itertools.permutations(p))

s = 0

for x in p_list:
    for y in range(n-1):
        s += how_far(x[y],x[y+1])

print(s/len(p_list))

Solution (Python):
from itertools import permutations
n = int(input())
x = []
y = []
ans,count,tempx,tempy = 0,0,0,0
for _ in range(n):
    a,b = map(int,input().split())
    x.append(a)
    y.append(b)
order = list(permutations(range(n)))
for i in order:
    for j in i:
        if j == i[0]:
            tempx = x[j]
            tempy = y[j]
            continue
        count += (((x[j]-tempx)**2)+((y[j]-tempy)**2)) ** (0.5) 
        tempx = x[j]
        tempy = y[j]
    ans += count / len(order)
    count = 0
print(ans)

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

Solution (Python):
import itertools,math
n = int(input())
points = [list(map(int,input().split())) for _ in range(n)]
roots = list(itertools.permutations(points))
ans = 0
for root in roots:
    for i in range(n-1):
        ans += math.sqrt(pow(root[i+1][0] - root[i][0],2) + pow(root[i+1][1] - root[i][1],2))
ans /= len(roots)
print(ans)

Solution (Python):





def resolve():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip())

    cities = [[int(x) for x in input().rstrip().split(" ")] for _ in range(n)]
    import math

    import itertools

    length_list = []
    p = itertools.permutations(list(range(n)), n)
    for v in p:
        length = 0
        for city_i in range(n - 1):
            city1 = cities[v[city_i]]
            city2 = cities[v[city_i + 1]]
            length += math.sqrt((city1[0] - city2[0]) ** 2 + (city1[1] - city2[1]) ** 2)

        length_list.append(length)

    print(sum(length_list) / len(length_list))


if __name__ == "__main__":
    resolve()

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

Solution (Python):
import itertools
import math

n = int(input())
x = []
num = []
for i in range(n):
  x.append([int(t) for t in input().split()])
  num.append(i)

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

Solution (Python):
from itertools import permutations

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

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

d = 0
cnt = 0
for per in permutations(list(range(n)), n):
    cnt += 1
    for i in range(n-1):
        a = xy[per[i]]
        b = xy[per[i+1]]
        d += distance(a, b)

print(d/cnt)

Solution (Python):
import math
import itertools

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

    ans = 0
    for order in itertools.permutations(list(range(N)), N):
        d = 0
        for i in range(N-1):
            s, e = order[i], order[i+1]
            d += math.sqrt((towns[s][0] - towns[e][0]) ** 2 + (towns[s][1] - towns[e][1]) ** 2)
        ans += d / math.factorial(N)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import math

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

root = {}
for i in range(n-1):
    ix, iy = xy[i][0], xy[i][1]
    for j in range(i+1, n):
        jx, jy = xy[j][0], xy[j][1]
        root[(i, j)] = ((ix-jx)**2+(iy-jy)**2)**(1/2)

long = 0
for i in itertools.permutations([i for i in range(n)]):
    for j in range(1, len(i)):
        long += root[tuple(sorted([i[j-1], i[j]]))]
print(long/math.factorial(n))

Solution (Python):
from itertools import combinations

import math
N = int(input())

x = []
y = []

for i in range(N):
    _x, _y = map(int, input().split())
    x.append(_x)
    y.append(_y)
    
s = 0
for c in combinations(zip(x, y), 2):
    s += math.sqrt((c[0][0] - c[1][0]) ** 2 + (c[0][1] - c[1][1]) ** 2)

print(s * 2 / N)

Solution (Python):
import math
import itertools

N = int(input())
L = []
cnt = 0

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

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

print(cnt / math.factorial(N))

Solution (Python):
import math
n = int(input())
nn = 1
xl = []
yl = []
ll = 0
for i in range(n):
    x,y = map(int, input().split())
    xl.append(x)
    yl.append(y)
 
j = 0
while j < n-1:
    k = j+1
    while k <= n-1:
        ll += math.sqrt((xl[j]-xl[k])**2 + (yl[j] - yl[k])**2)
        k += 1
    j += 1
 
print(ll*2/n)

Solution (Python):
from itertools import permutations

N = int(input())
XY = [0 for _ in range(N)]
for i in range(N):
  xy = list(map(int,input().split()))
  XY[i] = xy
  
nums =[i for i in range(N)]
pers = permutations(nums,N)
distance = 0
count = 0
for i in pers:
  count += 1
  for j in range(N-1):
    distance += ((XY[i[j]][0]-XY[i[j+1]][0])**2 + (XY[i[j]][1]-XY[i[j+1]][1])**2)**0.5
    
print(distance/count)

Solution (Python):
import math

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

def recursive(pos):
    if len(pos) == 1:
        return 0
    dist = 0
    for p in range(len(pos) - 1):
        dist += distance(pos[0], pos[p + 1])
    dist += recursive(pos[1:])
    return dist

N = int(input())
pos = []
for i in range(int(N)):
    p = input().split(" ")
    pos.append([int(p[0]), int(p[1])])

print(recursive(pos) * 2 / N)

Solution (Python):
N = int(input())
def length(a,b):
    return ((a[0]-b[0])**2 + (a[1]-b[1])**2)**(1/2)
p = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        ans += length(p[i],p[j])
print(ans*2/N)

Solution (Python):
N = int(input())
def length(a,b):
    return ((a[0]-b[0])**2 + (a[1]-b[1])**2)**(1/2)
p = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        ans += length(p[i],p[j])
print(ans*2/N)

Solution (Python):


import sys
import itertools
import math

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

for i in range(n):
    arr=list(map(int,input().split()))
    point.append(arr)
ans=[]
l = [i for i in range(n)]

for v in itertools.permutations(l, n):
    dist=0
    for j in range(len(v)-1):
        dist+=math.sqrt(math.pow((point[v[j]][0]-point[v[j+1]][0]),2)+math.pow((point[v[j]][1]-point[v[j+1]][1]),2))
    ans.append(dist)
print(sum(ans)/len(ans))

Solution (Python):


import math
import itertools

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

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

p = itertools.permutations(range(n))
tmp_n = n
num_p = 1
while tmp_n > 1:
    num_p *= tmp_n
    tmp_n -= 1
res = 0
for perm in p:
    for i in range(n-1):
        dist = distance[perm[i]][perm[i+1]]
        res += dist / num_p

print(res)

Solution (Python):

"""
Created on Wed Sep  9 02:04:12 2020

@author: liang
"""
import math

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

lis = list(range(N))
num = list()
perm_list = list()

def make_perm():
    if len(num) == N:
        perm_list.append(num.copy())
    for n in lis:
        a = lis.pop(0)
        num.append(a)
        make_perm()
        num.pop()
        lis.append(a)
        
make_perm()

res = 0
for nums in perm_list:
    tmp = 0
    for i in range(N-1):
        tmp += math.sqrt((d[nums[i]][0]-d[nums[i+1]][0])**2 + (d[nums[i]][1] - d[nums[i+1]][1])**2)
    res += tmp
print(res/len(perm_list))

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





avg = 0
permutations = list(itertools.permutations(range(N)))
for l in permutations:
  for i in range(len(l)-1):
    avg += math.sqrt((xy[l[i+1]][0] - xy[l[i]][0])**2 + (xy[l[i+1]][1] - xy[l[i]][1])**2)

avg /= len(permutations)
print(avg)

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

avg /= len(permutations)
print(avg)

Solution (Python):
import math
n = int(input())
nn = 1
xl = []
yl = []
ll = 0
for i in range(n):
    x,y = map(int, input().split())
    xl.append(x)
    yl.append(y)

j = 0
while j < n-1:
    k = j+1
    while k <= n-1:
        ll += math.sqrt((xl[j]-xl[k])**2 + (yl[j] - yl[k])**2)
        k += 1
    j += 1

print(ll*2/n)

Solution (Python):
import math
import itertools


def calc_digit_sum(num):
    digits = sums = 0
    while num > 0:
        digits += 1
        sums += num % 10
        num //= 10
    return digits, sums


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

total = 0
routes = list(itertools.permutations(range(n), n))
for route in routes:
    distance = 0
    for index in range(len(route)-1):
        idx1 = route[index]
        idx2 = route[index+1]
        distance += math.sqrt((distances[idx1][0] - distances[idx2][0]) ** 2 + (distances[idx1][1] - distances[idx2][1]) ** 2)
    total += distance

print(total / len(routes))

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

sm=0

for i in itertools.permutations(A):
    for j in range(1,N):
        sm+=(abs(i[j-1][0]-i[j][0])**2+abs(i[j-1][1]-i[j][1])**2)**0.5

print(sm/math.factorial(N))

Solution (Python):
def main():
    import sys
    readline = sys.stdin.buffer.readline

    import math
    import itertools

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

    c = list(itertools.combinations(range(n), 2))
    ans = 0
    for a, b in c:
        ans += ((xy[a][0] - xy[b][0])**2 + (xy[a][1] - xy[b][1])**2)**(1/2)
    print(ans*2*math.factorial(n-1)/math.factorial(n))

if __name__ == '__main__':
    main()

Solution (Python):
import math
from decimal import Decimal
import itertools

N = int(input())
x, y = [0] * N, [0] * N
per = list(itertools.permutations(range(1, N+1)))
for i in range(N):
  x[i], y[i] = map(int, input().split())
dis = 0
for lis in per:
  for j in range(1, len(lis)):
    k = lis[j]
    l = lis[j-1]
    dis += math.sqrt((x[l-1] - x[k-1])**2 + (y[l-1] - y[k-1])**2)
fac = math.factorial(N)
print(dis/fac)

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

def dfs(current, dist, already):
    if len(already) == N:
        return dist
    d = 0
    for i in range(N):
        if i in already:
            continue
        d += dfs(i, dist + math.sqrt((town[current][0] - town[i][0]) ** 2 + (town[current][1] - town[i][1]) ** 2), already | set([i]))
    return d
answer = 0
for i in range(N):
    answer += dfs(i, 0, set([i]))
print(answer / math.factorial(N))

Solution (Python):
import math
def dis(x1,y1,x2,y2):
    return(((x1-x2)**2+(y1-y2)**2)**(1/2))

N = int(input())
cord = []
tem = 0

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

for i in range(N):
    x1,y1 = cord[i]
    for j in range(0,i):
        x2,y2 = cord[j]
        tem += dis(x1,y1,x2,y2)    
    for j in range(i+1,N):
        x2,y2 = cord[j]
        tem += dis(x1,y1,x2,y2)

print(tem*math.factorial(N-1)/math.factorial(N))

Solution (Python):


import math

def solver(visited, coord, depth = 0):
  dists = []

  if len(visited) == depth:
    for i in range(1, len(visited)):
      x1, y1 = coord[visited[i - 1]][0], coord[visited[i - 1]][1]
      x2, y2 = coord[visited[i]][0], coord[visited[i]][1]
      dists.append(math.sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)))
    return sum(dists)

  for i in range(0, len(visited)):
    if visited[i] != -1: continue
    visited[i] = depth
    dists.append(solver(visited, coord, depth + 1))
    visited[i] = -1;

  return sum(dists)

def main():
  n = int(input())
  coord = []
  for i in range(0, n):
    coord.append([int(c) for c in input().split()])

  print(solver([-1 for i in range(0, n)], coord) / math.factorial(n))

if __name__ == "__main__":
  main()

Solution (Python):
N = int(input())
ct = []
 
for i in range(N):
  ct.append([int(i) for i in input().split()])
 
dist = 0
for a in ct:
  for b in ct:
    dist += (abs(a[0] - b[0])**2 +abs(a[1] - b[1])**2)**0.5
print(dist/N)

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

from itertools import permutations
import math
m = math.factorial(n)
per = permutations(xy,n)

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

print(d/m)

Solution (Python):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

import itertools, math

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

def do():
    xs=[]
    ys=[]
    per=[]
    n=INT()
    ans=0
    for i in range(n):
        x,y=INTM()
        xs.append(x)
        ys.append(y)
        per.append(i)
    
    for i in itertools.permutations(per, n):
        for k in range(n-1):
            ans+=distance(xs[i[k]],ys[i[k]],xs[i[k+1]],ys[i[k+1]])
        
    
    print(ans/math.factorial(n))

    
if __name__=='__main__':
    do()

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

xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]
l = 0

for j in range(N):
    for k in range(N):
        if j >= k:
            continue
        l += math.sqrt((x[j] - x[k])**2 + (y[j] - y[k]) ** 2)

print(l * 2/N)

Solution (Python):
from itertools import permutations
import math

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

l = list(permutations(XY, N))
sum = 0
for i in l:
    d = 0
    for j in range(len(i)-1):
        d += math.sqrt((i[j][0] - i[j+1][0]) ** 2 + (i[j][1] - i[j+1][1]) ** 2)
    sum += d
print(sum/len(l))

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

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

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

for i in range(N):
  ct.append([int(i) for i in input().split()])

dist = 0
for a in ct:
  for b in ct:
    dist += (abs(a[0] - b[0])**2 +abs(a[1] - b[1])**2)**0.5
print(dist/N)

Solution (Python):
from itertools import permutations

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

sum = 0
cnt = 0
for i in permutations(xy):
    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
    cnt += 1
print(sum / cnt)

Solution (Python):
import itertools

N = int(input())
cities = [list(map(int, input().split())) for _ in range(N)]
patterns = itertools.permutations(cities, N)
result = 0
count = 0
for ptn in patterns:
  count += 1
  dis = 0
  for i in range(N-1):
    dis += ((ptn[i][0]-ptn[i+1][0])**2 + (ptn[i][1]-ptn[i+1][1])**2)**0.5
  result += dis
print(result/count)

Solution (Python):
def dist(x, y, i, j):
    dx = x[i] - x[j]
    dy = y[i] - y[j]
    return (dx * dx + dy * dy) ** 0.5

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

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

ans = 0
for i in range(n):
    for j in range(i + 1, n):
       ans += dist(x, y, i, j) * 2 / n

print(ans)

Solution (Python):
from itertools import permutations
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]

ans = 0
t = 0
for i in permutations(xy, n):
  t += 1
  for j in range(n-1):
    ans += ((i[j][0] - i[j+1][0])**2 + (i[j][1] - i[j+1][1])**2)**0.5
print(ans/t)

Solution (Python):
import itertools
import math

n = int(input())


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


per_list = []
for j in itertools.permutations([x for x in range(n)]) :
    per_list.append(j)


d = 0
for k in per_list :
    for l in range(n - 1) :
        d += math.sqrt((xy_list[k[l + 1]][0] - xy_list[k[l]][0]) ** 2 + (xy_list[k[l + 1]][1] - xy_list[k[l]][1]) ** 2)
        
print(d/(len(per_list)))

Solution (Python):
import itertools as it
import math
def Dist (x1,y1,x2,y2):
    dis = (x2 - x1)**2 + (y2 - y1)**2
    return math.sqrt(dis)
N = int(input())
Pos = []
res = 0
for i in range(N):
    pos = list(map(int,input().split()))
    Pos.append(pos)
array = list(it.permutations(i for i in range(N)))
for i in range(math.factorial(N)):
    for j in range(N-1):
        res += Dist(Pos[array[i][j]][0],Pos[array[i][j]][1],Pos[array[i][j+1]][0],Pos[array[i][j+1]][1])
print(res / math.factorial(N))

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

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

Solution (Python):
import math
import itertools

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

ans=cnt=0
for i in itertools.permutations([_ for _ in range(n)]):
  for j in range(n-1):
    x1,x2=d[i[j]][0],d[i[j+1]][0]
    y1,y2=d[i[j]][1],d[i[j+1]][1]
    ans+=math.sqrt((x1-x2)**2+(y1-y2)**2)
  cnt+=1
  
print(ans/cnt)

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

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

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    X=[0]*N
    Y=[0]*N
    d=[[0]*N for _ in range(N)]
    for i in range(N):
        X[i],Y[i]=MI()
        
    for i in range(N):
        for j in range(N):
            dx=X[i]-X[j]
            dy=Y[i]-Y[j]
            d[i][j]=(dx**2 + dy**2)**0.5
            
    import itertools
    
    ans=0
    for ite in itertools.permutations(range(N), N):
        now=ite[0]
        for i in range(1,N):
            nxt=ite[i]
            ans+=d[nxt][now]
            now=nxt
    M=1
    for i in range(1,N+1):
        M*=i
    ans=ans/M
    print(ans)
            

main()

Solution (Python):
import itertools

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

L = [i for i in range(N)]

sum = 0
LL = list(itertools.permutations(L))
for v in LL:
  x, y = xy[v[0]]
  for u in v[1:]:
    x2, y2 = xy[u]
    sum += ((x2 - x) ** 2 + (y2 - y) ** 2) ** 0.5
    x, y = x2, y2
  
ave = sum / len(LL)
print(ave)

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

Solution (Python):
import math
N = int(input())
xy = []
l = []
def comb(n,k):
  if n < k:
    n, K = k, N
  nu = 1
  de = 1
  for i in range(k):
    nu *= (N - i)
    de *= (K-i)
  return nu // de

for i in range(N):
  xy.append(list(map(int, input().split())))
for i in range(N-1):
  for j in range(i+1,N):
    l.append(math.sqrt((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1]) ** 2))

nu = math.factorial(N-2) * (N - 1) * 2
de = math.factorial(N)
ans = sum(l) * nu / de
print(ans)