import Control.Applicative
import Data.List

lenJOIandIOI :: (Int, Int) -> String -> [Int]
lenJOIandIOI (a, b) []     = [a, b]
lenJOIandIOI (a, b) str
  | "JOI" `isPrefixOf` str = lenJOIandIOI (a + 1, b) (tail str)
  | "IOI" `isPrefixOf` str = lenJOIandIOI (a, b + 1) (tail str)
  | otherwise              = lenJOIandIOI (a, b) (tail str)

solver :: [String] -> [Int]
solver = concatMap $ lenJOIandIOI (0, 0)

main :: IO()
main = do
  contents <- lines <$> getContents
  mapM_ print $ solver contents