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:
N = int(input())
n=[]
s=range(N)
for i in range(N):
    n.append([int(x) for x in input().split()])
Q = list(itertools.permutations(s))
L=0
for i in range(int(len(Q)/2)):
    for j in range(N-1):
        L+= np.sqrt((n[Q[i][j+1]][0] - n[Q[i][j]][0])**2 + (n[Q[i][j+1]][1] - n[Q[i][j]][1])**2)
print(L/(len(Q)/2))

Submission status: Runtime Error

Solution code:
N = int(input())
 
xy = []
for _ in range (N):
  x, y = map(int, input().split())
  xy = xy.append([x, y])
 
nu = 0
for i in range (N):
  for j in range (i,N):
    nu += ((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2)**0.5
    
answer = nu * (2/N)
 
print(answer)

Submission status: Runtime Error

Solution code:
N = int(input())

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

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

print(answer)

Submission status: Runtime Error

Solution code:
N = int(input())

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

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

print(answer)

Submission status: Runtime Error

Solution code:
import sys
import math
from typing import List, Tuple


def len(lhs: Tuple[int, int], rhs: Tuple[int, int]):
    return math.sqrt((lhs[0] - rhs[0]) ** 2 + (lhs[1] - rhs[1]) ** 2)


def solve(n: int, cities: List[Tuple[int, int]]):
    sum = 0
    for i1, city1 in enumerate(cities):
        for i2, city2 in enumerate(cities):
            if i1 != i2:
                sum += len(city1, city2)
    return sum / n


def main():
    inputs = list(sys.stdin)
    n = int(inputs.pop(0))
    cities = [[int(n) for n in s.split(" ")] for s in inputs]
    print(solve(n, cities))


main()

Submission status: Runtime Error

Solution code:
import itertools
import math

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

pattern_list = list(itertools.permutations(town_list, n))

a = int(math.factorial(n))

sum = 0
for j in range(a):
	for k in range(n-1):
		x1 = pattern_list[j][k][0]
		x2 = pattern_list[j][k+1][0]
		y1 = pattern_list[j][k][1]
		y2 = pattern_list[j][k+1][1]
		sum += math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)

print(sum/a)

Submission status: Runtime Error

Solution code:
import math
n=int(input())
out=0
x,y=int[n]
x[1],y[1]=list(map(int,input().spilt()))
for i in range(2,n):
  x,y=list(map(int,input().spilt()))
  for j in range(i,1,-1):
    if i==j:continue
    else:out+=math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)

print(out/n)

Submission status: Runtime Error

Solution code:
x,y = list(map(int,input().split()))

mod = 10**9 + 7

# import math
# def comb(n,r):
#     return (math.factorial(n)//(math.factorial(n-r)*math.factorial(r)))

def comb(n,r,mod):
	'''
	return nCr
	O(min{n-r, r})
	'''
	a=1
	b=1
	r = min(r,n-r)
	for i in range(r):
		a = a*(n-i)%mod
		b = b*(i+1)%mod
	return a*pow(b,mod-2,mod)%mod

if (x+y)%3!=0:
    print(0)
    exit()
else:
    n = (2/3)*x - (1/3)*y
    m = (2/3)*y - (1/3)*x
    if n>=0 and m>=0:
        print(comb(int(n+m),int(m),mod))
        exit()
    else:
        print(0)
        exit()

Submission status: Runtime Error

Solution code:
import math
n=int(input())
out=0
x,y=int[n]
x[1],y[1]=list(map(int,input().spilt()))
for i in range(2,n):
  x,y=list(map(int,input().spilt()))
  for j in range(i,1,-1):
    if i==j:continue
    else:out+=math.sqrt((x[i]-x[j])^2+(y[i]-y[j])^2)

print(out/n)

Submission status: Runtime Error

Solution code:
import math
n=int(input())
out=0
x,y=int[n]
x[1],y[1]=input().spilt()
for i in range(2,n):
  x,y=input().spilt()
  for j in range(i,1,-1):
    if i==j:continue
    else:out+=math.sqrt((x[i]-x[j])^2+(y[i]-y[j])^2)

print(out/n)

Submission status: Runtime Error

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

k=0
for i in range(N):
    for j in range(N):
        if(i!=j):
            k=k+((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]))**0.5

print(k/N)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

double x[1000], y[1000];
double sol = 0, fn = 1;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> x[i] >> y[i];
        fn *= double(i + 1);
    }
    for (int i = 0; i < n; ++i)
    {
        
        for (int j = 0; j < n; ++j)
            if (i != j)
                sol += hypot(x[i] - x[j], y[i] - y[j]);
    }
    cout << sol / n;
}

Submission status: Runtime Error

Solution code:
n=int(input())
s=[list(map(int,list(input().split()))) for i in range(n)]  # 二次元配列入力　二次元マップみたいな入力のとき

import math
from functools import lru_cache

@lru_cache(maxsize=100000)
def calc_distance(a, b):
    tmp = (a[0]-b[0])**2 + (a[1]-b[1])**2
    return math.sqrt(tmp)


import itertools
sum = 0
for all in itertools.permutations(s, 3):
    for i in range(n-1):
        # tupleにすることで、lru_cacheを使用可能にする．
        # listはハッシュ出来ないが、tupleはハッシュ可能．
        sum += calc_distance(tuple(all[i]), tuple(all[i+1])) 

kaizyo = math.factorial(n)
# print("sum:", sum)
# print("kaizyo:", kaizyo)

print(sum/kaizyo)

Submission status: Runtime Error

Solution code:
# C - Average Length

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

####

import math
import statistics
import itertools

table = [[0]*N for i in range(N)]
for i in range(N):
    ti = arr[i]
    for j in range(N):
        tj = arr[j]
        dist = math.sqrt((ti[0] - tj[0])**2 + (ti[1] - tj[1])**2)
        #print(i, j, ti, tj, dist)
        table[i][j] = dist

#print(table)

kumi_all = list(itertools.permutations(range(N)))
kumi_all_count = len(kumi_all)

total_dist = 0

for i in range(kumi_all_count):
    this_dist = 0
    this_kumi = kumi_all[i]

    for j in range(N-1):
        this_dist += table[this_kumi[j]][this_kumi[j+1]]

    #print("{}: {}".format(i, this_dist))
    total_dist += this_dist

#print(total_dist, stop_loop)
avr_dist = total_dist / stop_loop

print(avr_dist)

Submission status: Runtime Error

Solution code:
import math
from itertools import permutations
#　　　　　　　　　　　　　　↑
#こいつはリストなどのイテレータを渡すと勝手に考えられるすべての並びの順列を作ってくれるすごい奴


def distance(a,b):
	#2点間の距離を返す関数。
    print(a)
    print(b)
    return math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)
 j in range(1,len(l j in range(1,len(lst)):
			counter += func(lst[i],lst[j])
	return counter

def meta_all_distance(lst,func):
	#最初は「all_distanceだけでいけるじゃん！」と思っていたが
    #all_distanceで計算できるのは「ひとつの移動経路の移動距離合計」であって
    #問題を解くには「考えられるすべての移動経路の移動距離の合計」を出さなくてはいけないと気付き
    #急遽作られたクッソ無様な高階関数の高階関数
    counter = 0
    for i in lst:
        counter += all_distance(i,distance)
    return counter

#実行部分　
n = int(input())
point_lst = []
for _ in range(n):
  point_lst.append(list(map(int,input().split())))
  #受け取った点の座標は文字列なので、空白文字で分割して、
  #分割した各要素をint化して、とりあえずリストにして格納している




p = list(permutations(point_lst))
count = meta_all_distance(p,all_distance)
print(count/math.factorial(n))st)):
			counter += func(lst[i],lst[j])
	return counter

def meta_all_distance(lst,func):
	#最初は「all_distanceだけでいけるじゃん！」と思っていたが
    #all_distanceで計算できるのは「ひとつの移動経路の移動距離合計」であって
    #問題を解くには「考えられるすべての移動経路の移動距離の合計」を出さなくてはいけないと気付き
    #急遽作られたクッソ無様な高階関数の高階関数
    counter = 0
    for i in lst:
        counter += all_distance(i,distance)
    return counter

#実行部分　
n = int(input())
point_lst = []
for _ in range(n):
  point_lst.append(list(map(int,input().split())))
  #受け取った点の座標は文字列なので、空白文字で分割して、
  #分割した各要素をint化して、とりあえずリストにして格納している




p = list(permutations(point_lst))
count = meta_all_distance(p,all_distance)
print(count/math.factorial(n))


def all_distance(lst,func=distance):
  	#座標のリスト（移動経路）を渡すと第二引数の関数（今回はdistanceなので二点間の距離）を
    #合計して返してくれる関数。関数の引数に関数を渡す高階関数を使ってみたかった。
	counter = 0
	for i in range(0,len(lst)-1):
		for j in range(1,len(lst)):
			counter += func(lst[i],lst[j])
	return counter

def meta_all_distance(lst,func):
	#最初は「all_distanceだけでいけるじゃん！」と思っていたが
    #all_distanceで計算できるのは「ひとつの移動経路の移動距離合計」であって
    #問題を解くには「考えられるすべての移動経路の移動距離の合計」を出さなくてはいけないと気付き
    #急遽作られたクッソ無様な高階関数の高階関数
    counter = 0
    for i in lst:
        counter += all_distance(i,distance)
    return counter

#実行部分　
n = int(input())
point_lst = []
for _ in range(n):
  point_lst.append(list(map(int,input().split())))
  #受け取った点の座標は文字列なので、空白文字で分割して、
  #分割した各要素をint化して、とりあえずリストにして格納している




p = list(permutations(point_lst))
count = meta_all_distance(p,all_distance)
print(count/math.factorial(n))

Submission status: Runtime Error

Solution code:
import math
from itertools import permutations

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

def all_distance(lst,func):
	counter = 0
	for i in range(0,len(lst)-1):
		for j in range(1,len(lst)):
			counter += func(lst[i],lst[j])
	return counter

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

p = permutations(point_lst)
count = all_distance(p,distance)
print(counte/n)

Submission status: Runtime Error

Solution code:
from itertools import permutations as perm
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
XY = np.array(read().split(), np.int64)
X = XY[0::2]
Y = XY[1::2]

res = 0
cnt = 0
for p in perm(range(N)):
    for i in range(N - 1):
        res += math.sqrt((X[p[i + 1]] - X[p[i]])**2 + (Y[p[i + 1]] - Y[p[i]])**2)
    cnt += 1    
print(res/cnt)

Submission status: Runtime Error

Solution code:
n=int(input())
x,y=[int(input()) for _ in range(n)],[int(input()) for _ in range(n)]
d=0
for i,j in zip(x,y):
  for k,l in zip(x,y):
    m1,m2=i-k,j-l
    o=m1**2+m2**2
    d+=o**0.5
print(d/n)

Submission status: Runtime Error

Solution code:
n=int(input())
x,y=[int(input()) for _ in range(int(input()))],[int(input()) for _ in range(int(input()))]
d=0
for i,j in zip(x,y):
  for k,l in zip(x,y):
    m1,m2=i-k,j-l
    o=m1**2+m2**2
    d+=o**0.5
print(d/n)

Submission status: Runtime Error

Solution code:
n=int(input())
x,y=[int(input()) for _ in range(int(input()))],[int(input()) for _ in range(int(input()))]
d=0
for i,j in zip(x,y):
  for k,l in zip(x,y):
    m=(i-k)**2+(j-l)**2
    d+=m**0.5
print(d/n)

Submission status: Runtime Error

Solution code:
n=int(input())
x,y=[int(input) for _ in range(int(input()))],[int(input) for _ in range(int(input()))]
d=0
for i,j in zip(x,y):
  for k,l in zip(x,y):
    m=(i-k)**2+(j-l)**2
    d+=m**0.5
print(d/n)

Submission status: Runtime Error

Solution code:
import math

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

Submission status: Runtime Error

Solution code:
import math

N = int(input())
xy_list = [0] * N
for i in range(N):
    xy_list.append(input().split())
result = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        city1 = math.pow(xy_list[i][0] - xy_list[j][0], 2)
        city2 = math.pow(xy_list[i][1] - xy_list[j][1], 2)
        result += math.sqrt(city1 + city2)
print("{:.10f}".format(result / N))

Submission status: Runtime Error

Solution code:
import math

N = int(input())
xy_list = [0] * N
for i in range(N):
    xy_list.append(input().split())
result = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        city1 = math.pow(xy_list[i][0] - xy_list[j][0], 2)
        city2 = math.pow(xy_list[i][1] - xy_list[j][1], 2)
        result += math.sqrt(city1 + city2)
print(result / N)

Submission status: Runtime Error

Solution code:
import math
2
from math import sqrt
3
​
4
n=int(input())
5
N=math.factorial(n)
6
s=[]
7
for l in range(n):
8
  s.append(list(map(int,input().split())))
9
​
10
total=0  
11
for i in range(n-1):
12
    r = sqrt((s[i][0]-s[i+1][0])**2+(s[i][1]-s[i+1][1])**2)
13
    total+=r
14
print(total/2)

Submission status: Runtime Error

Solution code:
n = int(input())

xy = [input().split() for i in range(n)]
s = 0
for i in range(n):
    for j in range(i+1, n):
        s += ((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)**0.5
print(s*2/n)

Submission status: Runtime Error

Solution code:
n = int(input())

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

Submission status: Runtime Error

Solution code:
N = int(input())
for _ in range(N):
    x, y = map(int, input().split(" "))
dis = 0
for i in range(N):
    for j in range(N):
        dis = dis + ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** 0.5
import math
average = dis / math.factorial(N)
print(average)

Submission status: Runtime Error

Solution code:
N = int(input())
for _ in range(N):
    x, y = map(int, input().split(" "))
dis = 0
for i in range(N):
    for j in range(N):
        dis = dis + ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** 0.5
average = dis * 2 / math.factorial(N)
print(average)

Submission status: Runtime Error

Solution code:
N = int(input())
for _ in range(N):
    x, y = map(int, input().split(" "))
dis = 0
for i in range(N):
    for j in range(N):
        dis = dis + ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** 0.5
average = dis / math.factorial(N)
print(average)

Submission status: Runtime Error

Solution code:
N=int(input("2<=N<=8"))
sum=0
listx=[]
listy=[]
for i in range(N):
  x=int(input())
  y=int(input())
  listx.append(x)
  listy.append(y)
print(listx,listy)
for j in range(N):
  for k in range(j+1,N):
    sum=sum+((listx[j]-listx[k])**2+(listy[j]-listy[k])**2)**(1/2)
answer=sum*(2/N)
print(answer)

Submission status: Runtime Error

Solution code:
N=int(input("2<=N<=8"))
sum=0
prex=0
prey=0
for i in range(N):
  x=int(input("integer x"))
  y=int(input("integer y"))
  sum=sum+((x-prex)**2+(y-prey)**2)**(1/2)
  prex=x
  prey=y
ave=sum/N
print(ave)

Submission status: Runtime Error

Solution code:
import numpy as np
def kyori(x1,y1,x2,y2):
    dis = ((x1-x2)**2+(y1-y2)**2)**0.5
    return dis
N = int(input())
xy = []
for n in range(N):
    xy.append(list(map(int, input().split())))
diss = np.zeros(N)
for i in range(N-1):
    for j in range(i+1,N):
        diss[i+j-1] = kyori(xy[i][0],xy[i][1],xy[j][0],xy[j][1])
print(np.average(np.sum(diss) - diss))

Submission status: Runtime Error

Solution code:
N=int(input())
##c=list(map(int, input().split()))
a={}
b={}
for i in range(N):
    a[i]=int(input())
    b[i]=int(input())

k=float(0)
for i in range(N-1):
    for j in range(i+1,N-i-1):
        k=k+((a[i]-a[j])**2+(b[i]-b[j])**2)**0.5

k=float(k*2/N)
print(k)

Submission status: Runtime Error

Solution code:
N=int(input())
##c=list(map(int, input().split()))
a={}
b={}
for i in range(N):
    a.append(int(input()))
    b.append(int(input()))
k=float(0)
for i in range(N-1):
    for j in range(i,N):
        k=k+((a[i]-a[j])**2+(b[i]-b[j])**2)**0.5

k=float(k*2/N)
print(k)

Submission status: Runtime Error

Solution code:
N=int(input())
##c=list(map(int, input().split()))
a=[]
b=[]
for i in range(N):
    a.append(int(input()))
    b.append(int(input()))
k=float(0)
for i in range(N-1):
    for j in range(i,N):
        k=k+((a[i]-a[j])**2+(b[i]-b[j])**2)**0.5

k=float(k*2/N)
print(k)

Submission status: Runtime Error

Solution code:
import math
##(A,B,C,D)=map(int,input().split())

N=int(input())
##c=list(map(int, input().split()))


a=[]
b=[]


for i in range(N):
    a.append(int(input()))
    b.append(int(input()))
k=float(0)
for i in range(N-1):
    for j in range(i,N):
        k=k+float(((a[i]-a[j])**2+(b[i]+b[j])**2)**0.5)

k=float(k*2/N)
print(k)

Submission status: Runtime Error

Solution code:
import math
##(A,B,C,D)=map(int,input().split())

N=int(input())
##c=list(map(int, input().split()))

a=[]
b=[]


for i in range(N):
    a.append(int(input()))
    b.append(int(input()))
k=float(0)
for i in range(N-1):
    for j in range(i,N):
        k=k+float(((a[i]-a[j])**2+(b[i]+b[j])**2)**0.5)

k=float(k*2/N)
print(k)

Submission status: Runtime Error

Solution code:
import math
##(A,B,C,D)=map(int,input().split())

N=int(input())
##c=list(map(int, input().split()))


a=[]
b=[]

for i in range(N):
    a.append(input())
    b.append(input())
k=float(0)
for i in range(N-1):
    for j in range(i,N):
        k=k+float(math.sqrt(abs(a[i]-a[j])+abs(b[i]+b[j])))

k=float(k*2/N)
print(k)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
pl = list()
for i in range(n):
    pl.append(list(map(int, input().split())))

import math
lsum = 0
for i in range(n):
    for j in range(n):
        if i != j:
            a, b = pl[i]
            c, d = pl[j]
            lsum += math.sqrt((a-c) ** 2 + (b-d) ** 2)
print(lsum /(n)

Submission status: Runtime Error

Solution code:
n = int(input())
pl = list()
for i in range(n):
    pl.append(list(map(int, input().split())))

import math
lsum = 0
for i in range(n):
    for j in range(n):
        if i != j:
            a, b = pl[i]
            c, d = pl[j]
            lsum += math.sqrt((a-c) ** 2 + (b-d) ** 2)
print(lsum /(2 * n)

Submission status: Runtime Error

Solution code:
import math
N= int(input())
x=[0]*N
y=[0]*N
for i in range(N):
  X[i]=int(input())
  y[i]=int(input())
S = 0
nb =0
for i in range(N) :
  for j in range(0, i) :
    S += math.sqrt( (x[i]-x[j])**2 + (y[i]-y[j])**2 )
    nb += 1
print(S/nb*(nb-1))

Submission status: Runtime Error

Solution code:
import math
N= int(input())
x=[0]*N
y=[0]*N
for i in range(N):
  X[i]=int(input())
  y[i]=int(input())
S = 0
nb =0
for i in range(N) :
  for j in range(0, i) :
    S += math.sqrt( (x[i]-x[j])**2 + (y[i]-y[j])**2 )
    nb += 1
print(S/nb)

Submission status: Runtime Error

Solution code:
import math
import itertools

def all_combination(lst,func):
    for i in range(len(lst)-1):
        for j in range(i+1,len(lst)):
            yield func(lst[i],lst[j])
def distance(a,b):
    return math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)

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

all_route = list(itertools.itertools.permutations(lst))

count = 0
for i in all_combination(all_route,distance):
  count += i

print(count / math.factorial())

Submission status: Runtime Error

Solution code:
import math
import itertools

def all_combination(lst,func):
    for i in range(len(lst)-1):
        for j in range(i+1,len(lst)):
            yield func(lst[i],lst[j])
def distance(a,b):
    return math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)



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

all_route　= list(itertools.itertools.permutations(lst))

count = 0
for i in all_combination(all_route,distance):
  count += i

print(count / math.factorial())

Submission status: Runtime Error

Solution code:
import math
import itertools

def all_combination(lst,func):
    for i in range(len(lst)-1):
        for j in range(i+1,len(lst)):
            yield func(lst[i],lst[j])
def distance(a,b):
    return math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)

def nCr(n,r):
  for i in range()

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

all_route　= list(itertools.itertools.permutations(lst))

count = 0
for i in all_combination(all_route,distance):
  count += i

print(count / math.factorial())

Submission status: Runtime Error

Solution code:
import math
import numpy as np
from itertools import permutations
N = int(input())
x = []; y= []
for _ in range(N):
    x_,y_ = map(int,input().split())
    x.append(x_)
    y.append(y_)
lis = np.zeros((8,8))
for i in range(N):
    for j in range(N):
        lis[i,j] = math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
num = 0
su = 0
ite = permutations([i for i in range(N)])
for it in ite:
    for i in range(len(it)-1):
        su += lis[it[i],it[i+1]]
    num += 1
print(su/num)

Submission status: Runtime Error

Solution code:
from itertools import permutations

n = int(input())
distance_array = [[0 for x in range(2)] for y in range(n)]
for i in range(n):
    x, y = map(int, input().split())
    distance_array[i][0] = x
    dustance_array[i][1] = y
p = permutations([x for x in range(n)], 8)
print(p)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pii;
#define dbg(x) cout << #x << " has a value of: " << x << "\n";
#define usize(x) (int)(x.size())
#define plist(x)                       \
    for (int i = 0; i < usize(x); i++) \
        cout << "eleman " << i << " = " << x[i] << "\n";
#define foreach(x) for (auto item : x)
#define fill(s, x)              \
    for (int i = 0; i < x; i++) \
        cin >> s[i];
#define in(veriler, a) (veriler.find(a) != veriler.end())
#define btw(x, y, z) x >= y&& x <= z;
std::ostream& operator<<(std::ostream& os, pair<int,int> p) {
    os << p.first << ", " << p.second;
    return os;
}
#ifdef ONLINE_JUDGE
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#else
#define fio //a
#endif
int main(){
	int n;
	cin>>n;
	vector<pii> rts;
	double sm=0;
	for (int i = 0; i < n; i++)
	{
		int a,b;
		cin>>a>>b;
		foreach(rts){
			sm+=sqrt((item.first-a)*(item.first-a)+(item.second-b)*(item.second-b));
		}
		rts.push_back(pii(a,b));
		
	}
	cout<<setprecision(13)<<sm*2/n<<"\n";
	return 0;
}

Submission status: Runtime Error

Solution code:
def dis(p1,p2):
  return ((p1[0]-p2[0])**2+(p1[1]-p2[0])**2)**0.5

n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
ans=0
fac=1
for i in range(n):
  if(i!=0):
    fac*=i
  for j in range(i+1,n):
    ans+=dis(p[i],p[j])
print(ans*(2n-2)/(fac*n))

Submission status: Runtime Error

Solution code:
def dis(p1,p2):
  return ((p1[0]-p2[0])**2+(p1[1]-p2[0])**2)**0.5

n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
ans=0
fac=1
for i in range(n):
  for j in range(i+1,n):
    ans+=dis(p[i],p[j])
  fac*=i
print(ans*(2n-2)/fac)

Submission status: Runtime Error

Solution code:
import numpy as np
num=int(input())
List=[map(int, input()split()) for i in range(num)]
List=np.array(List)

#distance関数  
def distance(x,y):
  delta=List[x]-List[y]
  length=(delta[0]**2+delta[1]**2)**(1/2)
  
#順列リスト作る
order=[i for i in range(num)]
jun=list(itertools.permutations(order))

final_ans=[]
#その順列にしたがって、for文で計算：結果をansに加え、平均値とる
for k in jun:
  ans=[]
  for j in range(num-1):
    distance(k[j],k[j+1])
    ans.append(length)
  final_ans.append(sum(ans))
print(average(fina_ans))

Submission status: Runtime Error

Solution code:
def factorial(n):
    if n == 0:
        return 1.0
    else:
        return n*factorial(n-1)


n = int(raw_input())
k = n
arr = []
while(k > 0):
    x, y = map(int, raw_input().split())
    arr.append((x, y))
    k -= 1

total = 0.0
for i in range(n):
    x1 = arr[i][0]
    x2 = arr[i][1]
    for j in range(i+1, n, 1):
        y1 = arr[j][0]
        y2 = arr[j][1]
        dist = (x1-y1)*(x1-y1) + (x2-y2)*(x2-y2)
        print dist
        dist = float(math.sqrt(dist))
        dist = dist * float((factorial(n-1)*2))
        total += dist * float(1/factorial(n))

print total

Submission status: Runtime Error

Solution code:
def abc145_c():    
    n = int(input())
    xy = [list(map(int,input().split())) for i in range(n)]
    ans = 0
    for i in range(n):
        for j in range(n):
            cnt += 1
            ans += ((xy[i][0] - xy[j][0])** 2 + (xy[i][1] - xy[j][1])** 2)**0.5
    print(ans / n)
    
if __name__ == '__main__':
    abc145_c()

Submission status: Runtime Error

Solution code:
import numpy as np
from itertools import permutations

n = int(input())

li = []
for _ in range(n):
    i, j = map(int, input().split())
    li.append(np.array([i, j]))

li2 = permutations(li)

re = []
for a in li2:
    dis = 0 
    for (x1,y1),(x2,y2) in zip(a,a[1:]):
        dis += math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
    re.append(dis)

print(np.average(re))

Submission status: Runtime Error

Solution code:
import numpy as np
from itertools import permutations

n = int(input())

li = []
for _ in range(n):
    i, j = map(int, input().split())
    li.append(np.array([i, j]))

li2 = permutations(li)

re = []
for a in li2:
    b = np.array([i for i in a])
    dis = map(np.linalg.norm, (b[1:] - b[:-1]))
    re.append(sum(dis))

print(np.average(re))

Submission status: Runtime Error

Solution code:
x,y = map(int,input().split())
a = 1
b = 1
n = (2*y-x)//3
m = (2*x-y)//3

if (x+y)%3 == 0:
  for i in range(n+1,n+m+1):
    a *= i
  for j in range(1,m+1):
    b *= j
  print(a//b)
else:
  print(0)

Submission status: Runtime Error

Solution code:
N = int(input())
x = []
y = []
for i in range(N):
    a,b = map(int, (input().split()))
    x.append(a)
    y.append(b)
​
aaa = 0
for i in range(N):
    for k in range(N):
        aaa += ((x[i] - x[k])**2+(y[i] - y[k])**2)**0.5
print(aaa/N)

Submission status: Runtime Error

Solution code:
from numpy.linalg import solve

#制約
MOD = 10**9 +7
MAX = 10**6

#　組み合わせ計算
def COM(n, r):
    fac = [1, 1]
    finv = [1, 1]
    inv = [0, 1]
    for i in range(2, MAX):
        fac.append(fac[i - 1] * i % MOD)
        inv.append(-inv[MOD % i] * (MOD // i))
        finv.append(finv[i - 1] * inv[i] % MOD)
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD

x,y = map(int,input().split())

if (x+y)%3 != 0:
    print(0)
    exit()

l = solve([[2, 1], [1, 2]], [x, y])
if l[0] < 0 or l[1] < 0: #n,m <0の時0
    print(0)
    exit()
# n+m回のうち，どのn回で移動するか n+mCOMnを計算
print(COM(int(l[0]+l[1]), int(l[0])))

Submission status: Runtime Error

Solution code:
N = int(input())
t = [(int(input()), int(input())) for i in range(N)]

def dst( a,b, c,d ):
  return ((a-c) ** 2 + (b-d) ** 2) ** (0.5)

s = [[] for k in range(N)]
s[0] = [str(i) for i in range(N)]
for j in range(N-1):
  for x in range(N):
    for string in s[j]:
      if not(str(x) in string):
        s[j+1] += [string + str(x)]
path_set = s[-1]

avg_len = sum(sum(dst(*t[int(path[i])], *t[int(path[i+1])]) for i in range(N-1)) for path in path_set) / len(path_set)
print(avg_len)

Submission status: Runtime Error

Solution code:
N = int(input())
t = [(int(input()), int(input())) for i in range(N)]

def dst( a,b, c,d ):
  return ((a-c) ** 2 + (b-d) ** 2) ** (0.5)

s = [[] for k in range(N)]
s[0] = [str(i) for i in range(N)]
for j in range(N-1):
  for x in range(N):
    for string in s[j]:
      if not(str(x) in string):
        s[j+1] += [string + str(x)]
path_set = s[-1]

def path_len(path):
  return sum(dst(*t[int(path[i])], *t[int(path[i+1])]) for i in range(N-1))

avg_len = sum(path_len(path) for path in path_set) / len(path_set)
print(avg_len)

Submission status: Runtime Error

Solution code:
N = int(input())
town = [(int(input()), int(input())) for i in range(N)]

def dst( a,b, c,d ):
  return ((a-c) ** 2 + (b-d) ** 2) ** (0.5)

s = [[] for k in range(N)]
s[0] = [str(i) for i in range(N)]
for j in range(N-1):
  for x in range(N):
    for string in s[j]:
      if not(str(x) in string):
        s[j+1] += [string + str(x)]
        print(s[j+1])
path_set = s[-1]
print(s[N-1])

def path_len(path):
  return sum(dst(*town[int(path[i])], *town[int(path[i+1])]) for i in range(N-1))

avg_len = sum(path_len(path) for path in path_set) / len(path_set)
print(avg_len)

Submission status: Runtime Error

Solution code:
N = int(input())
town = [[int(input()), int(input())] for i in range(N)]

def dst((a,b),(c,d)):
  return ((a-c) ** 2 + (b-d) ** 2) ** (0.5)

s = [[] for k in range(N)]
for j in range(N-1):
  for x in range(N):
    for string in s[j]:
      if not(str(x) in string):
        s[j+1] += [string + str(x)]
path_set = s[-1]

def path_len(path):
  return sum(dst(town[int(path[i])], town[int(path[i+1])]) for i in range(N-1))

avg_len = sum(path_len(path) for path in path_set) / len(path_set)
print(avg_len)

Submission status: Runtime Error

Solution code:
n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
ans=0
den=1
for i in range(n):
  ans+=(p[i][0]**2+p[i][1]**2)**0.5
  den*=i
print(ans/den)