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

Submission status: Wrong Answer

Solution code:
def dis(p1,p2):
  return ((p1[0]-p2[0])**2+(p1[1]-p2[0])**2)**0.5

n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
ans=0
fac=1
for i in range(n):
  for j in range(i+1,n):
    ans+=dis(p[i],p[j])
print(ans*2/n)

Submission status: Wrong Answer

Solution code:
def dis(p1,p2):
  return ((p1[0]-p2[0])**2+(p1[1]-p2[0])**2)**0.5

n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
ans=0
fac=1
for i in range(n):
  if(i!=0):
    fac*=i
  for j in range(i+1,n):
    ans+=dis(p[i],p[j])
print(ans*(2*n-2)/(fac*n))

Submission status: Wrong Answer

Solution code:
def dis(p1,p2):
  return ((p1[0]-p2[0])**2+(p1[1]-p2[0])**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/n)

Submission status: Wrong Answer

Solution code:
import itertools as iter
n = int(input())
li = [list(map(int,input().split())) for i in range(n)]
com = list(iter.permutations(li))
start = com[0]
ans = 0
print(com)
for i in com:
    for j in range(n-1):
        a,b=i[j]
        c,d=i[j+1]
        ans+=((c-a)**2+(d-b)**2)**0.5
print(ans/len(com))

Submission status: Wrong Answer

Solution code:
import math

def factorial(n):
    if n == 0:
        return 1.0
    else:
        return n*factorial(n-1)


n = int(raw_input())
k = n
arr = []
while(k > 0):
    x, y = map(int, raw_input().split())
    arr.append((x, y))
    k -= 1

total = 0.0
for i in range(n):
    x1 = arr[i][0]
    x2 = arr[i][1]
    for j in range(i+1, n, 1):
        y1 = arr[j][0]
        y2 = arr[j][1]
        dist = (x1-y1)*(x1-y1) + (x2-y2)*(x2-y2)
        print dist
        dist = float(math.sqrt(dist))
        dist = dist * float((factorial(n-1)*2))
        total += dist * float(1/factorial(n))

print total

Submission status: Wrong Answer

Solution code:
import math

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
import math

N = int(input())
Fac = math.factorial(N)
x = []
y = []
X = []
Y = []
leng = []
tmp = 0
for i in range(N):
    tmp = list(map(int,input().split()))
    x.append(tmp[0])
    y.append(tmp[1])
for i in itertools.permutations(x):
    X.append(i)
for i in itertools.permutations(y):
    Y.append(i)
for i in range(Fac):
    try:
        leng.append((((X[i][0]-X[i][1]) ** 2) ** 0.5 + ((Y[i][0]-Y[i][1]) ** 2)) ** 0.5)
    except:
        pass
tmp = 0
for i in range(Fac):
    tmp += leng[i]
ans = tmp / (Fac/(Fac/N))
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import math

N = int(input())
Fac = math.factorial(N)
x = []
y = []
X = []
Y = []
leng = []
tmp = 0
for i in range(N):
    tmp = list(map(int,input().split()))
    x.append(tmp[0])
    y.append(tmp[1])
for i in itertools.permutations(x):
    X.append(i)
for i in itertools.permutations(y):
    Y.append(i)
for i in range(Fac):
    try:
        leng.append((((X[i][0]-X[i][1]) ** 2) + ((Y[i][0]-Y[i][1]) ** 2)) ** 0.5)
    except:
        pass
tmp = 0
for i in range(Fac):
    tmp += leng[i]
ans = tmp / N
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import math

N = int(input())
Fac = math.factorial(N)
x = []
y = []
X = []
Y = []
leng = []
tmp = 0
for i in range(N):
    tmp = list(map(int,input().split()))
    x.append(tmp[0])
    y.append(tmp[1])
for i in itertools.permutations(x):
    X.append(i)
for i in itertools.permutations(y):
    Y.append(i)
for i in range(Fac):
    try:
        leng.append((((X[i][0]-X[i][1]) ** 2) + ((Y[i][0]-Y[i][1]) ** 2)) ** 0.5)
    except:
        pass
tmp = 0
for i in range(Fac):
    tmp += leng[i]
ans = (tmp / Fac)*2
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
path = list(itertools.permutations(set(range(n))))

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


def dist(x, y):
    return (x ** 2 + y ** 2) ** 0.5


check = list()
for p in path:
    for i in range(len(p) - 1):
        total += dist(town[p[i]][0] - town[p[i + 1]][0], town[p[i]][1] - town[p[i + 1]][1])

print(total / n)

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
path = list(itertools.permutations(set(range(n))))

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


def dist(x, y):
    return (x ** 2 + y ** 2) ** 0.5


check = list()
for p in path:
    for i in range(len(p) - 1):
        total += dist(town[p[i]][0] - town[p[i + 1]][0], town[p[i]][1] - town[p[i + 1]][1])

print(total / 6)

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 j in range(n):
		ans=+((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**0.5
print(ans/n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import sqrt

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

n = int(input())
a = []
for i in range(n):
    s = list(map(int,input().split()))
    a.append(s)
s = 0
for i in range(1,n):
    s = s + (2 * (n - 1) * calc(a[i], a[i - 1]))
s = s + (2 * (n - 1) * calc(a[0], a[-1]))
print(s/(2 * n))

Submission status: Wrong Answer

Solution code:
n=int(input())
d=[]
for i in range(0,n):
   a=[int(x) for x in input().split()] 
   d.append(a)
dis=0


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

Submission status: Wrong Answer

Solution code:
n=int(input())
d=[]
for i in range(0,n):
   a=[int(x) for x in input().split()] 
   d.append(a)
dis=0


for i in range(n):
    for j in range(n):
        dis+=(abs(d[i][0]**2-d[j][0]**2)+abs(d[i][1]**2-d[j][1]**2))**0.5

print(dis/n)

Submission status: Wrong Answer

Solution code:
def compute(x1,y1,x2,y2):
    a1,a2 = (x1-x2)**2,(y1-y2)**2
    return (a1+a2)**0.5
def fact(n):
    mul=1;
    for i in range(2,n+1):
        mul*=i
    return mul
cc,a,b = [],[],[]
n = int(input())
for i in range(n):
    cc.append(0)
    if i == 2:
        cc[2]=2
    if i>2:
        cc[int(i)] = cc[int(i)-1]*(i-1)
    aa,bb = input().split()
    aa,bb = int(aa),int(bb)
    a.append(aa)
    b.append(bb)
sum=0
sum = float(sum)
cc.append(cc[n-1]*(n-1))
for i in range(n):
    for j in range(i+1,n):
        sum+=compute(a[int(i)],b[int(i)],a[int(j)],b[int(j)])*cc[int(n)]
print(sum/fact(n))

Submission status: Wrong Answer

Solution code:
def compute(x1,y1,x2,y2):
    a1,a2 = (x1-x2)**2,(y1-y2)**2
    return (a1+a2)**0.5
def fact(n):
    mul=1;
    for i in range(2,n+1):
        mul*=i
    return mul
cc,a,b = [],[],[]
n = int(input())
for i in range(n):
    cc.append(0)
    if i == 2:
        cc[2]=2
    if i>2:
        cc[int(i)] = cc[int(i)-1]*(i-1)
    aa,bb = input().split()
    aa,bb = int(aa),int(bb)
    a.append(aa)
    b.append(bb)
sum=0
cc.append(cc[n-1]*(n-1))
for i in range(n):
    for j in range(i+1,n):
        sum+=compute(a[int(i)],b[int(i)],a[int(j)],b[int(j)])*cc[int(n)]
print(sum/fact(n))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

def length(x1,y1,x2,y2):
    L = np.sqrt((x1-x2)**2 + (y1-y2)**2)
    return L

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

L = []
for i in range(Num):
    for k in range(Num):
        L.append(length(x[i],y[i],x[k],y[k]))
                 
                 
print(sum(L)/math.factorial(Num))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
 
def length(x,y):
    return np.sqrt(x**2+y**2)

N = int(input())
xy = []
for i in range(N):
    xyi = map(int,input().split())
    xy.append(np.array(list(xyi)))

L=0
for i in range(N):
    for j in range(N):
        d = xy[i] - xy[j]
        l = length(d[0],d[1])
        L += l
nn = math.factorial(N)
ans = L/nn
print(ans)

Submission status: Wrong Answer

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

SUM = 0
CNT = math.factorial(N)
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        else:
            SUM = SUM + math.sqrt((X[i] - X[j])**2 + (Y[i] - Y[j])**2)
            print(i, j, X[i], Y[i], math.sqrt((X[i] - X[j])**2 + (Y[i] - Y[j])**2), SUM)

print(SUM/N, CNT)

Submission status: Wrong Answer

Solution code:
import math
from itertools import permutations 
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
print('a')
print(a)
print()
List = list(range(n))
n_list = list(permutations(List,n))
print('n_list')
print(n_list)
print()
length = 0
LENGTH = 0
for i in range(len(n_list)):
    for j in range(len(n_list[i])):
        if j+1 != n:
            length += math.sqrt((a[n_list[i][j]][0]-a[n_list[i][j+1]][0])**2+(a[n_list[i][j]][1]-a[n_list[i][j+1]][1])**2)
            #print(length)
    #print(length)  
    LENGTH += length
print(length/len(n_list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
import itertools    

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

p = list(itertools.permutations(xy, 2))

sum = 0 
for j in p:
    sum += math.sqrt((int(j[0][0])-int(j[1][0]))**2 + (int(j[0][1])-int(j[1][1]))**2)

ret = sum/len(p)
print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
N = int(input())
xy = [[0,0] for _ in range(N)]
for a in xy:
    a[0], a[1] = map(int, input().split())
x=a[0]
y=a[1]
avg=0
print(avg)

Submission status: Wrong Answer

Solution code:
import itertools
import math

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

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

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

tmp =0

for j in itertools.combinations(s,2):
    tmp += distance(j[0],j[1])

print(tmp*2/n)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import numpy as np

lines = sys.stdin.readlines()

N = int(lines[0].rstrip())
perms = list(itertools.permutations(range(N)))
combs = list(itertools.combinations(range(N), 2))

arr_2d = np.zeros((N,2))
if N <= 2:
	arr_dist_memo = np.zeros((len(combs)+1,len(combs)+1))
else:
	arr_dist_memo = np.zeros((len(combs),len(combs)))

print(np.mean(arr_dist_memo))

Submission status: Wrong Answer

Solution code:
import itertools
import math

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

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

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

tmp =0

for j in itertools.combinations(s,2):
    print(j)
    tmp += distance(j[0],j[1])
    print(tmp)

print(tmp*2/n)

Submission status: Wrong Answer

Solution code:
n=int(input())
towns=[None]*n
for i in range(n):
  x,y=map(int,input().split())
  towns[i]=[x,y]
routes=0
import math
for i in range(len(towns)):
  for j in range(i+1,len(towns)):
    routes+=math.sqrt((towns[i][0]-towns[j][0])**2+(towns[i][1]-towns[j][1])**2)

# routes 全ルートの合計
if n==2:
  print(routes)
else:
  print(routes/n)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

from math import sqrt,factorial

ans = 0

for i in range(n):
  for j in range(n):
    if i == j:
      continue
    
    temp = sqrt((z[i][0] - z[j][0]) ** 2 + (z[i][1] - z[j][1]) ** 2)
    ans += temp

print(ans*2/factorial(n))

Submission status: Wrong Answer

Solution code:
import sys

# import numpy as np
import math
from fractions import gcd
from collections import deque
import bisect

sys.setrecursionlimit(10000)


def main():
    # map(int, input().split())
    # l = list(map(int, input().split()))
    N = int(input())
    x = [0]*N
    y = [0]*N
    for i in range(N):
        x[i], y[i] = map(int, input().split())
    d = [[0]*N for i in range(N)]
    for i in range(N):
        for j in range(N):
            d[i][j] = math.sqrt((x[i] - x[j])**2 + (y[i]-y[j])**2)
    num_sum = math.factorial(N)

    def DFS(cur, i, j, P):
        P |= (1 << j)

        if cur == N:
            return d[i][j]
        elif cur == 1:
            return sum([DFS(cur+1, j, k, P) for k in range(N) if (1 << (k)) & P == 0])
        else:
            return sum([(d[i][j] + DFS(cur+1, j, k, P)) for k in range(N) if (1 << (k)) & P == 0])

    print(sum([DFS(1, -1, i, 0) for i in range(N)]) / num_sum)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

# import numpy as np
import math
from fractions import gcd
from collections import deque
import bisect

sys.setrecursionlimit(10000)


def main():
    # map(int, input().split())
    # l = list(map(int, input().split()))
    N = int(input())
    x = [0]*N
    y = [0]*N
    for i in range(N):
        x[i], y[i] = map(int, input().split())
    d = [[0]*N for i in range(N)]
    for i in range(N):
        for j in range(N):
            d[i][j] = math.sqrt((x[i] - x[j])**2 + (y[i]-y[j])**2)
    num_sum = math.factorial(N)

    def DFS(cur, i, j, P):
        P |= (1 << j)
        print(bin(P))
        print(i, j)
        if cur == N:
            return d[i][j]
        elif cur == 1:
            return sum([DFS(cur+1, j, k, P) for k in range(N) if (1 << (k)) & P == 0])
        else:
            return sum([(d[i][j] + DFS(cur+1, j, k, P)) for k in range(N) if (1 << (k)) & P == 0])

    print(sum([DFS(1, -1, i, 0) for i in range(N)]) / num_sum)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
import math
import itertools
x=[]
y=[]
l=[]
w=[]
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(i+1,n):
        L=((x[i]-x[j])**2 + (y[i]-y[j])**2)**0.5
        l.append(L)

q=list(itertools.permutations(l, n-1))


for i in range(len(q)):
    m=0
    for j in range(n-1):
        m += q[i][j]
    w.append(m)
print(sum(w)/math.factorial(n))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

from math import sqrt,factorial

ans = 0

for i in range(n):
  for j in range(i+1,n):
    temp = sqrt((z[i][0] - z[j][0]) ** 2 + (z[i][1] - z[j][1]) ** 2)
    ans += temp

print(ans/factorial(n))

Submission status: Wrong Answer

Solution code:
n=int(input())
import math
import itertools
x=[]
y=[]
l=[]
w=[]
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(i+1,n):
        L=((x[i]-x[j])**2 + (y[i]-y[j])**2)**0.5
        l.append(L)
print(l)
q=list(itertools.permutations(l, n-1))


for i in range(len(q)):
    m=0
    for j in range(n-1):
        m += q[i][j]
    w.append(m)
print(sum(w)/math.factorial(n))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

leng_list=[]
for i in range(n):
    j = i - 1
    leng_list.append(((x_list[i] - x_list[j])**2 + (y_list[i] - y_list[j])**2)**0.5)

sum_list =[]
for i in range(n):
    j = i - 1
    sum_list.append(leng_list[i] + leng_list[j])


print(sum(sum_list)/n)

Submission status: Wrong Answer

Solution code:
import itertools
import math

data = []
array = []
average = 0
goukei = 0
counter = 0
count = int(input())
for i in range(count):
    array.append(i)
    data.append(input())

# 順列作成
#for i in data:
#    print(i.split())

for order in itertools.permutations(array):
    #(1,3,2),(1,2,3)
    for t in order:
        #(x,y),(x,y)
        counter += 1

        if counter == count:
            break

        x = int(
            int(data[counter - 1].split()[0]) - int(data[counter].split()[0]))
        y = int(
            int(data[counter - 1].split()[1]) - int(data[counter].split()[1]))
        #print(str(t) + "⬇️(" + str(x) + "," + str(y) + ")")
        goukei += math.sqrt(x * x + y * y)

    counter = 0

print(goukei / int(math.factorial(count)))

Submission status: Wrong Answer

Solution code:
from math import sqrt
x=int(input())
l=[]
for __ in range(x):
   a,b=map(int,input().split())
   l.append([a,b])
k=[]   
for i in range(x):
    for j in range(i+1,x):
        k.append(sqrt(pow(l[j][0]-l[i][0],2)+pow(l[j][1]-l[i][1],2)))
print(sum(k)/len(k))

Submission status: Wrong Answer

Solution code:
import math

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

l_s = 0

for i in range(N):
    for j in range(N):
        if i == j:
            pass
        else:
            l_s += 2*(((X[i]-X[j])**2) + ((Y[i]-Y[j])**2)) **(0.5)
l_s

l_r = 0
for i in range(N-1):
    for j in range(i+1,N):
        l_r += (((X[i]-X[j])**2) + ((Y[i]-Y[j])**2)) **(0.5)

l_r = l_r * 2

ans = (l_s - l_r)
print(ans)

Submission status: Wrong Answer

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

# 町の数(整数)の入力
N = int(input())

i = 1
x_i = []
y_i = []

while i <= N:
    # スペース区切りの整数の入力
    x, y = map(int, input().split())
    
    x_i.append(x)
    y_i.append(y)
    
    i += 1


print(x_i,y_i,math.factorial(N))

Submission status: Wrong Answer

Solution code:
N = int(input())
l = []

def kaijo(n):
    
    if n == 1:
        return n
    elif n == 0:
      return 1
    return n * kaijo(n-1)
for i in range(N):
  a = list(map(int, input().split()))
  l.append(a)
import numpy as np
l = np.array(l)
dist = []
for i in range(N):
  for j in range(i+1, N):
    dist.append(np.linalg.norm(l[i]- l[j]))
dist = np.array(dist)*kaijo(N)-np.array(dist)*kaijo(N-2)*2
print(np.sum(dist)/kaijo(N))

Submission status: Wrong Answer

Solution code:
import itertools
import math

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

lst = list(itertools.permutations(xbox))

num = 0
for i in range(len(lst)-1):
    for j in range(N-1):
        line = ((lst[i][j][0]-lst[i][j+1][0])**2 +  (lst[i][j][1]-lst[i][j+1][1])**2)**0.5
        num += line

print(num/len(lst))

Submission status: Wrong Answer

Solution code:
from math import sqrt
from math import factorial

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

Submission status: Wrong Answer

Solution code:
import math
from itertools import permutations

N = int(input())
c = list()
for n in range(N):
  x, y = list(map(int, input().split()))
  c.append((x, y))

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

L = 0
A = 0
for i in list(permutations(range(len(c)))):
  for j in range(len(i)-1):
    L += length(c[j], c[j+1])
  A += L
print(A/len(c))

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
CNT = math.factorial(N)
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        else:
            SUM = SUM + math.sqrt((X[i] - X[j])**2 + (Y[i] - Y[j])**2) 

print(SUM/CNT)

Submission status: Wrong Answer

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

List = list(range(n))
n_list = list(permutations(List,n))

length = 0
LENGTH = 0
for i in range(len(n_list)):
    Tuple = n_list[i]
    length = 0
    for j in range(n):
        if Tuple[j+1] == Tuple[-1]:
            length += math.sqrt((a[j][0]-a[j+1][0])**2+(a[j][1]-a[j+1][1])**2)
            break
        else:
            length += math.sqrt((a[j][0]-a[j+1][0])**2+(a[j][1]-a[j+1][1])**2)
            
    LENGTH += length
print(int(LENGTH/math.factorial(n)))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
city = []
l=[]
def sousu(N):
    s=0
    for i in range(N-1):
        s += math.factorial(N)/math.factorial(i)
    return s
for i in range(N):
    city.append(list(map(int, input().split())))
for j in range(N):
    for k in range(N-j-1):
        l.append( ((city[j][0]-city[N-k-1][0])**2 +(city[j][1]-city[N-k-1][1])**2)**0.5*sousu(N)/ (math.factorial(N) / math.factorial(2) / math.factorial(N- 2) ) )
#print(sum(l)/math.factorial(N)*sousu(N)/ (math.factorial(N) / math.factorial(2) / math.factorial(N- 2) ))
print(sum(l)/math.factorial(N))

Submission status: Wrong Answer

Solution code:
import math
import itertools

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

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)

m = []
for i in itertools.permutations(range(N)):
    m.append(i)

ans = 0
for i in range(math.factorial(N)):
    print(i)
    x0 = 0
    y0 = 0
    for j in range(N):
        ans += distance(x[m[i][j]],y[m[i][j]],x0, y0)
        x0 = x[m[i][j]]
        y0 = y[m[i][j]]

print(ans / math.factorial(N))

Submission status: Wrong Answer

Solution code:
import math

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

dist = [[0 for a in range(N)] for b in range(N)]

def calcdist(i, j):
  if i > j:
    return dist[j][i]
  else:
    return dist[i][j]

for i in range(N):
  for j in range(i, N):
    if i != j:
      x_i = XY[i][0]
      y_i = XY[i][1]
      x_j = XY[j][0]
      y_j = XY[j][1]
      dist[i][j] = math.sqrt((x_i-x_j)**2 + (y_i-y_j)**2)

def calctotal(mem, current):
  newmem = list(mem)
  newmem[current] = 1
  total = 0
  for next in range(N):
    if newmem[next] == 0:
      total = total + dist[current][next] + calctotal(newmem, next)
  return total

totaldistance = 0
for i in range(N):
  result = calctotal([0 for a in range(N)], i)
  totaldistance = totaldistance + result
print(totaldistance*2/math.factorial(N))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import math

def main():
  n = int(input())
  cities = []
  for i in range(0, n):
    inputs = input().split(" ")
    cities.append([int(inputs[0]), int(inputs[1])])
  
  result = 0
  for i in range(0, n-1):
    for j in range(i+1, n):
      result += distance(cities[i], cities[j])
  
  print((result*(factorial(n)-2*factorial(n-2)))/factorial(n))

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

def distance(pos1, pos2):
  return math.sqrt(math.pow(pos1[0] - pos2[0], 2) + math.pow(pos1[1] - pos2[1], 2))

main()

Submission status: Wrong Answer

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

List = list(range(n))
n_list = list(permutations(List,n))

length = 0
LENGTH = 0
for i in range(len(n_list)):
    Tuple = n_list[i]
    length = 0
    for j in range(n):
        if Tuple[j+1] == Tuple[-1]:
            length += math.sqrt((a[j][0]-a[j+1][0])**2+(a[j][1]-a[j+1][1])**2)
            break
        else:
            length += math.sqrt((a[j][0]-a[j+1][0])**2+(a[j][1]-a[j+1][1])**2)
            
    LENGTH += length
print(LENGTH/math.factorial(n))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

N = int(input())

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

for i in range(N-1):
    for j in range(i+1, N):
        ans += np.sqrt((A[i][0]-A[j][0])**2+(A[i][1]-A[j][1])**2)
        
f = math.factorial(N)
if N >2:
    ans *= (f-2*math.factorial(N-2)) / f
#ans *= N*(N-1)*(N-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import sqrt
input = sys.stdin.readline
N = int(input())
p = []
for _ in range(N):
  p.append(list(map(int, input().split())))
def dist(x1, y1, x2, y2):
  return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
res = 0
vis = set()
c = [0] * N
def dfs(n):
  global vis
  global c
  r = 0
  vis.add(n)
  for x in range(N):
    if x in vis: continue

    r += dfs(x) + dist(p[n][0], p[n][1], p[x][0], p[x][1])

  vis.discard(n)
  return r
res = 0
for y in range(N):
  vis = set()

  res += dfs(y)


for i in range(1, N + 1):
  res /= i
  #print(res)
print(res)

Submission status: Wrong Answer

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

print(sum*ss[N]/N)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from math import sqrt
from math import factorial

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

Submission status: Wrong Answer

Solution code:
N=int(input())
XY=[list(map(int,input().split())) for i in range(N)]
print(XY)
value=0
for i in range(N):
    for m in range(i+1,N):
        print(i,m)
        x0,y0,x1,y1=XY[i][0],XY[i][1],XY[m][0],XY[m][1]
        print(x0,y0,x1,y1)
        print(value,i,m)
        value+=(((x0-x1)**2+(y0-y1)**2)**0.5)
print(value*2/N)

Submission status: Wrong Answer

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

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

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