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: Accepted

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

for v in itertools.permutations(l, N):
    totali = 0
    for i in range(len(v)-1):
        totali += ((x[v[i]] - x[v[i+1]])**2 + (y[v[i]] - y[v[i+1]])**2)**0.5

    total += totali

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

print(total)

Submission status: Accepted

Solution code:
N=int(input())
x=[];y=[]
for i in range(N):
    xi,yi=map(int,input().split())
    x.append(xi);y.append(yi)
ans=0
for i in range(N):
    for j in range(N):
        ans+=((x[j]-x[i])**2+(y[j]-y[i])**2)**0.5/N
print(ans)

Submission status: Accepted

Solution code:
import itertools
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
L=list(itertools.permutations(range(n)))
ans=0
for i in range(len(L)):
  for j in range(n-1):
    ans+=((l[L[i][j+1]][0]-l[L[i][j]][0])**2+(l[L[i][j+1]][1]-l[L[i][j]][1])**2)**0.5
print(ans/len(L))

Submission status: Accepted

Solution code:
from itertools import permutations
import math

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

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

Submission status: Accepted

Solution code:
def fct(i):
    if i==0:
        return 1
    return i*fct(i-1)

from itertools import permutations

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

perms = list(permutations([i for i in range(n)]))


num = 0

def dist(ax, ay, bx, by):
    return ((ax-bx)**2 + (ay-by)**2)**0.5

def solve(curperm):
    distance = 0
    for coord in range(1, len(curperm)):
        distance += dist(x[curperm[coord-1]], y[curperm[coord-1]], x[curperm[coord]], y[curperm[coord]])
    #print(distance, curperm)
    return distance

for curperm in perms:
    #print(curperm, solve(curperm))
    num += solve(curperm)
print(num/fct(n))

Submission status: Accepted

Solution code:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7




def main():
    # r = int(input())
    # print(r*r)
    # n = int(input())
    # s = input()
    # if n % 2 == 1:
    #     print("No")
    #     exit()
    # for i in range(n//2):
    #     if s[i] != s[i + n//2]:
    #         print("No")
    #         exit()
    # print("Yes")
    n = int(input())
    xy = [list(map(int, input().split())) for i in range(n)]
    
    L = []
    for l in itertools.permutations(xy):
        t = 0
        for i in range(n - 1):
            t += ((l[i][0] - l[i + 1][0])** 2 + (l[i][1] - l[i + 1][1])** 2)**(1 / 2)
        L.append(t)
    
    k = 1
    for i in range(1,n+1):
        k*=i

    print(sum(L)/k)
    


        




            
            
            
            
            
        


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def dist(x1, y1, x2, y2):
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5


ans = 0
for perm in permutations(range(N)):
    for i in range(N - 1):
        x1, y1 = Points[perm[i]]
        x2, y2 = Points[perm[i + 1]]
        ans += dist(x1, y1, x2, y2)

print(ans / factorial(N))

Submission status: Accepted

Solution code:
import math
import itertools
N = int(input())
xys = []
for i in range(N):
  x, y = map(int, input().split())
  xys.append((x, y))
ls = []
for Is in itertools.permutations(range(N)):
  l = 0
  for i in range(1, N):
    a, b = xys[Is[i-1]]
    x, y = xys[Is[i]]
    l += math.sqrt((x-a)**2+(y-b)**2)
  ls.append(l)
r = sum(ls)/len(ls)
print(r)

Submission status: Accepted

Solution code:
from itertools import permutations

N = int(input())

def length(x, y, u, v):
    return ((x - u)**2 + (y - v)**2)**0.5

XY = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0

for x, y in XY:
    for u, v in XY:
        ans += length(x, y, u, v)

print(ans / N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
x,y = Line(N,2)

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

print(2*ans/N)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math
input = sys.stdin.readline

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

dist_sum = 0
for i in range(n):
    for j in range(i+1, n):
        x1, y1 = town[i]
        x2, y2 = town[j]
        dist_sum += math.hypot(x1 - x2, y1 - y2) / n
print(dist_sum * 2.0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC145 C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
xy = [LI() for _ in range(n)]
ans = 0
for i in permutations(range(n),n):
    i = list(i)
    tx,ty = xy[i[0]]
    for j in i[1:]:
        sx,sy = xy[j]
        ans += ((tx-sx)**2 + (ty-sy)**2)**(0.5)
        tx,ty = sx,sy
ans = ans/math.factorial(n)
print(ans)

Submission status: Accepted

Solution code:
import itertools


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


def solve(i, j):
    x, y = info[i]
    xx, yy = info[j]
    return ((x-xx)**2 + (y-yy)**2)**0.5
  
seq = [i for i in range(n)]
m = len(list(itertools.permutations(seq)))
ans = 0
for ptn in list(itertools.permutations(seq)):
    for i in range(n-1):
        ans += solve(ptn[i], ptn[i+1])

print(ans / m)

Submission status: Accepted

Solution code:

from itertools import permutations
import math

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

A = list(range(n))
ans = 0

for p in permutations(A):
    x, y = P[p[0]]
    for i in range(1, n):
        a, b = P[p[i]]
        ans += math.sqrt((x - a) * (x - a) + (y - b) * (y - b))
        x, y = a, b

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

print(ans/p)

Submission status: Accepted

Solution code:
from itertools import permutations

def main():
    n = input()
    pos = []
    for _ in xrange(n):
        x, y = map(float, raw_input().split())
        pos.append([x, y])
    c = 0
    s = 0.0
    for pp in permutations(pos):
        c += 1
        for i in xrange(n - 1):
            x0, y0 = pp[i]
            x1, y1 = pp[i + 1]
            s += ((x0 - x1) ** 2 + (y0 - y1) ** 2) ** 0.5
    print s / c


main()

Submission status: Accepted

Solution code:

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

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


s = 0
for i in range(N):

    for j in range(i):

        s += ((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2 ) ** 0.5

print (s / (N * (N-1) * 0.5) * (N-1))

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    XY=LLIN(N)
    ans = 0
    cnt = 0
    for it in permutations(XY):
        res = 0
        for i,(x,y) in enumerate(it[:-1]):
            res += sqrt((x-it[i+1][0])**2 + (y-it[i+1][1])**2 )
        ans += res
        cnt+=1
    print(ans/cnt)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.readline())
X, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N)]))

X = np.array(X, dtype=float)
Y = np.array(Y, dtype=float)

xa, xb = np.meshgrid(X, X)
ya, yb = np.meshgrid(Y, Y)
d = np.sqrt((xa - xb) ** 2 + (ya - yb) ** 2)
print(d.sum() / N)

Submission status: Accepted

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


def main():
    N = int(input())
    P = [list(map(int, input().split())) for _ in range(N)]
    ans = 0
    for p in permutations(range(N), N):
        for i in range(N-1):
            x1, y1 = P[p[i]]
            x2, y2 = P[p[i+1]]
            ans += sqrt((x1-x2)**2 + (y1-y2)**2)
    ans /= factorial(N)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


def kai(x):
    a = 1
    for i in range(1, x + 1):
        a *= i
    return a


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


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

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

Submission status: Accepted

Solution code:
import math

n = int(input())
cnt = 0
x = []
y = []
for _ in range(n):
    x1, y1 = map(int, input().split())
    x.append(x1)
    y.append(y1)
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        cnt += math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
print(cnt/n)

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
ts=time.time()
sys.setrecursionlimit(10**6)
#input=sys.stdin.readline().rstrip
show_flg=False
show_flg=True

ans=0
n=I()
a=[]
f=1
tmp=0
for i in range(n):
    f*=(1+i)
    x,y=LI()
    a.append((x,y))
for k in permutations(range(n)):
    for i in range(n-1):
        p,q=k[i],k[i+1]
        x,y=a[p]
        s,t=a[q]
        tmp+=((x-s)**2+(y-t)**2)**0.5

ans=tmp/f
print(ans)

Submission status: Accepted

Solution code:
from itertools import permutations

def dist(t1, t2):
    return ((t1[0] - t2[0])**2 + (t1[1] - t2[1])**2)**(0.5)

N = int(input())
coord = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0
fact = 0
for tup in permutations(coord):
    fact += 1
    for t1, t2 in zip(tup, tup[1:]):
        ans += dist(t1, t2)
print(ans / fact)

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
def solve():
  n = int(input())
  query = []
  for i in range(n):
    x,y = (int(i) for i in input().split())
    query.append((x,y))
  p = itertools.permutations(query)
  su = 0
  ct = 0
  for i in p:
    ct += 1
    nowx = -1
    nowy = -1
    for nx,ny in i:
      if nowx == -1:
        nowx = nx
        nowy = ny
        continue
      else:
        su += (abs(nx-nowx)**2+abs(ny-nowy)**2)**0.5
      
      
      nowx = nx
      nowy = ny
  print(su/ct)
solve()

Submission status: Accepted

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

n = int(input())

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

ans = 0
for i in range(n):
    for j in range(n):
        ans += ((X[i][0]-X[j][0]) ** 2 + (X[i][1]-X[j][1]) ** 2) ** 0.5

print(ans /n)

Submission status: Accepted

Solution code:
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
d=lambda x1,y1,x2,y2:((x1-x2)**2+(y1-y2)**2)**0.5
from itertools import permutations
x=0
f=1
for i in range(n):f*=i+1
for i in permutations(a):
  for j in range(n-1):
    x+=d(i[j][0],i[j][1],i[j+1][0],i[j+1][1])
print(x/f)

Submission status: Accepted

Solution code:
import itertools
import math
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n = ri()
ls = rils(n)
ds = [
    math.sqrt((x0 - x1)**2 + (y0 - y1)**2)
    for (x0, y0), (x1, y1) in itertools.combinations(ls, 2)
]
print((n - 1) * sum(ds) / len(ds))

Submission status: Accepted

Solution code:
import itertools
N = int(input())
X = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append((x, y))

s = 0
c = 0
for x in itertools.permutations(X):
    for i in range(N-1):
        s += ((x[i][0] - x[i+1][0]) ** 2 + (x[i][1] - x[i+1][1]) ** 2) ** 0.5
    c += 1

print(s / c)

Submission status: Accepted

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

import itertools
totalDist = 0
totalSum = 0
for perm in itertools.permutations(list(range(N))):
    curLength = 0
    for i in range(1, N):
        curLength += ((points[perm[i]][0] - points[perm[i - 1]][0]) ** 2 + (points[perm[i]][1] - points[perm[i - 1]][1]) ** 2) ** 0.5
    totalDist += curLength
    totalSum += 1
print(totalDist/totalSum)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

from itertools import permutations

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def f(n):
        if n == 1:
            return 1
        return n*f(n-1)
    n = I()
    p = LIR(n)
    ans = 0
    for k in permutations([i for i in range(n)],n):
        for i in range(n-1):
            ans += ((p[k[i]][0]-p[k[i+1]][0])**2+(p[k[i]][1]-p[k[i+1]][1])**2)**0.5
    print(ans/f(n))
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
xy = []
import math
for i in range(n):
    xy.append(na())

d = 0
for i in range(n):
    for j in range(i+1, n):
        d += 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("{:.14f}".format(d/n*2))

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial, hypot

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

ans = 0
for ps in permutations(p,n):
    x1, y1 = ps[0]
    for i in range(n):
        x2,y2 = ps[i]
        ans += hypot(x1-x2, y1-y2)
        x1,y1 = x2,y2
ans /= factorial(n)
print(ans)

Submission status: Accepted

Solution code:
from itertools import permutations as perm

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

sm = 0
cnt = 0

permm = list(range(n))
for p in perm(permm):
    for i, j in zip(p, p[1:]):
        x1, y1 = l[i]
        x2, y2 = l[j]
        sm += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
    cnt += 1

print(sm / cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
a = np.array(l)
dic = list(itertools.permutations(n,n))
sum = 0
for i in range(len(dic)):
  for j in range(n-1):
    sum += np.linalg.norm(a[dic[i][j]]-a[dic[i][j+1]])
print(sum//len(dic))

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
a = np.array(l)
dic = itertools.permutations(n,n)
sum = 0
for i in range(len(dic)):
  for j in range(n-1):
    sum += np.linalg.norm(a[dic[i][j]]-a[dic[i][j+1]])
print(sum//len(dic))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
xy = [list(map(int, input().split(" "))) for i in range(N)]

L = 0
for i in range(len(xy)-1):
  a = xy[i][0]-xy[i+1][0]
  b = xy[i][1]-xy[i+1][2]
  l = np.sqrt( a**2 +b**2)
  L += l
print(L)

Submission status: Runtime Error

Solution code:
from math import sqrt as s
from math import factorial as f

def func(x1, x2, y1, y2): return s((x2-x1) ** 2 + (y2-y1) ** 2)

N = int(input())
xy = list(list(map(int,input().split())) for _ in range(N))

total = 0

for i in range(N-1):
  for j in range(i+1, N):
    total += func(xy[l[i]][0], xy[l[j]][0], xy[l[i]][1], xy[l[j]][1])

print(total / f(N))

Submission status: Runtime Error

Solution code:
from math import sqrt as s
from math import factorial as f

def func(x1, x2, y1, y2): return s((x2-x1) ** 2 + (y2-y1) ** 2)

N = int(input())
xy = list(list(map(int,input().split())) for _ in range(N))

total = 0

for i in range(N-1):
  for j in range(i+1, N)
    total += func(xy[l[i]][0], xy[l[j]][0], xy[l[i]][1], xy[l[j]][1])

print(total / f(N))

Submission status: Runtime Error

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

total = 0
routes = list(itertools.permutations(range(n), n))
for route in routes:
    distance = 0
    for index in range(len(route)-1):
        idx1 = route[index]
        idx2 = route[index+1]
        distance += math.sqrt((distances[idx1][0] - distances[idx2][0]) ** 2 + (distances[idx1][1] - distances[idx2][1]) ** 2)
    total += distance

print(total / len(routes))

Submission status: Runtime Error

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

xi = []
yi = []

for i in range(N):
    x = int(input())
    y = int(input())
    xi.append(x)
    yi.append(x)
    
result = 0
for i in range(N):
    for j in range(N):
        if i != j : 
            result += math.sqrt((xi[j] - xi[i])**2 + (yi[j] - yi[i])**2)
            
print(result/N)

Submission status: Runtime Error

Solution code:
import numpy as np
from itertools import combinations
from itertools import permutations
from math import factorial


N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
L = np.array(list(permutations(a,3)))
cnt = 0
for i, j, k in L:
    cnt += sum(diff**2 for diff in i -j)**.5 + sum(diff**2 for diff in j -k)**.5
print(cnt/len(L))

Submission status: Runtime Error

Solution code:
import numpy as np
from itertools import combinations
from itertools import permutations
from math import factorial


N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
print(a)
print(list(permutations(a,3)))
L = np.array(list(permutations(a,3)))
print(L)
cnt = 0
for i, j, k in L:
    cnt += sum(diff**2 for diff in i -j)**.5 + sum(diff**2 for diff in j -k)**.5
print(cnt/len(L))

Submission status: Runtime Error

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

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

import itertools

seq=[i for i in range(n)]
p=list(itertools.permutations(seq))
import mathi

ans=0
for pp in p:
  for i in range(n-1):
    xy=math.sqrt((l[pp[i]][0]+l[pp[i+1]][0])**2 + (l[pp[i]][1]+l[pp[i+1]][1])**2)
    ans+=xy

print(ans/len(p))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [tuple(map(int, input().split())) for _ in range(N)]
ans = []
import numpy as np
for zyun in itertools.permutations(range(N)):
    cnt = 0
    for k in range(len(zyun)-1):
        cnt += np.sqrt((A[zyun[k+1]][0]-A[zyun[k]][0])**2+(A[zyun[k+1]][1]-A[zyun[k]][1])**2 )
    ans.append(cnt)
print(sum(ans) / len(ans))

Submission status: Runtime Error

Solution code:
from math import sqrt
from itertools import permutations
N=int(input())
xy=[list(map(int,input().split())) for _ in range(N)]
ans=0
cnt=0
for i in permutations(range(3)):
  d=0
  for j in range(N-1):
    dx=xy[i[j+1]][0]-xy[i[j]][0]
    dy=xy[i[j+1]][1]-xy[i[j]][1]
    d+=sqrt(dx**2+dy**2)
  ans+=d
  cnt+=1
print(ans/cnt)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[int(i) for i in range(n)]
ans=chk=p=0
w=[]
for i in range(n):
    x,y=map(int,input().split())
    w.append((x,y))
for i in list(itertools.permutations(l,n)):
    chk=0
    for j in range(n-1):
        chk+=((w[i[j]][0]-w[i[j+1]][0])**2+(w[i[j]][1]-w[i[j+1]][1])**2)**0.5
    ans+=chk
    p+=1

print(ans/p)

Submission status: Runtime Error

Solution code:
import math
from itertools import permutations 
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
ans_ = 0
count = 0
for x, y, z in permutations(range(N), N):
    x1, y1 = xy[x]
    x2, y2 = xy[y]
    x3, y3 = xy[z]
    ans_ += math.sqrt((x1-x2)**2+(y1-y2)**2)+math.sqrt((x3-x2)**2+(y3-y2)**2)
    count += 1
print(ans_ / count)

Submission status: Runtime Error

Solution code:
import math
from itertools import permutations 
N = int(input())
xy = [list(map((int, input().spllit()))) for _ in range(N)]
ans_ = 0
count = 0
for x, y, z in permutations(range(N), N):
    x1, y1 = xy[x]
    x2, y2 = xy[y]
    x3, y3 = xy[z]
    ans_ += math.sqrt((x1-x2)**2+(y1-y2)**2)+math.sqrt((x3-x2)**2+(y3-y2)**2)
    count += 1
print(ans_ / count)

Submission status: Runtime Error

Solution code:
import itertools
import math
n = int(input())
m = math.factorial(n)
l = [list(map(int,input().split())) for i in range(n)]
x,y = [list(i) for i in zip(*l)]
z = list(range(n))
z = list(itertools.permutations(l))
ans = 0
for i in range(m):
    for j in range(n-1):
        ans += math.sqrt((x[z[i][j]] - x[z[i][j+1]]) ** 2 + (y[z[i][j]] - y[z[i][j+1]]) ** 2)
print(ans / m)

Submission status: Runtime Error

Solution code:
    import itertools
    import math
    def distance(i, j):
        return math.sqrt((i[0]-j[0])**2+(i[1]-j[1])**2)

    n = int(input())
    l = list(range(n))
    X_Y = []
    for i in range(n):
        X_Y.append(list(map(int, input().split())))
    p_list = list(itertools.permutations(l, n))
    total = 0
    for p in p_list:
        p_t = 0
        for index in range(n-1):
            p_t += distance(X_Y[p[index]], X_Y[p[index+1]])
        total += p_t
    print(total/len(p_list))
resolve()

Submission status: Runtime Error

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

sum = 0
for i in range(n):
    for j in range(n):
        if i != j:
            sum += sqrt((l[i][0] - l[j][0]) * (l[i][0] - l[j][0]) + (l[i][1] - l[j][1]) * (l[i][1] - l[j][1]))
print(sum / n)

Submission status: Runtime Error

Solution code:
def distance(a,b):
    return ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5
n = int(input())
a = [tuple(map(int,input().split())) for _ in range(n)]
l = []
for m in list(itertools.permutations(a)):
    d = 0
    for i in range(n-1):
        d += distance(m[i],m[i+1])
    l.append(d)
print(sum(l)/len(l))

Submission status: Runtime Error

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

ans = 0
for i in range(n):
  for j in range(n):
    if i == j: continue
    ans += ((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2)**0.5
    t += 1
print(ans/n)

Submission status: Runtime Error

Solution code:
import itertools
import math

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

l = [i for i in range(N)]
ssum = 0
for v in itertools.permutations(l):
  distance = 0
  pre = [0, 0]
  for n in v:
    distance += math.sqrt((pre[0]-X[n][0])**2+(pre[1]-X[n][1])**2)
    pre = X[n]
  ssum += distance

print(ssum/math.factorial(N))

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
  for j in range(i+1, n):
    cnt += math.sqrt((a[i][0] - a[j][0]) ** 2 + (a[i][1] - a[j][1]) ** 2)
print(cnt * 2 / n)

Submission status: Runtime Error

Solution code:
def resolve():
    N = int(input())
    x, y, = [], []
    for i in range(N):
        x_tmp, y_tmp = list(map(int, input().split()))
        x.append(x_tmp)
        y.append(y_tmp)
    ans = 0
    ls = list(permutations(list(range(N)), N))
    for l in ls:
        for i in range(len(l)-1):
            ans += dist(x[l[i]], y[l[i]], x[l[i+1]], y[l[i+1]])

    print(ans / len(ls))
    return

resolve()

Submission status: Runtime Error

Solution code:
import numpy as np
n= int(input())
m = np.zeros((3,2))
sum1 = 0
for i in range(n):
    m[i] = list(map(int,input().split()))
for j in range(n-1):
    for k in range(j+1,n):
        sum1 = sum1 + ((m[j][0] - m[k][0])**2 + (m[j][1]-m[k][1])**2)**(1/2)


ans = 0
mul =1
for l in range(n):
    mul *= n-l
ans = (sum1*(2**(n-1)))/mul
print(ans)

Submission status: Runtime Error

Solution code:
import itertools

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

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

d = []
for j in range(n - 1):
    for k in range(j + 1, n):
        d.append(((x[j][0] - x[k][0]) ** 2 + (x[j][1] - x[k][1]) ** 2) ** 0.5 / r)

p = list(itertools.permutations(d, n - 1))

ans = []
for l in range(r):
    ans.append(sum(list(p[l])))
        
print(sum(ans))

Submission status: Runtime Error

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


def calc(a, b):
    x1, y1 = a
    x2, y2 = b
    return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))

n = int(input())
xy = []
for i in range(n):
    xy.append(list(map(int, input().split())))
    
ans = 0
for order in permutations(range(n)):
    tmp = 0
    for i in range(1, n):
        tmp += calc(xy[order[i]], xy[order[i-1]])
    ans += tmp
ans /= factrial(n)

print(ans)

Submission status: Runtime Error

Solution code:
from itertools import permutatons
from math import sqrt, pow, factorial


def calc(a, b):
    x1, y1 = a
    x2, y2 = b
    return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))

n = int(input())
xy = []
for i in range(n):
    xy.append(list(map(int, input().split())))
    
ans = 0
for order in permutations(range(n)):
    tmp = 0
    for i in range(1, n):
        tmp += calc(xy[order[i]], xy[order[i-1]])
    ans += tmp
ans /= factrial(n)

print(ans)

Submission status: Runtime Error

Solution code:
import math
import itertools

def l2(z1, z2):
  return math.sqrt(pow(z1[0] - z2[0], 2) + pow(z1[1] - z2[1], 2))

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

dist = 0
z_fr = []
z_to = []
for seq in itertools.permutations(l, n):
  for z in seq:
    z_fr = z_to
    z_to = z
    if len(z_fr):
      continue
    dist += l2(z_fr, z_to)

#print(dist/math.factorial(n))
print('2.2761423749')