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())
pnts = []
for i in range(n):
    x,y = map(int,input().split())
    pnts.append((x,y))
s = 0
for i in range(n):
    for j in range(n):
        if j != i:
            s += ((pnts[j][0]-pnts[i][0])**2 + (pnts[j][1]-pnts[i][1])**2)**0.5
print(s/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import itertools as it

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

a = list(it.permutations(list(range(n))))
b = list(it.combinations(list(range(n)), 2))
c = []
for bb in b:
    xx,yy = o[list(bb)]
    zz = xx - yy
    delta = np.sqrt(zz[0]**2 + zz[1]**2)
    c.append(delta)

ans = sum(c)*(n-1)/len(c)
print(ans)

Submission status: Accepted

Solution code:
import math
import itertools
N = int(input())
Sum = 0
N_2 = math.factorial(N)
lis = []
for i in range(N):
  a,b = map(int,input().split())
  lis.append([a,b])
P = list(itertools.permutations(range(N)))
for j in range(N_2):
  for g in range(N-1):
    Sum += math.sqrt(((lis[P[j][g]][0]-lis[P[j][g+1]][0])**2) + ((lis[P[j][g]][1]-lis[P[j][g+1]][1])**2))
print(Sum/N_2)

Submission status: Accepted

Solution code:
n = int(raw_input())
l = [map(int,raw_input().split()) for i in range(n)]
print sum(((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)**(.5) for i in range(n) for j in range(n) if i !=j)/n

Submission status: Accepted

Solution code:
N = int(input())
list_x = []
list_y = []
list_distance = []

for _ in range(N):
    (x, y) = map(int, input().split())
    list_x.append(x)
    list_y.append(y)
    
for i in range(N-1):
    for j in range(i+1,N):
        xi = list_x[i]
        yi = list_y[i]    
        xj = list_x[j]
        yj = list_y[j]
        
        distance = ((xj-xi)**2 + (yj-yi)**2)**(1/2)
        list_distance.append(distance)

Total = sum(list_distance)

Ans = (2*Total)/N
print(Ans)

Submission status: Accepted

Solution code:
def d(a,b):
    return ((a[0]-b[0])**2+(a[1]-b[1])**2)**(.5)
n = int(raw_input())
l = [map(int,raw_input().split()) for i in range(n)]
s = 0
for i in range(n):
    for j in range(n):
        if i !=j:
            s += d(l[i],l[j])
print s/n

Submission status: Accepted

Solution code:
import numpy as np
import itertools
import math

def l2_norm(node1,node2):
    x1 = node1[0]
    y1 = node1[1]
    x2 = node2[0]
    y2 = node2[1]
    return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

def pmt(n):
    result = 1
    for i in range(1,n + 1):
        result = result * i
    return result
node_num = int(input())

node_list = []
dist_list = []

# for i in itertools.permutations([i for i in range(3)]):
for i in range(node_num):
    a, b =  map(float,input().split())
    node_list.append((a,b))
for i in itertools.combinations([i for i in range(node_num)],2):
    node1 = node_list[i[0]]
    node2 = node_list[i[1]]
    dist_list.append(l2_norm(node1, node2))

tmp_list = []
for i in itertools.permutations([i for i in range(node_num)]):
    tmp_list.append("".join(map(str, i)))

count = 0
for i in tmp_list:
    if i.find("01") >= 0:
        count = count + 1
    if i.find("10") >= 0:
        count = count + 1

dist = np.asarray(dist_list)
dist = dist * count
dist = dist.sum()
dist = dist / pmt(node_num)
print(dist)

Submission status: Accepted

Solution code:
import math

N = int(input())
xy_list = []
for i in range(N):
    xy_list.append([int(i) for i in input().split()])
result = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        city1 = math.pow(xy_list[i][0] - xy_list[j][0], 2)
        city2 = math.pow(xy_list[i][1] - xy_list[j][1], 2)
        result += math.sqrt(city1 + city2)
print("{:.10f}".format(result / N))

Submission status: Accepted

Solution code:
import math
dis_sum =0
ans =0
root_num =0

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

#距離を計算する
for i in range(n-1):
    for j in range(i+1,n):
   
        x_dis = (distance_list[i][0] - distance_list[j][0]) **2
        y_dis = (distance_list[i][1] - distance_list[j][1]) **2
        city_dis = math.sqrt(x_dis + y_dis)
        dis_sum += city_dis


ans = 2/n * dis_sum
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
XY = list(map(int, read().split()))
X = XY[0::2]
Y = XY[1::2]

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
XY = list(map(int, read().split()))
X = XY[0::2]
Y = XY[1::2]

t = 0
for i in range(N):
    for j in range(i, N):
        t += ((X[i] - X[j])**2 + (Y[i] - Y[j])**2)**0.5
print(2*t/N)

Submission status: Accepted

Solution code:
from itertools import permutations as perm
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
XY = list(map(int, read().split()))
X = XY[0::2]
Y = XY[1::2]

res = 0
cnt = 0
for p in perm(range(N)):
    for i in range(N - 1):
        res += ((X[p[i + 1]] - X[p[i]])**2 + (Y[p[i + 1]] - Y[p[i]])**2)**0.5
    cnt += 1    
print(res/cnt)

Submission status: Accepted

Solution code:
from itertools import permutations as perm
import sys
import math
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
XY = np.array(read().split(), np.int64)
X = XY[0::2]
Y = XY[1::2]

res = 0
cnt = 0
for p in perm(range(N)):
    for i in range(N - 1):
        res += math.sqrt((X[p[i + 1]] - X[p[i]])**2 + (Y[p[i + 1]] - Y[p[i]])**2)
    cnt += 1    
print(res/cnt)

Submission status: Accepted

Solution code:
import itertools,math

def distance(x1,y1,x2,y2):
    d=((x1-x2)**2+(y1-y2)**2)**0.5
    return d

N=int(input().strip())
x=[0]*N
y=[0]*N

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

lst=list(range(N))
dist=0
for v in itertools.permutations(lst):
    for i in range(N-1):
        dist+=distance(x[v[i]],y[v[i]],x[v[i+1]],y[v[i+1]])
print(dist/math.factorial(N))

Submission status: Accepted

Solution code:
import math
import itertools

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

m = []
l = 1
for i in range(N):
  m.append(int(i))

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

for j in itertools.permutations(m):
  for i in range(N-1):
     cnt = cnt + math.sqrt(((n[j[i]][0]-n[j[i+1]][0])**2)+((n[j[i]][1]-n[j[i+1]][1])**2))

print(cnt/l)

Submission status: Accepted

Solution code:
import itertools
import math
n = int(input())
cities = []
distance = 0
for i in range(n):
    cities.append([int(x) for x in input().split()])

all  = list(itertools.permutations(cities))

for j in range(len(all)):
    for k in range(len(all[j])-1):
        distance += math.hypot(all[j][k][0] - all[j][k+1][0], all[j][k][1] - all[j][k+1][1]) 
average = distance/len(all)
print(average)

Submission status: Accepted

Solution code:
from itertools import permutations

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

p_li = list(permutations(li))

dist = 0

for p in p_li:
  for j in range(n-1):
    dist += ((p[j][0] - p[j+1][0]) ** 2 + (p[j][1] - p[j+1][1]) ** 2) ** 0.5
  
result = dist/(len(p_li))
print(result)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
arr = [list(map(int, input().split())) for i in range(n)]
ans = 0
perms = list(itertools.permutations(arr))

for perm in perms:
    for i in range(n - 1):
        x1, y1 = perm[i]
        x2, y2 = perm[i + 1]
        ans += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
print(ans / len(perms))

Submission status: Accepted

Solution code:
n = int(input())
 
li = []
dis = 0
 
for i in range(n):
  x, y = map(int,input().split())
  li.append((x, y))
  
for j in range(n):
  for k in range(n):
    dis += ((li[j][0]-li[k][0]) ** 2 + (li[j][1]-li[k][1]) ** 2) ** 0.5
 
print(dis/n)

Submission status: Accepted

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

for i in range(n):
    for j in range(n):
        sum_dict+=((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)**0.5
print(sum_dict/n)

Submission status: Accepted

Solution code:
n = int(input())

li = []
dire = 0

for i in range(n):
  x, y = map(int,input().split())
  li.append((x, y))
  
for j in range(n):
  for k in range(n):
    dire += ((li[j][0]-li[k][0]) ** 2 + (li[j][1]-li[k][1]) ** 2) ** 0.5

print(dire/n)

Submission status: Accepted

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

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

for l in n_list:

    for j in range(n-1):
        distance[j] = distance[j] + math.sqrt((x[l[j]]-x[l[j+1]])**2 + (y[l[j]]-y[l[j+1]])**2)

    j += 1
print(sum(distance)/math.factorial(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())
d=0
for i,j in zip(x,y):
  for k,l in zip(x,y):
    m1,m2=i-k,j-l
    o=m1**2+m2**2
    d+=o**0.5
print(d/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

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

n = range(N)
ptns = list(itertools.permutations(n,N))

ans = 0

for route in ptns:
    for idx, val in enumerate(route):
        if idx == len(route) - 1:
            break
        dep = route[idx]
        arr = route[idx + 1]
        dist = distance(x[dep][0], x[arr][0], x[dep][1], x[arr][1])
        ans += dist

print(ans / len(ptns))

Submission status: Accepted

Solution code:
import numpy as np
import scipy
from scipy.spatial import distance_matrix

N = int(input())

cords = []
for _ in range(N):
  sp = input().split()
  x, y = float(sp[0]), float(sp[1])
  cords.append([x, y])

cords = np.array(cords)
d = distance_matrix(cords, cords)
np.fill_diagonal(d, 0)
print(d.sum()/cords.size*2)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
from itertools import permutations
import math

n = int(input())
P = []
for _ in range(n):
    P.append(tuple(map(int, input().split())))
distance = 0
for array in permutations(P):
    for i in range(n - 1):
        p1 = array[i]
        p2 = array[i + 1]
        diff_x = p1[0] - p2[0]
        diff_y = p1[1] - p2[1]
        distance += math.sqrt(diff_x ** 2 + diff_y ** 2)
print(distance / math.factorial(n))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math
INF = float("inf")


def cmb(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    if r == 1:
        return n

    numer = [n - r + k + 1 for k in range(r)]
    denom = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denom[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numer[k - offset] /= pivot
                denom[k] /= pivot

    result = 1
    for k in range(r):
        if numer[k] > 1:
            result *= int(numer[k])

    return result


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


def solve(N: int, x: "List[int]", y: "List[int]"):
    tot = 0
    for i in range(N):
        for j in range(i+1, N):
            tot += math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
    tot *= 2/N
    print(tot)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math, itertools
N = int(input())
Ax = []
Ay = []
for _ in range(N):
    x, y = map(int, input().split())
    Ax.append(x)
    Ay.append(y)

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

    
Ncomb = N * (N - 1) // 2

Npair = Nperm * (N - 1) // Ncomb

ans = 0
for c in itertools.combinations(range(N), 2):
    p1, p2 = c
    ans += math.sqrt((Ax[p1] - Ax[p2])**2 + (Ay[p1] - Ay[p2])**2) * Npair

print(ans / Nperm)

Submission status: Accepted

Solution code:
import math
import itertools

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

sum = 0
for towns in list(itertools.permutations(towns)):
    for i in range(n - 1):
        sum += math.sqrt((towns[i][0] - towns[i + 1][0]) ** 2 + (towns[i][1] - towns[i + 1][1]) ** 2)

print(sum / math.factorial(n))

Submission status: Accepted

Solution code:
import math
n = int(input())
m = []
ds = []

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

for i in range(n):
  for j in range(i+1, n):
    ds.append(math.sqrt((m[i][0]-m[j][0])**2+(m[i][1]-m[j][1])**2))
ps = math.factorial(n)

print(sum(ds)*(n-1)/len(ds))

Submission status: Accepted

Solution code:
import math
n=int(input())
m=[]
ds=[]

for i in range(n):
    m.append(list(map(int,input().split())))
for i in range(n):
    for j in range(i+1,n):
        ds.append(math.sqrt((m[i][0]-m[j][0])**2+(m[i][1]-m[j][1])**2))
ps=math.factorial(n)
x=(n-1)*math.factorial(n)/len(ds)
print(sum(ds)*(n-1)/len(ds))

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
XY = np.empty([N,2])
for i in range(N):
    XY[i] = list(map(int, input().split()))

ans = 0.0
for i in range(N):
    for j in range(i+1,N):
        ans += np.sqrt(np.sum(np.square(XY[i]-XY[j])))
ans = ans*2/N

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
XY = np.empty([N,2])
for i in range(N):
    XY[i] = list(map(int, input().split()))

ans = 0.0
for i,a in enumerate(XY):
    for b in XY[i+1:]:
        ans += np.sqrt(np.sum(np.square(a-b)))
ans = ans*2/N

print(ans)

Submission status: Accepted

Solution code:
import itertools

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

ans = 0
paths = list(itertools.permutations(range(N)))
for p in paths:
    for i in range(N-1):
        s = p[i]
        d = p[i+1]
        ans += ((x[s] - x[d]) ** 2 + (y[s] - y[d]) ** 2) ** 0.5
ans /= len(paths)
print(ans)

Submission status: Accepted

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

def get_dist(i,j):
  return ((i[0] - j[0])**2 + (i[1] - j[1])**2) ** 0.5

leng = [get_dist(i,j) for i,j in itertools.product(l,l)]
print(sum(leng)/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n=int(input())
A=[]
sum=0
for i in range(n):
  a,s=(int(x) for x in input().split()) 
  A.append((a,s))
for i in A:
  for i2 in A:
    sum+=math.sqrt((i[0]-i2[0])**2+(i[1]-i2[1])**2)
print(sum/n)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
from math import sqrt
n = int(input())
a = []
for i in range(n):
  x,y=map(int,input().split())
  t = (x,y)
  a.append(t)
d,f=0,0
for i in range(n-1):
  for j in range(i+1,n):
    r = sqrt((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)
    d+=(n-1)*r
  f+=(i+1)
print(d/f)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial


class Point:
    def __init__(self, y, x):
        self.y = y
        self.x = x


def main():
    N = int(input())
    xy = []
    for i in range(N):
        xi, yi = map(int, input().split())
        xy.append(Point(yi, xi))
    ans = 0
    for i in permutations(xy):
        for j in range(N - 1):
            ans += ((i[j + 1].y - i[j].y) ** 2 +
                    (i[j + 1].x - i[j].x) ** 2) ** 0.5
    print('{:.10f}'.format(ans / factorial(N)))
    return


main()

Submission status: Accepted

Solution code:
n,*z=[list(map(int,t.split()))for t in open(0)];
print(sum(((a-x)**2+(b-y)**2)**.5for a,b in z for x,y in z)/n[0])

Submission status: Accepted

Solution code:
#ステップについて
#順列の全列挙(N!通り)をする
#平均移動距離を求める

import math

#入力受付
n=int(input())
xy=[]
for _ in range(n):
    #map(関数, イテラブル) ＜＝高階関数
	x,y=map(int,input().split())
	xy.append([x,y])

# print(xy)

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

Submission status: Accepted

Solution code:
from math import *

def kaijou(n):
    ka = 1
    for e in range(1,n+1):
        ka *= e
    return ka

N = int(input())


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

all_distances = []

for i in range(N-1):
    for j in range(i+1,N):
        all_distances.append(sqrt(pow(coordinates[i][0]-coordinates[j][0],2) + pow(coordinates[i][1]-coordinates[j][1],2)))


sum_distances = sum(all_distances)

ans = (sum_distances ) * 2   /   N

print(ans)

Submission status: Accepted

Solution code:
import itertools,math
N=int(input())
nl=[i for i in range(N)]
x=[]
y=[]
d=0
for _ in range(N):
	X,Y=[int(i) for i in input().split()]
	x.append(X)
	y.append(Y)
per_nl=list(itertools.permutations(nl))
for k in per_nl:
	for i in range(N-1):
		d+=((x[k[i+1]]-x[k[i]])**2+(y[k[i+1]]-y[k[i]])**2)**(0.5)
print(d/math.factorial(N))

Submission status: Accepted

Solution code:
N = int(input())

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

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

print(s*2/N)

Submission status: Accepted

Solution code:
n = int(input())
l = [[int(i) for i in input().split()] for _ in range(n)]
import math
distance = 0
for i in l:
    for j in l:
        distance += ((i[0] - j[0])**2 + (i[1] - j[1])**2)**0.5*math.factorial(n-1)
        
print(distance/math.factorial(n))

Submission status: Accepted

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

distance = 0
for i in l:
    for j in l:
        distance += ((i[0] - j[0])**2 + (i[1] - j[1])**2)**0.5
        
print(distance/n)

Submission status: Accepted

Solution code:
N = int(input())
M = [0]*N
edge = [0]*N
for i in range(N):
  edge[i]=[0]*N
sum=0
for i in range(N):
    M[i] = list(map(int,input().split()))
for i in range(N):
    for k in range(i+1,N):
        edge[i][k] = pow(((M[i][0]-M[k][0])**2 + (M[i][1]-M[k][1])**2),0.5)
        sum+=edge[i][k]
average = sum/N*2
print(average)

Submission status: Accepted

Solution code:
import math

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

def calc_distance(a, b):
    return math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)
num = 0
d = 0
for i in range(N):
    for j in range(i+1, N):
        num += 1
        d += calc_distance(coordinates[i], coordinates[j])

print(d / N * 2)

Submission status: Accepted

Solution code:
import numpy as np
from math import sqrt,factorial
N = int(input())
M = [0]*N
edge = np.zeros([N,N])
sum=0
for i in range(N):
    M[i] = list(map(int,input().split()))
for i in range(N):
    for k in range(i+1,N):
        edge[i,k] = sqrt((M[i][0]-M[k][0])**2 + (M[i][1]-M[k][1])**2)
        sum+=edge[i,k]
average = sum/N*2
print(average)

Submission status: Accepted

Solution code:
import math

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

dist = 0
for i, xyi in enumerate(xy):
    for xyj in xy[i+1:]:
        dist += math.sqrt((xyi[0] - xyj[0])**2 + (xyi[1] - xyj[1])**2)
print(dist*2/n)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
points = []

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

def calcDistance(point1,point2):
  dis = ((point1[0]-point2[0])**2 + (point1[1]-point2[1])**2)**(1/2)
  return dis
  
ans = 0
Nlist= list(itertools.permutations(range(N)))
for i in range(len(Nlist)):
  for j in range(N):
    if j != N-1:
      ans += calcDistance(points[Nlist[i][j]],points[Nlist[i][j+1]])
        
print(ans / len(Nlist))

Submission status: Accepted

Solution code:
import itertools

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

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

p = itertools.permutations(range(n), 2)
print(sum(dist(cities[x[0]], cities[x[1]]) for x in p) / n)

Submission status: Accepted

Solution code:
import itertools
import math

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

l = [i for i in range(n)]
p = list(itertools.permutations(l))
dist = 0
for pp in p:
    preppi = pp[0]
    for ppi in pp[1:]:
        dist += math.sqrt((xy[ppi][0] - xy[preppi][0])**2 + (xy[ppi][1] - xy[preppi][1])**2)
        preppi = ppi
print(dist/len(p))

Submission status: Accepted

Solution code:
from itertools import permutations

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

def dist(A, B):
    x0, y0 = A
    x1, y1 = B
    res = pow((x0-x1)**2 + (y0-y1)**2, 1/2)
    return res

def sum_dist(arr):
    res = 0
    for A, B in zip(arr[:], arr[1:]):
        res += dist(A, B)
    return res

ans = 0
cnt = 0
for p in permutations(pos):
    ans += sum_dist(p)
    cnt += 1

ans /= cnt
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import numpy as np
import itertools
def kyori(x1,y1,x2,y2):
    dis = ((x1-x2)**2+(y1-y2)**2)**0.5
    return dis
N = int(input())
xy = []
for n in range(N):
    xy.append(list(map(int, input().split())))
diss = np.zeros((N,N))
c = list(itertools.permutations(range(N), N))
s = 0
for n in range(len(c)):
    for d in range(N-1):
        if diss[c[n][d]][c[n][d+1]]==0:
            diss[c[n][d]][c[n][d+1]] = kyori(xy[c[n][d]][0],xy[c[n][d]][1],xy[c[n][d+1]][0],xy[c[n][d+1]][1])
            diss[c[n][d+1]][c[n][d]] = diss[c[n][d]][c[n][d+1]]
        s += diss[c[n][d]][c[n][d+1]]
print(s/len(c))

Submission status: Accepted

Solution code:
import numpy as	np
n =int(input())
d = np.zeros((n,2))
for i in range(n):
    s_list =	str(input()).split()
    d[i, 0], d[i, 1] = s_list[0], s_list[1]
count = 0
sum = 0
for i in range(n):
    for	j in range(n):
        if i < j:
            sum	+= np.linalg.norm(d[i]-d[j])
            count += 1
print(sum / count * (n-1))

Submission status: Accepted

Solution code:
N = int(input())
l = []
 
def kaijo(n):
    
    if n == 1:
        return n
    elif n == 0:
      return 1
    return n * kaijo(n-1)

for i in range(N):
  a = list(map(int, input().split()))
  l.append(a)
import numpy as np
l = np.array(l)
dist = []
for i in range(N):
  for j in range(i+1, N):
    dist.append(np.linalg.norm(l[i]- l[j]))
print(sum(dist)*2/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])**2+(xy[i][1]-xy[j][1])**2)

print(result/N)

Submission status: Accepted

Solution code:
'''
def factorial(n):
    if n == 1:
        return n
    return n*factorial(n-1)
'''
def dist(i, j):
    dx = x[i] - x[j]
    dy = y[i] - y[j]
    return (dx**2 + dy**2)**0.5

n = int(input())
x = [None]*n
y = [None]*n

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

sum = 0
for idi in range(n):
    for idj in range(idi+1, n):
        sum += dist(idi, idj)

ans = sum*2/n

print(ans)

Submission status: Accepted

Solution code:
import math
import itertools


N = int(input())
l = list(range(N))
p = itertools.permutations(l)
xy = [list(map(int, input().split())) for _ in range(N)]
s = 0
for pp in p:
    for i in range(1, N):
        pi, pj = pp[i - 1], pp[i]
        s += ((xy[pi][0] - xy[pj][0]) ** 2 +
              (xy[pi][1] - xy[pj][1]) ** 2) ** 0.5
ave = s / math.factorial(N)
print(ave)

Submission status: Accepted

Solution code:
import itertools
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N=II()
lis=[LI() for i in range(N)]
nums = list(range(N))

su = 0.0
for perm in itertools.permutations(nums, N):
    for i in range(len(perm)-1):
        su += math.sqrt((lis[perm[i]][0]-lis[perm[i+1]][0])**2 + (lis[perm[i]][1]-lis[perm[i+1]][1])**2)

print(su / math.factorial(N))

Submission status: Accepted

Solution code:
# coding: utf-8
import itertools

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

sum=0
for i in range(N):
    for j in range(i+1,N):
        sum += pow(pow(town[i][0]-town[j][0],2)+pow(town[i][1]-town[j][1],2),0.5)
print(sum/len(list(itertools.combinations(town, 2)))*(N-1))

Submission status: Accepted

Solution code:
from math import sqrt
n = int(input())
x = []
y = []
sum = 0
for i in range(n):
    X,Y = map(int,input().split())
    x.append(X)
    y.append(Y)
for i in range(n):
    for j in range(n):
        if j == i:
            continue
        sum += sqrt((x[i]-x[j])**2+((y[i]-y[j])**2))
def rank(s):
    if s != 1:
        return s * rank(s-1)
    else:
        return 1

print(sum * 2 * rank(n-1)/ rank(n)/2)

Submission status: Accepted

Solution code:
from itertools import combinations

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

lengths = [((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5 for a, b in combinations(towns, 2)]
average_lengths = 2*sum(lengths)/n

print(average_lengths)

Submission status: Accepted

Solution code:
from math import sqrt
from itertools import permutations


def norm(i, j):
    return sqrt((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2)


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

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

rst = 0
cnt = 0
for order in permutations([n for n in range(N)]):
    for n in range(N - 1):
        rst += norm((x[order[n]], y[order[n]]), (x[order[n + 1]], y[order[n + 1]]))
    cnt += 1

print(rst / cnt)

Submission status: Accepted

Solution code:
import itertools,math
N=int(input())
N_fac=math.factorial(N)
X={}
Y={}
distance_dic={}
cnt=0
distance=0
for n in range(N):
    x,y=map(int,input().split())
    X[n]=x
    Y[n]=y
lst=list(itertools.permutations(X.keys(),N))
len_lst=len(lst)
for l in lst:
    l_2=list(l)
    for i in range(N-1):
        key1=l[i]
        key2=l[i+1]
        distance=distance+((X[key1]-X[key2])**2+(Y[key1]-Y[key2])**2)**0.5
print(distance/N_fac)

Submission status: Accepted

Solution code:
from itertools import combinations
import math
n = int(input())
li_point = list()
li_kyori = list()
for i in range(n):
    li_point.append(list(map(int, input().split())))


for x, y in combinations(range(n), 2):
    li_kyori.append(
        math.sqrt(
            abs(li_point[x][0] - li_point[y][0]) ** 2 +
            abs(li_point[x][1] - li_point[y][1]) ** 2
        )
    )

ave = sum(li_kyori) / len(li_kyori)
print(ave * (n - 1))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

dist = 0
for i in range(N):
  for j in range(i,N):
    dist += ((spot[i][0]-spot[j][0])**2+(spot[i][1]-spot[j][1])**2)**0.5
print(dist*2/N)