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
import numpy as np
def l2_dist(a,b):
    return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
def rate(n):
    if n == 1:
        return 2
    else:
        return n * rate(n - 1) 
def fact(n):
    if n == 1 or n == 0:
        return 1
    else:
        return n * fact(n - 1)
n = int(input())
point_list = []
for i in range(n):
    point_list.append(tuple(map(float,input().split(' '))))
dist_list = []
for i in itertools.combinations([i for i in range(n)], 2):
    dist_list.append(l2_dist(point_list[i[0]],point_list[i[1]]))
r = rate(n - 1) if n > 2 else 1
f = fact(n) if n > 2 else 1
dist_list = np.asarray(dist_list) * r
print(dist_list.sum() / f)

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

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

print(s * (n-1) / (n*(n-1)/2))

Solution (Python):

from math import sqrt
N = int(input())
lst = [list(map(int, input().split())) for _ in range(N)]

res = 0
for i in range(N):
    for j in range(N):
        if i != j:
            res += sqrt((lst[i][0] - lst[j][0])**2 + (lst[i][1] - lst[j][1])**2) 
print(res/N)

Solution (Python):
import math

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

ans = 0
count = 1;
for i in range(1, N):
    count *= i

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


print(ans / count / N)

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

x=[]
y=[]
total=0
num=math.factorial(n)
for i in range(n):
    X,Y=map(int,input().split())
    x.append(X)
    y.append(Y)
num_lis=[i for i in range(n)]
P=itertools.permutations(num_lis,n)
for p in P:
    for i in range(n-1):
        tmp=math.sqrt((x[p[i+1]]-x[p[i]])**2+(y[p[i+1]]-y[p[i]])**2)
        total+=tmp
print(total/num)

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

x=[]
y=[]
total=0
num=math.factorial(n)
for i in range(n):
    X,Y=map(int,input().split())
    x.append(X)
    y.append(Y)
num_lis=[]
for i in range(n):
    num_lis.append(i)
P=itertools.permutations(num_lis,n)
for p in P:
    for i in range(n-1):
        tmp=math.sqrt((x[p[i+1]]-x[p[i]])**2+(y[p[i+1]]-y[p[i]])**2)
        total+=tmp
print(total/num)

Solution (Python):
import itertools
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
g = [[0] * n for i in range(n)]
for i,j in itertools.combinations(range(n),2):
  i,j = min(i,j),max(i,j)
  g[i][j] = ((l[i][0]-l[j][0])**2 + (l[i][1]-l[j][1])**2) ** 0.5
a = 0
c = 0
for i in itertools.permutations(range(n)):
  c += 1
  cur = i[0]
  for j in i[1:]:
    pre,cur = cur,j
    a += g[min(pre,cur)][max(pre,cur)]
print(a/c)

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

print(2 * ans / N)

Solution (Python):
import math
from itertools import permutations
 
N = int(input())
xy = [[int(i) for i in input().split()] for j in range(N)]
 
dist = [[0]*N for i in range(N)]
for i in range(N):
    for j in range(N):
        dist[i][j] = math.sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)
 
answer = 0.0
 
for i in permutations(range(N)):
    for j in range(1,N):
        answer += dist[i[j-1]][i[j]]
answer /= math.factorial(N)
 
print(answer)

Solution (Python):

from itertools import permutations
from math import sqrt

def calc(x0, y0, x1, y1):
    return sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2)

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

for l in ll:
    tmp = 0
    x0, y0 = X[l[0]], Y[l[0]]
    for j in range(1, N):
        x1, y1 = X[l[j]], Y[l[j]]
        tmp += calc(x0, y0, x1, y1)
        x0, y0 = x1, y1
    ls.append(tmp)
    
print(sum(ls) / len(ll))

Solution (Python):




n_text = input()
n = int(n_text)

class Zahyo:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    
    @staticmethod
    def parse(text):
        x_txt, y_txt = text.split()
        x = int(x_txt)
        y = int(y_txt)
        zahyo = Zahyo(x, y)
        return zahyo


def calc_kyori(zahyo1, zahyo2):
    kyori = (((zahyo1.x - zahyo2.x) ** 2) + ((zahyo1.y - zahyo2.y) ** 2)) ** 0.5
    return kyori


def calc_kyoris(my_zahyo_list):
    kyori = 0
    for i in range(len(my_zahyo_list)-1):
        kyori += calc_kyori(my_zahyo_list[i], my_zahyo_list[i+1])
    return kyori


zahyo_list = []
for i in range(n):
    zahyo_list.append(Zahyo.parse(input()))

kyori_list = []


def calc(my_kakutei_zahyo_list, my_un_kakutei_zahyo_list, my_kyori_list):
    
    if len(my_un_kakutei_zahyo_list) == 0:
        kyori = calc_kyoris(my_kakutei_zahyo_list)
        my_kyori_list.append(kyori)
    for i in range(len(my_un_kakutei_zahyo_list)):
        calc(my_kakutei_zahyo_list + [my_un_kakutei_zahyo_list[i]], my_un_kakutei_zahyo_list[0:i] + my_un_kakutei_zahyo_list[i+1:], my_kyori_list)


calc([], zahyo_list, kyori_list)

heikin = sum(kyori_list) / len(kyori_list)
print(heikin)

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


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

k=0
for i in range(N):
    for j in range(N):
        if(i!=j):
            k=k+((a[i][0]-a[j][0])*(a[i][0]-a[j][0])+(a[i][1]-a[j][1])*(a[i][1]-a[j][1]))**0.5

print(k/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]) * (xy[i][0] - xy[j][0]) + (xy[i][1] - xy[j][1]) * (xy[i][1] - xy[j][1]))
print(result / N)

Solution (Python):
import math
import itertools
N = int(input())
town = []
kyori = []
for i in range(N):
  x,y = map(int, input().split())
  town.append([x,y])
  
for route in itertools.permutations(town, N):
  L = 0
  for i in range(N-1):
    L = L + math.sqrt((route[i+1][0]-route[i][0])**2 + (route[i+1][1]-route[i][1])**2)
  kyori.append(L)

print(sum(kyori)/math.factorial(N))

Solution (Python):
import math
import itertools

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


N = int(input())
S = []
for _ in range(N):
  S.append(list(map(int, input().split())))
l = [i for i in range(N)]
dic=[]
for v in itertools.permutations(l):
    dic.append(v)

    
sum_l=0.0
for i in range(len(dic)):
  for j in range(N-1):
    sum_l += distance(S[dic[i][j]][0],S[dic[i][j]][1],S[dic[i][j+1]][0],S[dic[i][j+1]][1])
print(sum_l/len(dic))

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


def distance(xy_lst1,xy_lst2):
    xi = xy_lst1[0]
    yi = xy_lst1[1]
    xj = xy_lst2[0]
    yj = xy_lst2[1]

    d = ((xi-xj)**2 + (yi-yj)**2)**(0.5)
    return(d)


d_dic = {}
d_sum = 0
for i in range(N):
    i_dic = {}
    for j in range(N):
        dij = distance(XY_lst[i], XY_lst[j])
        d_sum += dij
        i_dic[str(j)] = dij
    d_dic[str(i)] = i_dic

        


print(d_sum / N)

Solution (Python):
import math

N = int(input())
pts = [[int(i) for i in input().split()] for _ in range(N)]
tot = 0
for i in range(N):
  tot += sum([math.sqrt((pts[i][0]-pts[j][0])**2+(pts[i][1]-pts[j][1])**2) for j in range(i+1, N)])
print(tot / math.factorial(N) * math.factorial(N-1) * 2)

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

import math
from functools import lru_cache

@lru_cache(maxsize=100000)
def calc_distance(a, b):
    tmp = (a[0]-b[0])**2 + (a[1]-b[1])**2
    return math.sqrt(tmp)


import itertools
sum = 0
for all in itertools.permutations(s, n):
    for i in range(n-1):
        
        
        sum += calc_distance(tuple(all[i]), tuple(all[i+1])) 

kaizyo = math.factorial(n)



print(sum/kaizyo)

Solution (Python):


N = int(input())
arr = []
for i in range(N):
    tmp = list(map(int, input().split()))
    arr.append(tmp)



import math
import statistics
import itertools

table = [[0]*N for i in range(N)]
for i in range(N):
    ti = arr[i]
    for j in range(N):
        tj = arr[j]
        dist = math.sqrt((ti[0] - tj[0])**2 + (ti[1] - tj[1])**2)
        table[i][j] = dist

kumi_all = list(itertools.permutations(range(N)))
kumi_all_count = len(kumi_all)

total_dist = 0

for i in range(kumi_all_count):
    this_dist = 0
    this_kumi = kumi_all[i]

    for j in range(N-1):
        this_dist += table[this_kumi[j]][this_kumi[j+1]]

    total_dist += this_dist

avr_dist = total_dist / kumi_all_count

print(avr_dist)

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

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

Solution (Python):
import math
n = int(input())
c = []
for i in range(n):
    x,y = map(int,input().split())
    c.append([x,y])
dist = []
for i in range(len(c)):
    for j in range(len(c)):
        dist.append(math.sqrt(pow(c[i][0]-c[j][0],2)+pow(c[i][1]-c[j][1],2)))
print(sum(dist)/n)

Solution (Python):
n = int(input())
a = [0]*n
b = [0]*n

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

c = 0

for i in range(n):
    for j in range(n):
        c += ((a[j]-a[i])**2 + (b[i]-b[j])**2)**0.5
print(c/n)

Solution (Python):

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

def calc_dist(x, y):
    ret = ((x[0] - y[0]) ** 2 + (x[1] -y[1]) **2) ** 0.5
    return ret

dist = []
for i in range(n):
    temp = []
    for j in range(n):
        temp.append(calc_dist(coord[i], coord[j]))
    dist.append(temp)

summed = 0
for k in range(len(dist)):
    summed += sum(dist[k])

ans = summed / n

print(ans)

Solution (Python):
import itertools

N = int(input())
P = [list(map(int,input().split())) for i in range(N)]
number = 0
Sum = 0
for pair in itertools.permutations(P,N):
    for i in range(N-1):
        Sum = Sum + ((pair[i][0]-pair[i+1][0])**2+(pair[i][1]-pair[i+1][1])**2)**(1/2)
    number += 1
print(Sum/number)

Solution (Python):
import itertools
import math

def main():
    lists = []
    i=0
    N= int(input())
    while i < N:
        a = [int(j) for j in input().split()]
        lists.append(a)
        i+=1
    ans=0
    length=0
    for line in itertools.permutations(lists):
        a = []
        b = []
        for data in line:
            if len(b) ==0:
                b = data
                continue
            else:
                a = b
                b = data
                length = math.sqrt(((b[0]-a[0])**2)+((b[1]-a[1])**2))
                ans+=length
    print(ans/math.factorial(N))

if __name__ == "__main__":
    main()

Solution (Python):


import numpy as np
import itertools as it









N = int(input())
townpoints = np.empty((N, 2), dtype=np.int16)
distances = np.empty((N, N))

for i in range(N):
    line = input()
    townpoints[i] = list(map(int, line.split(' ')))

xx, xy = np.meshgrid(townpoints[:, 0], townpoints[:, 0])
yx, yy = np.meshgrid(townpoints[:, 1], townpoints[:, 1])

xdist = (xx - xy) ** 2
ydist = (yx - yy) ** 2

distances = (xdist+ydist)**0.5


orders = list(it.permutations(list(range(N))))

distance_list = np.empty((len(orders)))

for n, i in enumerate(orders):
    dist_tmp = 0
    for j in range(N-1):
        dist_tmp += distances[i[j], i[j+1]]
    distance_list[n] = dist_tmp

avg = distance_list.sum()/len(distance_list)

print(avg)

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

ans=0
for v in itertools.permutations(xy):
  x=[v[i][0] for i in range(n)]
  y=[v[i][1] for i in range(n)]

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

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

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




import math

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

sum = 0
for i in s: 
    for j in s:
        dist = calc_distance(i, j)
        sum += dist

print(float(sum/n))

Solution (Python):
import math
def distance(x1,y1,x2,y2):
    x = pow(abs(x1-x2),2)
    y = pow(abs(y1-y2),2)
    return math.sqrt(x+y)

import itertools

def permutation(list_):
    return list(itertools.permutations(list_))

def main():
    n = int(input())
    x,y = [0 for _ in range(n)],[0 for _ in range(n)]
    for i in range(n):
        x[i],y[i] = map(int,input().split())
    
    can = permutation(list(range(n)))

    all_path = 0
    for ls in can:
        path = 0
        for i in range(1,len(ls)):
            path += distance(x[ls[i-1]],y[ls[i-1]],x[ls[i]],y[ls[i]])
        all_path += path
    
    print(all_path/len(can))

if __name__=='__main__':
    main()

Solution (Python):
from math import sqrt, factorial
from itertools import permutations
import sys
input = sys.stdin.readline



class Solver(object):
    def __init__(self):
        pass

    def solve(self, N: int, cities: list):
        dist = float()
        for p in permutations(range(N)):
            for index, n in enumerate(p):
                if index == 0:
                    a = cities[n]
                    continue
                else:
                    b = a
                    a = cities[n]
                    dist += self.__distance(a, b)
        return dist/factorial(N)

    def __distance(self, a: list, b: list) -> float:
        return sqrt(abs(a[0]-b[0])*abs(a[0]-b[0]) + abs(a[1]-b[1])*abs(a[1]-b[1]))


def main():
    N = int(input())
    t_l = [[int(i) for i in input().split()] for _ in range(N)]

    solver = Solver()
    print(solver.solve(N, t_l))


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

import math

n = int(input())

a = []

sum = 0

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

for i in range(n):
    for s in range(i,n):
        sum += np.linalg.norm(a[s] - a[i]) * math.factorial(n-1) * 2

print(sum/math.factorial(n))

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

b = []
for i in range(n):
    for j in range(n-i-1):
        xi,yi = a[i]
        xj,yj = a[j+i+1]
 
        z = ((xi-xj)**2+(yi-yj)**2)**0.5
        b.append(z)

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

Solution (Python):
import math
import heapq
import sys
from collections import Counter
import numpy as np





N=int(input())
points = []
for i in range(N):
    p = str(input()).split(" ")
    points.append((int(p[0]), int(p[1])))



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

Solution (Python):

import math

def get_distance(p1, p2):
    return math.hypot(p1[0] - p2[0], p1[1] - p2[1])

N = int(input())
points = []
for i in range(N):
    p = str(input()).split(" ")
    points.append((int(p[0]), int(p[1])))

total_dist = 0
for i in range(N):
    for j in range(i,N):
        total_dist += get_distance(points[i], points[j])

print(2*total_dist/N)

Solution (Python):
import itertools

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

for i in itertools.combinations(l,2):
    ans += ((i[0][0]-i[1][0])**2 + (i[0][1]-i[1][1])**2)**(1/2)

print(ans*2/n)

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

N = int(input())

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

p = permutations(points,N)

average = 0

for j in p:
    for k in range(0,len(j)-1):
        average += ((j[k+1][0] -j[k][0])**2 + (j[k+1][1] -j[k][1])**2)**0.5

print('{:.10f}'.format(average/factorial(N)))

Solution (Python):
import numpy as np


def main():
    N = int(input())
    xs = np.array([tuple(map(int, input().split()))
                   for _ in range(N)], np.float32)
    dmap = dist(xs)
    s = 0.
    for i, p in enumerate(permutations(np.arange(N))):
        d = sum(dmap[p[k - 1], p[k]] for k in range(1, N))
        s += d
    print(s / (i + 1))


def permutations(iterable, r=None):
    pool = tuple(iterable)
    n = len(pool)
    r = n if r is None else r
    if r > n:
        return
    indices = list(range(n))
    cycles = list(range(n, n-r, -1))
    yield tuple(pool[i] for i in indices[:r])
    while n:
        for i in reversed(range(r)):
            cycles[i] -= 1
            if cycles[i] == 0:
                indices[i:] = indices[i+1:] + indices[i:i+1]
                cycles[i] = n - i
            else:
                j = cycles[i]
                indices[i], indices[-j] = indices[-j], indices[i]
                yield tuple(pool[i] for i in indices[:r])
                break
        else:
            return


def dist(xs):
    x, y = xs.T
    z = np.sqrt(np.power(x[:, None] - x[None], 2)
                + np.power(y[:, None] - y[None], 2))
    return z


if __name__ == "__main__":
    main()

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

Solution (Python):
n = int(input())
x, y = [], []
for i in range(n):
	a, b = map(int, input().split())
	x.append(a)
	y.append(b)
res = 0
for x1, y1 in zip(x, y):
	for x2, y2 in zip(x, y):
		res += ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
res /= n
print(res)

Solution (Python):
import itertools
import statistics
N = int(input())
place_list = [list(map(int, input().split())) for i in range(N)]
all_place_list = list(itertools.permutations(place_list))
dist_list =[]
for place_list_iter in all_place_list:
    dist_sum = 0
    for i, (x, y) in enumerate(place_list_iter):
        if i == 0:
            pre_x, pre_y = x, y
        else:
            dist = ((x-pre_x)**2+(y-pre_y)**2)**(1/2)
            dist_sum += dist
    dist_list.append(dist_sum)
print(statistics.mean(dist_list))

Solution (Python):
n = int(input())
df = [list(map(int, input().split())) for _ in range(n)]
m = 1
for i in range(1, n+1):
    m *= i
result = 0
for i in range(n):
    for j in range(n):
        if i != j:
            result += (abs(df[i][0]-df[j][0])**2 + abs(df[i][1] - df[j][1])**2)**0.5
print(result/n)

Solution (Python):

N=int(raw_input())
xn=[]
for i in range(N):
    xn.append(map(int, raw_input().split()))

S = 0
for i in range(N):
    for j in range(N):
        S += pow( \
               pow(xn[i][0] - xn[j][0], 2) + \
               pow(xn[i][1] - xn[j][1], 2) , \
               0.5 \
             )

print str(S / N)

Solution (Python):

import math
import heapq

N = int(input())

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

ans = 0
for a1 in A:
    for a2 in A:
        ans += math.sqrt((a1[0]-a2[0])**2 + (a1[1]-a2[1])**2)

ans /= N
print(ans)

Solution (Python):
List = []

def f(n):
    s = 0;
    for i in range(n):
        for j in range(n):
            if i != j:
                s += ((List[i][0] - List[j][0])**2 + (List[i][1] - List[j][1])**2)**0.5
    
    return s/n

if __name__ == '__main__':
    n = int(input())
    for i in range(n):
        x, y = map(int, input().split())
        List.append((x, y))
    print(f(n))

Solution (Python):
import itertools
import math

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

_list = list(itertools.permutations(xy))
a = []
for i in _list:
    b = 0
    for j in range(len(i)-1):
        a.append(math.sqrt(pow(i[j][0]-i[j+1][0], 2) + pow(i[j][1]-i[j+1][1], 2)))
print(sum(a)/len(_list))

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

Solution (Python):
import math
n = int(input())
a = [[int(j) for j in input().split()] for i in range(n)]
t = 0
for i in range(n-1):
    for j in a[i+1:]:
        t += math.sqrt((a[i][0]-j[0])**2 + (a[i][1]-j[1])**2)
print(t*2/n)

Solution (Python):
import numpy as np
import itertools as it

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

a = list(it.permutations(list(range(n))))
b = list(it.combinations(list(range(n)), 2))
c = []
for bb in b:
    xx,yy = o[list(bb)]
    zz = xx - yy
    delta = np.sqrt(zz[0]**2 + zz[1]**2)
    c.append(delta)

ans = sum(c)*(n-1)/len(c)
print(ans)

Solution (Python):
import math
import itertools
N = int(input())
Sum = 0
N_2 = math.factorial(N)
lis = []
for i in range(N):
  a,b = map(int,input().split())
  lis.append([a,b])
P = list(itertools.permutations(range(N)))
for j in range(N_2):
  for g in range(N-1):
    Sum += math.sqrt(((lis[P[j][g]][0]-lis[P[j][g+1]][0])**2) + ((lis[P[j][g]][1]-lis[P[j][g+1]][1])**2))
print(Sum/N_2)

Solution (Python):
n = int(raw_input())
l = [map(int,raw_input().split()) for i in range(n)]
print sum(((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)**(.5) for i in range(n) for j in range(n) if i !=j)/n

Solution (Python):
N = int(input())
list_x = []
list_y = []
list_distance = []

for _ in range(N):
    (x, y) = map(int, input().split())
    list_x.append(x)
    list_y.append(y)
    
for i in range(N-1):
    for j in range(i+1,N):
        xi = list_x[i]
        yi = list_y[i]    
        xj = list_x[j]
        yj = list_y[j]
        
        distance = ((xj-xi)**2 + (yj-yi)**2)**(1/2)
        list_distance.append(distance)

Total = sum(list_distance)

Ans = (2*Total)/N
print(Ans)

Solution (Python):
def d(a,b):
    return ((a[0]-b[0])**2+(a[1]-b[1])**2)**(.5)
n = int(raw_input())
l = [map(int,raw_input().split()) for i in range(n)]
s = 0
for i in range(n):
    for j in range(n):
        if i !=j:
            s += d(l[i],l[j])
print s/n

Solution (Python):
import numpy as np
import itertools
import math

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

def pmt(n):
    result = 1
    for i in range(1,n + 1):
        result = result * i
    return result
node_num = int(input())

node_list = []
dist_list = []


for i in range(node_num):
    a, b =  map(float,input().split())
    node_list.append((a,b))
for i in itertools.combinations([i for i in range(node_num)],2):
    node1 = node_list[i[0]]
    node2 = node_list[i[1]]
    dist_list.append(l2_norm(node1, node2))

tmp_list = []
for i in itertools.permutations([i for i in range(node_num)]):
    tmp_list.append("".join(map(str, i)))

count = 0
for i in tmp_list:
    if i.find("01") >= 0:
        count = count + 1
    if i.find("10") >= 0:
        count = count + 1

dist = np.asarray(dist_list)
dist = dist * count
dist = dist.sum()
dist = dist / pmt(node_num)
print(dist)

Solution (Python):
import math

N = int(input())
xy_list = []
for i in range(N):
    xy_list.append([int(i) for i in input().split()])
result = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        city1 = math.pow(xy_list[i][0] - xy_list[j][0], 2)
        city2 = math.pow(xy_list[i][1] - xy_list[j][1], 2)
        result += math.sqrt(city1 + city2)
print("{:.10f}".format(result / N))

Solution (Python):
import math
dis_sum =0
ans =0
root_num =0

n = int(input())
now =n
distance_list=[]
for i in range(n):
    distance_list.append(list(map(int, input().split())))


for i in range(n-1):
    for j in range(i+1,n):
   
        x_dis = (distance_list[i][0] - distance_list[j][0]) **2
        y_dis = (distance_list[i][1] - distance_list[j][1]) **2
        city_dis = math.sqrt(x_dis + y_dis)
        dis_sum += city_dis


ans = 2/n * dis_sum
print(ans)

Solution (Python):
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
XY = list(map(int, read().split()))
X = XY[0::2]
Y = XY[1::2]

t = 0
for i in range(N):
    for j in range(i, N):
        
        t += math.sqrt((X[i] - X[j])**2 + (Y[i] - Y[j])**2)
print(2*t/N)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
XY = list(map(int, read().split()))
X = XY[0::2]
Y = XY[1::2]

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

Solution (Python):
from itertools import permutations as perm
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
XY = list(map(int, read().split()))
X = XY[0::2]
Y = XY[1::2]

res = 0
cnt = 0
for p in perm(range(N)):
    for i in range(N - 1):
        res += ((X[p[i + 1]] - X[p[i]])**2 + (Y[p[i + 1]] - Y[p[i]])**2)**0.5
    cnt += 1    
print(res/cnt)

Solution (Python):
from itertools import permutations as perm
import sys
import math
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
XY = np.array(read().split(), np.int64)
X = XY[0::2]
Y = XY[1::2]

res = 0
cnt = 0
for p in perm(range(N)):
    for i in range(N - 1):
        res += math.sqrt((X[p[i + 1]] - X[p[i]])**2 + (Y[p[i + 1]] - Y[p[i]])**2)
    cnt += 1    
print(res/cnt)

Solution (Python):
import itertools,math

def distance(x1,y1,x2,y2):
    d=((x1-x2)**2+(y1-y2)**2)**0.5
    return d

N=int(input().strip())
x=[0]*N
y=[0]*N

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

lst=list(range(N))
dist=0
for v in itertools.permutations(lst):
    for i in range(N-1):
        dist+=distance(x[v[i]],y[v[i]],x[v[i+1]],y[v[i+1]])
print(dist/math.factorial(N))

Solution (Python):
import math
import itertools

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

m = []
l = 1
for i in range(N):
  m.append(int(i))

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

for j in itertools.permutations(m):
  for i in range(N-1):
     cnt = cnt + math.sqrt(((n[j[i]][0]-n[j[i+1]][0])**2)+((n[j[i]][1]-n[j[i+1]][1])**2))

print(cnt/l)

Solution (Python):
import itertools
import math
n = int(input())
cities = []
distance = 0
for i in range(n):
    cities.append([int(x) for x in input().split()])

all  = list(itertools.permutations(cities))

for j in range(len(all)):
    for k in range(len(all[j])-1):
        distance += math.hypot(all[j][k][0] - all[j][k+1][0], all[j][k][1] - all[j][k+1][1]) 
average = distance/len(all)
print(average)

Solution (Python):
from itertools import permutations

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

p_li = list(permutations(li))

dist = 0

for p in p_li:
  for j in range(n-1):
    dist += ((p[j][0] - p[j+1][0]) ** 2 + (p[j][1] - p[j+1][1]) ** 2) ** 0.5
  
result = dist/(len(p_li))
print(result)

Solution (Python):
import itertools
n = int(input())
arr = [list(map(int, input().split())) for i in range(n)]
ans = 0
perms = list(itertools.permutations(arr))

for perm in perms:
    for i in range(n - 1):
        x1, y1 = perm[i]
        x2, y2 = perm[i + 1]
        ans += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
print(ans / len(perms))

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

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

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

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

li = []
dire = 0

for i in range(n):
  x, y = map(int,input().split())
  li.append((x, y))
  
for j in range(n):
  for k in range(n):
    dire += ((li[j][0]-li[k][0]) ** 2 + (li[j][1]-li[k][1]) ** 2) ** 0.5

print(dire/n)

Solution (Python):
import itertools
import math
n = int(input())
x = [0]*n
y = [0]*n
distance = [0]*math.factorial(n)
j = 0
for i in range(n):
    x[i],y[i] = map(int,input().split())

n_list = list(itertools.permutations(list(range(n))))

for l in n_list:

    for j in range(n-1):
        distance[j] = distance[j] + math.sqrt((x[l[j]]-x[l[j+1]])**2 + (y[l[j]]-y[l[j+1]])**2)

    j += 1
print(sum(distance)/math.factorial(n))

Solution (Python):
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int, input().split())
d=0
for i,j in zip(x,y):
  for k,l in zip(x,y):
    m1,m2=i-k,j-l
    o=m1**2+m2**2
    d+=o**0.5
print(d/n)

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

Solution (Python):
import itertools

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

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

n = range(N)
ptns = list(itertools.permutations(n,N))

ans = 0

for route in ptns:
    for idx, val in enumerate(route):
        if idx == len(route) - 1:
            break
        dep = route[idx]
        arr = route[idx + 1]
        dist = distance(x[dep][0], x[arr][0], x[dep][1], x[arr][1])
        ans += dist

print(ans / len(ptns))