import qualified Data.ByteString.Char8 as B

main :: IO ()
main = B.interact solve

solve :: B.ByteString -> B.ByteString
solve s = go $ Just B.empty
    where
        go Nothing = B.pack "NO"
        go (Just t)
            | t == s    = B.pack "YES"
            | otherwise = go next
            where
                next = case [ p <> t | p <- prfs, (p <> t) `B.isSuffixOf` s ] of
                    [t'] -> Just t'
                    _    -> Nothing
                prfs = map B.pack ["dream", "dreamer", "erase", "eraser"]
