{-# LANGUAGE OverloadedStrings #-}

import           Control.Applicative
import qualified Data.ByteString.Char8 as B

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

solve :: B.ByteString -> B.ByteString
solve s 
    | B.null s = "YES"
    | otherwise = maybe "NO" solve $ strip s
        
strip :: B.ByteString -> Maybe B.ByteString
strip s = foldl1 (<|>) $ map (`B.stripSuffix` s) $
    ["dream", "dreamer", "erase", "eraser"]
