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())
arr = []
for i in range(n):
	arr.append(list(map(int,input().split())))

def cul(a,b,c,d):
	rtmp = ((a-b)**2 + (c-d)**2)**0.5
	return rtmp
	
all = cul(arr[0][0],arr[-1][0],arr[0][1],arr[-1][1])

for i in range(n-1):
	all += cul(arr[i][0],arr[i+1][0],arr[i][1],arr[i+1][1])

part = 0

for j in range(n-1):
	for k in range(n-j):
		part += cul(arr[j][0],arr[j+k][0],arr[j][1],arr[j+k][1])

def cul2(e):
	tp=1
	for l in range(1,e):
		tp *= l
	return tp
		
ans = (all /n )
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
n=int(input())
s=[]
for i in range(n):
    s.append(list(map(int,input().split())))
    
def distance(x,y):
    return np.sqrt((x[1]-x[0])**2+(y[1]-y[0])**2)

d_sum=0
a=0
for i in itertools.permutations(range(n)):
    for j in range(n-1):
        d_sum+=distance(s[i[j]],s[i[j+1]])
    a+=1
print(d_sum/a)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
a = []
x = []
y = []
count = 0

def factorial(n):
    if n<2:
        return 1
    else:
        return(n*factorial(n-1))

for i in range(N):
    a.append(list(map(int,input().split())))    
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        count += np.sqrt((a[i][0] - a[j][0])**2 + (a[i][1] - a[j][1])**2)
b = factorial(N)
print(count/b)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
a = []
x = []
y = []
count = 0
def factorial(n):
    if n<2:
        return 1
    else:
        return(n*factorial(n-1))

        

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

for i in range(N):
    for j in range(N):
        if i==j:
            continue
        count += np.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
b = factorial(N)
print(count/b)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
a = []
x = []
y = []
count = 0
def factorial(n):
    if n<2:
        return 1
    else:
        return(n*factorial(n-1))

        

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

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        elif i == N-1:
            count += np.sqrt((x[0] - x[i])**2 + (y[0] - y[i])**2)
            if j == N-1:
                count += np.sqrt((x[0] - x[j])**2 + (y[0] - y[j])**2)
            else:
                count += np.sqrt((x[j+1] - x[j])**2 + (y[j+1] - y[j])**2)
        else:
            count += np.sqrt((x[i+1] - x[i])**2 + (y[i+1] - y[i])**2)
            if j == N-1:
                count += np.sqrt((x[0] - x[j])**2 + (y[0] - y[j])**2)
            else:
                count += np.sqrt((x[j+1] - x[j])**2 + (y[j+1] - y[j])**2)
b = factorial(N)
print(count/b)

Submission status: Wrong Answer

Solution code:
N=int(input())

A=[input().split() for i in range(N)]
x=0
y=1
L=0
num=0
import itertools
import math
citylist=[0]*N
#０からN-1までのN要素のリスト生成
for j in range(N):
  citylist[j]=j

Plist=list(itertools.permutations(citylist))

for l in range(math.factorial(N)):
  L=0
  for k in range(N-1):
    L+=((int(A[Plist[l][k]][x])-int(A[Plist[l][k+1]][x]))**2+(int(A[Plist[l][k]][y])-int(A[Plist[l][k+1]][y]))**2)**(1/2)
  num+=L
  
print(num/N)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
X = []
Y = []
for _ in range(n):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    
dist = 0
for j in range(len(X)):
    for k in range(len(Y)):
        if j == k:
            continue
        else:
            dist +=  math.sqrt((X[j]-X[k])**2+(Y[j]-Y[k])**2)

ans = dist
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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


arr = [i for i in range(1,n)]
for i in range(n):
  a,b = map(int,input().split())
  x.append(a)
  y.append(b)
  
count = 0
for i in range(n-1):
  for j in range(i+1,n):
    count += math.sqrt(((x[i]-x[j])**2)+((y[i]-y[j])**2))

print(count)
print(count / n * 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

N = int(input())
xy = []
for i in range(N):
  x, y = map(int, input().split())
  xy.append([x, y])
town = list(range(0, N))
path = list(permutations(town, N))
path = [list(way) for way in path]
Path_sum = []
for way in path:
  path_sum = []
  for i in range(len(way) - 1):
    j = xy[way[i]]
    k = xy[way[i+1]]
    path_x = (j[0] + k[0])**2
    path_y = (j[-1] + k[-1])**2
    path_len = np.sqrt(path_x + path_y)
    path_sum.append(path_len)
  sum_path = np.sum(path_sum)
  Path_sum.append(sum_path)
result = np.sum(Path_sum) / len(path)
print(result)

Submission status: Wrong Answer

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

def cul(a,b,c,d):
	rtmp = ((a-b)**2 + (c-d)**2)**0.5
	return rtmp
	
all = cul(arr[0][0],arr[-1][0],arr[0][1],arr[-1][1])

for i in range(n-1):
	all += cul(arr[i][0],arr[i+1][0],arr[i][1],arr[i+1][1])

part = 0

for j in range(n-1):
	for k in range(n-j):
		part += cul(arr[j][0],arr[j+k][0],arr[j][1],arr[j+k][1])

ans = (all * (n*(n-1)/2) - part ) / (n*(n-1)/2)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import permutations
from math import factorial
from math import sqrt
n=int(input())
l=[]
def distance(x,y):
  a=sqrt((x[0]-y[0])**2+(x[1]-y[1])**2)
  return a
def dist(l):
  d=0
  for i in range(1,n):
    d+=distance(l[i],l[i-1])
  return d
for i in range(n):
  l.append(list(map(int, input().split())))
x=list(permutations(l))
avg=0
for i in x:
    avg+=dist(i)
print(avg/n)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

num = int(input())
x = []
y = []
for i in range(num):
  x_N, y_N = map(int, input().split())
  x.append(x_N)
  y.append(y_N)

index = [str(i) for i in range(num)]
index_permut = list(itertools.permutations(index))

distance_all = 0
for l in index_permut:
  distance = 0
  index = list(map(int, l))

  for pos in range(num-1):
    x_diff = (x[index[pos+1]] - x[index[pos]]) ** 2
    y_diff = (y[index[pos+1]] - y[index[pos]]) ** 2
    distance += np.sqrt(x_diff + y_diff)

  distance_all += distance
res = distance_all / len(index_permut)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
import math

L = []
A = 0
t = 0
N = int(input())
for i in range(N):
    x, y = list(map(int, input().split()))
    L.append([x, y])
# print(L[1][0])
K = np.array(L)
for i in itertools.permutations(L):
    np.array(i)
    for k in range(N-1):
        u = math.sqrt((i[k][0]-i[k+1][0])**2+(i[k][1]-i[k+1][1])**2)
        print(u)
        A = A + u
    t += 1
B = A/t
print(B)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
towns = []
for i in range(N):
    town = list(map(int, input().split(" ")))
    towns.append(town)

def distance(town1,town2):
    x1,y1 = town1
    x2,y2 = town2
    return ((x1-x2)**2 + (y1-y2)**2)**0.5

print(towns)

total_distance = 0

for i in range(0, len(towns)):
    town1 = towns[i]
    for j in range(0, len(towns)):
        if i != j:
            town2 = towns[j]
            total_distance += distance(town1,town2)

avg_distance = (1/N)*total_distance
print(avg_distance)

Submission status: Wrong Answer

Solution code:
import math
import itertools

N=int(input())
P=[]
all_dist=[]


def Len(X,Y):
    return math.sqrt((X[0]-Y[0])**2+(X[1]-Y[1])**2)

for _ in range(N):
    a,b=map(int,input().split())
    P.append([a,b])
#print('townmap_is',P)

route=list(itertools.permutations(P))
print(route)

for k in range(math.factorial(N)):
    B=0
    A=list(route[k])
    for i in range(len(A)-1):
        B+=Len(A[i],A[i+1])
    all_dist.append(B)
ans=sum(all_dist)/len(all_dist)

print(str(ans))

Submission status: Wrong Answer

Solution code:
import math

def getDistance(l1,l2):
  return math.sqrt((l1[0]-l2[0])**2+(l1[1]-l2[1])**2)
def nex(n):
  if n == 0:
    return 1
  else:
    return n*nex(n-1)

n = int(input())
xy = []
for i in range(n):
  xy.append(list(map(int, input().split())))
ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    ans += getDistance(xy[i], xy[j])
print(ans/nex(n)*4)

Submission status: Wrong Answer

Solution code:
import math
from collections import deque

n = int(input())
ans = 0.0
town = []
length = [[0 for i in range(n)]for j in range(n)]
temp = []

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

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        else:
            length[i][j] = math.sqrt(
                ((town[i][0] - town[j][0]) ** 2) + ((town[i][1] - town[j][1]) ** 2))

queue = deque()

for i in range(n):
    queue.append([[i], 0])

while len(queue) != 0:
    visited = []
#    print(queue)
    left = queue.popleft()
    visited = left[0]
    now_length = left[1]
    for i in range(n):
        if i in visited:
            continue
        else:
            now_length = now_length + length[visited[len(visited) - 1]][i]
            for j in visited:
                temp.append(j)
            temp.append(i)
            if len(temp) == 8:
                ans += now_length
            else:
                queue.append([temp, now_length])
            temp = []
            now_length = left[1]

print(ans / math.factorial(n))

Submission status: Wrong Answer

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

l = 0
c = 0
for v in itertools.permutations(xy): #順列をすべて列挙
    print(v)
    for i in range(len(v)-1):
        l += ((v[i][0] - v[i+1][0]) **2 + (v[i][1] - v[i+1][1])**2)**0.5 
    c += 1
print(l/c)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np


N = int(input())
n=[]
s=range(N)
for i in range(N):
    n.append([int(x) for x in input().split()])
Q = list(itertools.permutations(s))
L=0
for i in range(int(len(Q)/2)):
    for j in range(N-1):
        L+= np.sqrt((n[Q[i][j+1]][0] - n[Q[i][j]][0])**2 + (n[Q[i][j+1]][1] - n[Q[i][j]][1])**2)
print(L/(len(Q)/2))

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
list=[]
le=[]

def Len(X,Y):
    return math.sqrt((X[0]-Y[0])**2+(X[1]-Y[1])**2)

for _ in range(N):
    a,b=map(int,input().split())
    list.append([a,b])
    
for k in range(N):
    for p in range(1,N-k,1):
        le.append(Len(list[k],list[k+p]))

le=le*(N-1)**2

print(str(sum(le)/math.factorial(N)))

Submission status: Wrong Answer

Solution code:
import itertools as it
def dis(a):
  return ((a[0]-a[2])*(a[0]-a[2])+(a[1]-a[3])*(a[1]-a[3]))**0.5
def f(n):
  o=1
  for i in range(2,n+1):
    o*=i
  return o
n = int(input())
p=[]
for i in range(n):
  a,b = map(int,input().split())
  p.append([a,b])
d=[[0]*n for _ in range(n)]
s=0
for i in range(n):
  for j in range(i+1,n):
    g = dis(p[i]+p[j])
    d[i][j]=d[j][i]=g
    s+=2*g
print("%.7f"%(s*f(n-1)/n))

Submission status: Wrong Answer

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

def dist(p1, p2):
  return math.sqrt(math.pow(p1[0]-p2[0],2) + math.pow(p1[1]-p2[1], 2))

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

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

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

total = 0

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

print(total/N)

Submission status: Wrong Answer

Solution code:
def main():
    # input
    n = int(input())
    li = [tuple(map(int, input().split())) for _ in range(n)]

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

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

    # calc


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    # input
    n = int(input())
    li = [tuple(map(int, input().split())) for _ in range(n)]

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

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

    # calc


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import itertools
N = int(input())
town = []
kyori = []
for i in range(N):
  x,y = map(int, input().split())
  town.append([x,y])

for route in itertools.permutations(town, N):
  L = 0
  # print(route)
  for i in range(N-1):
    L =+ math.sqrt((route[i+1][0]-route[i][0])**2 + (route[i+1][1]-route[i][1])**2)
  kyori.append(L)

print(sum(kyori)/N)

Submission status: Wrong Answer

Solution code:
import math

i = int(input())

x = []
y = []
k = 1

for a in range(i):
    c, d = map(int, raw_input().split())
    x.append(c)
    y.append(d)

for j in range(i):
    k = k * (j + 1)
    print k

sum = 0

for e in range(i):
    for f in range(i):
        if e != f:
            sum = sum + math.sqrt(((x[e] - x[f]) * (x[e] - x[f])) + ((y[e] - y[f]) * (y[e] - y[f])))
print (sum/i)

Submission status: Wrong Answer

Solution code:
N = int(input())
dp = dict()

dp[0] = 0
for n in range(1, N+1):
  ans = dp[n-1] + 1
  
  # メモ化
  x = 6
  while x <= n:
    ans = min(ans, dp[n-x]+1)
    x *= 6
  
  x = 9
  while x <= n:
    ans = min(ans, dp[n-x]+1)
    x *= 9
    
  dp[n] = ans
  
print(dp[N])

Submission status: Wrong Answer

Solution code:
import math
from itertools import permutations
#　　　　　　　　　　　　　　↑
#こいつはリストなどのイテレータを渡すと勝手に考えられるすべての並びの順列を作ってくれるすごい奴


def distance(a,b):
	#2点間の距離を返す関数。
    return math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)



def all_distance(lst,func=distance):
  	#座標のリスト（移動経路）を渡すと第二引数の関数（今回はdistanceなので二点間の距離）を
    #合計して返してくれる関数。関数の引数に関数を渡す高階関数を使ってみたかった。
	counter = 0
	for i in range(0,len(lst)-1):
		for j in range(1,len(lst)):
			counter += func(lst[i],lst[j])
	return counter

def meta_all_distance(lst,func):
	#最初は「all_distanceだけでいけるじゃん！」と思っていたが
    #all_distanceで計算できるのは「ひとつの移動経路の移動距離合計」であって
    #問題を解くには「考えられるすべての移動経路の移動距離の合計」を出さなくてはいけないと気付き
    #急遽作られたクッソ無様な高階関数の高階関数
    counter = 0
    for i in lst:
        counter += all_distance(i,distance)
    return counter

#実行部分　
n = int(input())
point_lst = []
for _ in range(n):
  point_lst.append(list(map(int,input().split())))
  #受け取った点の座標は文字列なので、空白文字で分割して、
  #分割した各要素をint化して、とりあえずリストにして格納している

p = list(permutations(point_lst))
count = meta_all_distance(p,all_distance)
print(count/math.factorial(n))

Submission status: Wrong Answer

Solution code:
import math
from itertools import permutations
#　　　　　　　　　　　　　　↑
#こいつはリストなどのイテレータを渡すと勝手に考えられるすべての並びの順列を作ってくれるすごい奴


def distance(a,b):
	#2点間の距離を返す関数。
    print(a)
    print(b)
    return math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)
  


def all_distance(lst,func=distance):
  	#座標のリスト（移動経路）を渡すと第二引数の関数（今回はdistanceなので二点間の距離）を
    #合計して返してくれる関数。関数の引数に関数を渡す高階関数を使ってみたかった。
	counter = 0
	for i in range(0,len(lst)-1):
		for j in range(1,len(lst)):
			counter += func(lst[i],lst[j])
	return counter

def meta_all_distance(lst,func):
	#最初は「all_distanceだけでいけるじゃん！」と思っていたが
    #all_distanceで計算できるのは「ひとつの移動経路の移動距離合計」であって
    #問題を解くには「考えられるすべての移動経路の移動距離の合計」を出さなくてはいけないと気付き
    #急遽作られたクッソ無様な高階関数の高階関数
    counter = 0
    for i in lst:
        counter += all_distance(i,distance)
    return counter

#実行部分　
n = int(input())
point_lst = []
for _ in range(n):
  point_lst.append(list(map(int,input().split())))
  #受け取った点の座標は文字列なので、空白文字で分割して、
  #分割した各要素をint化して、とりあえずリストにして格納している

p = list(permutations(point_lst))
count = meta_all_distance(p,all_distance)
print(count/n)

Submission status: Wrong Answer

Solution code:
import math
from itertools import permutations

def distance(a,b):
    print(a)
    print(b)
    return math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)

def all_distance(lst,func):
	counter = 0
	for i in range(0,len(lst)-1):
		for j in range(1,len(lst)):
			counter += func(lst[i],lst[j])
	return counter

def meta_all_distance(lst,func):
    counter = 0
    for i in lst:
        counter += all_distance(i,distance)
    return counter


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

p = list(permutations(point_lst))
#print(p)
count = meta_all_distance(p,all_distance)
print(count/n)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import heapq

N = int(input())

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

ans = 0
for a1 in A:
    for a2 in A:
        ans += (a1[0]-a2[0])**2 + (a1[1]-a2[1])**2

ans /= N
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
list_x = []
list_y = []
list_distance = []

for _ in range(N):
    (x, y) = map(int, input().split())
    list_x.append(x)
    list_y.append(y)
    
for i in range(1,N):
    for j in range(i+1,N):
        xi = list_x[i]
        yi = list_y[i]    
        xj = list_x[j]
        yj = list_y[j]
        
        distance = ((xj-xi)**2 + (yj-yi)**2)**(1/2)
        list_distance.append(distance)

last_distance = ((list_x[N-1]-list_x[0])**2 + (list_y[N-1]-list_y[0])**2)**(1/2)
list_distance.append(last_distance)
Total = sum(list_distance)

Ans = (2*Total)/N
print(Ans)

Submission status: Wrong Answer

Solution code:
import math
import itertools

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

m = []
l = 0
for i in range(N):
  m.append(int(i))

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

for j in itertools.permutations(m):
  for i in range(N-1):
     cnt = cnt + math.sqrt(((n[j[i]][0]-n[j[i+1]][0])**2)+((n[j[i]][1]-n[j[i+1]][1])**2))

print(cnt/l)

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
info=[]
for i in range(n):
    x,y=map(int,input().split())
    info.append([x,y])
total=0
for i in range(n-1):
    for j in range(i+1,n):
        total+=math.sqrt((info[i][0]**2+info[j][0]**2)+(info[i][1]**2+info[j][1]**2))
print(total*2/n)

Submission status: Wrong Answer

Solution code:
N = int(input())
list_x = []
list_y = []
list_distance = []

for _ in range(N):
    (x, y) = map(int, input().split())
    list_x.append(x)
    list_y.append(y)
    
for i in range(1,N):
    x1 = list_x[i-1]
    y1 = list_y[i-1]    
    
    xi = list_x[i]
    yi = list_y[i]
    
    distance = ((xi-x1)**2 + (yi-y1)**2)**(1/2)
    list_distance.append(distance)

last_distance = ((list_x[N-1]-list_x[0])**2 + (list_y[N-1]-list_y[0])**2)**(1/2)
list_distance.append(last_distance)
Total = sum(list_distance)

Ans = (2*Total)/N
print(Ans)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
m=[]
ds=[]

for i in range(n):
    m.append(list(map(int,input().split())))
for i in range(n):
    for j in range(i+1,n):
        ds.append(math.sqrt((m[i][0]-m[j][0])**2+(m[i][1]-m[j][1])**2))
    ps=math.factorial(n)
    x=(n-1)*math.factorial(n)/len(ds)
    print(sum(ds)*(n-1)/len(ds))

Submission status: Wrong Answer

Solution code:
from math import sqrt
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] = list(map(int, input().split()))
dist = 0.0
for i in range(N-1):
  for j in range(i+1, N):
    dist += sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)
dist = dist / N
print(dist)

Submission status: Wrong Answer

Solution code:
from math import sqrt
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] = list(map(int, input().split()))
count = 0
dist = 0.0
for i in range(N-1):
  for j in range(i+1, N):
    dist += sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)
    count += 1
dist = dist / count 
print(dist)

Submission status: Wrong Answer

Solution code:
from math import sqrt
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] = list(map(float, input().split()))
i = N
count = 1
while i > 0:
  count *= i
  i -= 1
dist = 0.0
for i in range(N):
  for j in range(i+1, N):
    dist += sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)
dist = dist / count 
print(dist)

Submission status: Wrong Answer

Solution code:
#ステップについて
#順列の全列挙(N!通り)をする
#平均移動距離を求める

import math

#入力受付
n=int(input())
xy=[]
for _ in range(n):
    #map(関数, イテラブル) ＜＝高階関数
	x,y=map(int,input().split())
	xy.append([x,y])

#各パターンの距離を集計
ans=0
for i in range(n):
	for j in range(n):
        # sqrtの代わりに、**0.5で0.5乗することでも求められる
		ans+=math.sqrt((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)

#n!で割って終了
print(ans/(math.factorial(n)))

Submission status: Wrong Answer

Solution code:
#ステップについて
#順列の全列挙(N!通り)をする
#平均移動距離を求める

import math

#入力受付
n=int(input())
xy=[]
for _ in range(n):
    #map(関数, イテラブル) ＜＝高階関数
	x,y=map(int,input().split())
	xy.append([x,y])

#各パターンの距離を集計
ans=0
for i in range(n):
	for j in range(n):
        # sqrtの代わりに、**0.5で0.5乗することでも求められる
		ans+=math.sqrt((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)

#n!で割って終了
print(ans/math.factorial(n))

Submission status: Wrong Answer

Solution code:
import numpy as	np
n =int(input())
d = np.zeros((n,2))
for i in range(n):
    s_list =	str(input()).split()
    d[i, 0], d[i, 1] = s_list[0], s_list[1]
count = 0
sum = 0
for i in range(n):
    for	j in range(n):
        if i < j:
            sum = np.linalg.norm(d[i]-d[j])
            count += 1
print(sum / count)

Submission status: Wrong Answer

Solution code:
import math
import copy
x = int(input())
y = []
for i in range(x):
    y.append([int(j) for j in input().split(' ')])

def calc_distance(a, b):
    c0 = pow(a[0]-b[0], 2)
    c1 = pow(a[1]-b[1], 2)
    print(a, b)
    return math.sqrt(c0 + c1)

all_sum = 0
for (i, v1) in enumerate(y):
    new_array_1 = copy.deepcopy(y)
    new_array_1.pop(i)
    for (j, v2) in enumerate(new_array_1):
        all_sum = all_sum + calc_distance(v1, v2)
        new_array_2 = copy.deepcopy(new_array_1)
        new_array_2.pop(j)
        for (k, v3) in enumerate(new_array_2):
            all_sum = all_sum + calc_distance(v2, v3)

print(all_sum/math.factorial(x))

Submission status: Wrong Answer

Solution code:
from math import sqrt
n = int(input())
x = []
y = []
sum = 0
for i in range(n):
    X,Y = map(int,input().split())
    x.append(X)
    y.append(Y)
for i in range(n):
    for j in range(n):
        if j == i:
            continue
        sum += sqrt((x[i]-x[j])**2+((y[i]-y[j])**2))
def rank(s):
    if s != 1:
        return s * rank(s-1)
    else:
        return 1
print(rank(n))

print(sum * 2 * rank(n-1)/ rank(n)/2)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
tl = [[int(x) for x in input().split()] for _ in range(N)]

def dfs(s):
  if int(len(s)) > N+1:
    return 0
  ret = math.sqrt((tl[int(s[-1])-1][0] - tl[int(s[-2])-1][0])**2 + (tl[int(s[-1])-1][1] - tl[int(s[-2])-1][1])**2) if int(len(s)) > 2 else 0
  for i in range(1, N+1):
    ret += dfs(s+str(i))
  return ret 

print(dfs("0") / math.factorial(N))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
C = list()
for _ in range(n):
  a, b = map(int, input().split(" "))
  C.append((a, b))

D = list()

for i, (a1, b1) in enumerate(C):
  for j, (a2, b2) in enumerate(C):
    if i >=j:continue
    d = math.sqrt((a1-a2)**2 + (b1-b2)**2)
    D.append(d)

k = (n-1)*math.factorial(n-1)
D = map(lambda x: x*k, D)
ans = sum(D) / math.factorial(n)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
C = list()
for _ in range(n):
  a, b = map(int, input().split(" "))
  C.append((a, b))

D = list()

for i, (a1, b1) in enumerate(C):
  for j, (a2, b2) in enumerate(C):
    if i >=j:continue
    d = math.sqrt((a1-a2)**2 + (b1-b2)**2)
    D.append(d)
print(D)
k = (n-1)*math.factorial(n-1)
D = map(lambda x: x*k, D)
ans = sum(D) / math.factorial(n)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import itertools

N = int(input())
A =[]
path_length = 0

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

for p in list(itertools.permutations(A, 2)):
  # p は、点の順列

  for (x1,y1), (x2,y2) in zip(p, p[1:]):
      path_length += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
ans = path_length / math.factorial(N)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x_list = [ tuple(int(i) for i in input().split()) for _ in range(n) ]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
y = []
for i in range(n):
  _x, _y = map(int, input().split())
  x.append(_x)
  y.append(_y)
#それぞれの組み合わせに対して2*(n-1)!回ずつ合計に加算される→平均への寄与は2/n倍
def d(x1, y1, x2, y2):
  return ((x1-x2)**2 - (y1-y2)**2)**0.5

ans = 0
for i in range(n):
  for j in range(i+1, n):
    ans += d(x[i], y[i], x[j], y[j])
print(ans*2/n)

Submission status: Wrong Answer

Solution code:
import math

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

XY_dict = {}

for i in range(0,N):
  for j in range(i+1,N):
    key = str(i) + str(j)
    XY_dict[key] = math.sqrt( (XY[i][0] - XY[j][0])**2 + (XY[i][1] - XY[j][1])**2 )

ans = 0
print(XY_dict)
for xy in XY_dict.values():
  ans += xy

ans = (ans * 2)/N

print(ans)

Submission status: Wrong Answer

Solution code:
def dist(x1, x2):
    d = (x1[0] - x2[0])**2 + (x1[1] - x2[1])**2
    return d**0.5

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

Submission status: Wrong Answer

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

coord = list()
for _ in range(N):
    c = tuple(map(int, input().split()))
    coord.append(c)

def calc_fact(N):
    base_case = 1
    for i in range(2, N + 1):
        base_case *= i
    return base_case

def calc_dist(p1, p2):
    return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)

def calc_perm(N, dist):
    while N > 2:
        return (N - 2) * calc_perm(N - 1, dist)  + 2*dist
    
    return 2*dist

perm = 0
for i, p1 in enumerate(coord):
        for p2 in coord[i+1:]:
            d = calc_dist(p1, p2)
            perm += calc_perm(N, d)

print(perm/calc_fact(N))

Submission status: Wrong Answer

Solution code:
def dis(p1,p2):
  return ((p1[0]-p2[0])**2+(p1[1]-p2[1])**2)**0.5
import math
n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(n):
  for j in range(i+1,n):
    ans+=dis(p[i],p[j])
print(ans*4/math.factorial(n))

Submission status: Wrong Answer

Solution code:
import math
def dis(p1,p2):
  return ((p1[0]-p2[0])**2+(p1[1]-p2[1])**2)**0.5
 
n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(n):
  for j in range(i+1,n):
    ans+=dis(p[i],p[j])
print(ans*4/math.factorial(n))

Submission status: Wrong Answer

Solution code:
def dis(p1,p2):
  return ((p1[0]-p2[0])**2+(p1[1]-p2[1])**2)**0.5
 
n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(n):
  for j in range(i+1,n):
    print('i', i)
    print('j', j)
    ans+=dis(p[i],p[j])
print(ans*2/n)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc145/tasks/abc145_c

import sys
sys.setrecursionlimit(12345678)
import itertools
import math
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n = int(input())
    nl = [i for i in range(n)]

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

    total = 0
    routes = list(itertools.permutations(nl))
    for route in routes:
        distance = 0
        for i in range(1, len(route)):
            src_x = xy[i-1][0]
            src_y = xy[i-1][1]
            dst_x = xy[i][0]
            dst_y = xy[i][1]
            distance += math.sqrt((dst_x - src_x) * (dst_x - src_x) + (dst_y - src_y) * (dst_y - src_y))

        total += distance

    print(total / len(routes))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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 * N * (N-1)
print(total/N)

Submission status: Wrong Answer

Solution code:
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 = 2 * total
print(total/N)