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

import itertools

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

suml = 0

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

Solution (Python):
import math
import itertools

n = int(raw_input())

pos = list()
for i in range(0, n):
    x, y = map(int, raw_input().split(" "))
    pos.append((x, y))

all_permutations = list(itertools.permutations(pos))
sum = 0.0
for x in all_permutations:
    length = len(x)
    tmp = 0.0
    for s in range(1,length):
        x_1, y_1 = x[s - 1]
        x_2, y_2 = x[s]
        dist = math.sqrt((x_1 - x_2) ** 2 + (y_1 - y_2) ** 2)
        tmp = tmp + dist
    sum = sum + tmp

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

Solution (Python):
import math
import itertools

N = int(input())
x_y_list = [list(map(int,input().split()))for _ in range(N)]
distance_list = []
for i in range(N):
  for j in range(i+1,N,1):
    distance = math.sqrt((x_y_list[i][0]-x_y_list[j][0])**2 + 
                         (x_y_list[i][1]-x_y_list[j][1])**2)
    distance_list.append(distance)
ans = 0
c = list(itertools.combinations(distance_list,N-1))
for i in range(len(c)):
  ans += sum(c[i])
ans = ans/len(c)
print(ans)

Solution (Python):

import sys
from math import hypot
from itertools import permutations
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0

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

prr = list(permutations(li, n))
count=len(prr)
for pr in prr:
    for i in range(n-1):
        
        
        
        
        ans += hypot(xy[pr[i]][0]-xy[pr[i+1]][0],
                        xy[pr[i]][1]-xy[pr[i+1]][1])
print(ans/count)

Solution (Python):
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

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

n = INT()
ll = [MAP() for _ in range(n)]

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

print(ans/math.factorial(n))

Solution (Python):
import numpy as np
import math
N = int(input())
arr = [np.array(list(map(int,input().split()))) for _ in range(N)]
dist_arr = []
for i in range(N):
  for j in range(i+1,N):
    dist_arr.append(np.linalg.norm(arr[i]-arr[j]))

dist_arr = np.array(dist_arr)
dist_arr = dist_arr*(N-1)*2*(math.factorial(N-2))
print((dist_arr.sum())/math.factorial(N))

Solution (Python):
n=int(input())
XY=[list(map(int,input().split())) for _ in range(n)]
fact1,fact2=1,1
for i in range(1,n+1):
    fact1*=i
for i in range(1,n):
    fact2*=i
dist=0
for i in range(n):
    for j in range(i+1,n):
        dist+=((XY[i][0]-XY[j][0])**2+(XY[i][1]-XY[j][1])**2)**0.5
dist*=2*fact2
dist/=fact1
print(dist)

Solution (Python):
n = int(input())
location = []
import math
for _ in range(n):
    x,y  = map(int,input().split())
    location.append([x,y])
s = 0
for i in range(n):
    idex=i
    for j in range(n-1):
        idex +=1
        if idex>=n:
            idex=0
        v1 = abs(location[i][0]-location[idex][0])
        v2 = abs(location[i][1]-location[idex][1])
        v = math.sqrt((v1*v1)+(v2*v2))
        s += v*2
print(s/(2*n))

Solution (Python):
from scipy.spatial import distance

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

dist_mat = distance.cdist(points, points, metric='euclidean')

print(sum(sum(dist_mat))/N)

Solution (Python):
import math
n = int(input())
lst = [[int(j) for j in input().split()] for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(n):
        if lst[i][0] == lst[j][0] and lst[i][1] == lst[j][1]:
            continue
        else:
            a = (lst[i][0] - lst[j][0]) ** 2 + (lst[i][1] - lst[j][1]) ** 2
        ans += math.sqrt(a)
print(ans / n)

Solution (Python):
n = int(input())
c = [[int(i) for i in input().split()] for i in range(n)]
length = []
for i in range(n):
    for j in range(i+1,n):
        length.append(((c[i][0]-c[j][0])**2 + (c[i][1]-c[j][1])**2)**0.5)

print(sum(length)*2/n)

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

ans=0
for i in range(n-1):
    for j in range(n-1-i):
        x=(lis[i][0]-lis[n-1-j][0])**2
        y=(lis[i][1]-lis[n-1-j][1])**2
        l=(x+y)**0.5
        
        ans+=l

ans=ans*2/n

print(ans)

Solution (Python):
import math

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

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

print(2 * d / N)

Solution (Python):

import numpy as np
N = int(input())
x = np.zeros(N)
y = np.zeros(N)
for i in range(N):
  x[i], y[i] = map(int, input().split())

sum = 0
for i in range(N):
  for j in range(i+1, N):
    sum += np.sqrt(np.square(x[i] - x[j]) + np.square(y[i] - y[j]))

print(sum*2/N)

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

Solution (Python):
import math
import itertools

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

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

print(2*ans/n)

Solution (Python):
import itertools

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

for v in itertools.permutations(xy, N):
    p.append(v)

for i in range(len(p)):
    for j in range(N-1):
        cnt += ((p[i][j][0] - p[i][j+1][0])**2 + (p[i][j][1] - p[i][j+1][1])**2) ** 0.5

ans = cnt / len(p)

print(ans)

Solution (Python):

import numpy as np
N = int(input())
P = np.array([input().split() for _ in range(N)], dtype=int)

LEN = np.zeros((N,N), dtype=float)

for i in range(N):
  for j in range(N):
    LEN[i,j] = sum((P[i] - P[j])**2)**0.5

rote = 0


def getlen(before=(), after=()):
  if len(after) == 0:
    global rote
    rote += 1
    return sum([LEN[before[i], before[i+1]] for i in range(N-1)])
  t = 0
  for i in range(len(after)):
    t += getlen(before + (after[i],), after[:i] + after[i+1:])
  return t

t = getlen((), tuple(range(N)))

print(t / rote)

Solution (Python):
import itertools
import math
def dist(x1,y1,x2,y2):
    r = math.sqrt( (x1-x2)**2 + (y1-y2)**2 )
    return r

n = int(input())
r = [ list(map(int, input().split())) for i in range(n) ]
id = range(n)
idlst = list(itertools.permutations(id))
N = math.factorial(n)
distance = 0
for i in range(N):
    for j in range(1,n):
        pre = idlst[i][j-1]
        now = idlst[i][j]
        distance += dist(r[pre][0],r[pre][1],r[now][0],r[now][1])

ans = distance / N
print(ans)

Solution (Python):
import logging
import math

logging.basicConfig(level=logging.INFO, format="%(message)s")


def main():
    N = int(input())
    L_2 = [list(map(int, input().split())) for _ in range(N)]
    logging.info("Hello!")

    logging.info(L_2)

    sum = 0
    for i in range(N):
        for j in range(i + 1, N):
           sum += math.sqrt((L_2[i][0] - L_2[j][0]) ** 2 + (L_2[i][1] - L_2[j][1]) ** 2)

    print('{:.10f}'.format(sum * 2 / N))
    
    
if __name__ == "__main__":
    main()

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

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

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


length = [[0]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        length[i][j] = ((pointx[i]-pointx[j])**2 + (pointy[i]-pointy[j])**2)**(1/2)

total = sum([sum([length[i][j] for i in range(n)]) for j in range(n) ])
print(total/(n**2-n)*(n-1))

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


x = []
y = []
for i in range(N):
    tmp = [int(i) for i in input().split()]
    x.append(tmp[0])
    y.append(tmp[1])

d_list = []
for i in range(N):
    for j in range(N):
        dx = x[i] - x[j]
        dy = y[i] - y[j]
        distance = (dx**2 + dy**2)**(0.5)
        d_list.append(distance)

print(sum(d_list)/N)

Solution (Python):
import math
import itertools
n = int(input())
city = [[int(i) for i in input().split()] for j in range(n)]


allnum = math.factorial(n)

city_num = [int(i) for i in range(n)]

ans = 0

for v in itertools.permutations(city_num):
    
    pre = -1
    for i in v:
        if pre == -1:
            pre = i
            continue
        ans += math.sqrt((city[i][0] - city[pre][0]) **
                         2 + (city[i][1] - city[pre][1]) ** 2)
        pre = i

print(ans/allnum)

Solution (Python):
N=int(input())
X =  [0] * N
Y =  [0] * N
for i in range(N):
    x,y = map(int,input().split())
    X[i] = x
    Y[i] = y
long = 0
for i in range(N-1):
    for j in range(i+1,N):
        l = ((X[i] - X[j])**2 + (Y[i] - Y[j])**2)**(1/2)
        long += l

ans = long*2/N
print(ans)

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

Solution (Python):
import itertools
import math
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())
def fact(N):
    if N == 0:
        return 1
    return N * fact(N - 1)

total = 0
for p in itertools.permutations(range(N)):
    dis = 0
    for i in range(len(p) -1):
        dis += math.sqrt((x[p[i + 1]] - x[p[i]]) ** 2 + (y[p[i + 1]] - y[p[i]]) ** 2)
    total += dis
print(total / fact(N))

Solution (Python):
import numpy as np
n = int(input())
c = []
for _ in range(n):
    x, y = map(int, input().split())
    c.append((x, y))

s = 0
for i in range(n):
    for j in range(n):
        xi, yi = c[i]
        xj, yj = c[j]
        d = np.sqrt((xi - xj)**2 + (yi - yj)**2)
        s += d
print(s / n)

Solution (Python):
import sys
import math
import itertools

def solve(n, p):
    s = 0
    patterns = list(itertools.permutations(range(n)))
    for pattern in patterns:
        
        for i in range(n-1):
            s += math.sqrt((p[pattern[i]][0] - p[pattern[i+1]][0])**2 + (p[pattern[i]][1] - p[pattern[i+1]][1])**2)
    print(s / len(patterns))


if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    p = []
    for _ in range(n):
        p.append(list((map(int, sys.stdin.readline().strip().split(" ")))))
    solve(n, p)

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

result = 0

for i in range(N):
  for j in range(i+1,N):
    dis = (XY[i][0] - XY[j][0])**2 + (XY[i][1] - XY[j][1])**2
    dis = dis**0.5

    result += dis

print((result * 2)/N)

Solution (Python):
import sys
import itertools as it
from collections import defaultdict
sys.setrecursionlimit(10**6)

ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    N=ii()
    x=[]
    y=[]
    dec=defaultdict(list)
    dec_sum=0
    dec_ave=0
    cnt=0
    for i in range(N):
        X,Y=mis()
        x.append(X)
        y.append(Y)
    for i in range(N):
        for j in range(N):
            dec[i].append(((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5)
    for ll in it.permutations(range(N)):
        now=ll[0]
        cnt+=1
        for i in ll[1:]:
            dec_sum+=dec[now][i]
            now=i
    print(dec_sum/cnt)

    


if __name__ == "__main__":
    main()

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


def main():
    N = int(stdin.readline().rstrip())
    xys = [[int(i) for i in stdin.readline().rstrip().split()] for _ in range(N)]
    perm = list(permutations(range(N)))
    results = []
    for points in perm:
        dis = 0
        for i, point in enumerate(points[:-1]):
            p1 = point
            p2 = points[i + 1]
            x1, y1 = xys[p1]
            x2, y2 = xys[p2]
            dis += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
        results.append(dis)
    print(sum(results) / len(results))


if __name__ == "__main__":
    main()

Solution (Python):


import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions
from operator import itemgetter


import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())

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

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

keiros = list(permutations(towns))

sum = 0

def dist(A, B):
	sum = (A[0] - B[0])**2 + (A[1] - B[1])**2
	sum = sum ** 0.5
	return sum


for keiro in keiros:
	total = 0
	for i in range(N - 1):

		A = XY[keiro[i]]
		B = XY[keiro[i + 1]]
		total += dist(A, B)
	sum += total



def fact(n, mod=1000000007):
	ans = 1
	for i in range(n):
		ans *= i + 1
		if mod != 0 and ans >= mod:
			ans = ans % mod
	return ans

sum /= fact(N)

print(sum)

Solution (Python):
import itertools
import math

N = int(input())
List=[list(map(int,input().split())) for i in range(N)]
roots = list(itertools.permutations(range(N)))
sum_length = 0
for root in roots:
    first_city = 100 
    for city in root:
        if first_city == 100:
            first_city = city
            continue
        x = List[first_city][0] - List[city][0]
        y = List[first_city][1] - List[city][1]
        sum_length += math.sqrt(pow(x,2)+pow(y,2))
print(sum_length/len(roots))

Solution (Python):
import itertools
import math

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

rootlis = list(itertools.permutations(dislis))

dis = 0
for lis in rootlis:
    for j in range(n-1):
        dis += ((int(lis[j][0])-int(lis[j+1][0])) ** 2 + (int(lis[j][1])-int(lis[j+1][1])) ** 2) ** (1/2)


print(str(dis/math.factorial(n)))

Solution (Python):
import math
import itertools

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

Solution (Python):
def dist(A, B):
    return ((A[0]-B[0])**2 + (A[1]-B[1])**2)**(0.5)

from math import factorial
from itertools import permutations
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
dists = 0
for l in permutations(XY):
    for i in range(len(l)-1):
        dists += dist(l[i], l[i+1])

print(dists/factorial(N))

Solution (Python):

import sys
import heapq
import math
import itertools

INF = float("inf")


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


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

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

    ans = 0
    data = [i for i in range(0, N)]
    routes = list(itertools.permutations(data))
    for route in routes:
        
        for i in range(0, len(route) - 1):
            
            test = dis(x[route[i]], y[route[i]], x[route[i+1]], y[route[i+1]])
            
            ans += test

    print(ans / len(routes))


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
import itertools

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

def dist(a,b):
  return ((a[0]-b[0])**2+(a[1]-b[1])**2)**(1/2)
  
a=[]
for i in range(n):
  b=[]
  for j in range(n):
      b.append(dist(s[i],s[j]))
  a.append(b)

t=np.arange(n)      

sum=0
k=0
for v in itertools.permutations(t, n):
  k+=1
  for m in range(n-1):
    sum += a[v[m]][v[m+1]]

print(sum/k)

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

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

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

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

    print(tmp*2/n)



    

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

N = int(input())
xy = []
for _ in range(N):
  xy.append(list(map(int, input().split())))
  
xy = np.array(xy)
d = np.linalg.norm(xy[np.newaxis,:,:] - xy[:,np.newaxis,:], axis=2)

print(np.sum(d)/N)

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

A=[[0,0] for i in range(N)]
B=[0]*(N*(N-1)//2)
for i in range(N):
    A[i][0],A[i][1]=map(int,input().split())
c=0
for i in range(N):
    for j in range(i+1,N):
        B[c]=((A[i][0]-A[j][0])**2+(A[i][1]-A[j][1])**2)**0.5
        c+=1

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

print(sum(B)*(N-1)/(D))

Solution (Python):


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

Solution (Python):
import itertools
import math

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

ave = 0
patterns = list(itertools.permutations(towns))
for path in patterns:
    distance = 0
    for i in range(1, len(path)):
        diff_x = path[i][0] - path[i-1][0]
        diff_y = path[i][1] - path[i-1][1]
        distance += math.sqrt(diff_x ** 2 + diff_y ** 2)
    ave += distance
print(ave / len(patterns))

Solution (Python):
import itertools
import math

N = int(input())
input_list = [input() for i in range(N)]
count = 0
sum_length = 0

for points in itertools.permutations(input_list, N):
    length = 0
    for i in range(N-1):
        x, y = map(int, points[i].split())
        next_x, next_y = map(int, points[i + 1].split())
        length += math.sqrt((next_x - x) ** 2 + (next_y - y) ** 2)
    sum_length += length
    count += 1

print(sum_length/count)

Solution (Python):
import itertools
import math
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
num = [i for i in range(N)]
C = []
sum = 0
for _ in itertools.permutations(num):
    C.append(list(_))
for a in C:
    for i in range(len(a)-1):
        sum += math.sqrt((xy[a[i]][0]-xy[a[i+1]][0])**2+(xy[a[i]][1]-xy[a[i+1]][1])**2)
print(sum/math.factorial(N))

Solution (Python):
from itertools import permutations
import math


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

lst = list(range(N)) 
distance = 0

for root in permutations(lst):
    for i in range(N-1):
        distance += math.sqrt((xy[root[i]][0]-xy[root[i+1]][0])**2
                              + (xy[root[i]][1] -xy[root[i+1]][1])**2)
distance /= math.factorial(N)
print(distance)

Solution (Python):



import math

N = int(input().strip())
pos_list = []

for _ in range(N):
    obj = input().strip().split(' ')
    x = float(obj[0])
    y = float(obj[1])
    pos_list.append((x, y))

total = 0
for i in range(N):
    xi, yi = pos_list[i]
    for j in range(i + 1, N):
        xj, yj = pos_list[j]
        dist = math.sqrt((xi - xj) ** 2 + (yi - yj) ** 2)
        total += dist

res = total * 2 / N
print(res)

Solution (Python):
import math
n = int(input())
x = [0]*n
y = [0]*n
s = 1
for i in range(n):
    x[i], y[i] = map(int, input().split())
    s *= (i+1)
l = 0
for i in range(n):
    for j in range(n):
        if i > j:
            l += math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
s2 = s//n

print(l*s2*2/s)

Solution (Python):
from itertools import permutations


N = int(input())

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

routes = list(permutations(range(N)))

tmp = 0
cnt = 0
for route in routes:
    for i in range(1, N):
        FROM = route[i-1]
        TO = route[i]
        tmp += ((XY[FROM][0]-XY[TO][0])**2 + (XY[FROM][1]-XY[TO][1])**2)**0.5
    cnt+=1

print(tmp/cnt)

Solution (Python):
n = int(input())
X, Y= [0]*n,[0]*n

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

def kaijo(x):
    if x==1:
        return 1
    else:
        return x*kaijo(x-1)

dis = 0.0
for i in range(n):
    for j in range(n):
        dis += (((X[i]-X[j])**2+(Y[i]-Y[j])**2)**0.5)*kaijo(n-1)


print(dis/kaijo(n))

Solution (Python):
import math
import itertools

n = int(input())

p = []
for i in range(n):
    x, y = map(int, input().split())
    p.append((x, y))
    
def dist(p1, p2):
    return math.sqrt(math.pow(p1[0]-p2[0], 2) + math.pow(p1[1]-p2[1], 2))
    
patterns = list(itertools.permutations(list(range(n))))


total = 0
for pattern in patterns:
    for i in range(n):
        if i+1 == n:
            continue
        total += dist(p[pattern[i]], p[pattern[i+1]])
        
print(total/len(patterns))

Solution (Python):
N = int(input())
s = []
for i in range(N):
  s.append([int(x) for x in input().split()])
import math
num = math.factorial(N)
n = N-1
p = sum(range(N))
a = num * n//p


d = 0
for i in range(len(s)-1):
  t = s[i]
  for j in range(i+1,len(s)):
    k = s[j]
    d += math.sqrt((t[0]-k[0])**2+(t[1]-k[1])**2)
print(a*d/num)

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


ans=0
P=list(itertools.permutations([i for i in range(n)]))
for p in P:
  for i in range(1,len(p)):
    xi,xj=XY[p[i-1]][0],XY[p[i]][0]
    yi,yj=XY[p[i-1]][1],XY[p[i]][1]
    ans+=math.sqrt((xi-xj)**2 + (yi-yj)**2)
print(ans/math.factorial(n))

Solution (Python):
import sys
import math
import itertools

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def pp(n):
    c = 1
    for i in range(1, n+1):
        c *= i
    return c


def solve(inputs):
    towns = list(map(string_to_int, inputs))

    distances = []
    sum_distance = 0
    for t in towns:
        ds = []
        for t2 in towns:
            d = math.sqrt((t[0] - t2[0]) ** 2 + (t[1] - t2[1]) ** 2)
            ds.append(d)
            sum_distance += d
        distances.append(ds)

    per = list(itertools.permutations(range(0, len(towns))))
    sum_d = 0
    count = 0
    for p in per:
        d = 0
        for i, index in enumerate(p):
            if i == len(towns) - 1:
                break
            d += distances[index][p[i+1]]
        sum_d += d
        count += 1
    return sum_d / count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)

Solution (Python):
import math


def main():
    N = int(input())
    x = []
    y = []
    total = 0
    
    for i in range(N):
        a, b = map(int, input().split())
        x.append(a)
        y.append(b)
    for i in range(N):
        now_x = x[i]
        now_y = y[i]
        for j in range(N):
            if i == j:
                continue
            total += math.sqrt(abs(now_x - x[j]) ** 2 + abs(now_y - y[j]) ** 2) * math.factorial(N - 1)
    print("{0:.7f}".format(total / math.factorial(N)))

if __name__ == "__main__":
    main()

Solution (Python):
import math

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

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

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

sum = 0
M = math.factorial(N-1)
for i in range(N):
    for j in range(N):
           sum += math.sqrt((x[j]-x[i])*(x[j]-x[i]) + (y[j]-y[i])*(y[j]-y[i])) * M


print(sum/math.factorial(N))

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

f = math.factorial(N)
a = N * (N - 1) // 2


sumd = 0
for n in range(N - 1):
    for m in range(n, N):
        sumd += ((XY[n][0] - XY[m][0]) ** 2 + (XY[n][1] - XY[m][1]) ** 2) ** 0.5

print (sumd   / N * 2)

Solution (Python):
import numpy as np
import math

N = int(input())
ave = []
ans = 0.0

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

for i in range(N):
    Sum = 0
    for j in range(N):
        if(i == j):
            continue
        else:
            Sum += math.sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)

    ans += (Sum / float(N))

print(ans)

Solution (Python):
import itertools
import math


def find_path_len(p, distances):
    dist = 0
    for i in range(1, n):
        dist += distances[p[i]][p[i-1]]
    return dist


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

pathes = list(itertools.permutations(range(0,n)))

distances = [[0 for _ in range(n)] for _ in range(n)]

for i in range(n):
    for j in range(n):
        s = a[i]
        f = a[j]
        d = math.sqrt((s[0] - f[0]) ** 2 + (s[1] - f[1]) ** 2)
        distances[i][j] = d
        distances[j][i] = d

pathes_length = list(map(lambda x: find_path_len(x, distances), pathes))

print(sum(pathes_length) / len(pathes_length))

Solution (Python):
n = int(input())
x, y = [None]*n, [None]*n

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


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


total = 0
for i in range(n-1):
    for j in range(i+1, n):
        total += dist(i, j)

print(2*total/n)

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

Solution (Python):
import math
import itertools

N = int(input())
town = [0]*N

for i in range(N):
    town[i] = [int(i) for i in input().split()]
    
k = math.factorial(N)

zenbu = list(itertools.permutations(town))

kyori = 0

for i in zenbu:
    for j in range(N-1):
        kyori += math.sqrt((i[j][1]-i[j+1][1])**2 + (i[j][0]-i[j+1][0])**2)

print(kyori/k)

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

pair = math.factorial(n) // math.factorial(n-2)
avg = 0
for x1, y1 in place:
  for x2, y2 in place:
    avg += math.sqrt((x1-x2)**2 + (y1-y2)**2)
avg = avg / pair

result = avg * (n - 1)
print(result)

Solution (Python):

import numpy as np
from math import factorial
from itertools import permutations

def solve():
    N = int(input())
    Z = np.zeros((N,1,2))
    for i in range(N):
        x, y = map(int, input().split())
        Z[i] = x,y
    W = Z.swapaxes(0,1)
    return str(np.sqrt(((Z-W)**2).sum(axis=-1)).sum()*factorial(N-1)/factorial(N))

if __name__ == '__main__':
    print(solve())

Solution (Python):
import math
from itertools import permutations


def length(p, q):
    return math.sqrt((p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2)


n = int(input())
l = [list(map(int, input().split(" "))) for i in range(n)]
orders = list(permutations([i for i in range(n)]))

allL = 0

for i in range(len(orders)):
    order = orders[i]
    d = [length(l[order[j]], l[order[j + 1]]) for j in range(n - 1)]
    allL += sum(d)

print(allL / len(orders))

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

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    XY = [LIST() for _ in range(N)]

    pmt = list(permutations(range(N)))

    dist = 0
    for p in pmt:
        for cur, nxt in zip(p[:N-1], p[1:]):
            dist += sqrt((XY[nxt][0] - XY[cur][0])**2 + (XY[nxt][1] - XY[cur][1])**2)

    print(dist/len(pmt))


if __name__ == '__main__':
    main()