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

Solution (Python):
import numpy as np
import scipy
from scipy.spatial import distance_matrix

N = int(input())

cords = []
for _ in range(N):
  sp = input().split()
  x, y = float(sp[0]), float(sp[1])
  cords.append([x, y])

cords = np.array(cords)
d = distance_matrix(cords, cords)
np.fill_diagonal(d, 0)
print(d.sum()/cords.size*2)

Solution (Python):
import math

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

Solution (Python):
from itertools import permutations
import math

n = int(input())
P = []
for _ in range(n):
    P.append(tuple(map(int, input().split())))
distance = 0
for array in permutations(P):
    for i in range(n - 1):
        p1 = array[i]
        p2 = array[i + 1]
        diff_x = p1[0] - p2[0]
        diff_y = p1[1] - p2[1]
        distance += math.sqrt(diff_x ** 2 + diff_y ** 2)
print(distance / math.factorial(n))

Solution (Python):

import sys
import math
INF = float("inf")


def cmb(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    if r == 1:
        return n

    numer = [n - r + k + 1 for k in range(r)]
    denom = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denom[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numer[k - offset] /= pivot
                denom[k] /= pivot

    result = 1
    for k in range(r):
        if numer[k] > 1:
            result *= int(numer[k])

    return result


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


def solve(N: int, x: "List[int]", y: "List[int]"):
    tot = 0
    for i in range(N):
        for j in range(i+1, N):
            tot += math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
    tot *= 2/N
    print(tot)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    x = [int()] * (N)  
    y = [int()] * (N)  
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)


if __name__ == '__main__':
    main()

Solution (Python):
import math, itertools
N = int(input())
Ax = []
Ay = []
for _ in range(N):
    x, y = map(int, input().split())
    Ax.append(x)
    Ay.append(y)

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

    
Ncomb = N * (N - 1) // 2

Npair = Nperm * (N - 1) // Ncomb

ans = 0
for c in itertools.combinations(range(N), 2):
    p1, p2 = c
    ans += math.sqrt((Ax[p1] - Ax[p2])**2 + (Ay[p1] - Ay[p2])**2) * Npair

print(ans / Nperm)

Solution (Python):
import math
import itertools

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

sum = 0
for towns in list(itertools.permutations(towns)):
    for i in range(n - 1):
        sum += math.sqrt((towns[i][0] - towns[i + 1][0]) ** 2 + (towns[i][1] - towns[i + 1][1]) ** 2)

print(sum / math.factorial(n))

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

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

for i in range(n):
  for j in range(i+1, n):
    ds.append(math.sqrt((m[i][0]-m[j][0])**2+(m[i][1]-m[j][1])**2))
ps = math.factorial(n)

print(sum(ds)*(n-1)/len(ds))

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

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

Solution (Python):
import numpy as np

N = int(input())
XY = np.empty([N,2])
for i in range(N):
    XY[i] = list(map(int, input().split()))

ans = 0.0
for i in range(N):
    for j in range(i+1,N):
        ans += np.sqrt(np.sum(np.square(XY[i]-XY[j])))
ans = ans*2/N

print(ans)

Solution (Python):
import numpy as np

N = int(input())
XY = np.empty([N,2])
for i in range(N):
    XY[i] = list(map(int, input().split()))

ans = 0.0
for i,a in enumerate(XY):
    for b in XY[i+1:]:
        ans += np.sqrt(np.sum(np.square(a-b)))
ans = ans*2/N

print(ans)

Solution (Python):
import itertools

N = int(input())
x, y = [], []
for _ in range(N):
    _x, _y = map(int, input().split())
    x.append(_x)
    y.append(_y)

ans = 0
paths = list(itertools.permutations(range(N)))
for p in paths:
    for i in range(N-1):
        s = p[i]
        d = p[i+1]
        ans += ((x[s] - x[d]) ** 2 + (y[s] - y[d]) ** 2) ** 0.5
ans /= len(paths)
print(ans)

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

def get_dist(i,j):
  return ((i[0] - j[0])**2 + (i[1] - j[1])**2) ** 0.5

leng = [get_dist(i,j) for i,j in itertools.product(l,l)]
print(sum(leng)/n)

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

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

Solution (Python):
n = int(input())

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

Solution (Python):
from math import sqrt
n = int(input())
a = []
for i in range(n):
  x,y=map(int,input().split())
  t = (x,y)
  a.append(t)
d,f=0,0
for i in range(n-1):
  for j in range(i+1,n):
    r = sqrt((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)
    d+=(n-1)*r
  f+=(i+1)
print(d/f)

Solution (Python):
from itertools import permutations
from math import factorial


class Point:
    def __init__(self, y, x):
        self.y = y
        self.x = x


def main():
    N = int(input())
    xy = []
    for i in range(N):
        xi, yi = map(int, input().split())
        xy.append(Point(yi, xi))
    ans = 0
    for i in permutations(xy):
        for j in range(N - 1):
            ans += ((i[j + 1].y - i[j].y) ** 2 +
                    (i[j + 1].x - i[j].x) ** 2) ** 0.5
    print('{:.10f}'.format(ans / factorial(N)))
    return


main()

Solution (Python):
n,*z=[list(map(int,t.split()))for t in open(0)];
print(sum(((a-x)**2+(b-y)**2)**.5for a,b in z for x,y in z)/n[0])

Solution (Python):




import math


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+=math.sqrt((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)
print(ans/n)

Solution (Python):
from math import *

def kaijou(n):
    ka = 1
    for e in range(1,n+1):
        ka *= e
    return ka

N = int(input())


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

all_distances = []

for i in range(N-1):
    for j in range(i+1,N):
        all_distances.append(sqrt(pow(coordinates[i][0]-coordinates[j][0],2) + pow(coordinates[i][1]-coordinates[j][1],2)))


sum_distances = sum(all_distances)

ans = (sum_distances ) * 2   /   N

print(ans)

Solution (Python):
import itertools,math
N=int(input())
nl=[i for i in range(N)]
x=[]
y=[]
d=0
for _ in range(N):
	X,Y=[int(i) for i in input().split()]
	x.append(X)
	y.append(Y)
per_nl=list(itertools.permutations(nl))
for k in per_nl:
	for i in range(N-1):
		d+=((x[k[i+1]]-x[k[i]])**2+(y[k[i+1]]-y[k[i]])**2)**(0.5)
print(d/math.factorial(N))

Solution (Python):
N = int(input())

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

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

print(s*2/N)

Solution (Python):
n = int(input())
l = [[int(i) for i in input().split()] for _ in range(n)]
import math
distance = 0
for i in l:
    for j in l:
        distance += ((i[0] - j[0])**2 + (i[1] - j[1])**2)**0.5*math.factorial(n-1)
        
print(distance/math.factorial(n))

Solution (Python):
n = int(input())
l = [[int(i) for i in input().split()] for _ in range(n)]

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

Solution (Python):
N = int(input())
M = [0]*N
edge = [0]*N
for i in range(N):
  edge[i]=[0]*N
sum=0
for i in range(N):
    M[i] = list(map(int,input().split()))
for i in range(N):
    for k in range(i+1,N):
        edge[i][k] = pow(((M[i][0]-M[k][0])**2 + (M[i][1]-M[k][1])**2),0.5)
        sum+=edge[i][k]
average = sum/N*2
print(average)

Solution (Python):
import math

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

def calc_distance(a, b):
    return math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)
num = 0
d = 0
for i in range(N):
    for j in range(i+1, N):
        num += 1
        d += calc_distance(coordinates[i], coordinates[j])

print(d / N * 2)

Solution (Python):
import numpy as np
from math import sqrt,factorial
N = int(input())
M = [0]*N
edge = np.zeros([N,N])
sum=0
for i in range(N):
    M[i] = list(map(int,input().split()))
for i in range(N):
    for k in range(i+1,N):
        edge[i,k] = sqrt((M[i][0]-M[k][0])**2 + (M[i][1]-M[k][1])**2)
        sum+=edge[i,k]
average = sum/N*2
print(average)

Solution (Python):
import math

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

dist = 0
for i, xyi in enumerate(xy):
    for xyj in xy[i+1:]:
        dist += math.sqrt((xyi[0] - xyj[0])**2 + (xyi[1] - xyj[1])**2)
print(dist*2/n)

Solution (Python):
import itertools
N = int(input())
points = []

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

def calcDistance(point1,point2):
  dis = ((point1[0]-point2[0])**2 + (point1[1]-point2[1])**2)**(1/2)
  return dis
  
ans = 0
Nlist= list(itertools.permutations(range(N)))
for i in range(len(Nlist)):
  for j in range(N):
    if j != N-1:
      ans += calcDistance(points[Nlist[i][j]],points[Nlist[i][j+1]])
        
print(ans / len(Nlist))

Solution (Python):
import itertools

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

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

p = itertools.permutations(range(n), 2)
print(sum(dist(cities[x[0]], cities[x[1]]) for x in p) / n)

Solution (Python):
import itertools
import math

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

l = [i for i in range(n)]
p = list(itertools.permutations(l))
dist = 0
for pp in p:
    preppi = pp[0]
    for ppi in pp[1:]:
        dist += math.sqrt((xy[ppi][0] - xy[preppi][0])**2 + (xy[ppi][1] - xy[preppi][1])**2)
        preppi = ppi
print(dist/len(p))

Solution (Python):
from itertools import permutations

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

def dist(A, B):
    x0, y0 = A
    x1, y1 = B
    res = pow((x0-x1)**2 + (y0-y1)**2, 1/2)
    return res

def sum_dist(arr):
    res = 0
    for A, B in zip(arr[:], arr[1:]):
        res += dist(A, B)
    return res

ans = 0
cnt = 0
for p in permutations(pos):
    ans += sum_dist(p)
    cnt += 1

ans /= cnt
print(ans)

Solution (Python):


import numpy as np
import itertools
def kyori(x1,y1,x2,y2):
    dis = ((x1-x2)**2+(y1-y2)**2)**0.5
    return dis
N = int(input())
xy = []
for n in range(N):
    xy.append(list(map(int, input().split())))
diss = np.zeros((N,N))
c = list(itertools.permutations(range(N), N))
s = 0
for n in range(len(c)):
    for d in range(N-1):
        if diss[c[n][d]][c[n][d+1]]==0:
            diss[c[n][d]][c[n][d+1]] = kyori(xy[c[n][d]][0],xy[c[n][d]][1],xy[c[n][d+1]][0],xy[c[n][d+1]][1])
            diss[c[n][d+1]][c[n][d]] = diss[c[n][d]][c[n][d+1]]
        s += diss[c[n][d]][c[n][d+1]]
print(s/len(c))

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

Solution (Python):
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]))
print(sum(dist)*2/N)

Solution (Python):
from math import sqrt

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

result = 0
for i in range(N):
    for j in range(N):
        if i != j :
            result += sqrt((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)

print(result/N)

Solution (Python):
'''
def factorial(n):
    if n == 1:
        return n
    return n*factorial(n-1)
'''
def dist(i, j):
    dx = x[i] - x[j]
    dy = y[i] - y[j]
    return (dx**2 + dy**2)**0.5

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

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

sum = 0
for idi in range(n):
    for idj in range(idi+1, n):
        sum += dist(idi, idj)

ans = sum*2/n

print(ans)

Solution (Python):
import math
import itertools


N = int(input())
l = list(range(N))
p = itertools.permutations(l)
xy = [list(map(int, input().split())) for _ in range(N)]
s = 0
for pp in p:
    for i in range(1, N):
        pi, pj = pp[i - 1], pp[i]
        s += ((xy[pi][0] - xy[pj][0]) ** 2 +
              (xy[pi][1] - xy[pj][1]) ** 2) ** 0.5
ave = s / math.factorial(N)
print(ave)

Solution (Python):
import itertools
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N=II()
lis=[LI() for i in range(N)]
nums = list(range(N))

su = 0.0
for perm in itertools.permutations(nums, N):
    for i in range(len(perm)-1):
        su += math.sqrt((lis[perm[i]][0]-lis[perm[i+1]][0])**2 + (lis[perm[i]][1]-lis[perm[i+1]][1])**2)

print(su / math.factorial(N))

Solution (Python):

import itertools

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

sum=0
for i in range(N):
    for j in range(i+1,N):
        sum += pow(pow(town[i][0]-town[j][0],2)+pow(town[i][1]-town[j][1],2),0.5)
print(sum/len(list(itertools.combinations(town, 2)))*(N-1))

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

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

Solution (Python):
from itertools import combinations

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

lengths = [((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5 for a, b in combinations(towns, 2)]
average_lengths = 2*sum(lengths)/n

print(average_lengths)

Solution (Python):
from math import sqrt
from itertools import permutations


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


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

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

rst = 0
cnt = 0
for order in permutations([n for n in range(N)]):
    for n in range(N - 1):
        rst += norm((x[order[n]], y[order[n]]), (x[order[n + 1]], y[order[n + 1]]))
    cnt += 1

print(rst / cnt)

Solution (Python):
import itertools,math
N=int(input())
N_fac=math.factorial(N)
X={}
Y={}
distance_dic={}
cnt=0
distance=0
for n in range(N):
    x,y=map(int,input().split())
    X[n]=x
    Y[n]=y
lst=list(itertools.permutations(X.keys(),N))
len_lst=len(lst)
for l in lst:
    l_2=list(l)
    for i in range(N-1):
        key1=l[i]
        key2=l[i+1]
        distance=distance+((X[key1]-X[key2])**2+(Y[key1]-Y[key2])**2)**0.5
print(distance/N_fac)

Solution (Python):
from itertools import combinations
import math
n = int(input())
li_point = list()
li_kyori = list()
for i in range(n):
    li_point.append(list(map(int, input().split())))


for x, y in combinations(range(n), 2):
    li_kyori.append(
        math.sqrt(
            abs(li_point[x][0] - li_point[y][0]) ** 2 +
            abs(li_point[x][1] - li_point[y][1]) ** 2
        )
    )

ave = sum(li_kyori) / len(li_kyori)
print(ave * (n - 1))

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

Solution (Python):
def d(x,y):
    return ((x[0]-y[0])**2+(x[1]-y[1])**2)**(1/2)
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+=d(x[i],x[j])
print(ans/n)

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

dist = 0
for i in range(N):
  for j in range(i,N):
    dist += ((spot[i][0]-spot[j][0])**2+(spot[i][1]-spot[j][1])**2)**0.5
print(dist*2/N)

Solution (Python):



def rint():
    return int(input())


def rints():
    return list(map(int, input().split()))


n = rint()
p = [rints() for _ in range(n)]
from itertools import permutations
from math import sqrt
per = list(permutations(range(n)))
s = 0
for pe in per:
    for i in range(1, n):
        x1, y1 = p[pe[i - 1]]
        x2, y2 = p[pe[i]]
        s += sqrt((x1 - x2)**2 + (y1 - y2)**2)
print(s / len(per))

Solution (Python):
import math
n = int(input())
b = 0
c = math.ceil(n/2)
e = math.factorial(n)
s = []
for i in range(n):
    a = list(map(int,input().split()))
    s.append(a)
ans = 0
for l in range(n):
    for m in range(l+1,n):
        ans += ((s[l][0]-s[m][0])**2 + (s[l][1] - s[m][1])**2)**0.5
    b += 1
print(ans*2 / n)

Solution (Python):
import numpy as np
from itertools import permutations

N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())
x = np.array(x).reshape(N, 1)
y = np.array(y).reshape(N, 1)
dist = ((x - x.T)**2 + (y - y.T)**2)**0.5
_sum = 0
combination = list(permutations([i for i in range(N)]))
for comb in combination:
    for i in range(N-1):
        _sum += dist[comb[i], comb[i+1]]
ret = _sum / len(combination)
print(ret)

Solution (Python):
from itertools import permutations
from math import sqrt

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

d = []
for route in permutations(range(N), N):
    dist = 0
    for i, j in zip(range(N - 1), range(1, N)):
        dist += sqrt((X[route[j]] - X[route[i]]) ** 2 + (Y[route[j]] - Y[route[i]]) ** 2)
    d.append(dist)
print(sum(d) / len(d))

Solution (Python):


import math
n = int(input())
x_list = []
y_list = []
d_sum = 0
for i in range(0, n):
    x, y = map(int, input().split())
    x_list.append(x)
    y_list.append(y)

for i in range(0, n - 1):
    for j in range(i + 1, n):
        d_sum += 2 / n * math.sqrt((x_list[i] - x_list[j])**2 + (y_list[i] - y_list[j])**2)
print(d_sum)

Solution (Python):
import math

n = int(input())
m = []
ds = []

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

for i in range(n):
    for j in range(i + 1, n):
        ds.append(math.sqrt((m[i][0] - m[j][0]) ** 2 + (m[i][1] - m[j][1]) ** 2))

ps = math.factorial(n)

x = (n-1) * math.factorial(n) / len(ds)

print(sum(ds) * (n-1) / len(ds))

Solution (Python):
import math
n = int(input())
cities = [list(map(int, input().split())) for _ in range(n)]

n_fact = math.factorial(n)
n1_fact = math.factorial(n-1)
ans = 0
for i in range(n):
    for j in range(i+1, n):
        ans += ((cities[i][0]-cities[j][0])**2+(cities[i][1]-cities[j][1])**2)**0.5*n1_fact
print(ans/n_fact*2)

Solution (Python):
import itertools
import math
N = int(input())
x = [[int(x) for x in input().split()] for _ in range(N)]
p = itertools.permutations([x for x in range(N)])
d = 0
cnt = 0
for seq in p:
    cnt+=1
    for i in range(1,N):
        d += math.sqrt((x[seq[i-1]][0] - x[seq[i]][0])**2 + (x[seq[i-1]][1] - x[seq[i]][1])**2) 
print(d/cnt)

Solution (Python):
import math
x = []
y = []
length = 0
N = int(input())
for i in range(N):
    a, b = input().strip().split()
    x.append(int(a))
    y.append(int(b))
for i in range(N):
    for j in range(N):
        length += math.sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]))
length /= N
print(length)

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

D = list()
for i, (x1, y1) in enumerate(C):
  for j, (x2, y2) in enumerate(C):
    if i>=j:continue
    d = math.sqrt((x1-x2)**2+(y1-y2)**2)
    D.append(d)


D = [x*(2*math.factorial(n-1)) for x in D]



print(sum(D) / math.factorial(n))

Solution (Python):
import math

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


for i in range(n):
  xy_list.append(list(map(int,input().split())))
counter = 0
for m in range(n-1):
  for l in range(m,n):
    x_l = xy_list[l][0]
    y_l = xy_list[l][1]
    x_m = xy_list[m][0]
    y_m = xy_list[m][1]
    counter += ((x_m - x_l)**2 + (y_m - y_l)**2)**0.5

print(counter*2/n)

Solution (Python):
n=int(input())
x=[]
y=[]
for _ in range(n):
  xt,yt=map(int,input().split())
  x.append(xt)
  y.append(yt)
ans=0
for i in range(n):
  for j in range(n):
    ans+=((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
    
print(ans/n)

Solution (Python):
import itertools
import math

N = int(input())
XY = [list(map(int,input().split(' '))) for _ in range(N)]
All_combination = list(itertools.permutations(XY))
All_distances = []
for each_list in All_combination:
    distance = 0
    for i in range(1,N):
        distance += math.sqrt((each_list[i-1][0] - each_list[i][0])**2 + (each_list[i-1][1] - each_list[i][1])**2) 
    All_distances.append(distance)
print(sum(All_distances)/len(All_distances))

Solution (Python):
import math

def main():
        index=0
        a=[]
        b=[]
        N = int(input())
        for i in range(N):
            A,B=input().split()
            a.append(int(A))
            b.append(int(B))
        for i in range(N):
            for j in range(N-1-i):
                index+=calc_length(a[i],a[j+1+i],b[i],b[j+1+i])

        print(index*2/N)

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


if __name__ == "__main__":
    main()

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

su=0
for i in range(N-1):
  for j in range(i+1,N):
  	d=math.sqrt((points[i][0]-points[j][0])**2+(points[i][1]-points[j][1])**2)
  	su=su+d
print(su*2/N)

Solution (Python):
import itertools
import numpy as np

def solve(n, x, y):
    total, num = 0, 0
    x, y = np.asarray(x), np.asarray(y)
    for p in itertools.permutations(range(n)):
        num += 1
        p = np.array(p, dtype=int)
        dx = x[p[1:]] - x[p[:-1]]
        dy = y[p[1:]] - y[p[:-1]]
        total += np.sum(np.sqrt(dx**2 + dy**2))
    return total / num

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

Solution (Python):
import math
N = int(input())
x_list=[]
y_list=[]
dirsum=0
for i in range(N):
	x,y = input().split()
	x_list.append(int(x))
	y_list.append(int(y))
for i in range(N):
	for j in range(i+1,N):
		dirsum += math.sqrt(pow(x_list[i]-x_list[j],2)+pow(y_list[i]-y_list[j],2))
print(2*math.factorial(N-1)*dirsum/math.factorial(N))

Solution (Python):
N = int(input())
tl = [[int(x) for x in input().split()] for _ in range(N)]
ans = 0

for i in range(N):
  for j in range(N):
    ans += ((tl[i][0]-tl[j][0])**2 + (tl[i][1]-tl[j][1])**2)**0.5
    
print(ans/N)

Solution (Python):
import itertools
import math

N = int(input())

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

s = 0
for p in itertools.permutations(range(N), N):
    for i in range(len(p) - 1):
        s += (((X[p[i]] - X[p[i+1]]) ** 2) + ((Y[p[i]] - Y[p[i+1]]) ** 2)) ** 0.5

print(s / math.factorial(N))

Solution (Python):
from itertools import permutations

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

lengths = []
for ps in permutations(points):
    lengths.append(sum(
        ((ps[i][0] - ps[i - 1][0]) ** 2 + (ps[i][1] - ps[i - 1][1]) ** 2) ** 0.5
        for i in range(1, N)
    ))
print(sum(lengths) / len(lengths))

Solution (Python):
n=int(input())
hoge=[]
for i in range(n):
  x,y=map(int,input().split())
  hoge.append([x,y])
ans=0
for i in range(n):
  for j in range(n):
    if(i!=j):
      ans+=((hoge[i][0]-hoge[j][0])**2+(hoge[i][1]-hoge[j][1])**2)**0.5
ans=(ans/n)
print(ans)

Solution (Python):
N = int(input())
x = []
y = []
for num in range(N):
  li = input()
  ubah = li.split(" ")
  x.append(int(ubah[0]))
  y.append(int(ubah[1]))

sum = 0
for i in range(N):
    for j in range(1+i,N):
        dist = ((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
        sum += dist*2/N
print(sum)

Solution (Python):
import math
import itertools
n = int(input())
x = [0 for _ in range(n)]
y = [0 for _ in range(n)]
for i in range(n):
    x[i], y[i] = map(int, input().split())
a = [k for k in range(n)]
cnt = math.factorial(n)
l_list = [0 for _ in range(cnt)]
m = 0
for b in itertools.permutations(a):
    l = 0
    for j in range(1, n):
        l += ((x[b[j]] - x[b[j - 1]]) ** 2 + (y[b[j]] - y[b[j - 1]]) ** 2) ** 0.5
    l_list[m] = l
    m += 1
print(sum(l_list) / cnt)

Solution (Python):
import copy
import heapq
import math

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)

n = ip()
a = []
s=0
for i in range(n):
    a.append(iprow())
adder = math.factorial(n)*2//n

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

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

Solution (Python):
import itertools
import math



N = int(raw_input())
xy = []
p = []
ans = float(0)
for i in range(0,N):
  tmp = list(map(int,raw_input().split()))
  xy.append(tmp)
  p.append(i)


x = 0

for v in itertools.permutations(p, N):
  
  for j in range(0,N-1):
    
    x = (xy[v[j]][0]-xy[v[j+1]][0])**2 + (xy[v[j]][1]-xy[v[j+1]][1])**2
    x = math.sqrt(int(x))
    
    ans += x

print ans/math.factorial(N)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
from itertools import combinations
from math import sqrt

def main():
    n=int(input())
    xy=[]
    for _ in range(n):
        x,y=map(int,input().split())
        xy.append((x,y))
    s=0
    c=0
    for a,b in combinations(xy, 2):
        s+=sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)
        c+=1
    s*=(n-1)
    s/=c
    print(s)

main()

Solution (Python):
import itertools

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

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

cnt = 0
cnt2 = 0
	
for _ in itertools.permutations(lst,n):
	cnt2 +=1
	for i in range(n-1):
		cnt += ((_[i][0]-_[i+1][0])**2+(_[i][1]-_[i+1][1])**2)**0.5

print(cnt/cnt2)

Solution (Python):
import itertools
import math

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

P = math.factorial(N)

paterns = list(itertools.permutations(A))
sum = 0

for _patern in paterns:
    patern = list(_patern)
    last = patern.pop(0)
    for point in patern:
        d = ((last[0] - point[0])**2 + (last[1] - point[1])**2)**0.5 / P
        sum = sum + d
        last = point

print(sum)

Solution (Python):
from itertools import permutations
from math import sqrt

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

result = 0
d = 0
for p in permutations(xy):
    d += 1
    for i in range(N - 1):
        result += sqrt((p[i][0] - p[i + 1][0]) * (p[i][0] - p[i + 1][0]) + (p[i][1] - p[i + 1][1]) * (p[i][1] - p[i + 1][1]))
print(result / d)

Solution (Python):
N=int(input())
L=[]
for i in range(N):
    x,y=map(int,input().split())
    L.append([x,y])
    
cnt=0
S=0
for i in range(N-1):
    for j in range(i+1,N):
        cnt+=1
        S+=((L[i][0]-L[j][0])**2+(L[i][1]-L[j][1])**2)**0.5
AVE=S/cnt
print(AVE*(N-1))

Solution (Python):
from math import sqrt,factorial
from itertools import permutations
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
perm = permutations(range(N),N)
tmp = 0
for p in perm:
    for i in range(1,N):
        tmp += sqrt((xy[p[i]][0] - xy[p[i-1]][0])**2 + (xy[p[i]][1] - xy[p[i-1]][1])**2)
print(tmp/factorial(N))