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 i in range(n):
	array = list(map(int, input().split()))
	a.append(array)
	
c = 0

for i in range(n):
	for ii in range(n):
		c += math.sqrt((a[i][0] -a[ii][0])**2 + (a[i][1] -a[ii][1])**2 )

d = c / n

print(d)

Submission status: Accepted

Solution code:
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
dist = 0
for x1, y1 in XY:
    for x2, y2 in XY:
        dist += ((x1 - x2)**2 + (y1 - y2)**2)**(1/2)
print(dist/N)

Submission status: Accepted

Solution code:
#145c
import math
import itertools

N = int(input()) #N<=8 …8!=40320。総当たりOK

xy_list = [0]

for i in range(N): #8回ループ
    x,y = map(int, input().split())
    xy_list.append((x,y))
    
city_distance_dict = dict() #key = (from,to) , value = distance

for i in range(1,N+1):
    for j in range(1,N+1): #64/2回ループ
        xi = xy_list[i][0]
        yi = xy_list[i][1]
        xj = xy_list[j][0]
        yj = xy_list[j][1]
        distance = math.sqrt((xi - xj)**2 + (yi - yj)**2)
        city_distance_dict[(i,j)] = distance
        city_distance_dict[(j,i)] = distance

sum_distance = 0
route_list = list(itertools.permutations(range(1,N+1)))

for route in route_list: #40320
    distance = 0
    #print(route)
    for i in range(N-1): #7
        from_city = route[i]
        to_city = route[i+1]
        #print(from_city,"→",to_city,":",city_distance_dict[(from_city,to_city)])
        sum_distance += city_distance_dict[(from_city,to_city)]

#print(sum_distance)
#print(len(route_list))
print(sum_distance/len(route_list))

Submission status: Accepted

Solution code:
import itertools

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

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

dist = {}
for i in range(N):
    dist[i] = {}
    for h in range(N):
        if i == h:
            dist[i][h] = 0
        dist[i][h] = pow((Xs[i] - Xs[h]) * (Xs[i] - Xs[h]) + (Ys[i] - Ys[h]) * (Ys[i] - Ys[h]), 0.5)

whole = 0
for path in all_paths:
    for l, r in zip(path[:-1], path[1:]):
        whole += dist[l][r]

number = len(all_paths)
print(whole / number)

Submission status: Accepted

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

def kyori(a, b): # 2座標間の距離を求める関数
    return ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5

soukyori = 0
for j in range(n):#★各町のペア間の距離の総和の2倍
    for k in range(n):
        soukyori = soukyori + kyori(l[j],l[k])
#print(soukyori)
print((soukyori * 2)/n/2) #★解説を要再確認！！！

Submission status: Accepted

Solution code:
n = int(input())
l=[]
for i in range(n):
    x, y = [int(i) for i in input().split()]
    l.append([x, y])
#print(l)

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

soukyori = 0
for j in range(n):
    for k in range(n):
        soukyori = soukyori + kyori(l[j],l[k])
#print(soukyori)
print((soukyori * 2)/n/2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import numpy as np
import itertools

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

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

def roots_distance(roots):
  dist = 0
  for i in range((len(roots)-1)):
    dist+=distance(locates[roots[i]],locates[roots[i+1]])
    
  return dist

N = int(input())

locates = np.array([LI() for i in range(N)])

dist = 0
count = 0
for roots in itertools.permutations(range(N),N):
  dist+=roots_distance(roots)
  count+=1
  
print(dist / count)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
dis = []
for i in range(n):
    x,y = map(int,input().split())
    dis.append([x,y])

li = [i+1 for i in range(n)]

ans = 0
for elm in itertools.permutations(li):
    #print(elm)
    for j in range(len(elm)-1):
        ans += ((dis[elm[j]-1][0] - dis[elm[j+1]-1][0])**2 + (dis[elm[j]-1][1] - dis[elm[j+1]-1][1])**2) **0.5

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

print(ans/mm)

Submission status: Accepted

Solution code:
N=int(input())

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


from math import sqrt
def d(p1,p2):
    x1,y1=p1
    x2,y2=p2
    return sqrt((x1-x2)**2 + (y1-y2)**2)

s=0
n=0

import itertools
from functools import reduce
for p in itertools.permutations(P):
    s += sum( [ d(p[i],p[i+1]) for i in range(N-1) ] )
    n+=1
print(s/n)

Submission status: Accepted

Solution code:
import itertools
import numpy as np
import math

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

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

    distance = [[None]*N for _ in range(N)]

    for i in range(N):
        x1, y1 = coordinate[i]
        for j in range(N):
            x2, y2 = coordinate[j]
            distance[i][j] = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)

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

    sum = 0
    for c in itertools.permutations(C):
        c_1 = c[0]
        for j in range(1, len(c)):
            c_2 = c[j]
            sum += distance[c_1][c_2]
            c_1 = c_2
    print(sum/math.factorial(N))

    return 0
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import sqrt, pow

def get_distance(xi, yi, xj, yj):
  return sqrt(pow(xi - xj, 2) + pow(yi - yj, 2))

def solve():
  n = int(input())
  locations = [list(map(int, input().split())) for _ in range(n)]
  
  distance = 0
  
  for xi, yi in locations:
    for xj, yj in locations:
      distance += get_distance(xi, yi, xj, yj)
  
  return distance / n

print(solve())

Submission status: Accepted

Solution code:
from math import sqrt, pow

def get_distance(xi, yi, xj, yj):
  return sqrt(pow(xi - xj, 2) + pow(yi - yj, 2))

def solve():
  n = int(input())
  locations = [list(map(int, input().split())) for _ in range(n)]
  
  distance = 0
  
  for i, [xi, yi] in enumerate(locations):
    if i+1 == len(locations):
      remain = locations[:i]
    else:
      remain = locations[:i] + locations[i+1:]
    
    for xj, yj in remain:
      distance += get_distance(xi, yi, xj, yj)
  
  return distance / n

print(solve())

Submission status: Accepted

Solution code:
import itertools

import numpy as np


N  = int(input())
XY = []

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

XY = np.array(XY)
D  = []

for iter in itertools.permutations(list(range(N))):
    XY_tmp = XY[np.array(iter)]
    D.append((((XY_tmp[:-1] - XY_tmp[1:]) ** 2).sum(axis=1) ** 0.5).sum())

print(sum(D)/len(D))

Submission status: Accepted

Solution code:
import itertools
import math
n = int(input())
xys = []
for i in range(n):
  xy = input().split()
  xys.append(xy)
total = 0
xys_list = list(itertools.permutations(xys, len(xys)))
for j in range(len(xys_list)):
  r = 0
  for k in range(n-1):
    xk = int(xys_list[j][k][0])
    yk = int(xys_list[j][k][1])
    xk2 = int(xys_list[j][k+1][0])
    yk2 = int(xys_list[j][k+1][1])
    r = math.sqrt(((xk - xk2)**2) + ((yk - yk2)**2))
    total += r
fac = math.factorial(n)
print(total / fac)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
P = []
L_total = []
for i in range(N):
    p = list(map(int, input().split()))
    P.append(p)
for v in itertools.permutations(P, N):
    L = []
    for i in range(N - 1):
        l = ((v[i][0] - v[i + 1][0]) ** 2 + (v[i][1] - v[i + 1][1]) ** 2) ** 0.5
        L.append(l)
    L_total.append(sum(L))
ans = sum(L_total) / (len(L_total))
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
import math
import itertools
x=[]
y=[]
total=0
factorial=math.factorial(n)
for i in range(n):
    X,Y=map(int,input().split())
    x.append(X)
    y.append(Y)
index_lis=[i for i in range(n)]#N!通り並べるために使う配列
P=itertools.permutations(index_lis,n)#N!通り並べる
for p in P:
    for i in range(n-1):
        tmp=math.sqrt((x[p[i+1]]-x[p[i]])**2+(y[p[i+1]]-y[p[i]])**2)
        total+=tmp
print(total/factorial)

Submission status: Accepted

Solution code:
import math

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

sum = 0

for i in range(N):
    for j in range(N):
      dx = abs(x[i]-x[j])
      dy = abs(y[i]-y[j])
      sum = sum + math.sqrt((dx*dx) + (dy*dy))

    
ave = sum/math.factorial(N)*math.factorial(N-1)

print(ave)

Submission status: Accepted

Solution code:
import itertools
import numpy as np

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



ans = []

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

for v in itertools.permutations(xy, n):

    tmp = 0
    for i in range(n-1):
        tmp += distance(v[i], v[i+1])

    ans.append(tmp)


print(np.average(ans))

Submission status: Accepted

Solution code:
import itertools
from math import sqrt

N = int(input())
zahyo = []
kyori_ichiran = []
for i in range(N):
    x,y = map(int,input().split())
    zahyo.append((x,y))
junban_ichiran = list(itertools.permutations(range(N),N))
for i in range(len(junban_ichiran)):
    junban = junban_ichiran[i]
    kyori = 0
    for j in range(len(junban)-1):
        kyori += sqrt((zahyo[junban[j]][0]-zahyo[junban[j+1]][0])**2 + (zahyo[junban[j]][1]-zahyo[junban[j+1]][1])**2)
    kyori_ichiran.append(kyori)
print(sum(kyori_ichiran)/len(kyori_ichiran))

Submission status: Accepted

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

s = 0
for i in range(n):
    for j in range(n):
        s += ((X[i]-X[j])**2 + (Y[i]-Y[j])**2)**.5

print(s/n)

Submission status: Accepted

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

Submission status: Accepted

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

import itertools
import math
average_dist = 0
patterns = math.factorial(N)

for path in itertools.permutations(range(N)):
    dist = 0
    for i in range(N-1):
        st = cities[path[i]]
        en = cities[path[i+1]]
        dist += math.sqrt((en[1]-st[1])**2 + (en[0]-st[0])**2)
    average_dist += dist/patterns

print(average_dist)

Submission status: Accepted

Solution code:
import math
import itertools
N = int(input())
pos = []
for _ in range(N):
    tmp = tuple(map(int, input().split()))
    pos.append(tmp)

ave = 0
cnt = 0
for x in itertools.permutations(pos):
    for i in range(N-1):
        ave += math.sqrt((x[i][0] - x[i+1][0]) ** 2 + (x[i][1] - x[i+1][1]) ** 2)
    cnt += 1
print(ave / cnt)

Submission status: Accepted

Solution code:
from sys import stdin as s
from math import sqrt as sq
lx=[]
ly=[]
c=0
n=int(s.readline())
for i in range(n):
  x,y=map(int,s.readline().split())
  lx.append(x)
  ly.append(y)
for i in range(n):
  for j in range(i+1,n):
    c+=sq((lx[i]-lx[j])**2+(ly[i]-ly[j])**2)
print(c*2/n)

Submission status: Accepted

Solution code:
import math

N = int(input())

town = []

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

ret = 0

for i in range(N):
    for j in range(i + 1, N):
        dx = town[i][0] - town[j][0]
        dy = town[i][1] - town[j][1]

        ret += 2 / N * math.sqrt(dx ** 2 + dy ** 2)

print(ret)

Submission status: Accepted

Solution code:
import math
import itertools

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

res = 0
cnt = 0
for v in itertools.permutations(x):
  for i in range(n-1):
    res += math.sqrt((v[i+1][0] - v[i][0]) ** 2 + (v[i+1][1] - v[i][1]) ** 2)
  cnt += 1

print((res+0.0)/cnt)

Submission status: Accepted

Solution code:
import math

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

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

dist_sum = 0

for i in range(n):
  for j in range(i+1,n):
    dist_sum += get_distance(d[i][0],d[i][1],d[j][0],d[j][1])

print(dist_sum * 2 / n)

Submission status: Accepted

Solution code:
from itertools import permutations
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
na=list(permutations(a,n))
ans=0
for i in range(len(na)):
  for j in range(n-1):
    ans+=((na[i][j][0]-na[i][j+1][0])**2+(na[i][j][1]-na[i][j+1][1])**2)**.5
print(ans/len(na))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import math
import itertools

N = int(input())

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

pattern = list(itertools.combinations(X, 2))
pattern2 = list(itertools.permutations(X))
dist_list = []

for i in pattern:
  a = np.array(i[0])
  b = np.array(i[1])
  dist_list.append(np.linalg.norm(a-b))
  
#係数求める
kaijou = math.factorial(N)
nC2 = len(pattern2)

k = (kaijou * (N-1)) / nC2

print(sum(dist_list)*k / len(pattern))

Submission status: Accepted

Solution code:
N = int(input())

l = list(" " * 8)

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

import numpy as np
import math

l = np.array(l)

mat = np.zeros([N,N])

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

print(np.sum(mat + mat.T) / N)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
v = []
ans = 0.0
for _ in range(n):
    x,y = map(int,input().split())
    v.append([x,y])
for x1,y1 in v:
    for x2,y2 in v:
        ans += ((x1-x2)**2 + (y1-y2)**2 ) ** 0.5
print(ans/n)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import combinations
 
z = []
N = int(input())
for i in range(N):
    temp_x, temp_y = map(int, input().split())
    z = z + [temp_x] + [temp_y]
z = np.array(z).reshape(N,2)
 
d = 0
count = 0
for j, k in combinations(range(N),2):
    temp_d = np.sqrt((z[j,0] - z[k,0])**2 + (z[j,1] - z[k,1])**2)
    d += temp_d
    count += 1
print(d*(N-1)/count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

X = []; Y = []
for i in range(N):
    x, y = [int(i) for i in input().split()]
    X.append(x); Y.append(y);

s = 0
for i in range(N):
    for j in range(N):
        s += ((X[i]-X[j])**2 + (Y[i]-Y[j])**2)**.5

print(s/N)

Submission status: Accepted

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

for i, j in enumerate(permutations(range(n))):
    for num in range(n-1):
        k[i] += sqrt((li[int(j[num+1])][0] - li[int(j[num])][0])**2 + (li[int(j[num+1])][1] - li[int(j[num])][1])**2)

print(sum(k)/len(k))

Submission status: Accepted

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

import math

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

a = 2 * math.factorial(n - 1) / math.factorial(n)

print(l * a)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

import itertools
import math
for path in itertools.permutations(list(range(N))):
  for i in range(N-1):
    x1 = coord[path[i]][0]
    y1 = coord[path[i]][1]
    x2 = coord[path[i+1]][0]
    y2 = coord[path[i+1]][1]
    ans += ((x1-x2)**2 + (y1-y2)**2)**0.5
    
print(ans/math.factorial(N))

Submission status: Accepted

Solution code:
import math

n=int(input())
e = [[int(i) for i in input().split()] for i in range(n)] 
c=0

for i in range(n):
    for j in range(n):
        if i!=j:
            c+=math.sqrt((e[i][0]-e[j][0])**2+(e[i][1]-e[j][1])**2)
print(c/n)

Submission status: Accepted

Solution code:
import math
def rec(li, p_coor, s):
  total_len = 0
  if len(li)==0:
    return s
  for i in range(len(li)):
    c_li = li[:]
    c_coor = c_li.pop(i)
    d = dist(c_coor, p_coor) if p_coor is not None else 0
    total_len += rec(c_li, c_coor, s+d)
  return total_len
  
def dist(c1, c2):
  x1, y1 = c1
  x2, y2 = c2
  return math.sqrt((x1-x2)**2+(y1-y2)**2)

n = int(input())
coor = []
for _ in range(n):
  coor.append(tuple(map(int, input().split())))
print(rec(coor,None,0)/math.factorial(n))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import math

N = int(input())
x = []
y = []

for i in range(N) : 
    x_temp, y_temp = map(int, input().split())
    x.append(x_temp)
    y.append(y_temp)
    
numerator = 0
cnt = 0
    
for i in range(N) : 
    for j in range(N) : 
        if i != j : 
            numerator += math.sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)
            cnt += 1
            
print(numerator/N)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
t = []
l = []
for i in range(n):
    t.append(readl())
    l.append(i)
s = 0
for i in list(itertools.permutations(l,2)):
    s += math.sqrt(((t[i[0]][0] - t[i[1]][0]) ** 2) + ((t[i[0]][1] - t[i[1]][1]) ** 2))

print(s / n)

Submission status: Accepted

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

Submission status: Accepted

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

def solve():
    input = sys.stdin.readline
    N = int(input())
    coordinate = dict()
    for i in range(N):
        coordinate[i] = tuple(map(int, input().split()))

    total_length = 0
    perm_count = 0
    for p in permutations(range(N)):
        perm_count += 1
        current_id = coordinate[int(p[0])]
        for j in range(1, N):
            next_id = coordinate[int(p[j])]
            total_length += sqrt((current_id[0] - next_id[0]) ** 2 + (current_id[1] - next_id[1]) ** 2)
            current_id = next_id

    print(total_length / perm_count)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

import itertools
import math
comb = list(itertools.permutations(xy_list))
ans = 0
for s in comb:
    ans_tmp = 0
    #print(ans)
    for zyun in range(len(s)-1):
        ans_tmp += math.sqrt((s[zyun][0] - s[zyun+1][0])**2 + (s[zyun][1] - s[zyun+1][1])**2)
    ans += ans_tmp
print(round(ans/len(comb), 12))

Submission status: Accepted

Solution code:
from math import sqrt
n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
l=[]
m=1
for i in range(n):
    m*=i+1
    for j in range(i+1,n):
        r=sqrt((p[i][0]-p[j][0])**2+(p[i][1]-p[j][1])**2)
        l.append(r)

a=(n-1)*m//len(l)
print((sum(l)*(a))/m)

Submission status: Accepted

Solution code:
n=int(input())
a=[[int(i)for i in input().split()]for i in range(n)]
import itertools as it
li=list(it.permutations(range(n)))
total=0
for i in li:
    tmp=0
    for j in range(n-1):
        x1,x2=a[i[j]][0],a[i[j+1]][0]
        y1,y2=a[i[j]][1],a[i[j+1]][1]
        tmp=(x1-x2)**2+(y1-y2)**2
        total+=tmp**0.5
print(total/len(li))

Submission status: Accepted

Solution code:
from math import sqrt

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

distance=0
for i in range(N):
    for j in range(i+1,N):
        distance+=sqrt( pow( (XY[i][0])-(XY[j][0]) ,2 ) + pow(XY[i][1] - XY[j][1],2) )

tmp=0        
for i in range(1,N):
    tmp+=i
    

print(distance*(N-1)/tmp)

Submission status: Accepted

Solution code:
from math import sqrt

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

distance=0
for i in range(N):
    for j in range(i+1,N):
        distance+=sqrt( pow( (XY[i][0])-(XY[j][0]) ,2 ) + pow(XY[i][1] - XY[j][1],2) )

print(2*distance/N)

Submission status: Accepted

Solution code:
from math import sqrt


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


def main():
    x = []
    y = []
    N = int(input())
    distance = 0
    for i in range(N):
        list = input().split(" ")
        x.append(int(list[0]))
        y.append(int(list[1]))
    for j in range(N):
        for k in range(j + 1, N):
            distance += get_distance(x[j], y[j], x[k], y[k])
    print(distance * 2 / N)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import math

n1 = int(input())

n3 = []
for i2 in range(n1):
    n3.append([int(i) for i in input().split()])

r4 = 0

for i5 in range(n1):
    for i6 in range(n1):
        if i5 != i6:
            r4 += math.sqrt(pow((n3[i5][0] - n3[i6][0]), 2) + pow((n3[i5][1] - n3[i6][1]), 2))

print(r4 / n1)

Submission status: Accepted

Solution code:
import math
import itertools

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

distance = 0
total = 0
routes = itertools.permutations(range(N), N)

for v in routes:
    for i in range(0, N - 1):
        distance += math.sqrt((P[v[i]][0] - P[v[i + 1]][0]) ** 2 + (P[v[i]][1] - P[v[i + 1]][1]) ** 2)

    total += distance
    distance = 0

print(total / math.factorial(N))

Submission status: Accepted

Solution code:

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

result = 0
for i in range(n):
 for j in range(n):
  if i != j:
   result += 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(result/n)

Submission status: Accepted

Solution code:
import math
import functools
import itertools


N = int(input())
positions = list()
for _ in range(N):
    positions.append([int(i) for i in input().split(" ")])

d = dict()
for a, b in itertools.product(range(N), range(N)):
    a_x, a_y = positions[a]
    b_x, b_y = positions[b]
    distance = math.sqrt((a_x - b_x) ** 2 + (a_y - b_y) ** 2)
    d[(a, b)] = distance

total = 0
multiplier = functools.reduce(lambda x, y: x*y, range(1, N))
for key in d:
    total += d[key] * multiplier

print(total / functools.reduce(lambda x, y: x*y, range(1, N+1)))

Submission status: Accepted

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

from itertools import permutations
from math import sqrt
def main():
    TMP = permutations(XY)
    sm = 0
    cnt = 0
    for tmp in TMP:
        cnt += 1
        prex,prey = tmp[0]
        for x,y in tmp[1:]:
            sm += sqrt((prex -x)**2 + (prey -y)**2)
    print(sm / cnt)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools


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

    return N, town


def solve(N, town):
    ans = 0
    import math
    townLens = 0.0
    for xys in itertools.permutations(town):
        townLen = 0.0
        for i in range(len(xys) - 1):
            townLen += math.sqrt((xys[i][0] - xys[i + 1][0]) ** 2 + (xys[i][1] - xys[i + 1][1]) ** 2)
        townLens += townLen

    ans = townLens / math.factorial(N)
    return ans


if __name__ == '__main__':
    N, town = read()
    # print("%d" % solve(N, renga))
    print(solve(N, town))

Submission status: Accepted

Solution code:
import sys
bbn=1000000007
	
#+++++
		
def main():
	n = int(input())
	al=[]
	for i in range(n):
		b , c = map(int, input().split())
		al.append([b,c])
	tps=0
	for xi,yi in al:
		for xj,yj in al:
			bb=((xi-xj)**2) + ((yi-yj)**2)
			tps+=(bb**0.5)
	print(tps/n)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
import itertools
import math

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

ans = 0
sum = 0
for v in itertools.permutations(range(n), n):
    past = [0, 0]
    for i, t in enumerate(v):
        if i == 0:
            past = p[t]
            continue
        x, y = p[t]
        x_p, y_p = past
        distance = math.sqrt((x - x_p)**2 + (y - y_p)**2)
        sum += distance
        past = [x, y]

pattrun = math.factorial(n)
print(sum/pattrun)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import math
import itertools

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

for i in range(N):
    for j in range(i):
        L[i][j]=math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
        L[j][i]=L[i][j]

per = list(itertools.permutations(range(1,N+1),N))

ans=0
for path in per:
    for i in range(N-1):
        ans+=L[path[i]-1][path[i+1]-1]
print(ans/len(per))

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 distance(i, j):
    res = (XY[i][0] - XY[j][0]) ** 2 + (XY[i][1] - XY[j][1]) ** 2
    return math.sqrt(res)


m = []

for n in range(N):
    m.append([-1] * N)


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


ans = 0

for j in range(N):
    for i in range(N):
        ans += m[j][i]

print(ans / N)

Submission status: Accepted

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

ans = 0
for i in range(N):
    ix, iy = P[i]
    for j in range(i, N):
        jx, jy = P[j]
        ans += ((ix - jx) ** 2 + (iy - jy) ** 2) ** 0.5

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

Submission status: Accepted

Solution code:
import math
import itertools

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

numbers=[c for c in range(N)]
kyori=0
for i in itertools.permutations(numbers,N):
   for j in range(N-1):
      mae=i[j]
      usiro=i[j+1]
      kyori+=(((X[usiro]-X[mae])**2)+((Y[usiro]-Y[mae])**2))**0.5

N_f=math.factorial(N)
print(kyori/N_f)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = 0
ans_1 = 0
n = inp()
initial_list = ['None']*n
for i in range(n):
    temp = np.array(inpl())
    initial_list[i] = temp

my_abs = lambda x:  math.sqrt((x[0]**2+x[1]**2))
for i in range(n):
    ans_1 += sum([my_abs(x-initial_list[i]) for x in initial_list[i:]])

ans = ans_1*2/float(n)
print(ans)