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
import math
n=int(input())
x=[]
for i in range(n):
    a=input().split()
    x.append([int(i) for i in a])


all_way=[]
for i in itertools.permutations(x):
    all_way.append(list(i))

result=[]
for each_way in all_way:
    total=0
    for town in range(len(each_way)-1):
        total+=math.sqrt((each_way[town][0]-each_way[town+1][0])**2 + (each_way[town][1]-each_way[town+1][1])**2)
    result.append(total)

print(sum(result)/len(result))

Solution (Python):
import itertools
import math

def main():
    N = int(input())
    x = [list(map(int,input().split())) for _ in range(N)]
    d_all = 0
    for root in itertools.permutations(range(N)):
        d_x,d_y = 0,0
        for i in range(N-1):
            d_x += x[root[i+1]][0]-x[root[i]][0]
            d_y += x[root[i+1]][1]-x[root[i]][1]
            d_all += (d_x**2+d_y**2)**(1/2)
    
    all_ = math.factorial(N)     
    print(d_all/all_)

if __name__ == "__main__":
    main()

Solution (Python):
import itertools


def distance(route_index: tuple, points: list):
	sum_distance = 0
	for i in range(len(route_index) - 1):
		p1_x = points[route_index[i]][0]
		p1_y = points[route_index[i]][1]

		p2_x = points[route_index[i + 1]][0]
		p2_y = points[route_index[i + 1]][1]

		X = p2_x - p1_x
		Y = p2_y - p1_y

		sum_distance += (X ** 2 + Y ** 2) ** (1 / 2)
	return sum_distance


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

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

sum_distance = 0
for route_index in route_index_list:
	sum_distance += distance(route_index, points)

print(sum_distance / len(route_index_list))

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

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

Solution (Python):
N = int(input())
array = []
for i in range(N):
  x,y = list(map(int,input().split()))
  array.append([x,y])
sum = 0
for j in range(N):
  for k in range(N):
    if j >= k:
      continue
    else:
      length = ((array[j][0]-array[k][0])**2 + (array[j][1]-array[k][1])**2)**(1/2)
      sum += length
print((2*sum)/N)

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

total = 0
for i in range(1,n):
    x0,y0 = lst[i][0],lst[i][1]
    for j in range(i):
        x1,y1 = lst[j][0],lst[j][1]
        total += ((x1 - x0)**2 + (y1 - y0)**2)**0.5
print(total*2/n)

Solution (Python):
import math
N = int(input())
l_x = []
l_y = []
s = 0
a = (math.factorial(N) * (N-1)) // (((N-1)*N)//2)
for i in range(N):
    x,y = map(int,input().split())
    l_x.append(x)
    l_y.append(y)
for i in range(N):
    for j in range (i+1,N):
        m = (l_x[i]-l_x[j])**2 + (l_y[i] - l_y[j])**2
        s += math.sqrt(m)*a
print(s / math.factorial(N))

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

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

total_distance = 0

for i in range(0, len(towns)):
    town1 = towns[i]
    for j in range(0, len(towns)):
        if i != j:
            town2 = towns[j]
            total_distance += distance(town1,town2)

avg_distance = (1/N)*total_distance
print(avg_distance)

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

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


Nbiku = math.factorial(N)
Nbikuhiku = math.factorial(N - 1) 

ans = 0
for index in range(N):
    for index2 in range(N):
        if index == index2:
            continue

        dx = x[index] - x[index2]
        dy = y[index] - y[index2]

        ans += (dx ** 2 + dy ** 2)** 0.5 * Nbikuhiku
        

print(ans / Nbiku)

Solution (Python):
N = input()

hoge = []
for i in range(1, int(N) + 1):
    x, y = input().split()
    hoge.append([x, y])

d = 0
for i in range(int(N)):
    for j in range(i, int(N)):
        d += (((int(hoge[i][0]) - int(hoge[j][0])) ** 2 + (int(hoge[i][1]) - int(hoge[j][1])) ** 2) ** (1 / 2))

print(d * (2/int(N)))

Solution (Python):

def dis(a):
  return ((a[0]-a[2])*(a[0]-a[2])+(a[1]-a[3])*(a[1]-a[3]))**0.5

n = int(input())
p=[]
for i in range(n):
  a,b = map(int,input().split())
  p.append([a,b])
d=[[0]*n for _ in range(n)]
s=0
for i in range(n):
  for j in range(i+1,n):
    g = dis(p[i]+p[j])
    d[i][j]=d[j][i]=g
    s+=2*g
print("%.7f"%(s/n))

Solution (Python):
import math
import itertools
 
N=int(input())
P=[]
all_dist=[]
 
def Len(X,Y):
    return math.sqrt((X[0]-Y[0])**2+(X[1]-Y[1])**2)

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

 
route=list(itertools.permutations(P))

 
for k in range(math.factorial(N)):
    B=0
    A=list(route[k])
    for i in range(len(A)-1):
        B+=Len(A[i],A[i+1])
    all_dist.append(B)
ans=sum(all_dist)/len(all_dist)
 
print(str(ans))

Solution (Python):
from math import sqrt

def distance(p, q):
    return sqrt((p[0]-q[0])*(p[0]-q[0])+(p[1]-q[1])*(p[1]-q[1]))

def main():
    n = int(input())
    p_array = []
    s = 0
    for i in range(n):
        p = list(map(int, input().split(' ')))
        for q in p_array:
            s += distance(p, q)
        p_array.append(p)
    return 2*s/n

if __name__ == "__main__":
    print(main())

Solution (Python):


import numpy as np

import math


n = int(input())


a = []


sum = 0


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

for i in range(n):
    for s in range(i,n):
        sum += np.linalg.norm(a[s] - a[i])


print(sum*2/n)

Solution (Python):




import numpy as np

import math


n = int(input())


a = []


sum = 0


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

for i in range(n):
    for s in range(i,n):
        sum += np.linalg.norm(a[s] - a[i])


print(sum*2/n)

Solution (Python):
import numpy as np
N = int(raw_input())
P = np.empty([N,2], dtype=float)
for i in xrange(N):
    P[i] = map(float, raw_input().split())

Distance_matrix = np.empty([N,N], dtype=float)
for i in xrange(N):
    for j in xrange(i+1,N):
        temp = np.sqrt((P[i,0] - P[j,0])**2 + (P[i,1] - P[j,1]) ** 2)
        Distance_matrix[i,j] = Distance_matrix[j,i] = temp

from itertools import permutations
path = permutations(range(N), N)

length = []
for p in path:
    sum = 0
    for i in xrange(N-1):
        sum += Distance_matrix[p[i], p[i+1]]
    length.append(sum)

print "{:12.10f}".format(np.mean(length))

Solution (Python):
import itertools
import math

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

ans = 0
cnt = 0

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

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

l = 0
c = 0

for v in itertools.permutations(xy):
  for i in range(len(v)-1):
    l += ((v[i][0] - v[i+1][0])**2 + (v[i][1] - v[i+1][1])**2)**0.5
  c += 1

print(l/c)

Solution (Python):
import numpy as np

N = int(input())
x = np.zeros((N, 1))
y = np.zeros((N, 1))
for n in range(N):
    x[n], y[n] = map(int, input().split())
dist_mat = np.sqrt((x - x.T) ** 2 + (y - y.T) ** 2)
print(np.mean(dist_mat * N))

Solution (Python):
def get_dist(p1, p2):
    x1, y1 = p1
    x2, y2 = p2
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5

def solve():
    from itertools import combinations
    from math import factorial
    from sys import stdin
    f_i = stdin
    
    N = int(f_i.readline())
    points = tuple(tuple(map(int, f_i.readline().split())) for i in range(N))
    s = sum(get_dist(p1, p2) for p1, p2 in combinations(points, 2))
    print(s * 2 / N)

solve()

Solution (Python):
import itertools

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)]
dis=0
cnt=0
for v in itertools.permutations(l):
  
  cnt+=1
  for i in range(1,N):
    dis+=((x[v[i]]-x[v[i-1]])**2+(y[v[i]]-y[v[i-1]])**2)**0.5

print(dis/cnt)

Solution (Python):
import math
from collections import deque

n = int(input())
ans = 0.0
town = []
length = [[0 for i in range(n)]for j in range(n)]
temp = []

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

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        else:
            length[i][j] = math.sqrt(((town[i][0] - town[j][0]) ** 2) + ((town[i][1] - town[j][1]) ** 2))

queue = deque()

for i in range(n):
    queue.append([[i], 0.0])

while len(queue) != 0:
    left = queue.popleft()
    visited = left[0]
    now_length = left[1]
    for i in range(n):
        if i in visited:
            continue
        else:
            now_length = now_length + length[visited[len(visited) - 1]][i]
            for j in visited:
                temp.append(j)
            temp.append(i)
            if len(temp) == n:
                ans += now_length
            else:
                queue.append([temp, now_length])
            temp = []
            now_length = left[1]

print(ans / math.factorial(n))

Solution (Python):
import math

n = int(input().strip())
x_y = [[0] * 2] * n

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

den = math.factorial(n)
mol = 0

for i in range(n):
    for j in range(n):
        if (i == j):
            next
        else:
            mol += math.factorial(n - 1) * ((x_y[i][0] - x_y[j][0]) ** 2 + (x_y[i][1] - x_y[j][1]) ** 2) ** (1 / 2)

print(mol / den)

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

l = 0
c = 0
for v in itertools.permutations(xy): 
    for i in range(len(v)-1):
        l += ((v[i][0] - v[i+1][0]) **2 + (v[i][1] - v[i+1][1])**2)**0.5 
    c += 1
print(l/c)

Solution (Python):
N = int(input())
dic = {}
for n in range(N):
    X, Y = input().split()
    x = int(X)
    y = int(Y)
    dic[n] = (x, y)
distancesum = 0    
for a in range(N):
    xa, ya = dic[a]
    
    for b in range(N):
        xb, yb = dic[b]
        
        distance2 = (xa-xb)**2+(ya-yb)**2
        distance = distance2**0.5
        distancesum += distance

ans = distancesum/N   
print(ans)

Solution (Python):
import itertools
import numpy as np


N = int(input())
n=[]
s=range(N)
for i in range(N):
    n.append([int(x) for x in input().split()])
Q = list(itertools.permutations(s))
L=0
for i in range(int(len(Q))):
    for j in range(N-1):
        L+= np.sqrt((n[Q[i][j+1]][0] - n[Q[i][j]][0])**2 + (n[Q[i][j+1]][1] - n[Q[i][j]][1])**2)
print(L/(len(Q)))

Solution (Python):
import math
from scipy.misc import comb

n = int(input())
t = [list(map(int, input().split())) for _ in range(n)]
d = 0
for i in range(n - 1):
    for j in range(i, n):
        d += (((t[i][0] - t[j][0]) ** 2 + (t[i][1] - t[j][1]) ** 2)
              ** 0.5) * ((n - 1) * math.factorial(n)/comb(n, 2))

print(d/math.factorial(n))

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

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

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

loc = []
for i in range(n):
  loc.append(list(map(int, input().split())))
tot = 0
for i in range(n):
  for j in range(i + 1, n):
    tot += ((loc[i][0] - loc[j][0]) ** 2 + (loc[i][1] - loc[j][1]) ** 2) ** 0.5
tot *= all // (n * (n - 1) // 2)

print(tot / all * (n - 1))

Solution (Python):
N = int(input())
 
xy = []
for _ in range (N):
  x, y = map(int, input().split())
  xy.append([x, y])
 
nu = 0
for i in range (N):
  for j in range (i,N):
    nu += ((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2)**0.5
    
answer = nu * (2/N)
 
print(answer)

Solution (Python):
import itertools
import math

if __name__ == '__main__':

	n = int(input())

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

	p = list(itertools.permutations(A))

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

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

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

Solution (Python):
import sys
import math


def len(lhs, rhs):
    return math.sqrt((lhs[0] - rhs[0]) ** 2 + (lhs[1] - rhs[1]) ** 2)


def solve(n: int, cities):
    sum = 0
    for i1, city1 in enumerate(cities):
        for i2, city2 in enumerate(cities):
            if i1 != i2:
                sum += len(city1, city2)
    return sum / n


def main():
    inputs = list(sys.stdin)
    n = int(inputs.pop(0))
    cities = [[int(n) for n in s.split(" ")] for s in inputs]
    print(solve(n, cities))


main()

Solution (Python):
import math

N = int(input())
town_location = [input().split() for _ in range(N)]
town_location = [[int(town_location[i][0]), int(town_location[i][1])] for i in range(N)]
sum_length = 0
for i in range(N-1):
    for j in range(i+1, N):
        sum_length += math.sqrt((town_location[i][0]-town_location[j][0])**2 + (town_location[i][1]-town_location[j][1])**2)
ans = (sum_length * 2) / N
print(ans)

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

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

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

def path(p):
  distance = 0
  for i in range(len(p)-1):
    distance += sd(p[i],p[i+1])
  return distance

ans = sum(map(path,permutations(towns)))/factorial(n)
print(ans)

Solution (Python):
n=int(input())
x = [0]*n
y = [0]*n
for i in range(n):
    x[i], y[i] = map(int, input().split())
    
l=0
for i in range(n):
    for j in range(n):
        if(i!=j):
            l+=((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5

print(l/n)

Solution (Python):
import numpy
import itertools
import math

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

pattern_list = list(itertools.permutations(town_list, n))

a = int(math.factorial(n))

sum = 0
for j in range(a):
	for k in range(n-1):
		
		x1 = pattern_list[j][k][0]
		x2 = pattern_list[j][k+1][0]
		y1 = pattern_list[j][k][1]
		y2 = pattern_list[j][k+1][1]
		sum += math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)

print(sum/a)

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

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

permus = list(permutations(list(range(n)),n))

def calc(i,j):
    return ((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**0.5

sum = 0
for permu in permus:
    for i in range(n-1):
        sum += calc(permu[i],permu[i+1])

ans = sum/len(permus)
print(ans)

Solution (Python):
import itertools
import math

def main():
    N = int(input())
    XY = []
    for i in range(N):
        x, y = list(map(int, input().split()))
        XY.append([x, y])
    
    CITY = [i for i in range(N)]
    
    p = list(itertools.permutations(CITY, N))
    

    ds = []
    for pi in p:
        dist = 0
        for i in range(N-1):
            cs = pi[i]
            ns = pi[i+1]

            x1 = XY[cs][0]
            y1 = XY[cs][1]
            x2 = XY[ns][0]
            y2 = XY[ns][1]
            d = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
            dist += d
        ds.append(dist)
    ans = sum(ds) / len(ds)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import math
N = int(input())
N_prime = 1
for i in range(1, N + 1):
    N_prime *= i

coordinate = [0] * N
for k in range(N):
    coordinate[k] = [0] * 2
    coordinate[k][0], coordinate[k][1] = map(int, input().split())

N_C_2 = (N * (N - 1)) // 2

sum_dis = 0
for j in range(N-1):
    for h in range(j + 1, N):
        sum_dis += math.sqrt((coordinate[j][0]-coordinate[h][0])
                             ** 2 + (coordinate[j][1] - coordinate[h][1]) ** 2)
        
        
ans = sum_dis * 2 / N
print(ans)

Solution (Python):
import itertools
import math

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

Solution (Python):
import itertools

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

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

for l in itertools.permutations(range(n)):
  for i in range(len(l)-1):
    ans +=  ((x[l[i]]-x[l[i+1]])**2 + (y[l[i]]-y[l[i+1]])**2)**0.5

print(ans/len(list(itertools.permutations(range(n)))))

Solution (Python):
N = int(input())
lis = [[int(i)for i in input().split()]for _ in range(N)]
def leng(i,j):
    global lis
    return ((lis[i][0]-lis[j][0])**2+(lis[i][1]-lis[j][1])**2)**0.5

ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += leng(i,j)
print(ans*2/N)

Solution (Python):
from itertools import permutations

if __name__ == "__main__":
    n = int(input())
    x = [0 for i in range(n)]
    y = [0 for i in range(n)]

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

    ans = 0
    for perm in permutations(range(n)):

        for i in range(len(perm)-1):
            
            ans +=  ((x[perm[i]]-x[perm[i+1]])**2 + (y[perm[i]]-y[perm[i+1]])**2)**0.5
    
    print(ans/len(list(permutations(range(n)))))

Solution (Python):
from itertools import permutations


def dist(x1, y1, x2, y2):
    x = x1 - x2
    y = y1 - y2
    return (x**2+y**2)**0.5


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

ans = 0
cnt = 0
for order in permutations(range(n)):
    cnt += 1
    d = 0
    for s, t in zip(order[:-1], order[1:]):
        x1, y1 = town[s]
        x2, y2 = town[t]
        d += dist(x1, y1, x2, y2)
    ans += d
print(ans/cnt)

Solution (Python):
import statistics
import itertools
import math

def get_distance(from_x, from_y, to_x, to_y) :
    return math.sqrt((to_x-from_x) **2 + (to_y-from_y)**2)

def main() :
    N = int(input())
    dic = {}
    for i in range(N) :
        p = input().split()
        dic[i] = {"x":int(p[0]), "y":int(p[1])}
    
    town_list = [int(i) for i in range(N)]

    route_list = list(itertools.permutations(town_list,N))

    total_distance = 0
    for routes in route_list :
        for i in range(len(routes)-1) :
            current_town = dic[routes[i]]
            next_town = dic[routes[i+1]]
            total_distance += get_distance(current_town["x"], current_town["y"], next_town["x"], next_town["y"])
    
    
    print(total_distance / math.factorial(N))


main()

Solution (Python):
import itertools
import math
N = int(input())
position = [list(map(int, input().split())) for i in range(N)]
l = [0, 1, 2, 3, 4, 5, 6, 7]
length = 0
for v in itertools.permutations(l[:N], N):
    for k in range(N-1):
        length += ((position[v[k]][0] - position[v[k+1]][0]) ** 2 +
                   (position[v[k]][1] - position[v[k+1]][1]) ** 2)**0.5
print(length/math.factorial(N))

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

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

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

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

Solution (Python):
def cal(p,q):
    add=(l[p][0]-l[q][0])**2+(l[p][1]-l[q][1])**2
    return math.sqrt(add)

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


a=[]
ans=0
for i in range(n):
    a.append(i)
for x in itertools.permutations(a): 
    for i in range(n-1):
        ans+=cal(x[i],x[i+1])
for i in range(1,n+1):
    ans/=i
print(ans)

Solution (Python):




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

"""
for i in range(n):
    print(l[i])
"""

def cal(p,q):
    add=(l[p][0]-l[q][0])**2+(l[p][1]-l[q][1])**2
    return math.sqrt(add)


a=[]
ans=0
for i in range(n):
    a.append(i)
for x in itertools.permutations(a): 
    for i in range(n-1):
        ans+=cal(x[i],x[i+1])
for i in range(1,n+1):
    ans/=i
print(ans)

Solution (Python):




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

"""
for i in range(n):
    print(l[i])
"""

a=[]
ans=0
for i in range(n):
    a.append(i)
for x in itertools.permutations(a): 
    for i in range(n-1):
        
        add=(l[x[i]][0]-l[x[i+1]][0])**2+(l[x[i]][1]-l[x[i+1]][1])**2
        add=math.sqrt(add)
        ans+=add
        
    
for i in range(1,n+1):
    ans/=i
print(ans)

Solution (Python):
import math

N = int(input())

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

total = 0

for i in range(N):
    for j in range(N):
        if i != j:
            total += math.sqrt((L[i][0]-L[j][0])**2 + (L[i][1]-L[j][1])**2)
 
print(total/N)

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

m=0

for i in range(N):
    for p in range(N):
        m+=((l[i][0]-l[p][0])**2+(l[i][1]-l[p][1])**2)**(1/2)
print(m/N)

Solution (Python):
from math import sqrt
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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


def dist(p1, p2):
    return sqrt(abs(p1[0]-p2[0])**2 + abs(p1[1]-p2[1])**2)


for i in range(N):
    for j in range(i, N):
        ans += dist(L[i], L[j])

print(ans*2/N)

Solution (Python):
import math

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

for j in range(n):
    for k in range(n):
        dist += math.sqrt(((x[j] - x[k])**2) +  ((y[j] - y[k])**2))
        
fac = math.factorial(n)
kaz = n * (n-1) / 2

bas = dist / 2
print (bas * (n-1) / kaz )

Solution (Python):
import math

N = int(input())
li = [list(map(int,input().split())) for i in range(N)]
ans = []
for i in range(N):
    for j in range(N):
        d = (li[i][0] - li[j][0])**2 + (li[i][1]-li[j][1])**2
        d = math.sqrt(d)
        ans.append(d)
print(sum(ans)/N)

Solution (Python):
import math
import itertools
row_length = int(input())
point = {}
for i in range(row_length):
    point[i] = list(map(int, input().split()))
point_list = [point[x] for x in range(len(point))]
pattern_list = list(itertools.permutations(point_list))



def calc_dist(pat_list): 
    dist = 0
    for i in range(len(pat_list)-1):
        dist += math.sqrt(pow(pat_list[i][0] - pat_list[i+1][0], 2) + pow(pat_list[i][1] - pat_list[i+1][1], 2))
    return dist

ans_dist = 0
for j_list in pattern_list:
    ans_dist += calc_dist(j_list)

print(ans_dist/len(pattern_list))

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

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



import itertools
import numpy as np

def calc_distance(z1,z2):
    v1 = np.array(z1)
    v2 = np.array(z2)
    d = np.linalg.norm(v1-v2,2)
    return d


table = np.zeros((n,n))
for i in range(n):
    for j in range(n):
        if i==j:
            pass
        else:
            z1 = xy[i]
            z2 = xy[j]
            table[i,j] = calc_distance(z1,z2)
        
    


wa = 0
count = 0
for i in itertools.permutations(range(1,n+1)):
    
    count += 1
    for j in range(len(i)-1):
        d = table[i[j]-1,i[j+1]-1]
        
        wa += d

ans = wa/count


print(ans)

Solution (Python):
from math import sqrt
from itertools import combinations
N=int(input())
XY=[list(map(int, input().split())) for _ in range(N)]
print((N-1)*sum(map(lambda z: sqrt((z[0][0]-z[1][0])**2+(z[0][1]-z[1][1])**2), combinations(XY,2)))/len(list(combinations(XY,2))))

Solution (Python):
import sys
import itertools


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    xy = [list(map(int, readline().split())) for _ in range(n)]
    mt = 0
    cnt = 0
    for v in itertools.permutations([i for i in range(n)], n):
        cnt += 1
        for i in range(1, n):
            mt += ((xy[v[i]][0] - xy[v[i-1]][0]) ** 2 + (xy[v[i]][1] - xy[v[i-1]][1]) ** 2) ** 0.5
    print(mt / cnt)


if __name__ == '__main__':
    solve()

Solution (Python):
def main():
    
    n = int(input())
    li = [tuple(map(int, input().split())) for _ in range(n)]

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

    print(l*(n-1)/(n*(n-1)/2))

    


if __name__ == '__main__':
    main()

Solution (Python):
import itertools

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


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

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

candidate = list(itertools.permutations(base, N))

ans = 0
for i in candidate:
        tmp = 0
        for j in range(len(i) - 1):
                tmp += calc_distance(point[i[j]], point[i[j+1]])
        ans += tmp

print(ans / len(candidate))

Solution (Python):
import math

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

def dist(x_1, y_1, x_2, y_2):
  return math.sqrt((x_2 - x_1)**2 + (y_2 - y_1)**2)

for i in range(n):
  for j in range(i, n):
    sum += dist(xy[i][0], xy[i][1], xy[j][0], xy[j][1])

print(sum*2/n)

Solution (Python):
import numpy as np

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

all_diffs = np.expand_dims(X, axis=1) - np.expand_dims(X, axis=0)
distance_matrix = np.sqrt(np.sum(all_diffs**2, axis=-1))
distance = np.sum(distance_matrix) / N

print(distance)

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

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

k=0
for i in range(N):
    for j in range(N):
        if(i!=j):
            k=k+((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)**0.5

print(k/N)

Solution (Python):
import math

a = int(input())
x = []
y = []
total_dis = 0
count = 0
for i in range(a):
  n, m = map(int, input().split())
  x.append(n)
  y.append(m)

for i in range(a):
  x_1 = x[i]
  y_1 = y[i]
  for j in range(a):
    dis = math.sqrt((x_1 - x[j])**2 + (y_1 - y[j])**2)
    count += 1
    total_dis += dis


print(total_dis/(count/a))

Solution (Python):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    return


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

    num = 0
    ans = 0
    l = list(range(N))
    for p in permutations(l):
        num += 1

        for i in range(1, len(p)):
            ans += sqrt((points[p[i - 1]][0] - points[p[i]][0]) ** 2 + (points[p[i - 1]][1] - points[p[i]][1]) ** 2)

    print(ans / num)


if __name__ == '__main__':
    main()

Solution (Python):

import sys
from math import sqrt, factorial
from itertools import permutations

def _i(): return int(sys.stdin.readline().strip())
def _ia(): return [int(x) for x in sys.stdin.readline().strip().split()]


n = _i()
xy = [_ia() for _ in range(n)]

tot = 0
for s in permutations([i for i in range(n)]):
    i = s[0]
    tmp = 0
    for j in s[1:]:
        dx = xy[i][0] - xy[j][0]
        dy = xy[i][1] - xy[j][1]
        tmp += sqrt(dx ** 2 + dy ** 2)
        i = j
    tot += tmp

print(tot / factorial(n))