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>
#include<iostream>
#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(long long i=j;i<(n);++i)
#define bk(i,j,n)   for(long long i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define srt(x) sort(x.begin(),x.end());
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>

typedef long long ll;

//std::cout << std::setprecision(12) << s << '\n';
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

ll n;
ll a[305];
double dp[301][301][301];
typedef double ld;

ld fun(ll on,ll tw,ll th)
{
    ld s=1.0*(on+tw+th);

    if(dp[on][tw][th]!=-1)
        return dp[on][tw][th];

    ld a=0,b=0,c=0;

    if(on)
    {
        a=(fun(on-1,tw,th)+1.0)*on/s;
    }
    if(tw)
    {
        b=(fun(on+1,tw-1,th)+1.0)*tw/s;
    }
    if(th)
    {
        c=(fun(on,tw+1,th-1)+1.0)*th/s;
    }
    ld nn=1.0*n;
    return dp[on][tw][th]=a+b+c+(nn-s)/s;





}


int main()
{
    run;
    cin>>n;
    ll c1=0,c2=0,c3=0;
    fr(i,0,n)
    {
        cin>>a[i];
        if(a[i]==1)
        {
            c1++;
        }else if(a[i]==2)
        {
            c2++;
        }else{
        c3++;}
    }

    fr(i,0,301)
    {
        fr(j,0,301)
        {
            fr(k,0,301)
            {
                dp[i][j][k]=-1;
            }
        }
    }
    dp[0][0][0]=0;

    cout<<setprecision(12)<<fun(c1,c2,c3)<<endl;

    


}