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: S = input()
  ans = True
  W = ["dream", "erase", "eraser", "dreamer"]
  while S:
      if S[:5] in W[:2]:
          match = False
          mw = ""
          for w in W:
              if S == w:
                  match = True
                  mw = w
          for w1 in W:
              for w2 in W:
                  if S[: len(w1) + len(w2)] == w1 + w2:
                      match = True
                      mw = w1
          if match:
              S = S[len(mw) :]
          else:
              ans = False
              break
      else:
          ans = False
          break
  print("YES" if ans else "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"}]