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 <cmath>
#include <chrono>
#include <random>
#include <ctime>
#include <algorithm>
#include <iosfwd>
#include <iostream>
#include <list>
#include <ostream>
#include <streambuf>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define fori(i, n) for(ll i = 0; i < (n); ++i)
#define forI(i, n) for(ll i = 1; i <= (n); ++i)
#define pll pair<ll, ll>
#define ff first
#define ss second

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#define pt pair<ll, ll>
#define x first
#define y second

pll operator+(pll a, pll b) { return {a.x + b.x, a.y + b.y}; }

ll rand0m() {
    return (ull(rand()) << 15ull | ull(rand()));
}                   //[0 ... n)
ll rand0m(ll x) {
    return rand0m() % x;
}               //[0 ... n)
ll rand0m(ll minn, ll maxx) {
    return rand0m(maxx - minn + 1) + minn;
}   //[minn ... maxx]

const ll MAXN = 1e5 + 1;
const ll mod = 1e9 + 7;
const ll INF = 1e18;

ll n, m;

ld dp[311][311][311];

ld solve(vector<ll> &ve) {
    ll ar[] = {0, 0, 0};
    fori(i, n){
        ++ar[ve[i] - 1];
    }
    //dp[ar[0]][ar[1]][ar[2]] = 0;
    fori(k, ar[2] + 1){
        fori(j, ar[1] + ar[2] + 1){
            fori(i, ar[0] + ar[1] + ar[2] + 1){
                if(k == 0 && j == 0 && i == 0) continue;
                //1 / (1 - (n - a - b - c) / n) = n / (a + b + c)
                ld p0 = ld(n) / (i + j + k);
                ld p1 = ld(i) / (i + j + k);
                ld p2 = ld(j) / (i + j + k);
                ld p3 = ld(k) / (i + j + k);
                dp[i][j][k] = p0;
                if(i) dp[i][j][k] += p1 * dp[i - 1][j][k];
                if(j) dp[i][j][k] += p2 * dp[i + 1][j - 1][k];
                if(k) dp[i][j][k] += p3 * dp[i][j + 1][k - 1];
            }
        }
    }
    return dp[ar[0]][ar[1]][ar[2]];
}

ll dfs(ll step, vector<ll> ve, ll a){
    if(a == 0)
        return step;
    ll i = rand0m(n);
    if(ve[i] > 0){
        --ve[i];
        --a;
    }
    return dfs(step + 1, ve, a);
}
void stress(){
    srand(1);

    //vector<ll> ve = {1, 3, 2, 3, 3, 2, 3, 2, 1, 3};
    cin >> n;
    vector<ll> ve(n);
    fori(i, n) cin >> ve[i];

    ll m = 0;
    n = ve.size();
    for(ll w: ve) m += w;
    ll c = 0;
    ll t = 1000000;
    fori(i, t){
        c += dfs(0, ve, m);
    }
    cout.precision(10);
    cout << fixed << ld(c) / t << " " << solve(ve);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    vector<ll> ve(n);
    fori(i, n) cin >> ve[i];
    //stress();
    cout.precision(12);
    cout << fixed << solve(ve);
}