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())
x, y = [], []
for i in range(n):
    xi, yi = map(int, input().split())
    x.append(xi)
    y.append(yi)
d = 0
for i in range(n):
    for j in range(n):
        d += ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** 0.5
print(d / n)

Solution (Python):
import itertools
n = int(input())
x, y = [], []
f = 1
for i in range(n):
    f *= i + 1
    xi, yi = map(int, input().split())
    x.append(xi)
    y.append(yi)
p = [i for i in range(n)]
d = 0
for perm in itertools.permutations(p):
    for i in range(n - 1):
        d += ((x[perm[i]] - x[perm[i + 1]]) ** 2 + (y[perm[i]] - y[perm[i + 1]]) ** 2) ** 0.5
print(d / f)

Solution (Python):
import math
import itertools

n = int(input())
e = [[int(i) for i in input().split()] for i in range(n)] 
len_sum = 0
count = 0

for x in itertools.permutations(e):
  for i in range(n):
    for j in range(n):
      if j - i != 1:
        continue
      else:
        len_sum += math.sqrt(math.pow(x[i][0] - x[j][0], 2) + math.pow(x[i][1] - x[j][1], 2))
  count += 1
  
print(len_sum/count)

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

Solution (Python):
n = int(input())
pl = list()
for i in range(n):
    pl.append(list(map(int, input().split())))

import math
lsum = 0
for i in range(n):
    for j in range(n):
        if i != j:
            a, b = pl[i]
            c, d = pl[j]
            lsum += math.sqrt((a-c) ** 2 + (b-d) ** 2)
print(lsum /(n))

Solution (Python):
import math

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

k = [1]
for i in range(n):
    k.append(k[i] * (i + 1))
l = 0


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

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

Solution (Python):



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


def main():
    from itertools import permutations

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

    m = len(list(permutations(range(n))))

    for p in permutations(range(n)):
        for i in range(len(p) - 1):
            a = p[i]
            b = p[i + 1]
            total += calc_dist(xy[a][0], xy[b][0], xy[a][1], xy[b][1])

    print(total / m)


if __name__ == '__main__':
    main()

Solution (Python):
import math
import itertools

N = int(input())
A =[]
path_length = 0
permm = list(range(N))

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

for p in itertools.permutations(permm):
  

  for i, j in zip(p, p[1:]):
      x1, y1 = A[i]
      x2, y2 = A[j]
      path_length += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
ans = path_length / math.factorial(N)

print(ans)

Solution (Python):
from itertools import permutations
from math import hypot, factorial
n = int(input())
t = [list(map(int,input().split())) for _ in range(n)]

sum = 0
for p in permutations(t):
  for i in range(n-1):
    sum += hypot(p[i+1][0]-p[i][0], p[i+1][1]-p[i][1])
print(sum/factorial(n))

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

a = sum(((p-r)**2 + (q-s)**2 ) **0.5 for [(p,q),(r,s) ]in itertools.combinations(x,2))

print(2*a/N)

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() )
S = 0
nb =0
for i in range(N) :
  for j in range(0, i) :
    S += math.sqrt( (x[i]-x[j])**2 + (y[i]-y[j])**2 )
    nb += 1
print(S/nb*(N-1))

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

R = list(itertools.permutations(range(n), n))
out = 0
N = math.factorial(n)
for case in R:
  for i in range(1, n):
    out += math.sqrt((L[case[i]][0] - L[case[i-1]][0])**2 
                     + (L[case[i]][1] - L[case[i-1]][1])**2)
print(out/N)

Solution (Python):
import itertools
import math
n = int(input())
town = [tuple(map(int, input().split())) for _ in range(n)]
ans = 0
cnt = 0

for p in itertools.permutations(range(0, n), n):
    for i in range(n - 1):
        distance = (town[p[i]][0] - town[p[i + 1]][0]) ** 2 + \
            (town[p[i]][1] - town[p[i + 1]][1]) ** 2
        ans += math.sqrt(distance)
    cnt += 1
ans /= cnt
print(ans)

Solution (Python):
import math
from itertools import permutations, combinations,combinations_with_replacement,product

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

def distance_aaa(arg_list):
    result =[]
    for i in range(len(arg_list)-1):
        result.append(math.sqrt((list_aaa[arg_list[i]][0]-list_aaa[arg_list[i+1]][0])**2+(list_aaa[arg_list[i]][1]-list_aaa[arg_list[i+1]][1])**2))
    return sum(result)


loop_x =list(permutations(range(N)))

result_aaa =[]

for i in loop_x:
    result_aaa.append(distance_aaa(i))

print(sum(result_aaa)/math.factorial(N))

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


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

sum = 0
perms = itertools.permutations(range(N), N)

distances = [[0] * N for _ in range(N)]

for i in range(N):
    for j in range(N):
        distances[i][j] = np.linalg.norm(towns[i]-towns[j])

sum = 0
for p in perms:
    distance = 0
    for i in range(N-1):
        distance += distances[p[i]][p[i + 1]]
    sum += distance


print(sum / math.factorial(N))

Solution (Python):
import numpy as np
from scipy.spatial import distance
from scipy.sparse.csgraph import floyd_warshall
n = int(input())
xy = np.zeros((n, 2))
for i in range(n):
    xy[i, 0], xy[i, 1] = (int(x) for x in input().split())
print(np.sum(distance.cdist(xy, xy, metric='euclidean'))/n)

Solution (Python):
import numpy as np
N = int(input())
pos = []
for i in range(N):
    pos.append(list(map(int, input().strip().split())))
pos = np.array(pos)
tmp_index = np.arange(N)
xx, yy = np.meshgrid(tmp_index, tmp_index)
distances = np.linalg.norm(pos[xx]-pos[yy], axis=2)

print(distances.mean()*N)

Solution (Python):
import itertools
import math

N = int(input())

dis = 0
a = 0


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

Solution (Python):
import math
import itertools
N = int(input())
x = [0] * N
y = [0] * N
way = [0] * N
seq = []
dis = 0

def distance(a, b):
    return ((x[way[a]] - x[way[b]]) ** 2 + (y[way[a]] - y[way[b]]) ** 2) ** 0.5

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

ways = list(itertools.permutations(seq))

n = len(ways)
for i in range(n):
    way = ways[i]
    for j in range(N - 1):
        dis += distance(j, j + 1)
print(dis / n)

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

import itertools

town_number = [i for i in range(N)]
town_group = list(itertools.combinations(town_number,2))

length = []

for i in range(len(town_group)):
    x = xy[town_group[i][0]][0] - xy[town_group[i][1]][0]
    y = xy[town_group[i][0]][1] - xy[town_group[i][1]][1]
    length.append((x**2 + y**2)**0.5)
    
print(sum(length)*2/N)

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

ls = []
from itertools import permutations
Ns = [i for i in range(N)]
perms = permutations(Ns)
perms = list(perms)

for perm in perms:
    cnt = 0
    for i in range(1,N):
        x1, y1 = a[perm[i-1]]
        x2, y2 = a[perm[i]]
        cnt += ((x1-x2)**2+(y1-y2)**2)**0.5
    ls.append(cnt)





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

Solution (Python):
n=int(input())
p=1
a=[]
for i in range(n):
  p*=i+1
  a.append(list(map(int,input().split())))
p//=n
ans=0
Dis=lambda x,y:((x[0]-y[0])**2+(x[1]-y[1])**2)**.5
for x in a:
  for y in a:
    ans+=p*Dis(x,y)

print("%.10f" % (ans/p/n))

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


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v

def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None


def f(a, b, c, d):
    return math.sqrt((a - b) ** 2 + (c - d) ** 2)

def main():
    N = int(input())
    L = [list(map(int, input().split())) for i in range(N)]
    Dsum = 0
    Dlen = 0

    for i, l in enumerate(itertools.permutations(range(N))):
        for j in range(len(l)-1):
            Dsum += f(L[l[j]][0], L[l[j+1]][0], L[l[j]][1], L[l[j+1]][1])
        Dlen += 1

    print(Dsum / Dlen)


main()

Solution (Python):
import numpy as np
n = int(input())
l = [[int(i) for i in input().split()] for _ in range(n)]

distance = 0
for i in l:
    for j in l:
        distance += np.sqrt((i[0] - j[0])**2 + (i[1] - j[1])**2)
        
print(distance/n)

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

Solution (Python):
n = int(input())
x_list = [ tuple(int(i) for i in input().split()) for _ in range(n) ]

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

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

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

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

Solution (Python):
import math
N=int(input())
A = [[int(i) for i in input().split()] for N in range(N)] 
S=0
for x in range(0,N-1):
  for y in range(x+1,N):
    S=S+math.sqrt((A[x][0]-A[y][0])**2+(A[x][1]-A[y][1])**2)
ave=S*2/N
print(ave)

Solution (Python):
n=int(input())
po=[]
for i in range(n):
    a,b=map(int,input().split())
    po.append([a,b])

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

    
print(ans*2/n)

Solution (Python):
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
def l2(a,b,c,d):
    return ((a-c)**2+(b-d)**2)**0.5
c=[]
for i in range(n):
    for j in range(n):
        if i==j: continue
        else:
            c.append(l2(a[i][0],a[i][1],a[j][0],a[j][1]))

print(sum(c)*(n-1)/len(c))

Solution (Python):
class Pos:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def cal_distance(self, pos):
        return ((self.x - pos.x)**2 + (self.y - pos.y)**2)**0.5


N = int(input())
data = [input() for _ in range(N)]

pos_list = []
for d in data:
    x,y = map(int, d.split())
    pos = Pos(x, y)
    pos_list.append(pos)

result_list = []
for i in range(N):
    for j in range(N):
        cal = pos_list[i].cal_distance(pos_list[j])
        result_list.append(cal)

print(sum(result_list) / N)

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

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

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

Solution (Python):
def calc(x1,y1,x2,y2):
    return (((x1-x2)**2+(y1-y2)**2))**0.5

def kaijo(n):
    if n == 1:
        return n
    return n * kaijo(n-1)

n = int(input())
lsx = []
lsy = []

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

num = 0
cnt = 0

for i in range(n):
    for j in range(i+1,n):
        num += calc(lsx[i],lsy[i],lsx[j],lsy[j])
        cnt += 1

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

Solution (Python):
import math

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

XY_dict = {}

for i in range(0,N):
  for j in range(i+1,N):
    key = str(i) + str(j)
    XY_dict[key] = math.sqrt( (XY[i][0] - XY[j][0])**2 + (XY[i][1] - XY[j][1])**2 )

ans = 0
for xy in XY_dict.values():
  ans += xy

ans = (ans * 2)/N

print(ans)

Solution (Python):


import sys
from math import hypot

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
XY = []
for i in range(N):
    x, y = MAP()
    XY.append((x, y))

dist = 0
for i in range(N):
    x, y = XY[i]
    for j in range(i+1):
        x2, y2 = XY[j]
        dist += hypot(x-x2, y-y2)
print(dist * 2 / N)

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

def solve(ite):
	a = 0
	for i in range(len(ite)-1):
		a += ((x[ite[i]] - x[ite[i+1]])**2 + (y[ite[i]] - y[ite[i+1]])**2) ** (1/2)
	return a


def next_permutation(n, flg, perm):
	S = []
	if flg.count(0) == 0:
		return solve(perm)

	a = 0
	for i in range(n):
		if flg[i] != 0:
			continue

		flg[i] = 1
		perm.append(i)

		a += next_permutation(n, flg, perm)

		flg[i] = 0
		perm.pop()

	return a


flg = [0] * N
perm = []

A = next_permutation(N,flg,perm)

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

print(A)

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


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

Sum_N = 0

for i in range(len(p)):

    Sum = 0

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

    Sum_N += Sum

print(Sum_N / len(p))

Solution (Python):
import math
import numpy as np
import itertools
N = int(input())
x = []; y= []
for _ in range(N):
    x_,y_ = map(int,input().split())
    x.append(x_)
    y.append(y_)
lis = np.zeros((8,8))
for i in range(N):
    for j in range(N):
        lis[i,j] = math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
num = 0
su = 0
ite = itertools.permutations([i for i in range(N)])
for it in ite:
    for i in range(len(it)-1):
        su += lis[it[i],it[i+1]]
    num += 1
print(su/num)

Solution (Python):

import copy
from math import factorial

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

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

    memo = {}  
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            memo[(i,j)] = calc_distance(cities[i], cities[j])

    degree = N-1  
    coef = factorial(degree)

    ans = 0
    for key, value in memo.items():
        ans += value * coef * 2  
    ans = ans / factorial(N)
    print(ans)


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

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

    memo = {}  
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            memo[(i,j)] = calc_distance(cities[i], cities[j])

    def dfs(will_visit, visited, now_i, total_d):
        if now_i is None:
            ans = 0
            for i in will_visit:
                new_will_visit = copy.deepcopy(will_visit)
                new_visited = copy.deepcopy(visited)
                new_will_visit.remove(i)
                new_visited.add(i)
                ans += dfs(new_will_visit, new_visited, i, 0)
            return ans

        if will_visit == []:
            return total_d

        ans = 0
        for i in will_visit:
            if i in visited: continue
            new_will_visit = copy.deepcopy(will_visit)
            new_visited = copy.deepcopy(visited)
            new_will_visit.remove(i)
            new_visited.add(i)
            ans += dfs(new_will_visit, new_visited, i, total_d+memo[min(now_i, i), max(now_i, i)])
        return ans

    will_visit = [i for i in range(1, N+1)]
    visited = set()
    ans = dfs(will_visit, visited, None, 0)
    print(ans/factorial(N))


if __name__ == "__main__":
    solve2()

Solution (Python):
import itertools
import numpy as np
def dist(p1,p2):
    dx = p1[0] - p2[0]
    dy = p1[1] - p2[1]
    return (dx ** 2 + dy ** 2)**0.5
    
ans = 0
n = int(input())
lis = []
for _ in range(n):
  x, y = map(int, input().split())
  lis.append((x, y))
per = list(itertools.permutations(lis, n))
count = 0
for i in per:
    for j in range(1,n):
        ans += dist(i[j-1],i[j])
print(ans/len(per))

Solution (Python):
import math
import itertools

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

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

distance = 0
for r in itertools.permutations(route):
    for i in range(n-1):
        distance += math.sqrt((town[r[i]][0] - town[r[i+1]][0])
                              ** 2 + (town[r[i]][1] - town[r[i+1]][1])**2)

print(distance/math.factorial(n))

Solution (Python):
def dist(x1, x2):
    d = (x1[0] - x2[0])**2 + (x1[1] - x2[1])**2
    return d**0.5

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

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

pos = []

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

routes= list(itertools.permutations(pos, n))

sum = 0
for r in routes:
  for i in range(1, n):
    d = ((r[i][0] - r[i-1][0]) ** 2) + ((r[i][1] - r[i-1][1]) ** 2)
    sum += math.sqrt(d)

print(sum/len(routes))

Solution (Python):
def dist(x1, x2):
    d = (x1[0] - x2[0])**2 + (x1[1] - x2[1])**2
    return d**0.5

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

Solution (Python):
import itertools
import math

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

ans = 0
for perm in itertools.permutations([i for i in range(N)]):
    for i in range(N - 1):
        ans += ((P[perm[i]][0] - P[perm[i+1]][0]) ** 2
                + (P[perm[i]][1] - P[perm[i+1]][1]) ** 2) ** 0.5

print(ans / math.factorial(N))

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

Solution (Python):
def dist(x1, x2):
    d2 = (x1[0] - x2[0]) ** 2 + (x1[1] - x2[1]) ** 2
    return d2 ** 0.5

n = int(input())
x = [list(map(int, input().split())) for _ in range(n)]
d = 0
for i in range(n - 1):
    xi = x[i]
    for j in range(i + 1, n):
        d += dist(xi, x[j])
print(2 * d / n)

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

coord = list()
for _ in range(N):
    c = tuple(map(int, input().split()))
    coord.append(c)

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

perm = 0
for i, p1 in enumerate(coord):
        for p2 in coord[i+1:]:
            d = calc_dist(p1, p2)
            perm += 2*d/N

print(perm)

Solution (Python):
import math
import itertools

n = int(input())

fac = math.factorial(n)

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







term = 0
for c in list(itertools.permutations(p)):
    t = 0
    for i in range(len(c)-1):
        t += math.sqrt((c[i][0] - c[i+1][0]) ** 2 + (c[i][1] - c[i+1][1]) ** 2)
        
        
    term += t
    
print(term / fac)

Solution (Python):
import math
import itertools
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
rt=[]
for i in range(n):
    for j in range(i+1,n):
        x1=xy[i][0]
        y1=xy[i][1]
        x2=xy[j][0]
        y2=xy[j][1]
        rt.append([(i,j),math.sqrt((x1-x2)**2+(y1-y2)**2)])
l=[i for i in range(n)]
sm=0
cnt=0
for v in list(itertools.permutations(l,n)):
    for i in range(n-1):
        f,t=v[i],v[i+1]
        if f>t:
            f,t=t,f
        for r in rt:
            if r[0]==(f,t):
                sm+=r[1]
    cnt+=1
print(sm/cnt)

Solution (Python):
import itertools
import math
n = int(input())
towns = []
s = 0
s_list = []
for i in range(n):
    towns.append([int(a) for a in input().split(' ')])
    s_list.append(str(i))
ps = [''.join(p) for p in itertools.permutations(s_list)]

k = 0
for i, p in enumerate(ps):
    p = list(p)  
    for j in range(len(p)):
        if j+1 >= n:  
            break
        s += math.sqrt(((towns[int(p[j])][0] - towns[int(p[j+1])][0])**2) + ((towns[int(p[j])][1] - towns[int(p[j+1])][1])**2))
    k += 1

print(s / k)

Solution (Python):
from itertools import permutations
from math import hypot, factorial
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
 
total = 0
for p in permutations(a):
    for i in range(N-1):
        total += hypot(p[i][0]-p[i+1][0], p[i][1]-p[i+1][1])
    
print(total / factorial(N))

Solution (Python):
def dis(p1,p2):
  return ((p1[0]-p2[0])**2+(p1[1]-p2[1])**2)**0.5
 
n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(n):
  for j in range(i+1,n):
    ans+=dis(p[i],p[j])
print(ans*2/n)

Solution (Python):
import sys
from collections import Counter, deque, defaultdict, OrderedDict
from math import factorial
from fractions import Fraction
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
x = [0]*n
y = [0]*n
res = 0
for i in range(n):
    xx, yy = MAP()
    x[i] = xx
    y[i] = yy
dist = [[0]*n for i in range(n)]
for i in range(n):
    for j in range(n):
        dist[i][j] = math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)

p_list = list(itertools.permutations([i for i in range(n)], n))
for per in p_list:
    temp = list(per)
    for i in range(n-1):
        res += dist[temp[i]-1][temp[i+1]-1]

print(res/len(p_list))

Solution (Python):


import sys
sys.setrecursionlimit(12345678)
import itertools
import math
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n = int(input())
    nl = [i for i in range(n)]

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

    total = 0
    routes = list(itertools.permutations(nl))
    for route in routes:
        
        distance = 0
        for i in range(1, len(route)):
            src_x = xy[route[i-1]][0]
            src_y = xy[route[i-1]][1]
            dst_x = xy[route[i]][0]
            dst_y = xy[route[i]][1]
            distance += math.sqrt((dst_x - src_x) * (dst_x - src_x) + (dst_y - src_y) * (dst_y - src_y))

        total += distance
    
    print(total / len(routes))


if __name__ == '__main__':
    main()

Solution (Python):
import math
n = int(input())
A = []
sum = 0
for i in range(n) :
  a,s = (int(x) for x in input().split())
  A.append((a,s))
for i in A:
  for i2 in A:
    sum+=math.sqrt((i[0]-i2[0])**2+(i[1]-i2[1])**2)
print(sum/n)

Solution (Python):
import math
N=int(input())
Z=[]*N
for i in range(N):
    A=list(map(int,input().split()))
    Z.append(A)
def D(x1,x2,y1,y2):
    return pow((x1-x2)**2+(y1-y2)**2,0.5)

ans=0
for i in range(N):
    for j in range(i,N):
        ans+=D(Z[i][0],Z[j][0],Z[i][1],Z[j][1])*math.factorial(N-1)*2
print(ans/math.factorial(N))

Solution (Python):
from itertools import permutations
import math

N = int(input())
V = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0
for indices in permutations(range(N)):
    for i in range(N - 1):
        j = indices[i]
        k = indices[i + 1]
        ans += math.sqrt((V[j][0] - V[k][0]) ** 2 + (V[j][1] - V[k][1]) ** 2)
ans /= math.factorial(N)
print(ans)

Solution (Python):
import itertools
import math

if __name__ == "__main__":
  N = int(input())
  
  points = []
  
  for _ in range(N):
    points.append(list(map(int, input().split())))
    
  sum_dist = 0

  for ord_ps in itertools.permutations(points, N):
    for i in range(N - 1):
      sum_dist += math.sqrt((ord_ps[i][0] - ord_ps[i + 1][0]) ** 2 + (ord_ps[i][1] - ord_ps[i + 1][1]) ** 2)
  
  print(sum_dist / math.factorial(N))

Solution (Python):
a = int(input())
ar = []
br = []
for i in range(a):
    x,y = map(int,input().split(" "))
    ar.append([x,y])
    br.append([x,y])
count = 0
for i in range(a):
    for j in range(a):
        if i != j:
            count += ( (abs(ar[i][0] - br[j][0]) ** 2 + (abs(ar[i][1] - br[j][1])) ** 2) )** 0.5
print(count / a)

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

from itertools import permutations

a = (permutations(p))

from math import sqrt

def dis(a):
    sum = 0
    for i in range(n-1):
        sum += sqrt( (a[i][0]-a[i+1][0]) ** 2 + (a[i][1]-a[i+1][1]) ** 2 )
    return sum

b = map(dis, a)

from statistics import mean

print(mean(b))

Solution (Python):
import math
N=int(input())
a=1
b=N
for i in range(1,N):
  a*=i
  b*=i
XY=[list(map(int,input().split())) for i in range(N)]
ans=0
for j in range(1,N):
  i=0
  while i+j<N:
    ans += math.sqrt((XY[i][0]-XY[i+j][0])**2 + (XY[i][1]-XY[i+j][1])**2)*a*2
    i+=1
print(ans/b)

Solution (Python):
import sys
from math import sqrt
input = sys.stdin.readline
N = int(input())
p = []
for _ in range(N):
  p.append(list(map(int, input().split())))
def dist(x1, y1, x2, y2):
  return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
res = 0
vis = set()
c = 0
def fact(n):
  r = 1
  for i in range(1, n + 1):
    r *= i
  return r
def dfs(n):
  global vis
  global res
  global c
  for x in range(N):
    if x in vis: continue
    vis.add(x)
    res += dist(p[n][0], p[n][1], p[x][0], p[x][1]) * fact(N - len(vis))
    dfs(x)
    vis.discard(x)
  if len(vis) == N: c += 1

for y in range(N):
  vis.add(y)
  dfs(y)
  vis.discard(y)


print(res / c)

Solution (Python):
n = int(input().strip())
town = [list(map(int, input().split())) for _ in range(n)]
def dist(p, q):
  return ((p[0]-q[0]) ** 2 + (p[1]-q[1]) ** 2) ** 0.5
s = sum(dist(p, q) for p in town for q in town)
avg = s / n
print ("{:.10f}".format(avg))

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

n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(n):
  for j in range(i+1,n):
    ans+=dis(p[i],p[j])
print(ans*2/n)

Solution (Python):
import itertools as iter
n = int(input())
li = [list(map(int,input().split())) for i in range(n)]
com = list(iter.permutations(li))
start = com[0]
ans = 0
for i in com:
    for j in range(n-1):
        a,b=i[j]
        c,d=i[j+1]
        ans+=((c-a)**2+(d-b)**2)**0.5
print(ans/len(com))