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 itertools
n=int(input())
x=[list(map(int,input().split())) for i in range(n)]
a=[]
for i in range(n):
    a.append(i)

p=list(itertools.permutations(a,n))

aa=1
for j in range(1,n+1):
  aa*=j

len=0
for j in range(aa):
  for i in range(n-1):
    len+=((x[p[j][i]][0]-x[p[j][i+1]][0])**2+(x[p[j][i]][1]-x[p[j][i+1]][1])**2)**(1/2)
b=len/aa
print(b)

Solution (Python):
import itertools
import math

n = int(input())

xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]
sum = 0
def distance(a, b):
  return ((x[a]-x[b])**2+(y[a]-y[b])**2)**(1/2)


permutations_lis = itertools.permutations(range(n))


for one_case in permutations_lis: 
  for i in range(n-1):
    sum += distance(one_case[i], one_case[i+1])
    
print(sum/math.factorial(n))

Solution (Python):
import itertools

def calculate_distance(x1, x2):
    l2_norm = (x1[0] - x2[0])**2 + (x1[1] - x2[1])**2
    return l2_norm**(1/2)

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

distance = 0
M = 0
for a in itertools.permutations(range(N)):
  M += 1
  
  for i in range(N-1):
        start, end = a[i], a[i+1]
        distance += calculate_distance(point[start], point[end])
print(distance/M)

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

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


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

nC2 = list(combinations(xy, 2))
dist = []
d_append = dist.append
for a, b in nC2:
    d_append(sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2))

if len(dist) == 1:
    print(dist[0])
else:
    dist_sum = 0
    dist_case = list(combinations(dist, N - 1))
    for d in dist_case:
        dist_sum += sum(d)

    print(dist_sum / len(dist_case))

Solution (Python):
from itertools import permutations
from numpy import sqrt
def dist(x,y):
    return sqrt((x[0]-y[0])**2 + (x[1]-y[1])**2)

N = int(input())

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

ans = 0
l = 0
for way in permutations(range(0,N)):
    l += 1
    for i in range(N-1):
        ans += dist(d[way[i]],d[way[i+1]])
    
print(ans/l)

Solution (Python):


import sys
import numpy as np
import itertools

N = int(input())
town = []
for _ in range(N):
    x, y = map(int, sys.stdin.readline().strip().split())
    town.append((x, y))


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


total = 0
for i in itertools.permutations(iterable=town):
    for j in range(len(i) - 1):
        total += distance(i[j], i[j + 1])

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

ans = total / n_fact

print(ans)

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

def dis(li_i, li_y):
    return ((li_i[0]-li_y[0])**2+(li_i[1]-li_y[1])**2)**(1/2)

ans=[]
for p in itertools.permutations([i for i in range(n)]):
    total_dis=0
    for v in range(n-1):
        total_dis+=dis(li[p[v]], li[p[v+1]])
    ans.append(total_dis)
print(sum(ans)/len(ans))

Solution (Python):
from itertools import permutations

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

ans = []
for case in permutations([i for i in range(N)]):
    total = 0
    for i in range(len(case)-1):        
        total += ((dist[case[i]][0]-dist[case[i+1]][0])**2 + (dist[case[i]][1]-dist[case[i+1]][1])**2)**(1/2)
    ans.append(total)

print(sum(ans)/len(ans))

Solution (Python):
from itertools import permutations, combinations

def main():
    n = int(input())
    x_l = [] ; y_l = []
    for _ in range(n):
        tmp_x, tmp_y = map(int, input().split())
        x_l.append(tmp_x) ; y_l.append(tmp_y)
    cnt = 0
    total_dist = 0
    for c in permutations(range(n)):
        
        for i in range(n-1):
            dist = ((x_l[c[i]] - x_l[c[i+1]])**2 + (y_l[c[i]] - y_l[c[i+1]])**2)**(1/2)
            total_dist += dist
        cnt += 1

    print(total_dist/cnt)

if __name__ == "__main__":
    main()

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

Solution (Python):
from math import sqrt

n = int(input())

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

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

distSum = 0
for i in range(n):
	for j in range(i+1,n):
		distSum += dist(tCood[i],tCood[j])

avg = (2*distSum)/n
print(avg)

Solution (Python):
from math import sqrt
n = int(input())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

d = 0
for i in range(n):
    for j in range(i):
        x = a[i] - a[j]
        y = b[i] - b[j]
        d += sqrt(x**2 + y**2)
d *= 2
d /= n
print(d)

Solution (Python):
import itertools

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

jyunlist = [i for i in range(N)]
p_list = list(itertools.permutations(jyunlist))
a = 0
sum = 0
for keiro in p_list:
    for i in range(N-1):
        a = ((xylist[keiro[i+1]][0]-xylist[keiro[i]][0])**2+(xylist[keiro[i+1]][1]-xylist[keiro[i]][1])**2)**(1/2)
        sum += a
ans = sum/len(p_list)

print(ans)

Solution (Python):



import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect

from itertools import permutations




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

cases = list(permutations(list(range(N)), N))

ans = 0
for case in cases:
    dist = 0
    for i in range(1, N):
        a, b = case[i-1], case[i]
        dist += ((data[a][0] - data[b][0])**2 + (data[a][1] - data[b][1])**2)**.5
    ans += dist

print(ans/len(cases))

Solution (Python):
import math

n = int(input())
xy_list = [list(map(int,input().split())) 
           for nesya in range(n)]
c = 0
for xy in xy_list:
  x = xy[0]
  y = xy[1]
  for ab in xy_list:
    a = ab[0]
    b = ab[1]
    c += math.sqrt((x-a)**2+(y-b)**2)
print(c/n)

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
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

def resolve():
    N,=pin()
    p=[tupin() for _ in range(N)]
    def fact(k):
        if k==0:return 1
        return k*fact(k-1)
        
    ans=dict()
    for i in range(N-1):
        for j in range(i+1,N):
            temp=0
            for k in range(2):
                temp+=(p[i][k]-p[j][k])**2
            ans.setdefault(temp,0)
            ans[temp]+=1
    x=0
    for a in ans.items():
        x+=(a[0]**0.5)*a[1]
    
    print((x*2)/(N))
        

resolve()

Solution (Python):
import itertools

n = int(input()) 
p_list = itertools.permutations([x for x in range(n)])




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


d_sum = 0
cnt = 0
for p in p_list:
    cnt+=1
    curr_d_sum = 0
    curr_pos = p[0]
    for i in p:
        x_d = a_list[curr_pos][0] - a_list[i][0]
        y_d = a_list[curr_pos][1] - a_list[i][1]
        d = (x_d**2 + y_d**2)**0.5
        curr_d_sum += d
        curr_pos = i
    d_sum += curr_d_sum
print(d_sum/cnt)

Solution (Python):
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

import itertools
import math

n = I()
p = [LI() for i in range(n)]

nums = range(n)
result = 0
count = 0
for lis in itertools.permutations(nums,n):
    x = 0
    for i in range(n-1):
        x += math.sqrt((p[lis[i+1]][1]-p[lis[i]][1])**2 + (p[lis[i+1]][0]-p[lis[i]][0])**2)
    
    result += x
    count += 1

print(result / count)

Solution (Python):
import itertools, math

n = int(input())
xy = []
kai = 1
for i in range(n):
    xy.append(list(map(int, input().split())))
    kai *= (i + 1)
    
cost = 0
for lst in itertools.permutations(range(n), n):
    x = xy[lst[0]][0]
    y = xy[lst[0]][1]
    for num in lst:
        dx = xy[num][0] - x
        dy = xy[num][1] - y
        cost += math.sqrt(dx ** 2 + dy ** 2)
        x = xy[num][0]
        y = xy[num][1]
print(cost / kai)

Solution (Python):

import re
import math
from collections import defaultdict
from collections import deque
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache

readline=sys.stdin.readline
sys.setrecursionlimit(2000000)

alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_pow(a,b):
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
    return ret
def seifu(x):
    return x//abs(x)

def main():
    n=int(input())
    facs=get_facs(n+5)
    ans=0
    x=[0]*n
    y=[0]*n
    for a in range(n):x[a],y[a]=map(int,input().split())
    for a in range(n):
        for b in range(n):
            ans+=facs[n-1]*math.sqrt((x[a]-x[b])**2+(y[a]-y[b])**2)
    ans/=facs[n]
    print(ans)
main()

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


x = [i for i in range(n)]
candi = itertools.permutations(x)

dist = 0
count = 0
for i in candi: 
  for j in range(0,n-1):
    now = a[i[j]] 
    next = a[i[j+1]] 
    dist += math.sqrt((next[0] - now[0])**2 + (next[1] - now[1])**2)
  count += 1

print(dist/count)

Solution (Python):
import itertools
n = int(input())
xy = [[]]*n
for i in range(n):
  xy[i] = list(map(int,input().split()))
routes = list(itertools.permutations(list(range(n))))
routenum = len(routes)
routeavg = 0
for i in routes:
  curroute = 0
  for j in range(1,n):
    curroute += ((xy[i[j]][0]-xy[i[j-1]][0])**2+(xy[i[j]][1]-xy[i[j-1]][1])**2)**0.5
  routeavg += curroute/routenum
print(routeavg)

Solution (Python):
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
import numpy as np
import math
import itertools
t = math.factorial(n)/(math.factorial(2)*math.factorial(n-2))

dist = np.zeros(int(t))
count =0
for i in range(n-1):
    
    for j in range(i+1,n):
        
        dist[count] = math.sqrt(pow(p[i][0]-p[j][0],2)+pow(p[i][1]-p[j][1],2))
        count += 1


print(2*sum(dist)/n)

Solution (Python):
import itertools
import math

N = int(input())

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

list_per = list(itertools.permutations(list(range(N))))
num = len(list_per)

llength = list()
for i in range(num):
    length = 0
    for j in range(N-1):
        length += math.sqrt((lloc[list_per[i][j]][0] - lloc[list_per[i][j+1]][0])**2 + (lloc[list_per[i][j]][1] - lloc[list_per[i][j+1]][1])**2)
    llength.append(length)

print(sum(llength)/len(llength))

Solution (Python):
import itertools
import math

N = int(input())

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

list_per = list(itertools.permutations(list(range(N))))
num = len(list_per)

llength = list()
for i in range(num):
    length = 0
    for j in range(N-1):
        length += math.sqrt((lloc[list_per[i][j]][0] - lloc[list_per[i][j+1]][0])**2 + (lloc[list_per[i][j]][1] - lloc[list_per[i][j+1]][1])**2)
    llength.append(length)

print(sum(llength)/len(llength))

Solution (Python):
import itertools
N = int(input())
place = [list(map(int,input().split())) for _ in range(N)]
d_sum = 0
perm_len = 0
for p in itertools.permutations(list(range(N))):
    perm_len += 1
    for i in range(1,N):
        d_sum += ((place[p[i-1]][0]-place[p[i]][0])**2 + (place[p[i-1]][1]-place[p[i]][1])**2)**(1/2)
print(d_sum/perm_len)

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

N = int(input())

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

i = 0
length = []
for comb in permutations(range(1, N+1), N):
    tmp = 0
    for i in range(len(comb)-1):
        tmp += ((x[comb[i+1]-1] - x[comb[i]-1])**2 + (y[comb[i+1]-1] - y[comb[i]-1])**2)**(1/2)
    length.append(tmp)
print(sum(length)/factorial(N))

Solution (Python):
import itertools
import math
n=int(input())
xlist=[]
ylist=[]
ans=0
numlist=list(itertools.permutations(range(1,n+1)))
for i in range(n):
    x,y=map(int,input().split())
    xlist.append(x)
    ylist.append(y)
for i in range(len(numlist)):
    for j in range(n-1):
        a=numlist[i][j]-1
        b=numlist[i][j+1]-1
        ans+=math.sqrt((xlist[a]-xlist[b])*(xlist[a]-xlist[b])+(ylist[a]-ylist[b])*(ylist[a]-ylist[b]))
print(ans/(len(numlist)))

Solution (Python):
import itertools
import math


def distance():
    N = int(input())
    x_y = [tuple(map(int, input().split())) for _ in range(N)]
    combis = list(itertools.permutations(x_y, N))

    def euclid(p1, p2):
        return math.sqrt((pow((p1[0] - p2[0]), 2) + pow((p1[1] - p2[1]), 2)))
    result = 0
    for combi in combis:
        for i in range(len(combi)-1):
            result += euclid(combi[i], combi[i+1])
    print(float(result / len(combis)))


if __name__ == "__main__":
    distance()

Solution (Python):
import math
import itertools


N = int(input())

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

permutation_list = itertools.permutations([x for x in range(N)])

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

result = 0
count = 0
for data in permutation_list:
    count += 1
    for i in range(1, len(data)):
        result += calc[data[i - 1]][data[i]]
print(result / count)

Solution (Python):
import math
import itertools


N = int(input())

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

result = 0
count = 0
permutation_list = itertools.permutations([x for x in range(N)])

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

for data in permutation_list:
    count += 1
    for i in range(1, len(data)):
        result += calc[data[i - 1]][data[i]]
print(result / count)

Solution (Python):
from itertools import permutations
from math import factorial
n = int(input())
towns = [list(map(int, input().split())) for _ in range(n)]
path_length = 0
for p in permutations(towns):
    for (x1, y1), (x2, y2) in zip(p, p[1:]):
        path_length += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 
ans = path_length / factorial(n)
print(ans)

Solution (Python):
import math
import itertools


N = int(input())

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

result = 0
count = 0
permutation_list = itertools.permutations([x for x in range(N)])
for data in permutation_list:
    count += 1
    for i in range(1, len(data)):
        result += math.sqrt((array[data[i]][0] - array[data[i - 1]][0]) ** 2 +
                            (array[data[i]][1] - array[data[i - 1]][1]) ** 2)
print(result / count)

Solution (Python):
import itertools
import math
n = int(input())
pattern = list(itertools.permutations(range(n)))
xy = [list(map(int,input().split())) for _ in range(n)]
n2 = 1

for i in range(1,n+1):
    n2 *=i
ans = 0
for j in pattern:
    for k in range(n-1):
        ans += ((xy[j[k+1]][0] - xy[j[k]][0])**2 + (xy[j[k+1]][1] - xy[j[k]][1])**2)**0.5

print(ans/n2)

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 itertools
import math
n=int(input())
xy=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in itertools.permutations(xy,n):
  sum=0
  for t in range(n-1):
    sum+=((i[t][0]-i[t+1][0])**2+(i[t][1]-i[t+1][1])**2)**(1/2)
  ans+=sum
print(ans/math.factorial(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())

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

print(ans)

Solution (Python):
def main():
    N=int(input())
    xy=[[int(_) for _ in input().split()] for _ in range(N)]
    distance = 0
    for i in range(N-1):
        for j in range(i, N):
            distance += ( (xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2 ) ** 0.5
    print(distance / (N/2))

main()

Solution (Python):

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

Solution (Python):
import numpy as np
import itertools 
def distance(a,b):
    x1,y1 = a
    x2,y2 = b
    return np.sqrt((x1-x2)**2 + (y1- y2)**2)
n = int(input())
xy = []
for _ in range(n):
    x,y = map(int,input().split())
    xy.append([x,y])
n_permutations = itertools.permutations(range(n))
dist_list=[]
for one_case in n_permutations:
    dist = 0
    for i in range(n-1):
        a = xy[one_case[i]]
        b = xy[one_case[i+1]]
        dist += distance(a,b)
    dist_list.append(dist)
print(sum(dist_list)/len(dist_list))

Solution (Python):
n = int(input())
a = []
for i in range(n):
  x,y=map(int,input().split())
  a.append((x,y))
s = 0
import itertools
import math
import fractions
for l in itertools.permutations(range(n)):

  for i in range(n-1):
    s += math.sqrt((a[l[i]][0]-a[l[i+1]][0])**2 + (a[l[i]][1]-a[l[i+1]][1])**2)
print(s/math.factorial(n))

Solution (Python):
import itertools
n = int(input());
X = []
Y = []

for i in range(n):
  x, y = map(int, input().split());
  X.append(x);
  Y.append(y);
    
list_ = list(itertools.permutations(range(n)))
ans = 0
ans_list = []

for i in list_:
  for j in range(n - 1):
    ans += ((X[i[j + 1]] - X[i[j]]) ** 2 + (Y[i[j + 1]] - Y[i[j]]) ** 2) ** (1 / 2)
  
  ans_list.append(ans)
  ans = 0 
  
print(sum(ans_list) / len(ans_list))

Solution (Python):

import sys
import math
from collections import defaultdict
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines

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

ans = 0
fa = 0

for x in list(itertools.permutations( [i for i in range(1,N+1)] , N)):
    for i in range(N-1):
        xx = coordinate[x[i]-1][0] - coordinate[x[i+1]-1][0]
        y = coordinate[x[i]-1][1] - coordinate[x[i+1]-1][1]
        ans += math.sqrt(xx**2 + y ** 2)
    fa += 1
print(ans/fa)

Solution (Python):

import sys
import math
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines

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

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

ans = 0.0
for i in range(N):
    for j in range(N):
        ans = ans + math.sqrt( (coordinate[i][0] - coordinate[j][0]) ** 2 + (coordinate[i][1] - coordinate[j][1]) ** 2)
print(ans * foactorial / (foactorial * N) )

Solution (Python):
import itertools
import math

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

for i in p_lis:
    for j in range(n-1):
        r = ((x[i[j+1]][0] - x[i[j]][0])**2 + (x[i[j+1]][1] - x[i[j]][1])**2) **0.5
        s += r
ans = s/math.factorial(n)
print(ans)

Solution (Python):
import math

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


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





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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

N = INT()
xy = [LIST() for _ in range(N)]

distance = 0
cnt = 0

for p in permutations(xy, N):
	cnt += 1
	for i in range(N-1):
		distance += dist(p[i], p[i+1])

print(distance/cnt)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

N = INT()
xy = [LIST() for _ in range(N)]

distance = 0
cnt = 0

for p in permutations(xy, N):
	cnt += 1
	for i in range(N-1):
		distance += dist(p[i], p[i+1])

print(distance/cnt)

Solution (Python):
n = int(input())
import math
import itertools
p = []
q = 0
for i in range(n):
    a,b = map(int,input().split())
    p.append((a,b))
s = itertools.permutations(p, n)
for i in s:
    for j in range(n-1):
        q += ((i[j][0]-i[j+1][0])**2+(i[j][1]-i[j+1][1])**2)**0.5
print(q/math.factorial(n))

Solution (Python):

from itertools import permutations


def main():
    temp = 0
    n = int(input())
    plot_list = [list(map(int,input().split())) for _ in range(n)]
    case = list(permutations(range(n)))

    for c in case:
        for i in range(n-1):
            temp += ((plot_list[c[i]][0] - plot_list[c[i+1]][0])**2 + (plot_list[c[i]][1] - plot_list[c[i+1]][1])**2)**0.5

    print(temp/len(case))


if __name__ == '__main__':
    main()

Solution (Python):
import math
import itertools
def distance(xi,yi,xj,yj):
    return(math.sqrt((xi-xj)**2+(yi-yj)**2))
n = int(input())
xy = []
for i in range(n):
    li = list(map(int,input().split()))
    xy.append(li)
dis_li = []
count = 0
for it in itertools.permutations(xy):
    dis = 0
    for i in range(len(it)-1):
        dis += distance(it[i][0],it[i][1],it[i+1][0],it[i+1][1])
    dis_li.append(dis)
    count += 1
print(sum(dis_li)/count)

Solution (Python):
from itertools import permutations

n = int(input())

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

s = 0
count = 0

for i in permutations(range(n), n):
    count += 1
    for a, b in zip(i, i[1:]):
        s += ((lis[a][0] - lis[b][0])**2 + (lis[a][1] - lis[b][1])**2) ** 0.5

print(s/count)

Solution (Python):
from itertools import permutations

n = int(input())

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

s = 0
count = 0

for i in permutations(range(n), n):
    count += 1
    for a, b in zip(i, i[1:]):
        s += ((lis[a][0] - lis[b][0])**2 + (lis[a][1] - lis[b][1])**2) ** 0.5

print(s/count)

Solution (Python):
from itertools import combinations
N = int(input())
town = []
for n in range(N):
    x, y = map(int,input().split())
    town.append((x,y))

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

Solution (Python):
import itertools

n=int(input())
li=[list(map(int,input().split())) for _ in range(n)]
ans,div=[],0

for i in itertools.permutations(range(n),n):
  div+=1
  dis=0
  for a,b in zip(i,i[1:]):
    dis += ((li[b][0]-li[a][0])**2 + (li[b][1]-li[a][1])**2)**0.5
  ans.append(dis)

print(sum(ans)/div)

Solution (Python):
import math

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

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

from math import sqrt
from itertools import permutations

length = []
r = list(permutations(range(n)))

for i in r:
    for j in range(n-1):
        x1 = x[i[j]][0]
        y1 = x[i[j]][1]
        x2 = x[i[j+1]][0]
        y2 = x[i[j+1]][1]
        length.append(sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)))

print(sum(length)/len(r))

Solution (Python):
import itertools
import math

N = int(input())
pl = itertools.permutations([i for i in range(N)])
xy = [list(map(int, input().split())) for _ in range(N)]
s = 0
for l in pl:
    for i in range(N - 1):
        xi, yi = xy[l[i]]
        xj, yj = xy[l[i + 1]]
        s += ((xi - xj)**2 + (yi - yj)**2)**0.5
print(s / math.factorial(N))

Solution (Python):
n = int(input())
clist = []
for i in range(n):
  cx, cy = list(map(int, input().split()))
  c = [cx, cy]
  clist.append(c)
dlist = []
for j in range(n):
  sc = clist[j]
  for k in range(j + 1, n):
    dc = clist[k]
    d = ((sc[0] - dc[0]) ** 2 + (sc[1] - dc[1]) ** 2) ** 0.5
    dlist.append(d)
print(sum(dlist) / n * 2)