Problem:


Score : 300 points

Problem Statement

There are N towns in a coordinate plane. Town i is located at coordinates (x_i, y_i). The distance between Town i and Town j is \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2}.

There are N! possible paths to visit all of these towns once. Let the length of a path be the distance covered when we start at the first town in the path, visit the second, third, \dots, towns, and arrive at the last town (assume that we travel in a straight line from a town to another). Compute the average length of these N! paths.

Constraints

2 \leq N \leq 8

-1000 \leq x_i \leq 1000

-1000 \leq y_i \leq 1000

\left(x_i, y_i\right) \neq \left(x_j, y_j\right) (if i \neq j)

(Added 21:12 JST) All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the average length of the paths.
Your output will be judges as correct when the absolute difference from the judge's output is at most 10^{-6}.

Sample Input 1

3
0 0
1 0
0 1

Sample Output 1

2.2761423749

There are six paths to visit the towns: 1 → 2 → 3, 1 → 3 → 2, 2 → 1 → 3, 2 → 3 → 1, 3 → 1 → 2, and 3 → 2 → 1.

The length of the path 1 → 2 → 3 is \sqrt{\left(0-1\right)^2+\left(0-0\right)^2} + \sqrt{\left(1-0\right)^2+\left(0-1\right)^2} = 1+\sqrt{2}.

By calculating the lengths of the other paths in this way, we see that the average length of all routes is:

\frac{\left(1+\sqrt{2}\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)}{6} = 2.276142...

Sample Input 2

2
-879 981
-866 890

Sample Output 2

91.9238815543

There are two paths to visit the towns: 1 → 2 and 2 → 1. These paths have the same length.

Sample Input 3

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

Sample Output 3

7641.9817824387



Sample input:
3
0 0
1 0
0 1


Sample output:
2.2761423749

Submission status: Wrong Answer

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

num=[j for j in range(n)]
new=list(itertools.permutations(num))
ans=0
for i in range(len(new)):
    for j in range(n-1):
        a=new[i][j]
        b=new[i][j+1]
        ans+=math.sqrt((lis[a][0]-lis[a][1])**2+(lis[b][0]-lis[b][1])**2)
print(ans/len(new))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# ABC1４５C 

import itertools, math

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

length = 0
sum_ = 0
for num, val in enumerate(itertools.permutations(city_list, n)):
    for i in range(len(val) - 1):
        length =  math.sqrt((val[i][0] - val[i + 1][0]) ** 2 +  (val[i][1] - val[i + 1][1]) ** 2)
        length += length
    sum_ += length
    length = 0
        
ans = sum_ / (num + 1)
print(ans)

Submission status: Wrong Answer

Solution code:
points = [map(int, raw_input().split(' ')) for _ in range(int(raw_input()))]
print points
def distance(u,v):
	return ((u[1] - v[1]) ** 2 + (u[0] - v[0]) ** 2) ** 0.5
c = [0,0]
def permut(i, points, c):
	if i == len(points):
		tot = 0
		for u,v in zip(points, points[1:]): tot += distance(u,v)
		c[0] +=  tot
		c[1] += 1
		return 
	for j in range(i,len(points)):
		points[i], points[j] = points[j], points[i]
		permut(i+1, points,c)
		points[i], points[j] = points[j], points[i]

permut(0, points,c)

print c[0] / float(c[1])

Submission status: Wrong Answer

Solution code:
n=int(input())
k = [list(map(int, input().split())) for i in range(n)]
import math
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        z=math.sqrt((k[i][0]-k[j][0])**2+((k[i][1]-k[j][1])**2))
        ans+=(n-1)*2*z

z=math.factorial(n)
print(ans/z)

Submission status: Wrong Answer

Solution code:
n=int(input())
k = [list(map(int, input().split())) for i in range(n)]
import math
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        z=math.sqrt((k[i][0]-k[j][0])**2+((k[i][1]-k[j][1])**2))
        ans+=(n-1)*2*z
z=(n*(n-1))/2

print(ans/z)

Submission status: Wrong Answer

Solution code:
n=int(input())
k = [list(map(int, input().split())) for i in range(n)]
import math
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        z=math.sqrt((k[i][0]-k[j][0])**2+((k[i][1]-k[j][1])**2))
        ans+=2*z
z=(n*(n-1))/2

print(ans/z)

Submission status: Wrong Answer

Solution code:
n=int(input())
k = [list(map(int, input().split())) for i in range(n)]
import math
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        z=math.sqrt((k[i][0]-k[j][0])**2+((k[i][1]-k[j][1])**2))
        ans+=2*z
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
k = [list(map(int, input().split())) for i in range(n)]
import math
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        z=math.sqrt((k[i][0]-k[j][0])**2+((k[i][0]-k[j][0])**2))
        ans+=2*z
print(ans)

Submission status: Wrong Answer

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

n = int(input())

nf = factorial(n)

xy = []
X = 0
Y = 1

l = [i for i in range(n)]
s = 0

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


for p in permutations(l, n):
    p = list(p)
    # print(p)
    for i in range(len(p) - 1):
        s += sqrt((xy[i][X] - xy[i+1][X])**2 + (xy[i][Y] - xy[i+1][Y])**2)

print(s/nf)

Submission status: Wrong Answer

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

n = int(input())

nf = factorial(n)

xy = []
X = 0
Y = 1

l = [i for i in range(n)]
s = 0

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


for p in permutations(l, n):
    p = list(p)
    print(p)
    for i in range(len(p) - 1):
        s += sqrt((xy[i][X] - xy[i+1][X])**2 + (xy[i][Y] - xy[i+1][Y])**2)

print(s/nf)

Submission status: Wrong Answer

Solution code:
import itertools
N=int(input())
XY=[]
for i in range(N):
  x,y=map(int,input().split())
  XY+=[[x,y]]
ALL=list(itertools.permutations(XY))
print(ALL)
ans=10**9
d=0
for i in ALL:
  for k in range(N-1):
    d2=((i[k][0]-i[k+1][0])**2+(i[k][1]-i[k+1][1])**2)**(1/2)
    d+=d2
ans=d/len(ALL)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

print(s)

dist=0
a=math.factorial(n)
for i in range(n):
  for j in range(i+1,n):
    dist+=math.sqrt((s[i][0]-s[j][0])**2+(s[i][1]-s[j][1])**2)
print(dist*2/n)

Submission status: Wrong Answer

Solution code:
import itertools
import math
n=int(input())
X=[list(map(int,input().split())) for _ in range(n)]
P=[i for i in range(n)]
total=0
for j in itertools.permutations(P,n):
  candi=list(j)
  for k in range(len(candi)-1):
    dis1=(X[candi[k]][0]-X[candi[k+1]][0])**2
    dis2=(X[candi[k]][1]-X[candi[k+1]][1])**2
    total+=(dis1+dis2)**(1/2)
    print(candi,total)
print(total/math.factorial(n))

Submission status: Wrong Answer

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

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

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

print(ans/kaijo)

Submission status: Wrong Answer

Solution code:
import itertools
import math
import statistics

N = int(input())
direction = [list(map(int,input().split())) for _ in range(N)]
_l = itertools.permutations(direction,N)
l = []
for lst in _l:
	l.append([[0,0]] + list(lst))

s = []
for d in l:
	tmp = 0
	for i in range(len(d)-1):
	  tmp += math.sqrt((d[i+1][0]-d[i][0])**2 + (d[i+1][1]-d[i][1])**2)
	s.append(tmp)
print(sum(s)/len(s))

Submission status: Wrong Answer

Solution code:
import numpy as np
from math import factorial

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

def dist(i, j):
    return np.sqrt((x[i]-x[j])**2 + (y[i] - y[j])**2)

matrix = np.zeros((N, N))
for i in range(N*N):
    iy = i%N
    ix = i//N
    if iy > ix:
        matrix[ix, iy] = dist(ix, iy)
        print(ix, iy)

avepath = np.sum(matrix)*2/N
print(avepath)

Submission status: Wrong Answer

Solution code:
import numpy as np


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

def dist(i, j):
    return np.sqrt((x[i]-x[j])**2 + (y[i] - y[j])**2)

matrix = np.zeros((N, N))
for i in range(N*N):
    iy = i%N
    ix = i//N
    if iy > ix:
        matrix[ix, iy] = dist(ix, iy)
        print(ix, iy)

avepath = np.sum(matrix)*2/N
print(avepath)

Submission status: Wrong Answer

Solution code:
from math import sqrt
import numpy as np

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

def dist(i, j):
    return sqrt((x[i]-x[j])**2 + (y[i] - y[j])**2)

NN = N*N
matrix = np.zeros((N, N))
for i in range(NN):
    iy = i%N
    ix = i//N
    if iy > ix:
        matrix[ix, iy] = dist(ix, iy)
        print(ix, iy)

avepath = np.sum(matrix)*(N-1)/N
print(avepath)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools as it

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

dist = [[[] for i in range(n)] for i in range(n)]
for i in range(n):
    for j in range(n):
        v = city[i] - city[j]
        dist[i][j] = np.linalg.norm(v, ord=2)

ps = it.permutations([i for i in range(n)])
anss = []
for p in ps:
    ans = 0
    print(p)
    for i in range(n-1):
        ans += dist[p[i]][p[i+1]]
    anss.append(ans)

print(np.average(anss))

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools as it

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

dist = [[[] for i in range(n)] for i in range(n)]
for i in range(n):
    for j in range(n):
        v = city[i] - city[j]
        dist[i][j] = np.linalg.norm(v, ord=2)

ps = it.permutations([i for i in range(n)])
anss = []
for p in ps:
    ans = 0
    print(p)
    for i in range(n-1):
        ans += dist[p[i]][p[i+1]]
    anss.append(ans)

print(anss)
print(np.average(anss))

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
for j in range(N-1):
    for i in range(j + 1, N-1):
        total += ((xy[j][0] - xy[i][0])**2 + (xy[j][1]-xy[i][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 + 1, 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 itertools
n=int(input())
x=[list(map(int,input().split())) for i in range(n)]
a=[]
for i in range(n):
    a.append(i)

p=list(itertools.permutations(a,n))

len=0
for j in range(n):
  for i in range(n-1):
    len+=((x[p[j][i]][0]-x[p[j][i+1]][0])**2+(x[p[j][i]][1]-x[p[j][i+1]][1])**2)**(1/2)
b=len/n
print(b)

Submission status: Wrong Answer

Solution code:
import itertools

def calculate_distance(x1, x2):
    l2_norm = (x1[0] - x2[0])**2 + (x1[1] - x2[1])**2
    return l2_norm**(1/2)

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

distance = 0
for a in itertools.permutations(range(N)):
    for i in range(N-1):
        start, end = a[i], a[i+1]
        distance += calculate_distance(point[start], point[end])
print(distance/N)

Submission status: Wrong Answer

Solution code:
import itertools

def calculate_distance(x1, x2):
    l2_norm = (x1[0] - x2[0])**2 + (x1[1] - x2[1])**2
    return l2_norm**(1/2)

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

distance = 0
for a in itertools.permutations(range(N)):
    for i in range(N-1):
        distance += calculate_distance(point[i], point[i+1])
print(distance/N)

Submission status: Wrong Answer

Solution code:
import math
import itertools

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

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

distance = 0
for a in itertools.permutations(range(N)):
    for i in range(N-1):
        distance += calculate_distance(point[i], point[i+1])
print(distance/N)

Submission status: Wrong Answer

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

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

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

if len(dist) == 1:
    print(dist[0])
else:
    dist_sum = 0
    dist_case = list(combinations_with_replacement(dist, 2))
    for m, n in dist_case:
        dist_sum += m + n
    
    print(dist_sum / len(dist_case))

Submission status: Wrong Answer

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

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

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

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

print(dist_sum / len(dist_case))

Submission status: Wrong Answer

Solution code:
from itertools import combinations
from math import sqrt

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

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

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

print(dist_sum / len(nC2))

Submission status: Wrong Answer

Solution code:
from itertools import combinations
from math import sqrt

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

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

print(dist / len(nC2))

Submission status: Wrong Answer

Solution code:
from itertools import permutations, combinations

def main():
    n = int(input())
    x_l = [] ; y_l = []
    for _ in range(n):
        tmp_x, tmp_y = map(int, input().split())
        x_l.append(tmp_x) ; y_l.append(tmp_y)
    cnt = 0
    total_dist = 0
    for c in permutations(range(n)):
        # c の中から２辺の数繰り返す
        for i in range(n-1):
            dist = ((x_l[i] - x_l[i+1])**2 + (y_l[i] - y_l[i+1])**2)**(1/2)
            total_dist += dist
        cnt += 1

    print(total_dist/cnt)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
if __name__ == "__main__":
    N = int(input())

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

    fac = math.factorial(N)
    NN = (fac * (N -1 )) / N

    # print("fac",fac)

    Z  = 0
    for i in range(N):
        Z += ((math.sqrt((X[i - 1] - X[i])**2 + (Y[i - 1] - Y[i])**2 ) ) * NN) 
    
    # print("z",Z)
    # print("nn",NN)

    print(Z / fac)

Submission status: Wrong Answer

Solution code:
import math
if __name__ == "__main__":
    N = int(input())

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

    fac = math.factorial(N)
    NN = (fac * (N -1 )) / N

    Z  = 0
    for i in range(N):
        Z += ((math.sqrt((X[i - 1] - X[i])**2 + (Y[i -1] - X[i])**2 ) ) * NN) 
    
    print(Z / fac)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_pow(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
    return ret
def seifu(x):
    return x//abs(x)
###################################################
def main():
    n=int(input())
    facs=get_facs(n+5)
    ans=0
    x=[0]*n
    y=[0]*n
    for a in range(n):x[a],y[a]=map(int,input().split())
    for a in range(n):
        for b in range(n):
            ans+=facs[n-1]*math.sqrt((x[a]-x[b])**2+(y[a]-y[b])**2)
    ans/=n
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_pow(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
    return ret
def seifu(x):
    return x//abs(x)
###################################################
def main():
    n=int(input())
    facs=get_facs(n+5)
    ans=0
    x=[0]*n
    y=[0]*n
    for a in range(n):x[a],y[a]=map(int,input().split())
    for a in range(n-1):
        for b in range(a+1,n):
            ans+=facs[n-1]*math.sqrt((x[a]-x[b])**2+(y[a]-y[b])**2)
    ans/=n
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
import math


def test(checked_array: list, array: list,
         last_index: int, count: int, max_count: int, result: list, st):
    # print("{}".format(count))

    if count == max_count:
        result[1] += 1
        return
    for i in range(len(array)):
        if checked_array[i] is True:
            # print("{}は処理済み".format(i))
            continue
        new_array = checked_array[:]
        distance = (
            array[i][0] - array[last_index][0]
        ) ** 2 + (
            array[i][1] - array[last_index][1]
        ) ** 2
        result[0] += math.sqrt(distance)
        new_array[i] = True

        test(
            new_array,
            array,
            i,
            count + 1,
            max_count,
            result,
            "{}->{}".format(st, i)
        )


N = int(input())

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

result = [float('0.0'), 0]
checked_array = [False] * N
for i in range(N):
    ary = checked_array[:]
    ary[i] = True
    test(ary, array, i, 1, N, result, "{}".format(i))
# print(result[0])
# print(result[1])
print(result[0] / result[1])

Submission status: Wrong Answer

Solution code:
import math


def test(checked_array: list, array: list,
         last_index: int, count: int, max_count: int, result: list, st):
    # print("{}".format(count))

    if count == max_count:
        result[1] += 1
        return
    for i in range(len(array)):
        if checked_array[i] is True:
            # print("{}は処理済み".format(i))
            continue
        new_array = checked_array[:]
        distance = (
            array[i][0] - array[last_index][0]
        ) ** 2 + (
            array[i][1] - array[last_index][1]
        ) ** 2
        result[0] += math.sqrt(distance)
        new_array[i] = True

        test(
            new_array,
            array,
            i,
            count + 1,
            max_count,
            result,
            "{}->{}".format(st, i)
        )


N = int(input())

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

result = [float('0.0'), 0]
checked_array = [False] * N
for i in range(N):
    ary = checked_array[:]
    ary[i] = True
    test(ary, array, i, 1, N, result, "{}".format(i))
print(result[0])
print(result[1])
print(result[0] / result[1])

Submission status: Wrong Answer

Solution code:
n = int(input())

l = []
cnt = 1
for i in range(1, n):
  cnt *= i
  print(i)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
X = [list(map(int, input().split())) for i in range(N)]
x = list(itertools.permutations(range(N), N))
res = 0
for a in x:
    for i in range(N - 1):
        print(res)
        res += ((X[a[i]][0] - X[a[i + 1]][0]) ** 2 + (X[a[i]][1] - X[a[i + 1]][1]) ** 2) ** 0.5
print(res / len(x))

Submission status: Wrong Answer

Solution code:
import itertools
N=int(input())
point=[]
for _ in range(N):
    x,y=map(int,input().split())
    point.append([x,y])
nums=[i for i in range(1,N+1)]
perm=list(itertools.permutations(nums,N))
dist=0

for pattern in perm:
    tmp_dist=0
    for i in range(N-1):
        tmp_dist+=((point[pattern[i]-1][0]-point[pattern[i+1]-1][0])**2+(point[pattern[i]-1][1]-point[pattern[i+1]-1][1])**2)**0.5
    dist+=tmp_dist

Submission status: Wrong Answer

Solution code:
import itertools
N=int(input())
point=[]
for _ in range(N):
    x,y=map(int,input().split())
    point.append([x,y])
nums=[i for i in range(1,N+1)]
perm=list(itertools.permutations(nums,N))
dist=0
for pattern in perm:
    tmp_dist=0
    for i in range(N-1):
        tmp_dist+=((point[i][0]-point[i+1][0])**2+abs(point[i][1]-point[i+1][1])**2)**0.5
    dist+=tmp_dist
print(dist/len(perm))

Submission status: Wrong Answer

Solution code:
import math
import itertools
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
def distance(x1, y1, x2, y2):
    return math.sqrt((x1 - x2)**2 + (y1 - y2)**2)

dist = 0
cnt = 0
for p in itertools.permutations(range(n)):
    for i in range(n-1):
        dist += distance(xy[i][0], xy[i][1], xy[i+1][0], xy[i+1][1])
    cnt += 1
ans = dist / cnt
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import itertools
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
def distance(x1, y1, x2, y2):
    return math.sqrt((x1 - x2)**2 + (y1 - y2)**2)

dist = 0
cnt = 0
for p in itertools.permutations(range(8)):
    for i in range(n-1):
        dist += distance(xy[i][0], xy[i][1], xy[i+1][0], xy[i+1][1])
    cnt += 1
ans = dist / cnt
print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial
from itertools import permutations
def main():
    n = int(input())
    town_coor = []
    for _ in range(n):
        town_coor.append(tuple(map(int, input().split())))

    towns = [i for i in range(n)]
    roads = permutations(towns, n)
    sum_roads = 0
    for load in roads:
        sum_road = 0
        for i1 in range(n-1):
            sum_road += ((town_coor[i1][0] - town_coor[i1 +1][0])**2 + (town_coor[i1][1] - town_coor[i1 +1][1])**2)**0.5
        sum_roads += sum_road
    print(sum_roads / factorial(n))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

import math
ans = 0
for i in range(n):
    dist = 0
    for j in range(n-1):
        dist += math.sqrt((place[route[i][j+1]][0] - place[route[i][j]][0])**2 + (place[route[i][j+1]][1] - place[route[i][j]][1])**2)
    
    ans += dist

print(ans/n)

Submission status: Wrong Answer

Solution code:
import math
from itertools import combinations

N = int( input() )

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

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

base = list(combinations(range(N),2))
sums = 0
for x in base:
  a, b = x
  sums += distance( d[a], d[b] )
print( len( base ) )
print( sums / (len(base)) * ( N - 1 ))

Submission status: Wrong Answer

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

from itertools import combinations
def f(x1,y1,x2,y2):
    dx = x2 - x1
    dy = y2 - y1
    return (dx**2+dy**2)**0.5
dst = 0
for i,j in combinations(range(0,N),2):
    dst += f(pts[i][0], pts[i][1], pts[j][0], pts[j][1])
print(dst / (N // 2))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
K = math.factorial(N)
P = []
r = 0

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

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

for i in range(N):
  for j in range(i+1, N):
    r += f(*(P[i]+P[j]))

if N > 2:
  print(r * (K - 2) / K)
else:
  print(r)