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())
p = [list(map(int, input().split())) for _ in range(N)]
table = [[0] * N for _ in range(N)]
for i in range(N-1):
  for j in range(i+1, N):
    table[i][j] = table[j][i] = ((p[i][0] - p[j][0]) ** 2 + (p[i][1] - p[j][1]) ** 2) ** 0.5

dist = 0
flag = [False] * N
def rec(p1, ans):
  for i in range(N):
    if not flag[i]:
      flag[i] = True
      ans.append(table[p1][i])
      rec(i, ans)
      flag[i] = False
  
ans = []
for i in range(N):
  flag[i] = True
  rec(i, ans)
  flag[i] = False 
import math
print(sum(ans)/(math.factorial(N)))

Submission status: Wrong Answer

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

dist = 0
flag = [False] * N
def rec(p1, ans):
  for i in range(N):
    if not flag[i]:
      flag[i] = True
      ans.append(table[p1][i])
      rec(i, ans)
      flag[i] = False
  
ans = []
for i in range(N):
  flag[i] = True
  rec(i, ans)
  flag[i] = False 
import math
print(sum(ans), math.factorial(N), sum(ans)/(math.factorial(N)))

Submission status: Wrong Answer

Solution code:
import itertools

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()

A = [tuple(int(i) for i in input().split()) for _ in range(n)]

memo = [[-1]*n for i in range(n)]
keiro_sum = 0

cnt = 0
print(A)
for i in itertools.permutations(range(n)):
    cnt += 1
    one_root = 0
    for j in range(1,n):
        if(memo[i[j-1]][i[j]] == -1):
            distance = ((A[i[j]][0] - A[i[j-1]][0])**2 + (A[i[j]][1] - A[i[j-1]][1])**2)**0.5
            memo[i[j]][i[j-1]] = distance
            memo[i[j-1]][i[j]] = distance
        else:
            distance = memo[i[j-1]][i[j]]
        one_root += distance

    keiro_sum += one_root

print(keiro_sum/cnt)

Submission status: Wrong Answer

Solution code:
import itertools

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

fact = [1] * (N + 1)
for i in range(1, N + 1):
    fact[i] = fact[i-1] * i


def L2norm(i, j):
    X = XY[i][0] - XY[j][0]
    Y = XY[i][1] - XY[j][1]
    return (X**2 + Y**2) ** (1/2)


dist = [[0] * N for i in range(N)]
for i in range(N):
    for j in range(i, N):
        r = L2norm(i, j)
        dist[i][j] = r
        dist[j][i] = r

ans = 0
stock = 0
for perm in itertools.permutations(range(N), N):
    cur = 0
    for i in range(N-1):
        cur += dist[perm[i]][perm[i+1]]
    stock += cur

    if stock >= fact[N]:
        ans += stock/fact[N]
        stock = 0

print(ans)

Submission status: Wrong Answer

Solution code:
#abc129 c
import math
import itertools
n=int(input())
zahyo=[]
for i in range(n):
    line=list(map(int,input().split()))
    zahyo.append(line)
num=[i for i in range(n)]
patarn=list(itertools.permutations(num))
print(patarn)

def kyori(xy1,xy2):
    x1,y1=xy1
    x2,y2=xy2
    s=math.sqrt((x1-x2)**2+(y1-y2)**2)
    return s
ans=0
for i in patarn:
    s=0
    for j in range(n-1):
        s+=kyori(zahyo[i[j]],zahyo[i[j+1]])
    ans+=s
ans/=len(patarn)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import sqrt
input = sys.stdin.readline
N = int(input())
x = 0
y = 0
ps = []
for _ in range(N): 
  u, v = map(int, input().split())
  x += u
  y += v
  ps.append((u, v))

x /= N
y /= N
res = 0
for p in ps:
  u, v = p
  res += sqrt((x - u) ** 2 + (y - v) ** 2)
print(res)

Submission status: Wrong Answer

Solution code:
import itertools
import math

N = int(input())
xy  = [[int(i) for i in input().split()] for j in range(N)]
distance = [[0 for j in range(N)] for i in range(N)]
for i in range(N):
    for j in range(N):
        xi = xy[i][0]
        yi = xy[i][1]
        xj = xy[j][0]
        yj = xy[j][1]
        d = math.sqrt((xi-xj)**2+(yi-yj)**2)
        distance[i][j] = d
        distance[j][i] = d

print(sum([sum(i) for i in distance])*2/N)

Submission status: Wrong Answer

Solution code:
import itertools
import math

N = int(input())
xy  = [[int(i) for i in input().split()] for j in range(N)]
distance = [[0 for j in range(N)] for i in range(N)]
for i in range(N):
    for j in range(N):
        xi = xy[i][0]
        yi = xy[i][1]
        xj = xy[j][0]
        yj = xy[j][1]
        d = math.sqrt((xi-xj)**2+(yi-yj)**2)
        distance[i][j] = d
        distance[j][i] = d

print(sum([sum(i) for i in distance])*(N-1)/math.factorial(N))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [list(map(int,input().split())) for i in range(n)]
from itertools import permutations
def distance(s):
    res = 0
    for i in range(n-1):
        res += ((s[i][0]-s[i+1][0])**2 + (s[i][1]-s[i+1][1])**2)**0.5
    return res
k = 0
for key in list(permutations(s,n)):
    k += distance(key)
fin_res = format(k/(n*2),'.10f')
print(fin_res)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
permu_list = itertools.permutations(range(N))
ans=0
c = 0
for p in permu_list:
  c += 1
  for i in range(1,N):
    ans += ((A[i-1][0]-A[i][0])**2+(A[i-1][1]-A[i][1])**2)**0.5
print(ans/c)

Submission status: Wrong Answer

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

for i in range(n):
    z.append(list(map(int, input().split())))
    x.append(z[i][0])
    y.append(z[i][1])

D = 0
for i in range(n):
    for j in range(n):
        if i < j:
            continue
        D += math.sqrt((x[i]-x[j])**2 + (y[i] - y[j])**2)

print(D*(n-1)/n)

Submission status: Wrong Answer

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(input())


inputDataList = []
data = []
for i in range(n):
    inputData = input().split()
    inputDataList = [int(n) for n in inputData]
    data.append(inputDataList)

mat = [[-1 for i in range(n)] for j in range(n)] #二次元の静的確保


def calc_dis(x1, x2, y1, y2):
    dis = pow(x1 - x2, 2) + pow(y1 - y2, 2)
    dis = math.sqrt(dis)
    return dis


def path_dis(path):
    dis = 0
    for i in range(len(path)-1):
        dis += mat[path[i]][path[i+1]]
    return dis

for i in range(n):
    for j in range(n):
        mat[i][j] = calc_dis(data[i][0], data[i][1], data[j][0], data[j][1])

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

ans = 0
for p in perm:
    tmp_ans = path_dis(p)
    ans += tmp_ans

ans = ans/len(perm)
print(ans)

Submission status: Wrong Answer

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


def dfs(visited, x, y, prev, dis):
    n = len(x)
    allCityVisited = True
    for i in range(n):
        if visited[i] is False:
            allCityVisited = False
    if allCityVisited:
        return dis

    for i in range(n):
        if visited[i] is False:
            dis += distance(x[i], y[i], x[prev], y[prev])
            visited[i] = True
            org_prev = prev
            prev = i
            dis = dfs(visited, x, y, prev, dis)
            visited[i] = False
            prev = org_prev

    return dis


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

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

visited = [False] * n

dis = 0

for i in range(n):
    visited[i] = True
    dis = dfs(visited, x, y, i, dis)
    visited[i] = False

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

print(dis / perm)

Submission status: Wrong Answer

Solution code:
import math


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


def dfs(visited, x, y, prev, dis, total_dis):
    n = len(x)
    allCityVisited = True
    for i in range(n):
        if visited[i] is False:
            allCityVisited = False
    if allCityVisited:
        total_dis += dis
        return total_dis

    for i in range(n):
        if visited[i] is False:
            dis += distance(x[i], y[i], x[prev], y[prev])
            visited[i] = True
            org_prev = prev
            prev = i
            total_dis = dfs(visited, x, y, prev, dis, total_dis)
            visited[i] = False
            prev = org_prev

    return total_dis


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

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

visited = [False] * n
total_dis = 0

for i in range(n):
    visited[i] = True
    total_dis += dfs(visited, x, y, i, 0, 0)
    visited[i] = False

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

print(total_dis / perm)

Submission status: Wrong Answer

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

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

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

ans = 0

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        print ("i="+str(i)+", j="+str(j))
        print ("xi="+str(x[i])+", xj="+str(x[j]))
        print ("yi="+str(y[i])+", yj="+str(y[j]))
        ans += math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)

ans = ans / N
print (ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = []
for i in range(N):
    a, b = (int(x) for x in input().split())
    xy.append([a, b])
    
def distance(d, xy, i, j):
    return (
              (xy[i][0] - xy[j][0]) ** 2
            + (xy[i][1] - xy[j][1]) ** 2
        ) ** 0.5

import itertools
d = []
l1 = [x for x in range(N)]
for v in itertools.permutations(l1, N):
    l2 = list(v)
    d0 = []
    r = 2 if N != 2 else 1
    for c in range(r):
        i = l2[c]
        j = l2[c+1]
        d0.append(distance(d, xy, i, j))
    d.append(sum(d0))

print(sum(d) / len(d))

Submission status: Wrong Answer

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

perm_towns = list(itertools.permutations(towns))
sum_length = 0
for i in range(len(perm_towns)//2):
    for j in range(n-1):
        length = ((perm_towns[i][j][0]-perm_towns[i][j+1][0]) **2 + (perm_towns[i][j][1] - perm_towns[i][j+1][1]) **2) **0.5
        sum_length += length 

ans = sum_length / (len(perm_towns)//2)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import math 
import sys

N = int(input())
coordList = []
permList = []
distList = []
distance = 0

for i in range(N):
  x = input().split()
  coordList.append(x)

permList = list(itertools.permutations(coordList))

for perm in range(len(permList)):
  xList = []
  yList = []
  print('Reset values!')
  for coord in range(len(permList[perm])):
    for num in range(len(permList[perm][coord])):
      if len(xList) != N and num + 1 < 2:
        xList.append(int(permList[perm][coord][num]))
        print(xList)
      if len(yList) != N and num + 1 < 2:
        yList.append(int(permList[perm][coord][num + 1]))
        print(yList)
      elif len(xList) and len(yList) == N: 
        for i in range(N):
          if i + 1 < N: 
            dist = math.sqrt(((xList[i] - xList[i+1]) ** 2) + ((yList[i] - yList[i+1]) ** 2))
            distList.append(dist)

for i in range(len(distList)):
  distance += distList[i]

print(distance / math.factorial(N))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
import math

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

nums = [_ for _ in range(n)]
total = 0
for v in itertools.permutations(nums, n):
    dist = 0
    for i in range(n-1):
        dist += math.sqrt((dots[i][0] - dots[i+1][0]) **
                          2 + (dots[i][1] - dots[i+1][1])**2)
    total += dist

print(total/math.factorial(n))

Submission status: Wrong Answer

Solution code:
import itertools


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

sum_dist = 0
num_pattern = 0

for pattern in itertools.permutations([i for i in range(n)], n):
    print(pattern)
    for i in range(1, n):
        x, y = geo[pattern[i]]
        x_prev, y_prev = geo[pattern[i-1]]
        d = ((x-x_prev) ** 2 + (y-y_prev) ** 2) ** 0.5
        sum_dist += d
    num_pattern += 1

print(sum_dist / num_pattern)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import sqrt

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)

pattern = 1
for i in range(N):
    if (N < i+1):
        break
    pattern = pattern * (i+1)
# print (pattern)

sum = 0
for i in range(N):
    for j in range(N):
        if i != j:
            sum = sum + sqrt( (x[i] - x[j])*(x[i] - x[j])+(y[i] - y[j])*(y[i] - y[j]) )

print (sum/pattern)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#n個の都市を好きな都市から出発してすべての都市を１度だけ訪れる最短時間
#全ての都市の組i,jについてi,jを結ぶ道がある

import itertools
n=int(input())
A=[]
for i in range(n):
  A.append(list(map(int,input().split())))
  
def kaijo(x):
  if x==1:
    return x
  return x*kaijo(x-1)

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

DIST=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
  for j in range(n):
    DIST[i][j]=dist(i,j)
    
ans=[]   
for Q in itertools.permutations([i for i in range(n)]):
  t=0
  for i in range(n-1):
    t+=DIST[Q[i]][Q[i+1]]
  ans.append(t)
  print(Q)
print(sum(ans)/kaijo(n))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
k = 0
total = 0
while k != N-1:
    for i in range(k, N-1):
        total += ((xy[i][0] - xy[i+1][0])**2 + (xy[i][1]-xy[i+1][1])**2)**(1/2)
    k += 1
total = total * 2
print(total/N)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
k = 0
total = 0
while k != N-1:
    for i in range(k, N-1):
        total += ((xy[i][0] - xy[i+1][0])**2 + (xy[i][1]-xy[i+1][1])**2)** 0.5
    k += 1
total = total * math.factorial(N-1)*2
print(total/math.factorial(N))

Submission status: Wrong Answer

Solution code:
N = int(input())
XY = [[0]*2]*N
dis = 0
for i in range(N):
  XY[i] = [int(_) for _ in input().split()]
for i in range(N):
  Xi = XY[i][0]
  Yi = XY[i][1]
  for j in range(i+1,N):
    Xj = XY[j][0]
    Yj = XY[j][1]
    dis += ((Xi-Xj)**2 + (Yi-Yj)**2)**0.5/N

print(dis)

Submission status: Wrong Answer

Solution code:
N = int(input())
XY = [[0]*2]*N
dis = 0
for i in range(N):
  XY[i] = [int(_) for _ in input().split()]
for i in range(N):
  Xi = XY[i][0]
  Yi = XY[i][1]
  for j in range(i+1,N):
    Xj = XY[j][0]
    Yj = XY[j][1]
    dis += ((Xi-Xj)**2 + (Yi-Yj)**2)**0.5
_N = 1
for n in range(N,0,-1):
  _N *= n
print(dis/_N)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans=0
XY=[]
for i in range(N):
    X,Y = list(map(int,input().split()))
    print(XY)
    for xy in XY:
        ans += ((xy[0]-X)**2+(xy[1]-Y)**2)**0.5
        print(xy[0],xy[1])
    XY.append((X,Y))
print(ans*2/N)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
N=int(input())
L=[list(map(int,input().split())) for _ in range(N)]
L=np.array(L)

for p in itertools.permutations(L):

    path_length = 0
    for (x1,y1), (x2,y2) in zip(p, p[1:]):
        path_length += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** .5
print(path_length)

Submission status: Wrong Answer

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

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

# 順列計算
for i in range(n-1):
    for j in range(i+1, n):
        distance = math.sqrt((coord_list[i][0] - coord_list[j][0]) ** 2 + (coord_list[i][1] - coord_list[j][1]) ** 2)      
        all_distances += distance
        print("i:{}, j:{} distance:{}".format(i, j, distance))

print(all_distances * 2 / n)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
coord_list = [list(map(int, input().split())) for _ in range(n)]
all_distances = 0

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# 順列計算
for i in range(n-1):
    for j in range(i+1, n):
        distance = math.sqrt((coord_list[i][0] - coord_list[j][0]) ** 2 + (coord_list[i][1] - coord_list[j][1]) ** 2)      
        all_distances += distance
        print("i:{}, j:{} distance:{}".format(i, j, distance))

print(all_distances * 2 / n)

Submission status: Wrong Answer

Solution code:
N = int(input())
town = [None]*N

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

avr_temp = 0
for i in range(N):
    for j in range(i+1, N):
        #町iから町jまでの距離を求める。
        avr_temp += ((town[i][0]-town[j][0])**2+(town[i][1]-town[j][1])**2)**0.5
avr = avr_temp * 2 / N

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
XY = tuple(tuple(map(int, input().split())) for _ in range(N))
kumi = tuple(itertools.permutations(XY, N))
ans = 0
def f(xi, yi, xj, yj):
    return ((xi - xj) ** 2 + (yi - yj) ** 2) ** 0.5

for i in kumi:
    for j in range(N-1):
        xi, yi = i[j]
        xj, yj = i[j+1]
        ans += f(xi, yi, xj, yj)
print(ans/N/2)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
c = [list(map(int, input().split())) for i in range(n)]
#print(d)
# 方針1:足しながら随時平均を出していく
# 方針2:法則もとい漸化式的なものを見つける
def euc_dist(c1, c2):
  x1, y1 = c1
  x2, y2 = c2
  return round(math.sqrt((x1 - x2)**2 + (y1 - y2)**2), 10)
def dcount(m):
  if m<2: return 0
  elif m==2: return 1
  else: return dcount(m-1) + m-1

d = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
  for j in range(n):
    if i==j: d[i][j] = 0
    else: d[i][j] = euc_dist(c[i], c[j])
#print(d)

sum = 0
for i in range(n):
  for j in range(n):
    sum += d[i][j]
avg = (math.factorial(n-1) * sum) / n
print(avg)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
c = [list(map(int, input().split())) for i in range(n)]
#print(d)
# 方針1:足しながら随時平均を出していく
# 方針2:法則もとい漸化式的なものを見つける
def euc_dist(c1, c2):
  x1, y1 = c1
  x2, y2 = c2
  return round(math.sqrt((x1 - x2)**2 + (y1 - y2)**2), 2)
def dcount(m):
  if m<2: return 0
  elif m==2: return 1
  else: return dcount(m-1) + m-1

d = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
  for j in range(n):
    if i==j: d[i][j] = 0
    else: d[i][j] = euc_dist(c[i], c[j])
#print(d)

sum = 0
for i in range(n):
  for j in range(n):
    sum += d[i][j]
avg = math.factorial(n-1) * sum / n
print(avg)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
xy = [[int(x) for x in input().split()] for i in range(N)]
ans = 0
count = 0
for city in itertools.permutations(xy,2):
  ans += ((city[0][0]-city[1][0])**2 + (city[0][1]-city[1][1])**2)**0.5
  count += 1
  print(count)
print(ans/N)

Submission status: Wrong Answer

Solution code:
from math import sqrt
from itertools import permutations
N = int(input())
roots = permutations(range(N))
points = [[int(i) for i in input().split()] for _ in range(N)]


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


distance_sum = 0
for i, root in enumerate(roots):
    _d = 0
    for i in range(1, N):
        prev = root[i-1]
        current = root[i]
        _d += calc_distance(points[prev], points[current])
    distance_sum += _d
print(distance_sum / (i+1))

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

for i in range(N):
    for j in range(N):
        if i != j:
            dx = x[i]-x[j]
            dy = y[i]-y[j]
            sum += math.sqrt(dx*dx + dy*dy)
        else:
            continue
    
ave = sum*2/math.factorial(N)

print(ave)

Submission status: Wrong Answer

Solution code:
import math
import itertools

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

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

    lengths = []
    for root in itertools.permutations(lst):
        sum_length = 0
        for index in range(N-1):
            i, j = root[index], root[index+1]
            sum_length = length(i, j)
        lengths.append(sum_length)
    print(sum(lengths) / len(lengths))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
dis_list = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for x1,y1 in dis_list:
    print(x1,y1)
    for x2,y2 in dis_list:
        print(x2,y2)
        ans += ((x1-x2)**2 + (y1-y2)**2)**0.5
print(ans/N)

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
e = [[int(i) for i in input().split()] for i in range(n)] 
c=0

for i in range(n):
    for j in range(n):
        if i!=j:
            c+=math.sqrt((e[i][0]-e[j][0])**2+(e[i][1]-e[j][1])**2)
        print(c)
print(c/n)

Submission status: Wrong Answer

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

import itertools
import math
comb = list(itertools.permutations(xy_list))
ans = 0
for s in comb:
    #print(ans)
    for zyun in range(len(s)-1):
        ans += math.sqrt((s[zyun][0] - s[zyun+1][0])**2 + (s[zyun][1] - s[zyun+1][1])**2)
print(round(ans/len(comb)/(len(s)-1), 12))

Submission status: Wrong Answer

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

import itertools
import math
comb = list(itertools.permutations(xy_list))
ans = 0
for s in comb:
    #print(ans)
    for zyun in range(len(s)-1):
        ans += math.sqrt((s[zyun][0] - s[zyun+1][0])**2 + (s[zyun][1] - s[zyun+1][1])**2)
print(round(ans/n/(len(s)-1), 12))

Submission status: Wrong Answer

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

import itertools
import math
comb = list(itertools.permutations(xy_list))
ans = 0
for s in comb:
    #print(ans)
    for zyun in range(len(s)-1):
        ans += math.sqrt((s[zyun][0] - s[zyun+1][0])**2 + (s[zyun][1] - s[zyun+1][1])**2)
print(round(ans/n/(len(s)-1), 7))

Submission status: Wrong Answer

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

import itertools
import math
comb = list(itertools.permutations(xy_list))
ans = 0
for s in comb:
    #print(ans)
    for zyun in range(len(s)-1):
        ans += math.sqrt((s[zyun][0] - s[zyun+1][0])**2 + (s[zyun][1] - s[zyun+1][1])**2)
print(round(ans/n/(len(s)-1), 6))

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
x=[]
for i in range(n):
	X=list(map(int,input().split()))
	x.append(X)
x=np.array(x)
ans=0
for i in range(n):
	for j in range(i+1,n):
		d=np.linalg.norm(x[i]-x[j]) #ベクトルの距離を計算
		ans+=d
#nc2=n*(n-1)/2
print('{:.8f}'.format(ans*2/(n*(n-1))))

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
x=[]
for i in range(n):
	X=list(map(int,input().split()))
	x.append(X)
x=np.array(x)
ans=0
for i in range(n):
	for j in range(i+1,n):
		d=np.linalg.norm(x[i]-x[j]) #ベクトルの距離を計算
		ans+=d
nc2=n*(n-1)/2
print('{:.8f}'.format(ans/nc2)) #桁数設定

Submission status: Wrong Answer

Solution code:
import sys
import math

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

    print(xy)

    sqs=[]
    for i in range(0,len(xy)):
        for j in range(i+1,len(xy)):
            sqs.append(math.sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2))

    print(sum(sqs) * 2 / N)


main()

Submission status: Wrong Answer

Solution code:
import math

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

a = 2
b = 0
while a < n:
  b += 2*math.factorial(n-a)
  a+=1
else:
  b+=2

print(d*b/math.factorial(n))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [0] * N
b = [0] * N

Ans = 0

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

for i in range(N):
    for k in range(1, N-i):
        Ans += ((a[i]-a[i+k])**2 +(b[i]-b[i+k])**2)**0.5 

print(Ans*(N-1)/N)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [0] * N
b = [0] * N

Ans = 0

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

for i in range(N):
    for k in range(1, N-i):
        Ans += ((a[i]-a[i+k])**2 +(b[i]-b[i+k])**2)**0.5 
        print(i,i+k)

print(Ans*(N-1)/N)

Submission status: Wrong Answer

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

seq=[i for i in range(N)]
kumi=list(itertools.permutations(seq))
L_sum=0
for i in range(len(kumi)):
    for j in range(N-1):
        L_sum+=math.sqrt((T[kumi[i][j]-1][0]-T[kumi[i][j+1]-1][0])**2+(T[kumi[i][j]-1][1]-T[kumi[i][j+1]-1][1])**2)
        #print(kumi[i][j],kumi[i][j+1])
        #,T[kumi[i][j+1]-1][0],T[kumi[i][j]-1][1],T[kumi[i][j+1]-1][1])
num=1
for i in range(N):
    num+=i

#print(L_sum)
print(L_sum/num)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

cities = []
for i in range(n):
  cities.append(tuple(map(int, input().split())))
  
score = 0
for i in range(n-1):
  city1 = cities[i]
  for j in range(i+1, n):
    city2 = cities[j]
    distance = math.sqrt(
      (city1[0] - city2[0]) ** 2 + \
      (city1[1] - city2[1]) ** 2)
    score += distance
    
print(distance / (n - 1))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

cities = []
for i in range(n):
  cities.append(tuple(map(int, input().split())))
  
score = 0
for i in range(n-1):
  city1 = cities[i]
  for j in range(i+1, n):
    city2 = cities[j]
    distance = math.sqrt(
      (city1[0] - city2[0]) ** 2 + \
      (city1[1] - city2[1]) ** 2)
    score += distance
    
print(distance / n)