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: Runtime Error

Solution code:
import math
import itertools

def l2(z1, z2):
  return math.sqrt(pow(z1[0] - z2[0], 2) + pow(z1[1] - z2[1], 2))

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

dist = 0
z_fr = []
z_to = []
for seq in itertools.permutations(l, n):
  for z in seq:
    z_fr = z_to
    z_to = z
    if len(z_fr):
      continue
    dist += l2(z_fr, z_to)

print(dist/math.factorial(n))

Submission status: Runtime Error

Solution code:
import math
import itertools

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

def l2(z1, z2):
  return math1.sqrt(pow(z1[0] - z2[0], 2) + pow(z1[1] - z2[1], 2))


dist = 0
z_fr = []
z_to = []
for seq in itertools.permutations(l, n):
  for z in seq:
    z_fr = z_to
    z_to = z
    if len(z_fr):
      continue
    dist += l2(z_fr, z_to)

print(dist/math.factorial(n))

Submission status: Runtime Error

Solution code:
import math
import itertools
import numpy as np

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

def l2(z1, z2):
  return np.sqrt((z1[0]^2 - z2[0]^2) + (z1[1]^2 - z2[1]^2))


dist = 0
z_fr = []
z_to = []
for seq in itertools.permutations(l, n):
  for z in seq:
    z_fr = z_to
    z_to = z
    if len(z_fr):
      continue
    dist += l2(z_fr, z_to)

print(dist/math.factorial(n))

Submission status: Runtime Error

Solution code:
def dist(x0, y0, x1, y1):
    return math.sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2)

def resolve():
    N = int(input())
    x, y = [], []
    for _ in range(N):
        x_tmp, y_tmp = list(map(int, input().split()))
        x.append(x_tmp)
        y.append(y_tmp)

    ls = list(permutations(list(range(N)), N))
    ans = 0
    for l in ls:
        idx = 0
        while idx + 1 < len(l):
            ans += dist(x[l[idx]], y[l[idx]], x[l[idx+1]], y[l[idx+1]])
            idx += 1

    print(ans / len(ls))
    return

resolve()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import math
import itertools


def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力を取得
    """
    N = int(input())
    x, y = [], []
    for n in range(N):
        x_n, y_n = list(map(int, input().split()))
        x.append(x_n)
        y.append(y_n)

    return N, x, y


def get_distance(x: list, y: list, i: int, j: int) -> float:
    """
    町iと町jの間の距離を取得する.

    Args:\n
        x (list): 町のx座標
        y (list): 町のy座標
        i (int): 町
        j (int): 町

    Returns:\n
        float: 町iと町jの間の距離
    """
    return math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)


def get_path_length(N: int, distance: dict, path: list) -> float:
    """
    経路の長さを求める.

    Args:\n
        N (int): 町の数
        distance (dict): 町間の距離
        path (list): 経路

    Returns:\n
        float: 経路の長さ
    """
    path_length = 0
    for n in range(N - 1):
        path_length += distance[(path[n], path[n + 1])]

    return path_length


def main(N: int, x: list, y: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 町の数
        x (list): 町のx座標
        y (list): 町のy座標
    """
    # 事前に町間の距離情報を作っておく
    distance = {}
    for i, j in itertools.product(range(N), repeat=2):
        distance[(i, j)] = get_distance(i, j)

    # 求解処理
    ans = 0
    for path in itertools.permutations(range(N)):
        ans += get_path_length(distance, path)
    ans /= math.factorial(N)

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, x, y = get_input()

    # メイン処理
    main(N, x, y)

Submission status: Runtime Error

Solution code:
import numpy as np
from math import factorial
n = int(input())
x = []
y = []
for i in range(n):
  x_, y_ = list(map(int, input().split()))
  x.append(x_)
  y.append(y_)
val = 0
for i in range(n):
  for j in range(i+1, n):
    val += np.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)

ans = val/factorial(n) * factorial(n-1) * 2
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n = int(input())
x = []
y = []
for i in range(n):
  x_, y_ = list(map(int, input().split()))
  x.append(x_)
  y.append(y_)
val = 0
for i in range(n):
  for j in range(i+1, n):
    val += np.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)

ans = val/math.factorial(n) * math.factorial(n-1) * 2
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:


from itertools import permutations
import math

n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
d = lambda x1,x2,x3,x4: ((x1-x2)**2 + (x3-x4)**4)**0.5

x = 0
for i in permutations(a):
	for j in range(n-1):
		x += d(i[j][0],i[j][1], i[j+1][0],i[j+1][1])

#for i in range(n): f*=i+1
print(x / math.factorial(N))

Submission status: Runtime Error

Solution code:

from itertools import permutations

n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
d = lambda x1,x2,x3,x4: ((x1-x2)**2 + (x3-x4)**4)**0.5

x = 0
for i in permutations(a):
	for j in range(n-1):
		x += d(i[j][0],i[j][1], i[j+1][0],i[j+1][1])

#for i in range(n): f*=i+1
print(x / factorial(N))

Submission status: Runtime Error

Solution code:
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
d = lambda x1,x2,x3,x4: ((x1-x2)**2 + (x3-x4)**4)**0.5

x = 0
for i in permutations(a):
	for j in range(n-1):
		x += d(i[j][0],i[j][1], i[j+1][0],i[j+1][1])

#for i in range(n): f*=i+1
print(x / factorial(N))

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np
N=int(input())
retu=[i for i in range(N)]
XY=[]
for i in range(N):
    x=list(map(int,input().split()))
    XY.append(x)
XY=np.array(XY)
permi=list(itertools.permutations(retu))
goukei=0
count=0
for i,j,k in permi:
    count+=1
    goukei+=np.linalg.norm(XY[i]-XY[j])+np.linalg.norm(XY[j]-XY[k])
print(goukei/count)

Submission status: Runtime Error

Solution code:
from math import factorial
from itertools import permutations

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

dist_sum = 0
for route in permutations(range(n), n):
    for j in range(1, n):
        dist = (x[route[j]] - x[route[j - 1]]) ** 2
        dist += (y[route[j]] - y[route[j - 1]]) ** 2
        dist = dist ** 0.5
        dist_sum += dist
ans = dist_sum / factorial(n)
print(ans)

Submission status: Runtime Error

Solution code:

import itertools as it
import math
from statistics import mean
N=int(input())
X=[list(map(int,input().split())) for i in range(N)]
A=[]
for i in list(it.permutations(X,N)):
    B=[]
    for j in range(N-1):
        B.append(math.sqrt((i[j][0]-i[j+1][0])**2+(i[j][1]-i[j+1][1])**2))
    A.append(sum(B))
print(mean(A))

Submission status: Runtime Error

Solution code:
a = int(input())
b = [list(map(int, input().split())) for i in range(a)]
import math
c = math.factorial(a)//(a-1)
count = 0
for i in range(a-1):
  for j in range(i+1:a):
    count += ((b[i][0]-b[j][0])*2+(b[i][1]-b[j][1])*2)*0.5
print(count*c)

Submission status: Runtime Error

Solution code:
import math
 
N = int(input())
x = list()
y = list()
 
for i in range(N):
    #print(i)
    xy = list(input().split())
    x.append(int(xy[0]))
    y.append(int(xy[1]))
 
lis = list(itertools.permutations(list(range(1, N + 1))))
 
ans = 0    
for i in range(N):
    for j in range(N):
        tmp = math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
        ans += tmp
 
print(ans/N)

Submission status: Runtime Error

Solution code:
import itertools
 
N = int(input())
x = list()
y = list()
 
for i in range(N):
    #print(i)
    xy = list(input().split())
    x.append(int(xy[0]))
    y.append(int(xy[1]))

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

Submission status: Runtime Error

Solution code:
import itertools

N = int(input())
x = list()
y = list()

for i in range(N):
    #print(i)
    xy = list(input().split())
    x.append(int(xy[0]))
    y.append(int(xy[1]))

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

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

Submission status: Runtime Error

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

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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


def main():
    N = int(readline())
    C = [tuple(map(int, readline().split())) for _ in range(N)]

    dist = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(i + 1, N):
            dist[i][j] = dist[j][i] = distance2(*C[i], *C[j])

    ans = 0
    for perm in permutations(range(N)):
        for i in range(N - 1):
            ans += dist[perm[i]][perm[i + 1]]

    print(ans / factorial(N))
    return


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
ls = []
ls2 = []
for i in range(N):
  ls.append(map(int,input().split()))
X = 0
Y = 0
for i in range(N):
  for j in range(i+1,N):
    X = (ls[i][0]-ls[j][0])**2
    Y = (ls[i][1]-ls[j][1])**2
    XY = (X+Y)**(0.5)
    ls2.apppend(XY)
if len(ls2) == 1:
  print(ls2[0])
else:
  ans = sum(ls2)*2/N
  print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline
n = int(rl())
li = []
for _ in range(n):
  lis = list(map(int, rl().split()))
  li.append(lis)
t = 0
for i in list(collections.permutations(n)):
  for k in range(n-1):
    s = (li[i[k]][0] - li[i[k+1]][0])**2 + (li[i[k]][1] - li[i[k+1]][1])**2
    t += s**0.5
print(t/math.factorial(n))

Submission status: Runtime Error

Solution code:
import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline
n = int(rl())
li = []
for _ in range(n):
  lis = list(map(int, rl().split()))
  li.append(lis)
t = 0
for i in collections.permutations(n):
  for k in range(n-1):
    s = (li[i[k]][0] - li[i[k+1]][0])**2 + (li[i[k]][1] - li[i[k+1]][1])**2
    t += s**0.5
print(t/math.factorial(n))

Submission status: Runtime Error

Solution code:
import itertools
import math

n = int(input())
lis = [x for x in range(1,n+1)]  #順列とる数列
xy = [list(map(int,input().split())) for i in range(n)]　#座標をメモ
permutations_lis = itertools.permutations(lis)　#順列とって
l = list(permutations_lis)#全順列のリストを作る
ans = 0

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

Submission status: Runtime Error

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

dist=[[0]*N in range(N)]
for i in range(N):
  for j in range(N):
    dist[i][j]=((AB[i][0]-AB[j][0])**2+(AB[i][1]-AB[j][1])**2)**0.5
    
ans=0
def go(town,rest):
  for i in len(rest):
    nrest=rest[:]
    ntown=nrest.pop(i)
    ans+=dist[town][ntown]
    if len(rest)==0:
      return
    go(ntown,nrest)
    
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
xy = list()
for i in range(n):
  xy.append(list(map(int, input().split())))
  
dsum = 0
dist_1 = [[0] * n for k in range(n)]
for i in range(n-1):
  for J in range(i+1, n):
    dist = ((xy[i][0] - xy[j][0] ** 2 + (xy[i][1] - xy[j][1]) ** 2)**(1/2)
    dist_1[i][j] = dist

Submission status: Runtime Error

Solution code:
    N = int(input())

    XY = []

    for i in range(N):
        Xi, Yi = map (float, input().split())
        XY.append([Xi,Yi])

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

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    import numpy as np
    n=int(input())
    l=[list(map(int,input().split()))]
    lkyori=[]
    for i in range(n):
        for j in range(i+1,n+1):
            a=np.array(l[i])
            b=np.array(l[j])
            lkyori.append(np.linalg.norm(a-b)/n)
    import itertools
    answer=0
    print(list(itertools.permutations(lkyori,2)))

resolve()

Submission status: Runtime Error

Solution code:
def calculate_distance(x1, x2):
    l2_norm = (x1[0] - x2[0])**2 + (x1[1] - x2[1])**2
    return math.sqrt(l2_norm)

N = int(input())
point = []
for i in range(N):
    a,b = map(int,input().split())
    point.append([a, b])
    
res = []
for a in itertools.permutations(range(N)):
    distance = 0
    for i in range(N-1):
        distance += calculate_distance(point[i], point[i+1])
    res.append(distance)
np.mean(res)

Submission status: Runtime Error

Solution code:
from itertools import combinations, combinations_with_replacement
from math import sqrt

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

nC2 = list(combinations(xy, 2))
dist = []
d_append = dist.append
for a, b in nC2:
    d_append(sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2))

dist_sum = 0
dist_case = combinations_with_replacement(dist, 2)
for m, n in dist_case:
    dist_sum += m + n

print(dist_sum / len(dist_case))

Submission status: Runtime Error

Solution code:
8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

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

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


print(distance/math.factorial(n))

Submission status: Runtime Error

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

for order in itertools.permutation(range(N)):
  for i in range(1, N):
    dis += ((coord[order[i]][0]-coord[order[i-1]][0])**2 + (coord[order[i]][1]-coord[order[i-1]][1])**2)**0.5
 
Ave = dis / N
print(Ave)

Submission status: Runtime Error

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

for order in itertools.permutations(range(N)):
  for i in range(1, N):
    dis += ((coord[order[i]][0]-coord[order[i-1]][0])**2 + (coord[order[i]][1]-coord[order[i-1]][1])**2)**0.5
 
Ave = dis / N
print(Ave)

Submission status: Runtime Error

Solution code:
import itertools

N = int(input)
coords = [list(map(int, input().split())) for i in range(N)]
dis = 0
n = list(range(N))

for order in itertools.permutations(n):
  for i in range(1, N):
    dis += ((coords[order[i]][0]-coords[order[i-1]][0])**2 + (coords[order[i]][1]-coords[order[i-1]][1])**2)**0.5

ave = dis / N
print(ave)

Submission status: Runtime Error

Solution code:
import itertools

N = int(input)
coords = [list(map(int, input().split())) for i in range(N)]
dis = 0
n = list(range(N))

for order in itertools.permutations(n):
  for i in range(1, N):
    dis += ((coords[order[i]][0]-coords[order[i-1]][0])**2 + (coords[order[i]][1]-coords[order[i-1]][1])**2)**0.5

ave dis / N
print(ave)

Submission status: Runtime Error

Solution code:
import itertools,math,numpy as np
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
xy = np.array([LI() for _ in range(N)])
sum_norm = 0
dict_norm = {}
for a in itertools.permutations(range(N)):
    for i in range(len(a)-1):
        vector = tuple(xy[a[i+1]]-xy[a[i]])
        if not vector in dict_norm:
            dict_norm[vector] = np.linalg.norm(vector)
            vector_inverse = tuple(vector[0]*-1,vector[1]*-1)
            dict_norm[vector_inverse] = dict_norm[vector]
        sum_norm += dict_norm[vector]
print(sum_norm/math.factorial(N))

Submission status: Runtime Error

Solution code:
import math

N = int(input())

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

D = 0
for i in range(N):
    for j in range(N):
        if i < j:
            a = (X[i]-X[j])**2
            b = (Y[i]-Y[j])**2
            c = math.sqrt(a+b)
            D += c
print((2*D)/2)

Submission status: Runtime Error

Solution code:
from math import sqrt

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

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

for _ in range(0,n):
  x_y = input()
  x.append(int(x_y[0]))
  y.append(int(x_y[2]))
  
_sum = 0
  
for i in range(0,n):
  for j in range(i+1,n):
    _sum+=distance(x[i],y[i],x[j],y[j])

print(round((_sum*2)/n,10))

Submission status: Runtime Error

Solution code:
n = int(input())
x = []
y = []

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

for _ in range(0,n):
  x_y = input()
  x.append(x_y[0])
  y.append(x_y[1])
  
_sum = 0
  
for i in range(0,n):
  for j in range(i+1,n):
    _sum+=distance(x[i],y[i],x[j],y[j])

print((_sum*2)/n)

Submission status: Runtime Error

Solution code:
from math import sqrt

n = int(input())

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

x=[0]*n
y=[0]*n

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

dis = 0

for i in range(n):
    for j in range(n):
        dis += distance(x[i], y[i], x[j], y[j])

dis = dis/n
print(dis)

Submission status: Runtime Error

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

XY = [[int(x) for x in input().rstrip().split()] for i in range(N)]

ans = 0
for i in range(N):
  for j in range(N):
    if i < j:
      ans += math.sqrt((XY[i][0]-XY[j][0])**2+(XY[i][1]-XY[j][1])**2)
bb = 1
for i in range(1,N+1):
  bb* = i

print(2*ans/N)

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

N = int(input())

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

average_distance = 0
count = 0
for v in itertools.permutations(x_y_list, N):
    dis = [np.sqrt((v[i][0] - v[i + 1][0])**2 + (v[i][1] - v[i + 1][1])**2) for i in range(N - 1)]
    average_distance += sum(dis)
    count += 1

print('{:.10f}'.format(average_distance / count))

Submission status: Runtime Error

Solution code:

N = int(input())
xy = []
for count in range(N):
    xy.append(input().split())
    itertools.permutations(xy)
XY = []
sum = 0
ave = 0
count = 0
for XY in itertools.permutations(xy):
    for i in range(N-1):
        leng = math.sqrt(((int(XY[i+1][0]) - int(XY[i][0])) ** 2) +
                         ((int(XY[i + 1][1]) - int(XY[i][1])) ** 2))
        sum += leng

ave = sum / math.factorial(N)
print(ave)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
dis = [list(map(int,input().split())) for _ in range(n)]
ans = 0
num = 0
from itertools import permutations
for path in list(permutations(range(n))):
  num += 1
  path = list(path)
  distance = 0
  for i in range(1,n):
    xi = dis[path[i-1]][0]
    xj = dis[path[i]][0]
    yi = dis[path[i-1]][1]
    xj = dis[path[i]][1]
    distance += (pow(xi-xj,2)+pow(yi-yj,2))**0.5
  ans = ans + distance
ans = ans/num
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
input = stdin.readlines
import math

def main():
    N = int(input())
    p = [list(map(int, input().split())) for _ in range(N)]
    s = 0.0
    for i in range(N - 1):
        for j in range(i + 1, N):
            s += math.sqrt((p[i][0] - p[j][0])**2 + (p[i][1] - p[j][1])**2)
    print(s*2/N)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

dists=[]
for i in perm:
    dist=0
    for j in range(1,3):
        dist+=((i[j][0]-i[j-1][0])**2+(i[j][1]-i[j-1][1])**2)**0.5
    dists.append(dist)
ans=sum(dists)/len(dists)
print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial

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

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

ans = 0

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

ans /= factorial(N)

print(ans)

Submission status: Runtime Error

Solution code:
from itertools import permutations
import sys
import heapq
from collections import Counter
from collections import deque
from math import gcd
from math import factorial
from math import sqrt
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


#ここから書き始める
n = int(input())
a = []
for i in range(n):
    x, y = map(int, input().split())
    a.append([x, y])
total = 0
for i in permutations(a):
    # print(i)
    for j in range(1, n):
        x_distance = i[j][0] - i[j - 1][0]
        y_distance = i[j][1] - i[j - 1][1]
        d = sqrt(x_distance ** 2 + y_distance ** 2)
        total += d
ans = total / factorial(n)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

a = sum(dis)

print(a*(n-1)/(n*(n-1)//2))

Submission status: Runtime Error

Solution code:
N = int(input())
xi = []
yi = []

for i in range(N):
  x, y = map(int, input(). split())
  xi.append(x)
  yi.append(y)
  
for j in range(N):
  for k in range(N):
    if j >= k:
      continue
    L += math.sqrt((xi[j]-xi[k])**2 + (yi[j]-yi[k])**2)
    
print(2*L/N)

Submission status: Runtime Error

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_sum=0
for i in range(N):
    for j in range(N):
        if i!=j:
            ans_sum+=math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
print(ans_sum*(n-1)/math.factorial(N))

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
l1=[]
for i in range(n):
    x,y=map(int,input().split())
    l.append((x,y))
N=math.factorial(n)
c=itertools.permutations(l,n)
l=list(c)
for j in range(N):
    for k in range(n-1):
        l1.append(math.sqrt((l[j][k][0]-l[j][k+1][0])**2+(l[j][k][1]-l[j][k+1][1])**2))
print(sum(l1)/N)

Submission status: Runtime Error

Solution code:
import math;n = int(input());l = [list(map(int,input().split())) for i in range(n)];dist = 0
for x1,y1 in l:for x2,y2 in l:dist += math.sqrt((x1-x2)**2 + (y1-y2)**2)
print(dist/n)

Submission status: Runtime Error

Solution code:
n = int(input())
zahyou = []
for i in range(n):
    a = input().split()
    zahyou.append(a)
import math
import itertools
import statistics


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

allen = 0
for i in zahyou:
    for j in zahyou:
        allen += distance(int(i[0]),int(j[0]),int(i[1]),int(j[1]))

ans = allen/ n
print(ans)

Submission status: Runtime Error

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

import math
import itertools
import statistics

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

def permutations_count(nnn, rrr):
    return math.factorial(nnn) // math.factorial(nnn - rrr)

nlist = list(range(0,n))
nlist = list(itertools.permutations(nlist,n))
anslist = []
ans = 0
for i in range(0,permutations_count(n,2)):
    for j in range(0,n-1):
        x1 = xlist[nlist[i][j]]
        x2 = xlist[nlist[i][j+1]]
        y1 = ylist[nlist[i][j]]
        y2 = ylist[nlist[i][j+1]]
        ans += distance(x1,x2,y1,y2)
    anslist.append(ans)
    ans = 0

print(statistics.mean(anslist))

Submission status: Runtime Error

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

import cmath
sum=0  
for j in range(n):
  q=c[j][0];w=c[j][1]
  for k in range(j):
    sum+=cmath.sqrt((c[k][0]-q)**2+(c[k][1]-w)**2)
    
print(float(sum*2/n))

Submission status: Runtime Error

Solution code:
import math
import itertools
from decimal import Decimal
N = int(input())
z = []
A = []
for i in range(N):
  xy = list(map(int,input().split()))
  z.append(xy)
for j in range(N):
  for k in range(j+1,N):
    A.append(Decimal(math.sqrt((z[j][0]-z[k][0])**2+(z[j][1]-z[k][1])**2)))
B = list(itertools.permutations(A, 2))
for l in range(math.factorial(N)):
  B[l] = sum(B[l])
print(sum(B)/math.factorial(N))

Submission status: Runtime Error

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
from itertools import permutations
import math
#import numpy as np
input = sys.stdin.readline

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

    p=permutations(l)
    dist = 0
    for v in p:
        for i in range(N-1):
            dist+=math.sqrt((v[i][0]-v[i+1][0])**2+(v[i][1]-v[i+1][1])**2)
    print(dist/len(list(permutations((l)))))


resolve()

Submission status: Runtime Error

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
from itertools import permutations
# import math
import numpy as np
input = sys.stdin.readline

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

    p=permutations(l)
    dist = 0
    for v in p:
        for i in range(N-1):
            dist+=np.sqrt((v[i][0]-v[i+1][0])**2+(v[i][1]-v[i+1][1])**2)
    print(dist/len(list(permutations((l)))))


resolve()

Submission status: Runtime Error

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

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

    p=permutations(l)
    dist = 0
    for v in p:
        for i in range(N-1):
            dist+=np.sqrt((v[i][0]-v[i+1][0])**2+(v[i][1]-v[i+1][1])**2)
    print(dist/len(list(permutations((l)))))


resolve()

Submission status: Runtime Error

Solution code:
def dfs(coord, visited, route, sum):
    n = len(visited)
  
    allVisited = True
    for city in range(n):
        if visited[city] is False:
            allVisited = False
            break
      
    if allVisited is True:
        len = 0
        for i in range(1, n):
            len += (
              (coord[i-1][0] - coord[i][0])**2
              +
              (coord[i-1][1] - coord[i][1])**2
            )**0.5
        sum += len
        return sum
  
    for next_city in range(n):
        if visted[next_city] is False:
            visted[next_city] = True
            route.append(next_city)
            sum = dfs(coord, visited, route, sum)
            visted[next_city] = False
            route.pop(-1)
           
    return sum
                    
n = int(input())
coord = []
route = []
visited = [False]*n
                    
for i in range(n):
    x, y = map(int, input().split())
    coord.append([x, y])
           

sum = 0
sum = dfs(coord, visited, route, sum)
                    
perm = 1
for i in range(1, n+1):
    perm*=i

print(sum/perm)