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

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

Submission status: Accepted

Solution code:
# 初期入力
N=int(input())
S = [list(map(int, input().split())) for i in range(N)]

#町のいく順番　順列
from itertools import permutations
import math
from statistics import mean
junban =[ t for t in permutations(range(N)) ]
#junban =junban_2[:len(junban_2)//2] # 逆順は考えなくていい
j_len =len(junban) # 順番の要素数
x =[] #距離
x_sum =[]
def kyori(a,b): 
    return math.sqrt(pow( S[a][0]-S[b][0],2) + pow( S[a][1] - S[b][1],2) )

# 各点の距離　　組み合わせ
from itertools import combinations
kumiawase = [t for t in combinations(range(N), 2)]
kyori_all ={i:kyori(i[0],i[1]) for i in kumiawase}

#
for i in junban:
    for ji,jv in enumerate(i[:-1]):
        if i[ji]<i[ji+1]:
            x.append(kyori_all[ i[ji],i[ji+1] ] )
        if i[ji+1]<i[ji]:
            x.append(kyori_all[ i[ji+1],i[ji] ] )

    y =sum(x)    
    x_sum.append(y)
    x.clear()
kotae =mean(x_sum) 

print(kotae)

Submission status: Accepted

Solution code:
def main():
    from collections import namedtuple
    from itertools import combinations

    City = namedtuple('City', 'x y')

    def dist(a: City, b: City) -> float:
        dx = a.x - b.x
        dy = a.y - b.y
        return (dx * dx + dy * dy) ** 0.5

    N = int(input())

    cities = []
    for _ in range(N):
        x, y = map(int, input().split())
        c = City(x=x, y=y)
        cities.append(c)

    total = 0
    for comb in combinations(cities, r=2):
        total += dist(*comb)

    ans = total * 2 / N
    print(ans)


if __name__ == '__main__':
    main()

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

Submission status: Accepted

Solution code:
def main():
    from collections import namedtuple
    from itertools import permutations
    from math import factorial

    City = namedtuple('City', 'x y')

    def dist(a: City, b: City) -> float:
        dx = a.x - b.x
        dy = a.y - b.y
        return (dx * dx + dy * dy) ** 0.5

    N = int(input())

    cities = []
    for _ in range(N):
        x, y = map(int, input().split())
        c = City(x=x, y=y)
        cities.append(c)

    total = 0
    for perm in permutations(cities):
        it = iter(perm)
        p = next(it)

        for city in it:
            total += dist(p, city)
            p = city

    ans = total / factorial(N)
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

Submission status: Accepted

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

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)

def fac(n):
  if n==0:
    return 1
  if n==1:
    return 1
  return n*fac(n-1)

ans=0
for i in range(n):
  for j in range(n):
    tmp=(((x[i]-x[j])**2+(y[i]-y[j])**2)**.5)
    ans+=tmp
   

print(ans/n)

Submission status: Accepted

Solution code:
n = int(input())
xy = []
for i in range(n):
  arrat = [int(i) for i in input().split()]
  xy.append(arrat)

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

ans /= n
print(ans*2)

Submission status: Accepted

Solution code:
def examA():
    def calc_L(x1,y1,x2,y2):
        return ((x2-x1)**2 + (y2-y1)**2)**0.5
    N = I()
    X = [LI()for _ in range(N)]
    ans = 0
    for x in itertools.permutations(X):
        cur = 0
        for i in range(1,N):
            cur += calc_L(x[i-1][0],x[i-1][1],x[i][0],x[i][1])
        #print(x,cur)
        ans += cur
    for i in range(1,N+1):
        ans /= i
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examA()

"""

"""

Submission status: Accepted

Solution code:
import math
n = int(input())
xy = [list(map(int,input().split()))for _ in range(n)]
perm=[0]*n
res = []
used = [0] *n
def dfs(depth):
    if depth == n:
        res.append([perm[i] for i in range(n)])
        return
    for i in range(n):
        if used[i]:continue
        used[i] = 1
        perm[depth] = i
        dfs(depth+1)
        used[i] = 0
dfs(0)
ans = 0
for p in res:
    for i in range(len(p)-1):
        x1,y1 = xy[p[i]][0],xy[p[i]][1]
        x2,y2 = xy[p[i+1]][0],xy[p[i+1]][1]
        dist = math.sqrt((x1-x2)**2+(y1-y2)**2)
        ans +=dist
P = [1]
for i in range(n):
    P.append(P[-1]*(i+1))
    
ans/=P[n]
print(ans)

Submission status: Accepted

Solution code:
# Problem C - Average Length

from itertools import permutations
import math

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

# initialization
distance = 0
pattern_num = 0
pattern_moto = [i for i in range(1, N+1)]
for p in permutations(pattern_moto):
    pattern_num += 1
    tmp_distance = 0
    for d in range(len(p)-1):
        d_1 = distance_list[p[d]-1]
        d_2 = distance_list[p[d+1]-1]
        tmp = math.sqrt((d_1[0]-d_2[0])**2 + (d_1[1]-d_2[1])**2)
        tmp_distance += tmp
    distance += tmp_distance

# output
distance = distance / pattern_num
print(distance)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import sqrt

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


_sum = 0
for p in permutations(range(N)):
    s = p[0]
    x, y = xy[s]
    for i, pi in enumerate(p):
        if i == 0:
            continue
        nx, ny = xy[pi]
        d = (nx-x)**2 + (ny-y)**2
        _sum += sqrt(d)

a = 1
for i in range(1, N+1):
    a *= i
print(_sum/a)

Submission status: Accepted

Solution code:
from math import sqrt
n = int(input())
p = []
for _ in range(n):
    x, y = map(int, input().split())
    p.append([x, y])

cnt = 0
total = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        cnt += 1
        xi, yi = p[i]
        xj, yj = p[j]
        total += sqrt((xi - xj) ** 2 + (yi - yj) ** 2)

ans = total / cnt * (n - 1)
print(ans)

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 145
# C - Average Length
# https://atcoder.jp/contests/abc145/tasks/abc145_c
import sys
from itertools import permutations
input = sys.stdin.readline
N = int(input())

A = [tuple(map(int, input().split())) for _ in [0]*N]

suml = 0
cnt = 0
for i in permutations(range(N)):
    length = 0
    x0, y0 = A[i[0]]
    for j in i[1:]:
        x1, y1 = A[j]
        length += ((x1-x0)**2+(y1-y0)**2)**0.5
        x0, y0 = x1, y1
    suml += length
    cnt += 1

print(suml/cnt)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
point = []
a = [i for i in range(n)]
for i in range(n):
    x,y = map(int,input().split())
    point.append((x,y))
a = list(itertools.permutations(a,n))
length = 0
for i in range(len(a)):
    for j in range(n-1):
        cnt = (point[a[i][j]][0] - point[a[i][j+1]][0])**2\
        + (point[a[i][j]][1] - point[a[i][j+1]][1])**2
        cnt = cnt**0.5
        length += cnt
print(length / len(a))

Submission status: Accepted

Solution code:
import math
import itertools

n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]
rng = [i for i in range(n)]
ans = 0
for l in itertools.permutations(rng):
    t = 0
    for e, k in enumerate(l):
        if e==0:
            x,y = xy[k][0], xy[k][1]
        nx, ny = xy[k][0], xy[k][1]
        t += ((nx-x)**2 + (ny-y)**2)**0.5
        x,y = nx, ny
    ans += t
print(ans/math.factorial(n))

Submission status: Accepted

Solution code:
import itertools
n = int(input())
XY = []
for i in range(n):
    x, y = map(int, input().split())
    XY.append((x, y))
d = 0
for P in itertools.permutations(XY):
    for i in range(1, n):
        x0, y0 = P[i-1]
        x1, y1 = P[i]
        d += ((x0-x1)**2+(y0-y1)**2)**0.5
k = 1
for i in range(1, n+1):
    k *= i
print(d/k)

Submission status: Accepted

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

ans = 0
for x in permutations(range(N)):
    for i in range(N-1):
        ans += ((xy[x[i+1]][0] - xy[x[i]][0])**2 +
                (xy[x[i+1]][1] - xy[x[i]][1])**2) ** (1/2)

print(ans / math.factorial(N))

Submission status: Accepted

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

from itertools import permutations
from math import sqrt

states = list(permutations(list(range(N))))

ans = 0
for state in states:
    dist = 0
    for i,n in enumerate(state):
        if i == 0:
            prev = xy[n]
            continue
        now = xy[n]
        dist += sqrt((prev[0]-now[0]) ** 2+ (prev[1]-now[1]) ** 2)
        prev = now
    ans += dist

ans /= len(states)
print(ans)

Submission status: Accepted

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


import itertools
ans = 0
for xyl2 in itertools.permutations(xyl):
    x0 = xyl2[0][0]
    y0 = xyl2[0][1]
    tmp = 0
    for x, y in xyl2:
        tmp += ((x-x0) ** 2 + (y-y0) ** 2) ** (1/2)
        x0 = x
        y0 = y
    ans += tmp

print(ans / len(list(itertools.permutations(xyl))))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    from math import hypot
    XY = [[int(i) for i in input().split()] for j in range(N)]
    from itertools import permutations
    ans = 0
    for p in permutations(range(N)):
        cur = 0
        pre = p[0]
        for i in p[1:]:
            cur += hypot(XY[pre][0] - XY[i][0], XY[pre][1] - XY[i][1])
        ans += cur
    acc = 1
    for i in range(2, N+1):
        acc *= i
    print(ans/acc)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

n = inp()
xy = [inpl() for _ in range(n)]
res = 0
for f in itertools.permutations(range(n)):
    for i in range(n-1):
        a,b = xy[f[i]], xy[f[i+1]]
        dist = (a[0]-b[0])**2 + (a[1]-b[1]) ** 2
        res += math.sqrt(dist)
print(res/math.factorial(n))

Submission status: Accepted

Solution code:
import math
N = int(input())
ls1 = []
ls2 = []
for i in range(N):
    ls1.append(list(map(int,input().split())))
x = 0
y = 0
for i in range(N):
    for j in range(i+1,N):
        x = (ls1[i][0]-ls1[j][0])**2
        y = (ls1[i][1]-ls1[j][1])**2
        XY = math.sqrt(x+y)
        ls2.append(XY)
if len(ls2) == 1:
    print(ls2[0])
else:
    ans = sum(ls2)*2/N
    print(ans)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial
def d(a, b):
  x1, y1 = a
  x2, y2 = b
  return ((x1-x2)**2 + (y1-y2)**2)**0.5

cnt = 0
n = int(input())
XY = [list(map(int, input().split())) for _ in range(n)]
for l in permutations(XY):
  for i in range(n-1):
    cnt += d(l[i], l[i+1])
cnt /= factorial(n)
print(cnt)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import sqrt, factorial


def main():
    n = int(input())
    xy = []
    for _ in range(n):
        xy.append(list(map(int, input().split())))
    town = [i for i in range(n)]
    dist_sum = 0
    for p in permutations(town):
        for i in range(n - 1):
            dist_sum += sqrt((xy[p[i]][0] - xy[p[i + 1]][0]) ** 2 + (xy[p[i]][1] - xy[p[i + 1]][1]) ** 2)
    print(dist_sum / factorial(n))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import itertools
N = int(input())
p = [tuple(map(int, input().split())) for _ in range(N)]
num = [int(i) for i in range(N)]
d_sum = 0
for per in itertools.permutations(num):
    # print(per)
    for i in range(len(per) - 1):
        d_sum += math.sqrt((p[per[i]][0] - p[per[i+1]][0])**2 + (p[per[i]][1] - p[per[i+1]][1])**2)
        # print(d_sum)
ans = d_sum / math.factorial(N)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math
import itertools
n = int(input())
xy = []
for _ in range(n):
  xy.append(list(map(int, input().split())))
xy = np.array(xy)
dist = []
# calculate all distance
# n-1 * dist from a
# n-2 * dist from b
su = 0
for i in range(n-1):
  d = np.array(list(map(math.sqrt, ((xy[i+1:] - xy[i])**2).sum(axis=1))))
  mu = math.factorial(n-1)*2
  su += (d*mu).sum()
print(su/math.factorial(n))

Submission status: Accepted

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

from itertools import permutations
import math
distance = []
for route in list(permutations(range(1,n+1))):
  route = list(route)

  dis = 0
  for i in range(0,n-1):
    d = math.sqrt(pow(location[route[i]-1][0]-location[route[i+1]-1][0],2) + pow(location[route[i]-1][1]-location[route[i+1]-1][1],2))
    dis = dis + d
  distance.append(dis)
  
ans = sum(distance)/len(list(permutations(range(1,n+1))))
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())

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

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

s = 0
for x in itertools.permutations(l):
    for i in range(N-1):
        s += math.sqrt( (L[x[i]][0]-L[x[i+1]][0])**2 + (L[x[i]][1]-L[x[i+1]][1])**2 )

print(s/math.factorial(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC145 - Virtual
# A
# B
# C
import itertools

def fact(n,mod):
    ret=1
    for i in range(2,n+1):
        ret=(ret*i)%mod
    return ret

N=int(input())
X=[tuple(map(int,input().split())) for _ in range(N)]
ans=0
for p in itertools.permutations(X):
    # print(p)
    sx,sy=p[0]
    for x,y in p:
        ans+=((sx-x)**2+(sy-y)**2)**0.5
        sx,sy=x,y
    # print(ans)
ans/=fact(N,10**9+7)
print(ans)
    

    
# D
# E

Submission status: Accepted

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

town = [i for i in range(n)]
route = list(itertools.permutations(town,n))
dis = 0
for i in route:
    for j in range(n-1):
        dis += math.sqrt((xy[i[j]][0] - xy[i[j+1]][0])**2 + (xy[i[j]][1] - xy[i[j+1]][1])**2)

print(dis/len(route))

Submission status: Accepted

Solution code:
n=int(input())
A=[[0,0] for i in range(n)]
for i in range(n):
    A[i][0],A[i][1]=map(int,input().split())
B=0
def dis(a,b,c,d):
    return ((a-c)**2+(b-d)**2)**(1/2)
for i in range(n-1):
    for j in range(i,n-1):
        B=B+dis(A[i][0],A[i][1],A[j+1][0],A[j+1][1])
print(B*2/n)

Submission status: Accepted

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

s = 0
c = 0
for i in range(n):
    for k in range(i + 1, n):
        s += ((xs[i] - xs[k]) ** 2 + (ys[i] - ys[k]) ** 2) ** 0.5
a = s / n * 2
print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
L = []
for i in range(N):
    x,y = map(int, input().split())
    L.append([x,y])
def distance(List):
    s = 0
    for i in range(N-1):
        s += ( (List[i][0]-List[i+1][0])**2+(List[i][1]-List[i+1][1])**2 )**0.5
    return s
import itertools
import math
n = math.factorial(N)
A = list(itertools.permutations(L))
d = 0
for i in range(n):
    d += distance(A[i])
print(d/n)

Submission status: Accepted

Solution code:
import itertools
import math

n = int(input())
A = [[0,0] for _ in range(n)]
for i in range(n):
    A[i] = [int(s) for s in input().split()]


B = [s for s in range(n)]
al_list = list(itertools.permutations(B))
#print(al_list)

mx = math.factorial(n)

sm = 0
for j in range(mx):
    res = 0
    for k in range(n-1):
       st = al_list[j][k] 
       en = al_list[j][k+1]
       x_1,y_1 = A[st]
       x_2,y_2 = A[en]
       dist = math.sqrt((x_1-x_2)**2 + (y_1-y_2)**2)
       res += dist
    
    sm += res

print(sm/mx)
#print(A)

Submission status: Accepted

Solution code:
import itertools
import math

def dist(p1, p2):
    x1, y1 = p1
    x2, y2 = p2
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
n = int(input())
p = [tuple(map(int, input().split())) for _ in range(n)]
num = [i for i in range(n)]
avr = 0
for i, j in itertools.combinations(num, 2):
    avr += dist(p[i], p[j])
print(avr * 2 / n)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
import time
from bisect import bisect_left, insort_left, bisect_right
import sys
import random
from itertools import permutations

input = sys.stdin.readline
_NUMINT_ALL = list(range(10))
_START_TIME = time.time()


def main():
    ans = solve()

    if ans is True or ans is False:
        YesNo(ans)
    elif ans is not None:
        print(ans)


def solve():
    N = iip()[0]
    XY = iipt(N)
    n = 0
    s = 0

    for p in permutations(range(N)):
        cur_x = XY[p[0]][0]
        cur_y = XY[p[0]][1]


        for i in p[1:]:
            x = XY[i][0]
            y = XY[i][1]
            s += ((cur_x-x)**2+(cur_y-y)**2) ** 0.5
            cur_x = x
            cur_y = y
        n += 1

    print(s/n)



#####################################################ライブラリ集ここから




def kiriage_warizan(a, b):
    return -(-a//b)


def iip(listed=True):  # 数字のinputをlistで受け取る
    d = input().rstrip("\n").split()
    try:
        ret = [int(i) for i in d]
    except:
        ret = [int(i) if i in _NUMINT_ALL else i for i in d]
        if len(ret) == 1 and listed is False:
            return ret[0]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iipt(l, listed=True, num_only=True):  # 縦向きに並んでいるデータをリストに落とし込む(iip利用)
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed))
    return ret


def saidai_kouyakusuu(A):  # 最大公約数
    l = len(A)
    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m

def time_debug_10percent():
    a = random.randint(0, 9)
    if a == 9:
        sys.exit()

def time_debug(t):
    time.sleep(_START_TIME + t - time.time())
    sys.exit()


def make_graph_edge_flat(N):  # グラフ作成のための辺をリストで返す
    ret = []
    for i in range(N-1):
        a, b, c = iip()
        a -= 1
        b -= 1
        ret[a].append((b, c))
        ret[b].append((a, c))
    return ret


def sort_tuples(l, index):  # タプルのリストを特定のインデックスでソートする
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  # リストの中身の個数を種類分けして辞書で返す
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  # listの中身を取り出す時、listからはみ出たり
    if index >= len(l):                      # マイナスインデックスになったりするのを防ぐ
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def sortstr(s):  # 文字列をソートする
    return "".join(sorted(s))


def iip_ord(startcode="a"):  # 文字列を数字の列に変換する(数字と文字は1:1対応)
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  # TrueFalseや1, 0をYesNoに変換する
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  # リストを平たくしてprintする(二次元リストを見やすくしたりとか)
    for i in s:
        print(i)


def bitall(N):  # ビット全探索用のインデックスを出力
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  # リストの中身をスペース区切りで出力する
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  # リストの中身を改行区切りで出力する
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  # 素因数分解
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  # nCrをmodを使って計算する
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):  #  modnにおける逆元を計算
    return power(n, mod - 2)


def power(n, p, mod_=mod):  # 繰り返し二乗法でn**p % modを計算
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


def nibutan_func(func, target, left, right, side="left"): # 関数を二分探索
    l = left
    r = right
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if func(x) == target:
            return x
        elif func(x) > target:
            r = x
        else:
            l = x

    if side == "left" or func(x) == target:
        return l
    else:
        return r


def nibutan_list(list_, target, side="left"):  # リストを二分探索
    if not isinstance(list_, list):
        list_ = list(list_)

    l = 0
    r = len(list_)
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if list_[x] == target:
            return x
        elif list_[x] > target:
            r = x
        else:
            l = x

    if side == "left" or list_[x] == target:
        return l
    else:
        return r


class UfTree():
    def __init__(self, maxnum):
        self.parent = list(range(maxnum))
        self._size = [1] * maxnum
        self.rank = [0] * maxnum

    def size(self, a):
        return self._size[self.root(a)]

    def root(self, a):
        rank = 0
        cur = a
        while True:
            if self.parent[cur] == cur:
                #for i in path: # 経路圧縮
                #    self.parent[i] = cur
                return cur
            else:
                self.parent[cur] = self.parent[self.parent[cur]]
                cur = self.parent[cur]
                rank += 1

    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return self

        self._size[ra] += self._size[rb]
        self.parent[rb] = ra
        return self

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
xy = [0] * N
for i in range(N):
  xy[i] = list(map(int, input().split()))
  
#nC2通りの選び方のうち毎回n-1個の通りを選ぶ
#合計のながさ * (N - 1) /(nC2) = 合計 * 2 / N


ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import math
import itertools
from scipy.spatial import distance

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

d = 0
for i in itertools.permutations(l):
    for j in range(n-1):
        if j+1 < n:
            d += math.sqrt((i[j][0] - i[j+1][0]) ** 2 + (i[j][1] - i[j+1][1]) ** 2)

print(d/math.factorial(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math

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

ans = 0
ps = itertools.permutations(range(n))
c = 0
for ls in ps:
    c += 1
    head, tail = ls[0], ls[1:]
    for i in tail:
        x0, y0 = xy[head]
        x, y = xy[i]
        ans += math.sqrt((x - x0) ** 2 + (y - y0) ** 2)
print(ans / c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from collections import defaultdict
import itertools
N = int(input())
town = [[int(i) for i in input().split(' ')] for _ in range(N)]

dist = 0
c = 0
for v in itertools.permutations(town,len(town)):
    c += 1
    sx = v[0][0]
    sy = v[0][1]
    for i in v[1::]:
        dist += math.sqrt((sx - i[0]) ** 2 + (sy - i[1]) ** 2)
        sx, sy = i[0], i[1]

print(dist/c)

Submission status: Accepted

Solution code:
n=int(input())
A=[]
B=[]
sum=0
for i in range(n):
    a,b=map(int,input().split())
    A+=[a]
    B+=[b]
for i in range(n):
    for j in range(n):
        if i<j:
            sum+=((A[i]-A[j])**2+(B[i]-B[j])**2)**(1/2)
print(2*sum/n)

Submission status: Accepted

Solution code:
import math
N = int(input())
XY = [0]*N
for i in range(N):
    XY[i] = list(map(int,input().split()))
sum = 0


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

ans = sum * 2 / N
print(ans)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

d_sum = 0
cnt = 0
for i in range(n):
    for j in range(n):
        if i != j:
            d_sum += math.sqrt((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2)
            cnt += 1

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

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
pointXY = []
for _ in range(N):
    x, y = map(int, input().split())
    pointXY.append((x, y))
ans = 0
for xy in itertools.permutations(pointXY):
    tmpx = xy[0][0]; tmpy = xy[0][1]
    for (x, y) in xy[1:]:
        ans += math.sqrt((tmpx-x)**2 + (tmpy-y)**2)
        tmpx = x; tmpy = y
print(ans/math.factorial(N))

Submission status: Accepted

Solution code:
import math
N = int(input())
List = [list(map(int,input().split(" "))) for i in range(N)]

def fa(n):
  num = 1
  for i in range(1, n+1):
    num = num * i
  return num

dist = 0
for i in range(N):
  for j in range(i, N):
    dist += math.sqrt((List[i][0] - List[j][0])**2 + (List[i][1] - List[j][1])**2) * 2 * fa(N - 1)
print(dist / fa(N))