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



Sample input:
3
0 0
1 0
0 1


Sample output:
2.2761423749

Submission status: Accepted

Solution code:
n=int(input())
towns=[None]*n
for i in range(n):
  x,y=map(int,input().split())
  towns[i]=[x,y]
routes=0
import math
for i in range(len(towns)):
  for j in range(i+1,len(towns)):
    routes+=math.sqrt((towns[i][0]-towns[j][0])**2+(towns[i][1]-towns[j][1])**2)

# routes 全ルートの合計
if n==2:
  print(routes)
else:
  print(routes*2/n)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
x = np.array([input().split() for _ in range(n)], dtype=np.int)
norm2 = np.sum(x * x, axis=1)
dist = -2. * x.dot(x.T) + norm2
dist = np.sqrt(dist.T + norm2)
print(dist.sum() / n)

Submission status: Accepted

Solution code:
import math
n = int(input())
ar = []

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

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

print(sum_ / n)

Submission status: Accepted

Solution code:
import itertools
import math
n=int(input())
xys=[list(map(int,input().split())) for _ in [0]*n]
rs=0
l=lambda xy1,xy2:math.sqrt((xy1[0]-xy2[0])**2+(xy1[1]-xy2[1])**2)
f=0
for p in itertools.permutations(range(n), n):
  f+=1
  r=0
  for i in range(n-1):
    r+=l(xys[p[i+1]], xys[p[i]])
  rs+=r
print(rs/f)

Submission status: Accepted

Solution code:
import math
import itertools
N = int(input())
x = [list(map(int,input().split(' '))) for i in range(N)]
length = range(N)
ans = []

for i in itertools.permutations(length): #1,2,3 231

   result = []
   for i1 in range(len(i)-1):
       result.append(math.sqrt((x[i[i1]][0]-x[i[i1+1]][0])**2 + (x[i[i1]][1]-x[i[i1+1]][1]) **2))


   ans.append(sum(result))

print(sum(ans)/len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import namedtuple
from math import sqrt

Coordinates = namedtuple('Coordinates', 'idx x y')


def calc_dist(a: Coordinates, b: Coordinates) -> float:
    return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2))


n = int(input())

Coods = []
for idx in range(n):
    x, y = map(int, input().split())
    Coods.append(Coordinates(idx=idx, x=x, y=y))

ret = 0
for a in Coods:
    for b_idx in range(a.idx + 1, n):
        if a.idx == b_idx:
            continue
        b = Coods[b_idx]
        ret += calc_dist(a, b)
ret *= 2 / n
print(ret)

# 特定の2点を固定し、それ以外を並べる + 固定順を逆にする
# [oo]ooo... これを4個の要素の並び替えを見なす
# (n-1)! * 2!
# この2点間の移動が含まれる並び順は、(n-1)! * 2!通り
# 各2点間の距離の総和*(n-1)! * 2!通り / n!
# 各2点間の距離の総和*2/n

Submission status: Accepted

Solution code:
import math

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

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

for i in range(n):
    for j in range(n):
        sum += math.sqrt(pow((x[i]-x[j]),2) + pow((y[i]-y[j]),2))
        #print(x[i],y[i],x[j],y[j],sum)
print(sum/n)

Submission status: Accepted

Solution code:
# C - Average Length
from math import sqrt
import numpy as np
N = int(input())
length = np.zeros(int(N * (N - 1) / 2))
point = [0] * N
for i in range(N):
    x, y = map(int, input().split())
    point[i] = (x, y)
    
k = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        length[k] = sqrt((point[i][0] - point[j][0]) ** 2 + (point[i][1] - point[j][1]) ** 2)
        k += 1
        
print(length.sum() * 2 / N)

Submission status: Accepted

Solution code:
import itertools
import math
N = int(input())
A =[0]*N
B =[0]*N
su =0
count=0
for i in range(N):
  A[i],B[i] =map(int, input().split())
for i in itertools.permutations(range(N)):
  count +=1
  for j in range(1,len(i)):
    su += math.sqrt((A[i[j]]-A[i[j-1]])**2+(B[i[j] ]-B[i[j-1]])**2)
print(su/count)

Submission status: Accepted

Solution code:
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
CNT = math.factorial(N)
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        else:
            SUM = SUM + math.sqrt((X[i] - X[j])**2 + (Y[i] - Y[j])**2)

print(SUM/N)

Submission status: Accepted

Solution code:
import numpy as np
 
N = int(input())
A = [input().split() for _ in range(N)]
# sum(A, []) 次元をフラット化
XY = np.array(sum(A, []),np.int64)

X = XY[::2] # x部分
Y = XY[1::2] # y部分
# Noneで次元を追加 X[:, None] shap(N,1)
dx = X[:,None] - X[None,:] 
dy = Y[:,None] - Y[None,:]

dist_mat = (dx*dx + dy*dy)**.5
ans = dist_mat.sum() / N
print(ans)

Submission status: Accepted

Solution code:
import math
from itertools import permutations 
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
#print('a')
#print(a)
#print()
List = list(range(n))
n_list = list(permutations(List,n))
#print('n_list')
#print(n_list)
#print()
length = 0
LENGTH = 0
for i in range(len(n_list)):
    for j in range(len(n_list[i])):
        if j+1 != n:
            length += math.sqrt((a[n_list[i][j]][0]-a[n_list[i][j+1]][0])**2+(a[n_list[i][j]][1]-a[n_list[i][j+1]][1])**2)
            #print(length)
    #print(length)  
    LENGTH += length
print(length/len(n_list))

Submission status: Accepted

Solution code:
import math

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

L = []
for i in range(N):
    for j in range(i+1, N):
        L.append( math.sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) ) )
print(sum(L)*2/N)

Submission status: Accepted

Solution code:
import itertools

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

perm = list(itertools.permutations(list(range(n))))
m = len(perm)
ans = 0
for p in perm:
    tmp = 0
    limit = len(p)
    for pi in range(limit - 1):
        a = (table[p[pi]][0] - table[p[pi + 1]][0]) ** 2
        b = (table[p[pi]][1] - table[p[pi + 1]][1]) ** 2
        g = (a + b) ** 0.5
        tmp += g
    ans += tmp

print(ans / m)

Submission status: Accepted

Solution code:
n = int(input())
x = []
y = []

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

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
xy = [inpl() for i in range(n)]
cnt = 0
for i in itertools.permutations(xy):
    for j in range(n-1):
        cnt += math.sqrt(abs(i[j+1][0] - i[j][0])**2+abs(i[j+1][1] - i[j][1])**2)
print(cnt/math.factorial(n))

Submission status: Accepted

Solution code:
n = int(input())

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

from math import sqrt,factorial
from itertools import permutations

ans = 0

for zz in permutations(z):
  for i in range(n-1):
    ans += sqrt((zz[i][0] - zz[i+1][0]) ** 2 + (zz[i][1] - zz[i+1][1]) ** 2)

print(ans/factorial(n))

Submission status: Accepted

Solution code:
import math

N = int(input())

fact_n = math.factorial(N)

towns = []

for i in range(N):
    a, b = map(int, input().split())
    towns.append((a, b))

ans = 0


for i in range(N):
    for j in range(N-i-1):
        town_a = towns[i]
        town_b = towns[j+i+1]
        dist = math.sqrt((town_a[0] - town_b[0])**2 + (town_a[1] - town_b[1])**2)
        ans += 2 * math.factorial(N-1) * dist

ans = ans / fact_n


print(ans)

Submission status: Accepted

Solution code:
n,*L=map(int,open(0).read().split());r=range(0,2*n,2);print(sum(((L[i]-L[j])**2+(L[i+1]-L[j+1])**2)**.5for i in r for j in r)/n)

Submission status: Accepted

Solution code:
n = int(input())
s = [0]*n
for i in range(n):
    s[i] = list(int(x) for x in input().split())

key = [[0]*n for i in range(n)]

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

ans = ans * 2 / n
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
T=[list(map(int,input().split())) for i in range(N)]
X=0
c=1
for i in range(N):
  for j in range(N):
    X=X+((abs(T[i][0]-T[j][0]))**2+(abs(T[i][1]-T[j][1]))**2)**0.5
print(X/N)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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


def fac(n):
    ans = 1
    while n > 1:
        ans *= n
        n -= 1

    return ans


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


def chker(xylist):
    now = xylist[0]
    remain = xylist[1:]
    pathsum = 0

    while remain:
        for item in remain:
            pathsum += distance(now, item)

        now, remain = remain[0], remain[1:]

    return pathsum


print(chker(_xylist) * 2 / _n)

Submission status: Accepted

Solution code:
import itertools

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

key = [[False]*n for i in range(n)]

for i in range(n):
    for j in range(i+1, n):
        key[i][j] = ((s[i][0]-s[j][0])**2+(s[i][1]-s[j][1])**2)**0.5
ans = 0
key_permnutation = list(int(x) for x in range(n))
for key_list in itertools.permutations(key_permnutation):
    for i in range(n-1):
        p, q = key_list[i], key_list[i+1]
        p, q = min([p, q]), max([p, q])
        ans += key[p][q]

for i in range(1, n+1):
    ans /= i
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import pprint
import math

def solve(arrb, arra):
    ret = 0
    len_arrb = len(arrb)
    if len_arrb == 0:
        return dist_all(arra)
    for i in range(len_arrb):
        arrb_t = arrb[:]
        pop_arrb = arrb_t.pop(i)
        ret += solve(arrb_t, arra + [pop_arrb])
    return ret

def dist_all(arr):
    sum_dist = 0
    for i in range(len(arr) - 1):
        sum_dist += dist(arr[i], arr[i + 1])
    return sum_dist

def dist(arr1, arr2):
    return (((arr2[0] - arr1[0]) ** 2) + ((arr2[1] - arr1[1]) ** 2)) ** 0.5

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

print(solve(xy, []) / math.factorial(n))

Submission status: Accepted

Solution code:
from itertools import combinations
from math import hypot

N, *XY = map(int, open(0).read().split())

print("{:.9f}".format(sum(hypot(ax - bx, ay - by) for (ax, ay), (bx, by) in combinations(zip(*[iter(XY)] * 2), 2)) * 2 / N))

Submission status: Accepted

Solution code:
import math
N = int(input())
x = [0]*N
y = [0]*N
for i in range(N):
    x[i],y[i] = map(int,input().split())
at=[]
for i in range(N):
    for j in range(N):
        ea = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
        at.append(ea)
da = 0
for ag in at:
    da += ag
avg = da * math.factorial(N - 1) / math.factorial(N)
print(avg)

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
  l.append(list(map(int,input().split())))
ans=0
if n==2:
  print(((l[0][0]-l[1][0])**2+(l[0][1]-l[1][1])**2)**(1/2))
else:
  for i in range(n-1):
    for j in range(i+1,n):
      ans+=((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)**(1/2)
  print(2*ans/n)

Submission status: Accepted

Solution code:
import itertools
N=int(input())
xy=[0]*N

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

perm = list(itertools.permutations(range(N),N))

ans=0
for p in perm:
    for i,_ in enumerate(p[1:]):
        xi = xy[p[i-1]][0]
        xj = xy[p[i]][0]
        yi = xy[p[i-1]][1]
        yj = xy[p[i]][1]
        result = ((xi-xj)**2 + (yi-yj)**2) ** (1/2)
        ans+=result

print(ans/len(perm))

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import math

N = int(input())
x = list()
y = list()
sum = 0

def dist(i,j):
    dx = x[i] - x[j]
    dy = y[i] - y[j]
    return math.sqrt(dx*dx + dy*dy)

if __name__ == '__main__':
    for i in range(N):
        x_i,y_i = map(int,input().split())
        x.append(x_i)
        y.append(y_i)

    for i in range(N):
        for j in range(N):
            sum += dist(i,j)

    print(sum/N)

Submission status: Accepted

Solution code:
N = int(input())
x = []
y = []
for i in range(N):
  x1,y1 = map(int,input().split())
  x.append(x1)
  y.append(y1)
s = 0

for i in range(N - 1):
  for j in range(i + 1, N):
    s += ((x[i] - x[j])**2 + (y[i] - y[j])**2)**(1/2)
    
print(s * 2 / N)

Submission status: Accepted

Solution code:
import math
import itertools

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

dist = [[0 for a in range(N)] for b in range(N)]

def calcdist(i, j):
  if i > j:
    return dist[j][i]
  else:
    return dist[i][j]

for i in range(N):
  for j in range(i, N):
    if i != j:
      x_i = XY[i][0]
      y_i = XY[i][1]
      x_j = XY[j][0]
      y_j = XY[j][1]
      dist[i][j] = math.sqrt((x_i-x_j)**2 + (y_i-y_j)**2)

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

total = 0
for a in permlist:
  for b in range(len(a)-1):
    total += calcdist(a[b], a[b+1])
print(total/math.factorial(N))

Submission status: Accepted

Solution code:
import itertools
import math
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
ans=0
it=list(itertools.permutations(range(n),n))
for i in it:
    tmpx=l[i[0]][0]
    tmpy=l[i[0]][1]
    tmp=0
    for j in i[1:]:
        tmp+=math.sqrt((tmpx-l[j][0])**2+(tmpy-l[j][1])**2)
        tmpx=l[j][0]
        tmpy=l[j][1]
    ans+=tmp
print(ans/math.factorial(n))

Submission status: Accepted

Solution code:
import math

def main():
  n = int(input())
  cities = []
  for i in range(0, n):
    inputs = input().split(" ")
    cities.append([int(inputs[0]), int(inputs[1])])
  
  result = 0
  for i in range(0, n-1):
    for j in range(i+1, n):
      result += distance(cities[i], cities[j])
  
  print(result*factorial(n-1)*2/factorial(n))

def factorial(n):
  if n <= 0:
    return 0
  if n == 1:
    return 1
  else:
    return factorial(n-1) * n

def distance(pos1, pos2):
  return math.sqrt(math.pow(pos1[0] - pos2[0], 2) + math.pow(pos1[1] - pos2[1], 2))

main()

Submission status: Accepted

Solution code:
import math

def perms(n, li, result):
	li_l = len(li)
	result_l = len(result)
	if n == 0:
		return result
	if result_l == 0:
		for elem in li:
			result.append(str(elem))
		n -= 1
	else:
		for elem in li:
			for r in result[:result_l]:
				flag = True
				
				for r_e in r:
					if str(elem) == r_e:
						flag = False
						break
				if flag:
					r += str(elem)
					result.append(r)
				
		result = result[result_l:]
		n -= 1
	return perms(n, li,result)

def total(N, result, towns):
	total_dist = 0
	for elem in result:
		for ind in range(N-1):
			total_dist += dist(towns[int(elem[ind])], towns[int(elem[ind+1])])
	return total_dist

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


if __name__ == '__main__':
  N = int(input())
  li = list(range(N))
  result = []
  towns = []
  for n in range(N):
  	x, y = map(float, input().split())
  	towns.append((x,y))
  result = perms(N, li, result)
  total_dist = total(N, result, towns)
  print(total_dist/len(result))

Submission status: Accepted

Solution code:
# coding: utf-8
from itertools import permutations
from math import sqrt

def calc(x0, y0, x1, y1):
    return sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2)

N = int(input())
X, Y = [], []
for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    
ll = list(permutations(range(N)))
ls =[]

for l in ll:
    tmp = 0
    x0, y0 = X[l[0]], Y[l[0]]
    for j in range(1, N):
        x1, y1 = X[l[j]], Y[l[j]]
        tmp += calc(x0, y0, x1, y1)
        x0, y0 = x1, y1
    ls.append(tmp)
    
print(sum(ls) / len(ll))

Submission status: Accepted

Solution code:
#191116 B

import math
import itertools

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

if __name__ == "__main__":
    N = int(input())
    point = []
    for i in range(N):
        tmpx,tmpy = list(map(int,input().split()))
        point.append([tmpx,tmpy])
    sumlist = []
    for target in itertools.permutations(point):
        tmpsum = 0
        for i in range(1,len(target)):
            tmpsum = tmpsum + calcdis(target[i-1],target[i])
        sumlist.append(tmpsum)

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

Submission status: Accepted

Solution code:
def kyori(a, b, c, d):
    x = (int(a) - int(b)) ** 2
    y = (int(c) - int(d)) ** 2
    z = (x + y) ** 0.5
    return z

n = int(input())
city_list = [0]*n
total_kyori = 0.0

for i in range(n):
  city_list[i] = input().split(' ')

for j in range(n):
  for k in range(n):
    ret_kyori = kyori(city_list[j][0], city_list[k][0], city_list[j][1], city_list[k][1])
    total_kyori += ret_kyori

ret_value = total_kyori / n
print(ret_value)

Submission status: Accepted

Solution code:
import math

N= int(input())
a = math.factorial(N)
xy = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(len(xy)):
    for j in range(len(xy)):
        if i != j:
            ans += math.sqrt((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2)
print(ans / N)

Submission status: Accepted

Solution code:
import math

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

# 合計距離の計算
distance_sum = 0
for i in range(N):
    for j in range(N):
        distance_sum += math.sqrt((points[i][0] - points[j][0]) ** 2 + (points[i][1] - points[j][1]) ** 2)
distance_sum /= 2

# result = distance_sum
# if N > 2:
#     routes_num = math.factorial(N)
#     two_points_combi_num = math.factorial(N) / math.factorial(N - 2) / math.factorial(2)
#     duplicate_count = (two_points_combi_num - (N - 1)) / two_points_combi_num * routes_num
#     result = distance_sum * (routes_num - duplicate_count) / routes_num
routes_num = math.factorial(N)
two_points_combi_num = math.factorial(N) / math.factorial(N - 2) / math.factorial(2)
duplicate_count = (two_points_combi_num - (N - 1)) / two_points_combi_num * routes_num
result = distance_sum * (routes_num - duplicate_count) / routes_num
print(result)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- Coding: utf-8 -*-

import sys
import math
import itertools

input = sys.stdin.readline


def main():
    N = int(input())
    t = [[int(i) for i in input().split()] for _ in range(N)]

    div = math.factorial(N)
    ans = 0
    l = [i for i in range(N)]
    for ary in itertools.permutations(l):
        s = 0
        for i in range(len(ary)-1):
            a = ary[i]
            b = ary[i+1]
            s += math.sqrt((t[a][0]-t[b][0])**2+(t[a][1]-t[b][1])**2)
        ans += s
    print(ans/div)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
import math

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

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

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

tmp =0
# comb = len(itertools.combinations(s,2))
for j in itertools.combinations(s,2):
    tmp += distance(j[0],j[1])

print(tmp*2/n)

Submission status: Accepted

Solution code:
# C
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
for i in range(N):
    for j in range(N):
        sum += math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)

ans = sum/N
print(ans)

Submission status: Accepted

Solution code:
from itertools import permutations
import math
n = int(input())
perm = permutations(range(n)) 
a = []
b = []
r = []
for i in range(n):
	x,y = map(int,input().split())
	a.append(x)
	b.append(y)
for i in perm:
	x,y = a[i[0]],b[i[0]]
	res = 0
	for j in i[1:]:
		res += math.sqrt((a[j]-x)*(a[j]-x)+(b[j]-y)*(b[j]-y))
	r.append(res)
print(sum(r)/len(r))

Submission status: Accepted

Solution code:
import itertools
import math

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

l = list(range(N))
a = []

for i in itertools.permutations(l, N):
  a.append(list(i))
  
D = 0

for i in range(math.factorial(N)):
  d = 0
  for j in range(N-1):
    d += math.sqrt((xy[a[i][j]][0]-xy[a[i][j+1]][0])**2 + (xy[a[i][j]][1]-xy[a[i][j+1]][1])**2)
  else:
    D += d
    
print(D / math.factorial(N))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys, math
sys.setrecursionlimit(300000)


def solve(N: int, x: "List[int]", y: "List[int]"):
    ret = 0
    total = 0
    for i in range(N):
        for j in range(i + 1, N):
            total += math.sqrt((x[j] - x[i]) ** 2 + (y[j] - y[i]) ** 2)
    comb = N * (N - 1) // 2
    perm = 1
    for i in range(1, N + 1):
        perm *= i
    ret = total * ((N - 1) * perm // comb)
    ret /= perm
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import sqrt
from math import factorial
 
n = int(input())
t = []
for i in range(n):
  t.append(list(map(int,input().split())))
l = [[0]*n for j in range(n)]
for k in range(n):
  for m in range(n):
      l[k][m] = sqrt((t[k][0]-t[m][0])**2+(t[k][1]-t[m][1])**2)
ans = 0
for i in range(n):
  s = sum(l[i])
  ans += s*factorial(n-1)
z = ans/factorial(n)
print(z)

Submission status: Accepted

Solution code:
import itertools
import math
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)

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

print(ans / len(p))

Submission status: Accepted

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

aaa = 0
for i in range(N):
    for k in range(N):
        aaa += ((x[i] - x[k])**2+(y[i] - y[k])**2)**0.5
print(aaa/N)

Submission status: Accepted

Solution code:
import math
import itertools
n = int(input())
x = [0]*n
y = [0]*n
town =[[0 for _ in range(2)]for _ in range(n)]
dist = [[0 for _ in range(n)]for _ in range(n)]
comb = [[0 for _ in range(n)]for _ in range(n)]
ans = 0
for i in range(n):
	x[i],y[i] = map(int,input().split())
	town[i] = (x[i],y[i])



#dist[i][j] = すべての町の距離の配列
for i in range(n):
	for j in range(n):
		if i!=j:
			dist[i][j] = math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
			dist[j][i] = dist[i][j]
for i in range(n):
	for j in range(n):
		ans += dist[i][j]

print(ans/n)

Submission status: Accepted

Solution code:
import math

n = int(input())
town = [list(map(int, input().split())) for _ in range(n)]
sum = 0
for i in range(n-1):
    for j in range(i + 1, n):
        x1, y1 = town[i]
        x2, y2 = town[j]
        sum += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

print(2*sum/n)

Submission status: Accepted

Solution code:
import itertools
import math


if __name__ == '__main__':
    n = int(input())
    xy = [list(map(int,input().split())) for i in range(n)]

    sum_length = 0.0
    sum_count = 0

    for i in itertools.permutations(range(n)):
        sum_count+=1
        for j in range(1,len(i)):
            sum_length += math.sqrt((xy[i[j-1]][0]-xy[i[j]][0])**2+(xy[i[j-1]][1]-xy[i[j]][1])**2)

    print(sum_length/sum_count)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    for j in range(n):
        L.append(((li[i][0]-li[j][0])**2 + (li[i][1]-li[j][1])**2)**0.5)
    
print(sum(L)/n)

Submission status: Accepted

Solution code:
# coding : utf-8

import numpy as np
import math

N = int(input())

loc = []
for _ in range(N):
    line = input().split(" ")
    loc.append([ int(line[0]), int(line[1]) ])

loc = np.array(loc)

if(N==2):
    print(np.linalg.norm(loc[0]-loc[1]))
else: 
    # 街間の距離
    mat = np.zeros((N,N))
    for i in range(N):
        for j in range(i, N):
            mat[i][j] = np.linalg.norm(loc[i]-loc[j])
            
    for i in range(N):
        for j in range(0, i):
            mat[i][j] = mat[j][i]
      
    mat = mat * (N-1) * math.factorial(N-2)
    print(np.sum(mat) / math.factorial(N))

Submission status: Accepted

Solution code:
import math

N = int(input())
D = []
for i in range(N):
    D.append(list(map(int, input().split())))
s = 0
while len(D) > 1:
    a = D[0]
    for d in D[1:]:
        s += ((a[0] - d[0]) ** 2 + (a[1] - d[1]) ** 2) ** 0.5
    D = D[1:]
print((s * (math.factorial(N - 1) * 2)) / (math.factorial(N)))

Submission status: Accepted

Solution code:
import itertools

if __name__ == '__main__':

    n = int(input())
 

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

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

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

    p_list = list(itertools.permutations(p))

    total = 0
    for i in range(len(p_list)):
        sum = 0
    
        for j in range(n-1):
            x1,y1 = int(town[p_list[i][j]][0]), int(town[p_list[i][j]][1])
            x2,y2 = int(town[p_list[i][j+1]][0]), int(town[p_list[i][j+1]][1])
    
            sum = sum + ((x2-x1)**2+(y2-y1)**2)**0.5
       

        total = total + sum
       

    
    print(total/float(len(p_list)))

Submission status: Accepted

Solution code:
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())
c = distance.cdist(xy, xy, metric='euclidean')
cost = floyd_warshall(c)
print(np.sum(c)/n)

Submission status: Accepted

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

l_s = 0

for i in range(N):
    for j in range(N):
        l_s += (((X[i]-X[j])**2) + ((Y[i]-Y[j])**2)) **(0.5)
ans = l_s / N
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math
import numpy as np
z = []
N = int(input())
for i in range(N):
  z.append(list(map(int,input().split(' '))))
d = 0  
x = []
p = list(itertools.permutations(z, N))
#print(p,N)  
for i in p:
  #print(i)
  #ans = math.sqrt((i[0][0]-i[1][0])**2) + math.sqrt((i[0][1]-i[1][1])**2)
  for j in range(N-1):
    #print(j,i)
    #d += np.linalg.norm(np.array([i[j+1][0],i[j+1][1]]) - np.array([i[j][0],i[j][1]]))
    d += math.sqrt(((i[j][0]-i[j+1][0])**2) + ((i[j][1]-i[j+1][1])**2))
    #print(([i[j+1][0],i[j+1][1]]), ([i[j][0],i[j][1]]))
  x.append(d) 
  d = 0
  
  
#  print(ans)
  
#print(x)  
print(sum(x)/len(x))

Submission status: Accepted

Solution code:
def dist(a,b,c,d):
  return ((a-c)**2+(b-d)**2)**(1/2)
N=int(input())
m=0
z=[list(map(int,input().split())) for _ in range(N)]
for i in range(N):
  for j in range(i+1,N):
    m+=dist(z[i][0],z[i][1],z[j][0],z[j][1])
print(float(2*m/N))

Submission status: Accepted

Solution code:
N = int(input())
data = []
sum = 0
x = 0
y = 1
for i in range(N):
    data.append( list(map(int,input().split())))
for i in range(N):
    for j in range(N):
        if(i==j):
            continue
        sum+=((data[i][x]-data[j][x])**2+(data[i][y]-data[j][y])**2)**0.5

print(sum/N)

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ =='__main__': main()

Submission status: Accepted

Solution code:
n=int(input())
XY=[tuple(map(int,input().split())) for _ in range(n)]
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/n
print(dist)

Submission status: Accepted

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