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()
  length = len(s)
  
  i = 0
  res = "YES"
  
  while i < length: 
    if i+4 <= length and s[i:i+5] == "dream":
      i += 5
      if (i+2 <= length and s[i:i+2] == "er" and s[i+2] != "a") or (i+1 == length and s[i:i+2] == "er"):
        i += 2
    elif s[i] == "e":
    else:
      res = "NO"
      break
      
    if i+4 <= length and s[i:i+5] == "erase":
      i += 5
      if (i+1 <= length and s[i] == "r" and s[i+1] != "a") or (i == length and s[i] == "r"):
        i += 1
    elif s[i] == "d":
    else:
      res = "NO"
      break
          
  print(res)
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"}]