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: from collections import deque
  
  
  S = input()
  
  lenS = len(S)
  T = deque()
  for i in range(lenS):
      T.append(S[i])
  
  # print(T)
  
  A = len(T)
  
  while A > 7:
      if (
          T[A - 1] == "m"
          and T[A - 2] == "a"
          and T[A - 3] == "e"
          and T[A - 4] == "r"
          and T[A - 5] == "d"
      ):
          for i in range(5):
              T.pop()
      elif (
          T[A - 1] == "e"
          and T[A - 2] == "s"
          and T[A - 3] == "a"
          and T[A - 4] == "r"
          and T[A - 5] == "e"
      ):
          for i in range(5):
              T.pop()
  
      elif (
          T[A - 1] == "r"
          and T[A - 2] == "e"
          and T[A - 3] == "s"
          and T[A - 4] == "a"
          and T[A - 5] == "r"
          and T[A - 6] == "e"
      ):
          for i in range(6):
              T.pop()
  
      elif (
          T[A - 1] == "r"
          and T[A - 2] == "e"
          and T[A - 3] == "m"
          and T[A - 4] == "a"
          and T[A - 5] == "e"
          and T[A - 6] == "r"
          and T[A - 7] == "d"
      ):
          for i in range(7):
              T.pop()
      else:
          print("NO")
          exit()
  
      A = len(T)
  
  if A <= 4:
      print("NO")
  elif (
      A == 5
      and T[A - 1] == "m"
      and T[A - 2] == "a"
      and T[A - 3] == "e"
      and T[A - 4] == "r"
      and T[A - 5] == "d"
  ):
      print("YES")
  elif (
      A == 5
      and T[A - 1] == "e"
      and T[A - 2] == "s"
      and T[A - 3] == "a"
      and T[A - 4] == "r"
      and T[A - 5] == "e"
  ):
      print("YES")
  elif (
      A == 6
      and T[A - 1] == "r"
      and T[A - 2] == "e"
      and T[A - 3] == "s"
      and T[A - 4] == "a"
      and T[A - 5] == "r"
      and T[A - 6] == "e"
  ):
      print("YES")
  elif (
      A == 7
      and T[A - 1] == "r"
      and T[A - 2] == "e"
      and T[A - 3] == "m"
      and T[A - 4] == "a"
      and T[A - 5] == "e"
      and T[A - 6] == "r"
      and T[A - 7] == "d"
  ):
      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"}]