#include // #include #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define INF 2000000000000000000 #define ll long long #define ld long double #define pll pair using namespace std; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b, ld> mp; ld bfs(ll x, ll y, ll z) { if (mp.find({x, y, z}) != mp.end()) { return mp[{x, y, z}]; } if (z == N) { return 0; } ld res = 0; ld mul = (N - z) / (ld)(N); if (x + y + z != N) { res += (bfs(x + 1, y, z) * (N - (x + y + z)) / (ld)(N)); } if (x != 0) { res += ((bfs(x - 1, y + 1, z)) * (x) / (ld)(N)); } if (y != 0) { res += ((bfs(x, y - 1, z + 1)) * (y) / (ld)(N)); } mp[{x, y, z}] = (res + 1) / mul; return (res + 1) / mul; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; vector A(N); vector num(4, 0); for (ll i = 0; i < N; ++i) { cin >> A.at(i); num.at(min(3ll, A.at(i))) += 1; } cout << fixed << setprecision(15); cout << bfs(num.at(1), num.at(2), num.at(3)) << "\n"; }