peterverebics/CodeNet_Python_118 huggingface dataset:
s=input()
s=s.replace('eraser','0').replace('erase','0').replace('dreamer','0').replace('dream','0')
s=s.replace('0','')

if len(s)==0:print("YES")
else:print("NO")
import re
s = input()

if re.match("(dreamer|dream|eraser|erase)+$",s):
  print("YES")
else:
  print("NO")
S=input()
while len(S) >=5:
	if S[-7:]=='dreamer':
		S=S[:-7]
	elif S[-6:] == 'eraser':
		S=S[:-6]
	elif S[-5:] == 'dream':
		S=S[:-5]
	elif S[-5:] == 'erase':
		S=S[:-5]
	else:
		print('NO')
		break
if len(S)==0:
	print('YES')
if 1<=len(S)<=4:
	print('NO')
s = input()
s_reverse = s[::-1]

arr = ['dream', 'dreamer', 'erase', 'eraser']
arr_reversed = list(map(lambda item: item[::-1], arr))
able = True
t = ""
while s_reverse != t and able:
    for i in range(len(arr_reversed)):
        item = arr_reversed[i]
        if s_reverse[len(t): len(t) + len(item)] == item:
            t += item
            break
        elif i == len(arr_reversed) - 1:
            able = False

print("YES" if s_reverse == t else "NO")
S = input()

def check(S):
  DP = [False]*len(S)
  if S[:5] == 'dream' or S[:5] == 'erase':
    DP[4] = True
  if S[:7] == 'dreamer':
    DP[6] = True
  if S[:6] == 'eraser':
    DP[5] = True
  
  for i in range(7,len(S)):
    DP[i] = (DP[i-5]&((S[i-4:i+1]=='dream')|(S[i-4:i+1]=='erase')))|(DP[i-6]&(S[i-5:i+1]=='eraser'))|(DP[i-7]&(S[i-6:i+1]=='dreamer'))
  return DP[-1]
if check(S):
  print('YES')
else:
  print('NO')
s = input()
result = True

while 0 < len(s):
  if s[-5:] == "dream" or s[-5:] == "erase":
      s = s[:-5]
  elif s[-6:] == "eraser":
      s = s[:-6]
  elif s[-7:] == "dreamer":
      s = s[:-7]
  else:
      result = False
      break

print("YES" if result else "NO")
S = input()
day_dream_word = ["eraser", "erase", "dreamer", "dream"]
for replace_word in day_dream_word:
  S = S.replace(replace_word, "")

if S == "":
  print('YES')
else:
  print('NO')
import sys
readline = sys.stdin.readline

def main():
    S = readline().rstrip()
    T = S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
    if not T:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


import re


def main():
    S = input()
    if re.match("(dream|dreamer|erase|eraser)*$", S):
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()
s = input()
if s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream",""):
    print("NO")
else:
    print("YES")
S=input()
T=[]

l=-1
while l-2>=-len(S):
    k=S[l:l-3:-1]
    if k=="mae":
        T+="dream"[::-1]
        l-=5
    elif k=="rem":
        T+="dreamer"[::-1]
        l-=7
    elif k=="esa":
        T+="erase"[::-1]
        l-=5
    elif k=="res":
        T+="eraser"[::-1]
        l-=6
    else:
        break
if S=="".join(T[::-1]):
    print("YES")
else:
    print("NO")
s = str(input())
s1 = s[::-1]
u = ['dream','dreamer','erase','eraser']

while True:
    restart = False
    for i in range(4):
        if u[i][::-1] == s1[:len(u[i])]:
            s1 = s1[len(u[i]):]
            restart = True
            break
    if restart == False:
        break
if len(s1) > 0:
    print('NO')
else:
    print('YES')
from re import match
S = input()
L = r"^(dream|dreamer|erase|eraser)+$"
if match(L, S):
  print("YES")
else:
  print("NO")
i = input()[::-1]
T = []
for t in ['dreamer', 'dream', 'eraser', 'erase']:
    T.append(t[::-1])

match = True
while match:
    match = False
    for t in T:
        if i.startswith(t):
            match = True
            i = i.replace(t, '', 1)
            if len(i) < 1:
                print('YES')
                exit()

print('NO')
S = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
print('YES' if len(S) == 0 else 'NO')
s = str(input())
t = s.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if t == '':
    print('YES')
else:
    print('NO')
s = input()

if s.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", ""):
    print("NO")
else:
    print("YES")
s = input()[::-1]
n = len(s)
idx = 0
while idx < n:
    if s[idx:idx+5] == 'maerd':
        idx += 5
    elif s[idx:idx+7] == 'remaerd':
        idx += 7
    elif s[idx:idx+5] == 'esare':
        idx += 5
    elif s[idx:idx+6] == 'resare':
        idx += 6
    else:
        print("NO")
        exit()
print("YES")
import re
print("YES" if re.fullmatch("(erase(r)?|dream(er)?)+", input())else "NO")
S=input()
S=S[::-1]
L=["dream","dreamer","erase","eraser"]
L=[i[::-1] for i in L]
i=0
while i<len(S):
    flg=0
    for j in range(4):
        if S[i]==L[j][0] and S[i:min(i+len(L[j]),len(S))]==L[j]:
            flg=1
            i+=len(L[j])
            break
    if flg==0:
        break

if flg==1:
    print("YES")
else:
    print("NO")
S = list(input())
import re
S.reverse()
S = "".join(S)
S = re.split('maerd|remaerd|esare|resare', S)
if len(S) == S.count("") :
  print("YES")
else:
  print("NO")
S = input()
p = len(S)
while 0<p:
  if 0<=p-5 and S[p-5:p]=='dream':
    p -= 5
    continue
  elif 0<=p-7 and S[p-7:p]=='dreamer':
    p -= 7
    continue
  elif 0<=p-6 and S[p-6:p]=='eraser':
    p -= 6
    continue
  elif 0<=p-5 and S[p-5:p]=='erase':
    p -= 5
    continue
  else:
    print('NO')
    break
else:
  print('YES')
s=input()
s=s.replace("eraser","")
s=s.replace("erase","")
s=s.replace("dreamer","")
s=s.replace("dream","")
if len(s)==0: print("YES")
else: print("NO")
def resolve():
    S = input()
    pats = ('dream', 'dreamer', 'erase', 'eraser')

    dp = [False for _ in range(len(S) + 1)]
    dp[0] = True
    for i in range(len(S)):
        if not dp[i]:
            continue
        for pat in pats:
            if S[i:i + len(pat)] == pat:
                dp[i + len(pat)] = True
    if dp[-1]:
        print("YES")
    else:
        print("NO")


resolve()
import re

S = input()


if re.match("^(dream|dreamer|erase|eraser)+$", S):
    print('YES')
else:
    print('NO')
S = input().strip()

a = ("dream", "dreamer", "erase", "eraser")

while True:
    if S == "":
        break
    flg = False
    for aa in a:
        if S.endswith(aa):
            S = S[:-len(aa)]
            flg = True
    if flg:
        continue
    break

if S == "":
    print("YES")
else:
    print("NO")
S = input()
while S:
    if S[-5:] == 'dream':
        S = S[:-5]
    elif S[-5:] == 'erase':
        S = S[:-5]
    elif S[-6:] == 'eraser':
        S = S[:-6]
    elif S[-7:] == 'dreamer':
        S = S[:-7]
    else:
        answer = 'NO'
        break
else:
    answer = 'YES'

print(answer)
S = input()

ans = "YES"
while len(S) > 0:
    if S[-5:] == "dream":
        S = S[:-5]
    elif S[-5:] == "erase":
        S = S[:-5]
    elif S[-7:] == "dreamer":
        S = S[:-7]
    elif S[-6:] == "eraser":
        S = S[:-6]
    else:
        ans = "NO"
        break

print(ans)
S = input()
words = ['dream', 'dreamer', 'erase', 'eraser']
dp = [0] * (len(S) + 1)
dp[0] = 1
ans = 'NO'

for i in range(len(S)):
    if dp[i] == 0:
        continue
    for w in words:
        if S[i:i+len(w)] == w:
            dp[i+len(w)] = 1
    if dp[len(S)] == 1:
        ans = 'YES'
        break
print(ans)
s = input()

while s:
    if s.endswith('dream'):
        s = s[:-5]
        continue
    if s.endswith('erase'):
        s = s[:-5]
        continue
    if s.endswith('dreamer'):
        s = s[:-7]
        continue
    if s.endswith('eraser'):
        s = s[:-6]
        continue
    print('NO')
    exit()
print('YES')
S = list(input())
import re
S.reverse()
D1 = "maerd"
D2 = "remaerd"
E1 = "esare"
E2 = "resare"
S = "".join(S)
S = re.split('maerd|remaerd|esare|resare', S)
if len(S) == S.count("") :
  print("YES")
else:
  print("NO")
s = input()
ss = s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if ss:
    print("NO")
else:
    print("YES")
T=[]
S=input()
Sr=list(reversed(S))
w1=list(reversed('dream'))
w2=list(reversed('dreamer'))
w3=list(reversed('erase'))
w4=list(reversed('eraser'))

while True:
    if Sr[:5]==w1:
        del(Sr[:5])
    elif Sr[:5]==w3:
        del(Sr[:5])
    elif Sr[:6]==w4:
        del(Sr[:6])
    elif Sr[:7]==w2:
        del(Sr[:7])
    else:
        break
if Sr==T:
    print('YES')
else:
    print('NO')
s = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if s:
    print('NO')
else:
    print('YES')
S = input()[::-1]
day_dream_word = ["dreamer", "dream", "eraser", "erase"]
day_dream_word = list(map(lambda s: s[::-1], day_dream_word))
T = ""
Tindex = 0
res = False
partial_res = True
while not res and partial_res:
  partial_res = False
  for add_word in day_dream_word:
    nextTindex = Tindex + len(add_word)
    
    if S[Tindex:nextTindex] == add_word:
      if len(S) == nextTindex:
        res = True
        break
      else:
        partial_res = True
        break
  Tindex = nextTindex

if res:
  print('YES')
else:
  print('NO')
import re
S=input()
if re.match("^(dream|dreamer|erase|eraser)+$",S):
    print('YES')
else:
    print('NO')
s = input()[::-1]
len_s = len(s)

a = 'dream'[::-1]
b = 'dreamer'[::-1]
c = 'erase'[::-1]
d = 'eraser'[::-1]

idx = 1
for _ in range(len_s):
    if s[:idx] in [a, b, c, d]:
        s = s[idx:]
        idx = 0
    idx += 1
if s[:idx] in [a, b, c, d]:
    s = []

if len(s) == 0:
    print('YES')
else:
    print('NO')
# -*- coding: utf-8 -*-
 
I = ["dream", "dreamer", "erase", "eraser"]
I2 = input()
 
if I2.replace(I[1], "").replace(I[0], "").replace(I[3], "").replace(I[2], "").strip() == "":
  print("YES")
elif I2.replace(I[0], "").replace(I[2], "").replace(I[1], "").replace(I[3], "").strip() == "":
  print("YES")
elif I2.replace(I[2], "").replace(I[0], "").replace(I[3], "").replace(I[1], "").strip() == "":
  print("YES")
elif I2.replace(I[3], "").replace(I[2], "").replace(I[1], "").replace(I[0], "").strip() == "":
  print("YES")
else:
  print("NO")
s = input()
s = list(s)
s = s[::-1]

word_list = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
while i != len(s):
    a = s[i:i+5]
    a = ''.join(a)
    b = s[i:i+6]
    b = ''.join(b)
    c = s[i:i+7]
    c = ''.join(c)
    if a in word_list:
        i += 5
    elif b in word_list:
        i += 6
    elif c in word_list:
        i += 7
    else:
        print('NO')
        exit()

print('YES')
S = input()

ans = 'YES'

while S:
    if S.endswith('eraser'):
        S = S[:-6]
    elif S.endswith('erase'):
        S = S[:-5]
    elif S.endswith('dreamer'):
        S = S[:-7]
    elif S.endswith('dream'):
        S = S[:-5]
    else:
        ans = 'NO'
        break

print(ans)
from itertools import permutations

S = input()

def is_passed(s, ws):
    for w in ws:
        s = ''.join(s.split(w))
        if len(s) == 0:
            return True
    return False

def main():
    l = ['dreamer', 'eraser', 'dream', 'erase']
    pm = permutations(l, len(l))
    passed = False
    for ws in pm:
        passed = is_passed(S, ws)
        if passed:
            break
    print('YNEOS'[not passed::2])

if __name__ == '__main__':
    main()
S = input()
 
# 前から順に消すと詰む
# 後ろから順に消すと一意に定まる
while True:
  if S[-5:] == 'erase': S = S[:-5]
  else:
    if S[-6:] == 'eraser': S = S[:-6]
    else:
      if S[-5:] == 'dream': S = S[:-5]
      else:
        if S[-7:] == 'dreamer': S = S[:-7]
        else: break

if len(S) == 0: print('YES')
else: print('NO')
s = input()

new = s.replace('eraser','') .replace('erase','').replace('dreamer','').replace('dream','')

if len(new) == 0:
    print('YES')
else:
    print('NO')
s = input()

str_list = ["dream","dreamer","erase","eraser"]

def checklast(s):
    # print(s)
    for word in str_list:
        if s[-len(word):] == word:
            return s[:-len(word)]
    else:
            return None
    
for i in range(100000):
    if s is None:
        print("NO")
        break
    if len(s) == 0:
        print("YES")
        break
    s = checklast(s)
s = input()
s = s.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if s == '':
    print('YES')
else:
    print('NO')
S = input()

"""対象文字列
dream
erase
eraser
dreamer
"""

flg = True
while flg:
  if S[-7:] == 'dreamer':
    S = S[:-7]
  elif S[-6:] == 'eraser':
    S = S[:-6]
  elif S[-5:] == 'erase':
    S = S[:-5]
  elif S[-5:] == 'dream':
    S = S[:-5]
  else:
    flg = False


if len(S) == 0:
  ans = 'YES'
else:
  ans = 'NO'


print(ans)
S=input()[::-1]
N=len(S)
T=['maerd','esare','resare','remaerd']
ans='YES'
i=0
while i<N:
    if S[i:i+5]==T[0]:
        i+=5
    elif S[i:i+5]==T[1]:
        i+=5
    elif S[i:i+6]==T[2]:
        i+=6
    elif S[i:i+7]==T[3]:
        i+=7
    else:
        ans='NO'
        break
print(ans)
S = input()
S_inv = S[::-1]
i=0
flg = True
while i<len(S):
    if S_inv[i:i+5]=='dream'[::-1]:
        i = i + 5
    elif S_inv[i:i+7]=='dreamer'[::-1]:
        i = i + 7
    elif S_inv[i:i+5]=='erase'[::-1]:
        i = i + 5
    elif S_inv[i:i + 6] == 'eraser'[::-1]:
        i = i + 6
    else:
        flg = False
        break

if flg ==True:
    print('YES')
else:
    print('NO')
# -*- coding: utf-8 -*-

S = input()

words = ['dream', 'dreamer', 'erase', 'eraser']

while len(S)>0:
    hit = False
    for w in words:
        s = S[-len(w):]
        if w == s:
            S = S[0:-len(w)]
            hit = True
            break
    
    if not hit:
        break

if len(S)==0:
    print('YES')
else:
    print('NO')
def main():
  S = input()[::-1]
  i = 0
  while i < len(S):
    if S[i:i+5] == 'maerd' or S[i:i+5] == 'esare':
      i += 5
    elif S[i:i+6] == 'resare':
      i += 6
    elif S[i:i+7] == 'remaerd':
      i += 7
    else:
      print('NO')
      break
  else:
    print('YES')
  return

if __name__ == '__main__':
  main()
s = input()[::-1]
a = "maerd"
b = "remaerd"
c = "esare"
d = "resare"
while len(s)!=0:
  if s[:5]==a:
    s = s[5:]
  elif s[:7]==b:
    s = s[7:]
  elif s[:5]==c:
    s = s[5:]
  elif s[:6]==d:
    s = s[6:]
  else:
    print("NO")
    exit()
print("YES")
s = str(input())
while len(s) > 0:
    if s[-5:] == 'dream':
        s = s[:-5]
    elif s[-7:] == 'dreamer':
        s = s[:-7]
    elif s[-5:] == 'erase':
        s = s[:-5]
    elif s[-6:] == 'eraser':
        s = s[:-6]
    else:
        print('NO')
        break
else:
    print('YES')
S = input()
N = len(S)
i = N
while i:
    if S[i-5:i] == 'dream':
        i -= 5
    elif S[i-5:i] == 'erase':
        i -= 5  
    elif S[i-7:i] == 'dreamer':
        i -= 7
    elif S[i-6:i] == 'eraser':
        i -= 6
    else:
        print('NO')
        exit()
print('YES')
lt = ["dream", "dreamer", "erase", "eraser"]
s = input()

lt = [w[::-1] for w in lt]
s = s[::-1]
cond = True
i = 0
while i < len(s):
    for t in lt:
        if s[i:].startswith(t):
            i += len(t)
            break
    else:
        cond = False
        break

print("YES" if cond else "NO")
import sys
import resource
sys.setrecursionlimit(10 ** 9)

S = input()
l = []
def dfs(n):
  if n == len(S):
    l.append("YES")
  if n < len(S):
    if S[n:n+5] == "erase":
      dfs(n+5)    
    if S[n:n+5] == "dream":
      dfs(n+5)  
    if S[n:n+6] == "eraser":
      dfs(n+6)              
    if S[n:n+7] == "dreamer":
      dfs(n+7)
dfs(0)
if len(l) == 0:
  l.append("NO")
print(l[0])
s = input()
templates = ["dream", "dreamer", "erase", "eraser"]
while s:
    for template in templates:
        if s.endswith(template):
            s = s[:-len(template)]
            break
    else:
        break
print("YES" if not s else "NO")
import re
print('NYOE S'[bool(re.match('^(dream|dreamer|erase|eraser)+$',input()))::2])
S = list(input())

flag = True
while flag == True:
    if len(S) == 0:
        break
    if len(S) >= 5:
        if S[-5:] == list("dream"): del S[-5:]
        elif S[-5:] == list("erase"): del S[-5:]
        elif len(S)>=6 and S[-6:] == list("eraser"): del S[-6:]
        elif len(S)>=7 and S[-7:] == list("dreamer"): del S[-7:]
        else:
            flag = False
    else:
        flag = False
if flag:
    print("YES")
else:print("NO")
t=input()

def right(text):
  li=["dream","dreamer","erase","eraser"]
  for te in li:
    if text[-len(te):] == te:
      return text[:len(text)-len(te)]
  return text

flag=True
while flag:
  temp=right(t)
  if not temp:
    print("YES")
    break
  elif temp==t:
    print("NO")
    break
  t=temp
s = input()
s = s.replace("eraser", "").replace("erase", "").replace(
    "dreamer", "").replace("dream", "")
print("NO" if s else "YES")
from re import *
if match("^(dream|dreamer|erase|eraser)+$", input()):
    print('YES')
else:
    print('NO')
S=input().rstrip()
S=S[::-1]
T=["dream","dreamer","erase","eraser"]
for i in range(len(T)):
  T[i]=T[i][::-1]
while len(S):
  flag=False
  for t in T:
    if S.startswith(t):
      S=S[len(t):]
      flag=True
  if not flag: break
if len(S)==0:
  print("YES")
else:
  print("NO")
# https://atcoder.jp/contests/abc049/tasks/arc065_a

s = list(input())
words = ['dream','dreamer','erase','eraser']

def check(w):
    return word in words

while s:
    word = ''.join([s.pop() for _ in range(5)][::-1])
    if check(word): continue
    
    for _ in range(2):
        word = s.pop() + word
        if check(word): break
    else:
        print('NO')
        exit()
print('YES')
s=input()
lst=["eraser","erase","dreamer","dream",]
for e in lst: 
  s=s.replace(e,"")
print("YES" if s=="" else "NO")
s = input()
s = s.replace("eraser", "")
s = s.replace("erase", "")
s = s.replace("dreamer", "")
s = s.replace("dream", "")

if s:
  print("NO")
else:
  print("YES")
S=input()

N=len(S)
dp=[0]*(N+1)
dp[0]=1
L=["dream", "dreamer", "erase", "eraser"]
for i in range(1,N+1):
    for l in L:
        n=len(l)
        if 0<=i-n<N:
            if S[i-n:i]==l and dp[i-n]:
                dp[i]=1

if dp[-1]:
    print("YES")
else:
    print("NO")
import re
s = input()
s = re.sub('eraser','0',s)
#print(s)
s = re.sub('erase','0',s)
#print(s)
s = re.sub('dreamer','0',s)
#print(s)
s = re.sub('dream','0',s)
#print(s)


print('YES' if set(s) == set('0') else 'NO')
S = input()
ws = ['dreamer','eraser','dream','erase']
e = len(S)
while e:
    for w in ws:
        if S[e-len(w):e] == w:
            e -= len(w)
            break
    else:
        print('NO')
        exit()
print('YES')
S = input()
T = ''

add_word = ['eraser', 'erase', 'dreamer', 'dream']

for word in add_word:
    S = S.replace(word, '')

if S == T:
    ans = 'YES'
else:
    ans = 'NO'

print(ans)
import re

S = input()

# 文頭から行末まで
# +は直前のものが連続するの意
if re.match('^(dream|dreamer|erase|eraser)+$', S):
    print('YES')
else:
    print('NO')
def check():
    S = input()
    dp = [False]*len(S)
    dp[-1]=True
    for i in range(1,len(S)):
        dp[i] = (dp[i-5]&(S[max(0,i-4):i+1]in['dream','erase']))|(dp[i-7]&(S[max(0,i-6):i+1]=='dreamer'))|(dp[i-6]&(S[max(0,i-5):i+1]=='eraser'))

    if dp[-1]:
        return 'YES'
    return 'NO'
print(check())
s = input()

s = s[::-1]
lis = ['dreamer', 'dream', 'eraser', 'erase']
nlis = []
for i in lis:
    nlis.append(i[::-1])


for i in range(10**5 + 1):
    for j in nlis:
        if s.startswith(j):
            s = s[len(j):]


if s == '':
    print('YES')
else:
    print('NO')
import sys
sys.setrecursionlimit(10000)

s = 'HAKUTYUMU' + input()


while s != 'HAKUTYUMU':
    next_s = s

    if s[-5:] == 'dream':
        next_s = s[:-5]
    if s[-7:] == 'dreamer':
        next_s = s[:-7]
    if s[-5:] == 'erase':
        next_s = s[:-5]
    if s[-6:] == 'eraser':
        next_s = s[:-6]

    if s == next_s:
        print('NO')
        exit()

    s = next_s

print('YES')
a = str(input())
l = len(a)
let5 = ['dream','erase']


while l >= 5:
  lb = len(a)
  if a[-5:] in let5:
    a = a[:-5]
    l -= 5
  if a[-6:] == 'eraser':
    a = a[:-6]
    l -= 6
  if a[-7:] == 'dreamer':
    a = a[:-7]
    l -= 7
  if l == 0:
    print('YES')
    break
  if l == lb:
    print('NO')
    break
else:
  print('NO')
import re
S = input()
if re.match("^(dream|dreamer|erase|eraser)+$",S):
  print("YES")
else:
  print("NO")
s = input().replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')
if s:
    print('NO')
else:
    print('YES')
s = input()
s=s[::-1]
i=0
ans="YES"
while True:
    if len(s)==i:
        break
    elif s[i:i+5]=="maerd":
        i+=5
    elif s[i:i+7]=="remaerd":
        i+=7
    elif s[i:i+5]=='esare':
        i+=5
    elif s[i:i+6]=='resare':
        i+=6
    else:
        ans="NO"
        break
print(ans)
S = input()
array = ["eraser","erase","dreamer","dream"]

for str in array:
    S = S.replace(str," ")
ans = S.replace(" ","")
if len(ans) == 0:
    print("YES")
else:
    print("NO")
S = input().strip()[::-1]
div = [i[::-1] for i in ["dream", "dreamer", "erase", "eraser"]]

idx = 0
ok = False
while True:
    sub_ok = False
    for d in div:
        if S[idx:idx+len(d)] == d:
            idx += len(d)
            sub_ok = True
            break
    if sub_ok != True:
        break
    if idx == len(S):
        ok = True
        break

if ok:
    print("YES")
else:
    print("NO")
l = input()
l = l.replace('eraser','')
l = l.replace('erase','')
l = l.replace('dreamer','')
l = l.replace('dream','')

if l == '':
    print('YES')
else:
    print('NO')
import sys

s = input()

cand = ['dream', 'dreamer', 'erase', 'eraser']

q = ['']

while len(q) != 0:
    front = q.pop(0)

    for c in cand:
        start = len(front)
        end = len(front) + len(c)
        if end <= len(s) and s[len(front):len(front) + len(c)] == c:
            next_elm = front + c
            if next_elm == s:
                print('YES')
                sys.exit(0)
            q.append(next_elm)

print('NO')
S = input()

m = ["eraser","erase","dreamer","dream"]

for i in m:
    S = S.replace(i,"")


print("YES" if S == "" else "NO")
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7

s = input()
s = s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if len(s) == 0:
    print("YES")
else:
    print("NO")
# python 3.4.3
import sys
input = sys.stdin.readline
import numpy as np

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()
S = S[::-1]


words = ["dream","dreamer","erase","eraser"]
for i in range(4):
    words[i] = words[i][::-1]
 
i = 0
while i < len(S):
    for w in words:
        l = len(w)
        if w == S[i:i+l]:
            i += l
            break
    else:
        print("NO")
        sys.exit()
 
print("YES")
S = input()
while True:
    l = len(S)
    if l == 0:
        print('YES'); break
    if l-5 >= 0 and S[l-5:] == 'dream':
        S = S[:l-5]; continue
    if l-7 >= 0 and S[l-7:] == 'dreamer':
        S = S[:l-7]; continue
    if l-5 >= 0 and S[l-5:] == 'erase':
        S = S[:l-5]; continue
    if l-6 >= 0 and S[l-6:] == 'eraser':
        S = S[:l-6]; continue
    print('NO')
    break
s=input()
s=s[::-1]
w=['dream','dreamer','erase','eraser']
lenw=[5,7,5,6]
w=[i[::-1] for i in w]
i=0
n=len(s)
while i<n:
    flg=False
    for j in range(4):
        if s[i:min(i+lenw[j],n)]==w[j]:
            i=i+lenw[j]
            flg=True
    if flg==False:
        break

if i==n and flg:
    print('YES')
else:
    print('NO')
S = input().replace("eraser", "1").replace("erase", "1").replace(
    "dreamer", "1").replace("dream", "1").replace("1", "")
if len(S) == 0:
    print("YES")
else:
    print("NO")
s = input()[::-1]
a = ""
for i in range(len(s)):
    a = s[i] + a
    if a == "dreamer" or a == "dream" or a == "erase" or a == "eraser":
        a = ""
    #print(a)
if not a:
    print("YES")
else:
    print("NO")
s = input()
s = s[ : : -1]

n = len(s)
k = 0

flg = True
while k < n:
    if s[k : min(k + 7, n)] == 'remaerd':
        k += 7
    elif s[k : min(k + 6, n)] == 'resare':
        k += 6
    elif s[k : min(k + 5, n)] == 'maerd' or s[k : min(k + 5, n)] == 'esare':
        k += 5
    else:
        flg = False
        break

if flg:
    print('YES')
else:
    print('NO')
import re
N = input()

N_list = re.findall("^(dream|dreamer|erase|eraser)+$", N) 

if N_list==[]:
  print('NO')
else:
  print('YES')