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):
N = int(input())
import math
def d(x,y):
    return math.sqrt((x[0]-y[0])**2+(x[1]-y[1])**2)
ans = 0
xy = [list(map(int,input().split())) for i in range(N)]
for i in range(N-1):
    for j in range(i,N):
        ans += 2*d(xy[i],xy[j])/N
print(ans)

Solution (Python):
from itertools import permutations as per
n = int(input())
x = [0]*n
y = [0]*n
for i in range(n): x[i],y[i] = map(int,input().split())

s = 0
for p in per(range(n)):
    for i in range(1,n):
        a,b = p[i],p[i-1]
        s += ((x[a]-x[b])**2+(y[a]-y[b])**2)**0.5

fac = 1
for i in range(1,n+1): fac *= i
print(s/fac)

Solution (Python):
import sys
from bisect import bisect_right as bsr
from collections import Counter as cnt
from collections import defaultdict as dd
from collections import deque
from fractions import gcd
from itertools import combinations as comb
from itertools import permutations as perm
from math import ceil, factorial, floor
from operator import itemgetter as ig
from statistics import mean

sys.setrecursionlimit(1000000)


args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    N = input(int)
    XY = input([[int, 2], N])
    ans = []
    for p in perm([x for x in range(N)]):
        last = p[0]
        temp = 0
        for xy in p[1:]:
            temp += ((XY[last][0] - XY[xy][0]) ** 2 +
                     (XY[last][1] - XY[xy][1]) ** 2) ** 0.5
            last = xy
        ans.append(temp)
    print(mean(ans))


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Solution (Python):
import itertools
import math

N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
all_pattern = math.factorial(N)
sum_length = 0
for i in itertools.permutations(range(N)):  
    current_len = 0
    for x in range(len(i) - 1):
        sumlen = (xy[i[x + 1]][0] - xy[i[x]][0]) ** 2 + \
            (xy[i[x + 1]][1] - xy[i[x]][1]) ** 2
        current_len += math.sqrt(sumlen)
    sum_length += current_len
ave_length = sum_length / all_pattern
print(ave_length)

Solution (Python):
n = int(input())
xys = []
for i in range(n):
    xi, yi = [int(_) for _ in input().split()]
    xys.append([xi, yi])

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

print(dis_sum / n)

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

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



l = list(range(N))
total = 0
dist = 0
for i, v in enumerate(itertools.permutations(l, N)):
    total += 1
    old_j = v[0]
    for j in v[1:]:
        dist += math.sqrt((D[j][0] - D[old_j][0]) ** 2 + (D[j][1] - D[old_j][1]) ** 2)

print(dist / total)

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

n = int(input())

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

ans = 0
for count, temp in enumerate(permutations(list(range(n)))):
    for i in range(n - 1):
        a = temp[i + 1]
        b = temp[i]
        ans += sqrt((temp_list[a][0] - temp_list[b][0]) ** 2 + (temp_list[a][1] - temp_list[b][1]) ** 2)

ans /= (count + 1)
print(ans)

Solution (Python):
import math

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
distance = 0
for i in range(N):
    for j in range(N):
        distance += math.sqrt((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2)
print(distance / N)

Solution (Python):
import math, itertools
n = int(input())
l= []
for _ in range(n):
    l.append(list(map(int, input().split())))
s = [i for i in range(n)]
lis = list(itertools.permutations(s, n))
j = 0
sm = 0
for i in range(len(lis)):
    for j in range(n-1):
        sm += ((l[lis[i][j]][0]-l[lis[i][j+1]][0])**2+(l[lis[i][j]][1]-l[lis[i][j+1]][1])**2)**0.5
print(sm/math.factorial(n))

Solution (Python):
import itertools
import math
n=int(input())
t=[0]*n
for i in range(n):
  t[i]=list(map(int,input().split()))
  
s=list(itertools.permutations(range(n)))
ans=0
x=math.factorial(n)
for i in range(x):
  u=s[i]
  p=0
  for j in range(n-1):
    p+=((t[u[j+1]][0]-t[u[j]][0])**2+(t[u[j+1]][1]-t[u[j]][1])**2)**(1/2)
    
  ans+=p
print(ans/x)

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

soukyori=[] 
for j in range(n-1):
    for k in range(j+1,n):
        kyori=math.sqrt((l[j][0]-l[k][0])**2+(l[j][1]-l[k][1])**2)
        soukyori.append(kyori)

total=sum(soukyori)

ave=total*2/n
print(ave)

Solution (Python):
from itertools import permutations
import math

def f_len(a, b):
    x1, y1 = a
    x2, y2 = b
    return math.sqrt((x1 - x2)**2 + (y1 - y2)**2)

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for case in permutations(range(n)):
    temp = 0
    for i in range(1, n):
        temp += f_len(xy[case[i]], xy[case[i-1]])
    ans += temp
ans /= math.factorial(n)
print(ans)

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

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

XY=[[int(x) for x in input().rstrip().split()] for i in range(N)]

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


print(2*ans/N)

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

XY=[[int(x) for x in input().rstrip().split()] for i in range(N)]

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

print(2*ans/N)

Solution (Python):
from itertools import permutations
import math

def dist(area1, area2):
    return math.sqrt((area1[0] - area2[0]) ** 2 + (area1[1] - area2[1]) ** 2)


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

total = 0
for inds in aind:
    temp = [dist(area[inds[i]], area[inds[i+1]]) for i in range(len(inds)-1)]
    total += sum(temp)
print(total / len(aind))

Solution (Python):
import itertools

N = int(input())
X = []
for i in range(N):
  X.append([int(j) for j in input().split()])

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

def mean(array):
  return sum(array)/len(array)

p = itertools.permutations(X, N)

ans = []
for X in p:
  D = []
  for i in range(N-1):
    X1, X2 = X[i], X[i+1]
    D.append(distance(X1, X2))
  ans.append(sum(D))
print(mean(ans))

Solution (Python):

N=int(input())
import math

XY=[[int(x) for x in input().rstrip().split()] for i in range(N)]

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

print(2*ans/N)

Solution (Python):
import math
def func(n):
    if n == 2:
        return 2
    else:
        return (n-1)*func(n-1)
n = int(input())
town = [list(map(int,input().split())) for i in range(n)]
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        ans += ((town[i][0]-town[j][0])**2 + (town[i][1]-town[j][1])**2)**(1/2)
print(ans*func(n)/math.factorial(n))

Solution (Python):
from itertools import permutations
from math import factorial
def myAnswer(N:int, XY:list) -> int:
   l = [i for i in range(N)]
   number = factorial(N)
   ans = 0
   for i in permutations(l):
      i = list(i)
      pre = i.pop(0)
      for n in i:
         ans += ((XY[n][0] - XY[pre][0])**2 + (XY[n][1] - XY[pre][1])**2)**0.5
         pre = n
   return ans/number


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   XY = []
   for _ in range(N):
      XY.append(list(map(int,input().split())))
   print(myAnswer(N,XY[:]))
if __name__ == '__main__':
   main()

Solution (Python):
from itertools import permutations
n = int(input())
arr = [list(map(int, input().split())) for i in range(n)]
sm = 0
cnt = 0
for p in permutations(range(n)):
    for i, j in zip(p, p[1:]):
        x1, y1 = arr[i]
        x2, y2 = arr[j]
        sm += ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
    cnt += 1
print(sm / cnt)

Solution (Python):
import itertools
import math
N = int(input())
xy = []
for count in range(N):
    xy.append(input().split())
    itertools.permutations(xy)
XY = []
sum = 0
ave = 0
count = 0
for XY in itertools.permutations(xy):
    for i in range(N-1):
        leng = math.sqrt(((int(XY[i+1][0]) - int(XY[i][0])) ** 2) +
                         ((int(XY[i + 1][1]) - int(XY[i][1])) ** 2))
        sum += leng

ave = sum / math.factorial(N)
print(ave)

Solution (Python):
"""
C - Average Length
https://atcoder.jp/contests/abc145/tasks/abc145_c
"""
import itertools

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

distances = []

for i in range(n-1):
    for j in range(i+1, n):
        xi, yi = point[i]
        xj, yj = point[j]

        d = pow(pow(xi - xj, 2) + pow(yi - yj, 2), 0.5)
        distances.append(d)

ans = 2* sum(distances) / n

print(ans)

Solution (Python):
import numpy as np
import math
n=int(input())
machi = [[0]*2 for _ in range(n)]
for i in range(n):
    x,y = map(int,input().split())
    machi[i][0] = x
    machi[i][1] = y

kyori = np.array([[0]*n for _ in range(n)],dtype='float')

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

ans = np.sum(kyori) / n
print(ans)

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

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

for j in range(n):
    for k in range(n):
        if j >= k:
            continue
        l += math.sqrt((xi[j]-xi[k])**2 + (yi[j]-yi[k])**2)

print(l*2/n)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]




from itertools import permutations
N = ii()
xy = li2(N)
ans = float('inf')
tmp = 0.0
for l in permutations([i for i in range(N)]):
    for i in range(N-1):
        tmp += pow(pow(xy[l[i+1]][0]-xy[l[i]][0], 2) + pow(xy[l[i+1]][1]-xy[l[i]][1], 2), 0.5)

bunshi = 1
for i in range(1, N+1):
    bunshi *= i
print(tmp / bunshi)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]




from itertools import permutations
N = ii()
xy = li2(N)
ans = float('inf')
tmp = 0.0
for l in permutations([i for i in range(N)]):
    for i in range(N-1):
        tmp += pow(pow(xy[l[i+1]][0]-xy[l[i]][0], 2) + pow(xy[l[i+1]][1]-xy[l[i]][1], 2), 0.5)

bunshi = 1
for i in range(1, N+1):
    bunshi *= i
print(tmp / bunshi)

Solution (Python):
import sys
import math
import itertools

readline = sys.stdin.readline
sqrt = math.sqrt

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

def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(tuple(map(int, readline().split())))
    
    D = []
    for i in range(N):
        tmp = []
        for j in range(N):
            tmp.append(euclid_distance(A[i], A[j]))
        D.append(tmp)

    distance = []
    for root in itertools.permutations(range(N)):
        dsum = 0
        for r in range(N-1):
            dsum += D[root[r]][root[r+1]]
        distance.append(dsum)
    
    ans = sum(distance)/len(distance)    
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
li = []
for _ in range(n):
    a, b = map(float, input().split())
    li.append((a,b))
    
sum_ = 0
for i in range(n):
    for j in range(n):
        if i > j:
            sum_ += ((li[i][0]-li[j][0])**2 + (li[i][1]-li[j][1])**2)**0.5

print((2*sum_)/float(n))

Solution (Python):
import itertools
import math

N = int(input())
P = [[int(x) for x in input().split()] for _ in range(N)]
ans=0
for p in itertools.permutations(P):
    for (x1, y1), (x2, y2) in zip(p, p[1:]):
        ans += math.hypot(x1-x2, y1-y2)
print(ans/math.factorial(N))

Solution (Python):
import itertools
import math

N = int(input())
P = [[int(x) for x in input().split()] for _ in range(N)]
ans=0
for p in itertools.permutations(P):
    for (x1, y1), (x2, y2) in zip(p, p[1:]):
        ans += ((x1-x2)**2 + (y1-y2)**2)**.5
print(ans/math.factorial(N))

Solution (Python):
import itertools
import math


N = int(input())
P = [[int(x) for x in input().split()] for _ in range(N)]

Plist = list(itertools.permutations(P))
ans=0
for p in Plist:
    for i in range(len(p)-1):
        ans += math.hypot(p[i][0]-p[i+1][0], p[i][1]-p[i+1][1])
print(ans/len(Plist))

Solution (Python):
import sys
import itertools
import math

sys.setrecursionlimit(10**7)
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

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

pall = 0
for pat in pattern:
    for i in range(N-1):
        currp = xy[pat[i]]
        nextp = xy[pat[i+1]]
        dist = math.sqrt(
            (currp[0] - nextp[0])**2
          + (currp[1] - nextp[1])**2
            )
        pall += dist

print(pall/(len(pattern)))

Solution (Python):
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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

d = [[0]*(N) for _ in range(N)]
cnt = 0
for route in permutations(range(1, N+1)):
    for val1, val2 in zip(route[:-1], route[1:]):
        val1, val2 = val1-1, val2-1
        dist = d[val1][val2]
        if dist > 0:
            cnt += dist
        elif dist == 0:
            d[val1][val2] = (pow(xy[val1][0]-xy[val2][0], 2) + pow(xy[val1][1]-xy[val2][1], 2))**(1/2)
            cnt += d[val1][val2]
res = cnt/factorial(N)
print(res)

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


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

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

    sum = 0
    for i in permutations(pos, 2):
        
        """
        1箇所線分を固定した場合のパス(経路)は(n-1)!通り
        例えば、全パスn!通りのうち、1→2の線分が出てくるパスは(n-1)!通り
        各線分の距離*(n-1)!を全線分加算すると全パスの合計がでる
        """
        sum += sqrt((i[0][0]-i[1][0])**2+(i[0][1]-i[1][1])**2)*factorial(n-1)

    
    print(sum/factorial(n))


if __name__ == '__main__':
    main()

Solution (Python):
import itertools
n = int(input())
z = [list(map(int, input().split())) for _ in range(n)]
a = [0,1,2,3,4,5,6,7,8]
b = a[:n]
c = list(itertools.permutations(b))
ans = []
for i in range(len(c)):
    x = 0
    for j in range(n-1):
        y = ((z[c[i][j]][0]-z[c[i][j+1]][0])**2+(z[c[i][j]][1]-z[c[i][j+1]][1])**2)**0.5
        x += y
    ans.append(x)
print(sum(ans)/len(c))

Solution (Python):
from math import factorial

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

length = []

for i in range(n-1):
    for j in range(i+1, n):
        length.append(pow(((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2), 1/2))

m = (n-1) / (n*(n-1)/2)
mount = 0
for i in range(len(length)):
    mount += length[i] * m

print(mount)

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

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

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

ans=0

def kaijyo(n):
    if n==1:
        return 1
    return n*kaijyo(n-1)



for i in range(n-1):
    for j in range(i+1,n):
        a=spot[i]
        b=spot[j]
        dis=((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5
        ans+=dis*kaijyo(n-1)*2
        
print(ans/kaijyo(n))

Solution (Python):
N = int(input())
L = [list(map(int,input().split())) for i in range(N)]
ans = 0
import math
def d(x1,x2):
    return math.sqrt((x1[0]-x2[0])**2+(x1[1]-x2[1])**2)
for i in range(N-1):
    for j in range(i+1,N):
        ans += d(L[i],L[j])*2/N
print(ans)

Solution (Python):
import itertools
import math

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

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

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

ans = 0
count = 0
for i in range(len(l)):
	for j in range(n-1):
		ans += math.sqrt((xy[l[i][j]][0] - xy[l[i][j+1]][0])**2 + (xy[l[i][j]][1] - xy[l[i][j+1]][1])**2)
	count += 1

print(ans / count)

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

def calc(a, b):
    x1, y1 = a
    x2, y2 = b
    return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))
 
 
n = int(input())
xy = []
for i in range(n):
    xy.append(list(map(int, input().split())))
 
ans = 0
for order in permutations(range(n)):
    tmp = 0
    for i in range(1, n):
        tmp += calc(xy[order[i]], xy[order[i - 1]])
    ans += tmp
ans /= factorial(n)
 
print(ans)

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



li = [i for i in range(n)]
kumiawase = list(itertools.permutations(li))

fin_li = []
kumi_kazu = 0
for k in kumiawase:
    
    for i,kk in enumerate(list(k)):
        if i == 0:
            continue
        start = ma[k[i]]
        goal = ma[k[i-1]]
        x = (start[0]-goal[0])**2
        y = (start[1]-goal[1])**2
        fin_li.append(math.sqrt(x+y))
    kumi_kazu += 1



print(sum(fin_li)/kumi_kazu)

Solution (Python):
import sys
input = sys.stdin.readline
n=int(input())
s=[list(map(int, input().split())) for _ in range(n)]
a=0
for i in range(n-1):
    for j in range(i+1,n):
        a+=((s[i][0]-s[j][0])**2+((s[i][1]-s[j][1])**2))**(1/2)
print(2*a/n)

Solution (Python):

import io
import math
from math import sqrt

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

result = 0
for i in range(data):
  for j in range(data):
    if i != j:
      result += sqrt((arr[i][0]-arr[j][0])*(arr[i][0]-arr[j][0])+(arr[i][1]-arr[j][1])*(arr[i][1]-arr[j][1]))
print(result/data)

Solution (Python):
import sys
import numpy as np

n, *xy = map(int, sys.stdin.read().split())
x, y = np.array(xy).reshape(-1, 2).T

def main():
    dx = (x[:, None] - x) ** 2
    dy = (y[:, None] - y) ** 2
    ans = np.sqrt(dx + dy).sum() / n
    print(ans)

if __name__ ==  '__main__':
    main()

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

n = int(input())
xy = [(x, y) for x, y in (map(int, input().split()) for _ in range(n))]
ans = 0
for order in perm(range(n)):
    for i, j in zip(order, order[1:]):
        xi, yi = xy[i]
        xj, yj = xy[j]
        ans += sqrt((xi-xj)**2+(yi-yj)**2)

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

print(ans/nfact)

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

n = int(input())
xy = [(x, y) for x, y in (map(int, input().split()) for _ in range(n))]
ans = 0
for order in perm(range(n)):
    for i, j in zip(order, order[1:]):
        xi, yi = xy[i]
        xj, yj = xy[j]
        ans += sqrt((xi-xj)**2+(yi-yj)**2)

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

print(ans/nfact)

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

Solution (Python):
from math import factorial as fac
from math import sqrt
from collections import deque
N = int(input())
X = []
for i in range(N):
    x,y = map(int,input().split())
    X.append((x,y))
ans = 0
Q = deque()
for i in range(N):
    Q.append((0,[i],X[i][0],X[i][1]))
while Q:
    S,L,x,y = Q.pop()
    if len(L)==N:
        ans += S
        continue
    for i in range(N):
        if not(i in L):
            h,w = X[i]
            Q.append((S+sqrt(pow(x-h,2)+pow(y-w,2)),L+[i],h,w))
print(ans/fac(N))

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

def main():
  scan = sys.stdin.readline
  
  n = int(scan().rstrip())
  coordinates = np.array(
    tuple(tuple(int(x) for x in scan().rstrip().split()) for _ in range(n))
  )
  
  dist = np.array(
    tuple(
      tuple(
        np.sqrt(
          (coordinates[i][0] - coordinates[j][0]) ** 2 + (coordinates[i][1] - coordinates[j][1]) ** 2
        )
        for i in range(n)
      )
      for j in range(n)
    )
  )
  
  total = 0
  for pattern in itertools.permutations(range(n)):
    for i in range(n):
      if i == 0:
        continue
      else:
      	total += dist[pattern[i - 1]][pattern[i]]
    
  ave = total / math.factorial(n)
  
  print(ave)
  
  
if __name__ == "__main__":
  main()

Solution (Python):
import itertools
import math

def kj(k):
  if k==1:
    return 1
  else:
    return k*kj(k-1)
  return 0


n=int(input())

x=[]
y=[]

for i in range(n):
  a,b=map(int,input().split())
  x.append(a)
  y.append(b)

l=[i for i in range(n)]
dis=0

for v in itertools.permutations(l):
  for i in range(n-1):
    d=((x[v[i]]-x[v[i+1]])*(x[v[i]]-x[v[i+1]])) + ((y[v[i]]-y[v[i+1]])*(y[v[i]]-y[v[i+1]]))
    dis+=math.sqrt(d)

print(dis/kj(n))

Solution (Python):
import math
from itertools import permutations

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

d = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(i, N):
        dx = xy[i][0] - xy[j][0]
        dy = xy[i][1] - xy[j][1]
        d[i][j] = math.sqrt(dx**2 + dy**2)
        d[j][i] = math.sqrt(dx**2 + dy**2)

sum_ = 0
count = 0
for order in permutations(range(N)):
    for i in range(len(order)-1):
        sum_ += d[order[i]][order[i+1]]
    count += 1

print(sum_/count)

Solution (Python):
n = int(input())
xy_li = [list(map(int,input().split())) for _ in range(n)]
from itertools import permutations
import math
def distance(a,b):
    return math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)
ans = 0
cnt = 0
i_li = [i for i in range(n)]
for x in permutations(i_li,n):
    cnt += 1
    for i in range(n-1):
        ans += distance(xy_li[x[i]],xy_li[x[i+1]])
        
print(ans/cnt)

Solution (Python):










mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    XY = []
    for i in range(n):
        x,y = readInts()
        XY.append([x,y])
    a = 0
    for x1,y1 in XY:
        for x2,y2 in XY:
            a += ((x1-x2) ** 2 + (y1-y2)**2) **0.5
    print(a/n)
if __name__ == '__main__':
  main()

Solution (Python):










mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    XY = []
    for i in range(n):
        x,y = readInts()
        XY.append([x,y])
    a = 0
    for i in range(n):
        for j in range(i):
            a += ((XY[i][0] - XY[j][0]) ** 2 + (XY[i][1] - XY[j][1]) ** 2) ** 0.5
    print(a / (n * (n-1) * 0.5) * (n-1))
if __name__ == '__main__':
  main()

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

ans=0
for A in permutations(XY,n):
    cnt=0
    for j in range(n-1):
        cnt +=((A[j][0]-A[j+1][0])**2+(A[j][1]-A[j+1][1])**2)**0.5
    ans +=cnt
print(ans/factorial(n))

Solution (Python):
import math
N = int(input())
z = []
s = 0
def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n-1)

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

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

f = factorial(N)

print(s * (f*2//N) / f)

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

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

def input1():
	return int(input())


def input2():
	return map(int,input().split())


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

def keta(N):
	return len(str(N))

def euclid(town,dist):
	
	ans=0
	for i in range(1,len(town)):
		ans+=math.sqrt(( dist[town[i]-1][0] - dist[town[i-1]-1][0] )**2 + ( dist[town[i]-1][1] - dist[town[i-1]-1][1]) **2 )
	return ans

n=input1()
dist=[]
for _ in range(n):
	dist.append(input_array())
town=[i+1 for i in range(n)]
towns=list(itertools.permutations(town))

res=0

for i in towns:
	res+=euclid(list(i),dist)
print(res/len(towns))

Solution (Python):
from itertools import permutations

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

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

sm = 0
for itr in permutations(xy):
    dist = 0
    x, y = itr[0]
    for nx, ny in itr[1: ]:
        dist += ((nx-x)**2 + (ny-y)**2) ** 0.5
        x, y = nx, ny

    sm += dist

print(sm / n_fact)

Solution (Python):
from copy import copy
n = int(input())
x, y = [], []
for i in range(n):
    q, p = map(int, input().split())
    x.append(q)
    y.append(p)

x1 = copy(x)
y1 = copy(y)

ans = 0
for i in range(len(x)):
    for j in range(i + 1, len(x)):
        ans += ((x1[i] - x[j]) ** 2 + (y1[i] - y[j]) ** 2) ** (1 / 2)
        
      

print(ans * 2 / n)

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

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

sum=0
for i in range(n):
  for j in range(n):
    sum+=math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)


ave=sum/n
print(float(ave))

Solution (Python):

import sys
import numpy as np
import math
import itertools

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

def solve(N: int, x: "List[int]", y: "List[int]"):
    d = 0.0
    for v in itertools.permutations([i for i in range(N)],N):
        for i in range(len(v)-1):
            dist = distance(x[v[i]], y[v[i]],x[v[i+1]], y[v[i+1]])
            d += dist

    print(d/math.factorial(N))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    x = [int()] * (N)  
    y = [int()] * (N)  
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()

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

road = [0]*n
for i in range(n):
    road[i] = i

road_list = list(itertools.permutations(road))


def distance(a, b):
    x_a = xy[a][0]
    y_a = xy[a][1]
    x_b = xy[b][0]
    y_b = xy[b][1]
    dist = ((x_a - x_b)**2 + (y_a - y_b)**2)**0.5
    return dist


ans = 0

for i in range(len(road_list)):
    for j in range(len(road_list[i])-1):
        ans += distance(road_list[i][j+1], road_list[i][j])

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

Solution (Python):


def dst(point_a, point_b):
    return ((point_a[0]-point_b[0])**2 + (point_a[1]-point_b[1])**2)**(0.5)
   

def main():
    
    n = int(input()) 
    towns = []
    for _ in range(n):
        x, y = map(int, input().split())
        towns.append((x, y))
    cnt = 0 
    s = 0
    from itertools import permutations
    for i in permutations(towns):
        cnt += 1
        for j in range(n-1):
            s += dst(i[j], i[j+1])

    ans = s/cnt
    print(ans)
main()

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

Solution (Python):
n = int(input())
dis = [list(map(int,input().split())) for _ in range(n)]
ans = 0
num = 0
from itertools import permutations
for path in list(permutations(range(n))):
  num += 1
  path = list(path)
  distance = 0
  for i in range(1,n):
    xi = dis[path[i-1]][0]
    xj = dis[path[i]][0]
    yi = dis[path[i-1]][1]
    yj = dis[path[i]][1]
    distance += (pow(xi-xj,2)+pow(yi-yj,2))**0.5
  ans = ans + distance
ans = ans/num
print(ans)