output_description: If it is possible to obtain S = T, print `YES`. Otherwise, print `NO`.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      S
attempt: import queue
  
  
  def check_dream(s):
      return s.startswith("dream")
  
  
  def check_dreamer(s):
      return s.startswith("dreamer")
  
  
  def check_erase(s):
      return s.startswith("erase")
  
  
  def check_eraser(s):
      return s.startswith("eraser")
  
  
  def check_sentence(s, q):
      if check_dream(s):
          q.put(s[5:])
  
      if check_dreamer(s):
          q.put(s[7:])
  
      if check_erase(s):
          q.put(s[5:])
  
      if check_eraser(s):
          q.put(s[7:])
  
      return q
  
  
  def search():
      sentence_q = queue.Queue()
      initial_s = input()
  
      s = initial_s
      while 1:
          if s == "":
              return True
  
          sentence_q = check_sentence(s, sentence_q)
          if sentence_q.empty():
              return False
  
          s = sentence_q.get()
  
  
  if search():
      print("YES")
  else:
      print("NO")
  
problem_description: Statement
  
  You are given a string S consisting of lowercase English letters. Another
  string T is initially empty. Determine whether it is possible to obtain S = T
  by performing the following operation an arbitrary number of times:
  
    * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
samples: [{"input": "erasedream", "output": "YES\n    \n\nAppend `erase` and `dream` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreameraser", "output": "YES\n    \n\nAppend `dream` and `eraser` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreamerer", "output": "NO"}]