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 = list(input())
  N = len(S)
  
  def f(x):
      print(x)
      exit()
  
  if N < 5:
      f("NO")
  elif S[0] == "d":
      w = 1
  elif S[0] == "e":
      w = -1
  else:
      f("NO")
  
  i = 0
  while True:
      if w > 0:
          if S[i]+S[i+1]+S[i+2]+S[i+3]+S[i+4] == "dream":
              i += 5
              if i == N:
                  f("YES")
              elif S[i] == "d":
                  pass
              elif S[i] == "e":
                  if i+1 <= N-1:
                      if S[i+1] == "r":
                          if i+1 == N-1:
                              f("YES")
                          elif S[i+2] == "a":
                              w *= -1
                          elif S[i+2] == "e":
                              i += 2
                              w *= -1
                          elif S[i+2] == "d":
                              i += 2
                          else:
                              f("NO")
                      else:
                          f("NO")
                  else:
                      f("NO")
              else:
                  f("NO")
          else:
              f("NO")
      elif w < 0:
          if S[i]+S[i+1]+S[i+2]+S[i+3]+S[i+4] == "erase":
              i += 5
              if i == N:
              if S[i] == "r":
                  i += 1
                  if i == N:
              if S[i] == "d":
                  w *= -1
              elif S[i] == "e":
                  pass
              else:
                  f("NO")
          else:
              f("NO")
      if i+4 > N-1:
          f("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"}]