Problem:
 Score : 300 points    Problem Statement There are N towns in a coordinate plane. Town i is located at coordinates ( x_i , y_i ). The distance between Town i and Town j is \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2} .  There are N! possible paths to visit all of these towns once. Let the length of a path be the distance covered when we start at the first town in the path, visit the second, third, \dots , towns, and arrive at the last town (assume that we travel in a straight line from a town to another). Compute the average length of these N! paths.      Constraints  2 \leq N \leq 8  -1000 \leq x_i \leq 1000  -1000 \leq y_i \leq 1000  \left(x_i, y_i\right) \neq \left(x_j, y_j\right) (if i \neq j )  (Added 21:12 JST) All values in input are integers.         Input Input is given from Standard Input in the following format:  N  x_1  y_1  :  x_N  y_N       Output Print the average length of the paths.
Your output will be judges as correct when the absolute difference from the judge's output is at most 10^{-6} .        Sample Input 1 3
0 0
1 0
0 1      Sample Output 1 2.2761423749  There are six paths to visit the towns: 1 → 2 → 3 , 1 → 3 → 2 , 2 → 1 → 3 , 2 → 3 → 1 , 3 → 1 → 2 , and 3 → 2 → 1 .  The length of the path 1 → 2 → 3 is \sqrt{\left(0-1\right)^2+\left(0-0\right)^2} + \sqrt{\left(1-0\right)^2+\left(0-1\right)^2} = 1+\sqrt{2} .  By calculating the lengths of the other paths in this way, we see that the average length of all routes is:  \frac{\left(1+\sqrt{2}\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)}{6} = 2.276142...       Sample Input 2 2
-879 981
-866 890      Sample Output 2 91.9238815543  There are two paths to visit the towns: 1 → 2 and 2 → 1 . These paths have the same length.       Sample Input 3 8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310      Sample Output 3 7641.9817824387

Solution (Python):
import math
import itertools

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


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


d = [[0 for _ in range(N)] for _ in range(N)]

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

res = 0
for n in list(itertools.permutations(range(N))):
    for i in range(len(n) - 1):
        res += d[n[i]][n[i + 1]]

print(res / math.factorial(N))

Solution (Python):
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

kkk = []

for i in range(n):
    kkk.append(l())

su = 0


for i in range(n-1):
    for j in range(i+1,n):
        su += math.sqrt((kkk[i][0] - kkk[j][0])**2 + (kkk[i][1] - kkk[j][1])**2)

print(su/(n/2))

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from math import sqrt
from itertools import permutations

n = ni()
xy = [list(li()) for _ in range(n)]

zton = [i for i in range(n)]
lst = permutations(zton)

total = 0
for route in lst:
    dist = 0
    for st, ed in zip(route[:-1], route[1:]):
        dist += sqrt((xy[ed][0] - xy[st][0])**2 + (xy[ed][1] - xy[st][1])**2)
    total += dist

bunbo = 1
for i in range(1,n+1):
    bunbo *= i

print(total / bunbo)

Solution (Python):

import itertools
import math
n = int(input())
xs = []
ys = []
for _ in range(n):
    x, y = map(int, input().split())
    xs += [x]
    ys += [y]
num = 0
den = 0
for p in itertools.permutations(range(n)):
    dist = 0
    for i in range(n - 1):
        x1 = xs[p[i]]
        y1 = ys[p[i]]
        x2 = xs[p[i + 1]]
        y2 = ys[p[i + 1]]
        dist += math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
    num += dist
    den += 1
print('%.12f' % (num / den))

Solution (Python):
import math

N = int(input())
X,Y = [],[]
for i in range(N):
    x,y = input().split()
    x,y = int(x),int(y)
    X.append(x)
    Y.append(y)
    
sum_ = 0
for i in range(N):
    for j in range(N):
        if(i != j):
            sum_ += math.sqrt((X[i]-X[j])**2+(Y[i]-Y[j])**2)

print(sum_/N)

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

def factorial(n):
  if n < 2:
    return 1
  return n * factorial(n - 1)


def distance(a, b):
  dx = a[0] - b[0]
  dy = a[1] - b[1]
  return sqrt(dx * dx + dy * dy)


def calc_len(points, perm):
  res = 0
  for i in range(1, len(perm)):
    a = points[perm[i]]
    b = points[perm[i - 1]]
    res += distance(a, b)
  return res


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

total_len = 0
for perm in permutations(list(range(n))):
  total_len += calc_len(points, perm)
print(total_len / factorial(n))

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

    from itertools import permutations
    from math import factorial
    ans=0
    for perm in permutations(range(n)):
        score=0
        for i in range(n-1):
            tmp=(X[perm[i+1]]-X[perm[i]])**2+(Y[perm[i+1]]-Y[perm[i]])**2
            tmp=tmp**.5
            score+=tmp
        ans+=score
    print(ans/factorial(n))
resolve()

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

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

ans = 0

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

print(ans)

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

roads = []
for i in range(N-1):
    for j in range(i+1,N):
        t1 = town_list[i]
        t2 = town_list[j]
        length = ((t1[0]-t2[0])**2 + (t1[1] - t2[1])**2)** (1/2)
        roads.append(length)

print(sum(roads) / len(roads) * (N-1))

Solution (Python):
import itertools

N = int(input())

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

D = [[0]*N for i in range(N)]

for i in range(N):
    for j in range(N):
        D[i][j]=((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)**0.5

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

total = 0
for it in itertools.permutations(range(N)):
    s = 0
    for i in range(1,N):
        s+=D[it[i-1]][it[i]]
    total+=s

print(total/Nn)

Solution (Python):
from itertools import permutations

def calc_d(pos1, pos2):
  return ((pos1[0]-pos2[0])**2 + (pos1[1]-pos2[1])**2)**.5

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

sumd = 0
cnt = 0
for prm in permutations(XY):
  for i in range(N-1):
    sumd += calc_d(prm[i][:2],prm[i+1][:2])
  cnt += 1
print(sumd/cnt)

Solution (Python):
import itertools
N = int(input())
xy = [tuple(map(int, input().split()))for i in range(N)]
ans = []
for p in itertools.permutations(range(N)):
    dist = 0
    for i, pi in enumerate(p):
        if i == 0:
            pre_x, pre_y = xy[pi]
            continue
        x, y = xy[pi]
        dist += ((pre_x - x)**2 + (pre_y - y) ** 2)**0.5
        pre_x, pre_y = x, y
    ans.append(dist)
print(sum(ans) / len(ans))

Solution (Python):
import numpy as np
N = int(input())
l = list()
for n in range(N):
    l.append([int(x) for x in input().split()])
d = list()
for n in range(N):
    for m in range(n,N):
        d.append(np.sqrt((l[n][0]-l[m][0])**2+(l[n][1]-l[m][1])**2))
print(np.average(d)*(N+1))

Solution (Python):
import itertools
import math


n = int(input())
xs = list()
ys = list()
for i in range(n):
    x, y = map(int, input().split())
    xs.append(x)
    ys.append(y)

costs = list()
indices = itertools.permutations(range(n))
for index in indices:
    cost = 0.0
    for i, j in zip(index[:-1], index[1:]):
        d2 = (xs[j] - xs[i]) ** 2 + (ys[j] - ys[i]) ** 2
        cost += math.sqrt(d2)
    costs.append(cost)

print(sum(costs) / len(costs))

Solution (Python):
from itertools import permutations
from math import factorial
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for d in permutations(list(range(n))):
    tmp = 0
    for i in range(n - 1):
        x, y = l[d[i]]
        a, b = l[d[i + 1]]
        tmp += ((x - a) ** 2 + (y - b) ** 2) ** .5
    ans += tmp
print(ans / factorial(n))

Solution (Python):


import math

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    lp = []
    dist = [[0 for _ in range(n)] for _ in range(n)]
    for i in range(n):
        x, y = rli()
        lp.append([x, y])
    ans = 0
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            dist[i][j] = math.sqrt((lp[i][0]-lp[j][0])**2+(lp[i][1]-lp[j][1])**2)
            ans += dist[i][j]
    ans /= n
    print(ans)



if __name__ == '__main__':
    main()

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

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

ans = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    x1, y1 = xy[i]
    x2, y2 = xy[j]
    ans += (((x1 - x2) ** 2 + (y1 - y2) ** 2) ** (1 / 2)) * (N - 1) * 2 * t

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

ans /= n

print(ans)

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

seq = [i for i in range(N)]
import itertools
tar = list(itertools.permutations(seq))

ans = 0
for t in tar:
    s = 0
    p_x = -1
    p_y = -1
    for i, x in enumerate(t):
        x, y = items[x]
        if i != 0:
            tmp = (abs(p_x - x) ** 2 + abs(p_y - y) ** 2) ** 0.5
            ans += tmp
        p_x = x
        p_y = y
div = 1
for i in range(1, N+1):
    div *= i

print(ans / div)

Solution (Python):
import math
N=int(input())
ls=[[int(s) for s in input().split()] for i in range(N)]
def d(lsa,lsb):
  val=(lsa[0]-lsb[0])**2+(lsa[1]-lsb[1])**2
  return math.sqrt(val)
x=0
for i in range(N-1):
  for j in range(i+1,N):
    x+=d(ls[i],ls[j])
print(x*2/N)

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

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

S=0

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

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

Solution (Python):
from itertools import permutations
n = int(input())
div = 1
s = 0
for i in range(1, n + 1):
	div *= i
L = [list(map(int, input().split())) for _ in range(n)]
for x in permutations(range(n), n):
	s += sum(((L[i][0] - L[j][0]) ** 2 + (L[i][1] - L[j][1]) ** 2) ** .5 for i, j in zip(x, x[1:]))
print(s / div)

Solution (Python):
from itertools import permutations
n=int(input())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
c=0
g=0
for i in permutations(range(n),n):
    t=0
    c+=1
    for j in range(n-1):
        t+=((l[i[j]][0]-l[i[j+1]][0])**2+(l[i[j]][1]-l[i[j+1]][1])**2)**0.5
    g+=t
print(g/(1.0*c))

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

def dist(xi,yi,xj,yj):
    tmp= math.sqrt((xi-xj)**2+(yi-yj)**2)
    return tmp

tw=[]
for i in range(n):
    q,r=map(int,input().split())
    tw.append([q,r])

ans=0

for i in range(0,n-1):
    for j in range(i+1,n):
        f=dist(tw[i][0],tw[i][1],tw[j][0],tw[j][1])
        ans+=f

print(2*ans/n)

Solution (Python):
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
s=0
c=0
for i in range(n):
  for j in range(i+1,n):
    x1,y1=xy[i]
    x2,y2=xy[j]
    s+=((x1-x2)**2+(y1-y2)**2)**.5
    c+=1
print(s*(n-1)/c)

Solution (Python):
N = int(input())
p = list(list(map(int,input().split()))for i in range(N))
ans = 0
for i in range(N):
    for j in range(i+1,N):
        x1,y1 = p[i]
        x2,y2 = p[j]
        ans += ((x1-x2)**2 + (y1 - y2)**2)**0.5
rate = 0
for i in range(N):
    rate += i
rate /= N-1
print(ans/rate)

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

xyxy = []
for i in range(n):
  tmp = []
  for j in range(n):
    tmp.append((((xy[i][0]-xy[j][0])**2)+(xy[i][1]-xy[j][1])**2)**.5)
  xyxy.append(tmp)
ans = 0
for i in range(n):
  for j in range(n):
    if i < j:
      ans += xyxy[i][j]
ans *= 2/n
print(ans)

Solution (Python):
import itertools
N = int(input())
points = []
for _ in range(N):
    x, y = map(int, input().split())
    points.append((x, y))
P = list(itertools.permutations(list(range(N))))
ans = 0
for p in P:
    for i in range(N-1):
        x0, y0 = points[p[i]]
        x1, y1 = points[p[i+1]]
        ans+=((x1-x0)**2+(y1-y0)**2)**(1/2)
print(ans/len(P))

Solution (Python):
from math import hypot
N = int(input())
P = [tuple(int(x) for x in input().split()) for _ in range(N)]
term = 0
for i in range(N):
    for j in range(i + 1, N):
        x0, y0 = P[i]
        x1, y1 = P[j]
        term += hypot(x1 - x0, y1 - y0)
term /= N*(N - 1)//2
print((N - 1)*term)

Solution (Python):
import math
import itertools

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


def dis(t1, t2):
    return math.sqrt((t1[0] - t2[0]) ** 2 + (t1[1] - t2[1]) ** 2)


l = [i for i in range(n)]
res = 0
for sl in itertools.permutations(l):
    for i in range(1, n):
        res += dis(t[sl[i - 1]], t[sl[i]])
for i in range(n):
    res /= i + 1

print(res)

Solution (Python):
n=int(input())
s=0
xy=[tuple(map(int,input().split())) for _ in range(n)]
import itertools
l=[i for i in range(1,n+1)]
for y in itertools.permutations(l):
    for i in range(n-1):
        s+=((xy[y[i]-1][0]-xy[y[i+1]-1][0])**2+(xy[y[i]-1][1]-xy[y[i+1]-1][1])**2)**0.5
e=1
for i in range(1,n+1):
    e*=i
print(s/e)

Solution (Python):
import itertools
import math
N = int(input())
seq = list(range(N))
dic = {}
for i in range(N):
  x, y = map(int, input().split())
  dic[i] = (x,y)
ans = 0
for c in list(itertools.permutations(seq)):
  for j in range(N-1):
    nx, ny = dic[c[j+1]]
    x, y = dic[c[j]]
    ans += ((nx-x)**2 + (ny-y)**2)**0.5
print(ans/(math.factorial(N)))

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

all_root = list(itertools.permutations(xy))

ret = 0
for root in all_root:
    for i in range(len(root)-1):
        x = (root[i][0] - root[i+1][0]) ** 2
        y = (root[i][1] - root[i+1][1]) ** 2
        ret += math.sqrt(x+y)

print(ret/len(all_root))

Solution (Python):
import itertools


import sys
input = sys.stdin.buffer.readline


from collections import defaultdict


def getlist():
	return list(map(int, input().split()))


def main():
	N = int(input())
	L = []
	for i in range(N):
		x, y = getlist()
		L.append([x, y])
	X = [i for i in range(N)]
	Z = list(itertools.permutations(X))
	
	s = 0
	for i in range(len(Z)):
		for j in range(N - 1):
			x1 = L[Z[i][j]][0]
			y1 = L[Z[i][j]][1]
			x2 = L[Z[i][j + 1]][0]
			y2 = L[Z[i][j + 1]][1]
			s += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
	z = 1
	for i in range(N):
		z *= i + 1
	ans = s / z
	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):
from sys import stdin
from math import sqrt, factorial

def input():
    return stdin.readline()[:-1]


def intput():
    return int(input())


def sinput():
    return input().split()


def intsput():
    return map(int, sinput())



def distance(a, b):
    dx = a[0] - b[0]
    dy = a[1] - b[1]
    return sqrt(dx ** 2 + dy ** 2)

n = intput()

towns = []
dists = []

for _ in range(n):
    towns.append(list(intsput()))

for i in range(n):
    for j in range(i + 1, n):
        dists.append(distance(towns[i], towns[j]))

s = sum(dists)

print(s * 2 / n)

Solution (Python):
from itertools import permutations

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

d=[]
for i in permutations(l):
    t_d=0
    for j in range(len(i)-1):
        t_d+=((i[j][0]-i[j+1][0])**2+(i[j][1]-i[j+1][1])**2)**0.5
    d.append(t_d)
print(sum(d)/len(d))

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

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

all_sum = 0
for a in perm(XY):
    sum_num = 0
    for j in range(N-1):
        x1, y1 = a[j]
        x2, y2 = a[j+1]
        r = (abs(x1-x2)**2 + abs(y1-y2)**2)**(1/2)
        sum_num += r
    all_sum += sum_num

print(all_sum / factorial(N))

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


def dist(x1, y1, x2, y2):
    return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)


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

sm = 0
cnt = 0
for pat in permutations(xy, n):
    l = 0
    cnt += 1
    for e1, e2 in zip(pat, pat[1:]):
        x1, y1 = e1
        x2, y2 = e2
        l += dist(x1, y1, x2, y2)
    sm += l

ans = sm / cnt
print(ans)

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

Solution (Python):

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

dis = [[0]*n for _ in range(n)] 
ans = 0

for i in range(n):
    for j in range(n):
        tmp = (x[i] - x[j])**2 + (y[i] - y[j])**2
        tmp = tmp**(1/2)
        dis[i][j] = tmp
        if i != j :
            ans += tmp




print(ans/n)

Solution (Python):
import math

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

kyori=0
for i in range(n):
    for j in range(n):
        kyori+=math.sqrt((xylist[i][0]-xylist[j][0])**2+(xylist[i][1]-xylist[j][1])**2)

print(kyori/n)

Solution (Python):
import math

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

main()

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

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

ans = 0
for ptn in permutations(range(N)):
    dist = 0
    for i in range(N-1):
        j1, j2 = ptn[i], ptn[i+1]
        dist += hypot(xs[j1]-xs[j2], ys[j1]-ys[j2])
    ans += dist

print(ans / factorial(N))

Solution (Python):
import itertools

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

P = list(itertools.permutations(range(N)))
l = 0
for p in P:
  for i in range(N-1):
    x0,y0 = XY[p[i]]
    x1,y1 = XY[p[i+1]]
    l += ((x1-x0)**2+(y1-y0)**2)**0.5
print(l/len(P))

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 permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

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

ans = 0
for n in permutations(range(N)):
	tmp = 0
	for i in range(N-1):
		tmp += dist(xy[n[i]], xy[n[i+1]])
	ans += tmp
print(ans/factorial(N))

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

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


N = int(input())
xy = []
for _ in range(N):
    x, y = map(int, input().split())
    xy.append((x, y))
adj = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
    for j in range(N):
        adj[i][j] = dist(xy[i][0], xy[i][1], xy[j][0], xy[j][1])

ans = 0
for v_list in permutations(list(range(N))):
    for i in range(N-1):
        ans += adj[v_list[i]][v_list[i+1]]

print(ans / factorial(N))

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

import itertools

cnt = 0
ans = 0
for P in itertools.permutations(list(range(N))):
    cnt += 1
    tmp = 0
    for i in range(N-1):
        tmp += ((xy[P[i]][0]-xy[P[i+1]][0])**2+(xy[P[i]][1]-xy[P[i+1]][1])**2)**0.5
    ans += tmp
ans /= cnt
print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(10 ** 9)



INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
X = []
Y = []
for x, y in LIR(n):
    X += [x]
    Y += [y]


ret = 0
for pat in list(permutations((range(n)))):
    for i in range(len(pat) - 1):
        ret += ((X[pat[i]] - X[pat[i + 1]]) ** 2 + (Y[pat[i]] - Y[pat[i + 1]]) ** 2) ** 0.5

print(ret / factorial(n))

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

for v in itertools.permutations(l, N):
    totali = 0
    for i in range(len(v)-1):
        totali += ((x[v[i]] - x[v[i+1]])**2 + (y[v[i]] - y[v[i+1]])**2)**0.5

    total += totali

for i in range(1, N+1):
    total /= i

print(total)

Solution (Python):
N=int(input())
x=[];y=[]
for i in range(N):
    xi,yi=map(int,input().split())
    x.append(xi);y.append(yi)
ans=0
for i in range(N):
    for j in range(N):
        ans+=((x[j]-x[i])**2+(y[j]-y[i])**2)**0.5/N
print(ans)

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

Solution (Python):
from itertools import permutations
import math

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

a = range(n)
ans = 0
b = list(permutations(a, n))
for i in range(len(b)):
    for j in range(1, n):
        ans += math.sqrt((xy[b[i][j]][0] - xy[b[i][j - 1]][0])**2 + (xy[b[i][j]][1] - xy[b[i][j - 1]][1])**2)
ans /= len(b)
print(ans)

Solution (Python):
def fct(i):
    if i==0:
        return 1
    return i*fct(i-1)

from itertools import permutations

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

perms = list(permutations([i for i in range(n)]))


num = 0

def dist(ax, ay, bx, by):
    return ((ax-bx)**2 + (ay-by)**2)**0.5

def solve(curperm):
    distance = 0
    for coord in range(1, len(curperm)):
        distance += dist(x[curperm[coord-1]], y[curperm[coord-1]], x[curperm[coord]], y[curperm[coord]])
    
    return distance

for curperm in perms:
    
    num += solve(curperm)
print(num/fct(n))

Solution (Python):
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7




def main():
    
    
    
    
    
    
    
    
    
    
    
    
    n = int(input())
    xy = [list(map(int, input().split())) for i in range(n)]
    
    L = []
    for l in itertools.permutations(xy):
        t = 0
        for i in range(n - 1):
            t += ((l[i][0] - l[i + 1][0])** 2 + (l[i][1] - l[i + 1][1])** 2)**(1 / 2)
        L.append(t)
    
    k = 1
    for i in range(1,n+1):
        k*=i

    print(sum(L)/k)
    


        




            
            
            
            
            
        


if __name__ == '__main__':
    main()

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


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


ans = 0
for perm in permutations(range(N)):
    for i in range(N - 1):
        x1, y1 = Points[perm[i]]
        x2, y2 = Points[perm[i + 1]]
        ans += dist(x1, y1, x2, y2)

print(ans / factorial(N))

Solution (Python):
import math
import itertools
N = int(input())
xys = []
for i in range(N):
  x, y = map(int, input().split())
  xys.append((x, y))
ls = []
for Is in itertools.permutations(range(N)):
  l = 0
  for i in range(1, N):
    a, b = xys[Is[i-1]]
    x, y = xys[Is[i]]
    l += math.sqrt((x-a)**2+(y-b)**2)
  ls.append(l)
r = sum(ls)/len(ls)
print(r)

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):
from itertools import permutations

N = int(input())

def length(x, y, u, v):
    return ((x - u)**2 + (y - v)**2)**0.5

XY = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0

for x, y in XY:
    for u, v in XY:
        ans += length(x, y, u, v)

print(ans / N)

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

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



N = I()
x,y = Line(N,2)

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

print(2*ans/N)

Solution (Python):

import sys
import math
input = sys.stdin.readline

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

dist_sum = 0
for i in range(n):
    for j in range(i+1, n):
        x1, y1 = town[i]
        x2, y2 = town[j]
        dist_sum += math.hypot(x1 - x2, y1 - y2) / n
print(dist_sum * 2.0)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
xy = [LI() for _ in range(n)]
ans = 0
for i in permutations(range(n),n):
    i = list(i)
    tx,ty = xy[i[0]]
    for j in i[1:]:
        sx,sy = xy[j]
        ans += ((tx-sx)**2 + (ty-sy)**2)**(0.5)
        tx,ty = sx,sy
ans = ans/math.factorial(n)
print(ans)

Solution (Python):
import itertools


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


def solve(i, j):
    x, y = info[i]
    xx, yy = info[j]
    return ((x-xx)**2 + (y-yy)**2)**0.5
  
seq = [i for i in range(n)]
m = len(list(itertools.permutations(seq)))
ans = 0
for ptn in list(itertools.permutations(seq)):
    for i in range(n-1):
        ans += solve(ptn[i], ptn[i+1])

print(ans / m)

Solution (Python):

from itertools import permutations
import math

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

A = list(range(n))
ans = 0

for p in permutations(A):
    x, y = P[p[0]]
    for i in range(1, n):
        a, b = P[p[i]]
        ans += math.sqrt((x - a) * (x - a) + (y - b) * (y - b))
        x, y = a, b

p = 1
for i in range(2, n+1):
    p *= i

print(ans/p)

Solution (Python):
from itertools import permutations

def main():
    n = input()
    pos = []
    for _ in xrange(n):
        x, y = map(float, raw_input().split())
        pos.append([x, y])
    c = 0
    s = 0.0
    for pp in permutations(pos):
        c += 1
        for i in xrange(n - 1):
            x0, y0 = pp[i]
            x1, y1 = pp[i + 1]
            s += ((x0 - x1) ** 2 + (y0 - y1) ** 2) ** 0.5
    print s / c


main()

Solution (Python):

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

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


s = 0
for i in range(N):

    for j in range(i):

        s += ((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2 ) ** 0.5

print (s / (N * (N-1) * 0.5) * (N-1))