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 math
import itertools

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

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

per = list(itertools.permutations(range(1,N+1),N))

ans=0
for path in per:
    for i in range(N-1):
        ans+=L[path[i]-1][path[i+1]-1]
print(ans/len(per))

Solution (Python):
import math
import itertools
N = int(input())
XY = []
for _ in range(N):
    XY.append(list(map(int, input().split())))


def distance(i, j):
    res = (XY[i][0] - XY[j][0]) ** 2 + (XY[i][1] - XY[j][1]) ** 2
    return math.sqrt(res)


m = []

for n in range(N):
    m.append([-1] * N)


for j in range(N):
    for i in range(N):
        m[j][i] = distance(i, j)


ans = 0

for j in range(N):
    for i in range(N):
        ans += m[j][i]

print(ans / N)

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

ans = 0
for i in range(N):
    ix, iy = P[i]
    for j in range(i, N):
        jx, jy = P[j]
        ans += ((ix - jx) ** 2 + (iy - jy) ** 2) ** 0.5

print(ans / (N * (N-1) // 2) * (N-1))

Solution (Python):
import math
import itertools

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

numbers=[c for c in range(N)]
kyori=0
for i in itertools.permutations(numbers,N):
   for j in range(N-1):
      mae=i[j]
      usiro=i[j+1]
      kyori+=(((X[usiro]-X[mae])**2)+((Y[usiro]-Y[mae])**2))**0.5

N_f=math.factorial(N)
print(kyori/N_f)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = 0
ans_1 = 0
n = inp()
initial_list = ['None']*n
for i in range(n):
    temp = np.array(inpl())
    initial_list[i] = temp

my_abs = lambda x:  math.sqrt((x[0]**2+x[1]**2))
for i in range(n):
    ans_1 += sum([my_abs(x-initial_list[i]) for x in initial_list[i:]])

ans = ans_1*2/float(n)
print(ans)

Solution (Python):
import math

def distance(k,j):
    return math.sqrt((x[k]-x[j])**2 + (y[k]-y[j])**2)

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

sum = 0.00
for k in range(N):
    for j in range(N):
        if k != j:
            sum += distance(k,j)
print(sum/N)

Solution (Python):
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
import math
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, = map(int, input().split())


L = [[int(v) for v in input().split()] for _ in range(N)]




l = []
def f(al):
    if len(al) == N:
        l.append(al)
    for i in range(N):
        if i not in al:
            f(al + [i])
for i in range(N):
    f([i])

ans = 0
for v in l:
    a = 0
    for i in range(len(v)-1):
        x = L[v[i]]
        y = L[v[i + 1]]
        a += ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) ** 0.5

    ans += a
print(ans / len(l))

Solution (Python):
n = int(input())
points = []
for i in range(n):
  points.append(tuple(map(int, input().split())))
res = 0
for i in range(n):
  for j in range(i+1, n):
    res += ((points[i][0] - points[j][0])**2 + (points[i][1] - points[j][1])**2)**.5
print(res * 2 / n)

Solution (Python):
import itertools as itr
n = int(input())
xy = []
for i in range(n):
    x, y = map(int, input().split(" "))
    xy.append([x, y])
all = list(itr.permutations(xy))
n_n = 1
ans = []
for i in range(2,n+1):
    n_n = n_n*i
for line in all:
    r = [0] * (n+1)
    x = [0]*(n+1)
    y = [0]*(n+1)
    for i in range(n-1):
        x[i+1] = line[i+1][0] - line[i][0]
        y[i+1] = line[i+1][1] - line[i][1]
        r[i+1] = (x[i+1]**2 + y[i+1]**2)**(1/2)
    ans.append(sum(r))
print(sum(ans)/n_n)

Solution (Python):
import numpy as np
n=int(input())
x=[]
for i in range(n):
	X=list(map(int,input().split()))
	x.append(X)
x=np.array(x)
ans=0
for i in range(n):
	for j in range(i+1,n):
		d=np.linalg.norm(x[i]-x[j]) 
		ans+=d

print('{:.8f}'.format(ans*2/n))

Solution (Python):
import numpy as np
n = int(input())
p = []
for i in range(n):
    p.append(list(map(int, input().split())))

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

Solution (Python):
point = []

t=int(input())

import math

def distance(x1,y1,x2,y2):
    return math.pow(math.pow(x1-x2,2)+math.pow(y1-y2, 2),0.5)

while t:
    a,b = map(int, input().split())
    point.append((a,b))
    t-=1

u = len(point)

s= 0

for i in range(u):
    for j in range(u):
        if i==j:
            continue
        s += distance(point[i][0],point[i][1],point[j][0],point[j][1])


print(s/u)

Solution (Python):
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(input())

def permutation(a, aa=[]):
  if len(a)<=1:
    return [aa+a]

  res = []
  for x in a:
    b = a.copy()
    b.remove(x)
    res.extend(permutation(b, aa+[x]))

  return res

N = readi()
P = [ints() for i in range(N)]

s = 0.0
ps = permutation(list(range(N)))
pn = len(ps)

for p in ps:
  for i in range(N-1):
    q = p[i]
    r = p[i+1]
    s += ((P[q][0]-P[r][0])**2+(P[q][1]-P[r][1])**2)**(0.5)/pn
print(s)

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

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

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

di2 = 0.0
for i in range(N):
  for j in range(N):
    if i >= j:
      continue
    else:
      di2 += dist(xy[i], xy[j])

print(2.0*di2/N)

Solution (Python):
import numpy as np
def dist(ax, ay, bx, by):
  ans = np.sqrt( (ax-bx)**2 +(ay-by)**2 )
  return ans

N = int(input())
xs = []
ys = []

for _ in range(N):
  x, y = map(int, input().split())
  xs.append(x)
  ys.append(y)

di2 = 0.0
for i in range(N):
  for j in range(N):
    if i >= j:
      continue
    else:
      di2 += dist(xs[i], ys[i], xs[j], ys[j])

print(2.0*di2/N)

Solution (Python):
N=int(input())
A=[]
for l in range(N):
  array = list(map(int, input().split()))
  A.append(array)
import math
import itertools as ir
x=0
y=1

def distance(u,v):
  distance = math.sqrt( (A[u][x]-A[v][x])**2 + (A[u][y]-A[v][y])**2 )
  return distance

city_list=[]
for i in range(N):
  city_list.append(i)

permutations=list(ir.permutations(city_list))

sum_distance=0
for j in range(math.factorial(N)):
  for k in range(N-1):
    sum_distance+=distance(permutations[j][k],permutations[j][k+1])
result=sum_distance/math.factorial(N)
print(result)

Solution (Python):
import itertools
import math

n = int(input())
x = [None for i in range(n)]
y = [None for i in range(n)]

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

towns = [i for i in range(n)]

sum = 0

for arranged_towns in itertools.permutations(towns):
  current_town = arranged_towns[0]

  for next_town in arranged_towns[1:]:
    sum += math.sqrt((x[current_town] - x[next_town])** 2
              + (y[current_town] - y[next_town]) ** 2)
    current_town = next_town

result = sum / math.factorial(n)

print(result)

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

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

for i in range(n):
  for j in range(n):
    if i == j:
      continue
    sm += distance(xy[i], xy[j])
    
print(sm / n )

Solution (Python):
from itertools import permutations 
N = int(input())

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


perm = list(range(N))

count = 0
distsum = 0
for i in permutations(perm):
    for j, k in zip(i, i[1:]):
        x1, y1 = point[j]
        x2, y2 = point[k]
        distsum += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
    count += 1

print(distsum / count)

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) 

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
xy = [[] for i in range(N)]
for i in range(N):
    xy[i] = LI()

distances = []
def distance(town, town2):
    return ((town[0] - town2[0])**2 + (town[1] - town2[1])**2)**0.5

for i in range(N):
    for j in range(i+1,N):
        distances.append(distance(xy[i], xy[j]))

print(sum(distances) / N * 2)

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

ans = []
for i in range(N):
    for j in range(N):
        ans.append(np.sqrt((X[i][0]-X[j][0])**2 + (X[i][1]-X[j][1])**2))

print(sum(ans) / N)

Solution (Python):
import math,itertools
n = int(input())
xy = []
L=0
for i in range(n):
    xy.append(list(map(int, input().split())))
for k in itertools.permutations(xy):
    for (x1,y1),(x2,y2) in zip(k,k[1:]):
        L+=((x1-x2)**2+(y1-y2)**2)**0.5
print(L/math.factorial(n))

Solution (Python):
import numpy as np 
import math

x_list = np.array([])
y_list = np.array([])

n = int(input())

for i in range(n):
    x,y = map(int, input().split())
    x_list = np.append(x_list, x)
    y_list = np.append(y_list, y)

X = x_list[:, None] - x_list[None, :]
Y = y_list[:, None] - y_list[None, :]

print(np.sqrt(X ** 2 + Y ** 2).sum() / n)

Solution (Python):
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)

import itertools
import math
l=range(0,N)
distance=[]
for v in itertools.permutations(l,N):
    summary=0
    for w in range(len(v)-1):
        tmp=math.sqrt((x[v[w]]-x[v[w+1]])**2+(y[v[w]]-y[v[w+1]])**2)
        summary+=tmp
    distance.append(summary)

print('{:.7f}'.format(sum(distance)/math.factorial(N)))

Solution (Python):
from sys import stdin
import math

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

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

print(sum * 2 / N)

Solution (Python):
import math

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

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

ans = 0

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

print(ans/N)

Solution (Python):
import numpy as np
n = int(input())
arr = []

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

l=0
for i in range(n-1):
    for j in range(i+1, n):
        x_i,y_i = arr[i][0],arr[i][1]
        x_j,y_j = arr[j][0],arr[j][1]
        l += ((x_i-x_j)**2 + (y_i-y_j)**2)**0.5

print((2*l)/n)

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

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

l = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        xi, yi = C[i][0], C[i][1]
        xj, yj = C[j][0], C[j][1]
        l += ((xi - xj)**2 + (yi - yj)**2)**0.5

print((2 * l) / n)

Solution (Python):
import sys
import math

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

    sqs=[]
    for i in range(0,len(xy)):
        for j in range(i+1,len(xy)):
            sqs.append(math.sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2))

    print(sum(sqs) * 2 / N)

main()

Solution (Python):
import math
def length(list1,list2):
    sum = math.sqrt((list1[0] - list2[0])**2 + (list1[1] - list2[1])**2)
    return(sum)


num = int(input())
data = ['' for i in range(num)]
for i in range(num):
    input_data = input().split(' ')
    int_data = [int(input_data[l]) for l in range(2)]
    data[i] = int_data

result = 0
for i in range(num):
    for l in range(num - i - 1):
        result += length(data[i],data[l + 1 + i])

result = result * 2 / num
print(result)

Solution (Python):
import math
import itertools

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

n = int(input())
points = {i: list(map(int,  input().split())) for i in range(n)}

total_distance = 0

for cource in itertools.permutations(range(n)):
    for i in range(1, n):
        total_distance += distance(points[cource[i-1]], points[cource[i]])

print(total_distance/math.factorial(n))

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

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

Solution (Python):
n = int(input())
x = []
y = []
ans = 0

for _ in range(n):
    a, b = map(int, input().split())
    x.append(a)
    y.append(b)

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

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

def distance(x1, y1, x2, y2):
    dist = ((x1-x2)**2 + (y1-y2)**2) ** (1/2)
    return dist

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

ans = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        else:
            x1 = XY[i][0]
            y1 = XY[i][1]
            x2 = XY[j][0]
            y2 = XY[j][1]
            ans += distance(x1, y1, x2, y2)





ans /= 2
ans *= 2/N
print(ans)

Solution (Python):
import numpy as np


def main():
    N = int(input())
    towns = [input().split() for _ in range(N)]
    
    towns = np.array(towns).astype(np.int64)
    
    diffs = np.expand_dims(towns, axis=1) - np.expand_dims(towns, axis=0)
    
    distances = np.sqrt(np.sum(diffs ** 2, axis=-1))
    
    ans = distances.sum(axis=1).mean()
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np


def main():
    N = int(input())
    towns = [input().split() for _ in range(N)]
    towns = np.array(towns).astype(np.int64)
    diffs = np.expand_dims(towns, axis=1) - np.expand_dims(towns, axis=0)
    distances = np.sqrt(np.sum(diffs ** 2, axis=-1))
    ans = distances.sum(axis=1).mean()
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import math

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

print(d*2*math.factorial(n-1)/math.factorial(n))

Solution (Python):
import math

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

Solution (Python):
import math
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int,input().split())
nkai = 1

for i in range(1,N+1):
    nkai *= i
sum_dict = 0




branch = list()
for i in range(N):
    for j in range(i+1,N):
        a = (x[i] - x[j])**2 + (y[i]-y[j])**2
        a = math.sqrt(a)
        branch.append(a)

count = (nkai*(N-1))/(len(branch))
for i in range(len(branch)):
    sum_dict += branch[i]*(count)



ave = sum_dict / nkai
print(ave)

Solution (Python):
import itertools


n = int(input())

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

permutations = list(itertools.permutations(range(1,n+1),n))
permutations_n = len(permutations)

distances = []


for i in range(permutations_n):
    distance = 0
    
    for j in range(n-1):
        distance += (((grid[permutations[i][j]-1][0])-(grid[permutations[i][j+1]-1][0]))**2 + ((grid[permutations[i][j]-1][1])-(grid[permutations[i][j+1]-1][1]))**2)**(1/2)

    distances.append(distance)

print(sum(distances)/permutations_n)

Solution (Python):
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
ans = 0
import itertools
for path in itertools.permutations([i for i in range(n)]):
  for i in range(n-1):
    next = a[path[i+1]]
    now = a[path[i]]
    ans += ((next[1]-now[1])**2 + (next[0]-now[0])**2)**(1/2)

for i in range(n, 0, -1):
  ans /= i
print(ans)

Solution (Python):
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 lst:
    for j in range(N-1):
        line = ((i[j][0]-i[j+1][0])**2 +  (i[j][1]-i[j+1][1])**2)**0.5
        num += line
print(num/len(lst))

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

N = int(input())
XY = [list(map(int, input().split())) for i in range(N)]
Distance = []
for v in itertools.permutations(XY, N):
  distance_each = [np.sqrt((v[i][0] - v[i + 1][0])**2 + (v[i][1] - v[i + 1][1])**2) for i in range(N - 1)]
  distance = np.sum(distance_each)
  Distance.append(distance)
ans = np.average(Distance)
print(ans)

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

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

Solution (Python):
from itertools import combinations, permutations


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

edges = [[0] * n for _ in range(n)]
for i, j in combinations(range(n), 2):
    xi, yi = xy[i]
    xj, yj = xy[j]
    distance = ((xi - xj)**2 + (yi - yj)**2)**0.5
    edges[i][j] = edges[j][i] = distance

totals = []
for node in permutations(range(n)):
    total = 0
    for i in range(1, n):
        total += edges[node[i-1]][node[i]]
    totals.append(total)

print(sum(totals) / len(totals))

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

dist = 0
for x1,y1 in XY:
    for x2,y2 in XY:
        dist += ((x1-x2)**2+(y1-y2)**2)**(1/2)
print(dist/N)

Solution (Python):
import sys
import itertools
import bisect
import math
stdin = sys.stdin

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

n = ni()
li = [na() for _ in range(n)]
tmp = list(itertools.permutations(li))
l = len(tmp)
s = 0
for rt in tmp:
    for i in range(n-1):
        s += ((rt[i+1][0] - rt[i][0]) ** 2 + (rt[i+1][1] - rt[i][1]) ** 2) ** 0.5

print(s/l)

Solution (Python):
N = int(input())
li = [list(map(int, input().split())) for x in range(N)]
length = 0
for i in range(len(li)):
	for j in range(len(li)):
		if i != j:
			length += ((li[i][0]-li[j][0])**2+(li[i][1]-li[j][1])**2)**0.5
print(length/N)

Solution (Python):
import math
N = int(input())
li = [list(map(int, input().split())) for x in range(N)]
length = 0
for i in range(len(li)):
	for j in range(len(li)):
		if i != j:
			length += ((li[i][0]-li[j][0])**2+(li[i][1]-li[j][1])**2)**0.5
n = math.factorial(N-1)
ans = (length*n)/math.factorial(N)
print(ans)

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

Solution (Python):
from itertools import permutations

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

def distance(a, b):
    x1, y1 = a[0], a[1]
    x2, y2 = b[0], b[1]
    dis = ((x1-x2)**2 + (y1-y2)**2)**0.5
    return dis


paths = list(permutations(a, len(a)))

distances = []
for p in paths:
    dis_path = []
    for i in range(len(a)-1):
        dis_path.append(distance(p[i], p[i+1]))
    distances.append(sum(dis_path))

print(sum(distances) / len(distances))

Solution (Python):

from math import sqrt 
N = int(input())
k = [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((k[i][0] - k[j][0]) * (k[i][0] - k[j][0]) + (k[i][1] - k[j][1]) * (k[i][1] - k[j][1]))
print(result / N)

Solution (Python):
def run():
  N = int(input())
  xy_li = [list(map(int, input().split())) for i in range(N)]
  d_sum = 0
  for i in range(N):
    for j in range(i+1, N):
      d_sum += ((xy_li[i][0]-xy_li[j][0])**2+(xy_li[i][1]-xy_li[j][1])**2)**(1/2)
      
  print(2*d_sum/N)
  
if __name__ == '__main__':
  run()

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

	

	for i in itertools.permutations(range(n),n):
		l_jun.append(i)
	

	for i in range(len(l_jun)):
		
		
		
		
		for t in range(n-1):
			
			
			
			
			dis_x = (( int(l[ l_jun[i][t] ][0])-int(l[ l_jun[i][t+1] ][0]) )**2)
			dis_y = (( int(l[ l_jun[i][t] ][1]) - int(l[ l_jun[i][t+1] ][1]) )**2)
			
			
			dis = (dis_x+dis_y)**.5
			ans_pre.append(dis)
			
			
			
	print(sum(ans_pre)/len(l_jun))




if __name__ == '__main__':
	main()

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

Solution (Python):
from math import sqrt
n = int(raw_input())
coords = [map(int, raw_input().split()) for i in range(n)]
dist = 0
for i in range(n):
    for j in range(i+1, n):
        if i != j:
            dist += sqrt((coords[i][0]-coords[j][0])**2 + (coords[i][1] - coords[j][1])**2)

def factorial(n):
    res = n
    for i in range(1, n):
        res *= i
    return res
            
print dist * 2 / n

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

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

import itertools
paths = list(itertools.permutations(range(N)))

total_length = 0
for i in paths:
    for j in range(N - 1):
        x1, y1 = coordinates[i[j]]
        x2, y2 = coordinates[i[j + 1]]
        total_length += ((x1 - x2)**2 + (y1 - y2)**2)**0.5

average_length = total_length / len(paths)
print(average_length)

Solution (Python):
import numpy as np
n=int(input())
xy=np.zeros((n,2))
for i in range(n):
    xy[i][0],xy[i][1]=map(int,input().split())

ans=0
for i in range(n-1):
    for j in range(i+1,n):
        ans+=np.sqrt(np.square(xy[i][0]-xy[j][0])+np.square(xy[i][1]-xy[j][1]))
ans/=(n/2)
print(ans)

Solution (Python):
import itertools
import math

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

ave = 0
count = 0
for path in itertools.permutations(cities):
    length = 0
    for i in range(len(path))[1:]:
        length += math.sqrt((path[i][0] - path[i-1][0]) ** 2 +
                            (path[i][1] - path[i-1][1]) ** 2)
    ave += length
    count += 1

print(ave / count)

Solution (Python):
import itertools
import math

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

n = int(input())
patern = list(itertools.permutations(range(1,n+1), n))

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

cal = 0
for i in range(len(patern)):
    for j in range(n-1):
        index = patern[i][j]
        index_ad = patern[i][j+1]
        x1 = input_list[index][0]
        x2 = input_list[index_ad][0]
        y1 = input_list[index][1]
        y2 = input_list[index_ad][1]

        cal += rt(x1, x2, y1, y2)

print(cal/len(patern))

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

n = int(input())

loc = [None]*n
for i in range(0, n):
	x, y = [int(el) for el in input().split(' ')]
	loc[i] = [x, y]




comb = combinations([i for i in range(0, n)], 2)

dist = dict()
for c in comb:
	start = c[0]
	goal = c[1]

	d = math.sqrt(pow(loc[start][0] - loc[goal][0], 2) \
		+ pow(loc[start][1] - loc[goal][1], 2))
	dist[c] = d


pattern = permutations([i for i in range(0, n)])

total_d = 0
for pat in pattern:
	sub_total_d = 0
	for j in range(0, n-1):
		start = min(pat[j], pat[j+1])
		goal = max(pat[j], pat[j+1])

		sub_total_d += dist[(start, goal)]
	total_d += sub_total_d
print(total_d / math.factorial(n))

Solution (Python):
import itertools

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


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

for i in range(0, N):
    z.append(list(map(int, input().split())))
    
d = [ [] for k in range(0, N) ]
for i in range(0, N):
    for j in range(0, N):
        d[i].append( distance(z[i], z[j]) )

seq = tuple( (k for k in range(0, N)) )
per = list(itertools.permutations(seq))
result = 0

for n in range(0, len(per)):
    summation = 0
    for l in range(0, N-1):
        summation = summation + d[per[n][l]][per[n][l+1]]
    result = result + summation

s = 1
for j in range(1, N+1):
    s = s * j

print(result/s)

Solution (Python):
import itertools
import math

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


def dist(g):
    global n
    c=0
    for i in range(n-1):
        c+=math.sqrt((g[i+1][0]-g[i][0])**2+(g[i+1][1]-g[i][1])**2)
    return c

m=0
k=0
for i in y:
    k+=1
    m+=dist(i)
print(m/k)

Solution (Python):
import itertools
from math import sqrt, pow

N = int(input())
lst = []
for _ in range(N):
    lst.append([int(x) for x in input().split()])

ret_lst = []
for l in itertools.permutations(lst):
    ret = 0
    for idx, (x1, y1) in enumerate(l[:-1]):
        x2 = l[idx + 1][0]
        y2 = l[idx + 1][1]
        ret += sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2))
    ret_lst.append(ret)

print(sum(ret_lst) / len(ret_lst))

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

res = 0
for i in range(n):
    for j in range(i+1, n):
        dist = ((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2) ** (1/2)
        res += dist

print(res*2/n)

Solution (Python):

from itertools import permutations
from math import sqrt
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

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

res = 0.0
cnt = 0
for p in permutations(range(n), n):
    cnt += 1
    for i in range(n-1):
        res += d(xy[p[i]],xy[p[i+1]])

print(res/cnt)

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

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)

Solution (Python):
import itertools
import math
L=0
M=0
N=int(input())
p=[list(map(int,input().split())) for i in range(N)]
for seq in itertools.permutations(range(N),N):
    tmp=0
    for i in range(N-1):
        x1,y1=p[seq[i]]
        x2,y2=p[seq[i+1]]
        tmp+=math.sqrt((x1-x2)**2+(y1-y2)**2)
    L+=tmp
    M+=1
print(L/M)

Solution (Python):
N=int(input())
points=[input().split() for i in range(N)]
import math
def calc_dist(start, end):
    return math.sqrt((int(start[0]) - int(end[0])) ** 2 + (int(start[1]) - int(end[1])) ** 2)

from itertools import combinations, permutations
total_dist = []
for root in permutations(range(N), N):
    dist = 0
    for num in range(len(root)-1):
        dist += calc_dist(points[root[num]], points[root[num+1]])
    total_dist.append(dist)
from statistics import mean
print(mean(total_dist))

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

path = []
for p in itertools.permutations(town_list):
    lengh = 0
    for i in range(N - 1):
        lengh += math.sqrt((p[i][0] - p[i + 1][0]) ** 2 + (p[i][1] - p[i + 1][1]) ** 2)
    path.append(lengh)

print(sum(path) / len(path))

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    C=[None]*n
    for i in range(n):
        x,y=map(int,input().split())
        C[i]=x+y*1j

    s=sum(abs(C[i]-C[j]) for i in range(n) for j in range(n))
    print(s/n)
resolve()

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

import math
def dist(x1,y1,x2,y2):
  x = (x1-x2)**2 + (y1-y2)**2
  return math.sqrt(x)


import itertools
rt_list = list(itertools.permutations(range(N)))

d = 0
for rts in rt_list:
  tmp_d = 0 
  for rt in range(len(rts) - 1):
    tmp_d += dist(lis[rts[rt]][0],lis[rts[rt]][1], lis[rts[rt+1]][0],lis[rts[rt+1]][1])
  d += tmp_d
print(d/len(rt_list))

Solution (Python):
import itertools
import math
N = int(input())

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

path = []
for l in itertools.permutations(xy):
    t = 0
    for i in range(N-1):
        t += math.sqrt((l[i][0] - l[i+1][0]) ** 2 + (l[i][1] - l[i+1][1]) ** 2)
    path.append(t)

print(sum(path)/len(path))