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()
  S = [s[i] for i in range(len(s))]
  a = input()
  
  
  def flag(list_s):
      flag_yes = True
      if len(list_s) <= 4:
          flag_yes = False
      else:
          flag_dreamer = False
          while len(list_s) > 0 and flag_yes:  # listが空でなく、まだ条件を満たしている時
              if (
                  flag_dreamer and len(list_s) >= 4 and list_s[:4] == ["a", "s", "e", "r"]
              ):  # dreameraser
                  list_s = list_s[4:]
                  flag_dreamer = False
              elif (
                  flag_dreamer and len(list_s) >= 3 and list_s[:3] == ["a", "s", "e"]
              ):  # dreamerase
                  list_s = list_s[3:]
                  flag_dreamer = False
              elif len(list_s) >= 5 and list_s[0:5] == [
                  "e",
                  "r",
                  "a",
                  "s",
                  "e",
              ]:  # eraseまたはeraserなら消去して初期化
                  flag_dreamer = False
                  list_s = list_s[5:]
                  if len(list_s) > 0 and list_s[0] == "r":
                      list_s = list_s[1:]
              elif list_s == ["d", "r", "e", "a", "m"]:  # [dream]なら全消去
                  flag_dreamer = False
                  list_s = list_s[5:]
              elif len(list_s) >= 6 and list_s[:6] == [
                  "d",
                  "r",
                  "e",
                  "a",
                  "m",
                  "d",
              ]:  # dreamdream or dreamdreamerなら前半消去
                  flag_dreamer = False
                  list_s = list_s[5:]
              elif len(list_s) >= 7 and list_s[:7] == [
                  "d",
                  "r",
                  "e",
                  "a",
                  "m",
                  "e",
                  "r",
              ]:  # dreamerが面倒
                  flag_dreamer = True
                  list_s = list_s[7:]
              else:
                  flag_yes = False
      return flag_yes
  
  
  if flag(S):
      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"}]