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

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


def main():
    sc = Scan()
    n = sc.intarr()[0]
    array = []
    for i in range(n):
        array.append(sc.intarr())
    d_sum = 0
    for i in range(len(array)):
        for j in range(i+1, len(array)):
            distance = math.sqrt(
                (array[i][0] - array[j][0])**2 + (array[i][1] - array[j][1])**2)
            d_sum += distance
    comb = math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))
    ans = d_sum * (n-1) / comb

    print(ans)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()

Solution (Python):
import itertools
import math

n = int(input())
fac = math.factorial(n-1)

ll = [i for i in range(0, n)]
con = list(itertools.combinations(ll, 2))
cnt = len(con)

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

ans = []
for i, j in con:
    ans.append(((ls[i][0] - ls[j][0])**2 + (ls[i][1]-ls[j][1])**2)**0.5)

print(sum(ans)/(n/2))

Solution (Python):
import math
N=int(input())
x=[]
y=[]
M=0
for i in range(0,N):
    F=input()
    [v,s]=list(map(int,F.split(' ')))
    x.append(v)
    y.append(s)
def dis(x,y,x2,y2):
    return math.sqrt((x-x2)**2+(y-y2)**2)
for i in range(0,N):
    for j in range(0,N):
        M=M+dis(x[i],y[i],x[j],y[j])
print(M/N)

Solution (Python):
import itertools
import math

N = int(input())
x = [input().split(" ") for j in range(N)]
ite = [i for i in range(N)]
iterter = list(itertools.permutations(ite,N))

ans = 0
fact = math.factorial(N)

for i in iterter:
    for j in range(len(i) - 1):
        tmp = math.sqrt(((int(x[i[j]][0]) - int(x[i[j + 1]][0])) ** 2) + ((int(x[i[j]][1]) - int(x[i[j + 1]][1]))**2))
        ans += tmp
    
print(ans / fact)

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

import math
import itertools

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

if (N>2):
  ali =[]
  for i in itertools.permutations(XY,N):
    for j in range(N-1):
      ali.append(math.sqrt(((i[j][0] - i[j+1][0])**2)+((i[j][1] - i[j+1][1])**2)))
  print(sum(ali)/math.factorial(N))
else:
  ali = []
  for i in itertools.permutations(XY,2):
    ali.append(math.sqrt(((i[0][0] - i[1][0])**2)+((i[0][1] - i[1][1])**2)))
  print(sum(ali)/math.factorial(N))

Solution (Python):
from math import sqrt 


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

Solution (Python):
import math
import itertools


def fact_list(seq:list):
    return list(itertools.permutations(seq))


def fact_num(n:int):
    seq = list(range(n))
    return len(fact_list(seq))

N = int(input())
n_fact_list = fact_list(list(range(N)))
n_fact_num = fact_num(N)
x, y = [], []
for i in range(N):
    xi, yi = map(int, input().split())
    x.append(xi)
    y.append(yi)

d = 0
for order in n_fact_list:
    for idx, i in enumerate(order[:-1]):
        j = order[idx+1]
        d += (math.sqrt( (x[i]-x[j])**2 + (y[i]-y[j])**2 ))
print(d/n_fact_num)

Solution (Python):
from itertools import combinations, permutations
from math import factorial
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    XY = [tuple(map(int, input().split())) for _ in [0] * N]

    n = list(range(N))
    dist = [[0] * N for _ in [0] * N]
    for i, j in combinations(n, 2):
        dist[i][j] = ((XY[i][0] - XY[j][0]) ** 2 + (XY[i][1] - XY[j][1]) ** 2) ** 0.5
        dist[j][i] = dist[i][j]

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


main()

Solution (Python):
if __name__=='__main__':
    n = int(input())
    x = ['' for i in range(n)]
    y = ['' for i in range(n)]
    length = 0.0
    for i in range(n):
        x[i],y[i]=map(int,input().split())
    for i in range(n-1):
        for j in range(i+1,n):
            length += pow( (x[i]-x[j])**2+(y[i]-y[j])**2, 0.5)
    print(length*2.0/n)

Solution (Python):
import math

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

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

dup = 1
for i in range(n-2):
  if dup == 0:
    dup = 1
  dup *= (i+1)

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

av = tlen / tcase * (dup * (n-1))
print(av)

Solution (Python):
import itertools
import math

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

x,y = [],[]
n = int(input())
for val in range(n):
    x_tmp,y_tmp = map(int,input().split())
    x.append(x_tmp)
    y.append(y_tmp)

comb = list(itertools.combinations(range(n), 2))
zyun = list(itertools.permutations(range(n)))
distance_L = {}


for val in comb:
    tenkan = list(sorted(list(val)))
    a = [x[val[0]],y[val[0]]]
    b = [x[val[1]],y[val[1]]]
    
    distance_L[val] = euclid(a,b)

ans = 0
counter = 0

for i in zyun:
    for j in range(n-1):
        tmp = tuple(sorted(i[j:j+2]))
        
        ans += distance_L[tmp]
    counter += 1

print(ans/counter)

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

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

for i in range(N - 1):
    for j in range(i + 1, N):
        ans += dist(x[i], y[i], x[j], y[j])

ans = ans * 2 / N

print(ans)

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

A = []

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

d = []

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

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

com *= 2

ans = 0
for i in range(len(d)):
    ans += d[i]*com

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

print(ans/M)

Solution (Python):
import math
N=int(input())
List=[list(map(int,input().split())) for i in range(N)]
V=[]
for idx in range(N):
    a=List[idx]
    for idy in range(N):
        if idx == idy:
            continue
        b=List[idy]
        V.append(pow(pow(a[0]-b[0],2) + pow(a[1]-b[1], 2), 1/2))
sum=0
pattern=math.factorial(N)
for i in V:
    sum += i * int(pattern/N)
print(sum/pattern)

Solution (Python):
import math
import itertools

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

kumi = [x for x in range(N)]

def kyori(x1,y1,x2,y2):
    return math.sqrt((y2 - y1)**2 + (x2 - x1)**2)
sum_kyori = 0.0
for i in itertools.permutations(kumi):
    for j in range(N-1):
        sum_kyori += kyori(x[i[j]],y[i[j]],x[i[j+1]],y[i[j+1]])
print( sum_kyori/math.factorial(N))

Solution (Python):
import math


class point():
    def __init__(self, x,y):
        self.x = x
        self.y = y



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


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

Solution (Python):
import math

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

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

def dist(i,j):
    b = ((a[i][1]-a[j][1])**2+(a[i][0]-a[j][0])**2)**0.5
    if b<0:
        print("false")
    return b

sum=0
for i in range(n):
    for j in range(n):
        if j==i:
            pass
        else:
            sum += dist(i,j)

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

Solution (Python):
from itertools import combinations, permutations
import math
N = int(input())
cor = []
for n in range(N):
    X, Y = map(int, input().split())
    cor.append((X, Y))

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

ans = 0
for item in list(permutations([i for i in range(N)], N)):
    for j in range(len(item) - 1):
        ans += dist[item[j]][item[j + 1]]
print(ans / math.factorial(N))

Solution (Python):

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

a = math.factorial(N)
b = a * 2 / N
ans = 0
for i in range(N-1):
    for j in range(i,N):
        m = ((X[i]-X[j])**2 + (Y[i]-Y[j])**2) ** (1/2)
        n = b * m
        ans += n
print(ans/a)

Solution (Python):
import math
n = int(input())
z = []
isum = 0
for _ in range(n):
    z.append(list(map(int, input().split())))

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        else:
            isum += math.factorial(n-1)*math.sqrt((z[i][0] - z[j][0])*(z[i][0] - z[j][0]) + (z[i][1] - z[j][1])*(z[i][1] - z[j][1]))
            

print(isum/math.factorial(n))

Solution (Python):
import math
import copy

n=int(input())
originmap=[] 
while True:
    try:
        originmap.append(list(map(int,input().split())))

    except:
        break;
        

length = 0
submap = originmap.copy()
for i,j in originmap:
  del submap[0]
  for a, b in submap:
    
    
    length += math.sqrt((i-a)**2 + (j-b)**2)

print(length*2/n)

Solution (Python):
from math import factorial

N = int(input())
x = [0 for i in range(N)]
y = [0 for i in range(N)]
for i in range(N):
    x[i], y[i] = map(int, input().split())
ans = 0
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        ans += ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** 0.5
        cnt += 1
print(ans  * (N - 1) / cnt )

Solution (Python):
def A():
    print(int(input())**2)

def B():
    length = int(input())
    s = str(input())
    if length%2 != 0 or s[:length//2]!=s[length//2:]:
        print('No')
    else:
        print('Yes')

import math
def C():
    length = int(input())
    coords = []
    for i in range(length):
        coords.append([int(k) for k in input().split()])
    def dist(p1, p2):
        return math.sqrt((p2[0]-p1[0])**2+(p2[1]-p1[1])**2)

    distances = []
    for i in range(length):
        for j in range(i+1, length):
            distances.append(dist(coords[i], coords[j]))
    
    
    
    m = length*(length-1)/2
    print(sum(distances)/m*(length-1))

C()

Solution (Python):
import math
import itertools
n = int(input())
x = []
y = []
p = []
seq = []
for i in range(n):
    a,b = map(float,input().split())
    x.append(a)
    y.append(b)
    seq.append(i)
p = list(itertools.permutations(seq))
li = []
for s in p:
    l = 0.0
    for i in range(n-1):
        l += math.sqrt((x[s[i]] - x[s[i+1]]) ** 2 + (y[s[i]] - y[s[i+1]]) ** 2)
    li.append(l)
print(sum(li) / len(p))

Solution (Python):
import math, itertools
n = int(input())
def d(a, b):
  return math.sqrt(((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2))
lst = []
for i in range(n):
  x, y = map(int, input().split())
  lst.append([x, y])
ans = 0
for v in itertools.permutations(lst, 2):
  ans += d(v[0], v[1])
print(ans/n)

Solution (Python):
import itertools

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

ret = []
for l in itertools.permutations(list(range(n))):
    tmp = 0
    for i in range(len(l)-1):
        j = l[i]
        k = l[i+1]
        tmp += (((xl[j] - xl[k]) ** 2) + ((yl[j] - yl[k]) ** 2)) ** 0.5
    ret.append(tmp)
print(sum(ret)/len(ret))

Solution (Python):
N = int(input())
x = [0]*N
y = [0]*N
z = [0]*N
for i in range(0,N):
    z[i] = list(map(int, input().split()))
    x[i] = z[i][0]
    y[i] = z[i][1]
sum = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        sum = sum + ((x[i]-x[j])**2+(y[i]-y[j])**2)**(1/2)
ans = sum*2 / N
print(ans)

Solution (Python):
import itertools
from math import factorial

n = int(input())
p = [tuple(map(int, input().split())) for _ in range(n)]
d = list()
for pp in itertools.combinations(p, 2):
    d.append(((pp[0][0] - pp[1][0])**2 + (pp[0][1] - pp[1][1])**2)**0.5)
f = factorial(n)
i = f * (n-1) / len(d)
print(sum(d) * i / f)

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

xList = []
yList = []

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

xsum = sum(xList)
ysum = sum(yList)

sum = 0
for i in range(N):
    isum = 0
    for j in range(N):
        length = ((xList[i]-xList[j])**2 + (yList[i]-yList[j])**2)**0.5
        isum += length
    isum /= N
    sum += isum



print(sum)

Solution (Python):
import math

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


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

summation = 0
for i in range(n):

    for j in range(i+1, n):
        d = dist(L[i], L[j])
        
        summation += d

print(summation * 2 / n)

Solution (Python):
import math as ma

n = int(input())
m = [list(map(int, input().split())) for i in range(n)]
t = [[0 for j in range(n) ] for i in range(n)]
f = [0 for _ in range(n)]
ans = 0

for i in range(n):
    for j in range(n):
        if i == j or t[i][j] > 0:
            pass
        else:
            x = m[i][0] - m[j][0]
            y = m[i][1] - m[j][1]
            l = x**2 + y**2
            t[i][j] = ma.sqrt(l)
            t[j][i] = ma.sqrt(l)
        
        

for i in range(n):
    ans += sum(t[i])

print(ans/n)

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

x = [0]*N
y = [0]*N

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

dist = np.zeros([N, N])
for i in range(N):
    for j in range(N):
        dist[i,j] = np.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)

perm = list(itertools.permutations(range(N)))
num = math.factorial(N)
sum = 0
for i in perm:
    for j in range(len(i)-1):
        sum += dist[i[j], i[j+1]]
print(sum/num)

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

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

sum_ = 0
for v in itertools.permutations(np.arange(n), n):
    for i, j in enumerate(v):
        if i == 0:
            pass
        else:
            sum_ += math.sqrt((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]])) 
    
    

print(sum_ / math.factorial(n))

Solution (Python):
import math

n = int(input())
lis = [0]*n
for i in range(n):
  x,y = map(float,input().split())
  lis[i] = [x,y]
ans = 0
for i in range(n):
  for j in range(i+1,n):
    ans += ((lis[i][0]-lis[j][0])**2+(lis[i][1]-lis[j][1])**2)**0.5

a = 2*ans/n
print(a)

Solution (Python):
N=int(input())
L=[]
for i in range(N):
  L.append(list(map(int,input().split())))
def distance(a,b):
  import math
  return math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)
dist=0
for i in range(N-1):
  for j in range(i+1,N):
    dist+=distance(L[i],L[j])
if N==2:
  print(dist)
else:
  print(dist*2/N)

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

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

av = float(sum) / ( n / 2 )
print(av)

Solution (Python):
import math

n = int(input())
a = math.factorial(n)
b = (a*(n-1))/(n*(n-1)/2)
l=0

x_list = []
y_list = []

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

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

print(l*b/a)

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

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

ave = 0
jun = permutations(range(n))
for j in jun:
    
    sm = 0
    for i in range(n-1):
        x, y = xy[j[i]]
        nx, ny = xy[j[i+1]]
        
        sm += ((x-nx)**2 + (y-ny)**2)**0.5
    ave += sm
print(ave/factorial(n))

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

m = 1
for i in range(1, n+1):
    m *= i
total = 0
for p in itertools.permutations(list(range(n)), n):
    for i in range(1, n):
        total += ((xy[p[i]][0] - xy[p[i-1]][0]) ** 2 + (xy[p[i-1]][1] - xy[p[i]][1]) ** 2) ** 0.5
print(total / m)

Solution (Python):
import os, sys, re, math

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

s = 0
for i in range(N):
    for j in range(N):
        if i != j:
            tmp = (root[i][0] - root[j][0]) ** 2 + (root[i][1] - root[j][1]) ** 2
            s += math.sqrt(tmp)

ret = s / N
print(ret)

Solution (Python):
import sys
import math

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

main()

Solution (Python):
import math

import itertools
N = int(input())
x = []
y = []
for i in range(N):
    s1,s2 = map(int,input().split())
    x.append(s1)
    y.append(s2)
    
def length(i,j):
    return math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)

LI = [i for i in range(N)]
A = list(itertools.permutations(LI))
ans = 0
for item in A:

    count = 0
    for i in range(len(item)):
        if i == len(item)-1:
            break

        ans = ans+length(item[count],item[count+1])
        count +=1
print(ans/math.factorial(N))

Solution (Python):
import sys
input = sys.stdin.readline
import math
import itertools
def distance(N, ar):
    table = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if i != j:
                dx = ar[i][0] - ar[j][0]
                dy = ar[i][1] - ar[j][1]
                table[i][j] = math.sqrt(dx * dx + dy * dy)
    return table    

def print_ans(N, ar):
    """Test Case
    >>> print_ans(3, [[0, 0],[1, 0],[0, 1]])
    2.2761423749
    >>> print_ans(2, [[-879, 981], [-866, 890]])
    91.9238815543
    >>> print_ans(8, [[-406, 10],[512, 859],[494, 362],[-955, -475],[128, 553],[-986, -885],[763, 77],[449, 310]])
    7641.9817824387
    """
    fac = math.factorial(N)
    perm_list = list(itertools.permutations(range(N) ) )
    table = distance(N, ar)
    dist = 0
    for perm in perm_list:
        for i in range(len(perm) -1):
            dist += table[perm[i]][perm[i+1]]
    print(dist/fac)


if __name__ == '__main__':
    N = int(input().rstrip())
    ar = [list(map(int, input().rstrip().split())) for _ in range(N)]
    print_ans(N, ar)

Solution (Python):
import numpy as np
import math
N = int(input())
L = []
for _ in range(N):
    temp = list(map(int,input().split()))
    L.append(np.array(temp))
A = []
for i in range(N-1):
    for j in range(i+1,N):
        u = L[i] - L[j]
        A.append(2*math.factorial(N-1)*(np.linalg.norm(u)))
A = np.array(A)
print(np.sum(A)/math.factorial(N))

Solution (Python):
n = int(input())
x = list()
y = list()
l = 0
t = 0

for i in range(n):
    m = list(map(int,input().split()))
    x.append(m[0])
    y.append(m[1])
    
for i in range(n - 1):
    for j in range(n - 1 - i):
        l_0 = (((x[i] - x[j + i + 1]) ** 2) + ((y[i] - y[j + i + 1]) ** 2)) ** (1 / 2)
        l += l_0

for i in range(n - 1):
    t += i + 1
    
print((n - 1) * l / t)

Solution (Python):
import itertools
n = int(input())
li = [list(map(int, input().split())) for i in range(n)]
li_p = list(itertools.permutations(li, n))
li_a = []
for x in li_p:
  a = 0
  for i in range(n-1):
    a += ((x[i][0]-x[i+1][0])**2 + (x[i][1]-x[i+1][1])**2)**(1/2)
  li_a.append(a)
print(sum(li_a)/len(li_a))

Solution (Python):
import math

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

for i in range(N):
  List.append(list(map(int,input().split())))
  
tot = 0

for m in range(N):
  for n in range(N):
    tot += math.sqrt((List[m][0]-List[n][0])**2+(List[m][1]-List[n][1])**2)

print(tot/N)

Solution (Python):
import math
def cal(x1, y1, x2, y2):
    return math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))

N = int(input())
x = []
y = []
for i in range(N):
    tempx, tempy = map(int,input().split())
    x.append(tempx)
    y.append(tempy)
acc = 0
kaijou = 1

for i in range(1, N+1):
    kaijou *= i
num_use = kaijou*(N-1) / (N*(N-1)/2)
for i in range(N):
    for j in range(i+1, N):
        val = cal(x[i], y[i], x[j], y[j])
        acc += val*num_use
print(str(acc/kaijou))

Solution (Python):
num = int(input())

x = [0]*num
y = [0]*num

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

sol_n = 1
for n in range(num):
    sol_n *= (n+1)

sol = [0]*sol_n

sum_l = 0.0

for n in range(num):
    for m in range(num):
        if(n != m):
            sum_l += ((x[n] - x[m])**2 + (y[n] - y[m])**2)**(1/2)
print(sum_l / (num))

Solution (Python):

import math


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

    for i in range(n):
        pos.append(list(map(int, input().split(' '))))
    
    sum_ = 0
    for i in range(n):
        first = pos[i]
        for j in range(n):
            if j == i:
                continue
            x = (first[0] - pos[j][0])**2
            y = (first[1] - pos[j][1])**2
            d = (x + y)**0.5
            sum_ += d
    print(sum_/n)
    

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
import itertools as it
n = int(input())
x = []
y = []
for _ in range(n):
    a, b = input().split(' ')
    x.append(int(a))
    y.append(int(b))


def f(xi, xj, yi, yj):
    return np.sqrt((xi - xj)**2 + (yi - yj)**2)


n_l = list(range(n))

l = list(it.permutations(n_l))

count = 0

for i in set(l):
    i = list(i)
    for j in range(n - 1):
        a = i[j]
        b = i[j + 1]
        count += f(x[a], x[b], y[a], y[b])

print(count / len(l))

Solution (Python):
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi, factorial
from copy import deepcopy




def main():
    N = int(input())
    xxyy = [tuple(map(int, input().split())) for _ in range(N)]
    ssum = 0
    for a,b in combinations(xxyy,2):
        
        dx = (a[0] - b[0])**2
        dy = (a[1] - b[1])**2
        tmp = sqrt(dx+dy)
        
        ssum += tmp
    
    
    print(ssum*2/N)

if __name__ == '__main__':
    main()

Solution (Python):
import math

def dist(point1, point2):
	distance = math.sqrt((point1[0]-point2[0])**2+(point1[1]-point2[1])**2)
	return distance

n = int(input())

point=[] 
while True:
    try:
        point.append(list(map(int,input().split())))
    except:
        break;


kyori = 0
for i in range(n):
	for j in range(n):
		if(i!=j):
			kyori += dist(point[i],point[j])

print(kyori/n)

Solution (Python):
import math

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

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)


k = sum * 2 * (n - 1) / math.factorial(n)

print(sum*2/n)

Solution (Python):

import itertools

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

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



route_list = list(itertools.permutations(map_list, n))

dist_sum = 0

for route in route_list:
    for i in range(n-1):
        dist = detect_dist(route[i], route[i+1])
        dist_sum += dist

print(dist_sum/len(route_list))

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

def min_start(a, b):
    if a < b:
        return b, a
    return a, b

def main():
    N = int(input())
    point = list()
    length = list()
    for _ in range(N):
        point.append([int(x) for x in input().split()])
    point = np.array(point)

    for a in range(N):
        temp = list()
        for b in range(a, N):
            temp.append(np.linalg.norm(point[b]-point[a]))
        length.append(temp.copy())
    ans = 0
    for route in itertools.permutations([x for x in range(N)]):
        temp = 0
        for i in range(1, N):
            a = route[i - i]
            b = route[i]
            if a > b:
                ans += length[b][a-b]
            else:
                ans += length[a][b-a]
            
    print(ans / math.factorial(N))

if __name__ == "__main__":
    main()

Solution (Python):
import math
import itertools
n = int(input())
pos_lis = []
for i in range(n):
  x, y = map(int,input().split())
  pos_lis.append({'pos':(x,y)})
for k in range(n-1):
  x1 = pos_lis[k]['pos'][0]
  y1 = pos_lis[k]['pos'][1]
  for l in range(k+1,n):
    x2 = pos_lis[l]['pos'][0]
    y2 = pos_lis[l]['pos'][1]
    leng = math.sqrt((x1-x2)**2 + (y1-y2)**2)
    pos_lis[k][l] = leng
    pos_lis[l][k] = leng
numbers = list(range(n))
p = list(itertools.permutations(numbers, n))
len_sum = []
for j in range(len(p)):
	len_sum.append(sum([pos_lis[p[j][t]][p[j][t+1]] for t in range(n-1)]))
ans = sum(len_sum) / len(p)
print(ans)

Solution (Python):
import itertools
import math
N = int(input())
S = [list(map(int, input().split())) for i in range(N)]
perm = list(itertools.permutations([i for i in range(1, N + 1)]))

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

print(sum_d / len(perm))

Solution (Python):
import math
import itertools
def r(retu,N):
    first=retu[0]
    length=0
    n=0
    for i in retu:
        if n==0:
            n+=1
            continue
        length+=math.sqrt((i[0]-first[0])**2+(i[1]-first[1])**2)
        first=i

    
    return length

N=int(input())
S=[[int(i) for i in input().split()] for i in range(N)]
K=[]
kumi=0
for i in itertools.permutations(S):
    length=r(i,N)
    K.append(length)
    kumi+=1

print(sum(K)/kumi)

Solution (Python):
n=int(input())
x=[]
y=[]
t=float(0)
m=int(0)
for i in range(n):
    a, b = map(int, input().split())
    x.append(a)
    y.append(b)

for i in range(n-1):

    for k in range(i+1, n):
        t += (((x[i]-x[k])**2) + ((y[i]-y[k])**2))**(1/2)
        m +=1


ave=float(t/m*(n-1))

print('{:.9g}'.format(ave))

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

q = 1
for j in range(n):
    q *= (j+1)

ans = 0
for k in range(n):
    for l in range(n):
        c = (y[k][0] - y[l][0]) ** 2 + (y[k][1] - y[l][1]) ** 2
        d = math.sqrt(c)
        ans += d


print(ans / n)

Solution (Python):
import math

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

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

distanceSum = 0
for i in range(len(towns)):
  for j in range(i + 1, len(towns)):
    distanceSum += distance(towns[i], towns[j])

print(distanceSum * (math.factorial(n- 1) * 2) / math.factorial(n))

Solution (Python):
import math


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

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

    d = 0
    for i in range(N):
        for j in range(i, N):
            d += calc(x[i], x[j])

    N_fac = math.factorial(N)
    a = 0 if N < 2 else math.factorial(N-2) * (N-1) * 2

    print(d * a / N_fac)


averageLength()

Solution (Python):
import itertools

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

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

d = {}

for i in range(n):
	for j in range(n):
		d[(i, j)] = calc_dist(cities[i], cities[j])

ans = 0
cnt = 0
for x in itertools.permutations(range(n)):
	cnt += 1
	for i in range(n - 1):
		ans += calc_dist(cities[x[i + 1]], cities[x[i]])
	
print(ans / cnt)

Solution (Python):
N = int(input())
inputbox =[0]*N
X = [0]*N
Y = [0]*N
for i in range(0,N):
    inputbox[i] = input()

for j in range(N):
    a = inputbox[j]
    b = a.split()
    X[j]=float(b[0])
    Y[j]=float(b[1])

sum = 0
for s in range (N):
    for t in range (N):
        kyori = ((X[s]-X[t])**2+(Y[s]-Y[t])**2)**(1/2)
        sum = sum + kyori
ans = sum/N
print(ans)

Solution (Python):
def kai(a):
    if a == 1:
        return 1
    else:
        return a*kai(a-1)

def L(i, j, x, y):
    return ((x[i] - x[j])**2 + (y[i] - y[j])**2)**0.5

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

for X in range(N):
    for Y in range(N):
        if X <= Y:
            continue
        else:
            l += L(X, Y, x, y)
           

bi = ((N - 1) * k)/((N * (N - 1))/2)



print((l * bi)/k)

Solution (Python):
import itertools
import math

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

res = 0
for i in list(itertools.permutations(list(range(n)))):
    for j in range(len(i)-1):
        x1 = xy[i[j]][0]
        y1 = xy[i[j]][1]
        x2 = xy[i[j+1]][0]
        y2 = xy[i[j+1]][1]
        res += math.sqrt((x1-x2)**2 + (y1-y2)**2)

res /= math.factorial(n)

print(res)