Problem:
Score : 100 points

Problem Statement

There are N dishes, numbered 1, 2, \ldots, N.
Initially, for each i (1 \leq i \leq N), Dish i has a_i (1 \leq a_i \leq 3) pieces of sushi on it.

Taro will perform the following operation repeatedly until all the pieces of sushi are eaten:

Roll a die that shows the numbers 1, 2, \ldots, N with equal probabilities, and let i be the outcome. If there are some pieces of sushi on Dish i, eat one of them; if there is none, do nothing.

Find the expected number of times the operation is performed before all the pieces of sushi are eaten.

Constraints

All values in input are integers.

1 \leq N \leq 300

1 \leq a_i \leq 3

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_N

Output

Print the expected number of times the operation is performed before all the pieces of sushi are eaten.
The output is considered correct when the relative difference is not greater than 10^{-9}.

Sample Input 1

3
1 1 1

Sample Output 1

5.5

The expected number of operations before the first piece of sushi is eaten, is 1.
After that, the expected number of operations before the second sushi is eaten, is 1.5.
After that, the expected number of operations before the third sushi is eaten, is 3.
Thus, the expected total number of operations is 1 + 1.5 + 3 = 5.5.

Sample Input 2

1
3

Sample Output 2

3

Outputs such as 3.00, 3.000000003 and 2.999999997 will also be accepted.

Sample Input 3

2
1 2

Sample Output 3

4.5

Sample Input 4

10
1 3 2 3 3 2 3 2 1 3

Sample Output 4

54.48064457488221

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple

#define N 311111
#define A 1111111
#define BLOCK 555 // ~sqrt(N)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int INF = 1e9 +5;
const int nax = 1e5 +5;
const long M = 1000000007;
double p[305][305][305];
double ev[305][305][305];
int arr[4];
// int visited[nax];
// int in_degree[nax];
// vector<int> edges[nax];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout<<fixed;
	cout<<setprecision(10);
	int t;
	// cin>>t;
	t = 1;
	while(t--){
		int n;
		cin>>n;
		for(int i=0;i<n;i++){
			int x;
			cin>>x;
			arr[x]++;
		}
		// cout<<arr[1]<<arr[2]<<arr[3]<<endl;
		p[arr[1]][arr[2]][arr[3]] = 1;

		for(int c = n;c>=0;--c){
			for (int b = n; b >= 0; --b){			
				for (int a = n; a >= 0; --a){				
					if((a ==0 && b==0 && c==0) || (a+b+c > n)){
						continue;
					}
					double p_waste = (double) (n - (a+b+c))/n ;
					ev[a][b][c] += (1/(1-p_waste))*p[a][b][c];
					if(a!=0){
						double l = (double) a/(a+b+c);
						p[a-1][b][c] += p[a][b][c] * l;
						ev[a-1][b][c] += ev[a][b][c]*l;
					}
					if(b!=0){
						double l = (double) b/(a+b+c);
						p[a+1][b-1][c] += p[a][b][c] * l;
						ev[a+1][b-1][c] += ev[a][b][c]*l;
					}
					if(c!=0){
						double l = (double) c/(a+b+c);
						p[a][b+1][c-1] += p[a][b][c] * l;
						ev[a][b+1][c-1] += ev[a][b][c]*l;
					}
				}
			}
		}

		cout<<ev[0][0][0]<<endl;
	}
}