package main import ( "bufio" "fmt" "io" "log" "os" "strconv" ) var pri = fmt.Println var scan = fmt.Fscanln var scanone = fmt.Fscan func main() { if os.Getenv("DEBUG") != "" { fname := "input.txt" f, err := os.Open(fname) if err != nil { log.Fatal(err) } r := bufio.NewReader(f) for { solve(r) if r.Buffered() == 0 { break } } } else { f := os.Stdin r := bufio.NewReader(f) solve(r) } } func min(a ...int64) int64 { res := a[0] for i := 1; i < len(a); i++ { if res > a[i] { res = a[i] } } return res } func max(a ...int64) int64 { res := a[0] for i := 1; i < len(a); i++ { if res < a[i] { res = a[i] } } return res } func mustint(a string) int64 { i, _ := strconv.Atoi(a) return int64(i) } type P struct { x, y int64 } func (p *P) add(q *P) *P { return &P{p.x + q.x, p.y + q.y} } const huge = 1e10 func solve(r io.Reader) { var n int scan(r, &n) var x0, y0, z0 int for i := 0; i < n; i++ { var a int scanone(r, &a) switch a { case 0: x0++ case 1: y0++ case 2: z0++ } } const N = 101 var dp [N][N][N]float64 for i := 0; i < N; i++ { for j := 0; j < N; j++ { for k := 0; k < N; k++ { dp[i][j][k] = -1 } } } dp[0][0][0] = 0 var f func(x, y, z int) float64 f = func(x, y, z int) float64 { if dp[x][y][z] != -1 { return dp[x][y][z] } res := 0.0 if x-1 >= 0 { res += float64(x) * f(x-1, y+1, z) } if y-1 >= 0 { res += float64(y) * f(x, y-1, z+1) } if z-1 >= 0 { res += float64(z) * f(x, y, z-1) } res += float64(n) res /= float64(x + y + z) dp[x][y][z] = res return res } pri(f(x0, y0, z0)) }