import Control.Applicative import Data.Maybe import Data.List import Data.Array solve :: Array Int Int -> [Int] -> [Int] solve arr [] = return $ arr ! 4 solve arr (x:xs) = do i <- if x == 5 then [0..4] else [x] if i == 0 then return . maximum $ solve (arr // [(0,arr!0+1)]) xs else if arr!(i-1) > 0 then return . maximum $ solve (arr // [(i-1,arr!(i-1)-1),(i,arr!i+1)]) xs else return . maximum $ solve arr xs main :: IO () main = do s <- map (\x -> fromMaybe 6 $ findIndex (== x) "KUROI?") . filter (`elem` "KUROI?") <$> getLine print . maximum $ solve (listArray (0,4) $ repeat 0) s