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 sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res



def A():
    r = I()
    print(r * r)
    return



def B():
    N = I()
    s = S()
    if N % 2 != 0:
        print("No")
    elif ''.join(s[:N // 2]) == ''.join(s[N // 2:]):
        print("Yes")
    else:
        print("No")
    return



def C():
    n = I()
    a = [LI() for i in range(n)]
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            ans += pow(pow(a[i][0] - a[j][0], 2) + pow(a[i][1] - a[j][1], 2), 0.5)
    avg = ans / (n*(n-1)/2)
    print(avg * (n - 1))
    return



def D():
    return



def E():
    return



def F():
    return



def resolve():
    C()
    return



if __name__ == "__main__":
    C()

Solution (Python):
import itertools

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

kyori = 0
num = 0
for v in itertools.permutations(Town, N):
    num += 1
    for i in range(N-1):
        kyori += ((v[i][0]-v[i+1][0])**2 + (v[i][1]-v[i+1][1])**2)**0.5

print(kyori/num)

Solution (Python):
import sys
import itertools
import math
n = int(sys.stdin.readline())

pos = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
a = list(itertools.permutations(pos, n))

ans = 0
for ele in a:
    
    for i in range(n-1):
        ans += math.sqrt((ele[i][0] - ele[i+1][0])**2 + (ele[i][1] - ele[i+1][1])**2)
print(ans/len(a))

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

N, *XY = map(int, open(0).read().split())

XY = list(zip(*[iter(XY)] * 2))
ans = 0
for p in permutations(XY):
    ans += sum(hypot(ax - bx, ay - by) for (ax, ay), (bx, by) in zip(p, p[1:]))

print("{:.9f}".format(ans / factorial(N)))

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

M = [-1]*N
pathlist = []
def makepath(k, prev):
    if k==N: pathlist.append(M[:])
    for i in range(N):
        if M[i]>=0: continue
        M[i] = k
        makepath(k+1, i)
        M[i] = -1

makepath(0, -1)

s = 0
for p in pathlist:
    for i in range(N-1):
        s += D[p[i]][p[i+1]]
        
print(s/len(pathlist))

Solution (Python):
import math

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

dist = [[0] * N for _ in range(N)]


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

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


sum_ = 0
p = pow(N - 1)
for i in range(N):
    for j in range(i, N):
        c = d(pos[i][0], pos[i][1], pos[j][0], pos[j][1])
        sum_ += c * p * 2

print(sum_ / pow(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())
sum=0
for i in range(n-1):
  for j in range(i+1,n):
    sum += math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
print(2*sum/n)

Solution (Python):
import sys
from itertools import permutations

input = sys.stdin.readline
def main():
    N = int(input())
    x, y = [], []
    
    for i in range(N):
        a, b = map(int, input().split())
        x.append(a)
        y.append(b)
        
    table = {}
    
    for i in range(N):
        for j in range(N):
            if i == j: continue
            
            table[(i, j)] = ((x[i]-x[j]) ** 2 + (y[i]-y[j]) ** 2) ** 0.5
            
    ans = 0
    
    for r in list(permutations([i for i in range(N)])):  
        for j in range(N-1):
            ans += table[(r[j], r[j+1])]
    
    cur = 1
    for i in range(1, N+1): cur *= i
        
    print(ans / cur)

if __name__ == '__main__':
    main()

Solution (Python):
import math
def combination(x,y):
    return math.factorial(x)//(math.factorial(y)*math.factorial(x-y))

n = int(input())
xs = []
ys = []
sum = 0
for i in range(n):
    [x,y] = [int(i) for i in input().split()]
    xs.append(x)
    ys.append(y)
for i in range(n):
    for j in range(i+1, n):
        sum += math.sqrt((xs[i]-xs[j])**2 +(ys[i] - ys[j])**2)
if n > 2:
    sum *= math.factorial(n-1)*2
else:
    sum *= 2
print(sum/math.factorial(n))

Solution (Python):
import math
n = int(input())
A = []
for i in range(n):
  a,b = map(int,input().split())
  A.append([a,b])
sum = 0
for i in range(n):
  for j in range(n):
    if j <= i:
      continue
    else:
      sum += math.sqrt((A[i][0]-A[j][0])**2+(A[i][1]-A[j][1])**2)

print(sum*2/n)

Solution (Python):
import math
import itertools
n = int(input())
x = list() 
y = list()
for i in range(n):
    a,b = map(int, input().split())
    x.append(a)
    y.append(b)
its = list()
for val in range(n):
    its.append(val)
it = list(itertools.permutations(its))
all = 0
for i in it:
    for j in range(1, len(i)):
        c = math.sqrt((x[i[j-1]]-x[i[j]])**2 + (y[i[j-1]]-y[i[j]])**2)
        all += c
all /= len(it)
print(all)

Solution (Python):
from itertools import permutations
import math

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

for p in permutations(range(n)):

    p = list(p)
    sum = 0
    for i in range(n-1):
        xi,yi = xy[p[i]]
        xj,yj = xy[p[i+1]]
        sum += math.sqrt((xi-xj)**2 + (yi-yj)**2)
    d += sum

print(d/math.factorial(n))

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

from itertools import permutations
import math

def calc_distance(z_list):
    dist = 0
    (_x, _y) = z_list[0]
    for _x2, _y2 in z_list[1:]:
        dist += math.sqrt(abs(_x-_x2)**2+abs(_y-_y2)**2)
        _x = _x2
        _y = _y2
    return dist

ans = 0
for z in permutations(X):
    ans += calc_distance(z)

print(ans/math.factorial(n))

Solution (Python):
import math

n=int(input())
city=[[int(i) for i in input().split()] for i in range(n)]
nkai=math.factorial(n)
n1kai=math.factorial(n-1)

lengths=[]
for i in range(n):
  for j in range(n):
    length=((city[i][0]-city[j][0])**2+(city[i][1]-city[j][1])**2)**0.5
    lengths.append(length)
   
total=n1kai*2*sum(lengths)
ans=total/nkai/2
print(ans)

Solution (Python):
import itertools
import math

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


patterns = list(itertools.permutations(towns, n))

answers = []
for pattern in patterns:
  distance = 0
  for i in range(n-1):
    distance += math.sqrt((pattern[i+1][0] - pattern[i][0])**2+(pattern[i+1][1] - pattern[i][1])**2)
  answers.append(distance)


print(sum(answers)/len(answers))

Solution (Python):
import math
import itertools
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
rt=[]
for i in range(n):
    for j in range(i+1,n):
        x1=xy[i][0]
        y1=xy[i][1]
        x2=xy[j][0]
        y2=xy[j][1]
        rt.append([(i,j),math.sqrt((x1-x2)**2+(y1-y2)**2)])
l=[i for i in range(n)]
sm=0
cnt=0
for v in list(itertools.permutations(l,n)):
    for i in range(n-1):
        f,t=v[i],v[i+1]
        if f>t:
            f,t=t,f
        for r in rt:
            if r[0]==(f,t):
                sm+=r[1]
    cnt+=1
print(sm/cnt)

Solution (Python):
import math
N=int(input())
l=[]
ans=0
for _ in range(N):
  x,y=map(int,input().split())
  for s in l:
    ans+=math.sqrt((s[0]-x)**2+(s[1]-y)**2)
  l.append([x,y])
print(2*ans/N)

Solution (Python):
from itertools import permutations
from math import sqrt
def dist(x1,y1,x2,y2):
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
n = int(input().strip())
pl=[]
for i in range(n):
    pl.append(i)
l=[]
for i in range(n):
    x,y=map(int,input().strip().split())
    l.append([x,y])
d=[]
for i in permutations(pl):
    x=list(i)
    s=0
    for i in range(n-1):
        s+=dist(l[x[i]][0],l[x[i]][1],l[x[i+1]][0],l[x[i+1]][1])
    d.append(s)
avg=0.0
for i in range(len(d)):
    avg+=d[i]
print(avg/len(d))

Solution (Python):
import subprocess
import os
import time


import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)




def main():
    n = int(input())
    coordinates = []

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

    count = 0

    for x in range(n):
        for y in range(x+1, n):
            xg = (coordinates[x][0] - coordinates[y][0])**2
            yg = (coordinates[x][1] - coordinates[y][1])**2
            count += math.sqrt(xg+yg)

    r_avg = count / (n**2/2)

    print(r_avg * n)


if __name__ == '__main__':
    main()

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









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

total = 0
for keiro in list(it.permutations(point)):
  for i, town in enumerate(keiro[:-1]):
    x1, y1 = keiro[i]
    x2, y2 = keiro[i+1]
    total += math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
  
print(total/len(list(it.permutations(point))))

Solution (Python):
from itertools import permutations

def dist(xy1, xy2):
  return ((xy1[0] - xy2[0]) ** 2 + (xy1[1] - xy2[1]) ** 2)**.5

N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
li = list(permutations(range(N)))
lenli = len(li)

distSum = 0
for line in li:
  for i in range(N-1):
    distSum += dist(XY[line[i]], XY[line[i+1]])
  
print(distSum / lenli)

Solution (Python):
N = int(input())
XY = []
for _ in range(N):
    XY.append([int(i) for i in input().split()])
case_list = [n for n in range(N)]
from itertools import permutations
P = list(permutations(case_list,N))
dist_sum = 0
cnt = 0
for p in P:
    dist = 0
    for i in range(len(p)-1):
        dist += ((XY[p[i+1]][0] - XY[p[i]][0]) ** 2 + (XY[p[i+1]][1] - XY[p[i]][1]) ** 2) ** 0.5
    dist_sum += dist
    cnt += 1
print(dist_sum / cnt)

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


def length(point1, point2):
    delx = point1[0]-point2[0]
    dely = point1[1]-point2[1]
    return math.pow(delx*delx + dely*dely, 0.5)


def main():
    count = 0
    ways = math.factorial(n)
    for route in itertools.permutations(point_range, n):
        for i in range(len(route)-1):
          count += length(points[route[i]], points[route[i+1]])

    print(count / ways)

main()

Solution (Python):
import math


def get_input():

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


def distance(p1, p2):

    d = (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2
    return math.sqrt(d)


def main():

    N, cities = get_input()
    dist = 0
    for i in range(N):
        for j in range(i+1, N):
            start = cities[i]
            goal = cities[j]
            dist += distance(start, goal) * 2

    print(dist / N)


main()

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




N = int(input())

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

L = 0
for i, j in list(itertools.combinations([i for i in range(N)], 2)):
    x, y = town[i]
    z, w = town[j]
    L += sqrt((x - z)**2 + (y - w)**2)
print(L * 2 / N)

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

dist = [[math.sqrt((point[i][0] - point[j][0])**2 + (point[i][1] - point[j][1])**2) for j in range(n) ] for i in range(n)]
ans = 0
l = [i for i in range(n)]
for v in itertools.permutations(l):
  ans += sum([dist[v[i]][v[i+1]] for i in range(n-1)])
print(ans / math.factorial(n))

Solution (Python):

import sys
import itertools

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

P=list(itertools.permutations(range(N)))
pattern_num=len(P)


total=0

for L in P:
    l=0    
    for i,n in enumerate(L):
        if i==0:
            pass
        else:
            x2=xy[n][0]
            y2=xy[n][1]
            x1=xy[prev_n][0]
            y1=xy[prev_n][1]
            l+=( (x2-x1)**2+(y2-y1)**2 )**0.5
        prev_n=n
    total+=l

print total/pattern_num

Solution (Python):
from itertools import permutations

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

all = list(permutations(town,n))



sum = 0
for i in range(len(all)) :
    for j in range(1, len(all[i])) :
        x = (all[i][j][0] - all[i][j-1][0]) ** 2
        y = (all[i][j][1] - all[i][j-1][1]) ** 2
        sum += (x+y) ** 0.5
        

print(sum/len(all))

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

Solution (Python):
import itertools
n = int(input())
xy = [list(map(int,input().split())) for _ in [0]*n]

seq = [i+1 for i in range(n)]

p_seq = list(itertools.permutations(seq))



def dis(num1,num2):
  d = ((xy[num1][0]-xy[num2][0])**2 + (xy[num1][1]-xy[num2][1])**2)**0.5
  return d

l = len(p_seq)
ans = 0
for i in range(l):
  for j in range(1,n):
    ans += dis(p_seq[i][j-1]-1,p_seq[i][j]-1)
    
print(ans/l)

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

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

dd = [[0]*n for _ in range(n)]
for i in range(n):
  for j in range(i,n):
    dd[i][j] = dd[j][i] = sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)

p = permutations(range(n),n)

ans = 0
count = 0
for v in p:
  count+=1
  add = 0  
  for i in range(n-1):
    add += dd[v[i]][v[i+1]]
  ans += add
  
print(ans/count)

Solution (Python):
import math
import itertools

n = int(input())

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

l = list(itertools.permutations(xy, 2))

res = 0
for i in range(len(l)):
    x1, x2 = l[i][0][0], l[i][1][0]
    y1, y2 = l[i][0][1], l[i][1][1]

    res += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

print(res / n)

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

XY_list = [list(map(int,input().split())) for i in range(N)]
result = 0
for keiro in itertools.permutations(XY_list,N):
    for i in range(1,N):
        
        
        
        result += ((keiro[i][0] - keiro[i-1][0]) ** 2 + (keiro[i][1] - keiro[i-1][1]) ** 2) ** 0.5
print(result/math.factorial(N))

Solution (Python):
import math

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

for xs,ys in P:
  for x,y in P:
    ans += math.sqrt((xs-x)**2+(ys-y)**2)
  
print(ans/N)

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

n = int(input())
p = permutations(tuple(map(int, input().split())) for _ in range(n))
s=sum(((x1-x2)**2+(y1-y2)**2)**0.5 for a in p for(x1,y1),(x2,y2)in zip(a,a[1:]))
print(s / factorial(n))

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

import functools
import itertools
import math

@functools.lru_cache()
def dist_calc(p1, p2):
    return math.sqrt((points[p1][0] - points[p2][0]) ** 2 + (points[p1][1] - points[p2][1]) ** 2)

dist = []
for route in itertools.permutations(range(n)):
    for i in range(n-1):
        dist.append(dist_calc(route[i], route[i+1]))

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

Solution (Python):

import itertools
import math


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


ans = 0
l = list()
for i in range(N):
    l.append(i)

ll = list(itertools.permutations(l))
for i in range(len(ll)):
    for j in range(N - 1):
        ans += math.sqrt(((xy[ll[i][j]][0] - xy[ll[i][j + 1]][0]) ** 2) + ((xy[ll[i][j]][1] - xy[ll[i][j + 1]][1]) ** 2))


print(ans / len(ll))

Solution (Python):
import sys
sys.setrecursionlimit(10000000)

from bisect import *
from collections import *
from heapq import *
import functools
import itertools
import math
INF = float('inf')
MOD = 10**9+7



























N = int(input())
xy = [None]*N
for i in range(N):
    x, y = map(int, input().split())
    xy[i] = (x, y)
ans = 0
for vs in itertools.permutations(xy, N):
    d = 0
    for v1, v2 in zip(vs, vs[1:]):
        d += ((v1[0]-v2[0])**2+(v1[1]-v2[1])**2)**0.5
    ans += d
for i in range(1, N+1):
    ans /= i
print(ans)

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

d = []

for i in range(n):
  t = input().split(" ")
  t = [float(j) for j in t]
  d.append(t)

dsum = 0

for i in range(n):
  for j in list(range(i+1, n)):
    dtmp = ((d[i][0] - d[j][0]) ** 2) + ((d[i][1] - d[j][1]) ** 2)
    dsum = dsum + dtmp ** 0.5

res = dsum / (n / 2)

print(res)

Solution (Python):
n = int(input())
arr = [tuple(map(int,input().split())) for _ in range(n)]

routesum = 0
for i in range(n-1):
    for j in range(i+1,n):
        routesum += ((arr[i][0]-arr[j][0])**2 + (arr[i][1]-arr[j][1])**2)**0.5
        
for i in range(1,n):
    routesum *= i
for i in range(1,n+1):
    routesum /= i

print(routesum*2)

Solution (Python):
import math
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
p=0
for i in range(0,n-1):
  for j in range(i+1,n):
    p+=((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)**0.5
print(p*2/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())
d = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        d += math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
m = d * 2 / N
print(m)

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

N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
sum_ = 0
l = list(permutations(XY))
len_l = len(l)
for perm in l:
    for i in range(N-1):
        sum_ += sqrt((perm[i+1][0] - perm[i][0])**2 + (perm[i+1][1] - perm[i][1])**2)
print(sum_ / len_l)

Solution (Python):
import math

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

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


S = list(itertools.permutations(XY))
D = []
for s in S:
  
  d = 0
  for i in range(1,len(s)):
      d += math.sqrt((s[i-1][0] - s[i][0])**2 + (s[i-1][1] - s[i][1])**2)
  D.append(d)

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

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

Solution (Python):
import math

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

total = 0.0
for start in range(n):
    for end in range(start+1, n):
        dx = points[start][0] - points[end][0]
        dy = points[start][1] - points[end][1]
        dist = math.sqrt(dx*dx+dy*dy)
        total += dist / n
print(total*2)

Solution (Python):
n = int(input())
cities = [complex(*map(int, input().split())) for _ in range(n)]
facts = [1]
for i in range(1, n + 1):
    facts.append(facts[-1] * i)
ans = 0.
for i in range(n):
    ci = cities[i]
    for j in range(i + 1, n):
        cj = cities[j]
        dij = abs(ci - cj)
        ans += dij * facts[n - 1] * 2
print(ans / facts[n])

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=[LI() for _ in range(n)]
  l2=[i for i in range(n)]

  sm=0
  for c in itertools.permutations(l2,n):
    _sm=0
    for i in range(n-1):
      a=l[c[i]]
      b=l[c[i+1]]

      _sm+=math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)
    sm+=_sm

  return sm/math.factorial(n)


print(main())

Solution (Python):
import sys
import itertools
import math
N = int(input())
X = []
Y = []
for _ in range(N):
    x, y = [int(v) for v in input().split()]
    X.append(x)
    Y.append(y)

s = range(N)
ll = []
for l in itertools.permutations(s):
    d = 0
    for j in range(N - 1):
        d += math.sqrt((X[l[j]] - X[l[j + 1]]) * (X[l[j]] - X[l[j + 1]]) + (Y[l[j]] - Y[l[j + 1]]) * (Y[l[j]] - Y[l[j + 1]]))
    
    
    ll.append(d)
print(sum(ll) / len(ll))

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

from itertools import permutations

perms=permutations(xy)
dis=[]
for p in perms:
    d_tmp=[]
    for i in range(1,len(p)):
        d=((p[i][0]-p[i-1][0])**2+(p[i][1]-p[i-1][1])**2)**0.5
        d_tmp.append(d)
    dis.append(sum(d_tmp))
        
print(sum(dis)/len(dis))

Solution (Python):
import itertools
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
tmp = list(itertools.permutations(list(range(N)),N))
length = []
for i in range(len(tmp)):
    tmplen = 0
    for j in range(N-1):
        tmplen += ((xy[tmp[i][j]][0]-xy[tmp[i][j+1]][0])**2+(xy[tmp[i][j]][1]-xy[tmp[i][j+1]][1])**2)**(1/2)
    length.append(tmplen)
print(sum(length)/len(length))

Solution (Python):
import itertools
from math import *
n=int(input())
ps=[list(map(int,input().split())) for _ in range(n)]
perms = list(itertools.permutations(ps, n))
dists = []
for i in range(len(perms)):
  dist = 0
  cur = perms[i][0]
  for j in range(1,len(perms[i])):
    d = sqrt((perms[i][j][0]-cur[0]) ** 2 + (perms[i][j][1]-cur[1])**2)
    cur = perms[i][j]
    dist += d

  dists.append(dist)
print(sum(dists)/len(perms))

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

all_len = 0
p = list(itertools.permutations(range(n)))
for k in range(len(p)):
	for i in range(n-1):
		xi = xy[p[k][i]][0]
		xj = xy[p[k][i+1]][0]
		yi = xy[p[k][i]][1]
		yj = xy[p[k][i+1]][1]
		all_len += ((xi - xj)**2 + (yi - yj)**2)**0.5

print(all_len/len(p))

Solution (Python):
import sys
from itertools import permutations

def main():
    input = sys.stdin.readline
    N = int(input())
    pos = []
    for _ in range(N):
        x, y = map(int, input().split())
        pos.append((x, y))
    
    dists = []
    for root in permutations(range(N), N):
        d = 0
        for i in range(N-1):
            a = root[i]
            b = root[i+1]
            Xd = pos[a][0] - pos[b][0]
            Yd = pos[a][1] - pos[b][1]

            d += (Xd**2 + Yd**2)**0.5
        
        dists.append(d)
    
    return sum(dists) / len(dists)

if __name__ == '__main__':
    print(main())

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

cont = 0
for i in range(N):
  cont += sum(dis[i])

print(cont/N)

Solution (Python):
import sys
input = sys.stdin.readline

import math
import itertools

def main():
    n = int(input())

    x_list = []

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

    li = list(itertools.permutations(x_list))

    c = 0
    for l in li:
        for i, (x, y) in enumerate(l):
            if i+1 == n:
                break
            else:
                x1, y1 = l[i+1]
                c += math.sqrt((x1 - x)**2 + (y1 - y)**2)


    print(c / len(li))



if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
p = []
for i in range(n):
    p.append([int(s) for s in input().split()])

dsum = 0.0
count = 0
for i in range(n):
    for j in range(i):
        d = ((p[i][0]-p[j][0])**2 + (p[i][1]-p[j][1])**2)**0.5
        dsum += d
        count += 1
print((n-1)*dsum/count)

Solution (Python):
N=int(input())
X=[0]*N
Y=[0]*N
for i in range(N):
  X[i],Y[i]=map(int,input().split())
li=[]
for i in range(N):
  for j in range(i,N):
    if i!=j:
      li.append(((X[i]-X[j])**2+(Y[i]-Y[j])**2)**(1/2))
print(sum(li)*2*(N-1)/((N**2-N)))

Solution (Python):
import math
import itertools

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

def solve(N, P, INF=1000000):
    dist = [[0.0 for _ in range(N)] for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if P[i] == P[j]:
                dist[i][j] = 0.0
            else:
                dist[i][j] = math.sqrt((P[i][0] - P[j][0])**2 + (P[i][1] - P[j][1])**2)
    
    cities = list(range(N))
    D = []
    for order in itertools.permutations(cities, N):
        d = 0.0
        for i in range(1, N):
            s = order[i-1]
            t = order[i]
            d += dist[s][t]
        D.append(d)
    return sum(D) / math.factorial(N)

if __name__ == '__main__':
    inputs = read()
    output = solve(*inputs)
    print("%.10f" % output)

Solution (Python):
import math
n = int(input())
x = []
y = []
for i in range(n):
    x1,y1 = map(int, input().split())
    x.append(x1)
    y.append(y1)
tankyori = 0
for j in range(n-1):
    for k in range(j,n):
        tankyori += math.sqrt((x[j] - x[k])**2 + (y[j]- y[k])**2)
print(tankyori*2/n)

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

def inasi(ls,i):
    n = []
    for j in range(len(ls)):
        if j == i:continue
        n.append(ls[j])
    return n

def kyori(ls):
    ans = 0
    for i in range(len(ls)-1):
        ans += math.sqrt((graph[ls[i]][0] - graph[ls[i+1]][0])**2 + (graph[ls[i]][1] - graph[ls[i+1]][1])**2)
    return ans

check = 0
count = 0
def keisan(n,pls,ls):
    global check,count
    if len(ls) == 0:
        check += kyori(pls)
        count += 1
        
        return
    for i in range(len(ls)):
        pls.append(ls[i])
        keisan(n-1,pls,inasi(ls,i))
        try:pls.pop()
        except:pass
    return

keisan(10,[],[i for i in range(n)])
print(check/count)

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

import itertools
import math

ans = 0.0
i = 0
for route in itertools.permutations(town_list):
  i += 1
  before_town = False
  route_length = 0
  for town in route:
    if before_town is False:
      before_town = town
      continue
    route_length += math.sqrt(((before_town[0] - town[0]) ** 2) + ((before_town[1] - town[1]) ** 2))
    before_town = town
  ans += route_length

print(ans / i)

Solution (Python):
import math
import itertools

n = int(input())
t = [list(map(int, input().split())) for _ in range(n)]
d = 0
for i in range(n - 1):
    for j in range(i, n):
        d += (((t[i][0] - t[j][0]) ** 2 + (t[i][1] - t[j][1]) ** 2)
              ** 0.5) * ((n - 1) * math.factorial(n)/len(list(itertools.combinations(range(n), 2))))

print(d/math.factorial(n))

Solution (Python):
import itertools

n = int(input())

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

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

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

print(ans / c)

Solution (Python):
import itertools

N = int(input())

towns = []
for i in range(N):
    town = list(map(lambda x: int(x), input().split(" ")))
    towns.append(town)

p = list(itertools.permutations(towns))
result = 0
for nums in p:
    pre = None
    for num in nums:
        if pre is None:
            pre = num
            continue
        x = pow(pre[0] - num[0], 2)
        y = pow(pre[1] - num[1], 2)
        result += pow(x+y, 0.5)
        pre = num

result /= len(p)
print(result)

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

l=[i for i in range(1,n+1)]



import math
p_list=itertools.permutations(l,n)
ans_l=[]
for mytuple in p_list:
  
  distance=0
  for k in range(1,n):
    now=mytuple[k]
    
    bef=mytuple[k-1]
    
    distance+=math.sqrt((dis[now-1][0]-dis[bef-1][0])**2+(dis[now-1][1]-dis[bef-1][1])**2)
  
  ans_l.append(distance)
ans=sum(ans_l)/len(ans_l)
print("{:.11f}".format(ans))

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

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

amount = 0
for i in range(len(points)):
  for j in range(len(points)):
    if i == j:
      continue
    amount += distance(points[i],points[j])
print(amount/n)

Solution (Python):
import math
import itertools

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

z = []
cnt = 0
for v in itertools.permutations(li):
    cnt += 1
    for i in range(n-1):
        z.append(math.sqrt((v[i][0] - v[i+1][0])**2 + (v[i][1] - v[i+1][1])**2))
print(sum(z)/cnt)