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:
def main():
    global visited, adj, sets
    print = out.append
    ''' Cook your dish here! '''
    q = get_int()
    points = []
    res = 0
    for _ in range(q):
        pt = get_list()
        for i in points:
            res += ((pt[0]-i[0])**2+(pt[1]-i[1])**2)**(1/2)
        points.append(pt)
    print(2*res/q)


''' Coded with love at India by Satyam Kumar '''
import sys
#from collections import defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
# [main() for _ in range(int(input()))]
print(*out, sep='\n')

Submission status: Accepted

Solution code:
def main():
    global visited, adj, sets
    print = out.append
    ''' Cook your dish here! '''
    q = get_int()
    points = []
    res = 0
    for _ in range(q):
        pt = get_list()
        for i in points:
            res += ((pt[0]-i[0])**2+(pt[1]-i[1])**2)**(1/2)
        points.append(pt)
    print(2*res/q)


''' Coded with love at India by Satyam Kumar '''
import sys, threading, math
from collections import defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
# [main() for _ in range(int(input()))]
print(*out, sep='\n')

Submission status: Accepted

Solution code:
N=int(input())
lxy=[]
for i in range(N):
    lxy.append(list(map(int,input().split())))
def dij(l1,l2):
    return ((l1[0]-l2[0])**2+(l1[1]-l2[1])**2)**0.5
dsum=0
for i in range(N):
    for j in range(i+1,N):
        dsum+=dij(lxy[i],lxy[j])
print(2*dsum/N)

Submission status: Accepted

Solution code:
def abc145_c():    
    n = int(input())
    xy = [list(map(int,input().split())) for i in range(n)]
    ans = 0
    for i in range(n):
        for j in range(n):
            ans += ((xy[i][0] - xy[j][0])** 2 + (xy[i][1] - xy[j][1])** 2)**0.5
    print(ans / n)
    
if __name__ == '__main__':
    abc145_c()

Submission status: Accepted

Solution code:
# -*- Coding: utf-8 -*-
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
N = int(input())
x, y = [0]*N, [0]*N#N個の空のリストを作成
l = list(range(N))#範囲がNのリストを作成する

for i in range(N):
  x[i], y[i] = map(int, input().split())
#分けて入力する形式を設定することで可読性が高く仕上がっている
#素晴らしいことだ


dis = 0
comb = list(itertools.permutations(l))
#prmutation:英語の意味としては順列である
'''p[, r]で
長さrのタプル列、重複なしのあらゆる並びを表す
今回はリストlの重複なしの並び替え順序を新たなリストに収納している
並び方を計算しリストに収納しているイメージ
l[0,1,2]
l[0,2,1]これにもリスト番号が0,1,2と割り振られている
これが全通り入っている
これ作った人はすごい
自分も早く理解したい
'''
for i in range(0, len(comb)):#i番目のパターンの時を考える。
  for j in range(0, N-1):#lのリスト番号を読み込み
    dis += math.sqrt((x[comb[i][j]]-x[comb[i][j+1]])**2 + (y[comb[i][j]]-y[comb[i][j+1]])**2)
'''
各経路の距離を足していき全距離分を経路数
で割れば平均距離が出るので各経路ごとの距離は
不必要と判断されている。
'''
print(dis/len(comb))

Submission status: Accepted

Solution code:
import itertools,math
def dist(x,y):
    return ((x[0]-y[0])**2 + (x[1]-y[1])**2)**(1/2)
n = int(input())
data = [list(map(int,input().split()))for i in range(n)]
ans = 0
for v in itertools.permutations(data):
    for i in range(1,n):
        ans += dist(v[i],v[i-1])

print(ans/math.factorial(n))

Submission status: Accepted

Solution code:
N=int(input())
lxy=[]
for i in range(N):
    lxy.append(list(map(int,input().split())))
def fac(n):
    ans=1
    for i in range(1,n+1):
        ans*=i
    return ans
def dij(l1,l2):
    return ((l1[0]-l2[0])**2+(l1[1]-l2[1])**2)**0.5
#ans=0
dsum=0
for i in range(N):
    for j in range(i+1,N):
        dsum+=dij(lxy[i],lxy[j])
print(2*dsum/N)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import permutations
import math

n = int(input())

li = []
for _ in range(n):
    i, j = map(int, input().split())
    li.append(np.array([i, j]))

li2 = permutations(li)

re = []
for a in li2:
    dis = 0 
    for (x1,y1),(x2,y2) in zip(a,a[1:]): 
        x = x1-x2
        y = y1-y2
        dis += math.sqrt(x * x + y * y)
    re.append(dis)

print(np.average(re))

Submission status: Accepted

Solution code:
import numpy as np
from itertools import permutations
import math

n = int(input())

li = []
for _ in range(n):
    i, j = map(int, input().split())
    li.append(np.array([i, j]))

li2 = permutations(li)

re = []
for a in li2:
    dis = 0 
    for (x1,y1),(x2,y2) in zip(a,a[1:]):
        dis += math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
    re.append(dis)

print(np.average(re))

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
import itertools

def kyori(xi, yi, xj, yj):
    return ((xi-xj)**2 + (yi-yj)**2)**0.5

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

lst = list(range(n))
p = itertools.permutations(lst)
goukei = 0
cnt = 0
for kumi in p:
    cnt += 1
    for i in range(n-1):
        goukei += kyori(x[kumi[i]], y[kumi[i]], x[kumi[i+1]], y[kumi[i+1]])

print(goukei/cnt)

Submission status: Accepted

Solution code:
import math
from itertools import permutations
N = int(input())
coodinate = [list(map(int,input().split())) for _ in range(N)]
f_N = math.factorial(N)
SumDistance = 0
for val in permutations(coodinate):
    for i in range(len(val) - 1):
        SumDistance += ((val[i+1][0] - val[i][0]) ** 2 + (val[i+1][1] - val[i][1]) ** 2) ** (1 / 2)
print(SumDistance / math.factorial(N))

Submission status: Accepted

Solution code:
from itertools import permutations
from math import hypot

n = int(input())
cnt = 0
dis = 0

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

for a in permutations(li):
    cnt += 1
    for (x1,y1),(x2,y2) in zip(a,a[1:]):
        dis += hypot(x1-x2, y1-y2)

print(dis/cnt)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import hypot

n = int(input())
cnt = 0
dis = 0

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

ptn = list(range(n))

for a in permutations(ptn):
    cnt += 1
    for i, j in zip(a,a[1:]):
        x1, y1 = li[i]
        x2, y2 = li[j]
        dis += hypot(x1-x2, y1-y2)

print(dis/cnt)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import permutations
from math import hypot

n = int(input())
cnt = 0
dis = 0

li = []
for _ in range(n):
    i, j = map(int, input().split())
    li.append(np.array([i, j]))

ptn = list(range(n))

for a in permutations(ptn):
    cnt += 1
    for i, j in zip(a,a[1:]):
        x1, y1 = li[i]
        x2, y2 = li[j]
        dis += hypot(x1-x2, y1-y2)

print(dis/cnt)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import permutations
from math import hypot

n = int(input())
k = 0
dis = 0

li = []
for _ in range(n):
    i, j = map(int, input().split())
    li.append(np.array([i, j]))

li2 = permutations(li)

re = []
for a in li2:
    k += 1
    for (x1,y1),(x2,y2) in zip(a,a[1:]):
        dis += hypot(x1-x2, y1-y2)

print(dis/k)

Submission status: Accepted

Solution code:
import math
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())
kaijo = 1
for i in range(1,N+1):
    kaijo *= i
kaisu = kaijo * (N-1)
hen = N * (N-1) // 2
wa = 0
for i in range(N):
    for j in range(i+1,N):
        kyori = math.sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)
        wa += kyori * kaisu / hen
print(wa / kaijo)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import permutations
from math import hypot

n = int(input())

li = []
for _ in range(n):
    i, j = map(int, input().split())
    li.append(np.array([i, j]))

li2 = permutations(li)

re = []
for a in li2:
    dis = 0 
    for (x1,y1),(x2,y2) in zip(a,a[1:]):
        dis += hypot(x1-x2, y1-y2)
    re.append(dis)

print(np.average(re))

Submission status: Accepted

Solution code:
from itertools import permutations

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

# xy = [(x, y) for (x, y) in map(int, input().split())]

# print(xy)

path_length = 0
pxy = permutations(xy)
c = 0

for p in pxy:
    c += 1
    for (x1, y1), (x2, y2) in zip(p, p[1:]):
        path_length += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
ans = path_length / c
# print(c)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
xy = [[int(i) for i in input().split()] for i in range(n)]
import itertools
l = [int(i) for i in range(n)]
path_length = 0
for p in list(itertools.permutations(xy)):
    for (x1,y1),(x2,y2) in zip(p,p[1:]):
        path_length += ((x1-x2)**2 + (y1-y2)**2)**0.5
print(path_length / len(list(itertools.permutations(l))))

Submission status: Accepted

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

s = 0
for i in range(n-1):
  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:
#abc145c

n=int(raw_input())
l=[]
for i in range(n):
 x,y=map(int,raw_input().split())
 l.append([x,y])
res=0
for i in range(n):
 for j in range(n):
  res+=((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)**0.5
print res/n

Submission status: Accepted

Solution code:
import numpy as np
from itertools import permutations

N = int(input())
P = np.array([input().split() for _ in range(N)], dtype=int)

MAP = P.reshape(N,1,2) - P.reshape(1,N,2)
MAP = (MAP[:,:,0]**2 + MAP[:,:,1]**2)**0.5

total = 0
n_cnt = 0

for rt in permutations(range(N)):
  n_cnt += 1
  total += MAP[rt[:-1], rt[1:]].sum()

print(total / n_cnt)

Submission status: Accepted

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

def main():
    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(i+1, N):
            t = math.sqrt((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2)
            d[i][j] = t
            d[j][i] = t
    
    ans = 0
    count = 0
    for p in permutations(range(N)):
        count += 1
        for i in range(N-1):
            ans += d[p[i]][p[i+1]]
    print(ans / count)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
x = []
y = []
for i in range(N):
    a,b = map(int, (input().split()))
    x.append(a)
    y.append(b)
aaa = 0
for i in range(N):
    for k in range(N):
        aaa += ((x[i] - x[k])**2+(y[i] - y[k])**2)**0.5
print(aaa/N)

Submission status: Accepted

Solution code:
import math
import itertools
N=int(input())

def lengs(inp):
    x=0.0;y=0.0;S=0.0
    for i in range(N):
        J=math.sqrt((inp[i][0]-x)**2+(inp[i][1]-y)**2)
        x=float(inp[i][0]);y=float(inp[i][1])
        if i!=0:S+=J
    return S

J=[]
for i in range(N):
    j=input().split()
    J.append([float(j[0]),float(j[1])])
Js=list(itertools.permutations(J))
S=0.0
for Ja in Js:
    S+=lengs(Ja)
S=S/len(Js)
print(S)

Submission status: Accepted

Solution code:
import itertools
import math

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

def dis(p):
  d = 0
  for i in range(len(p)-1):
    d += ((p[i][0] - p[i+1][0]) ** 2 + (p[i][1] - p[i+1][1]) ** 2) ** 0.5
  return d

perm = itertools.permutations(p, N)
d = 0
for l in perm:
  #print(l, dis(l))
  d += dis(l)
  
print(d / math.factorial(N))

Submission status: Accepted

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

tmp = n = 0
for ptn in permutations(XY):
    n += 1
    for (x1,y1),(x2,y2) in zip(ptn,ptn[1:]):
        tmp += hypot(x1-x2, y1-y2)
print(tmp / n)

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:
import itertools
import math
N = int(input())
x, y = [0]*N, [0]*N
l = list(range(N))

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

dis = 0
comb = list(itertools.permutations(l))
for i in range(0, len(comb)):
  for j in range(0, N-1):
    dis += math.sqrt((x[comb[i][j]]-x[comb[i][j+1]])**2 + (y[comb[i][j]]-y[comb[i][j+1]])**2)

print(dis/len(comb))

Submission status: Accepted

Solution code:
N = int(input())
XY = [tuple(float(s) for s in input().split(' ')) for _ in range(N)]

total = 0.0
count = 0.0
for i in range(N):
  for j in range(i+1, N):
    length = ((XY[i][0] - XY[j][0])**2
              +(XY[i][1] - XY[j][1])**2)**0.5
#    print(i,j,length)
    count += 1
    total += length
mean = total/count
#print(total, count, mean)
print(mean * (N-1))

Submission status: Accepted

Solution code:
n = int(input())
d = [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 += ((d[i][0] - d[j][0])**2 + (d[i][1] - d[j][1])**2)**(1 / 2)
print(2 * D / n)

Submission status: Accepted

Solution code:
n = int(input())
d = [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 += ((d[i][0] - d[j][0])**2 + (d[i][1] - d[j][1])**2)**(1 / 2)
print(D * (n - 1) / (n * ~-n / 2))

Submission status: Accepted

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


def dist(x, y):
    return ((p[x][0] - p[y][0]) ** 2 + (p[x][1] - p[y][1]) ** 2) ** 0.5


for i in range(N - 1):
    for j in range(i + 1, N):
        ans += dist(i, j) * 2 / N

print(ans)

Submission status: Accepted

Solution code:
import math

n = int(input())

z = math.factorial(n-2)*(n-1)*2
total = 0
p = []

for _ in range(n):
	x, y = map(int, input().split())
	
	for a, b in p:
		d = ((x-a)**2 + (y-b)**2)**0.5
		total += z*d
		
	p.append((x,y))
	
print(total/math.factorial(n))

Submission status: Accepted

Solution code:
def c_average_length():
    N = int(input())
    Positions = [[int(i) for i in input().split()] for j in range(N)]

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

print(c_average_length())

Submission status: Accepted

Solution code:
import math
from itertools import permutations
import numpy as np

N = int(input())
c = list()
for n in range(N):
  x, y = list(map(int, input().split()))
  c.append((x, y))

def length(c1, c2):
  return math.sqrt((c1[0]-c2[0])**2 + (c1[1]-c2[1])**2)
 
A = list()
for i in list(permutations(range(len(c)))):
  L = 0
  for j in range(len(i)-1):
    L += length(c[i[j]], c[i[j+1]])
  A.append(L)
  
print(np.mean(A))

Submission status: Accepted

Solution code:
def permu(lis,n,prog):
  if len(lis)==1:
    result.append(prog+[lis[0]])
    n+=5
  
  else:
    for i in range(n):
      lx = lis.copy()
      x = lx[i]
      lx.remove(x)
      permu(lx,n-1,prog + [x])
      
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
import math
l_sum = 0
dic={}
lx = list(range(0,N))
 
for k,i in enumerate(xy):
  l = []
  for j in xy:
    length = ((i[0]-j[0])**2 + (i[1]-j[1])**2)**(1/2)
    l.append(length)
    
  dic[k]=l
  
  

result = []
permu(lx,N,[])
for i in result:
  for j in range(N-1):
    l_sum += dic[i[j]][i[j+1]]
    
print(l_sum/math.factorial(N))

Submission status: Accepted

Solution code:
import math

towns = int(input()) # 町の数
total_between_town = 0 # 各町間距離の合計
x_axis = [] # x軸の座標
y_axis = [] # y軸の座標

# 座標の読み込み
for i in range(towns):
  str = input()
  x_axis.append(int((str.split())[0]))
  y_axis.append(int((str.split())[1]))

# 各座標間の距離を算出し、各町間距離の合計を算出する
for i in range(towns):
  for j in range(i + 1, towns):
    len = math.sqrt((x_axis[i]- x_axis[j]) ** 2 + (y_axis[i]- y_axis[j]) ** 2)
    total_between_town = total_between_town + len

# 全経路の距離合計 = (各町間距離の合計) * {((地点数) - 1) * (経路の数) / (2町の組み合わせ)}
route = math.factorial(towns) # 経路数
pairs = int(towns * (towns - 1) // 2) # 2つの町の組み合わせ総数
total_length = total_between_town * (towns - 1) * route / pairs # 全経路の距離合計
average_length = total_length / route # 各経路の距離平均

# 結果出力
print(average_length)

Submission status: Accepted

Solution code:
from itertools import permutations
def fuctorial(n):
    if n <= 1:
        return 1
    else:
        return n * fuctorial(n - 1)


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


indice = list(range(N))
indices = permutations(indice, N)
res = 0
for ic in indices:
    for i in range(1, N):
        x1, y1 = zahyou[ic[i - 1]]
        x2, y2 = zahyou[ic[i]]
        res += ((x1 - x2)**2 + (y1 - y2)**2)**0.5


print(res/fuctorial(N))

Submission status: Accepted

Solution code:
from collections import namedtuple
from itertools import permutations
from math import sqrt

Point = namedtuple('Point', ['x', 'y'])


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

    ans = 0
    cnt = 0

    for perm in permutations(range(n)):
        dist = 0
        for i in range(1, n):
            p1 = points[perm[i-1]]
            p2 = points[perm[i]]
            dist += sqrt(
                ((p1.x - p2.x) ** 2) + ((p1.y - p2.y) ** 2))
        ans += dist
        cnt += 1

    ans = ans / cnt
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

import sys
from itertools import permutations
from math import hypot

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
XY = []
for i in range(N):
    x, y = MAP()
    XY.append((x, y))

sm = cnt = 0
for perm in permutations(XY):
    dist = 0
    prev = (0, 0)
    for i, (x, y) in enumerate(perm):
        if i == 0:
            prev = (x, y)
        else:
            x2, y2 = prev
            dist += hypot(x-x2, y-y2)
    sm += dist
    cnt += 1
print(sm/cnt)

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
X = []
Y = []

for i in range(N):
	x,y = map(int,input().split())
	X.append(x)
	Y.append(y)
	
def des(i, j):
	return math.sqrt( (X[i] - X[j]) ** 2.0 + (Y[i] - Y[j]) ** 2.0)
	
s = 0
for c in itertools.combinations(range(N), 2):
	s += des(c[0],c[1])
	
print(s*2 / 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())

import itertools
import math

allx = list(itertools.permutations(x,2))
ally = list(itertools.permutations(y,2))


anslist = []

for (a,b) in zip(allx,ally):
    anslist.append(math.sqrt(pow(a[0] - a[1],2) + pow(b[0] - b[1],2)))

nn = n - 1
lastans = sum(anslist) * nn / len(anslist)

print(lastans)

Submission status: Accepted

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

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


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


def chker(xylist):
    now = xylist[0]
    remain = xylist[1:]
    pathsum = 0

    while remain:
        for item in remain:
            pathsum += distance(now, item)

        now, remain = remain[0], remain[1:]

    return pathsum


print(chker(_xylist) * 2 / _n)

Submission status: Accepted

Solution code:
from itertools import permutations
import math

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

ans = cnt = 0
for perm in permutations(range(n)):
    dist = 0
    for i in range(1, n):
        dist += math.sqrt((p[perm[i]][0] - p[perm[i - 1]][0])**2 +
                          (p[perm[i]][1] - p[perm[i - 1]][1])**2)

    # print(perm, dist)
    ans += dist
    cnt += 1

ans /= cnt
print(ans)

Submission status: Accepted

Solution code:
l=map(int,open(0).read().split()[1:]);*z,=zip(l,l);print(sum(((a-x)**2+(b-y)**2)**.5for a,b in z for x,y in z)/len(z))

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
X = []
Y = []

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

def des(i, j):
    return math.sqrt( (X[i] - X[j])**2.0 + (Y[i] - Y[j])**2.0 )

s = 0
for c in itertools.combinations(range(N), 2):
    s += des(c[0], c[1])

print(s*2 / N)

Submission status: Accepted

Solution code:
n=int(input());x=[list(map(int,input().split()))for i in range(n)];a=0
for s in x:
 for t in x:a+=((s[0]-t[0])**2+(s[1]-t[1])**2)**.5
print(a/n)

Submission status: Accepted

Solution code:
N = int(input())
X = []
Y = []
Nex = 1

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


L = 0

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

if N == 2:
    print(L)
else:
    ans = 2*L/N
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
D = [list(map(int, input().split())) for i in range(N)]
Q = []
f = [1]
for i in range(N):
  f.append(f[i] * (i+1))
for i in range(N-1):
  for j in range(i+1, N):
    Q.append(((D[i][0] - D[j][0]) ** 2 + (D[i][1] - D[j][1]) ** 2) ** (1/2))
S = sum(Q) * (2 * f[N-1])
print(S / f[N])

Submission status: Accepted

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

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

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:
import math
import itertools
n = int(input())
x = [0]*n
y = [0]*n
dist = [[0 for _ in range(n)]for _ in range(n)]
comb = [[0 for _ in range(n)]for _ in range(n)]
ans = 0
count = 0
for i in range(n):
	x[i],y[i] = map(int,input().split())
#dist[i][j] = すべての町の距離の配列
for p in itertools.permutations(list(range(n))):
	#すべての組み合わせを一つずつ取り出すp
	for i,j in zip(p,p[1:]):
		ans += math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
	count += 1
ans = ans/count

print(ans)

Submission status: Accepted

Solution code:
import itertools as z;n=int(input());p=list(z.combinations([list(map(int, input().split())) for i in range(n)],2));a=0
for c,d in p:a+=((c[0]-d[0])**2+(c[1]-d[1])**2)**0.5
print(a*(n-1)/len(p))

Submission status: Accepted

Solution code:
n=int(input())
xy=[]
for i in range(n):
    xy.append([int(j) for j in input().split()])
ans=0
import itertools
for l in itertools.permutations("01234567"[:n]): 
    for i in range(n-1):
        x=xy[int(l[int(i)])][0]-xy[int(l[int(i+1)])][0]
        y=xy[int(l[int(i)])][1]-xy[int(l[int(i+1)])][1]
        ans+=((x)**2+(y)**2)**0.5
import math
print(ans/(math.factorial(n)))

Submission status: Accepted

Solution code:
from math import sqrt
inpl = lambda: list(map(int,input().split()))
N = int(input())
xy = [inpl() for _ in range(N)]
def distance(i,j): return sqrt(sum((xy[i][k]-xy[j][k])**2 for k in range(2)))
S = sum(distance(i,j) for i in range(N-1) for j in range(i,N))
print(2*S/N)

Submission status: Accepted

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

pair = list(combinations(xy,2))

ans = 0
for p in pair:
    ans += ((p[0][0]-p[1][0])**2 + (p[0][1]-p[1][1])**2)**0.5
print(ans*(n-1)/len(pair))

Submission status: Accepted

Solution code:
N = int(input())
L = []
for _ in range(N):
    l = list(map(int,input().split()))
    L.append(l)
from itertools import permutations
# permutations('ABCD', 2) --> AB AC AD BA BC BD CA CB CD DA DB DC
# permutations(range(3)) --> 012 021 102 120 201 210
permu_list = list(permutations(L,N))
ans = 0
for x in permu_list:
    for i in range(len(L)-1):
        l1 = x[i]
        l2 = x[i+1]
        length = ((l1[0] - l2[0])**2 + (l2[1] - l1[1]) ** 2)**(1/2)
        ans += length
print(ans/len(permu_list))

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial

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

root = list(permutations(xy,n))

ans = 0
for r in root:
    a = 0
    for i in range(n-1):
        a += ((r[i+1][0]-r[i][0])**2 + (r[i+1][1]-r[i][1])**2)**0.5
    ans += a
print(ans/factorial(n))

Submission status: Accepted

Solution code:
import numpy as np
import math
 
def length(x,y):
    return np.sqrt(x**2+y**2)

N = int(input())
xy = []
for i in range(N):
    xyi = map(int,input().split())
    xy.append(np.array(list(xyi)))

L=0
for i in range(N):
    for j in range(N):
        d = xy[i] - xy[j]
        l = float(length(d[0],d[1]))
        L += l * math.factorial(N-1)
nn = math.factorial(N)
ans = L/nn
print(ans)

Submission status: Accepted

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

from math import sqrt


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

s = 0

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

print(s*2/n)

Submission status: Accepted

Solution code:
import sys
from math import sqrt
read = sys.stdin.read

N, *xy = map(int, read().split())
x = xy[::2]; y = xy[1::2]

distance = []

for i in range(N - 1):
    for j in range(i + 1, N):
        distance.append(sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2))

print(sum(distance) / N * 2)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    cities = [list(map(int, input().split())) for _ in range(N)]
    distances = [distance(cities[i], cities[j]) for i in range(N) for j in range(N)]
    total_distances = sum(distances)
    print((total_distances) / N)


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import math

N = int(input())

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

for i in range(N-1):
    for j in range(i+1, N):
        ans += np.sqrt((A[i][0]-A[j][0])**2+(A[i][1]-A[j][1])**2)
        
f = math.factorial(N)
ans *= 2/N
#ans *= N*(N-1)*(N-1)
print(ans)

Submission status: Accepted

Solution code:
import itertools

def calc_dist(visit1, visit2):
    return ((xy[visit1][0] - xy[visit2][0])**2 + (xy[visit1][1] - xy[visit2][1])**2)** 0.5

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

dist = 0
count = 0
visit_list = [i for i in range(n)]
for visit_order in itertools.permutations(visit_list):
    for i in range(n-1):
        dist += calc_dist(visit_order[i], visit_order[i+1])
    count += 1

print(dist/count)

Submission status: Accepted

Solution code:
import itertools
import math
N = int(input())
count = 0
f = []
ans = 0
def ai(i, j):
    return (math.sqrt((i[0] - j[0])** 2 + (i[1] - j[1])** 2))
for i in range(N):
    f += [list(map(int, input().split()))]
for i in itertools.permutations(range(N)):
    count += 1
    for j in range(N-1):
        ans += ai(f[i[j]], f[i[j + 1]])
print(ans/count)

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
X = []
Y = []

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

def des(i, j):
    return math.sqrt( (X[i] - X[j])**2.0 + (Y[i] - Y[j])**2.0 )

s = 0
for c in itertools.combinations(range(N), 2):
    s += des(c[0], c[1])

print(s*2 / N)

Submission status: Accepted

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

print(d*2/n)

Submission status: Accepted

Solution code:
import math
import itertools
N = int(input())
m = math.factorial(N)
a = []
for _ in range(N):
    a.append(list(map(int, input().split())))
sum = 0
for i in itertools.permutations(a):
    for k in range(N-1):
        sum += math.sqrt(((i[k][0]-i[k+1][0])**2)+((i[k][1]-i[k+1][1])**2))
print(sum/m)

Submission status: Accepted

Solution code:
n = int(input())
x = [0]*8
y = [0]*8
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):
        if i != j:
            sum += pow(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2),0.5)
            
sum = sum / (n * (n - 1)) * (n - 1)
print(sum)