{-# LANGUAGE BangPatterns #-}

import qualified Data.ByteString.Char8 as B
import Control.Monad
import Data.Array
import qualified Data.Vector.Unboxed as UV

import Data.Array.ST
import Control.Monad.ST

main=do
    n<-readLn::IO Int
    as<-UV.unfoldr(B.readInt.B.dropWhile(<'!'))<$>B.getLine::IO (UV.Vector Int)
    print $ g (fromIntegral n) $ acc as

acc :: UV.Vector Int -> (Int,Int,Int)
acc as = (a1,a2,a3) where
    av = UV.accumulate (+) (UV.replicate 3 0) $ UV.concatMap ma as
    ma 1 = UV.singleton (0,1)
    ma 2 = UV.fromList [(0,1),(1,1)]
    ma 3 = UV.fromList [(0,1),(1,1),(2,1)]
    a1 = av UV.! 0
    a2 = av UV.! 1
    a3 = av UV.! 2

g::Double->(Int,Int,Int)->Double
g n (!a1,!a2,!a3) = runST $ do
    e <- newArray ((0,0,0),(a1,a2,a3)) (-1.0) :: ST s (STUArray s (Int,Int,Int) Double)
    writeArray e (0,0,0) 0.0
    rd e (a1,a2,a3)
    where
        rd :: STUArray s (Int,Int,Int) Double -> (Int,Int,Int) -> ST s Double
        rd e (i,j,k) = do
            e0 <- readArray e (i,j,k)
            if e0 >= 0
                then return e0
                else do
                    e1 <- if i>j then (* (fromIntegral (i-j)/n)) <$> rd e (i-1,j,k) else pure 0.0
                    e2 <- if j>k then (* (fromIntegral (j-k)/n)) <$> rd e (i,j-1,k) else pure 0.0
                    e3 <- if k>0 then (* (fromIntegral k/n))     <$> rd e (i,j,k-1) else pure 0.0
                    let en = (e1+e2+e3+1) * n / fromIntegral i
                    writeArray e (i,j,k) en
                    return en