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):
from math import sqrt
n = int(input())
p = []
for _ in range(n):
    x, y = map(int, input().split())
    p.append([x, y])

cnt = 0
total = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        cnt += 1
        xi, yi = p[i]
        xj, yj = p[j]
        total += sqrt((xi - xj) ** 2 + (yi - yj) ** 2)

ans = total / cnt * (n - 1)
print(ans)

Solution (Python):



import sys
from itertools import permutations
input = sys.stdin.readline
N = int(input())

A = [tuple(map(int, input().split())) for _ in [0]*N]

suml = 0
cnt = 0
for i in permutations(range(N)):
    length = 0
    x0, y0 = A[i[0]]
    for j in i[1:]:
        x1, y1 = A[j]
        length += ((x1-x0)**2+(y1-y0)**2)**0.5
        x0, y0 = x1, y1
    suml += length
    cnt += 1

print(suml/cnt)

Solution (Python):
import itertools
n = int(input())
point = []
a = [i for i in range(n)]
for i in range(n):
    x,y = map(int,input().split())
    point.append((x,y))
a = list(itertools.permutations(a,n))
length = 0
for i in range(len(a)):
    for j in range(n-1):
        cnt = (point[a[i][j]][0] - point[a[i][j+1]][0])**2\
        + (point[a[i][j]][1] - point[a[i][j+1]][1])**2
        cnt = cnt**0.5
        length += cnt
print(length / len(a))

Solution (Python):
import math
import itertools

n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]
rng = [i for i in range(n)]
ans = 0
for l in itertools.permutations(rng):
    t = 0
    for e, k in enumerate(l):
        if e==0:
            x,y = xy[k][0], xy[k][1]
        nx, ny = xy[k][0], xy[k][1]
        t += ((nx-x)**2 + (ny-y)**2)**0.5
        x,y = nx, ny
    ans += t
print(ans/math.factorial(n))

Solution (Python):
import itertools
n = int(input())
XY = []
for i in range(n):
    x, y = map(int, input().split())
    XY.append((x, y))
d = 0
for P in itertools.permutations(XY):
    for i in range(1, n):
        x0, y0 = P[i-1]
        x1, y1 = P[i]
        d += ((x0-x1)**2+(y0-y1)**2)**0.5
k = 1
for i in range(1, n+1):
    k *= i
print(d/k)

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

ans = 0
for x in permutations(range(N)):
    for i in range(N-1):
        ans += ((xy[x[i+1]][0] - xy[x[i]][0])**2 +
                (xy[x[i+1]][1] - xy[x[i]][1])**2) ** (1/2)

print(ans / math.factorial(N))

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

from itertools import permutations
from math import sqrt

states = list(permutations(list(range(N))))

ans = 0
for state in states:
    dist = 0
    for i,n in enumerate(state):
        if i == 0:
            prev = xy[n]
            continue
        now = xy[n]
        dist += sqrt((prev[0]-now[0]) ** 2+ (prev[1]-now[1]) ** 2)
        prev = now
    ans += dist

ans /= len(states)
print(ans)

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


import itertools
ans = 0
for xyl2 in itertools.permutations(xyl):
    x0 = xyl2[0][0]
    y0 = xyl2[0][1]
    tmp = 0
    for x, y in xyl2:
        tmp += ((x-x0) ** 2 + (y-y0) ** 2) ** (1/2)
        x0 = x
        y0 = y
    ans += tmp

print(ans / len(list(itertools.permutations(xyl))))

Solution (Python):
def main():
    N = int(input())
    from math import hypot
    XY = [[int(i) for i in input().split()] for j in range(N)]
    from itertools import permutations
    ans = 0
    for p in permutations(range(N)):
        cur = 0
        pre = p[0]
        for i in p[1:]:
            cur += hypot(XY[pre][0] - XY[i][0], XY[pre][1] - XY[i][1])
        ans += cur
    acc = 1
    for i in range(2, N+1):
        acc *= i
    print(ans/acc)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
xy = [inpl() for _ in range(n)]
res = 0
for f in itertools.permutations(range(n)):
    for i in range(n-1):
        a,b = xy[f[i]], xy[f[i+1]]
        dist = (a[0]-b[0])**2 + (a[1]-b[1]) ** 2
        res += math.sqrt(dist)
print(res/math.factorial(n))

Solution (Python):
import math
N = int(input())
ls1 = []
ls2 = []
for i in range(N):
    ls1.append(list(map(int,input().split())))
x = 0
y = 0
for i in range(N):
    for j in range(i+1,N):
        x = (ls1[i][0]-ls1[j][0])**2
        y = (ls1[i][1]-ls1[j][1])**2
        XY = math.sqrt(x+y)
        ls2.append(XY)
if len(ls2) == 1:
    print(ls2[0])
else:
    ans = sum(ls2)*2/N
    print(ans)

Solution (Python):
from itertools import permutations
from math import factorial
def d(a, b):
  x1, y1 = a
  x2, y2 = b
  return ((x1-x2)**2 + (y1-y2)**2)**0.5

cnt = 0
n = int(input())
XY = [list(map(int, input().split())) for _ in range(n)]
for l in permutations(XY):
  for i in range(n-1):
    cnt += d(l[i], l[i+1])
cnt /= factorial(n)
print(cnt)

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


def main():
    n = int(input())
    xy = []
    for _ in range(n):
        xy.append(list(map(int, input().split())))
    town = [i for i in range(n)]
    dist_sum = 0
    for p in permutations(town):
        for i in range(n - 1):
            dist_sum += sqrt((xy[p[i]][0] - xy[p[i + 1]][0]) ** 2 + (xy[p[i]][1] - xy[p[i + 1]][1]) ** 2)
    print(dist_sum / factorial(n))


if __name__ == '__main__':
    main()

Solution (Python):
import math
import itertools
N = int(input())
p = [tuple(map(int, input().split())) for _ in range(N)]
num = [int(i) for i in range(N)]
d_sum = 0
for per in itertools.permutations(num):
    
    for i in range(len(per) - 1):
        d_sum += math.sqrt((p[per[i]][0] - p[per[i+1]][0])**2 + (p[per[i]][1] - p[per[i+1]][1])**2)
        
ans = d_sum / math.factorial(N)

print(ans)

Solution (Python):
import numpy as np
import math
import itertools
n = int(input())
xy = []
for _ in range(n):
  xy.append(list(map(int, input().split())))
xy = np.array(xy)
dist = []



su = 0
for i in range(n-1):
  d = np.array(list(map(math.sqrt, ((xy[i+1:] - xy[i])**2).sum(axis=1))))
  mu = math.factorial(n-1)*2
  su += (d*mu).sum()
print(su/math.factorial(n))

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

from itertools import permutations
import math
distance = []
for route in list(permutations(range(1,n+1))):
  route = list(route)

  dis = 0
  for i in range(0,n-1):
    d = math.sqrt(pow(location[route[i]-1][0]-location[route[i+1]-1][0],2) + pow(location[route[i]-1][1]-location[route[i+1]-1][1],2))
    dis = dis + d
  distance.append(dis)
  
ans = sum(distance)/len(list(permutations(range(1,n+1))))
print(ans)

Solution (Python):
import itertools
import math

N = int(input())

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

l = [i for i in range(N)]

s = 0
for x in itertools.permutations(l):
    for i in range(N-1):
        s += math.sqrt( (L[x[i]][0]-L[x[i+1]][0])**2 + (L[x[i]][1]-L[x[i+1]][1])**2 )

print(s/math.factorial(N))

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

Solution (Python):




import itertools

def fact(n,mod):
    ret=1
    for i in range(2,n+1):
        ret=(ret*i)%mod
    return ret

N=int(input())
X=[tuple(map(int,input().split())) for _ in range(N)]
ans=0
for p in itertools.permutations(X):
    
    sx,sy=p[0]
    for x,y in p:
        ans+=((sx-x)**2+(sy-y)**2)**0.5
        sx,sy=x,y
    
ans/=fact(N,10**9+7)
print(ans)

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

town = [i for i in range(n)]
route = list(itertools.permutations(town,n))
dis = 0
for i in route:
    for j in range(n-1):
        dis += math.sqrt((xy[i[j]][0] - xy[i[j+1]][0])**2 + (xy[i[j]][1] - xy[i[j+1]][1])**2)

print(dis/len(route))

Solution (Python):
n=int(input())
A=[[0,0] for i in range(n)]
for i in range(n):
    A[i][0],A[i][1]=map(int,input().split())
B=0
def dis(a,b,c,d):
    return ((a-c)**2+(b-d)**2)**(1/2)
for i in range(n-1):
    for j in range(i,n-1):
        B=B+dis(A[i][0],A[i][1],A[j+1][0],A[j+1][1])
print(B*2/n)

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

s = 0
c = 0
for i in range(n):
    for k in range(i + 1, n):
        s += ((xs[i] - xs[k]) ** 2 + (ys[i] - ys[k]) ** 2) ** 0.5
a = s / n * 2
print(a)

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

Solution (Python):
N = int(input())
L = []
for i in range(N):
    x,y = map(int, input().split())
    L.append([x,y])
def distance(List):
    s = 0
    for i in range(N-1):
        s += ( (List[i][0]-List[i+1][0])**2+(List[i][1]-List[i+1][1])**2 )**0.5
    return s
import itertools
import math
n = math.factorial(N)
A = list(itertools.permutations(L))
d = 0
for i in range(n):
    d += distance(A[i])
print(d/n)

Solution (Python):
import itertools
import math

n = int(input())
A = [[0,0] for _ in range(n)]
for i in range(n):
    A[i] = [int(s) for s in input().split()]


B = [s for s in range(n)]
al_list = list(itertools.permutations(B))


mx = math.factorial(n)

sm = 0
for j in range(mx):
    res = 0
    for k in range(n-1):
       st = al_list[j][k] 
       en = al_list[j][k+1]
       x_1,y_1 = A[st]
       x_2,y_2 = A[en]
       dist = math.sqrt((x_1-x_2)**2 + (y_1-y_2)**2)
       res += dist
    
    sm += res

print(sm/mx)

Solution (Python):
import itertools
import math

def dist(p1, p2):
    x1, y1 = p1
    x2, y2 = p2
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
n = int(input())
p = [tuple(map(int, input().split())) for _ in range(n)]
num = [i for i in range(n)]
avr = 0
for i, j in itertools.combinations(num, 2):
    avr += dist(p[i], p[j])
print(avr * 2 / n)

Solution (Python):
import math

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

distance=0
for i in range(n):
  for j in range(i+1,n):
    distance+=math.sqrt((codes[i][0]-codes[j][0])**2+(codes[i][1]-codes[j][1])**2)
print(distance*2/n)

Solution (Python):
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
import time
from bisect import bisect_left, insort_left, bisect_right
import sys
import random
from itertools import permutations

input = sys.stdin.readline
_NUMINT_ALL = list(range(10))
_START_TIME = time.time()


def main():
    ans = solve()

    if ans is True or ans is False:
        YesNo(ans)
    elif ans is not None:
        print(ans)


def solve():
    N = iip()[0]
    XY = iipt(N)
    n = 0
    s = 0

    for p in permutations(range(N)):
        cur_x = XY[p[0]][0]
        cur_y = XY[p[0]][1]


        for i in p[1:]:
            x = XY[i][0]
            y = XY[i][1]
            s += ((cur_x-x)**2+(cur_y-y)**2) ** 0.5
            cur_x = x
            cur_y = y
        n += 1

    print(s/n)








def kiriage_warizan(a, b):
    return -(-a//b)


def iip(listed=True):  
    d = input().rstrip("\n").split()
    try:
        ret = [int(i) for i in d]
    except:
        ret = [int(i) if i in _NUMINT_ALL else i for i in d]
        if len(ret) == 1 and listed is False:
            return ret[0]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iipt(l, listed=True, num_only=True):  
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed))
    return ret


def saidai_kouyakusuu(A):  
    l = len(A)
    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m

def time_debug_10percent():
    a = random.randint(0, 9)
    if a == 9:
        sys.exit()

def time_debug(t):
    time.sleep(_START_TIME + t - time.time())
    sys.exit()


def make_graph_edge_flat(N):  
    ret = []
    for i in range(N-1):
        a, b, c = iip()
        a -= 1
        b -= 1
        ret[a].append((b, c))
        ret[b].append((a, c))
    return ret


def sort_tuples(l, index):  
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  
    if index >= len(l):                      
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def sortstr(s):  
    return "".join(sorted(s))


def iip_ord(startcode="a"):  
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  
    for i in s:
        print(i)


def bitall(N):  
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        
        pass
    return ret


def inv(n, mod):  
    return power(n, mod - 2)


def power(n, p, mod_=mod):  
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


def nibutan_func(func, target, left, right, side="left"): 
    l = left
    r = right
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if func(x) == target:
            return x
        elif func(x) > target:
            r = x
        else:
            l = x

    if side == "left" or func(x) == target:
        return l
    else:
        return r


def nibutan_list(list_, target, side="left"):  
    if not isinstance(list_, list):
        list_ = list(list_)

    l = 0
    r = len(list_)
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if list_[x] == target:
            return x
        elif list_[x] > target:
            r = x
        else:
            l = x

    if side == "left" or list_[x] == target:
        return l
    else:
        return r


class UfTree():
    def __init__(self, maxnum):
        self.parent = list(range(maxnum))
        self._size = [1] * maxnum
        self.rank = [0] * maxnum

    def size(self, a):
        return self._size[self.root(a)]

    def root(self, a):
        rank = 0
        cur = a
        while True:
            if self.parent[cur] == cur:
                
                
                return cur
            else:
                self.parent[cur] = self.parent[self.parent[cur]]
                cur = self.parent[cur]
                rank += 1

    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return self

        self._size[ra] += self._size[rb]
        self.parent[rb] = ra
        return self

if __name__ == "__main__":
    main()

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




ans = 0

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

print(ans)

Solution (Python):
import math
import itertools
from scipy.spatial import distance

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

d = 0
for i in itertools.permutations(l):
    for j in range(n-1):
        if j+1 < n:
            d += math.sqrt((i[j][0] - i[j+1][0]) ** 2 + (i[j][1] - i[j+1][1]) ** 2)

print(d/math.factorial(n))

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

Solution (Python):
import itertools
import math

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

ans = 0
ps = itertools.permutations(range(n))
c = 0
for ls in ps:
    c += 1
    head, tail = ls[0], ls[1:]
    for i in tail:
        x0, y0 = xy[head]
        x, y = xy[i]
        ans += math.sqrt((x - x0) ** 2 + (y - y0) ** 2)
print(ans / c)

Solution (Python):
import math
N = int(input())
l = []
for i in range(N):
  l.append(list(map(int,input().split())))
c = 0
for i in range(N):
  for j in range(i+1,N):
    c +=((l[i][0]-l[j][0])**2 + (l[i][1]-l[j][1])**2)**(1/2)
print(2*c/N)

Solution (Python):
import math
from collections import defaultdict
import itertools
N = int(input())
town = [[int(i) for i in input().split(' ')] for _ in range(N)]

dist = 0
c = 0
for v in itertools.permutations(town,len(town)):
    c += 1
    sx = v[0][0]
    sy = v[0][1]
    for i in v[1::]:
        dist += math.sqrt((sx - i[0]) ** 2 + (sy - i[1]) ** 2)
        sx, sy = i[0], i[1]

print(dist/c)

Solution (Python):
n=int(input())
A=[]
B=[]
sum=0
for i in range(n):
    a,b=map(int,input().split())
    A+=[a]
    B+=[b]
for i in range(n):
    for j in range(n):
        if i<j:
            sum+=((A[i]-A[j])**2+(B[i]-B[j])**2)**(1/2)
print(2*sum/n)

Solution (Python):
import math
from collections import defaultdict
import itertools
N = int(input())
town = [[int(i) for i in input().split(' ')] for _ in range(N)]

dist = 0
c = 0
for v in itertools.permutations(town,len(town)):
    c += 1
    sx = v[0][0]
    sy = v[0][1]
    for i in v[1::]:
        dist += math.sqrt((sx - i[0]) ** 2 + (sy - i[1]) ** 2)
        sx, sy = i[0], i[1]

print(dist/c)

Solution (Python):
import math
N = int(input())
XY = [0]*N
for i in range(N):
    XY[i] = list(map(int,input().split()))
sum = 0


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

ans = sum * 2 / N
print(ans)

Solution (Python):
import math

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

distance=0
for i in  range(n):
  for j in range(i+1,n):
    distance +=math.sqrt((codes[i][0]-codes[j][0])**2+(codes[i][1]-codes[j][1])**2)
print(distance*2/n)

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

Solution (Python):
import math

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

d_sum = 0
cnt = 0
for i in range(n):
    for j in range(n):
        if i != j:
            d_sum += math.sqrt((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2)
            cnt += 1

print(d_sum*(n-1)/cnt)

Solution (Python):
import itertools
import math

N = int(input())
pointXY = []
for _ in range(N):
    x, y = map(int, input().split())
    pointXY.append((x, y))
ans = 0
for xy in itertools.permutations(pointXY):
    tmpx = xy[0][0]; tmpy = xy[0][1]
    for (x, y) in xy[1:]:
        ans += math.sqrt((tmpx-x)**2 + (tmpy-y)**2)
        tmpx = x; tmpy = y
print(ans/math.factorial(N))

Solution (Python):
import math
N = int(input())
List = [list(map(int,input().split(" "))) for i in range(N)]

def fa(n):
  num = 1
  for i in range(1, n+1):
    num = num * i
  return num

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

Solution (Python):
from itertools import permutations
n = int(input())
xy = []
for i in range(n):
  x, y = map(int, input().split())
  xy.append((x, y))
np = len(list(permutations(range(n))))
dd = 0
for perm in permutations(range(n)):
  for i in range(n-1):
    dd += ((xy[perm[i-1]][0] - xy[perm[i]][0]) ** 2 + (xy[perm[i-1]][1] - xy[perm[i]][1]) ** 2) ** 0.5
print(dd/np)

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

N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
distance = {}
for i in range(N):
    for j in range(N):
        if i!=j:
            distance[str(i)+str(j)] = sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)
ans = 0

for S in list(permutations([i for i in range(N)], N)):
    for i in range(N-1):
        key = str(S[i]) + str(S[i+1])
        ans += distance[key]
print(ans/factorial(N))

Solution (Python):
import math
from itertools import permutations

def solve():
    n = int(input())
    cord = [list(map(int, input().split())) for _ in range(n)]
    
    
    
    
    
    
    
    
    sm = 0
    for cnt, i in enumerate(permutations(range(n))):
        
        for j in range(1, n):
            
            
            s = i[j-1]
            t = i[j]
            d = math.sqrt(pow(cord[s][0] - cord[t][0], 2) + pow(cord[s][1] - cord[t][1], 2))
            
            sm = sm + d
    print(sm / (cnt+1))


if __name__ == '__main__':
    solve()

Solution (Python):
import math
from itertools import permutations

def solve():
    n = int(input())
    cord = [list(map(int, input().split())) for _ in range(n)]
    
    dist = {}
    for i in range(n):
        for j in range(n):
            if i == j: continue
            d = math.sqrt(pow(cord[i][0] - cord[j][0], 2) + pow(cord[i][1] - cord[j][1], 2))
            dist[(i, j)] = d
    
    sm = 0
    for cnt, i in enumerate(permutations(range(n))):
        
        for j in range(1, n):
            
            d = dist[(i[j-1], i[j])]
            
            sm = sm + d
    print(sm / (cnt+1))


if __name__ == '__main__':
    solve()

Solution (Python):
import itertools

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



l = list(range(n))
cl = []
for i in itertools.permutations(l):
  cl.append(i)

total = 0
N = len(cl)
for i in range(N):
  for j in range(1,n):
    now = cl[i][j]
    past = cl[i][j-1]
    total += ((xy[now][0] - xy[past][0])**2+(xy[now][1] - xy[past][1])**2)**0.5
print(total/N)

Solution (Python):



from itertools import permutations

N, *A = map(int, open(0).read().split())
X = A[0::2]
Y = A[1::2]

def distance(a, b):
    return ((X[a]-X[b])**2 + (Y[a]-Y[b])**2)**0.5


length = 0
cnt = 0
for P in permutations(range(N)):
    cnt += 1
    prev = P[0]
    for i in P[1:]:
        length += distance(prev, i)
        prev = i

print(length/cnt)

Solution (Python):
import itertools
import math

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

def factorial(a):
  if (a == 1):
    return 1
  return a * factorial(a-1)

f = factorial(s)

length = 0
p = itertools.permutations(m, r=None)
for c in p:
  l = list(c)
  for k in range(len(l) - 1):
    length += math.sqrt((l[k+1][0] - l[k][0] ) ** 2 + (l[k+1][1] - l[k][1]) ** 2)

print(length / f)

Solution (Python):
import itertools
import math
N=int(input())
lis=[]
for i in range(N):
	[x,y]=[int(j)+1000 for j in input().split()]
	lis+=[x+y*10000]
A=list(itertools.permutations(lis))
add=0
cnt=0
for i in range(len(A)):
	for j in range(len(A[i])-1):
		add+=(((A[i][j]//10000)-(A[i][j+1]//10000))**2+((A[i][j]%10000)-(A[i][j+1]%10000))**2)**0.5
		cnt+=1
print(add/math.factorial(N))

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

from itertools import permutations, combinations,combinations_with_replacement,product

arr = list(permutations(P))

ans = 0

for p in arr:
    l = 0
    for (x1, y1), (x2, y2) in zip (p, p[1:]):
        l += ((x1-x2)**2 + (y1-y2)**2)**0.5
    ans += l

print(ans/len(arr))

Solution (Python):
import math

n = int(input())

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

s = 0
for i in range(n):
    x1, y1 = p[i]
    for j in range(n):
        x2, y2 = p[j]

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

print(s/n)

Solution (Python):
import itertools
N=int(input())
XY=[]
for _ in range(N):
    tmp=list(map(int,input().split()))
    XY.append(tmp)
l=[i for i in range(N)]
permutation = itertools.permutations(l, 2)
total=0
for p in permutation:
    i=p[0]
    j=p[1]
    total+=((XY[i][0] - XY[j][0])**2 + (XY[i][1] - XY[j][1])**2)**0.5

print(total/N)

Solution (Python):
import math

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

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

print(sum_dist * 2 / n)

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

print(ans*(2/n))

Solution (Python):
from math import sqrt, factorial
from itertools import permutations as pe
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
l = [i for i in range(N)]
d = 0
for i in pe(l):
    flag = False
    dd = 0
    x, y, xx, yy = 0, 0, 0, 0
    
    for ii in i:
        if flag:
            xx, yy = X[ii][0], X[ii][1]
            dd += sqrt((x-xx)**2+(y-yy)**2)
            flag=False
        x, y = X[ii][0], X[ii][1]
        flag=True
    d+=dd
print(d/factorial(N))

Solution (Python):
from itertools import permutations
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from math import factorial
from math import sqrt
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



n = int(input())
a = []
for i in range(n):
    x, y = map(int, input().split())
    a.append([x, y])
total = 0
for i in permutations(a):
    
    for j in range(1, n):
        x_distance = i[j][0] - i[j - 1][0]
        y_distance = i[j][1] - i[j - 1][1]
        d = sqrt(x_distance ** 2 + y_distance ** 2)
        total += d
ans = total / factorial(n)
print(ans)

Solution (Python):
from itertools import permutations
import math

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

cnt=0
ans=0.0
for p in permutations(range(N)):
    cnt+=1
    for i in range(N-1):
        dx=pts[p[i+1]][0]-pts[p[i]][0]
        dy=pts[p[i+1]][1]-pts[p[i]][1]

        ans+=math.sqrt(dx**2+dy**2)

print(ans/cnt)

Solution (Python):
import itertools
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
    x[i],y[i] = map(int,input().split())
num=[i for i in range(n)]
def dist(i,j):
    return ((x[i]-x[j])**2 + (y[i]-y[j])**2)**0.5
ans=0
s=0
for perm in list(itertools.permutations(num)):
    for i in range(n-1):
        ans+=dist(perm[i],perm[i+1])
    s+=1     
print(ans/s)

Solution (Python):
from math import sqrt, factorial
from itertools import permutations
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
order = [i for i in range(N)]
s = 0
for a in permutations(order, N):
    for b in range(N-1):
        s += sqrt((xy[a[b]][0]-xy[a[b+1]][0])**2+(xy[a[b]][1]-xy[a[b+1]][1])**2)
print(s/factorial(N))