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 in C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
 
public class Solve{
    static public int mod = 1000000007;
    static public string al = "abcdefghijklmnopqrstuvwxyz";
    public static void Main(){
        // 方針
        //
        var n = rint();
        var x = new double[n];
        var y = new double[n];
        for(int i=0;i<n;i++){
            var d = doublea();
            x[i] = d[0];
            y[i] = d[1];
        }
        var per = new Permutation(n);
        
        var ans = 0.0;
        while(true){
            var p = per.now();
            for(int i=1;i<n;i++){
                var nx = x[p[i]] - x[p[i-1]];
                var ny = y[p[i]] - y[p[i-1]];
                ans += Sqrt(nx*nx + ny*ny);
            }
            
            if(!per.next()){
                break;
            }
        }
        
        var divide = 1.0;
        for(int i=2;i<=n;i++){
            divide *= i;
        }
        WriteLine(ans/divide);
        
	
	
    }
    public static void swap(ref int a,ref int b){int temp = a;a= b;b = temp;}
    static void charswap(ref char a,ref char b){char temp = a;a= b;b = temp;}
    static int ncr(int n,int r){if(n<r)return 0;r = Min(r,n-r);long nn = 1;for(int i=n-r+1;i<=n;i++){nn = nn*i%mod;}long rr = 1;for(int i=1;i<=r;i++){rr = rr*i%mod;}rr = square((int)rr,mod-2);nn = nn * rr %mod;return (int)nn;}
    // a^b mod
    static int square(int a,int b){string binary = Convert.ToString(b,2);int bileng = binary.Length;long a_power = a;long value = 1;for(int i=bileng-1;i>=0;i--){if(binary[i] == '1'){value = value*a_power%mod;}a_power = a_power*a_power%mod;}return (int)value;}
    static int square2(int a,int b){long output = 1;var list = new List<long>();int sh = 1;long n = a;list.Add(a);while(sh < b){sh *= 2;n = n*n%mod;list.Add(n);}for(int i=list.Count-1;i>=0;i--){if(b > sh){b -= sh;sh /= 2;output = output*list[i]%mod;}}return (int)output;}
    //各種読取
    static string rstr(){ return ReadLine(); }
    static int rint(){ return int.Parse(ReadLine()); }
    static long rlong(){ return long.Parse(ReadLine()); }
    static string[] stra(){ return ReadLine().Split(' '); }
    static char[] chara(){ string[] a=stra();string b="";for(int i=0;i<a.Length;i++){b+=a[i];}return b.ToCharArray();}
    static int[] inta(){ string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for(int countup_i=0;countup_i<read_str_array.Length;countup_i++){ return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; }
    static int[,] inta2(int num_array,int in_array){ int[,] int_array2 = new int[num_array,in_array]; for(int i=0;i<num_array;i++){ int[] temp_array = inta(); for(int j=0;j<in_array;j++){ int_array2[i,j] = temp_array[j]; } } return int_array2; }
    static long[] longa(){ string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for(long countup_i=0;countup_i<read_str_array.Length;countup_i++){ return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; }
    static double[] doublea(){ string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for(long countup_i=0;countup_i<read_str_array.Length;countup_i++){ return_double_array[countup_i] = double.Parse(read_str_array[countup_i]); } return return_double_array; }
    // -----------------------------
    static long GCD(long a,long b){ if(a < b){ long temp = a; a = b; b = temp; } if(a % b == 0){ return b; } else{ long temp = b; b = a%b; a = temp; return GCD(a,b); } }
    static long LCM(long a,long b){ return a * b / GCD(a,b); }
    static void WriteArray(int[,] a,int b,int c){for(int i=0;i<b;i++){for(int j=0;j<c;j++){if(j!=0) Write(" ");Write(a[i,j]);}WriteLine();}}
}
class Permutation{
    private int[] _permutation;
    private int _length;
    
    public Permutation(int a){
        _permutation = new int[a];
        for(int i=0;i<a;i++){
            _permutation[i] = i;
        }
        _length = a;
    }
    public int[] now(){
        return _permutation;
    }
    
    public bool next(){
        var upper = -1;
        for(int i=0;i<_length-1;i++){
            if(_permutation[i] < _permutation[i+1]) upper = i;
        }
        if(upper == -1){
            return false;
        }
        var bigger = -1;
        for(int i=upper;i<_length;i++){
            if(_permutation[upper] <= _permutation[i]) bigger = i;
        }
        var temp = _permutation[upper];
        _permutation[upper] = _permutation[bigger];
        _permutation[bigger] = temp;
        var list = new List<int>();
        upper++;
        for(int i=upper;i<_length;i++){
            list.Add(_permutation[i]);
        }
        list.Reverse();
        for(int i=upper;i<_length;i++){
            _permutation[i] = list[i-upper];
        }
        return true;
    }
    
    public void prev0(){
        Array.Reverse(_permutation);
    }
    
    public bool prev(){
        var lower = -1;
        for(int i=0;i<_length-1;i++){
            if(_permutation[i] > _permutation[i+1]) lower = i;
        }
        if(lower == -1){
            return false;
        }
        var smaller = -1;
        for(int i=lower;i<_length;i++){
            if(_permutation[lower] >= _permutation[i]) smaller = i;
        }
        var temp = _permutation[lower];
        _permutation[lower] = _permutation[smaller];
        _permutation[smaller] = temp;
        var list = new List<int>();
        lower++;
        for(int i=lower;i<_length;i++){
            list.Add(_permutation[i]);
        }
        list.Reverse();
        for(int i=lower;i<_length;i++){
            _permutation[i] = list[i-lower];
        }
        return true;
    }
}