#include using namespace std; #ifdef LOCAL #include "debug.hpp" #else #define debug(...) 1 #endif int n; vector a; vector>> seen; vector>> memo; double solve(int c1, int c2, int c3) { if (seen[c1][c2][c3]) { return memo[c1][c2][c3]; } seen[c1][c2][c3] = true; if (c1 == 0 && c2 == 0 && c3 == 0) { return 0.0; } double ret = 1; if (c1 >= 1) { ret += solve(c1 - 1, c2, c3) * (double) c1 / n; } if (c2 >= 1) { ret += solve(c1 + 1, c2 - 1, c3) * (double) c2 / n; } if (c3 >= 1) { ret += solve(c1, c2 + 1, c3 - 1) * (double) c3 / n; } if (n - (c1 + c2 + c3) >= 1) { ret *= (double) n / (c1 + c2 + c3); } return memo[c1][c2][c3] = ret; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; a.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; } seen.resize(n + 1, vector>(n + 1, vector(n + 1, false))); memo.resize(n + 1, vector>(n + 1, vector(n + 1, 0))); int c1 = 0, c2 = 0, c3 = 0; for (int i = 0; i < n; i++) { int x = max(0, 3 - a[i]); if (x == 1) c1++; if (x == 2) c2++; if (x == 3) c3++; } double ans = solve(c1, c2, c3); cout << fixed << setprecision(15) << ans << '\n'; }