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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
l = inputILL(N)

count = 0
S = 0
for i in range(N):
  for j in range(i+1,N):
    a,b = l[i]
    c,d = l[j]
    S += math.sqrt((a-c)*(a-c)+(b-d)*(b-d))
    count += 1
    
print(S/count*(N-1))

Submission status: Accepted

Solution code:
import itertools
import math

def diff(xi, xj, yi, yj):
    x = (abs(xi - xj)) ** 2
    y = (abs(yi - yj)) ** 2
    return (x + y) ** 0.5

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

total = 0
for p in list(itertools.permutations(range(n), n)):
    length = 0
    for i in range(n-1):
        length += diff(x[p[i]], x[p[i+1]], y[p[i]], y[p[i+1]])
    total += length

print(total / math.factorial(n))

Submission status: Accepted

Solution code:
import itertools
N=int(input())
x=[0]*N
y=[0]*N
for i in range(N):
    x[i],y[i]=map(int,input().split())
t=[i for i in range(N)]
S=list(itertools.permutations(t))
l=[]
for i in range(len(S)):
    sum_A=0
    for j in range(N-1):
        sum_A=((x[S[i][j]]-x[S[i][j+1]])**2+(y[S[i][j]]-y[S[i][j+1]])**2)**0.5+sum_A
    l.append(sum_A)
kaijou=1
for i in range(N):
    kaijou=kaijou*(i+1)
print(sum(l)/kaijou)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import sqrt

N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
#順列(町の訪れ方)を作成→計算
d = 0
for route in permutations(range(N), N):
    route = list(route)
    for i in range(N-1):
        s = route[i]
        g = route[i+1]
        d += sqrt((X[g] - X[s]) ** 2 + (Y[g] - Y[s]) ** 2)
divisors = 1
for i in range(2, N+1):
    divisors *= i
print(d/divisors)

Submission status: Accepted

Solution code:
n = int(input())
li = []
ans = 0.0
x = 0

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

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

print(ans/x/2)

Submission status: Accepted

Solution code:
from itertools import combinations
import math
import numpy as np

n = int(input())
d = []
data = []

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

c = list(combinations(range(n), 2))

for row in c:
    x = [data[row[0]][0], data[row[1]][0]]
    y = [data[row[0]][1], data[row[1]][1]]

    d.append(np.sqrt((x[0]-x[1])**2 + (y[0]-y[1])**2))

print(sum(d)*math.factorial(n-1)*2/math.factorial(n))

Submission status: Accepted

Solution code:
import math
import itertools

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

ans = 0
for temp in itertools.permutations(A,N):
    distance = 0

    for i in range(0,N-1):
        distance +=  ((temp[i+1][0]-temp[i][0])**2 + (temp[i+1][1]-temp[i][1])**2)**0.5
    ans += distance

print(ans/math.factorial(N))

Submission status: Accepted

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

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

permutation_lis = itertools.permutations(town_lis)
ans = 0
cnt = 0
for one_case in permutation_lis:
    dist = 0
    cnt += 1
    for j in range(len(one_case)-1):         #one_caseのなかのリストのアイテム-1分の距離を数え上げる。jは各ループの始点となる町ナンバー
        dist += math.sqrt((one_case[j][0]-one_case[j+1][0]) ** 2 + (one_case[j][1]-one_case[j+1][1]) ** 2)
    ans += dist

print(ans/cnt)

Submission status: Accepted

Solution code:
import math
from itertools import permutations as perm

ii = lambda:int(input())
li = lambda:list(map(int,input().split()))
lix = lambda x:list(li() for _ in range(x))
##########
def main(n,x):
    res = 0
    count = 0
    for item in perm(x,n):
        res += calc(item)
        count += 1
    return res / count
    
def calc(item):
    res = 0
    for i in range(1,len(item)):
        st,ed = item[i-1], item[i]
        res += math.sqrt((ed[0]-st[0])**2 + (ed[1]-st[1])**2)
    return res

n = ii()
x = lix(n)
print(main(n,x))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
pts = [(list(map(int,input().split()))) for _ in range(0,N)]

from itertools import combinations
def f(x1,y1,x2,y2):
    dx = x2 - x1
    dy = y2 - y1
    return (dx**2+dy**2)**0.5
dst = 0
for i,j in combinations(range(0,N),2):
    dst += f(pts[i][0], pts[i][1], pts[j][0], pts[j][1])
print(dst / (N / 2))

Submission status: Accepted

Solution code:
N = int(input())
pts = [(list(map(int,input().split()))) for _ in range(0,N)]

from itertools import permutations
def f(x1,y1,x2,y2):
    dx = x2 - x1
    dy = y2 - y1
    return (dx**2+dy**2)**0.5

l = 0
dst = 0
for i,j in permutations(range(0,N),2):
    dst += f(pts[i][0], pts[i][1], pts[j][0], pts[j][1])
    l += 1
print(dst / l * (N-1))

Submission status: Accepted

Solution code:
import math

N = int(input())
P = []
r = 0

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

for i in range(N):
  P.append(list(map(int, input().split())))

for i in range(N):
  for j in range(i+1, N):
    r += f(*(P[i]+P[j]))

print(r * 2 / N)

Submission status: Accepted

Solution code:
import itertools


N = int(input())

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

town_l = [i for i in range(N)]
V = list(itertools.permutations(town_l, N))
C = len(V)
a = 0
for v in V:
    for i in range(N - 1):
        a += ((x[v[i]] - x[v[i + 1]]) ** 2 + (y[v[i]] - y[v[i + 1]]) ** 2) **0.5

ans = a / C
print(ans)

Submission status: Accepted

Solution code:
import itertools
 
N = int(input())
coord = [list(map(int, input().split())) for _ in range(N)]
dis = 0

for order in itertools.permutations(range(N)):
  for i in range(1, N):
    dis += ((coord[order[i]][0]-coord[order[i-1]][0])**2 + (coord[order[i]][1]-coord[order[i-1]][1])**2)**0.5
 
ave = dis / len(list(itertools.permutations(range(N))))
print(ave)

Submission status: Accepted

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

ans=0
for i in range(n):
    for j in range(n):
        x,y=a[i]
        xx,yy=a[j]
        ans+=((x-xx)**2+(y-yy)**2)**0.5
print(ans/n)

Submission status: Accepted

Solution code:
import math
import itertools

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

ans = []
for i in itertools.permutations([i for i in range(n)]):
    length = 0
    for j in range(n-1):
        length += math.sqrt((x[i[j]] - x[i[j+1]])**2 + (y[i[j]] - y[i[j+1]])**2)
    ans.append(length)
print(sum(ans)/len(ans))

Submission status: Accepted

Solution code:
import itertools
import math
n = int(input())
lis = [x for x in range(n)] 
permutations_lis = itertools.permutations(lis)
adjacent = []
for i in range(n):
  x, y = map(int, input().split())
  adjacent.append([x, y])
length = 0
for j in permutations_lis:
    lengthX = 0
    for i in range(n-1):
        a = j[i]
        b = j[i+1]
        ax, ay = adjacent[a]
        bx, by = adjacent[b]
        lengthX += math.sqrt((ax-bx)**2+(ay-by)**2)
    length += lengthX
print(length/math.factorial(n))

Submission status: Accepted

Solution code:
import math
import itertools

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

ans = []
for i in itertools.permutations([i for i in range(n)]):
    length = 0
    for j in range(n-1):
        length += math.sqrt((x[i[j]] - x[i[j+1]])**2 + (y[i[j]] - y[i[j+1]])**2)
    ans.append(length)
print(sum(ans)/len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import itertools

def get_length(p1, p2):
    x1 = p1[0]
    x2 = p2[0]
    y1 = p1[1]
    y2 = p2[1]

    return ((x1 - x2)**2 + (y1- y2)**2)**0.5

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

total_len = 0
pattern = 0
for i in itertools.permutations(list(range(N))):
    pattern += 1
    for j in range(N-1):
        total_len += get_length(xy[i[j]], xy[i[j+1]])

print(total_len / pattern)

Submission status: Accepted

Solution code:
import itertools
import math
import numpy as np
import sys
input = sys.stdin.readline

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

n_list = [l for l in range(n)]
dsum = 0
for i in itertools.permutations(n_list, n):
    xy1 = xy[list(i)][:-1]
    xy2 = xy[list(i)][1:]
    dsum += np.sum(np.sqrt(np.sum((xy1 - xy2)**2, axis=1)))

print(dsum/math.factorial(n))

Submission status: Accepted

Solution code:
import itertools
# n = int(input())
# lis = [x for x in range(n)] # 0からn-1までのリスト
# permutations_lis = itertools.permutations(lis)# 全ての場合のリストを生成
# # 以下出力
# for one_case in permutations_lis:
#     for num in one_case:
#         print(num, end=" ")
#     print("")

def main():
    # 入力
    n = int(input())

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

    # ｎ番目をスタート地点とする
    lis = [x for x in range(n)]
    permutations_lis = itertools.permutations(lis)

    num = 0
    sum = 0
    for plist in permutations_lis:
        num += 1
        now = pls[plist[0]]
        ls = plist[1:]
        for i in ls:
            x_diff_2 = (pls[i][0] - now[0])**2
            y_diff_2 = (pls[i][1] - now[1])**2
            zz = x_diff_2 + y_diff_2
            # print(zz)
            sum += pow(x_diff_2 + y_diff_2, 0.5)
            # print(sum)
            now = pls[i]

    print(sum/num)


main()

Submission status: Accepted

Solution code:
import math
def main():
    N =int(input())
    sum=0

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

    for i in range(N):
        for j in range(N):
            sum += math.sqrt((X[i]-X[j])**2 + (Y[i]-Y[j])**2)
    
    print (sum/N)

    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
XY = []
for _ in range(N):
    XY.append(list(map(int,input().split(' '))))

SUM = 0
cnt = 0
for v in itertools.permutations(XY, N):
    cnt += 1
    sx = v[0][0]
    sy = v[0][1]
    for i in v[::]:
        SUM += math.sqrt((sx - i[0])**2 + (sy - i[1])**2)
        sx , sy = i[0] ,i[1]

print(SUM/cnt)

Submission status: Accepted

Solution code:
import itertools,math,numpy as np
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
xy = np.array([LI() for _ in range(N)])
sum_norm = 0
dict_norm = {}
for a in itertools.permutations(range(N)):
    for i in range(len(a)-1):
        vector = tuple(xy[a[i+1]]-xy[a[i]])
        if not vector in dict_norm:
            dict_norm[vector] = np.linalg.norm(vector)
            vector_inverse = tuple(xy[a[i]]-xy[a[i+1]])
            dict_norm[vector_inverse] = dict_norm[vector]
        sum_norm += dict_norm[vector]
print(sum_norm/math.factorial(N))

Submission status: Accepted

Solution code:
import itertools,math,numpy as np
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
xy = np.array([LI() for _ in range(N)])
sum_norm = 0
dict_norm = {}
for a in itertools.permutations(range(N)):
    for i in range(len(a)-1):
        vector = tuple(xy[a[i+1]]-xy[a[i]])
        if not vector in dict_norm:
            dict_norm[vector] = np.linalg.norm(vector)
            vector_inverse = tuple([vector[0]*-1,vector[1]*-1])
            dict_norm[vector_inverse] = dict_norm[vector]
        sum_norm += dict_norm[vector]
print(sum_norm/math.factorial(N))

Submission status: Accepted

Solution code:
import numpy as np
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
xy = np.array([LI() for _ in range(N)])
sum_norm = 0
for i in range(N):
    for j in range(i,N):
        sum_norm += np.linalg.norm(xy[j]-xy[i])
print(2*sum_norm/N)

Submission status: Accepted

Solution code:
import sys, math
from pprint import pprint
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
points = []
for i in range(N):
	x, y = rl()
	points.append((x,y))

def get_len(p):
	x, y = p[0]
	l = 0
	for i in range(len(p)-1):
		d = ((p[i][0]-p[i+1][0])**2+(p[i][1]-p[i+1][1])**2)**0.5
		l += d
	return l

import itertools
sl = 0
n = 0
for p in itertools.permutations(points):
	l = get_len(p)
	sl += l
	n += 1
print(sl/n)

Submission status: Accepted

Solution code:
import itertools,math,numpy as np
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
xy = np.array(sorted([LI() for _ in range(N)]))
sum_norm = 0
dict_norm = {}
for a in itertools.permutations(range(N)):
    for i in range(len(a)-1):
        vector = tuple(xy[a[i+1]]-xy[a[i]])
        if not vector in dict_norm:
            dict_norm[vector] = np.linalg.norm(vector)
        sum_norm += dict_norm[vector]
print(sum_norm/math.factorial(N))

Submission status: Accepted

Solution code:
import itertools,math,numpy as np
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
xy = np.array([LI() for _ in range(N)])
sum_norm = 0
dict_norm = {}
for a in itertools.permutations(range(N)):
    for i in range(len(a)-1):
        vector = tuple(xy[a[i+1]]-xy[a[i]])
        if not vector in dict_norm:
            dict_norm[vector] = np.linalg.norm(vector)
            vector_Inverse = tuple(xy[a[i]]-xy[a[i+1]])
            dict_norm[vector_Inverse] = dict_norm[vector]
        sum_norm += dict_norm[vector]
print(sum_norm/math.factorial(N))

Submission status: Accepted

Solution code:
import itertools,math,numpy as np
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
xy = np.array([LI() for _ in range(N)])
sum_norm = 0
dict_norm = {}
for a in itertools.permutations(range(N)):
    for i in range(len(a)-1):
        vector = tuple(xy[a[i+1]]-xy[a[i]])
        if not vector in dict_norm:
            dict_norm[vector] = np.linalg.norm(vector)
        sum_norm += dict_norm[vector]
print(sum_norm/math.factorial(N))

Submission status: Accepted

Solution code:
import itertools,math,numpy as np
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
xy = np.array([LI() for _ in range(N)])
sum_norm = 0
dict_norm = {}
for a in itertools.permutations(range(N)):
    for i in range(len(a)-1):
        vector = xy[a[i+1]]-xy[a[i]]
        if not tuple(vector) in dict_norm:
            dict_norm[tuple(vector)] = np.linalg.norm(vector)
        sum_norm += dict_norm[tuple(vector)]
print(sum_norm/math.factorial(N))

Submission status: Accepted

Solution code:
cin = open(0).read().strip().split('\n')
n = int(cin[0])
xy = [tuple(map(int, a.split(' '))) for a in cin[1:]]

import itertools, math

ret = 0
case = 0
for cases in itertools.permutations(xy):
    case += 1
    for idx in range(n-1):
        ret += math.sqrt((cases[idx][0]-cases[idx+1][0])**2 + (cases[idx][1]-cases[idx+1][1])**2)

print(ret/case)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import sqrt, pow, factorial
def calc(a, b):
    x1, y1 = a
    x2, y2 = b
    return sqrt(pow(x1  - x2, 2) + pow(y1 - y2, 2))
n = int(input())
x_y = [list(map(int, input().split())) for i in range(n)]

ans = 0
for oder in permutations(range(n)):
    tmp = 0
    for i in range(n - 1):
        tmp += calc(x_y[oder[i] - 1], x_y[oder[i + 1] - 1])
    ans += tmp
ans = ans / factorial(n)
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt


def route(a, b):
    return(sqrt((p[a-1][0]-p[b-1][0])**2+(p[a-1][1]-p[b-1][1])**2))


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

sum = int()
cnt = int()
for i in range(1, n):
    for j in range(i+1, n+1):
        #print(i, j)
        sum+=route(i,j)
        cnt+=1

sum*=n-1
print(sum/cnt)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial

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

cnt = 0
for i in permutations(range(n)):
    for j in range(n - 1):
        cnt += ((xy[i[j]][0] - xy[i[j + 1]][0]) ** 2 +
                (xy[i[j]][1] - xy[i[j + 1]][1]) ** 2) ** 0.5
print(cnt/factorial(n))

Submission status: Accepted

Solution code:
import itertools
N=int(input())
X=[list(map(int,input().split())) for i in range(N)]
total=0
route=list(itertools.combinations(X,2))
for i in route:
    total+=((i[0][0]-i[1][0])**2+(i[0][1]-i[1][1])**2)**(1/2)
print(total*2/N)

Submission status: Accepted

Solution code:
import math

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

#print(L)
#print(len(L))
count=0
for i in range(len(L)):
  for j in range(i+1,len(L)):
    count += (math.sqrt((L[i][0]-L[j][0])**2 + (L[i][1]-L[j][1])**2))*2*(math.factorial(len(L)-1))
    #print(count)
print (count / math.factorial(len(L)))

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    N_kaijo=1
    for i in range(1,N+1):
        N_kaijo*=i

    x=[]
    y=[]
    for i in range(N):
        x_i,y_i=map(int,readline().split())
        x.append(x_i)
        y.append(y_i)
    
    res=0
    for i in range(N-1):
        for j in range(i+1,N):
            l=((x[j]-x[i])**2+(y[j]-y[i])**2)**0.5
            res+=l*2/N

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
N = int(input())
ans=0
XY=[]
for i in range(N):
    X,Y = list(map(int,input().split()))
    for xy in XY:
        ans += ((xy[0]-X)**2+(xy[1]-Y)**2)**0.5
    XY.append((X,Y))
print(ans*2/N)

Submission status: Accepted

Solution code:
import math
import itertools
n = int(input())
d=[]
for i in range(n):
    a,b=map(int, input().split())
    d.append([a,b])
p = itertools.permutations(d, 2)
ans=0
for v in p:
    ans += math.sqrt((v[0][0]-v[1][0])**2 + (v[0][1]-v[1][1])**2)
print(ans/n)

Submission status: Accepted

Solution code:
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,y = map(int, input().split())
    X[i] = x
    Y[i] = y

D = 0
for i in range(N):
    for j in range(N):
        if i < j:
            a = (X[i]-X[j])**2
            b = (Y[i]-Y[j])**2
            c = math.sqrt(a+b)
            D += c
print((2*D)/N)

Submission status: Accepted

Solution code:
import math
N=int(input())
L=[]
tmp=[]
t=1
for i in range (N):
	t=t*(i+1)
	x,y=map(int,input().split())
	L.append([x,y])
for i in range(N-1):
	for j in range(i+1,N):
		z=math.sqrt((L[i][0]-L[j][0])**2+(L[i][1]-L[j][1])**2)
		tmp.append(z)
print((sum(tmp))*2/N)

Submission status: Accepted

Solution code:
import itertools
from math import sqrt
N=int(input())
L=[]
for i in range(N):
    x,y=map(int, input().split())
    L.append((x,y))

def distance(x1,y1,x2,y2):
    return sqrt( (x2-x1)**2 + (y2-y1)**2 )

ans=0
count=0
for l in itertools.permutations(L):
    
    count+=1
    for i,t in enumerate(l):
        if i==0:
            px,py=t
            continue
        x,y=t
        ans+=distance(x,y,px,py)
        px=x
        py=y
print(ans/count)

Submission status: Accepted

Solution code:
n=int(input())
xy=[]
for i in range(n):
  xx,yy=map(int,input().split())
  xy.append((xx,yy))
from itertools import permutations
a=list(permutations(xy))
d=[]
for aa in a:
  t=0
  for i in range(len(aa)-1):
    t+=((aa[i+1][0]-aa[i][0])**2+(aa[i+1][1]-aa[i][1])**2)**0.5
  d.append(t)
print(sum(d)/len(d))

Submission status: Accepted

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

ans = 0
cnt = 0
for v in permutations(N):
    x = 0
    for i in range(n-1):
        a = v[i]
        b = v[i+1]
        x += ((xy[a][0]-xy[b][0])**2 + (xy[a][1]-xy[b][1])**2) ** 0.5
    cnt += 1
    ans += x
print(ans/cnt)

Submission status: Accepted

Solution code:
N = int(input())
C = []
for _ in range(N):
    C.append(list(map(int,input().split())))
s = 0
for k in range(N-1):
    for l in range(k+1,N):
        s += ((C[k][0]-C[l][0])**2 + (C[k][1]-C[l][1])**2)**(1/2)

print(s/(N/2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import permutations
import math
def dist(x,y):
    return ((x[0]-y[0])**2+(x[1]-y[1])**2)**(0.5)
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for z in permutations(range(N),N):
    for i in range(N-1):
        ans += dist(X[z[i]],X[z[(i+1)%N]])
print(ans/math.factorial(N))

Submission status: Accepted

Solution code:
import math
n = int(input())
li = [list(map(int,input().split())) for _ in range(n)]
length  = []
for x,y in li:
    for x_,y_ in li:
        length.append(math.sqrt((x-x_)**2+(y-y_)**2))
print(sum(length)/n)

Submission status: Accepted

Solution code:
import sys
def main():
    input = sys.stdin.readline
    N=int(input())
    A=[tuple(map(int, input().split())) for _ in range(N)]
    ans=0
    for i in range(N):
        for j in range(N):
            if i==j: continue
            ans+=((A[i][0]-A[j][0])**2 + (A[i][1]-A[j][1])**2) ** 0.5
    print(ans/N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from itertools import permutations
from math import sqrt

def solve():
    input = sys.stdin.readline
    N = int(input())
    C = [[int(i) for i in input().split()] for _ in range(N)]
    totalDist = 0
    count =0 
    for order in permutations(range(N)):
        count += 1
        dist = 0
        for i in range((N-1)):
            X = C[order[i]]
            Y = C[order[i+1]]
            dist += sqrt((X[0] - Y[0]) ** 2 + (X[1] - Y[1]) ** 2)
        totalDist += dist
    print(totalDist / count)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from itertools import permutations
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

res = 0
cnt = 0
gen = range(N)
for ls in permutations(gen):
    tmp = 0
    for i in range(N-1):
        tmp += ((xy[ls[i+1]][0]-xy[ls[i]][0])**2+(xy[ls[i+1]][1]-xy[ls[i]][1])**2)**0.5
    res += tmp
    cnt += 1
print(res/cnt)

Submission status: Accepted

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

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)

Submission status: Accepted

Solution code:
from math import sqrt, factorial
import itertools


N = int(input())

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

def calc(a, b):
    tmp = (XY[a][0] - XY[b][0]) ** 2 + (XY[a][1] - XY[b][1]) ** 2
    return sqrt(tmp)

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

ans = 0
for tmp in itertools.permutations(lst):
    for i in range(N - 1):
        ans += calc(tmp[i], tmp[i + 1])

ans /= factorial(N)

print (ans)

Submission status: Accepted

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

import math

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

ans = sum([sum([dist[i][j] for j in range(N)]) for i in range(N)]) / N
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
XY = [tuple(map(int,input().split())) for i in range(N)]

import itertools
from math import hypot
l = k = 0
for ptn in itertools.permutations(XY):
    k += 1
    for (x1,y1),(x2,y2) in zip(ptn,ptn[1:]):
        d = hypot(x1-x2, y1-y2)
        l += d
print(l/k)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from math import sqrt

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

sum = 0

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

print(sum/N)

Submission status: Accepted

Solution code:
import itertools
import math

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

t = 0
c = 0
for v in itertools.permutations(xy, n):
    c+=1
    for i in range(n - 1):
        t+=math.sqrt((v[i][0] - v[i+1][0]) ** 2 + (v[i][1] - v[i+1][1]) ** 2)
        # print(v, t)
print(t/c)

Submission status: Accepted

Solution code:

import math
def calc(u,v):
    return math.sqrt((u[0]-v[0])**2 + (u[1]-v[1])**2)
import itertools
N = int(input())
XY = [list(map(int,input().split())) for i in range(N)]

l = [i+1 for i in range(N)]
dist = 0
for v in itertools.permutations(XY,N):
    for i in range(1,N):
        dist += calc(v[i],v[i-1])

print(dist/math.factorial(N))

Submission status: Accepted

Solution code:
import math
from itertools import permutations
n = int(input())
total = 0
a = [list(map(int, input().split())) for _ in range(n)]

per = list(permutations([i for i in range(n)]))
for p in per:
    for i in range(1, n):
        p1, p2 = p[i], p[i-1]
        total += ((a[p1][0]-a[p2][0])**2 + (a[p1][1]-a[p2][1])**2)**0.5
print(total/math.factorial(n))

Submission status: Accepted

Solution code:
import math
import itertools

def calc_dist(u, v):
    return math.sqrt(((u[0] - v[0]) * (u[0] - v[0])) + ((u[1] - v[1]) * (u[1] - v[1])))

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

dist_sum = 0.0
for v in itertools.permutations(cities, n):
    dist = 0.0
    for i in range(1, n):
        dist += calc_dist(v[i], v[i - 1])
    dist_sum += dist
dist_sum /= math.factorial(n)
print(dist_sum)

Submission status: Accepted

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

seq = list(itertools.permutations(list(range(n))))

sum_list = []
for s in seq:  #移動の仕方の組み合わせ
    sum = 0
    for i in range(n-1):  # 町の数
        sum += math.sqrt((kyori[s[i]][0]-kyori[s[i+1]][0])**2 + (kyori[s[i]][1]-kyori[s[i+1]][1])**2)
    sum_list.append(sum)

print(statistics.mean(sum_list))

Submission status: Accepted

Solution code:
import itertools
n = int(input())
xy = [[int(i) for i in input().split()] for _ in [0]*n]
it = list(itertools.permutations(xy, n))
ans = 0
for i in it:
    for j in range(len(list(i))-1):
        ans += ((i[j][0] - i[j+1][0])**2 + (i[j][1] - i[j+1][1])**2)**0.5
print(ans/len(it))

Submission status: Accepted

Solution code:
import itertools

def distance(xy1, xy2):
    x1, y1 = xy1
    x2, y2 = xy2

    dis = ((x1-x2)**2 + (y1-y2)**2)**0.5

    return dis

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

    cnt = 0
    cnt2 = 0
    for l_xy in itertools.permutations(xy):
        cnt2 += 1
        for j in range(n-1):
            cnt += distance(l_xy[j], l_xy[j+1])

    return cnt/cnt2

    
print(solve())