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



Sample input:
3
0 0
1 0
0 1


Sample output:
2.2761423749

Submission status: Runtime Error

Solution code:
from itertools import permutations
from math import factorial


# メインプログラム
def func(N, lst):

    # N! を求める
    N_fact = factorial(N)

    # lst から座標のすべての組合せを求める。
    perm_grid_xy = permutations(lst)

    # すべての組合せを全探索して、総合距離を計算する
    total_dist = total_distance(N, perm_grid_xy)

    # 平均距離 = 総合距離 / N!
    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))

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

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

ans = ans/n
print(ans)

Submission status: Runtime Error

Solution code:
# import bisect
# import copy
# import fractions
import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product
import statistics as st

def resolve():

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

    total=0
    all=[]
    for i in range(N):
        if i!=N-1:
            all.append(math.sqrt((x[i]-x[i+1])**2+(y[i]-y[i+1])**2))
        else:
            all.append(math.sqrt((x[0]-x[N-1])**2+(y[0]-y[N-1])**2))
            #total+=math.sqrt((x[0]-x[N-1])**2+(y[0]-y[N-1])**2)
    print(sum(all)-st.mean(all))




resolve()

Submission status: Runtime Error

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(input())


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

mat = [[-1 for i in range(n)] for j in range(n)] #二次元の静的確保


def calc_dis(x1, x2, y1, y2):
    dis = pow(x1 - x2, 2) + pow(y1 - y2, 2)
    dis = math.sqrt(dis)


def path_dis(path):
    dis = 0
    for i in range(len(path)-1):
        dis += mat[path[i]][path[i+1]]
    return dis

for i in range(n):
    for j in range(n):
        mat[i][j] = calc_dis(data[i][0], data[i][1], data[j][0], data[j][1])

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

ans = 0
for p in perm:
    tmp_ans = path_dis(p)
    ans += tmp_ans

ans = ans/n
print(ans)

Submission status: Runtime Error

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(input())


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

mat = [[-1 for i in range(n)] for j in range(n)] #二次元の静的確保


def calc_dis(x1, x2, y1, y2):
    dis = pow(x1 - x2, 2) + pow(y1 - y2, 2)
    dis = math.sqrt(dis)


def path_dis(path):
    dis = 0
    for i in range(len(path)-1):
        dis += mat[path[i]][path[i+1]]
    return dis

for i in range(n):
    for j in range(n):
        mat[i][j] = calc_dis(data[i][0], data[i][1], data[j][0], data[j][1])

perm = list(itertools.permutations(n))

ans = 0
for p in perm:
    tmp_ans = path_dis(p)
    ans += tmp_ans

ans = ans/n
print(ans)

Submission status: Runtime Error

Solution code:
def dis(x1, y1, x2, y2):
  d = math.sqrt((x2-x1)**2 + (y2-y1)**2)
  return d

def dfs(visited, x, y, prev, dis, total_dis):
  n = len(x) 
  allCityVisited = True
  for i in range(n):
    if visited[i] is False:
      allCityVisited = False
  if allCityVisited:
    total_dis += dis
    return total_dis
    
  for i in range(n):
    if visited[i] is False:
      dis += dis(x[i], y[i], x[prev], y[prev])
      visited[i] = True
      org_prev = prev
      prev = i
      dfs(visited, x, y, prev, dis, total_dis)
      visited[i] = False
      prev = org_prev
      
  return total_dis

n = int(input())
x = [0]*n
y = [0]*n

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

for i in range(n):
  visited[i] = True
  total_dis += dfs(visited, x, y, i, 0, totala_dis)
  visited[i] = False
  
prem = 1
for i in range(n):
  perm*=n
  
print(total_dis/perm)

Submission status: Runtime Error

Solution code:
import itertools
import math

N = int(input())
town = list(itertools.permutations(range(N)))
dis = []
for i in range(N):
    s = tuple(map(int,input().split()))
    dis.append(s)
    
ans = 0
for i,j,k in town:
    calc = math.sqrt((dis[i][0]-dis[j][0])**2 + (dis[i][1]-dis[j][1])**2 ) + math.sqrt((dis[j][0]-dis[k][0])**2 + (dis[j][1]-dis[k][1])**2 )
    ans += calc
    
ans/len(town)

Submission status: Runtime Error

Solution code:
import itertools
n = int(input())
a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))

l = list(itertools.permutations(range(1,n+1)))

print(abs(l.index(a) - l.index(b)))

Submission status: Runtime Error

Solution code:
import itertools
n = int(input())
a = tuple([int(i) for i in input().split()])
b = tuple([int(i) for i in input().split()])

l = list(itertools.permutations(range(1,n+1)))

print(abs(l.index(a) - l.index(b)))

Submission status: Runtime Error

Solution code:
import itertools
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

l = list(itertools.permutations(range(1,n+1)))

print(abs(l.index(a) - l.index(b)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from itertools import combinations as comb
from math import sqrt
n = int(input())
xy = [[*map(int, input().split())] for _ in range(n)]


s = sum(sqrt((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2) for i,j in comb(range(n), 2))
print(s * 2 / n)

Submission status: Runtime Error

Solution code:
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect
from scipy.special import comb
from scipy.special import perm

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
L = list(itertools.permutations(xy, 2))
num = math.factorial(N-1) / comb(N, 2)
ans = 0
for i in range(N-1):
    for l in range(i+1, N):
        ans += math.sqrt((xy[i][0]-xy[l][0])**2+(xy[i][1]-xy[l][1])**2)
ans *= num
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
import itertools
read = sys.stdin.buffer.read
N = int(input())
XY = np.array(read().split(), np.int64).reshape(-1,2)

ans = 0
for ditour in itertools.permutations(range(N)):
	distance = 0
	for i in range(1,N):
		u = XY[ditour[i]] - XY[ditour[i-1]]
		distance += np.linalg.norm(u)

	ans += distance

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

print(ans)

Submission status: Runtime Error

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

import math
def distance(p1,p2):
  x1,y1 = p1
  x2,y2 = p2
  return math.sprt((x1-x2)**2 + (y1-y2)**2)
  
ans = 0
for i in range(n):
  for j in range(n):
    ans += distance(pos[i],pos[j])
print(ans/n)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
from itertools import permutations

def main():
    N = int(input())
    xy = [tuple(map(int,input().split())) for _ in range(N)]
    answer = 0
    for perm in permutations(list(range(N))):
        all_distance = 0

        for i in range(N-1):
            all_distance += ((perm[i+1][1]-perm[i][1])**2 + (perm[i+1][0]-perm[i][0])**2)**(1/2)

        answer = min(answer,all_distance)
    print(answer)
    return


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import itertools
n=int(input())
A=[]
for i in range(n):
  A.append(list(map(int,input().split())))
  
def kaijo(x):
  if x==1:
    return x
  return x*kaijo(x-1)

def dist(x,y):
  return ((A[x][0]-A[y][0])**2+(A[x][1]-A[y][1])**2)**(1/2)

DIST=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
  for j in range(n):
    DIST[i][j]=dist(i,j)
    
ans=[]   
for Q in itertools.permutations(n):
  t=0
  for i in range(n-1):
    t+=DIST[i][i+1]
  ans.append(t)
print(sum(ans)/kaijo(n))

Submission status: Runtime Error

Solution code:
from math import sqrt


def dis(i, j):
    ret = float((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2)
    return sqrt(ret)


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

p = list(permutations(range(n)))

sums = 0
for i in p:
    for j in range(len(i) - 1):
        sums += dis(xy[i[j]], xy[i[j + 1]])

print(sums / len(p))

Submission status: Runtime Error

Solution code:
n = int(input())
lis = [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 += ((lis[i][0] - lis[j][0]) ** 2 + (lis[i][1] - lis[j][1]) ** 2) ** 0.5

ans *= 2/N
print(ans)

Submission status: Runtime Error

Solution code:
#include <cmath>
#include <iomanip>
#include <iostream>
#define sqr(x) ((x)*(x))

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	int x[8]; int y[8];
	for(int i = 0; i < n; i++)
		cin >> x[i] >> y[i];
	
	double sum = 0;
	for(int i = 0; i < n - 1; i++)
		for(int j = i + 1; j < n; j++)
			sum += sqrt(sqr(x[i]-x[j])+sqr(y[i]-y[j]));
	
	cout << fixed;
	cout << setprecision(10) << sum * 2 / n << endl;
}

Submission status: Runtime Error

Solution code:
mport itertools
import math
N=int(input())
a=[]
kyori_list=[]
for i in range(N):
    x,y=map(int,input().split())
    a.append((x,y))
for j in itertools.permutations(a):
    k=list(j)
    
    cnt=0
    sum=0
    while cnt<N-1:
        kryoi=0
        kyori=((k[cnt+1][0]-k[cnt][0])**2+(k[cnt+1][1]-k[cnt][1])**2)**(1/2)
        cnt+=1
        
        sum+=kyori
    kyori_list.append(sum)
c=0

for i in kyori_list:
    c+=i
    
    
print(c/math.factorial(N))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

total_d=0
for i in range(N):
    for j in range(i):
        total_d+=((X[i][0]-X[j][0])**2+(X[i][1]-X[j][1])**2)**0.5
ans=total_d*2/N
print(ans)

Submission status: Runtime Error

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

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

x1,y1 = [int(s) for s in input().split()]

total_distance = 0
for i in range(1,N):
  x2,y2 = [int(s) for s in input().split()]
  total_distance += distance(x1,x2,y1,y2)
  
print total_distance / N

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools

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

res = 0
cnt = 0
for v in itertools.permutations(x):
  a = numpy.array(v[0])
  b = numpy.array(v[1])
  res += np.linalg.norm(b-a)
  cnt += 1

print((res+0.0)/cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools

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

res = 0
for v in itertools.combinations(x, 2):
  a = numpy.array(v[0])
  b = numpy.array(v[1])
  res += np.linalg.norm(b-a)

print(res)

Submission status: Runtime Error

Solution code:
N=int(input())
dis_list=[list(map(int, input().split())) for  in range(N)]
ans=0
for x1,y1 in dis_list:
  for x2,y2 in dis_list:
    ans += ((x1-x2)**2+(y1-y2)**2)**0.5
print(ans/N)

Submission status: Runtime Error

Solution code:
import pandas as pd
import numpy as np
from itertools import combinations

z = []
N = int(input())
for i in range(N):
    temp_x, temp_y = map(int, input().split())
    z = z + [temp_x] + [temp_y]
z = np.array(z).reshape(N,2)
print(z)

d = 0
count = 0
for j, k in combinations(range(N),2):
    temp_d = np.sqrt((z[j,0] - z[k,0])**2 + (z[j,1] - z[k,1])**2)
    d += temp_d
    count += 1
print(d*(N-1)/count)

Submission status: Runtime Error

Solution code:
n = int(input())
x = []; y = []
for i in range(n):
    x,y = [int(i) for i in input().split() ]
    x.append(x);y.append(y)
s = 0

for i in range(n):
    for j in range(n):
        s += ((x[i]-x[j])**2)+(y[i]-y[j]**2)**.5
print(s/n)

Submission status: Runtime Error

Solution code:
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(input())

def permutation(a, aa=[]):
  if len(a)<=1:
    return [aa+a]

  res = []
  for x in a:
    b = a.copy()
    b.remove(x)
    res.extend(permutation(b, aa+[x]))

  return res


N = readi()
P = [ints() for i in range(N)]

s = 0.0
ps = permutation(list(range(N)))
pn = len(ps)

for p in ps:
  for i in range(N-1):
    q = p[i]
    r = p[i+1]
    s += ((P[q][0]-P[r][0])**2+(P[q][1]-P[r][1])**2)**(0.5)/pn
print(s)

Submission status: Runtime Error

Solution code:
N=int(input())
X=[]
for _ in range(n):
	x,y=map(int,input().split())
	X.append([x,y])
    
ans = []
for i in range(N):
    for j in range(N):
        ans.append(np.sqrt((X[i][0]-X[j][0])**2 + (X[i][1]-X[j][1])**2))

print(sum(ans) / N)

Submission status: Runtime Error

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

ans = []
for i in range(N):
    for j in range(N):
        ans.append(np.sqrt((X[i][0]-X[j][0])**2 + (X[i][1]-X[j][1])**2))

print(sum(ans) / N)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import math
import itertools

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

n = input()
points = {i:input().split() for i in range(n)}

total_distance = 0

for cource in itertools.permutations(range(n)):
    for i in range(1, n):
        total_distance += distance(cource[i-1], cource[i])

print(total_distance/math.factorial(n))

Submission status: Runtime Error

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

sum_dict = 0
#全ての経路の距離の和を求める。
for i in range(N):
    for j in range(i+1,N):
        sum_dict += (x[i] - x[j])**2 - (y[i] - y[j])**2
nkai = 0
#N!の値を求める
for i in range(1,N+1):
    nkai *= i
#平均を求める
ave = sum_dict / nkai
print(ave)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[tuple(map(int,input().split())) for i in range(n)]
ans=0
for i in range(n):
  for j in range(i+1,n):
    ans +=

Submission status: Runtime Error

Solution code:
from math import sqrt 
N = int(input())
k = [[int(i) for i in input().split()] for i in range(N)]
result = 0
for i in range(N):
    for j in range(N):
        if i != j:
            result += sqrt((k[i][0] - k[j][0]) * (k[i][0] - k[j][0]) + k[i][1] - k[j][1]) * (k[i][1] - k[j][1]))
print(result / N)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>


using namespace std;

int main() {

    int N;
    cin >> N;
    vector<double> x(N);
    vector<double> y(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }
    
    double ans = 0;
    do {

        for (int i = 0; i < N-1; i++) {
            double dx = x[i] - x[i+1];
            double dy = y[i] - y[i+1];
            ans += pow(dx * dx + dy * dy, 0.5);
            }

    } while (next_permutation(x.begin(), x.end()));
    
    double factrial = 1;
    for (int i = 2; i <= N; i++) factrial *= i;

    cout << ans / factrial << '\n';

}

Submission status: Runtime Error

Solution code:
import math
 
numofpoints= int(raw_input())
coords=[]
for index in range(numofpoints):
	x,y= map(int, raw_input.split())
    coords.append((x,y))
    
sumofnum=0
c=0
for i in range(numofpoints):
  xi=coords[i][0]
  yi=coords[i][0]
	for j in range(i,numofpoints):
    	xj=coords[j][0]
  		yj=coords[j][0]
        rij = ((xi-xj)**2 + (yi-yj)**2)**0.5
       	sumofnum = sumofnum + rij
        
        
print sumofnum/math.factorial(numofpoints)

Submission status: Runtime Error

Solution code:
numofpoints= int(raw_input())
coords=[]
for index in range(numofpoints):
	x,y= map(int, raw_input.split())
    coords.append((x,y))
    
def factorial(n):
  	if n==0:
      return 1
    else:
		return n*factorial(n-1)

sumofnum=0
c=0
for i in range(numofpoints):
	for j in range(numofpoints):
    	if i!=j:
        	sumofnum+=((coords[i][0]-coords[j][0])**2+(coords[i][1]-coords[j][1])**2)**5
			c+=1
print(sumofnum/c)

Submission status: Runtime Error

Solution code:
numofpoints= int(raw_input())
coords=[]
for index in range(numofpoints):
	x,y= map(int, raw_input.split())
    coords.append((x,y))
    
def factorial(n):
  	if n==0:
      return 1
    else:
		return n*factorial(n-1)

sumofnum=0
c=0
for i in range(numofpoints):
	for j in range(numofpoints):
    	if i!=j:
        	sumofnum+=((coords[i][0]-coords[j][0])**2+(coords[j][1]-coords[j][1])**2)**5
			c+=1
print(sumofnum/c)

Submission status: Runtime Error

Solution code:
numofpoints= int(raw_input())
coords=[]
for index in range(numofpoints):
	x,y= map(int, raw_input.split())
    coords.append((x,y))
    
def factorial(n):
  	if n==0:
      return 1
    else:
		return n*factorial(n-1)

sum=0
for i in range(numofpoints):
	for j in range(numofpoints):
    	if i!=j:
        	sum+=((coords[i][0]-coords[j][0])**2+(coords[j][1]-coords[j][1])**2)**5
print(sum/factorial(n))

Submission status: Runtime Error

Solution code:
numofpoints= int(raw_input())
coords=[]
for index in range(numofpoints):
	x,y= map(int, raw_input.split())
    coords.append(x,y)
    
def factorial(n):
  	if n==0:
      return 1
    else:
		return n*factorial(n-1)

sum=0
for i in range(numofpoints):
	for j in range(numofpoints):
    	if i!=j:
        	sum+=((coords[i][0]+coords[j][0])**2+(coords[j][1]+coords[j][1])**2)**5
print(sum/factorial(n))

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;

double solve(double ans, int here, vector<int> dest, int N, vector<vector<double>> dist){
    double tmp = 0;
    for (int i=0; i<N; i++){
        // here から dest.at(i) への距離
        double d = 0;
        if (here >= 0){
            d = dist.at(here).at(dest.at(i));
        }
        vector<int> new_dest;
        for (int j=0; j<N; j++){
            if (i==j) continue;
            new_dest.push_back(dest.at(j));
        }
        tmp += (d + solve(ans, dest.at(i), new_dest, N-1, dist));
    }
    return ans + tmp;
}

double distance(vector<int> p1, vector<int> p2){
    return sqrt((p2.at(0) - p1.at(0)) * (p2.at(0) - p1.at(0)) + (p2.at(1) - p1.at(1)) * (p2.at(1) - p1.at(1)));
}

int main(){
    int N;
    cin >> N;
    vector<vector<int>> point(N, vector<int> (2));
    for (int i=0; i<N; i++){
        cin >> point.at(i).at(0) >> point.at(i).at(1);
    }
    
    vector<vector<double>> dist(N, vector<double> (N));
    for (int i=0; i<N; i++){
        for (int j=0; j<N; j++){
            if (i==j){
                dist.at(i).at(j) = 0;
            } else{
                dist.at(i).at(j) = distance(point.at(i), point.at(j));
            }
            //cout << dist.at(i).at(j) << endl;
        }
    }
    
    double ans = 0;
    vector<int> dest(N);
    for (int i=0; i<N; i++){
        dest.at(i) = i;
    }
  	ans = solve(ans, -1, dest, N, dist);
    int cnt = 1;
    for (int i=0; i<N; i++){
      cnt *= i+1;
    }
    
    printf("%.10f\n", ans / cnt);
    return 0;
}

Submission status: Runtime Error

Solution code:
from statistics import mean
import itertools
import math

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

pos_comb = itertools.combinations(pos, 2)
dis_list = []
for i in pos_comb:
    dis_list.append(math.sqrt((i[0][0]-i[1][0])**2+(i[0][1]-i[1][1])**2))
print(mean(dis_list)*(float(n)-1.0))

Submission status: Runtime Error

Solution code:
a, b, x = map(int, input().split())

"""にぶたん"""
minim = 0
maxim = 10**9 + 1

while maxim - minim > 1:
    int_ave = (minim + maxim)//2
    if (a*int_ave + b*len(str(int_ave))) > x:
        maxim = int_ave
    else:
        minim = int_ave

print(minim)

Submission status: Runtime Error

Solution code:

def fac(n):
    if n==0 or n==1:
        return 1
    else:
        return n*fac(n-1)
def dis(x1,y1,x2,y2):
    return ((x1-x2)**2 +(y1-y2)**2)**.5
def main():
    t=int(input())
    li=[]
    for i in range(t):
        li1=[float(i) for i in input().split(" ")]
        li.append(li1)
    ans=0.0
    for i in range(t):
        x,y=li[i][0],li[i][1]
        for j in range(i+1,t):
            if i!=j:
                ans+=dis(x,y,li[j][0],li[j][1])
    r=0.0
    r=((t-1)*(2*fac(t-2))*(ans/fac(t)))
    print(f"{r:0.10f}")

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:

def fac(n):
    if n==0 or n==1:
        return 1
    else:
        return n*fac(n-1)
def dis(x1,y1,x2,y2):
    return ((x1-x2)**2 +(y1-y2)**2)**.5
def main():
    t=int(input())
    li=[]
    for i in range(t):
        li1=[int(i) for i in input().split()]
        li.append(li1)
    ans=0.0
    for i in range(t):
        x,y=li[i][0],li[i][1]
        for j in range(i+1,t):
            if i!=j:
                ans+=dis(x,y,li[j][0],li[j][1])
    r=0.0
    r=((t-1)*(2*fac(t-2))*(ans/fac(t)))
    print(f"{r:0.10f}")

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
from math import sqrt
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
result=0
nums=[x for x in range(n)]
for i in nums:
  for j in nums:
    if(i!=j):
      result += sqrt((xy[i][0] - xy[j][0]) * (xy[i][0] - xy[j][0]) + (xy[i][1] - xy[j][1]) * (xy[i][1] - xy[j][1]))
print(result/n)

Submission status: Runtime Error

Solution code:
from itertools import permutations
from functools import reduce
from operator import mul


def solve(string):
    n, *xy = map(int, string.split())
    *xy, = zip(*[iter(xy)] * 2)
    return str(
        sum(
            sum(((xy[p0][0] - xy[p1][0])**2 + (xy[p0][1] - xy[p1][1])**2)**0.5
                for p0, p1 in zip(list(i),
                                  list(i)[1:]))
            for i in permutations(range(n), n)) / reduce(mul, range(1, n + 1)))


if __name__ == '__main__':
    print(solve(input()))

Submission status: Runtime Error

Solution code:
import math
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    xy = [tuple(map(int, input().split())) for _ in range(n)]
    checked = [[None for _ in range(n)] for _ in range(n)]
    sum_v = 0
    p = 1
    for i in range(n):
        p *= i + 1
        for j in range(n):
            if i == j or dis[i][j] is not None:
                continue
            checked[i][j] = 1
            checked[j][i] = 1
            sum_v += math.sqrt((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2)
    print(sum_v * 2 / n)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
N = int(input())
town = [list(map(int, input().split())) for _ in range(N)]
path = []
for p in itertools.permutations(town):
    path.append(sum([math.sqrt((p[i+1][0]-p[i][0])**2 + (p[i+1][1]-p[i][1])**2) for i in range(len(p)-1)]))

print(sum(path)/len(path))

Submission status: Runtime Error

Solution code:
N = int(input())
town = [list(map(int, input().split())) for _ in range(N)]
path = []
for p in itertools.permutations(town):
    path.append(sum([math.sqrt((p[i+1][0]-p[i][0])**2 + (p[i+1][1]-p[i][1])**2) for i in range(len(p)-1)]))

print(sum(path)/len(path))

Submission status: Runtime Error

Solution code:
import math
import itertools

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

li=list(range(N))
co=[]
sum=0

for i in itertools.permutations(li,N):
    co.append(list(i))

for i in range(len(co)):
    for j in range(N-1):
        sum+=((xy[co[i][j]][0]-xy[co[i][j+1]][0])**2+(xy[co[i][j]][1]-xy[co[i][j+1]][1])**2)**(1/2)
print({sum/len(co))

Submission status: Runtime Error

Solution code:
from itertools import permutations
from math import sqrt, pow

n = int(input())
x = []
y = []
for i in range(n):
    m = raw_input().split()
    x.append(int(m[0]))
    y.append(int(m[1]))

l = []
for i in range(n):
    l.append(i)

p = list(permutations(l))
ave = 0
cnt = 0
for i in p:
    j = 0
    while (j < n - 1):
        ave += sqrt(pow(x[i[j]] - x[i[j + 1]], 2) + pow(y[i[j]] - y[i[j + 1]], 2))
        j += 1
    cnt += 1

res = ave / cnt
print(res)

Submission status: Runtime Error

Solution code:
import math
import itertools

n = int(input())

distans = []
tmps = []
for i in range(n):
    x,y = map(int,input().split())
    tmps.append((x - y)**2)

ans = 0
comb = list(itertools.combinations(range(int((n*(n-1))/2)),2))
for k in range(len(comb)):
    distans.append(math.sqrt(tmps[comb[k][0]] + tmps[comb[k][1]]))
    ans += distans[k] * (math.factorial(n)-n+1) 
print(ans/math.factorial(n))

Submission status: Runtime Error

Solution code:
import math

n = int(input())

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

for i in range n-1:
    distans[i] = math.sqrt(tmps[i] + tmps[i+1])
    ans += distans[i] * (math.factorial(n)-1) 

print(ans/math.factorial(n))

Submission status: Runtime Error

Solution code:
n = int(input())

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

def dis(t1, t2):
    x1, y1 = t1
    x2, y2 = t2
    return ((x1- x2)**2 + (y1-y2)**2)**0.5

total_dis = 0

for i in range(0, len(t)):
    t1=t[i]
    for j in range(0, len(t)):
        t2 = t[j]
        total_dis += dis(t1, t2)

ans = (1/n)*total_dis
print(ans)

Submission status: Runtime Error

Solution code:
ソースコード 拡げる

Copy
Copy
import math
import itertools
 
N=int(input())
P=[]
all_dist=[]
 
 
def Len(X,Y):
    return math.sqrt((X[0]-Y[0])**2+(X[1]-Y[1])**2)
 
for _ in range(N):
    a,b=map(int,input().split())
    P.append([a,b])
#print('townmap_is',P)
 
route=list(itertools.permutations(P))
#print(route)
 
for k in range(math.factorial(N)):
    B=0
    A=list(route[k])
    for i in range(len(A)-1):
        B+=Len(A[i],A[i+1])
    all_dist.append(B)
ans=sum(all_dist)/len(all_dist)
 
print(str(ans))

Submission status: Runtime Error

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

l = 0
c = 0

for v in itertools.permutations(xy):
  for i in range(len(v)-1):
    l += ((v[i][0] - v[i+1][0])**2 + v[i][1] - v[i+1][1])**2)**0.5
  c += 1
  
print(l/c)

Submission status: Runtime Error

Solution code:
def get_dist(p1, p2):
    x1, y1 = p1
    x2, y2 = p2
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5

def solve():
    from itertools import combinations
    from math import factorial
    from sys import stdin
    #f_i = stdin
    f_i = open('145_C_s3')#
    
    N = int(f_i.readline())
    points = tuple(tuple(map(int, f_i.readline().split())) for i in range(N))
    s = sum(get_dist(p1, p2) for p1, p2 in combinations(points, 2))
    print(s * 2 / N)

solve()

Submission status: Runtime Error

Solution code:
n=int(input())
for i in range(1,n-1):
	x,y=map(int,input().split())
z=1
f=0
for i in range(1,n-1):
	z=z*i
import math
for i in range(1,n):
	for j in range(i+1,n):
		s=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])
        l=math.sqrt(s)
        f=f+l*z*2
ave=f/(z*n)
print(ave)