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
from itertools import permutations

cache = {}

def distance(p1, p2):
    dist = cache.get((p1, p2))
    if dist is not None:
        return dist
    x1, y1 = p1
    x2, y2 = p2
    dist = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
    cache[(p1, p2)] = dist
    return dist

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

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

count = 0
total_dist = 0
for p in permutations(t, len(t)):
    count += 1
    dist = 0
    for i in range(len(t) - 1):
        dist += distance(p[i], p[i + 1])
    total_dist += dist

print(total_dist / count)

Submission status: Accepted

Solution code:
import math

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

rtot = 0
temp = 1

for i in range(N):
    # temp *= i + 1
    for j in range(N):
        if i == j:
            continue
        rtot += math.sqrt( (xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2 )

# res = rtot / temp
ans = rtot / N

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
data=[]
for i in range(n):
    x,y=map(int,input().split())
    data.append((x,y))
ans=0
for i in range(n):
    for j in range(i+1,n):
        xi,xj,yi,yj=data[i][0],data[j][0],data[i][1],data[j][1]
        ans+=(((xi-xj)**2+(yi-yj)**2)**0.5)
ans*=2

print(ans/n)

Submission status: Accepted

Solution code:
import math

N=int(input())

t=[]
a=[0]*N

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

for i in range(N):
    for j in range(N):
        if i!=j:
            a[i]+=math.sqrt((t[i][0]-t[j][0])**2+(t[i][1]-t[j][1])**2)
    a[i]/=N-1

print(sum(a)*(N-1)/N)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
input=lambda :sys.stdin.readline().rstrip()
inputs= sys.stdin.buffer.readlines
INF=float("inf")
MOD=10**9+7
#input = sys.stdin.buffer.readline
#sys.setrecursionlimit(2147483647)
#rstrip().decode('utf-8')
import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#map(int,input().split())


def main():
	X=[]
	Y=[]
	n=int(input())
	ans=0
	for i in range(n):
		x,y=map(int,input().split())
		X.append(x)
		Y.append(y)
	
	for i in range(n-1):
		for j in range(i+1,n):
			ans+=((X[i]-X[j])**2+(Y[i]-Y[j])**2)**0.5
	
	print(ans*2/n)
	
	
	
	
	
if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
N = int(raw_input())
r=[]
for i in range(N):
    r.append(map(int, raw_input().split()))

ave = 0.0
for i in range(N):
    xi = r[i][0]
    yi = r[i][1]
    for j in range(i, N):
        xj = r[j][0]
        yj = r[j][1]
        rij = ((xi-xj)**2 + (yi-yj)**2)**0.5
        ave = ave + rij

ave = ave*2/N

print ave

Submission status: Accepted

Solution code:
from itertools import permutations
def dist(a,b):
    return ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5
n = int(input())
coords =[ ]
for _ in range(n):
    coords.append(tuple(int(x) for x in input().split()))
c=0
d = 0
for perm in permutations(range(n), n):
    for i, val in enumerate(perm[1:]):
        d += dist(coords[perm[i]], coords[val])
    c+=1
print(d / c)

Submission status: Accepted

Solution code:
n = int(input())
x = [0 for i in range(n)]
y = [0 for i in range(n)]

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

ans = 0

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

ans /= n / 2

print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

n = int(input())

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

p_list = list(itertools.permutations(li, n))

def cal_distance(lis):
    dis = 0
    for i in range(n-1):
        dis += math.sqrt((lis[i+1][0]-lis[i][0])**2 + (lis[i+1][1] - lis[i][1])**2)
    return dis

total_distance = 0
for i in range(len(p_list)):
    total_distance += cal_distance(p_list[i])

print(total_distance/len(p_list))

Submission status: Accepted

Solution code:

from math import factorial
from itertools import permutations

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

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

sum = 0

for r in permutations(v):
    d = 0
    x1, y1 = r[0]
    for u in r[1:]:
        x2, y2 = u
        d += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
    sum += d

print(sum / factorial(n))

Submission status: Accepted

Solution code:
import math
n = int(input())
x = []
y = []
for _ in range(n):
    xi, yi = map(int, input().split())
    x.append(xi)
    y.append(yi)
    
total = 0
for i in range(n):
    for j in range(i):
        total += math.sqrt((x[j] - x[i])**2 + (y[j] - y[i])**2)
print(total/(n/2))

Submission status: Accepted

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

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

print(d*2/N)

Submission status: Accepted

Solution code:
from itertools import permutations
import math
n = int(input())
res = []
for i in range(n):
    s = list(map(int,input().split()))
    res.append(s)
perm= permutations(res)
ans = 0
total = 1
for i in range(1,n+1):
    total = total*i
for i in perm:
    k = 0
    for j in range(1,len(i)):
        k+=math.sqrt(((i[j][0]-i[j-1][0])**2)+((i[j][1]-i[j-1][1])**2))
    ans+=(k/total)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import itertools
def fraction(n):
    r = 1
    for i in range(n):
        r *= (i+1)
    return(r)


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


for i in range(n):
    for j in range(n):
        d[i][j] = np.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)


seq = range(n)

p = list(itertools.permutations(seq))
a = 0.0
for pp in p:
    for i in range(n-1):
        a += d[pp[i]][pp[i+1]]
print(a/fraction(n))

Submission status: Accepted

Solution code:
import itertools
import math


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


def main():
    n = int(input())

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

    seq = range(n)
    sum_distance = 0
    for p in itertools.permutations(seq):
        for i in range(n-1):
            sum_distance += distance(towns[p[i]], towns[p[i+1]])
    ans = sum_distance / math.factorial(n)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math

N = int(sys.stdin.readline())
x = []
y = []
for i in range(N):
    tempx, tempy = map(int, sys.stdin.readline().split())
    x.append(tempx)
    y.append(tempy)


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

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


distance = 0
count = 0

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

print(distance/(count/(N-1)))

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())

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

tot = 0
for path in itertools.permutations(towns, N):
    path_length = 0
    for i, (x, y) in enumerate(path[:-1]):
        path_length += math.sqrt(
            (x - path[i + 1][0]) ** 2 + (y - path[i + 1][1]) ** 2
        )
    tot += path_length

print(tot / math.factorial(N))

Submission status: Accepted

Solution code:
N = int(input())

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


def CalDistence(x0, y0, x1, y1):
    return (((x0 - x1) ** 2) + (y0 - y1) ** 2) ** 0.5


AllDistance = 0
for i in range(N):
    for j in range(N):
        if i != j:
            AllDistance += CalDistence(x[i], y[i], x[j], y[j])

print(AllDistance / N)

Submission status: Accepted

Solution code:
from math import sqrt
from itertools import permutations as per
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
kumi = per(range(N))
ans = []
leng = 0
for p in kumi:
    cnt = 0
    for i in range(1, len(p)):
        cnt += sqrt((xy[p[i-1]][0] - xy[p[i]][0])**2 + (xy[p[i-1]][1] - xy[p[i]][1])**2)
    ans.append(cnt)
    leng += 1
print(sum(ans) / leng)

Submission status: Accepted

Solution code:
import math

n  = int(input())
ps = []
ds = []
a  = 1
b  = 1

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

for i in range(1, n):
	a *= i
	b *= i

b *= n

for i in range(0, n):
	for j in range(0, n):
		if i != j:
			dx = ps[i][0] - ps[j][0]
			dy = ps[i][1] - ps[j][1]
			ds.append(math.sqrt(dx * dx + dy * dy) * a)

print(sum(ds) / b)

Submission status: Accepted

Solution code:
import itertools

n = int(input())

route = [list(map(int, input().split())) for _ in range(n)]
results = []
for v in itertools.permutations(route, r=n):
    distance = 0
    for i in range(n - 1):
        start, goal = v[i], v[i + 1]
        distance += ((goal[0] - start[0]) ** 2 + (goal[1] - start[1]) ** 2) ** 0.5
    results.append(distance)
print(sum(results) / len(results))

Submission status: Accepted

Solution code:
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
length = []
for i in range(N):
    for j in range(i+1, N):
        l = (XY[j][0] - XY[i][0]) ** 2 + (XY[j][1] - XY[i][1]) ** 2
        length.append(l ** (1/2))
#print(len(length))
if N == 2:
    answer = sum(length)
else:
    answer = sum(length) * (N-1) / ((N-1) * N // 2)
print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

from itertools import permutations
from math import sqrt, factorial

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  points = [readInts() for _ in range(N)]

  s = 0
  for r in permutations(points):
    for i in range(N-1):
      x1, y1 = r[i]
      x2, y2 = r[i+1]
      s += sqrt((x2 - x1)**2 + (y2 - y1)**2)
  print(s / factorial(N))

if __name__ == "__main__":
  main()

Submission status: Accepted

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

dist = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        dist += (((x[i]-x[j])**2) + ((y[i]-y[j]) ** 2)) ** 0.5
print(dist/n)

Submission status: Accepted

Solution code:
import itertools
import math


n = int(input())
l = []
for i in range(n):
    l.append([int(_) for _ in input().split()])
ans = 0
for i in list(itertools.permutations(range(n))):
    for j in range(n-1):
        ans += math.sqrt((l[i[j]][0] - l[i[j+1]][0])**2 + (l[i[j]][1] - l[i[j+1]][1])**2)
print(ans/math.factorial(n))

Submission status: Accepted

Solution code:
import itertools

N = int(input())
table = [[0] * N for i in range(N)]
points = []
A = [i for i in range(N)]
ans = 0
count = 0

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

for i in range(N):
    for j in range(N):
        dist = ((points[j][0]-points[i][0])**2 + (points[j][1]-points[i][1])**2)**(1/2)
        table[i][j] = dist
        table[j][i] = dist

for p in itertools.permutations(A,N):
    tmp = 0
    for k in range(N-1):
        tmp += table[p[k]][p[k+1]]
    ans += tmp
    count += 1
print(ans/count)

Submission status: Accepted

Solution code:
import math

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

def dist(a, b):
  return math.sqrt(dist2(a, b))

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

ans = 0
for i in range(N):
  for j in range(i+1,N):
    ans += dist(coordinates[i], coordinates[j])

print(ans*2/N)

Submission status: Accepted

Solution code:
import math
import itertools

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

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

ans = 0
n = 0
for p in itertools.permutations(xy, N):
    d = 0
    for i in range(len(p)-1):
        d += get_dist(p[i], p[i+1])
    ans += d
    n += 1

print(ans / n)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
b=0
for i,j in zip(a[::2],a[1::2]):
    for k,l in zip(a[::2],a[1::2]):
        b+=((i-k)**2+(j-l)**2)**0.5
print(b/n)

Submission status: Accepted

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


def main():
    N = int(input())
    A = []
    for _ in range(N):
        x, y = map(int, input().split())
        A.append((x, y))
    ans = 0
    for a in itertools.permutations(range(N)):
        for i in range(len(a)-1):
            dx = A[a[i]][0]-A[a[i+1]][0]
            dy = A[a[i]][1]-A[a[i+1]][1]
            ans += math.sqrt((dx**2) + (dy**2))
    n = 1
    for i in range(1, N+1):
        n *= i
    print(ans/n)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        ans += math.sqrt(math.pow(paths[i][0] - paths[j][0], 2) + math.pow(paths[i][1] - paths[j][1], 2))

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

Submission status: Accepted

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

s = 1
t = 1
dis = 0

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

for j in range(1,n):
    t *= j
    
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        dis += ((li[i][0] - li[j][0])**2 + (li[i][1] - li[j][1])**2)**0.5

print(t*dis/s)

Submission status: Accepted

Solution code:
from itertools import permutations
import numpy as np

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

avg = []
for pair in list(permutations(towns)):
    x_prev = None
    y_prev = None
    dist = 0
    for i, (x, y) in enumerate(pair):
        if i > 0:
            dist += np.sqrt((x-x_prev)**2 + (y-y_prev)**2)
        x_prev = x
        y_prev = y
    
    avg.append(dist)

print('{:.10f}'.format(np.mean(avg)))

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial
from scipy.spatial import distance_matrix
import numpy as np

n = int(input())
x = []
for i in range(n):
    x.append(list(map(int, input().split())))
x = np.array(x)
d = distance_matrix(x, x)

res = 0
for path in permutations(range(n)):
    path = list(path)
    res += np.sum(d[path[:-1], path[1:]])
print(res/factorial(n))

Submission status: Accepted

Solution code:
import itertools
import math
n=int(input())
cal=[[0 for _ in range(n)] for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        d=math.sqrt((p[i][0]-p[j][0])**2+(p[i][1]-p[j][1])**2)
        cal[i][j]=d
    
kumi=list(itertools.permutations([i for i in range(n)]))
total=0
l=len(kumi)
for each in kumi:
    tmp=0
    for i in range(len(each)-1):
        tmp+=cal[each[i]][each[i+1]]
    tmp/=l
    total+=tmp
print(total)

Submission status: Accepted

Solution code:

import math
import sys
import itertools

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


ans = 0
fact = 1
for i in range(N):
    fact *= (i+1)

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

ans /= fact
print(ans)

Submission status: Accepted

Solution code:
import math
n = int(raw_input())
d = []
for i in range(n):
    tmp = map(int, raw_input().split())
    d.append(tmp)

ds = []
for i in range(n):
    for j in range(i+1,n):
        x0, y0 = d[i]
        x1, y1 = d[j]
        ds.append(math.sqrt((x0-x1)**2 + (y0-y1)**2))

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

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

print sum(map(lambda x: x*t*2,ds)) / n_

Submission status: Accepted

Solution code:
import math
N = int(input())
cands = [list(map(int, input().split())) for i in range(N)]
def calc_dis(x, y):
  return math.sqrt((x[0]-y[0])**2+(x[1]-y[1])**2)

sums = [[0 for i in range(N)] for i in range(N)]
for i in range(N):
  for j in range(i+1, N):
    sums[i][j] = calc_dis(cands[i], cands[j])

print(sum([sum(s) for s in sums])*2/N)

Submission status: Accepted

Solution code:
import sys
import itertools
import math
input=sys.stdin.readline
n=int(input())
G=[]
for i in range(n):
    x,y=map(int,input().split())
    G.append((x,y))
l=[i for i in range(n)]
p=itertools.permutations(l,n)
Sum=0
for i in p:
    pre=i[0]
    for j in range(1,n):
        now=i[j]
        Sum+=math.sqrt((G[pre][0]-G[now][0])**2+(G[pre][1]-G[now][1])**2)
        pre=now
ans=Sum/math.factorial(n)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
x=[]
y=[]
for i in range(N):
    xi, yi = map(int,input().split())
    x.append(xi)
    y.append(yi)
    
import itertools
total =0
for a,b in itertools.permutations(range(N), 2):
    len_x = (x[a]-x[b])**2
    len_y = (y[a]-y[b])**2
    length = (len_x+len_y)**0.5
    total+=length / N
print(total)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial
n=int(input())
A=[list(map(int,input().split())) for i in range(n)]

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

Submission status: Accepted

Solution code:
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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


def main():
    N = int(input())

    seq = [list(map(int, input().split())) for _ in range(N)]
    arr = list(itertools.permutations(seq))
    l = len(arr)

    k = 0
    for x in arr:
        for i in range(N-1):
            k += kyori(x[i], x[i+1])

    print(k / l)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input()) 
e = [[int(i) for i in input().split()] for i in range(N)] 
import itertools
seq = list(itertools.permutations(e))


def diff(x1,y1,x2,y2):
  return ((x1-x2)**2+(y1-y2)**2)**0.5

l = 0
for i in seq:
  for j in range(1,N):
    l += diff(i[j][0],i[j][1],i[j-1][0],i[j-1][1])
print(l/len(seq))

Submission status: Accepted

Solution code:
import itertools
import math

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

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

total = 0
for i in range(len(c)):
    x = xy[c[i][0]][0]
    y = xy[c[i][0]][1]
    dist = 0
    for j in range(1,len(c[i])):
        tmp_x = xy[c[i][j]][0]
        tmp_y = xy[c[i][j]][1]
        dist += math.sqrt((x - tmp_x) ** 2 + (y - tmp_y) ** 2)
        x = tmp_x
        y = tmp_y
    total += dist

print(total/len(c))

Submission status: Accepted

Solution code:
import math
import itertools

ans = 0

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
root = [i for i in range(n)]
roots = list(itertools.permutations(root))
for i in roots:
    for j in range(1, n):
        ans += math.sqrt(((xy[i[j - 1]][0] - xy[i[j]][0]) ** 2 +  (xy[i[j - 1]][1] - xy[i[j]][1]) ** 2))


print(ans / len(roots))

Submission status: Accepted

Solution code:
import math
from itertools import permutations

N = int(input())
p = [[int(_) for _ in input().split()] for _ in range(N)]

s = 0
cnt = 0
for a in permutations(p):
    for i in range(1, len(a)):
        s += math.sqrt((a[i-1][0]-a[i][0]) **2 + (a[i-1][1]-a[i][1]) **2)
    cnt +=1
print(s/cnt)

# for i in range(N-1):
#     for j in range(i+1,N):
#
#         cnt +=1
# print(s,cnt)
# print(s/cnt)

Submission status: Accepted

Solution code:
import math
import itertools
def length(X,Y,c):
    sum_=0
    for i in range(len(c)-1):
        sum_+=math.sqrt((X[c[i]]-X[c[i+1]])**2 + (Y[c[i]]-Y[c[i+1]])**2)
    #print(sum_)
    return sum_
N=int(input())
X=[0]*N
Y=[0]*N
for i in range(N):
    X[i], Y[i] = map(int,input().split())
C = list(itertools.permutations(range(0,N)))
sum_=0
for c in C:
    sum_+=length(X,Y,c)
print(sum_/len(C))

Submission status: Accepted

Solution code:
import itertools
import math
n = int(input())
ans = 0
data = []
per = itertools.permutations(range(n))
for i in range(n):
    data.append(list(map(int, input().split())))
for i in per:
    for k in range(n):
        if  k == n - 1:
            break
        ans += math.sqrt(((data[i[k]][0] - data[i[k+1]][0]) ** 2) + ((data[i[k]][1] - data[i[k+1]][1]) ** 2))
print(ans / math.factorial(n))

Submission status: Accepted

Solution code:
import math
N = int(input())
li = []

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

sum = 0
for l1 in li:
  for l2 in li:
    sum += math.sqrt((l1[0]-l2[0]) ** 2 + (l1[1]-l2[1]) ** 2)/N

print(sum)

Submission status: Accepted

Solution code:
import itertools

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

sum_length = 0
for i, j in itertools.product(coordinates, coordinates):
    sum_length += pow((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2, 1/2)

average_length = sum_length / n
print(average_length)

Submission status: Accepted

Solution code:
import math

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

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

ans = sum*2/n

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n=int(input())
L=[list(map(int,input().split())) for _ in range(n)]
D=0
for i in range(n-1):
    for j in range(i+1,n):
        D += 2*math.factorial(n-1)*(((L[i][0]-L[j][0])**2 
        + (L[i][1]-L[j][1])**2)**0.5)
print(D/math.factorial(n))

Submission status: Accepted

Solution code:
import itertools
import math


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

nfact = math.factorial(n)

sum = 0

perm = list(itertools.permutations(xy))

for i in range(nfact):
    xy_ = perm[i]
    dist = 0
    for j in range(0,n-1):
        x1, y1 = xy_[j]
        x2, y2 = xy_[j+1]
        dist += ( (x1-x2)**2 + (y1-y2)**2 )**0.5
    sum += dist

ans = sum/nfact

print(ans)