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:
N = int(input())
data = []
sum = 0
x = 0
y = 1
ss=[0,0,2,4,18,96,600,4320,35280]
for i in range(N):
    data.append( list(map(int,input().split())))
for i in range(N -1):
    for j in range(N - 1):
        if(j+1+i==N):
            break
        sum+=((data[i][x]-data[j+1+i][x])**2+(data[i][y]-data[j+1+i][y])**2)**0.5

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

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
n=int(input())
e = [[int(i) for i in input().split()] for i in range(n)]

def dist(i,j):
  return np.sqrt((e[i][0]-e[j][0]) ** 2 + (e[i][1]-e[j][1]) ** 2)

if n == 2:
  print(dist(0,1))
else:
  a = 0
  for i in range(n-1):
    j=n-2-i
    a += math.factorial(i) * math.factorial(j)
  ans=0
  for i in range(n):
    for j in range(n):
      ans += dist(i,j) * a
  ans = ans / math.factorial(n)
  print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
b = 0
c = math.ceil(n/2)
e = math.factorial(n)
s = []
for i in range(n):
    a = list(map(int,input().split()))
    s.append(a)
ans = 0
for l in range(n):
    for m in range(l+1,n):
        ans += ((s[l][0]-s[m][0])**2 + (s[l][1] - s[m][1])**2)**0.5
    b += 1
print(ans*(c*2) / e)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
n=int(input())
li=[]
a=[]
b=[]
s=0
while True:
    try:
        li.append(list(map(int,input().split())))
    except:
        break;
for x in li:
  a.append(x[0])
  b.append(x[1])

for i in range(0,n):
  for j in range(i,n):
  	s+=np.sqrt(((a[j]-a[i])**2)+((b[j]-b[i])**2))

p=math.factorial(n)
print(s,p)
print(s/p)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

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

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

fac = 1
for i in range(1, n):
    fac*=i
    
print(d * (n - 1) / n)

Submission status: Wrong Answer

Solution code:
from math import sqrt
from math import factorial

n = int(input())
t = []
for i in range(n):
  t.append(list(map(int,input().split())))
l = [[0]*n for j in range(n)]
for k in range(n):
  for m in range(n):
      l[k][m] = sqrt((t[k][0]-t[m][0])**2+(t[k][1]-t[m][1])**2)
ans = 0
for i in range(n):
  s = sum(l[i])
  ans += s*factorial(n-1)
z = int(ans/2)
print(z)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
b = 0
c = math.ceil(n/2)
e = math.factorial(n)
s = []
for i in range(n):
    a = list(map(int,input().split()))
    s.append(a)
ans = 0
for l in range(n):
    for m in range(l+1,n):
        ans += ((s[l][0]-s[m][0])**2 + (s[l][1] - s[m][1])**2)**0.5
        print(ans)
    b += 1
print(ans*(c*2) / e)

Submission status: Wrong Answer

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

#必要な掛け算の数字を出す
k=math.factorial(N) #k通り
w=0
for i in range(0,N):
    w=w+(N-i)
#必要な数
t=(k*(N-1))/(w/2)
#それぞれの辺の長さを総当たりで求めていく
p=0
q=0
for i in range(0,N):
    for j in range(i+1,N):
        p=(x[i][0]-x[j][0])**2+(x[i][1]-x[j][1])**2
        q=q+math.sqrt(p)
print(q*t/k)

Submission status: Wrong Answer

Solution code:
import itertools
import math

n = int(input())
towns = []
indexs = []
for i in range(n):
    tmp = input().split(' ')
    x = int(tmp[0])
    y = int(tmp[1])
    towns.append([x,y])
    indexs.append(i)

sum = 0
c = 0
for index in itertools.permutations(indexs):
    c = c + 1
    for k in range(n-1):
        i = towns[k]
        j = towns[k+1]
        sum = sum + math.sqrt(pow((i[0] - j[0]),2) + pow((i[1] - j[1]), 2))



print(sum/c)

Submission status: Wrong Answer

Solution code:
from math import sqrt
from math import factorial

n = int(input())
t = []
for i in range(n):
  t.append(list(map(int,input().split())))
l = [[0]*n for j in range(n)]
for k in range(n):
  for m in range(n):
      l[k][m] = sqrt((t[k][0]-t[m][0])**2+(t[k][1]-t[m][1])**2)
ans = 0
for i in range(n):
  s = sum(l[i])
  ans += s*factorial(n-2)*2/n
z = int(ans/2)
print(z)

Submission status: Wrong Answer

Solution code:
import math
import itertools
n = int(input())
x = [0]*n
y = [0]*n
town =[[0 for _ in range(2)]for _ in range(n)]
dist = [[0 for _ in range(n)]for _ in range(n)]
comb = [[0 for _ in range(n)]for _ in range(n)]
ans = 0
for i in range(n):
	x[i],y[i] = map(int,input().split())
	town[i] = (x[i],y[i])



#dist[i][j] = すべての町の距離の配列
for i in range(n):
	for j in range(i+1,n):
		dist[i][j] = math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
		dist[j][i] = dist[i][j]


comb = list(itertools.permutations(range(n),n))
dist = list(dist)
"""
for i in range(n-1):
	for j in range(n-1):
		a = int(comb[i][j])
		b = int(comb[i][j+1])
		#ans += dist[a][b]
"""
for i in range(n):
	for j in range(n):
		ans += dist[i][j]
print(2*ans/math.factorial(n))

Submission status: Wrong Answer

Solution code:
import itertools
import math

N = int(input())

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

P = list(itertools.permutations(XY,r = N))

D = math.factorial(N)

area = 0

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

print(area / D)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [list(map(int,input().split())) for i in range(n)]
l = 0
m = 1
r = 1
while 1 <= r <= n:
	m *= r
	r += 1
for i in range(n):
	for j in range(n):
		p = ((s[i][0] - s[j][0]) ** 2 + (s[i][1] - s[j][1]) ** 2) ** (1/2)
		l += p
print(2 * l / m)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
xy_list = []
#n = 3
#xy_list = [[0,0 ],[0 ,1],[1,0]]
for i in range(n):
  xy_list.append(list(map(int,input().split())))
counter = 0
for m in range(n-1):
  for l in range(m,n):
    x_l = xy_list[l][0]
    y_l = xy_list[l][1]
    x_m = xy_list[m][0]
    y_m = xy_list[m][1]
    counter += ((x_m - x_l)**2 + (y_m - y_l)**2)**0.5

print(counter*(n+1)/math.factorial(n))

Submission status: Wrong Answer

Solution code:
import math
import statistics
import itertools

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 m in itertools.permutations(range(n)):
    dsum = 0
    for i in range(n-1):
        ii = m[i]
        iii = m[i+1]
        print(ii,iii)
        dsum += d(xl[ii], yl[ii], xl[iii], yl[iii])
    dd.append(dsum)
ans = statistics.mean(dd)

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np


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

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

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

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

    return result


n = int(input())
x = np.zeros(n, dtype=float)
y = np.zeros(n, dtype=float)
tempx = np.zeros(n, dtype=float)
tempy = np.zeros(n, dtype=float)

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

# tempx = np.concatenate(np.array(x[-1]), x)
# tempy = np.concatenate(np.array(y[-1]), y)

tempx[0] = x[-1]
tempx[1:] = x[: n - 1]
tempy[0] = y[-1]
tempy[1:] = y[: n - 1]

d = ((x - tempx) ** 2 + (y - tempy) ** 2) ** 0.5

tempd = np.zeros(n, dtype=float)
tempd[0] = d[-1]
tempd[1:] = d[: n - 1]

dd = d + tempd

# print(x, y, tempx, tempy, d)
ans = sum(dd) / cmb(n, n - 1)

print(ans)

Submission status: Wrong Answer

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

#必要な掛け算の数字を出す
k=math.factorial(N) #k通り
w=0
for i in range(0,N):
    w=w+(N-i)
#必要な数
t=k*(N-1)/N
#それぞれの辺の長さを総当たりで求めていく
p=0
q=0
for i in range(0,N):
    for j in range(i+1,N):
        p=(x[i][0]-x[j][0])**2+(x[i][1]-x[j][1])**2
        q=q+math.sqrt(p)
print(q*t/k)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x = [list(map(int,input().split())) for _ in range(N)]
zip_i = []
zip_j = []
t = math.factorial(N)
total=0

for i in range(N):
  for j in range(i+1,N):
    zip_i.append(i)
    zip_j.append(j)
for a,b in zip(zip_i,zip_j):
  dis = math.sqrt((x[a][0]-x[b][0])**2+(x[a][1]-x[b][1])**2)
  total += dis
  
ans = (t*total-(t//N)*total)/t
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
f_list=[[int(thing) for thing in input().split()] for i in range(N)]

def distance(f_1,f_2):
    return math.sqrt((f_1[0]-f_2[0])**2+(f_1[1]-f_2[1])**2)
l=[]
for i in range(N-1):
    for j in range(i+1,N):
        l.append(distance(f_list[i],f_list[j]))
print((N-1)*sum(l)/3)

Submission status: Wrong Answer

Solution code:

def vs(n):
    if n == 2:
        return 1+1
    else:
        return 1+1+ (n-2) * vs(n-1)
def be(n):
    if n ==1:
        return 1
    else:
        return n*be(n-1)

n = int(input())
xarr =[];yarr=[]
la = vs(n); b = be(n)
for i in range(n):
    x,y = map(int, input().split())
    xarr.append(x); yarr.append(y)
c=0
for i in range(n):
    for j in range(n)[i+1:]:
        x1 = (xarr[i] - xarr[j])**2
        y1 = (yarr[i] - yarr[j])**2
        l = (x1+y1)**(1/2)
        c += l * la
print(c/b)

Submission status: Wrong Answer

Solution code:

from sys import stdin
n = int(stdin.readline().rstrip())
dis = []
for i in range(n):
    l = list(map(int, stdin.readline().rstrip().split()))
    dis.append(l)

def dist(x1,y1,xn,yn):
    di = ((x1-xn)**2 + (y1-yn)**2)**0.5
    return di

total = 0
for i in range(n-1):
    for j in range(i+1,n):
        d = dist(dis[i][0],dis[i][1],dis[j][0],dis[j][1])
        total += d

# nの階乗
ns = 1
for i in range(1,n+1):
    ns *= i

# 辺の数
num = 0
for i in range(n-1):
    num += 1 + i
print(num)

ans = total * ((n-1)*ns)/num/ns

print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
#距離の箱を作成
kyori = []
kyori2 = []
kyori3 = []
sumation = 0
for i in range(N):
    #N回繰り返す
    kyori.append(list(map(int,input().split())))
#x間の距離、y間の距離を算出
#ここで、2→1と1→2などは同じ距離なので計算しない
x_distance = 0
y_distance = 0
for i in range(0,N):
    for j in range(i+1,N):
        x_distance = (kyori[i][0]-kyori[j][0])**2
        y_distance = (kyori[i][1]-kyori[j][1])**2
        #xとyの距離を計算(sqrt導出)
        Kyorixy = math.sqrt(x_distance + y_distance)
        kyori2.append(Kyorixy)
if len(kyori2) == 1:
    print(kyori2[0])
else:
    for i in range(0,len(kyori2)):
        for j in range(i+1,len(kyori2)):
            kyori3.append(kyori2[i]+kyori2[j])
    for i in range(len(kyori3)):
        sumation += kyori3[i]
    goukei = sumation*(2**(N-2))/math.factorial(N)
    print(goukei)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x = []
y = []
i = 0
t = 0
k = 0
s = 0
r = 1
while i != N:
    p,q = input().split()
    x.append(int(p))
    y.append(int(q))
    i += 1
while k != N:
    while k + r != N:
        s = math.sqrt((x[k] - x[k+r]) ** 2 + (y[k] - y[k+r]) ** 2)
        r += 1
    t += r
    r = 0
    k += 1
print(s / t)

Submission status: Wrong Answer

Solution code:
import math
import statistics
import itertools

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 m in itertools.permutations(range(n)):
    for i in range(n-1):
        ii = m[i]
        iii = m[i+1]
        dd.append(d(xl[ii], yl[ii], xl[iii], yl[iii]))
        
ans = statistics.mean(dd)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import sqrt
from copy import copy
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])


def f(l):
# =============================================================================
#     print(l)
# =============================================================================
    if len(l) == 2:
        
        return sqrt((l[0][0] - l[1][0])**2 + (l[0][1] - l[1][1])**2)*2
    else:
        c = 0
        for i in range(len(l)):
            k = copy(l)
            x = k[i][0]
            y = k[i][1]
            del k[i]
            for m in k:
                c += sqrt((x - m[0])**2 + (y - m[1])**2)
            
            c += f(k)
        return c


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

print(f(l) / fac(n))

Submission status: Wrong Answer

Solution code:
N=int(input())

x = []
y = []
for i in range(0,N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
def d(e,f,g,h):
  return ((g-e)**2+(h-f)**2)**(1/2)
sum=0
for i in range(0,N):
  for j in range(i+1,N):
    sum=sum+d(x[i],y[i],x[j],y[j])
import math
print((N+1)*sum/math.factorial(N))

Submission status: Wrong Answer

Solution code:
import math
import statistics
import itertools

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 m in itertools.permutations(range(n)):
    for i in range(n-1):
        dd.append(d(xl[i], yl[i], xl[i+1], yl[i+1]))
        
ans = statistics.mean(dd)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import sqrt
from copy import copy
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])


def f(l):
# =============================================================================
#     print(l)
# =============================================================================
    if len(l) == 2:
        
        return sqrt((l[0][0] - l[1][0])**2 + (l[0][1] - l[1][1])**2)*2
    else:
        c = 0
        for i in range(len(l)):
            k = copy(l)
            x = k[i][0]
            y = k[i][1]
            del k[i]
            print(k)
            for m in k:
                c += sqrt((x - m[0])**2 + (y - m[1])**2)
            
            c += f(k)
        return c


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

print(f(l) / fac(n))

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

s = 0
for j in range(N):
    for k in range(N):
        if (j!=k):
            s += ((x[j] - x[k])**2 + (y[j] - y[k])**2)**(1/2)
if N==2:
    a = s / math.factorial(N)
else:
    a = s*N*math.factorial(N-2)/math.factorial(N)
print(a)

Submission status: Wrong Answer

Solution code:
import itertools
import math

N = int(input())

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

P = list(itertools.permutations(XY,r = N))

area = 0

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

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
xy_list = []
#n = 3
#xy_list = [[0,0 ],[0 ,1],[1,0]]
for i in range(n):
  xy_list.append(list(map(int,input().split())))
counter = 0
for m in range(n-1):
  for l in range(m,n):
    x_l = xy_list[l][0]
    y_l = xy_list[l][1]
    x_m = xy_list[m][0]
    y_m = xy_list[m][1]
    counter += ((x_m - x_l)**2 + (y_m - y_l)**2)**0.5

if n == 2:
  print(counter)
else:
  num = n*(n-3)/2 + n
  print(counter/(num**2)*math.factorial(n))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
#距離の箱を作成
kyori = []
kyori2 = []
kyori3 = []
sumation = 0
for i in range(N):
    #N回繰り返す
    kyori.append(list(map(int,input().split())))
print(kyori)
#x間の距離、y間の距離を算出
#ここで、2→1と1→2などは同じ距離なので計算しない
x_distance = 0
y_distance = 0
for i in range(0,N):
    for j in range(i+1,N):
        x_distance = (kyori[i][0]-kyori[j][0])**2
        y_distance = (kyori[i][1]-kyori[j][1])**2
        #xとyの距離を計算(sqrt導出)
        Kyorixy = math.sqrt(x_distance + y_distance)
        kyori2.append(Kyorixy)
print(kyori2)
if len(kyori2) == 1:
    print(kyori2[0])
else:
    for i in range(0,N):
        for j in range(i+1,N):
            kyori3.append(kyori2[i]+kyori2[j])
    for i in range(len(kyori3)):
        sumation += kyori3[i]
    print(sumation)
    goukei = sumation*(2**(N-2))/math.factorial(N)
    print(goukei)

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
a=[0]*N
b=[0]*N
s=0
for i in range(N):
    a[i], b[i] = map(int, input().split())
for i in range(N):
  for j in range(N):
    vec=[a[i]-a[j], b[i]-b[j]]
    s+=np.sqrt(np.linalg.norm(vec))
print(s/N)

Submission status: Wrong Answer

Solution code:
import itertools
import math

N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())
    
if N == 2:
    d = math.sqrt((x[0]-x[1]) ** 2 + (y[0]-y[1]) ** 2)
    print(d)
else:
  index = list(itertools.combinations(range(N), (N-1)))
  d_list = []
  for i in index:
    d_list.append(math.sqrt((x[i[0]]-x[i[1]]) ** 2 + (y[i[0]]-y[i[1]]) ** 2))
  
  SUM = 0

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

  for d in d_list:
    tmp = d * tmp_num
    SUM += tmp
  print(SUM / math.factorial(N))

Submission status: Wrong Answer

Solution code:
import math

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

m = 0
for list_i in list_1:
    for list_j in list_1:
        if list_i != list_j:
            d = math.sqrt((list_j[0]-list_i[0])**2 + (list_j[1]-list_i[1])**2)
            m += d

average = m * N

print(average)

Submission status: Wrong Answer

Solution code:
from math import hypot
import sys as sy
import math

a=int(input())
pts = []
for i in range(a):
    x,y=map(int,sy.stdin.readline().split())
    pts.append((x,y))


ptdiff = lambda p1, p2: (p1[0]-p2[0], p1[1]-p2[1])

diffs = (ptdiff(p1, p2) for p1, p2 in zip (pts, pts[1:]))
path = sum(hypot(*d) for d in  diffs)
sd=math.factorial(23)
print((sd*path)/sd)

Submission status: Wrong Answer

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

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

A = list(itertools.permutations(A))
print(A)
sum = 0

for i in A:
    for j in range(N):
        if j+1==N:
            break
        sum = sum + (((i[j][0]-i[j+1][0])**2+(i[j][1]-i[j+1][1])**2)**0.5).real

    #sum = sum + ((i[0][0]-i[1][0])**2+(i[0][1]-i[1][1]**2))**0.5+((i[1][0]-i[2][0])**2+(i[1][1]-i[2][1]**2))**0.5

print((sum/math.factorial(N)).real)

Submission status: Wrong Answer

Solution code:
import numpy, itertools

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

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

total = 0
for p1, p2 in itertools.combinations(points,2):
    print(p1, p2)
    q1 = numpy.array(p1)
    q2 = numpy.array(p2)
    total += numpy.linalg.norm(q1 - q2)

print(total * 2.0 / N)

Submission status: Wrong Answer

Solution code:
import math
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
x = [list(map(int, input().split())) for _ in range(N)]
nlst = '01234567'
xlst = []
a = [-1] * N
def dfs(cnt):
    if cnt == N:
        if a[0] != 0:
            return

        tmpF = True
        for i in range(N):
            if a.count(int(nlst[i])) != 1:
                tmpF = False
                break
        if tmpF:
            tlst = []
            for i in a:
                tlst.append(i)
            xlst.append(tlst)
        return

    for i in range(N):
        a[cnt] = i
        dfs(cnt + 1)

dfs(0)

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

print(xlst)

Submission status: Wrong Answer

Solution code:
import itertools,math,statistics
N = int(input())
town = []
for p in range(N):
    q = list(map(int, input().split()))
    town.append(q)
perm = itertools.permutations(town)
print()
c = []
for i in list(perm):
    b = 0
    for j in range(N-1):
        a = math.sqrt((i[j][0]-i[j+1][0])**2 + (i[j][1]-i[j+1][1])**2)
        b += a
    c.append(b)
print(statistics.mean(c))

Submission status: Wrong Answer

Solution code:
n = int(input())
xy_list = []
#n = 3
#xy_list = [[0,0 ],[0 ,1],[1,0]]
for i in range(n):
  xy_list.append(list(map(int,input().split())))
counter = 0
for m in range(n-1):
  for l in range(m,n):
    x_l = xy_list[l][0]
    y_l = xy_list[l][1]
    x_m = xy_list[m][0]
    y_m = xy_list[m][1]
    counter += ((x_m - x_l)**2 + (y_m - y_l)**2)**0.5

if n == 2:
  print(counter)
else:
  num = n*(n-3)/2 + n
  print(counter/num*2)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math


N = int(stdin.readline().rstrip())
X = []
Y = []
for el in range(N):
    tmp = [int(s) for s in stdin.readline().rstrip().split()]
    X.append(tmp[0])
    Y.append(tmp[1])

patt = math.factorial(N) / 2
noUseRootNum = patt-math.factorial(N-1)
diss = []
for k in range(N):
    for l in range(N):
        if (k >= l):
            continue
        diss.append(((X[k]-X[l])**2+(Y[k]-Y[l])**2)**0.5)
print(diss)


res = 0
for el in diss:
    res += el*(patt - noUseRootNum)
print(res/patt)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
l=list()
for _ in range(n):
  a,b=map(int,input().split())
  l.append([a,b])
su=0
for i in range(n):
  for j in range(n):
    if i!=j:
      su+=math.sqrt((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)
su=su*2
print(su/math.factorial(n))

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

ans = 0

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


print(ans * 2 / N)

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

d=0

for i in range(N):
  c=i+1
  for j in range(c,N):
    d+=((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
a=math.factorial(N)
print(d*2*(N-1)/a)

Submission status: Wrong Answer

Solution code:
import math

def distance(a, b, c, d):
    return math.sqrt(((a - b) ** 2) + ((c - d) ** 2))

N = int(input())

xy = []
for i in range(N):
    tmp = list(map(int, input().split()))
    xy.append(tmp)
    
sum_dis = 0
dis_list = []
for i in range(N-1):
    for j in range(i+1, N):
        dis_list.append(distance(xy[i][0], xy[j][0], xy[i][1], xy[j][1]))



print(dis_list)
print(sum(dis_list) * (math.factorial(N-1)*2) / (math.factorial(N)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from math import hypot
import sys as sy

a=int(input())
pts = []
for i in range(a):
    x,y=map(int,sy.stdin.readline().split())
    pts.append((x,y))


ptdiff = lambda p1, p2: (p1[0]-p2[0], p1[1]-p2[1])

diffs = (ptdiff(p1, p2) for p1, p2 in zip (pts, pts[1:]))
path = sum(hypot(*d) for d in  diffs)
print(path)

Submission status: Wrong Answer

Solution code:
import math
import itertools
n = int(input())
x = [0]*n
y = [0]*n
for i in range(n):
    x[i],y[i] = [int(j) for j in input().split()]
# print(n,x,y)
dict = {}
for i in range(n):
    for j in range(n):
        if i < j:
            dict[str(i)+str(j)] = math.sqrt((x[i] - x[j])**2 + (y[i]- y[j])**2)

# print(dict)
# perm = [n for n in range(n)]
# print(perm)
sumation = 0
# print(len([v for v in itertools.permutations(perm,n)]))
# for p for perm:
#     for i in p: #それぞれのまち
#         if i == 0:
#             continue
#         else:
#             sum
list = [v for v in dict.values()]
# print(type(list))
sumation = sum(list)
# print(sumation)
sumation = sumation * math.factorial(n)
# print(sumation)
for kei, length in dict.items():
    if n != 2:
        sumation -= length*2*math.factorial(n-2)
    else:
        continue
# print(sumation)
print(sumation/math.factorial(n))

Submission status: Wrong Answer

Solution code:
import math

print(math.factorial(5))

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

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

for j in range(N):
    for k in range(N):
        if (j!=k):
            s += ((x[j] - x[k])**2 + (y[j] - y[k])**2)**(1/2)
if N==2:
    a = s / math.factorial(N)
else:
    a = s*2*math.factorial(N-2)/math.factorial(N)
print(a)

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

import numpy as np

d=[0]*N

a=np.array([x[N-1], y[N-1]])
b=np.array([x[0], y[0]])
u=b-a
d[N-1]=np.linalg.norm(u)

for i in range(N-1):
  a=np.array([x[i], y[i]])
  b=np.array([x[i+1], y[i+1]])
  u=b-a
  d[i]=np.linalg.norm(u)

ans=(sum(d)*(N-1))/N
print(ans)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
coordinate_list = [input().split() for i in range(N)] 

distance_list = []

for i, one_coordinate in enumerate(coordinate_list[:len(coordinate_list)]):
    mini_distance_list = []
    for another_cordinate in coordinate_list[i+1:]:
        distance = math.sqrt((int(one_coordinate[0]) - int(another_cordinate[0])) ** 2 + (int(one_coordinate[1]) - int(another_cordinate[1])) ** 2)
        distance_list.append(distance)
        #mini_distance_list.append(distance)
    #distance_list.append(mini_distance_list)

distance_list = [n*(2**(N-1)) for n in distance_list]

print(sum(distance_list)/math.factorial(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:
    print(dis)
    dis = dis * 2 / N
    print(dis)

Submission status: Wrong Answer

Solution code:
import math
import itertools

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

l = list(range(1,N+1))

kai_list = list(itertools.permutations(l))

result = 0
count = 0

for item_i in kai_list:
    print(item_i)
    for i in range(1,len(item_i)):
        result += math.sqrt((X[item_i[0]-1] - X[item_i[i]-1])**2 + (Y[item_i[0]-1] - Y[item_i[i]-1])**2)

count = len(kai_list)
print(result/count)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

xy_dict = {}
tmp =[0]
for i in range(N):
    x, y = map(float, input().split())
    #print(x)
    #print(y)

    xy_dict[i] = (x,y)
print(xy_dict)
print(xy_dict[0][0])
print(xy_dict[0][1])

distance_list = []

for i in range(N):
    for j in range(i+1, N):
        x1 = xy_dict[i][0]
        y1 = xy_dict[i][1]
        x2 = xy_dict[j][0]
        y2 = xy_dict[j][1]
        a = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
        distance_list.append(a)
        #print("i,j is ", i,j)

sum = 0
for i in range(len(distance_list)):
    sum += distance_list[i]
        
print(math.factorial(N-1) * 2* sum/(math.factorial(N)))

Submission status: Wrong Answer

Solution code:
# 2019 11/16
# ABC 145 C Average Length
# A-Bと通るのがNのとき全体で 1 + (N - 2) ^ 2 回
# B-A も考えると2倍

import numpy as np

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

bunbo = 1

for i in range(N):
    bunbo *= i

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

point = np.array(point)

sum = 0

for i in range(N):
    for j in range(i+1, N):
        tmp = np.square(point[i, 0] - point[j, 0]) \
              + np.square(point[i, 1] - point[j, 1])
        sum = sum + np.sqrt(tmp)

ave = (sum * 2 * (1 + np.square(N-2))) / bunbo

print(ave)

Submission status: Wrong Answer

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

print("2.2761423749")

Submission status: Wrong Answer

Solution code:
class Pos:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def cal_distance(self, pos):
        return ((self.x - pos.x)**2 + (self.y - pos.y)**2)**0.5


N = int(input())
data = [input() for _ in range(N)]

pos_list = []
for d in data:
    x,y = map(int, d.split())
    pos = Pos(x, y)
    pos_list.append(pos)

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

result_list = []
for i in pos_list:
    for j in pos_list:
        if i is j:
            continue
        distance = i.cal_distance(j)
        result_list.append(distance)

average = sum(result_list) / (permuaion/(N-1))
print(average)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import numpy as np

n = int(input())

ls = []

for i in range(n):
    ls.append(list(map(int,input().split())))
    
ts = np.array([[0.0] * n for i in range(n)])

for i in range(n):
    for j in range(i+1,n):
        ts[i][j] = np.sqrt(pow(ls[i][0]-ls[j][0],2)+pow(ls[i][1]-ls[j][1],2))
        
        
def calcmo(n):
    rt = 0
    if(n == 2):
        return 2
    else:
        return calcmo(n-1) + (n*n-n)/2

def factional(n):
    if(n == 1):
        return 1
    else:
        return n * factional(n-1)
#print(ts)
#print(ts.sum())
print(ts.sum() * calcmo(n) / factional(n))