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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
xn = []
yn = []
for i in range(n):
    x,y = map(int, input().split())
    xn.append(x)
    yn.append(y)
    
def kaijou(n):
    if n == 1:
        return 1
    else:
        return n * kaijou(n-1)
    
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        #print(i+1 ,j+1)
        diff = (((xn[i] - xn[j]) ** 2) + ((yn[i] - yn[j]) ** 2)) ** 0.5
        #print(diff)
        ans += diff * (n-1) * 2
        
nkaijou = kaijou(n)
print(ans/ nkaijou)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
x=[]
y=[]
M=0
for i in range(0,N):
    F=input()
    [v,s]=list(map(int,F.split(' ')))
    x.append(v)
    y.append(s)
def dis(x,y,x2,y2):
    return math.sqrt((x-x2)**2+(y-y2)**2)
for i in range(0,N):
    for j in range(0,N):
        M=M+dis(x[i],y[i],x[j],y[j])
print(M/math.factorial(N))

Submission status: Wrong Answer

Solution code:
n = int(input())
xn = []
yn = []
for i in range(n):
    x,y = map(int, input().split())
    xn.append(x)
    yn.append(y)
    
    
def kaijou(n):
    if n == 1:
        return 1
    else:
        return n * kaijou(n-1)
    
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        #print(i+1 ,j+1)
        diff = (((xn[i] - xn[j]) ** 2) + ((yn[i] - yn[j]) ** 2)) ** 0.5
        #print(diff)
        ans += diff *  2 ** (n-1)
nkaijou = kaijou(n)
print(ans/ nkaijou)

Submission status: Wrong Answer

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

su = 0
ssu = []   
for i in range(N):
    for j in range(N):
        siki = (X[i] - X[j])*(X[i] - X[j]) + (Y[i] - Y[j])*(Y[i] - Y[j])
        cnt = siki**0.5
        su += cnt
        ssu += str(su)


print(su / len(ssu))

Submission status: Wrong Answer

Solution code:
n = int(input())
xn = []
yn = []
for i in range(n):
    x,y = map(int, input().split())
    xn.append(x)
    yn.append(y)
    
    
def kaijou(n):
    if n == 1:
        return 1
    else:
        return n * kaijou(n-1)
    
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        #print(i+1 ,j+1)
        diff = (((xn[i] - xn[j]) ** 2) + ((yn[i] - yn[j]) ** 2)) ** 0.5
        print(diff)
        ans += diff *  2 ** (n-1)
nkaijou = kaijou(n)
print(ans/ nkaijou)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

N = int(input().strip())
p = []
for n in range(N):
  i = list(map(int, input().strip().split(' ')))
  #p.append(i)
  p.append(np.array(i))

l = list(itertools.permutations(p, N))
print(l)
half_l = l[:int(len(l) /2)]

sum = 0
for l1 in half_l:
  j = 0
  while j < N - 1:
    sum += np.linalg.norm(l1[j] - l1[j + 1])
    j += 1
print(sum / len(half_l))

Submission status: Wrong Answer

Solution code:
from math import factorial

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

Submission status: Wrong Answer

Solution code:
n = int(input())
xn = []
yn = []
for i in range(n):
    x,y = map(int, input().split())
    xn.append(x)
    yn.append(y)
    
def kaijou(n):
    if n == 1:
        return 1
    else:
        return n * kaijou(n-1)
    
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        #print(i+1 ,j+1)
        diff = (((xn[i] - xn[j]) ** 2) + ((yn[i] - yn[j]) ** 2)) ** 0.5
        print(diff)
        ans += diff * (n-1) * 2
        
nkaijou = kaijou(n)
print(ans/ nkaijou)

Submission status: Wrong Answer

Solution code:
#!python3.4.3
import math


def main():
    n = int(input())
    pos = []

    for i in range(n):
        pos.append(list(map(int, input().split(' '))))
    
    sum_ = 0
    for i in range(n):
        first = pos[i]
        for j in range(n):
            if j == i:
                continue
            x = (first[0] - pos[j][0])**2
            y = (first[1] - pos[j][1])**2
            d = (x + y)**0.5
            sum_ += d
    print((sum_)*(n-1)/math.factorial(n))
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import math


if __name__ == '__main__':
    n = int(input())
    xy = [list(map(int,input().split())) for i in range(n)]

    sum_length = 0.0
    sum_count = 0

    seq = list(range(0,n))
    for e in itertools.permutations(seq):
        # print("=============")
        # print(e)
        # print("=============")
        sum_count += 1
        count = 0
        for i in list(e):
            if (count==n-1):
                continue
            # print(i)
            # print(i)
            if (i+1<=n-1):
                sum_length += math.sqrt((xy[i][0]-xy[i+1][0])*(xy[i][0]-xy[i+1][0]) + (xy[i][1]-xy[i+1][1])*(xy[i][1]-xy[i+1][1]))
            else:
                sum_length += math.sqrt((xy[i][0] - xy[0][0]) * (xy[i][0] - xy[0][0]) + (xy[i][1] - xy[0][1]) * (xy[i][1] - xy[0][1]))
            # print("ok")
            count += 1
            # print(i)
            # print(sum_length)
        # print(sum_length)
        # print(sum_count)
        break
        # print("----------")

    answer = sum_length/ (sum_count * 1.0)
    # print(sum_count)
    print(answer)

Submission status: Wrong Answer

Solution code:
from math import factorial
import math
def nCr(n,r):
    ans = factorial(n)/factorial(r)/factorial(n-r)
    return ans

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

n_2 = nCr(N,2)
temp = nCr(n_2,N-1)
coe = (N-1)*temp*2/n_2/factorial(N)

ans = coe*sum
print(ans)

Submission status: Wrong Answer

Solution code:
import math

def dist(p, q):
    return math.sqrt((p[0]-q[0])**2 + (p[1]-q[1])**2)


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

summation = 0
for i in range(n):
    print("i")
    print(i)
    for j in range(i+1, n):
        d = dist(L[i], L[j])
        
        summation += d

print(summation * 2 / n)

Submission status: Wrong Answer

Solution code:
import itertools
import math
n = int(input())
x1 = []
y1 = []
for i in range(n):
    x, y = map(int, input().split())
    x1.append(x)
    y1.append(y)
l = [i for i in range(n)]
l = list(itertools.permutations(l))
l = l[len(l)//2:]
ans = []
for i in l:
    c = 0
    for x in range(1, len(i)):
        x2 = i[x-1]
        x3 = i[x]
        c += math.sqrt((x1[x2] - x1[x3])**2 + (y1[x2] - y1[x3]) ** 2) 
    ans.append(c)
print(sum(ans)*2/(len(l)*2))

Submission status: Wrong Answer

Solution code:
import math
import numpy as np

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

count = 0

for a in range(N):
    x[a],y[a] = (int(num) for num in input().split())
    
for b in range(N):    
    for c in range(N):
        count += np.sqrt((x[b]-x[c])*(x[b]-x[c]) + (y[b]-y[c])*(y[b]-y[c]))
        
ans = count * (N-1) / int(math.factorial(N))
print(ans)

Submission status: Wrong Answer

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

su = 0
    
for i in range(N):
    for j in range(N):
        siki = (X[i] - X[j])*(X[i] - X[j]) + (Y[i] - Y[j])*(Y[i] - Y[j])
        cnt = math.sqrt(siki)
        su += cnt

N = math.factorial(N)
print(su / N)

Submission status: Wrong Answer

Solution code:
import itertools
import math
n = int(input())
x = []
y = []
for i in range(n):
  sam1, sam2= input().split()
  x.append(int(sam1))
  y.append(int(sam2))
    
a = list(itertools.permutations(range(n)))
kyori = 0
for i in a:
  for j in range(n-1):
    p = int(i[j])
    q = int(i[j+1])
    dx = x[p] - x[q]
    dy = x[p] - x[q]
    tmp = math.sqrt(dx * dx + dy * dy)
    kyori = kyori + tmp
print(kyori / len(a))

Submission status: Wrong Answer

Solution code:
import math

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

for j in range(n):
    x = [int(i) for i in input().split()]
    a.append(x)

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

sum=0
for i in range(n):
    for j in range(n):
        if j==i:
            pass
        else:
            sum += dist(i,j)

print(sum*(n-1)/math.factorial(n))

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
t_s=[]
for i in range(N):
  t=input().split(" ")
  t_s.append([int(t[0]),int(t[1])])
ans=0
for p in range(N):
  for q in range(p+1,N):
    ans+=np.sqrt((t_s[p][0]-t_s[q][0])**2+(t_s[p][1]-t_s[q][1])**2)
print(ans*(N-1)/N)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
list = []
for i in range(N):
    n = input()    
    m = n.split()
    p = [int(i) for i in m]
    list.append(p)
dis = 0
while list != []:
    for a in list:
        d = (a[0] - list[0][0]) ** 2 + (a[1] - list[0][1]) ** 2
        trued = d ** 0.5
        dis = dis + trued
    else:
        list = [] + list[1:]
else:
    dis = dis * 2 * (N - 1) / math.factorial(N)
    print(dis)

Submission status: Wrong Answer

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

import math
import itertools

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

ali =[]
for i in itertools.permutations(XY,3):
    ali.append(math.sqrt(((i[0][0] - i[1][0])**2)+((i[0][1] - i[1][1])**2))+math.sqrt(((i[1][0] - i[2][0])**2)+((i[1][1] - i[2][1])**2)))
print(sum(ali)/math.factorial(N))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# coding: utf-8

# 整数 > 整数型
def I(): return int(input())

# 整数列 '1 2 3 4' > 整数型リスト
def IsIl(): return list(map(lambda x: int(x), input().split()))

# 改行挟む整数列　'1/n 2/n 3/n' > 整数型りすと
def InIl(n): return [input() for i in range(n)]

# 整数列 '1 2' > 整数型タプル
def IsIt(): return map(lambda x: int(x), input().split())

# 改行挟む整数列　'1\n 2\n 3\n' > 整数型たぷる
def InIl(n): return map(input() for i in range(n))

# 文字列 'abcd' > 文字型リスト
def SsSl(): return list(map(lambda x: x, input()))

# 整数 '1234' > 整数型リスト

# 文字列 'aba' > 辞書（文字型:個数）{'a':2,'b':1}
def SSd():
    from collections import defaultdict
    A = input() # [int(i) for i in input().split()]
    dd=defaultdict(int)
    for a in A:
        dd[a]+=1
    return dd

import math

n = I()
lis = []
for i in range(n):
    tup = IsIl()
    lis.append(tup)

sum = 0.0
for i in range(n):
    [x1,y1] = lis[i]
    for j in range(n):
        [x2,y2] = lis[j]
        sum += ((x1-x2)**2 + (y1-y2)**2)**0.5
print(sum/math.factorial(n)*(n-1))

Submission status: Wrong Answer

Solution code:
import math
import statistics

n = int(input())
xl = []
yl = []

for i in range(n):
    x,y = map(int, input().split())
    xl.append(x)
    yl.append(y)

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

dd = []
for i in range(n):
    for j in range(i+1,n):
        dd.append(d(xl[i], yl[i], xl[j], yl[j]))

ans = statistics.mean(dd)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

len_r = 0

for i in range(N-1):
    for j in range(i, N):
        length = (((X[i]-X[j])**2 + (Y[i]-Y[j])**2)) ** (1/2)
        len_r += length

len_r = 2 * len_r

len_sum = 0
for i in range(1,N):
    l = (((X[i]-X[i-1])**2 + (Y[i]-Y[i-1])**2)) ** (1/2)
    len_sum += l

len_sum += (((X[0]-X[-1])**2 + (Y[0]-Y[-1])**2)) ** (1/2)

len_sum = len_sum *math.factorial(N)

ans = (len_sum - len_r) / math.factorial(N)

print(ans)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
a=[]
for i in range(n):
	x,y=map(int,input().split())
	a.append((x,y))
d=[]
for i in range(0,n):
	s=0
	for j in range(0,n):
		if(i==j):
			pass
		else:
			k1=(a[i][0]-a[j][0])**2
			k2=(a[i][1]-a[j][1])**2
			k3=math.sqrt(k1+k2)
			d.append(2*k3)
fact=1
for i in range(1,n+1):
	fact=fact*i
ans=(sum(d)/fact)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

for i in range(n):
    ix,iy=xy[i]
    tmp=[]
    for j in range(n):
        jx,jy=xy[j]
        tmp.append(math.sqrt((ix-jx)**2+(iy-jy)**2))
    l.append(tmp)

pat=1
for i in range(1,n+1):
    pat*=i
sa=1
for i in range(1, n-1):
    sa*=i
wei=pat/(n-1)-sa

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

print(l)
print(sum/pat)

Submission status: Wrong Answer

Solution code:
import math
import statistics

n = int(input())
xl = []
yl = []

for i in range(n):
    x,y = map(int, input().split())
    xl.append(x)
    yl.append(y)

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

dd = []
for i in range(n):
    for j in range(i,n):
        dd.append(d(xl[i], yl[i], xl[j], yl[j]))

ans = statistics.mean(dd)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

Submission status: Wrong Answer

Solution code:
import math
import statistics

n = int(input())
xl = []
yl = []

for i in range(n):
    x,y = i,i
    xl.append(x)
    yl.append(y)

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

dd = []
for i in range(n):
    for j in range(i,n):
        dd.append(d(xl[i], yl[i], xl[j], yl[j]))

ans = statistics.mean(dd)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

ans = 0
count = 0
for i in range(n-1):
    for j in range(i+1,n):
        ans += ((pos[i][0]-pos[j][0])**2 + (pos[i][1]-pos[j][1])**2)**0.5
        count += 1
print(ans*(2**(n-1))/math.factorial(n))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [list(map(int, input().split())) for i in range(n)]
def kaijo(a):
    s = 1
    for i in range(2,a+1):
        s = s * i
    return(s)
l = []
for i in range(n):
    for j in range(n):
        if i >> j:
            l.append(((x[i][0]-x[j][0])**2+(x[i][1]-x[j][1])**2)**0.5)
print(sum(l)*kaijo(n-1)/kaijo(n)*2)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())

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

seq = range(0,N)
kumi = list(itertools.permutations(seq))

print(kumi)
sum = 0
for k in kumi:
    for i, k_i in enumerate(k[:N-1]):
        n_i = k[i + 1]
        print('index {} and {}'.format(k_i, n_i))
        sum += ((X[k_i] - X[n_i]) ** 2 + (Y[k_i] - Y[n_i]) ** 2) ** 0.5

print(sum / len(kumi))


# print((2**0.5*4 + 8)/6)

Submission status: Wrong Answer

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

seq_list = []
for i in range(n):
    seq_list.append(i)

pattern_list = list(itertools.permutations(seq_list))

distance = 0

for j in range(len(pattern_list)):
    distance_sum_tmp = 0
    for k in range(len(pattern_list[j])-1):
            index_from = pattern_list[j][k]
            index_to = pattern_list[j][k+1]
            print(index_to)
            distance_sum_tmp += (((xy_list[index_from][0] - xy_list[index_to][0]) ** 2 ) + ((xy_list[index_from][1] - xy_list[index_to][1]) ** 2 )) ** 0.5
    distance += distance_sum_tmp

print(distance / len(pattern_list))

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
S=list()
ans=0

const=math.factorial(N-1)*2/math.factorial(N)

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


for i in range(N-1):
    for j in range(i+1,N):
        x1,y1=S[i]
        x2,y2=S[j]
        print(x1,y1,const)
        ans+=const*(((x1-x2)**2+(y1-y2)**2)**(1/2))

print(ans)

Submission status: Wrong Answer

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

import math
lsum = 0
for i in range(n):
    for j in range(n):
        if i != j:
            a, b = pl[i]
            c, d = pl[j]
            lsum += math.sqrt((a-c) ** 2 + (b-d) ** 2)
print(lsum / 4 * math.factorial(n))

Submission status: Wrong Answer

Solution code:
import math

n = input()
n = int(n)

points = []

kaijo = 1

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

for i in range(int(n)):
  p = input().split(" ")
  points.append((int(p[0]),int(p[1])))
  
sum = 0
for i in range(n):
  for j in range(n):
    dx = points[i][0] - points[j][0]
    dy = points[i][1] - points[j][1]
    sum += math.sqrt(dx*dx+dy*dy)
    
print(sum/kaijo*2)

Submission status: Wrong Answer

Solution code:
from math import sqrt
n = int(input())
l = [[None, None] for i in range(n)]
for i in range(n):
    a = input().split()
    l[i][0] = int(a[0])
    l[i][1] = int(a[1])
d = 0
for i in range(n-1):
    for j in range(n-i-1):
        k = j + i + 1
        d += sqrt((l[i][0] - l[k][0])**2 + (l[i][1] - l[k][1])**2)
def fac(n):
    if n == 1:
        return 1
    else:
        return n*fac(n-1)

print(d/fac(n))

Submission status: Wrong Answer

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

for j in range(N):
    x1 = xlist[j][0]
    y1 = xlist[j][1]
    for k in range(j+1,N):
        x2 = xlist[k][0]
        y2 = xlist[k][1]
        di = math.sqrt((x1-x2)**2 + (y1-y2)**2)
        dist[j][k] = di

ans = 0

for i in range(N):
    ans += sum(dist[i])*(2**(N-1))
M=1
for j in range(N):
    M*=(j+1)

ans = ans/M
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import itertools

# 引数のリストの全ての順列リストを返す
def fact_list(seq:list):
    return list(itertools.permutations(seq))

# n!を返す
def fact_num(n:int):
    seq = list(range(n))
    return len(fact_list(seq))

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

d = []
for i in range(N-1):
    for j in range(1, N):
        if j!=i:
            d.append(math.sqrt( (abs(x[i]-x[j]))**2 + (abs(y[i]-y[j]))**2 ) /(N*N*(N-1)/2))

n_fact = fact_num(N)
print(sum(d)*n_fact)

Submission status: Wrong Answer

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

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

sum = 0
M = math.factorial(N-1)
for i in range(N):
    for j in range(N):
           sum += math.sqrt((x[j]-x[i])*(x[j]-x[i]) + (y[j]-y[i])*(y[j]-y[i])) * M
           print(sum)


print(sum/math.factorial(N))

Submission status: Wrong Answer

Solution code:
n = int(input())
xn = []
yn = []
for i in range(n):
    x,y = map(int, input().split())
    xn.append(x)
    yn.append(y)
    
import math
def kaijou(n):
    if n == 1:
        return 1
    else:
        return n * kaijou(n-1)
diffs = []
for i in range(n-1):
    for j in range(i+1,n):
        #print(i+1 ,j+1)
        diff = math.sqrt(((xn[i] - xn[j]) ** 2) + ((yn[i] - yn[j]) ** 2))
        diffs.append(diff*2)
print(sum(diffs) / kaijou(n))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [0]*n
y = [0]*n
for i in range(0,n):
    x[i], y[i] = input().split()
    x[i] = int(x[i])
    y[i] = int(y[i])
dist = 0
for i in range(0,n):
    for j in range(0,i):
        dist += ((x[i]-x[j])**2 + (y[i]-y[j])**2)**0.5

kijo = 1
for i in range(1,n + 1):
    kijo *= i
print(dist * 2 * (n - 1) /kijo)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
n = int(input())  
x = [0] * n
y = [0] * n
for i in range(0,n):
    # print(i,c,s[i:i+1],x)
    (x[i],y[i]) = map(int,input().split())  
    print(x[i],y[i]) 

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

av = float(sum) / ( n / 2 )
print(av)

Submission status: Wrong Answer

Solution code:
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


# A
def A():
    r = I()
    print(r * r)
    return


# B
def B():
    N = I()
    s = S()
    if N % 2 != 0:
        print("No")
    elif ''.join(s[:N // 2]) == ''.join(s[N // 2:]):
        print("Yes")
    else:
        print("No")
    return


# C
def C():
    n = I()
    a = [LI() for i in range(n)]
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            ans += pow(pow(a[i][0] - a[j][0], 2) + pow(a[i][1] - a[j][1], 2), 0.5)
    avg = ans / n
    print(avg * (n - 1))
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    C()
    return


# Solve
if __name__ == "__main__":
    C()

Submission status: Wrong Answer

Solution code:
n = int(input())
xn = []
yn = []
for i in range(n):
    x,y = map(int, input().split())
    xn.append(x)
    yn.append(y)
    
import math
def kaijou(n):
    if n == 1:
        return 1
    else:
        return n * kaijou(n-1)
diffs = []
for i in range(n-1):
    for j in range(i+1,n):
        #print(i+1 ,j+1)
        diff = math.sqrt(((xn[i] - xn[j]) ** 2) + ((yn[i] - yn[j]) ** 2))
        diffs.append(diff*2)
sum(diffs) / kaijou(n)

Submission status: Wrong Answer

Solution code:
import itertools
import math

N = int(input())
input_list = [input() for i in range(N)]
count = 0
sum_length = 0

for points in itertools.permutations(input_list, N):
    print("#####")
    length = 0
    for i in range(N-1):
        x, y = map(int, points[i].split())
        next_x, next_y = map(int, points[i + 1].split())
        length += math.sqrt((next_x - x) ** 2 + (next_y - y) ** 2)
    sum_length += length
    count += 1

print(sum_length/count)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [0]*n
y = [0]*n
for i in range(0,n):
    x[i], y[i] = input().split()
    x[i] = int(x[i])
    y[i] = int(y[i])
dist = 0
for i in range(0,n):
    for j in range(0,i):
        dist += ((x[i]-x[j])**2 + (y[i]-y[j])**2)**0.5

kijo = 1
for i in range(1,n + 1):
    kijo *= i
print(dist * 4 /kijo)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import statistics
from math import factorial
import math
 


n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]

#重複なし組み合わせ
from itertools import combinations
lin = list(combinations(li,2))

lis = []

for i in range(len(lin)):

    a = (lin[i][1][1]-lin[i][0][1])**2
    b = (lin[i][1][0]-lin[i][0][0])**2
    c = math.sqrt(a+b)
    lis.append(c)

lin = list(combinations(lis, 2))

if len(lin) == 1:
    print(lin[0])
    exit()

point = 0
for i in range(len(lin)):
    point += sum(lin[i])

print(point/n)

Submission status: Wrong Answer

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

import math
import itertools

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

    x_list = []

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

    li = list(itertools.permutations(x_list))

    print(":::")

    c = 0
    for l in li:
        for i, (x, y) in enumerate(l):
            if i+1 == n:
                break
            else:
                x1, y1 = l[i+1]
                c += math.sqrt((x1 - x)**2 + (y1 - y)**2)


    print(c / len(li))



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = intn = int(input())
p = []
for i in range(n):
    p.append([int(s) for s in input().split()])

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

Submission status: Wrong Answer

Solution code:
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


# A
def A():
    r = I()
    print(r * r)
    return


# B
def B():
    N = I()
    s = S()
    if N % 2 != 0:
        print("No")
    elif ''.join(s[:N // 2]) == ''.join(s[N // 2:]):
        print("Yes")
    else:
        print("No")
    return


# C
def C():
    n = I()
    a = [LI() for i in range(n)]
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            ans += pow(pow(a[i][0] - a[j][0], 2) + pow(a[i][1] - a[j][1], 2), 0.5)
    print(ans / (n - 1))
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    C()
    return


# Solve
if __name__ == "__main__":
    C()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from math import factorial

N = int(input())

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

NN = [[0] * N for _ in range(N) ]
ans = 0
for i in range(N):
    for j in range(i,N):
        ans += (((x[i] - x[j]) ** 2 +(y[i] - y[j]) ** 2) ** (1/2)) * (N - 1) * 2
ans = ans / factorial(N)   

print(ans)

Submission status: Wrong Answer

Solution code:
def frac(n):
    if n==2:
        return 2
    else:
        return n*frac(n-1)

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
xy = []
for i in range(N):
    tmp1, tmp2 = map(int,input().split())
    xy.append((tmp1,tmp2))
print(xy)
d = np.zeros((N,N))
for i in range(N):
    for j in range(N):
        d[i][j] = np.sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)
print(np.sum(d)/N)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
xy=[]

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

import itertools

l=list(itertools.permutations(range(0,n)))
cnt=0
sum=0

while True:
    if len(l)==0:
        break
    temp=l.pop(0)
    for i in range(n-1):
        sum+=((xy[temp[i]][0]-xy[temp[i+1]][0])**2+(xy[temp[i]][1]-xy[temp[i+1]][1])**2)**(1/2)
    cnt+=1

print(sum/cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
import itertools
import math
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    loc = [list(map(int,input().split())) for _ in range(n)]
    arr = np.array(list(itertools.permutations(loc)))
    p = math.factorial(n)
    dis = np.zeros(p)
    for i in range(p):
        for j in range(n-1):
            dis[i] += np.linalg.norm(arr[i][j+1]-arr[i][j])
    print(dis.mean())
    
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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 in permi:
    count+=1
    for k in range(1,N):
        goukei+=np.linalg.norm(XY[i[k-1]]-XY[i[k]])
print(goukei/count)

Submission status: Time Limit Exceeded

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


def main():
    n = int(input())
    xys = [list(map(int, input().split())) for _ in range(n)]

    orders = np.array(list(perm([xys[i] for i in range(n)], n)))
    ans = 0
    order_num = len(orders)

    for order in orders:
        temp = 0
        for i in range(n-1):
            temp += np.linalg.norm(order[i]-order[i+1])
        ans += temp
    print(ans/order_num)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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


def main():
    n = int(input())
    xys = [list(map(int, input().split())) for _ in range(n)]

    orders = list(perm([xys[i] for i in range(n)], n))
    ans = 0
    order_num = len(orders)

    for order in orders:
        temp = 0
        for i in range(n-1):
            temp += np.linalg.norm(np.array(np.array(order[i]))-np.array(order[i+1]))
        ans += temp
    print(ans/order_num)


if __name__ == "__main__":
    main()