import qualified Data.Bits as B

data Action = HIT | HOMERUN | OUT deriving (Show , Read , Eq)
type OutNum = Int
type Base = Int
type Point = Int
type BasePoint = (Base , Point)

hit :: BasePoint -> BasePoint
hit (s , p) = (h `mod` 8 , h `div` 8 + p)
    where
        h = s * 2 + 1

homerun :: BasePoint -> BasePoint
homerun (s , p) = (0 , B.popCount s + 1 + p)

simulate :: OutNum -> BasePoint -> [Action] -> (Point , [Action])
simulate 3 (_ , p) xs = (p , xs)
simulate o bp (HIT:xs) = simulate o (hit bp) xs
simulate o bp (OUT:xs) = simulate (o + 1) bp xs
simulate o bp (HOMERUN:xs) = simulate o (homerun bp) xs
simulate _ bp [] = (snd bp , [])

loopSimulate :: [Action] -> IO ()
loopSimulate [] = return ()
loopSimulate xs = let (p , as) = simulate 0 (0 , 0) xs in print p >> loopSimulate as

main :: IO ()
main = getLine
    >> getContents
    >>= return . map (read :: String -> Action) . lines
    >>= loopSimulate