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:
import math

n = int(input())

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

d = []

for i in range(n):
    for j in range(i+1,n):
        dist = math.sqrt((a[i][0]-a[j][0])**2 + (a[i][1]-a[j][1])**2)
        d.append(dist)

sm = sum(d)

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


print(sm*2 /n)

Submission status: Accepted

Solution code:
import itertools 
import math

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

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
num = [i for i in range(n)]
li = list(itertools.permutations(num))
ans = 0
for per in li:
  for i in range(len(per)-1):
    ans += length(xy[per[i]][0], xy[per[i]][1], xy[per[i+1]][0], xy[per[i+1]][1])

print(ans/len(li))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math

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

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

seq = []
for i in range(N): seq.append(i)
per = list(itertools.permutations(seq))

ave = 0
for i in range(len(per)):
  tmp = list(per[i])
  for j in range(len(tmp)):
    if(j != 0):
      ave += dis(pos[tmp[j-1]][0],pos[tmp[j-1]][1],pos[tmp[j]][0],pos[tmp[j]][1])
ave = ave/len(per)
print(ave)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
L = list(range(N))
jun = list(itertools.permutations(L))
# print(jun)

ans = 0


for j in jun:
    for num, index in enumerate(j):
        if num == 0:
            bx, by = XY[index]
            continue
        else:
            x, y = XY[index]
            ans += ((x - bx) ** 2 + (y - by) ** 2) ** (0.5)
            bx, by = x, y
# print(len(jun))
print(ans / len(jun))

Submission status: Accepted

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

#p = n * (n-1) * (n-1) // 2
p = n / 2

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

print(d)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial, hypot
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for t in permutations(XY):
    for (x1, y1), (x2, y2) in zip(t[1:], t[:-1]):
        ans += hypot(x1-x2, y1-y2)

print(ans / factorial(N))

Submission status: Accepted

Solution code:
# ABC145c


def main():
    import sys
    import itertools
    import math
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    # map(int,input().split())
    n = int(input())
    town = [tuple(map(int, input().split())) for _ in range(n)]
    ans = 0

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

    def permutations_count(n, r):
        return math.factorial(n) // math.factorial(n - r)

    for i in itertools.permutations(town, n):
        # print(i)
        t = 0
        for j in range(1, n):
            t += kyori(i[j - 1], i[j])
        # print(t)
        ans += t
    print(ans/math.factorial(n))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

N=int(input())
AB=[list(map(int,input().split())) for i in range(N)]
M=math.factorial(N-1)
k=0

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

print(k/N)

Submission status: Accepted

Solution code:
import sys
import itertools
import math
from heapq import heapify, heappop, heappush
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
xy = [IL() for i in range(N)]

ans = 0
for i in itertools.permutations(xy):
  for j in range(N-1):
    x1, y1 = i[j]
    x2, y2 = i[j + 1]
    ans += math.sqrt( (x1 - x2)**2 + (y1 - y2)**2 )
num = 1
for i in range(1, N+1):
  num *= i
print(ans/num)

Submission status: Accepted

Solution code:
def examC():
    N = I()
    xy = [LI() for _ in range(N)]
    ansC = []
    for course in itertools.permutations(xy):
        cur = float(0)
        for i in range(len(course) - 1):
            cur += ((course[i+1][0]-course[i][0])**2 + (course[i+1][1]-course[i][1])**2)**(1/2)
        ansC.append(cur)
#    print(ansC)
    ans = sum(ansC)/len(ansC)
    print(ans)

import sys,copy,bisect,itertools
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 LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Accepted

Solution code:
#
import sys
import math
import numpy as np
import itertools
# ひとつ入力
n = int(input())

# n行の複数列ある数値を二次元配列へ。x[n][?]
xy = [[int(i) for i in input().split()] for i in range(n)]

a=0

for i in range(n):
    for j in range(n):
        if i==j:
            continue
        else:
            a += 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/n)

Submission status: Accepted

Solution code:
N=int(input())
XY=[list(map(int,input().split())) for i in range(N)]
from itertools import permutations
r=0
for xy in permutations(XY):
    for i in range(N-1):
        r+=((xy[i][0]-xy[i+1][0])**2+(xy[i][1]-xy[i+1][1])**2)**.5
p=1
for i in range(N):
    p*=i+1
print(r/p)

Submission status: Accepted

Solution code:

import  scipy
import  numpy as np
import  itertools

n = int(input())
arr = []
def dist(a,b):
  return  np.sqrt((a[0]-b[0])*(a[0]-b[0])+(a[1]-b[1])*(a[1]-b[1]))

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

hoge = 0
ind = 0
for z in itertools.permutations(range(n)):
  ind += 1
  for i in range(n-1):
    # print(arr[i],arr[i+1])
    hoge += dist(arr[z[i]],arr[z[i+1]])

print(hoge/ind)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i,x in enumerate(xy):
  x1, y1 = x[0], x[1]
  for x2,y2 in xy[i+1:]:
    ans += ((x2-x1) ** 2 + (y2-y1) ** 2) ** 0.5
ans /= n / 2
print(ans)

Submission status: Accepted

Solution code:
import math
import itertools

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


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


d = [[0 for _ in range(N)] for _ in range(N)]

for i in range(N):
    for j in range(N):
        d[i][j] = distance(XY[i], XY[j])

res = 0
for n in list(itertools.permutations(range(N))):
    for i in range(len(n) - 1):
        res += d[n[i]][n[i + 1]]

print(res / math.factorial(N))

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

kkk = []

for i in range(n):
    kkk.append(l())

su = 0


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

print(su/(n/2))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from math import sqrt
from itertools import permutations

n = ni()
xy = [list(li()) for _ in range(n)]

zton = [i for i in range(n)]
lst = permutations(zton)

total = 0
for route in lst:
    dist = 0
    for st, ed in zip(route[:-1], route[1:]):
        dist += sqrt((xy[ed][0] - xy[st][0])**2 + (xy[ed][1] - xy[st][1])**2)
    total += dist

bunbo = 1
for i in range(1,n+1):
    bunbo *= i

print(total / bunbo)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import itertools
import math
n = int(input())
xs = []
ys = []
for _ in range(n):
    x, y = map(int, input().split())
    xs += [x]
    ys += [y]
num = 0
den = 0
for p in itertools.permutations(range(n)):
    dist = 0
    for i in range(n - 1):
        x1 = xs[p[i]]
        y1 = ys[p[i]]
        x2 = xs[p[i + 1]]
        y2 = ys[p[i + 1]]
        dist += math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
    num += dist
    den += 1
print('%.12f' % (num / den))

Submission status: Accepted

Solution code:
import math

N = int(input())
X,Y = [],[]
for i in range(N):
    x,y = input().split()
    x,y = int(x),int(y)
    X.append(x)
    Y.append(y)
    
sum_ = 0
for i in range(N):
    for j in range(N):
        if(i != j):
            sum_ += math.sqrt((X[i]-X[j])**2+(Y[i]-Y[j])**2)

print(sum_/N)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import sqrt

def factorial(n):
  if n < 2:
    return 1
  return n * factorial(n - 1)


def distance(a, b):
  dx = a[0] - b[0]
  dy = a[1] - b[1]
  return sqrt(dx * dx + dy * dy)


def calc_len(points, perm):
  res = 0
  for i in range(1, len(perm)):
    a = points[perm[i]]
    b = points[perm[i - 1]]
    res += distance(a, b)
  return res


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

total_len = 0
for perm in permutations(list(range(n))):
  total_len += calc_len(points, perm)
print(total_len / factorial(n))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    X,Y=[0]*n,[0]*n
    for i in range(n):
        X[i],Y[i]=map(int,input().split())

    from itertools import permutations
    from math import factorial
    ans=0
    for perm in permutations(range(n)):
        score=0
        for i in range(n-1):
            tmp=(X[perm[i+1]]-X[perm[i]])**2+(Y[perm[i+1]]-Y[perm[i]])**2
            tmp=tmp**.5
            score+=tmp
        ans+=score
    print(ans/factorial(n))
resolve()

Submission status: Accepted

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

m = 1
for i in range(1,N):
    m *= i

ans = 0

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

print(ans)

Submission status: Accepted

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

roads = []
for i in range(N-1):
    for j in range(i+1,N):
        t1 = town_list[i]
        t2 = town_list[j]
        length = ((t1[0]-t2[0])**2 + (t1[1] - t2[1])**2)** (1/2)
        roads.append(length)

print(sum(roads) / len(roads) * (N-1))

Submission status: Accepted

Solution code:
import itertools

N = int(input())

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

D = [[0]*N for i in range(N)]

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

Nn = 1
for i in range(1,N+1):
    Nn*=i

total = 0
for it in itertools.permutations(range(N)):
    s = 0
    for i in range(1,N):
        s+=D[it[i-1]][it[i]]
    total+=s

print(total/Nn)

Submission status: Accepted

Solution code:
from itertools import permutations

def calc_d(pos1, pos2):
  return ((pos1[0]-pos2[0])**2 + (pos1[1]-pos2[1])**2)**.5

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

sumd = 0
cnt = 0
for prm in permutations(XY):
  for i in range(N-1):
    sumd += calc_d(prm[i][:2],prm[i+1][:2])
  cnt += 1
print(sumd/cnt)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
xy = [tuple(map(int, input().split()))for i in range(N)]
ans = []
for p in itertools.permutations(range(N)):
    dist = 0
    for i, pi in enumerate(p):
        if i == 0:
            pre_x, pre_y = xy[pi]
            continue
        x, y = xy[pi]
        dist += ((pre_x - x)**2 + (pre_y - y) ** 2)**0.5
        pre_x, pre_y = x, y
    ans.append(dist)
print(sum(ans) / len(ans))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
l = list()
for n in range(N):
    l.append([int(x) for x in input().split()])
d = list()
for n in range(N):
    for m in range(n,N):
        d.append(np.sqrt((l[n][0]-l[m][0])**2+(l[n][1]-l[m][1])**2))
print(np.average(d)*(N+1))

Submission status: Accepted

Solution code:
import itertools
import math


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

costs = list()
indices = itertools.permutations(range(n))
for index in indices:
    cost = 0.0
    for i, j in zip(index[:-1], index[1:]):
        d2 = (xs[j] - xs[i]) ** 2 + (ys[j] - ys[i]) ** 2
        cost += math.sqrt(d2)
    costs.append(cost)

print(sum(costs) / len(costs))

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for d in permutations(list(range(n))):
    tmp = 0
    for i in range(n - 1):
        x, y = l[d[i]]
        a, b = l[d[i + 1]]
        tmp += ((x - a) ** 2 + (y - b) ** 2) ** .5
    ans += tmp
print(ans / factorial(n))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8
import math

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    lp = []
    dist = [[0 for _ in range(n)] for _ in range(n)]
    for i in range(n):
        x, y = rli()
        lp.append([x, y])
    ans = 0
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            dist[i][j] = math.sqrt((lp[i][0]-lp[j][0])**2+(lp[i][1]-lp[j][1])**2)
            ans += dist[i][j]
    ans /= n
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

t = 1
for i in range(1, N - 1):
  t *= i

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

n = 1
for i in range(1, N + 1):
  n *= i

ans /= n

print(ans)

Submission status: Accepted

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

seq = [i for i in range(N)]
import itertools
tar = list(itertools.permutations(seq))

ans = 0
for t in tar:
    s = 0
    p_x = -1
    p_y = -1
    for i, x in enumerate(t):
        x, y = items[x]
        if i != 0:
            tmp = (abs(p_x - x) ** 2 + abs(p_y - y) ** 2) ** 0.5
            ans += tmp
        p_x = x
        p_y = y
div = 1
for i in range(1, N+1):
    div *= i

print(ans / div)

Submission status: Accepted

Solution code:
import math
N=int(input())
ls=[[int(s) for s in input().split()] for i in range(N)]
def d(lsa,lsb):
  val=(lsa[0]-lsb[0])**2+(lsa[1]-lsb[1])**2
  return math.sqrt(val)
x=0
for i in range(N-1):
  for j in range(i+1,N):
    x+=d(ls[i],ls[j])
print(x*2/N)

Submission status: Accepted

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

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

S=0

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

print(S/(N*(N-1)/2)*(N-1))

Submission status: Accepted

Solution code:
from itertools import permutations
n = int(input())
div = 1
s = 0
for i in range(1, n + 1):
	div *= i
L = [list(map(int, input().split())) for _ in range(n)]
for x in permutations(range(n), n):
	s += sum(((L[i][0] - L[j][0]) ** 2 + (L[i][1] - L[j][1]) ** 2) ** .5 for i, j in zip(x, x[1:]))
print(s / div)

Submission status: Accepted

Solution code:
from itertools import permutations
n=int(input())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
c=0
g=0
for i in permutations(range(n),n):
    t=0
    c+=1
    for j in range(n-1):
        t+=((l[i[j]][0]-l[i[j+1]][0])**2+(l[i[j]][1]-l[i[j+1]][1])**2)**0.5
    g+=t
print(g/(1.0*c))

Submission status: Accepted

Solution code:
import  math
n=int(input())

def dist(xi,yi,xj,yj):
    tmp= math.sqrt((xi-xj)**2+(yi-yj)**2)
    return tmp

tw=[]
for i in range(n):
    q,r=map(int,input().split())
    tw.append([q,r])

ans=0

for i in range(0,n-1):
    for j in range(i+1,n):
        f=dist(tw[i][0],tw[i][1],tw[j][0],tw[j][1])
        ans+=f

print(2*ans/n)

Submission status: Accepted

Solution code:
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
s=0
c=0
for i in range(n):
  for j in range(i+1,n):
    x1,y1=xy[i]
    x2,y2=xy[j]
    s+=((x1-x2)**2+(y1-y2)**2)**.5
    c+=1
print(s*(n-1)/c)

Submission status: Accepted

Solution code:
N = int(input())
p = list(list(map(int,input().split()))for i in range(N))
ans = 0
for i in range(N):
    for j in range(i+1,N):
        x1,y1 = p[i]
        x2,y2 = p[j]
        ans += ((x1-x2)**2 + (y1 - y2)**2)**0.5
rate = 0
for i in range(N):
    rate += i
rate /= N-1
print(ans/rate)

Submission status: Accepted

Solution code:
n = int(input())
xy = []
for _ in range(n):
  xy.append(list(map(int,input().split())))
#print(xy)
xyxy = []
for i in range(n):
  tmp = []
  for j in range(n):
    tmp.append((((xy[i][0]-xy[j][0])**2)+(xy[i][1]-xy[j][1])**2)**.5)
  xyxy.append(tmp)
ans = 0
for i in range(n):
  for j in range(n):
    if i < j:
      ans += xyxy[i][j]
ans *= 2/n
print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
points = []
for _ in range(N):
    x, y = map(int, input().split())
    points.append((x, y))
P = list(itertools.permutations(list(range(N))))
ans = 0
for p in P:
    for i in range(N-1):
        x0, y0 = points[p[i]]
        x1, y1 = points[p[i+1]]
        ans+=((x1-x0)**2+(y1-y0)**2)**(1/2)
print(ans/len(P))

Submission status: Accepted

Solution code:
from math import hypot
N = int(input())
P = [tuple(int(x) for x in input().split()) for _ in range(N)]
term = 0
for i in range(N):
    for j in range(i + 1, N):
        x0, y0 = P[i]
        x1, y1 = P[j]
        term += hypot(x1 - x0, y1 - y0)
term /= N*(N - 1)//2
print((N - 1)*term)

Submission status: Accepted

Solution code:
import math
import itertools

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


def dis(t1, t2):
    return math.sqrt((t1[0] - t2[0]) ** 2 + (t1[1] - t2[1]) ** 2)


l = [i for i in range(n)]
res = 0
for sl in itertools.permutations(l):
    for i in range(1, n):
        res += dis(t[sl[i - 1]], t[sl[i]])
for i in range(n):
    res /= i + 1

print(res)

Submission status: Accepted

Solution code:
n=int(input())
s=0
xy=[tuple(map(int,input().split())) for _ in range(n)]
import itertools
l=[i for i in range(1,n+1)]
for y in itertools.permutations(l):
    for i in range(n-1):
        s+=((xy[y[i]-1][0]-xy[y[i+1]-1][0])**2+(xy[y[i]-1][1]-xy[y[i+1]-1][1])**2)**0.5
e=1
for i in range(1,n+1):
    e*=i
print(s/e)

Submission status: Accepted

Solution code:
import itertools
import math
N = int(input())
seq = list(range(N))
dic = {}
for i in range(N):
  x, y = map(int, input().split())
  dic[i] = (x,y)
ans = 0
for c in list(itertools.permutations(seq)):
  for j in range(N-1):
    nx, ny = dic[c[j+1]]
    x, y = dic[c[j]]
    ans += ((nx-x)**2 + (ny-y)**2)**0.5
print(ans/(math.factorial(N)))

Submission status: Accepted

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

all_root = list(itertools.permutations(xy))

ret = 0
for root in all_root:
    for i in range(len(root)-1):
        x = (root[i][0] - root[i+1][0]) ** 2
        y = (root[i][1] - root[i+1][1]) ** 2
        ret += math.sqrt(x+y)

print(ret/len(all_root))

Submission status: Accepted

Solution code:
import itertools

#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	L = []
	for i in range(N):
		x, y = getlist()
		L.append([x, y])
	X = [i for i in range(N)]
	Z = list(itertools.permutations(X))
	#print(Z)
	s = 0
	for i in range(len(Z)):
		for j in range(N - 1):
			x1 = L[Z[i][j]][0]
			y1 = L[Z[i][j]][1]
			x2 = L[Z[i][j + 1]][0]
			y2 = L[Z[i][j + 1]][1]
			s += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
	z = 1
	for i in range(N):
		z *= i + 1
	ans = s / z
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
from sys import stdin
from math import sqrt, factorial

def input():
    return stdin.readline()[:-1]


def intput():
    return int(input())


def sinput():
    return input().split()


def intsput():
    return map(int, sinput())



def distance(a, b):
    dx = a[0] - b[0]
    dy = a[1] - b[1]
    return sqrt(dx ** 2 + dy ** 2)

n = intput()

towns = []
dists = []

for _ in range(n):
    towns.append(list(intsput()))

for i in range(n):
    for j in range(i + 1, n):
        dists.append(distance(towns[i], towns[j]))

s = sum(dists)

print(s * 2 / n)

Submission status: Accepted

Solution code:
from itertools import permutations

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

d=[]
for i in permutations(l):
    t_d=0
    for j in range(len(i)-1):
        t_d+=((i[j][0]-i[j+1][0])**2+(i[j][1]-i[j+1][1])**2)**0.5
    d.append(t_d)
print(sum(d)/len(d))

Submission status: Accepted

Solution code:
from itertools import permutations as perm
from math import factorial

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

all_sum = 0
for a in perm(XY):
    sum_num = 0
    for j in range(N-1):
        x1, y1 = a[j]
        x2, y2 = a[j+1]
        r = (abs(x1-x2)**2 + abs(y1-y2)**2)**(1/2)
        sum_num += r
    all_sum += sum_num

print(all_sum / factorial(N))

Submission status: Accepted

Solution code:
from math import sqrt
from itertools import permutations


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


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

sm = 0
cnt = 0
for pat in permutations(xy, n):
    l = 0
    cnt += 1
    for e1, e2 in zip(pat, pat[1:]):
        x1, y1 = e1
        x2, y2 = e2
        l += dist(x1, y1, x2, y2)
    sm += l

ans = sm / cnt
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
xy=[list(map(int,input().split())) for _ in [0]*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
print(dist/(((n*(n-1))//2))*(n-1))

Submission status: Accepted

Solution code:
#%%
n = int(input())
x, y = [0] * n, [0] * n
for i in range(n):
    x[i], y[i] = map(float, input().split())

dis = [[0]*n for _ in range(n)] 
ans = 0

for i in range(n):
    for j in range(n):
        tmp = (x[i] - x[j])**2 + (y[i] - y[j])**2
        tmp = tmp**(1/2)
        dis[i][j] = tmp
        if i != j :
            ans += tmp

#print(dis)
#print(ans)
#print(ans/(n*(n-1)))
print(ans/n)

Submission status: Accepted

Solution code:
import math

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

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

print(kyori/n)

Submission status: Accepted

Solution code:
import math

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

main()

Submission status: Accepted

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

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

ans = 0
for ptn in permutations(range(N)):
    dist = 0
    for i in range(N-1):
        j1, j2 = ptn[i], ptn[i+1]
        dist += hypot(xs[j1]-xs[j2], ys[j1]-ys[j2])
    ans += dist

print(ans / factorial(N))

Submission status: Accepted

Solution code:
import itertools

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

P = list(itertools.permutations(range(N)))
l = 0
for p in P:
  for i in range(N-1):
    x0,y0 = XY[p[i]]
    x1,y1 = XY[p[i+1]]
    l += ((x1-x0)**2+(y1-y0)**2)**0.5
print(l/len(P))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
xy = [LIST() for _ in range(N)]

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

ans = 0
for n in permutations(range(N)):
	tmp = 0
	for i in range(N-1):
		tmp += dist(xy[n[i]], xy[n[i+1]])
	ans += tmp
print(ans/factorial(N))

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial

def dist(x1, y1, x2, y2):
    return ((x2-x1)**2 + (y2-y1)**2)**(1/2)


N = int(input())
xy = []
for _ in range(N):
    x, y = map(int, input().split())
    xy.append((x, y))
adj = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
    for j in range(N):
        adj[i][j] = dist(xy[i][0], xy[i][1], xy[j][0], xy[j][1])

ans = 0
for v_list in permutations(list(range(N))):
    for i in range(N-1):
        ans += adj[v_list[i]][v_list[i+1]]

print(ans / factorial(N))

Submission status: Accepted

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

import itertools

cnt = 0
ans = 0
for P in itertools.permutations(list(range(N))):
    cnt += 1
    tmp = 0
    for i in range(N-1):
        tmp += ((xy[P[i]][0]-xy[P[i+1]][0])**2+(xy[P[i]][1]-xy[P[i+1]][1])**2)**0.5
    ans += tmp
ans /= cnt
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(10 ** 9)



INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
X = []
Y = []
for x, y in LIR(n):
    X += [x]
    Y += [y]


ret = 0
for pat in list(permutations((range(n)))):
    for i in range(len(pat) - 1):
        ret += ((X[pat[i]] - X[pat[i + 1]]) ** 2 + (Y[pat[i]] - Y[pat[i + 1]]) ** 2) ** 0.5

print(ret / factorial(n))