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 itertools import permutations

def calc(x, y):
    return ((x[0] - y[0])**2 + (x[1] - y[1])**2)**0.5

def main():
    n = int(input())
    A = [list(map(int, input().split())) for i in range(n)]
    A = list(permutations(A))
    ls = []
    for c in A:
        l = calc(c[0], c[1])
        if len(c) > 2:
            prev_idx = 1
            for a in c[2:]:
                l += calc(c[prev_idx], a)
                prev_idx += 1
        ls.append(l)
    print(sum(ls) / len(ls))


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
from itertools import combinations, permutations
import math

N = int(input())
t = np.zeros((N, 2))
for _ in range(N):
    t[_] = np.array(list(map(int, input().split())))

def distance(i, j):
    return np.sqrt(np.sum((t[i] - t[j])**2))

dm = np.zeros((N,N))

for i, j in combinations(range(N), 2):
    dm[i, j] = distance(i, j)

total = 0
for r in permutations(range(N), N):
    r = list(r)
    for i, j in zip(r[:-1], r[1:]):
        total += dm[min(i,j),max(i,j)]
    
res = total / math.factorial(N)
print(res)

Solution (Python):
import itertools
import math
N=int(input())
lst=[None]*N
for i in range(N):
    lst[i]=tuple(map(int, input().split()))
total=0
for i in range(N-1):
    for j in range(i+1,N):
        total+=math.sqrt( (lst[i][0]-lst[j][0])**2 + (lst[i][1]-lst[j][1])**2 )

ave=total*2/N
print(ave)

Solution (Python):
import numpy as np
import math

N = int(input())

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

gokei = 0
for i in range(N):
    for j in range(i+1, N):
        gokei += np.linalg.norm(X[i]-X[j])

print(gokei*math.factorial(N-1)*2/math.factorial(N))

Solution (Python):
import math
import itertools as its
x=int(input())
y=[[float(i) for i in input().split()] for _ in range(x)]
l=0
def di(i1,i2):
  return math.sqrt((y[i1][0]-y[i2][0])**2+(y[i1][1]-y[i2][1])**2)
z=[[di(j,-i-1) for i in range(x-1-j)]for j in range(x)]
yit=list(its.permutations(range(x)))
for i in yit:
  now=0
  while now<x-1:
    if i[now]<i[now+1]:
      l+=z[i[now]][-i[now+1]+i[now]]
    else:
      l+=z[i[now+1]][+i[now+1]-i[now]]
    now+=1
print(l/(len(yit)))

Solution (Python):
from math import sqrt

N = int(input())
loc = [[int(j) for j in input().split()] for i in range(N)]
dist = []
for i in range(N):
  for j in range(i + 1, N):
    dist.append(sqrt((loc[j][0] - loc[i][0]) ** 2 + (loc[j][1] - loc[i][1]) ** 2))
sum = 0
for d in dist:
  sum += d
print(sum * 2 / N)

Solution (Python):
import itertools

n = int(input())
a = [i for i in range(n)]
x,y = [0]*n , [0]*n
for i in range(n):
    x[i],y[i] = map(int,input().split())
r = list(itertools.permutations(a,len(a)))

ans = 0
for i in r:
    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
        
print(ans / len(r))

Solution (Python):
import itertools
import math

n=int(input())
lis=[i for i in range(n)]
P_lis=itertools.permutations(lis)

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

ans=0
P=list(P_lis)
for i in range(len(P)):
  for j in range(n-1):
    ans+=math.sqrt((x[P[i][j]]-x[P[i][j+1]])**2+(y[P[i][j]]-y[P[i][j+1]])**2)
print(ans/len(P))

Solution (Python):
import math

n=int(input())
P=[]
for i in range(n):
    x,y=map(int,input().split())
    P.append([x,y])
    
ans=0
for i in range(n-1):
    x1=P[i][0]
    y1=P[i][1]
    for j in range(i+1,n):
        x2=P[j][0]
        y2=P[j][1]
        ans+=math.sqrt((x1-x2)**2+(y1-y2)**2)
ans=ans*2/n
print(ans)

Solution (Python):
import math

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

total = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        x1, y1 = tmp[i]
        x2, y2 = tmp[j]
        total += math.sqrt((x1-x2)**2 + (y1-y2)**2)

print(total * (n - 1) * 2 / (n * (n - 1)))

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

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

ans *= 2/N
print(ans)

Solution (Python):
import math
n = int(input())
x = [0] * n
y = [0] * n
seq = []
for i in range(n):
    x[i],y[i] = map(int,input().split())
    seq.append(i)
import itertools
sum = 0
seq_list = list(itertools.permutations(seq))
for i in range(len(seq_list)):
    for j in range(n-1):
        sum += math.sqrt((x[seq_list[i][j+1]]-x[seq_list[i][j]])**2 + (y[seq_list[i][j+1]]-y[seq_list[i][j]])**2 )

print(sum/len(seq_list))

Solution (Python):

import itertools
import math

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

M = 0

for l in itertools.permutations(range(N)):
    L = 0
    for m in range(1, N):
        L += ((X[l[m]][0] - X[l[m-1]][0])**2 + (X[l[m]][1] - X[l[m-1]][1])**2)**0.5
    M += L

print(M / math.factorial(N))

Solution (Python):
import itertools
import math
n=int(input())
lst=[None]*n
for i in range(n):
    lst[i]=tuple(map(int, input().split()))
total=0
for v in itertools.permutations(lst):
    for i in range(n-1):
        dis=math.sqrt( (v[i][0]-v[i+1][0])**2 + (v[i][1]-v[i+1][1])**2 )
        total+=dis
print(total/math.factorial(n))

Solution (Python):

def inputlist(): return [int(j) for j in input().split()]
from collections import Counter


N = int(input())
x = [0]*N
y = [0]*N
ans = 0
for i in range(N):
    x[i],y[i] = inputlist()
for i in range(N-1):
    for j in range(i+1,N):
        dx = (x[i]-x[j])**2
        dy = (y[i]-y[j])**2
        dl = (dx+dy)**(1/2)
        ans += 2*dl
print(ans/N)

Solution (Python):
from itertools import permutations as perm


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


def getCost(p):
    ret = 0
    for i, ni in zip(p, p[1:]):
        x, y = XY[i]
        nx, ny = XY[ni]
        ret += ((nx-x)**2+(ny-y)**2)**0.5
    return ret


N = int(input())
XY = [inpl() for i in range(N)]

ans = sum(getCost(p) for p in perm([i for i in range(N)]))

f = 1
for i in range(1, N + 1):
    f *= i
print(ans / f)

Solution (Python):
def inpl():
    return list(map(int, input().split()))


def backtrack(towns, x=0, y=0, v=0, ans=0, flag=True):
    
    if not towns:
        ans += v
        return ans
    t = 0
    for i in range(len(towns)):
        nx, ny = XY[towns[i]]
        if flag:
            tmp = ((nx - x)**2 + (ny - y)**2)**0.5
        else:
            tmp = 0
        t += backtrack(towns[:i]+towns[i+1:], nx, ny, v+tmp, ans)
    return t + ans


N = int(input())
XY = [inpl() for i in range(N)]

ans = backtrack([i for i in range(N)], flag=False)

f = 1
for i in range(1, N + 1):
    f *= i
print(ans / f)

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

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

ans=0
from itertools import combinations

for a,b in combinations(xy, 2):
    ans+=dis(a,b)
print(2*ans/n)

Solution (Python):
from itertools import permutations
import math

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


B = []
for i in permutations(A,2):
    B.append(i)


ans = 0
for i in range(len(B)):
    ans += math.sqrt((B[i][0][0] - B[i][1][0])**2 + (B[i][0][1] - B[i][1][1])**2)

print(ans/N)

Solution (Python):
import math

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

ans = 0
for x1, y1 in xy:
    for x2, y2 in xy:
        ans += math.sqrt((x1-x2)**2 + (y1-y2)**2)
print(ans/n)

Solution (Python):
import itertools
import math

n = int(input())
li = list(itertools.permutations(range(1,n+1)))
a = []
for _ in range(n):
    a.append([int(x) for x in input().split()])
ans = 0
for i in li:
    for j in range(n-1):
        x = a[i[j]-1][0]-a[i[j+1]-1][0]
        y = a[i[j]-1][1]-a[i[j+1]-1][1]
        ans += math.sqrt(x**2+y**2)
x = 1
for i in range(1,n+1):
    x *= i
print(ans/x)

Solution (Python):
import math

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

ans = 0
for x1, y1 in xy:
    for x2, y2 in xy:
        ans += math.sqrt((x1-x2)**2 + (y1-y2)**2)
print(ans/n)

Solution (Python):
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s

n = load()

p = []
for i in range(n):
    x, y = load_list()
    p.append((x, y))

perms = perm_li([i for i in range(0, n)])

leng = []
for perm in perms:
    l = 0
    for i in range(1, len(perm)):
        e1, e2 = perm[i-1], perm[i]
        x1, y1 = p[e1][0], p[e1][1]
        x2, y2 = p[e2][0], p[e2][1]
        l += math.sqrt(math.pow(x2-x1, 2) + math.pow(y2-y1, 2))
    leng.append(l)

print(sum(leng) / len(leng))

Solution (Python):
import math
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
dist = 0
for x1,y1 in l:
    for x2,y2 in l:
        dist += math.sqrt((x1-x2)**2 + (y1-y2)**2)
ave = dist/n
print(ave)

Solution (Python):
import math

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

Solution (Python):





from itertools import permutations

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

    p=permutations(l)
    dist = 0
    for v in p:
        for i in range(N-1):
            dist+=((v[i][0]-v[i+1][0])**2+(v[i][1]-v[i+1][1])**2)**0.5

    print(dist/len(list(permutations((l)))))


resolve()

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

Solution (Python):
import math
import itertools

N = int(input())

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

routes = list(itertools.permutations(lst))

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

routes = [i for i in routes]
distancies = []
for i, r in enumerate(routes):
    for j, a in enumerate(r):
        if j >= len(r) - 1: break
        b = r[j + 1]
        ab_dist = distance(a, b)
        distancies.append(ab_dist)

print(sum(distancies) / len(routes))

Solution (Python):
import itertools
from math import factorial

N=int(input())
x=[0]*N
y=[0]*N
path=[0]*(factorial(N))
for i in range(N):
  x[i],y[i] = map(int,input().split())
  
L=list( itertools.permutations([i for i in range(N)]) )
for j,order in enumerate(L):
  for k in range(1,len(order)):
    path[j] += ( (x[order[k]]-x[order[k-1]])**2 + (y[order[k]]-y[order[k-1]])**2 )**0.5
  
    
print(sum(path)/len(path))

Solution (Python):

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

l = 0

for i in range(n):
    for j in range(n):
        l+=((ad[i][0]-ad[j][0])**2+(ad[i][1]-ad[j][1])**2)**(1/2)

ans = l / n
print(ans)

Solution (Python):
n=int(input())
a=[[int(i) for i in input().split()] for i in range(n)]
import itertools as it
import math
pe=list(it.permutations(range(n),n))

total=0
for i in pe:
    for x in range(len(i)-1):
        total+=((a[i[x]][0]-a[i[x+1]][0])**2+(a[i[x]][1]-a[i[x+1]][1])**2)**0.5

print(total/math.factorial(n))

Solution (Python):
import itertools
N = int(input())
mati = list()
for _ in range(N):
    mati.append(list(map(int, input().split())))

mati_list = list(range(N))
comb = list(itertools.combinations(mati_list, 2))
length = list()
for i, k in comb:
    x_i, y_i = mati[i]
    x_k, y_k = mati[k]
    l = ((x_i - x_k) ** 2 + (y_i - y_k) ** 2) ** 0.5
    length.append(l)
ave = sum(length) / len(length)
print(ave*(N-1))

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

import itertools

cnt = 0
dis_ = 0
sum_ = 0
for route in itertools.permutations(range(N), N):
    cnt += 1
    
    
    
    dis_ = 0
    for i in range(N - 1):
        dis = (xy[route[i]][0] - xy[route[i + 1]][0])**2 + (xy[route[i]][1] - xy[route[i + 1]][1])**2
        dis = dis**0.5
        dis_ += dis
    sum_ += dis_

print(sum_ / cnt)

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

ans = 0
for pat in permutations(Ts):
  x = 0
  for i, p in enumerate(pat):
    if i==0:
      past = p
      continue
    a, b = past
    c, d = p
    x += sqrt((a-c)**2+(b-d)**2)
  ans += x

print(ans/factorial(N))

Solution (Python):
import itertools

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

def distance(a, b):
  res = (a[0]-b[0])**2 + (a[1]-b[1])**2
  return res ** 0.5
  
ans = 0.0
combs = itertools.combinations(range(N), 2)
for comb in combs:
  ans += distance(xy[comb[0]], xy[comb[1]])

ans = ans * 2 / N
print(ans)

Solution (Python):
import itertools

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

def distance(a, b):
  res = (a[0]-b[0])**2 + (a[1]-b[1])**2
  return res ** 0.5
  
ans = 0.0
cnt = 0
perms = itertools.permutations(range(N))
for perm in perms:
  cnt += 1
  for j in range(N-1):
    a = perm[j]
    b = perm[j+1]
    ans += distance(xy[a], xy[b])

ans /= cnt
print(ans)

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

def dis(a, b, c, d):
    return ((a - c) ** 2 + (b - d) ** 2) ** (1/2)

s = 0
m = 0
for i in range(n):
    for j in range(i+1, n):
        a, b = t[i]
        c, d = t[j]
        s += dis(a, b, c, d)
        m += 1

ans = (s / m * (n-1))
print(ans)

Solution (Python):
import itertools
import math
N = int(input())
xy = []
for _ in range(N):
    xy.append(list(map(int,input().split())))
    
alls = list(itertools.permutations(range(1,N+1))) 
def length(X,Y): 
    l = math.sqrt((X[0]-Y[0])**2 + (X[1]-Y[1])**2)
    return l
Nk = math.factorial(N) 

L = 0
for i in range(Nk):
    l = 0
    for j in range(N-1):
        c1 = xy[alls[i][j]-1]
        c2 = xy[alls[i][j+1]-1]
        l += length(c1,c2)
    L += l
    
print(L/Nk)

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

dist = 0.0

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

print(dist / N)

Solution (Python):
import math
import itertools

A=[]
N = int(input())
E=math.factorial(N)
lis = [x for x in range(0,N)] 
P = list(itertools.permutations(lis))

for i in range(N):
 x=list(map(int,input().split()))
 A.append(x)
B=0
for j in range(E):
 for k in range(N-1):
  a=P[j][k]
  b=P[j][k+1]
  B+=((A[a][0]-A[b][0])**2+(A[a][1]-A[b][1])**2)**(1/2)
C=B/E
print(C)

Solution (Python):
import itertools
import math

n = int(input())

xy = []

for _ in range(n):
    xy.append(tuple(map(int,input().split())))

ans = 0

per = itertools.permutations(range(n))

for p in per:
    x1,y1 = xy[p[0]]
    dif_tmp = 0
    for i in range(1,len(p)):
        x2,y2 = xy[p[i]]
        dif_tmp += ((x1-x2)**2 + (y1-y2)**2)**0.5
        x1,y1 = x2,y2

    ans += dif_tmp

ans /= math.factorial(n)
print(ans)

Solution (Python):
import itertools
import math

def resolve():
    n = int(input())
    fac = math.factorial(n)
    S = [list(map(int, input().split())) for _ in range(n)]

    ans = 0
    for p in itertools.permutations(range(n)):
        sum = 0
        for i in range(n-1):
            sum += math.sqrt((S[p[i]][0] - S[p[i+1]][0])**2 + (S[p[i]][1] - S[p[i+1]][1])**2)
        ans += sum

    print(ans/fac)

if __name__ == '__main__':
    resolve()

Solution (Python):
import itertools
import math

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

town=[]
for i in range(N):
    town.append(i)

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



ans=0
for v in itertools.permutations(town):
    
    sum=0
    for i in range(len(v)-1):
        sum+=distance[v[i]][v[i+1]]
    ans+=(sum)
    
print(ans/(math.factorial(N)))

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

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

print(ans*2/n)

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

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

ans=l/n
print(ans)

Solution (Python):

import itertools
import math
n = int(input())
x = [0] * n
y = [0] * n
l = list(range(n))
ans = 0
for i in range(n):
    x[i], y[i] = map(int, input().split())
for v in itertools.permutations(l, 2):
    ans += math.sqrt((x[v[0]] - x[v[1]])**2 + (y[v[0]] - y[v[1]])**2)
print(ans/n)

Solution (Python):

import itertools
import math
n = int(input())
x = [0] * n
y = [0] * n
a = list(range(n))
ans = 0
for i in range(n):
    x[i], y[i] = map(int, input().split())
for v in itertools.permutations(a, 2):
    ans += math.sqrt((x[v[0]] - x[v[1]])**2 + (y[v[0]] - y[v[1]])**2)
print(ans/n)

Solution (Python):
import itertools
import math

def dist(xy1,xy2):
  x1,y1=xy1
  x2,y2=xy2
  return math.sqrt((x2-x1)**2+(y2-y1)**2)

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

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

allperm=list(itertools.permutations(range(N)))

allsum=0
for perm in allperm:
  for i in range(N-1):
    allsum+=dist(xylist[perm[i]],xylist[perm[i+1]])
    
print(allsum/len(allperm))

Solution (Python):
import math

def sort(n, pl):
    if n > 1:
        pl_list = []
        for i in range(n):
            tmp = []
            tmp.extend(pl)
            p = tmp.pop(i)
            for l in sort(n-1, tmp):
                l.insert(0, p)
                pl_list.append(l)
        return pl_list
    else:
        return [pl]

def average_len(n, pl):
    pl_list = sort(n, pl)
    ave = 0.0
    for pl in pl_list:
        for i in range(n-1):
            ave += math.sqrt((pl[i][0]-pl[i+1][0])**2+(pl[i][1]-pl[i+1][1])**2)
    ave /= len(pl_list)
    print(ave)

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

average_len(n, pl)

Solution (Python):
import numpy as np
n = int(input())
grid = []
for i in range(n):
    array = list(map(int,input().split()))
    grid.append(array)
sum = 0
for i in range(n):
    for j in range(i+1,n):
        sum += np.sqrt((grid[i][0]-grid[j][0])**2+(grid[i][1]-grid[j][1])**2)
print(sum*(n-1)/n/(n-1)*2)

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

for i, j in ten:
  for k, u in ten:
    a += math.sqrt((i - k)**2 + (j - u)**2)

print(a/n)

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

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

ll=[]
for v in itertools.permutations(range(n)):
    ll.append(list(v))
a=0
for j in ll:
    for k in range(len(j)-1):
        x=j[k]
        y=j[k+1]
        dis=math.sqrt((l[x][0]-l[y][0])**2+(l[x][1]-l[y][1])**2)
        a+=dis

print(a/len(ll))

Solution (Python):

from itertools import permutations

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

def main():
    N = int(input())
    points = tuple(tuple(map(int, input().split())) for _ in range(N))
    paths = list(permutations(list(range(N))))

    ans = 0
    for path in paths:
        for i in range(N-1):
            ans += dist(points[path[i]], points[path[i+1]])

    ans /= len(paths)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

from itertools import permutations

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

def main():
    N = int(input())
    points = tuple(tuple(map(int, input().split())) for _ in range(N))
    paths = list(permutations(list(range(N))))

    ans = 0
    for path in paths:
        for i in range(N-1):
            ans += dist(points[path[i]], points[path[i+1]])

    ans /= len(paths)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import itertools, math
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in itertools.permutations(range(n)):
    for j in range(len(i)-1):
        ans += pow(pow(xy[i[j]][0]-xy[i[j+1]][0], 2) + pow(xy[i[j]][1]-xy[i[j+1]][1], 2), 0.5)
print(ans/math.factorial(n))

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

for i, j in ten:
  for k, u in ten:
    a += math.sqrt((i - k)**2 + (j - u)**2)

print(a/n)

Solution (Python):
def dfs(coord, visited, route, sum):
    n = len(visited)

    allVisited = True
    for city in range(n):
        if visited[city] is False:
            allVisited = False
            break

    if allVisited is True:
        dist = 0

        for i in range(1, len(route)):
            prev = route[i - 1]
            cur = route[i]
            dist += (
                (coord[prev][0] - coord[cur][0]) ** 2
                + (coord[prev][1] - coord[cur][1]) ** 2
            ) ** 0.5
        sum += dist
        return sum

    for next_city in range(n):
        if visited[next_city] is False:
            visited[next_city] = True
            route.append(next_city)
            sum = dfs(coord, visited, route, sum)
            visited[next_city] = False
            route.pop(-1)

    return sum


n = int(input())
coord = []
route = []
visited = [False] * n

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


sum = 0
sum = dfs(coord, visited, route, sum)

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

print(sum / perm)

Solution (Python):
import itertools

n = int(input())
pos = tuple(tuple(int(i) for i in input().split()) for _ in range(n))

def distance(x, y):
    return ((x[0] - y[0])**2 + (x[1] - y[1])**2)**0.5

totals = []
for path in itertools.permutations(pos, n):
    d = 0
    for i in range(len(path)-1):
        d += distance(path[i], path[i+1])
    totals.append(d)

print(sum(totals) / len(totals))

Solution (Python):
import math
n = int(input())
ten = [list(map(int,input().split())) for i in range(n)]
av = 0

for i, j in ten:
  for k, u in ten:
    av += math.sqrt((i - k)**2 + (j - u)**2)

print(av/n)

Solution (Python):
import itertools

n = int(input())

l = []

for _ in range(n):

    l.append(list(map(int, input().split())))

aaaa = list(itertools.permutations(l , n))


distance = 0
for aa in aaaa:

    for i in range(len(aa)):
        if i != n-1:
            xi = (aa[i][0])
            yi = (aa[i][1])
            xj = (aa[i + 1][0])
            yj = (aa[i + 1][1])

            distance += ( (xi - xj) ** 2 + (yi - yj) ** 2 ) ** 0.5


pattern = len(aaaa)

ans = distance / pattern

print(ans)

Solution (Python):
import math
import copy

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

sum = 0
for i, xy in enumerate(a):
    xi, yi = xy
    aa = copy.deepcopy(a)
    aa.pop(i)
    for xj, yj in aa:
        sum += math.sqrt((xi - xj) ** 2 + (yi - yj) ** 2)

print(sum * math.factorial(n - 1) / math.factorial(n))

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



def func(N, lst):

    
    N_fact = factorial(N)

    
    perm_grid_xy = permutations(lst)

    
    total_dist = total_distance(N, perm_grid_xy)

    
    average_dist = total_dist / N_fact

    return average_dist


def total_distance(N, perm_grid_xy):

    ret = 0
    
    for grid_xy in perm_grid_xy:
        for i in range(N-1):
            x0, y0 = grid_xy[i][0], grid_xy[i][1]
            x1, y1 = grid_xy[i+1][0], grid_xy[i+1][1]
            dist = ((x0 - x1)**2 + (y0 - y1)**2) ** 0.5
            ret += dist

    return ret


if __name__ == "__main__":
    N = int(input())
    lst = [tuple(map(int, input().split())) for _ in range(N)]
    print(func(N, lst))

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



def func(N, lst):

    
    N_fact = factorial(N)

    
    perm_grid_xy = permutations(lst)

    
    total_dist = total_distance(N, perm_grid_xy)

    
    average_dist = total_dist / N_fact

    return average_dist


def total_distance(N, perm_grid_xy):
    
    ret = 0
    
    for grid_xy in perm_grid_xy:
        tmp = sum(
            ((grid_xy[i][0] - grid_xy[i+1][0]) ** 2 
            + (grid_xy[i][1] - grid_xy[i+1][1]) ** 2) ** 0.5 
            for i in range(N-1)
            )
        ret += tmp

    return ret


if __name__ == "__main__":
    N = int(input())
    lst = [tuple(map(int, input().split())) for _ in range(N)]
    print(func(N, lst))

Solution (Python):
import math
N = int(input())
city_list = [list(map(int, input().split())) for _ in range(N)]
average = 0
for x1, y1 in city_list:
    for x2, y2 in city_list:
        average += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
print(average / N)

Solution (Python):
import itertools
import math
N = int(input())
city_list = []
for i in range(N):
    x, y = map(lambda z: int(z), input().split())
    city_list.append((x, y))
root_list = list(itertools.permutations(city_list, N))
ave = 0
for root in root_list:
    length = 0
    while len(root) > 1:
        x1, y1, x2, y2 = root[0][0], root[0][1], root[1][0], root[1][1]
        length += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
        root = root[1:]
    ave += (length / len(root_list))
print(ave)

Solution (Python):
import itertools, math

def dist(way, n):
    dist = 0
    for i in range(n-1):
        x = (way[i][0] - way[i+1][0]) ** 2
        y = (way[i][1] - way[i+1][1]) ** 2
        dist += math.sqrt(x+y)
    return dist

n = int(input())
point = []

for _ in range(n):
    point.append(list(map(int, input().split())))

mean_dist = 0
cnt = 0
for v in itertools.permutations(point, n):
    mean_dist += dist(v, n)
    cnt += 1

print(mean_dist/cnt)

Solution (Python):
from math import sqrt
import itertools


def distance(dx,dy):
  return sqrt(dx**2 + dy**2)

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

ans=0
count=0
for sxy in itertools.permutations(xy):
  
  for i in range(1,N):
    x2,y2=sxy[i]
    x1,y1=sxy[i-1]
    
    dx=x2-x1
    dy=y2-y1
    ans+=distance(dx,dy)
  count+=1
    

print(ans/count)

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

ans=0
for x1, y1 in xy:
	for x2, y2 in xy:
		ans+=((x1-x2)**2+(y1-y2)**2)**0.5
print(ans/n)

'''
文字式にする、町の数をｎとするとき。

１経路に道 ( n-1 )　×　経路の数 n!　÷　道の種類 nC２　÷　経路の数 n!

= ( n-1 )　×　 n!　÷　 nC２　÷　n!
= ( n-1 )　÷　 nC２　　　　　　　　　
= ( n-1 )　÷　 ( n( n-1 ) ÷ 2・1 )
= 2 　÷　 n　　　　　　
'''

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

ans=0
for x1, y1 in xy:
	for x2, y2 in xy:
		ans+=((x1-x2)**2+(y1-y2)**2)**0.5
print(ans/n)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
import itertools
import math

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

def main():
    N = int(input())
    matrix = []
    for i in range(N):
        x, y = input_nums()
        matrix.append((x, y))
    total = 0
    count = 0
    for cmb in itertools.permutations(range(N), N):
        count += 1
        sumv = 0
        for i in range(len(cmb)-1):
            x1 = matrix[cmb[i]][0]
            y1 = matrix[cmb[i]][1]
            x2 = matrix[cmb[i+1]][0]
            y2 = matrix[cmb[i+1]][1]
            sumv += calc_distance(x1, y1, x2, y2)
        total += sumv
    print(total/count)


if __name__ == '__main__':
    main()