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


from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys
import numpy as np

INF = float('inf')


def solve(N: int, x: "List[int]", y: "List[int]"):
    def distance(x1, y1, x2, y2):
        return np.linalg.norm(np.array([x1, y1]) - np.array([x2, y2]))

    l = [[distance(x[i], y[i], x[j], y[j]) if j >
          i else 0 for j in range(N)] for i in range(N - 1)]

    return np.average([sum(l[r[i]][r[i+1]] if r[i] < r[i+1] else l[r[i+1]][r[i]] for i in range(N-1))
                       for r in its.permutations(range(N))])


def main():

    sys.setrecursionlimit(10 ** 6)

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


if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import math

N=int(input())
X=[]
Y=[]
s=0
l=[int(x) for x in range(N)]
L = list(itertools.permutations(l, N))
for i in range(N):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
for i in range(math.factorial(N)):
    for j in range(N-1):
        s+=((X[L[i][j]]-X[L[i][j+1]])**2+(Y[L[i][j]]-Y[L[i][j+1]])**2)**0.5
print(s/(math.factorial(N)))

Solution (Python):
import itertools
import math

N=int(input())
X=[]
Y=[]
s=0
l=[int(x) for x in range(N)]
L = list(itertools.permutations(l, N))
for i in range(N):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
for i in range(math.factorial(N)):
    for j in range(N-1):
        s+=((X[L[i][j]]-X[L[i][j+1]])**2+(Y[L[i][j]]-Y[L[i][j+1]])**2)**0.5
print(s/(math.factorial(N)))

Solution (Python):
import itertools

N = int(input())
c = []
d = 0


for i in range(N):
  x1, y1 = map(int, input().split())
  c.append((x1,y1))
  
cp = list(itertools.permutations(c))
x = len(cp)

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

Solution (Python):
def abc145c_average_length():
    import itertools
    import math
    n = int(input())
    x = []
    y = []
    for _ in range(n):
        a, b = map(int, input().split())
        x.append(a)
        y.append(b)
    result = 0
    cnt = 0
    for p in itertools.permutations(range(n)):
        total = 0
        for i in range(n-1):
            total += math.sqrt(pow(x[p[i]]-x[p[i+1]], 2)+pow(y[p[i]]-y[p[i+1]], 2))
        result += total
        cnt += 1
    print(result/cnt)
abc145c_average_length()

Solution (Python):
import itertools
import math

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

S = 0
for P in itertools.permutations(range(N)):
    for i in range(N-1):
        s, t = P[i+1], P[i]
        S += math.sqrt((town[s][0]-town[t][0]) ** 2 + (town[s][1]-town[t][1]) ** 2)

for i in range(1,N+1):
    S /= i

print(S)

Solution (Python):
import itertools
import math

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

S = 0
for P in itertools.permutations(range(N)):
    for i in range(N-1):
        s, t = P[i+1], P[i]
        S += math.sqrt((town[s][0]-town[t][0]) ** 2 + (town[s][1]-town[t][1]) ** 2)

for i in range(1,N+1):
    S /= i

print(S)

Solution (Python):

import sys
import itertools
import math
def input():
    return sys.stdin.readline()[:-1]

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

    l = [i for i in range(N)]
    p = [i for i in itertools.permutations(l, N)]
    d = 0
    for i in range(len(p)):
        t = p[i]
        for j in range(N - 1):
            d += math.sqrt(((x[t[j]] - x[t[j + 1]]) ** 2) + ((y[t[j]] - y
            [t[j + 1]])) ** 2)
    ans = d / math.factorial(N)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import math

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

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

ans = 0

for v in itertools.permutations(l):
    s = 0
    for i in range(n-1):
        s += d(v[i], v[i+1])
    ans += s

print(ans / math.factorial(n))

Solution (Python):
import itertools,math
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())
seq=[]
for i in range(N):
    seq.append(i)
    
l=list(itertools.permutations(seq))

num=0
for i in l:
    for u in range(1,len(i)):
        num+=math.sqrt((x[i[u-1]]-x[i[u]])**2+(y[i[u-1]]-y[i[u]])**2)
print(num/len(l))

Solution (Python):
import itertools

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

LIS = [i for i in range(n)]

big_lis = list(itertools.permutations(LIS))
L = len(big_lis)


def sai(i, j):
    return (lis[A[i + 1]][j] - lis[A[i]][j]) ** 2


keep = 0
ANS = 0
for i in range(L):
    A = list(big_lis[i])
    keep = 0
    for j in range(n - 1):
        keep += (sai(j, 0) + sai(j, 1)) ** (1 / 2)
    ANS += keep
print(ANS / L)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    N = int(readline())
    mat = []
    s = 0

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

    for per in permutations(range(N)):
        for i in range(N - 1):
            x1, y1 = mat[per[i]]
            x2, y2 = mat[per[i + 1]]
            s += ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5

    print(s / factorial(N))


if __name__ == '__main__':
    main()

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

s = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        s += ((town[i][0] - town[j][0])**2 + (town[i][1] - town[j][1])**2)**0.5

print(s / N)

Solution (Python):
import itertools
N = int(input())
z = []
for i in range(N):
  x,y = map(int,input().split())
  z.append((x,y))
ALL = 1
for i in range(N):
  ALL *= (i+1)
base = [i for i in range(N)]
A = list(itertools.permutations(base,N))
SUM = 0

def distance(a,b):
  ax = a[0]; ay = a[1]
  bx = b[0]; by = b[1]
  dis = ((ax-bx)**2 + (ay-by)**2)**(0.5)
  return dis

for X in A:
  now = z[X[0]]
  for i in range(1,N):
    nxt = z[X[i]]
    dif = distance(now,nxt)
    
    SUM += dif

ans = SUM/ALL
print(ans)

Solution (Python):

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

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

    ans = 0
    for can_move in combinations(xy, 2):
        xi, yi = can_move[0]
        xj, yj = can_move[1]
        ans += sqrt((xi - xj) ** 2 + (yi - yj) ** 2)
    print(f'{ans * 2 / N:.10f}')


if __name__ == '__main__':
    main()

Solution (Python):

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

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

    ans = 0
    for can_move in combinations(xy, 2):
        xi, yi = can_move[0]
        xj, yj = can_move[1]
        ans += sqrt((xi - xj) ** 2 + (yi - yj) ** 2)
    print(f'{ans * 2 / N:.10f}')


if __name__ == '__main__':
    main()

Solution (Python):

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

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

    ans = 0
    cnt = 0
    for can_order in permutations(xy):
        cnt += 1
        for k in range(1, N):
            xi, yi = can_order[k - 1]
            xj, yj = can_order[k]
            ans += sqrt((xi - xj) ** 2 + (yi - yj) ** 2)
    
    print(f'{ans / cnt:.10f}')


if __name__ == '__main__':
    main()

Solution (Python):
import itertools

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

distance = 0
for c in itertools.combinations(range(N), 2):
    c1, c2 = c
    distance += ((cities[c1][0] - cities[c2][0]) ** 2 + (cities[c1][1] - cities[c2][1]) ** 2) **0.5

answer = 2 * distance / N

print(answer)

Solution (Python):
import itertools

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

distance = 0
for c in itertools.combinations(range(N), 2):
    c1, c2 = c
    distance += ((cities[c1][0] - cities[c2][0]) ** 2 + (cities[c1][1] - cities[c2][1]) ** 2) **0.5

answer = 2 * distance / N

print(answer)

Solution (Python):
N = int(input())
towns = [tuple(map(int, input().split())) for _ in range(N)]

total_distance = 0
count = 0
for start in range(N-1):
    for end in range(start+1, N):
        start_x, start_y = towns[start]
        end_x, end_y = towns[end]

        total_distance += ((end_x - start_x)**2 + (end_y - start_y)**2)**0.5
        count += 1

answer = total_distance * ((N - 1) / count)
print(answer)

Solution (Python):


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

total_distance = 0
count = 0
for start in range(N-1):
    for end in range(start+1, N):
        start_x, start_y = towns[start]
        end_x, end_y = towns[end]

        total_distance += ((end_x - start_x)**2 + (end_y - start_y)**2)**0.5
        count += 1




answer = total_distance * ((N - 1) / count)
print(answer)

Solution (Python):
import numpy as np
import math
n=int(input())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
a=np.array(a, dtype=object)
ans=0
for i in range(n):
  for j in range(n):
    if i==j:
      continue
    else:
      x= (a[i]-a[j])**2
      hei=math.sqrt(sum(x))
      ans+= hei/n
print(ans)

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

way = 0
p_list = [i for i in range(n)]
for P in itertools.permutations(p_list):
    for i in range(n-1):
        way += ((xy[P[i+1]][1]-xy[P[i]][1])**2+(xy[P[i+1]][0]-xy[P[i]][0])**2)**0.5

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

print(way/kai)

Solution (Python):
import itertools
import math

def main():
    N = int(input())
    items = [i+1 for i in range(N)]

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

    paths =list(itertools.permutations(items))

    sum = 0
    for path in paths: 
        for i in range(len(path)-1):
            from_idx = path[i] -1
            to_idx = path[i+1] -1
            xdiff= locations[from_idx][0] - locations[to_idx][0]
            ydiff= locations[from_idx][1] - locations[to_idx][1]
            sum = sum + math.sqrt(xdiff**2 + ydiff**2)
    print( sum / len(paths))
main()

Solution (Python):
import itertools
import math
N = int(input())
P = [0] * N 
for i in range(N):
    P[i] = list(map(int,input().split()))
distance = 0
for root in itertools.permutations(P,N):
    start = root[0]
    for r in root:
        distance += pow((r[0]-start[0])**2 + (r[1]-start[1])**2,1/2)
        start = r
print(distance/math.factorial(N))

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

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

N=int(input())
x = []
y = []
for _ in range(N):
    a,b = map(int,input().split())
    x.append(a)
    y.append(b)
ls = []
for arr in itertools.permutations(list(range(N))):
    l = 0
    for ii in range(len(arr)-1):
        i = arr[ii]
        j = arr[ii+1]
        d = ((x[i]-x[j])**2 + (y[i]-y[j])**2)**0.5
        l += d
    ls.append(l)

print(sum(ls)/len(ls))

Solution (Python):
import itertools
import math
N = int(input())
ls = []
ans = 0
for i in range(N):
  x,y = map(int,input().split())
  ls.append([x,y])
ls2 = []
for i in itertools.permutations(ls,N):
  ls2.append(list(i))
for i in range(math.factorial(N)):
  ls3 = ls2[i]
  now_x = ls3[0][0]
  now_y = ls3[0][1]
  for j in range(1,N):
    ans += ((now_x - ls3[j][0])**2 + (now_y - ls3[j][1]) ** 2)**0.5
    now_x = ls3[j][0]
    now_y = ls3[j][1]
print(ans/math.factorial(N))

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

waru = 1
for i in range(N):
    waru*= i+1
a = [i+1 for i in range(N)]
c = 0
su = 0
for i in permutations(a,N):
    li = list(i)
    for j in range(len(li)-1):
        start = l[li[j]-1]
        g = l[li[j+1]-1]
        su += math.sqrt((start[0]-g[0]) ** 2 + (start[1]-g[1]) ** 2)
print(su/waru)

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

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

dsum = 0

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

dave = dsum / (n*(n-1) / 2)

print(dave*(n-1))

Solution (Python):
import itertools

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


cnt=0
num=0
for v in itertools.permutations(xy):
  num+=1
  for i in range(n-1):
    a=(v[i][0]-v[i+1][0])**2+(v[i][1]-v[i+1][1])**2
    b=a**0.5
    cnt+=b

print(cnt/num)

Solution (Python):
def dist(a,b):
    return ((b[0]-a[0])**2+(b[1]-a[1])**2)**(1/2)
n=int(input())
loca=[list(map(int, input().split())) for _ in range(n)]
import itertools
a=[i for i in range(n)]
sum=0
cnt=0
for i in itertools.permutations(a):
    li=list(i)
    cnt += 1
    for i in range(1,n):
        a=loca[li[i-1]]
        b=loca[li[i]]
        sum+=dist(a,b)
print(sum/cnt)

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

Solution (Python):
import math
import itertools
def distance(p1, p2):
    return math.sqrt((p1[0]-p2[0])**2 + (p1[1] - p2[1])**2)
n = int(input())
adj = {}
for i in range(1, n+1):
    x, y = map(int, input().split())
    adj[i] = (x, y)
dd = {}
ans = 0
for i in range(1, n):
    for j in range(i+1, n+1):
        dist = distance(adj[i], adj[j])
        ans += dist
print(format((2 * ans) / n, '.10f'))

Solution (Python):
n=int(input())
import math
import itertools
zahyou=[[0,0]]
for i in range(n):
    tmp=[int(x) for x in input().split()]
    zahyou.append(tmp)

    ans=0
    
for seq in itertools.permutations(range(1,n+1)):
    dist=0
    for i in range(len(seq)-1):
        dist+=math.sqrt((zahyou[seq[i]][0]-zahyou[seq[i+1]][0])**2+(zahyou[seq[i]][1]-zahyou[seq[i+1]][1])**2)
    ans+=dist

print(ans/math.factorial(n))

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


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

for i in xy:
    for j in xy:
        cnt += np.linalg.norm(i - j)
print(cnt / N)

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush

sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
XY = [(0,0)] + inplt(n)

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

Solution (Python):
import itertools
import math

n = int(input())
points = [list(map(int, input().split())) for _ in range(n)]
numbers = list(range(1, n + 1))
diff = 0
count = 0
for pattern in itertools.permutations(numbers):
    count += 1
    for j in range(n - 1):
        points_index = pattern[j] - 1
        next_index = pattern[j + 1] - 1
        diff += math.sqrt((points[points_index][0] - points[next_index][0]) ** 2 + (points[points_index][1] - points[next_index][1]) ** 2)

print(diff / count)

Solution (Python):








import itertools
import math
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]


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

a = list(itertools.permutations(seq))


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


print(ans/len(a))

Solution (Python):
import itertools
import math

N=int(input())
zahyou=[list(map(int,input().split()))for i in range(N)]
jyunban=list(itertools.permutations(range(N)))
dist=list()
for i in range(len(jyunban)):
    tmp=0
    for j in range(N-1):
        tmp+=math.sqrt((zahyou[jyunban[i][j]][0]-zahyou[jyunban[i][j+1]][0])**2+(zahyou[jyunban[i][j]][1]-zahyou[jyunban[i][j+1]][1])**2)
    dist.append(tmp)
print(sum(dist)/math.factorial(N))

Solution (Python):
import itertools
import math

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

route = list(itertools.permutations([i for i in range(n)]))
for num in route:
    for i in range(1,n):
        dist += math.sqrt((xy[num[i]][0]-xy[num[i-1]][0])**2+ (xy[num[i]][1]-xy[num[i-1]][1])**2)
    
print(dist/len(route))

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

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

Solution (Python):




import sys
from io import StringIO
import unittest
import math
import itertools


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
0 0
1 0
0 1"""
        output = """2.2761423749"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
-879 981
-866 890"""
        output = """91.9238815543"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310"""
        output = """7641.9817824387"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    P = [list(map(int, input().split())) for _ in range(N)]

    R = itertools.permutations(range(N))

    all = 0
    for r in R:
        for pi in range(1, len(r)):
            all += math.sqrt((P[r[pi]][0]-P[r[pi-1]][0])**2 +
                             (P[r[pi]][1]-P[r[pi-1]][1])**2)

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

    print(f"{all/n:.10f}")


if __name__ == "__main__":
    
    resolve()

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

Solution (Python):
import math
from itertools import permutations

def calc_distance(p1,p2):
    return  math.sqrt((p2[0]-p1[0])**2+(p2[1]-p1[1])**2)

def calc_distance_sum(position_arr,idx_arr):
    distance_sum = 0
    for i in range(len(idx_arr)-1):
        distance_sum += calc_distance(position_arr[idx_arr[i]],position_arr[idx_arr[i+1]])
    return distance_sum

if __name__ == "__main__":
    N = int(input())
    idx_list = [i for i in range(N)]
    idx_pattern_arr = list(permutations(idx_list))
    position_arr = [tuple(map(int,input().split())) for i in range(N)]
    distance_sum = 0
    for idx_pattern in idx_pattern_arr:
        distance_sum += calc_distance_sum(position_arr,idx_pattern)
    print(distance_sum/len(idx_pattern_arr))

Solution (Python):
import itertools
n = int(input())
seq = [i for i in range(n)]
steps = list(itertools.permutations(seq))
xy = [list(map(int,input().split())) for _ in range(n)]
sumlen = 0
for j in range(len(steps)):
    leng = 0
    step = steps[j]
    for k in range(n-1):
        x_1 = int(xy[step[k]][0])
        x_2 = int(xy[step[k+1]][0])
        y_1 = int(xy[step[k]][1])
        y_2 = int(xy[step[k+1]][1])
        leng += ((x_1 - x_2)**2  + (y_1 - y_2)**2)**0.5
    sumlen += leng
print((sumlen/len(steps)))

Solution (Python):
N = int(input())
xs, ys = [], []
for n in range(N):
  x, y = map(int, input().split(' '))
  xs.append(x)
  ys.append(y)
  
sum_dist = 0
for n1 in range(N-1):
  for n2 in range(n1+1, N):
    sum_dist += ((xs[n1]-xs[n2])**2 + (ys[n1]-ys[n2])**2)**(1/2)




print((2 * sum_dist) / N)

Solution (Python):
import itertools

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


cnt=0
num=0
for v in itertools.permutations(xy):
  num+=1
  for i in range(n-1):
    a=(v[i][0]-v[i+1][0])**2+(v[i][1]-v[i+1][1])**2
    b=a**0.5
    cnt+=b

print(cnt/num)

Solution (Python):
from itertools import permutations
N = int(input())

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

n = [i for i in range(N)]
sum = 0
for i in permutations(n):
    i = list(i)
    for j in range(N-1):
        sum += ((xy[i[j]][0]-xy[i[j+1]][0])**2 + (xy[i[j]][1]-xy[i[j+1]][1])**2)**(0.5)

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

print(sum/fct)

Solution (Python):




import sys
from io import StringIO
import unittest
import math
import itertools


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
0 0
1 0
0 1"""
        output = """2.2761423749"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
-879 981
-866 890"""
        output = """91.9238815543"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310"""
        output = """7641.9817824387"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    P = [list(map(int, input().split())) for _ in range(N)]

    L = [i for i in range(N)]
    R = itertools.permutations(L)

    all = 0
    for r in R:
        for pi in range(1, len(r)):
            all += math.sqrt((P[r[pi]][0]-P[r[pi-1]][0])**2 +
                             (P[r[pi]][1]-P[r[pi-1]][1])**2)

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

    print(f"{all/n:.10f}")


if __name__ == "__main__":
    
    resolve()

Solution (Python):
from itertools import combinations
N = int(input())
town = []
for n in range(N):
    x, y = map(int,input().split())
    town.append((x,y))

ans = 0
for i,j in combinations(town,2):
    ans += ((i[0]-j[0])**2 + (i[1]-j[1])**2)**0.5
print (2*ans/N)

Solution (Python):

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

def dist(A,B):
    return math.sqrt((A[0]-B[0])**2 + (A[1]-B[1])**2)
route = list(itertools.permutations(town))
tot = 0
for i in route:
    for j in range(len(i)-1):
        tot += dist(i[j],i[j+1])
ave = tot/len(route)
print(ave)

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

dist = 0
cnt = 0
for target_list in list(itertools.permutations(n)):
    for i in range(len(target_list)):
        if i == 0:
            continue
        dist += math.sqrt((XY[target_list[i]][0] - XY[target_list[i-1]][0]) ** 2 + (XY[target_list[i]][1] - XY[target_list[i-1]][1]) ** 2)
    cnt += 1
print(dist / cnt)

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

import math
from itertools import permutations
list = [i for i in range(N)]
per = permutations(list,N)

ans = 0
for i in per:
    for j in range(N-1):
        x1, y1 = pos[i[j]]
        x2, y2 = pos[i[j+1]]
        ans += math.sqrt((x1-x2)**2 + (y1-y2)**2)
        
for n in range(1,N+1):
    ans /= n

print(ans)

Solution (Python):
import sys
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy

    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N = I()
    mylist = [LI() for i in range(N)]
    dist = [[0 for i in range(N)] for i in range(N)]
    for index1, num1 in enumerate(mylist):
        for index2, num2 in enumerate(mylist):
            dist[index1][index2] = math.sqrt((num1[0]-num2[0])**2 + (num1[1]-num2[1])**2)
    result = 0
    index = 0
    seq = [i for i in range(N)]
    for i in itertools.permutations(seq):
        index += 1
        past = i[0]
        for num in i[1:]:
            result += dist[past][num]
            past = num
            
            
    print(result/index)

    
    
    
if __name__ == "__main__":
    main()

Solution (Python):
import math
N=int(input())
A=[0]*N
B=[0]*N
for i in range(N):
	A[i],B[i]=map(int,input().split())
total=0
for i in range(N):
  for j in range(i+1,N):
    total+=((A[i]-A[j])**2+(B[i]-B[j])**2)**0.5
    
    

print(total/N*2)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
 
N = int(readline())
XY = np.array(read().split(),np.int64)
 
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 collections 
import itertools 

import math 










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

cnt = math.factorial(n-1)
ans = 0

chkli = itertools.permutations(range(n),2)

for i, v in enumerate(chkli):
    ans += ((abs((li[v[0]][0]) - (li[v[1]][0])) ** 2) + (abs((li[v[0]][1]) - (li[v[1]][1])) ** 2)) **.5 * cnt

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

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

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

import itertools

seq=[i for i in range(n)]
p=list(itertools.permutations(seq))
import math

ans=0
for pp in p:
  for i in range(n-1):
    xy=math.sqrt((l[pp[i]][0]-l[pp[i+1]][0])**2 + (l[pp[i]][1]-l[pp[i+1]][1])**2)
    ans+=xy

print(ans/len(p))

Solution (Python):
import itertools
Row = int(input())
List = []
l=[]
for i in range (Row):
  l.append(i+1)
  List.append(list(map(int, input().split())))
x = 0
y = 0
mid = 0
p_list = list(itertools.permutations(l, Row))
for v in p_list:
  for i in range(1,Row):
    x = List[v[i]-1][0]-List[v[i-1]-1][0]
    y = List[v[i]-1][1]-List[v[i-1]-1][1]
    k = x*x+y*y
    mid += k**0.5
res = mid / len(p_list)
print(res)

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

Solution (Python):
import itertools
n = int(input())
test = list(itertools.permutations([i for i in range(n)]))
data = []
for i in range(n):
    x,y = map(int,input().split())
    data.append([x,y])
total = 0
for i in test:
    for k in range(n-1):
        total += ((data[i[k]][0] - data[i[k+1]][0])**2 + (data[i[k]][1] - data[i[k+1]][1])**2 )**0.5
print(total/len(test))

Solution (Python):
from itertools import permutations as perm

N = int(input())
XYS = [list(map(int, input().split())) for _ in range(N)]
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)