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
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    XY=LLIN(N)
    ans = 0
    cnt = 0
    for it in permutations(XY):
        res = 0
        for i,(x,y) in enumerate(it[:-1]):
            res += sqrt((x-it[i+1][0])**2 + (y-it[i+1][1])**2 )
        ans += res
        cnt+=1
    print(ans/cnt)
if __name__ == '__main__':
    main()

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



N = int(sys.stdin.readline())
X, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N)]))

X = np.array(X, dtype=float)
Y = np.array(Y, dtype=float)

xa, xb = np.meshgrid(X, X)
ya, yb = np.meshgrid(Y, Y)
d = np.sqrt((xa - xb) ** 2 + (ya - yb) ** 2)
print(d.sum() / N)

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


def main():
    N = int(input())
    P = [list(map(int, input().split())) for _ in range(N)]
    ans = 0
    for p in permutations(range(N), N):
        for i in range(N-1):
            x1, y1 = P[p[i]]
            x2, y2 = P[p[i+1]]
            ans += sqrt((x1-x2)**2 + (y1-y2)**2)
    ans /= factorial(N)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from math import sqrt
n = int(input())


def kai(x):
    a = 1
    for i in range(1, x + 1):
        a *= i
    return a


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


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

k = 0
for i in range(n):
    for j in range(i + 1, n):
        k += d(xy[i], xy[j])
print(k/n*2)

Solution (Python):
import math

n = int(input())
cnt = 0
x = []
y = []
for _ in range(n):
    x1, y1 = map(int, input().split())
    x.append(x1)
    y.append(y1)
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        cnt += math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
print(cnt/n)

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time

def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
ts=time.time()
sys.setrecursionlimit(10**6)

show_flg=False
show_flg=True

ans=0
n=I()
a=[]
f=1
tmp=0
for i in range(n):
    f*=(1+i)
    x,y=LI()
    a.append((x,y))
for k in permutations(range(n)):
    for i in range(n-1):
        p,q=k[i],k[i+1]
        x,y=a[p]
        s,t=a[q]
        tmp+=((x-s)**2+(y-t)**2)**0.5

ans=tmp/f
print(ans)

Solution (Python):
from itertools import permutations

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

N = int(input())
coord = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0
fact = 0
for tup in permutations(coord):
    fact += 1
    for t1, t2 in zip(tup, tup[1:]):
        ans += dist(t1, t2)
print(ans / fact)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
def solve():
  n = int(input())
  query = []
  for i in range(n):
    x,y = (int(i) for i in input().split())
    query.append((x,y))
  p = itertools.permutations(query)
  su = 0
  ct = 0
  for i in p:
    ct += 1
    nowx = -1
    nowy = -1
    for nx,ny in i:
      if nowx == -1:
        nowx = nx
        nowy = ny
        continue
      else:
        su += (abs(nx-nowx)**2+abs(ny-nowy)**2)**0.5
      
      
      nowx = nx
      nowy = ny
  print(su/ct)
solve()

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

n = int(input())

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

ans = 0
for i in range(n):
    for j in range(n):
        ans += ((X[i][0]-X[j][0]) ** 2 + (X[i][1]-X[j][1]) ** 2) ** 0.5

print(ans /n)

Solution (Python):
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
d=lambda x1,y1,x2,y2:((x1-x2)**2+(y1-y2)**2)**0.5
from itertools import permutations
x=0
f=1
for i in range(n):f*=i+1
for i in permutations(a):
  for j in range(n-1):
    x+=d(i[j][0],i[j][1],i[j+1][0],i[j+1][1])
print(x/f)

Solution (Python):
import itertools
import math
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n = ri()
ls = rils(n)
ds = [
    math.sqrt((x0 - x1)**2 + (y0 - y1)**2)
    for (x0, y0), (x1, y1) in itertools.combinations(ls, 2)
]
print((n - 1) * sum(ds) / len(ds))

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

s = 0
c = 0
for x in itertools.permutations(X):
    for i in range(N-1):
        s += ((x[i][0] - x[i+1][0]) ** 2 + (x[i][1] - x[i+1][1]) ** 2) ** 0.5
    c += 1

print(s / c)

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

import itertools
totalDist = 0
totalSum = 0
for perm in itertools.permutations(list(range(N))):
    curLength = 0
    for i in range(1, N):
        curLength += ((points[perm[i]][0] - points[perm[i - 1]][0]) ** 2 + (points[perm[i]][1] - points[perm[i - 1]][1]) ** 2) ** 0.5
    totalDist += curLength
    totalSum += 1
print(totalDist/totalSum)

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):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

from itertools import permutations

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def f(n):
        if n == 1:
            return 1
        return n*f(n-1)
    n = I()
    p = LIR(n)
    ans = 0
    for k in permutations([i for i in range(n)],n):
        for i in range(n-1):
            ans += ((p[k[i]][0]-p[k[i+1]][0])**2+(p[k[i]][1]-p[k[i+1]][1])**2)**0.5
    print(ans/f(n))
    return


if __name__ == "__main__":
    solve()

Solution (Python):
import sys

stdin = sys.stdin

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

n = ni()
xy = []
import math
for i in range(n):
    xy.append(na())

d = 0
for i in range(n):
    for j in range(i+1, n):
        d += math.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("{:.14f}".format(d/n*2))

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

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

ans = 0
for ps in permutations(p,n):
    x1, y1 = ps[0]
    for i in range(n):
        x2,y2 = ps[i]
        ans += hypot(x1-x2, y1-y2)
        x1,y1 = x2,y2
ans /= factorial(n)
print(ans)

Solution (Python):
from itertools import permutations as perm

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

sm = 0
cnt = 0

permm = list(range(n))
for p in perm(permm):
    for i, j in zip(p, p[1:]):
        x1, y1 = l[i]
        x2, y2 = l[j]
        sm += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
    cnt += 1

print(sm / cnt)