peterverebics/CodeNet_Python_118 huggingface dataset:
s = input()
while len(s) > 4:
    if s[-5:] == 'dream' or s[-5:] == 'erase':
        s = s[:-5]
        continue
    elif s[-7:] == 'dreamer':
        s = s[:-7]
        continue
    elif s[-6:] == 'eraser':
        s = s[:-6]
        continue
    else:
        break
if len(s) > 0:
    print('NO')
else:
    print('YES')
S = input()

S0 = S.replace("dream", "A")
S1 = S0.replace("erase", "B")
S2 = S1.replace("Aer", "A")
S3 = S2.replace("Br", "B")

#print(S3)
check = True
for i in range(len(S3)):
    if S3[i] != "A" and S3[i] != "B":
        check = False

print("YES" if check == True else "NO")
S = input()[::-1]
word1 = "dream"[::-1]
word2 = "dreamer"[::-1]
word3 = "erase"[::-1]
word4 = "eraser"[::-1]
while True:
    if S[:5] == word1:
        S = S[5:]
    elif S[:7] == word2:
        S = S[7:]
    elif S[:5] == word3:
        S = S[5:]
    elif S[:6] == word4:
        S = S[6:]
    elif S == "":
        print("YES")
        break
    else:
        print("NO")
        break
c = input().rstrip('\n')

str1 = "eraser"
str2 = "erase"
str3 = "dreamer"
str4 = "dream"



c = c.replace(str1, "")
c = c.replace(str2, "")
c = c.replace(str3, "")
c = c.replace(str4, "")

if (c == ""):
  print("YES")
else:
  print("NO")
S = input()
S_rvs = S[::-1]
texts = ["maerd", "remaerd", "esare", "resare"]

match = True
while len(S_rvs) > 0:
    if (S_rvs[0:5] == "maerd") or (S_rvs[0:5] == "esare"):
        S_rvs = S_rvs[5:]
    elif S_rvs[0:6] == "resare":
        S_rvs = S_rvs[6:]
    elif S_rvs[0:7] == "remaerd":
        S_rvs = S_rvs[7:]
    else:
        match = False
        break

if match:
    print("YES")
else:
    print("NO")
S = input()
i = 0
while len(S) > 0:
  if S[-5:] in ['dream', 'erase']:
    S = S[:-5]
  elif S[-6:] == 'eraser':
    S = S[:-6]
  elif S[-7:] == 'dreamer':
    S = S[:-7]
  else:
    print('NO')
    exit()
print('YES')
words = ['dream','dreamer', 'erase', 'eraser']
s = raw_input()
dp = [False for _ in range(len(s))]

for j in range(len(s)):
	for w in words:
		b = dp[j - len(w)] if j - len(w) -1 >= 0 else True
		b &= j-len(w) +1 >= 0 and s[j- len(w)+1:j+1] == w
		if b:
			dp[j] = True
			break
print 'YES' if dp[-1] else 'NO'
S = input()
while True :
  if S[-5:] == "dream":
    S = S[:-5]
  elif S[-6:] == "eraser":
    S = S[:-6]
  elif S[-7:] == "dreamer":
    S = S[:-7]
  elif S[-5:] == "erase":
    S = S[:-5]
  elif len(S) == 0:
    print("YES")
    break
  else:
    print("NO")
    break
S = input()
S = S[::-1]
s1 = 'maerd'
s2 = 'esare'
s3 = 'remaerd'
s4 = 'resare'

while(1):
	if S[:5] == s1:
		S = S[5:]
	elif S[:5] == s2:
		S = S[5:]
	elif S[:7] == s3:
		S = S[7:]
	elif S[:6] == s4:
		S = S[6:]
	else:
		break

if len(S)==0:
	print("YES")
else :
	print("NO")
S = input()
ch = ["dream", "dreamer", "erase", "eraser"]
while S:
  N = len(S)
  if S[N-5:] == ch[0] or S[N-5:] == ch[2]:
    S = S[:N-5]
  elif S[N-6:] == ch[3]:
    S = S[:N-6]
  elif S[N-7:] == ch[1]:
    S = S[:N-7]
  else:
    print("NO")
    exit()
print("YES")
s = input()
t_list = ['dream','dreamer','erase','eraser']
while s != '':
    for i in range(len(t_list)):
        if s[-len(t_list[i]):] == t_list[i]:
            s = s[:len(s)-len(t_list[i])]
            break
    else:
        print('NO')
        break
if s == '':
    print('YES')
s = input()
a = s.replace("eraser","")
b = a.replace("erase","")
c = b.replace("dreamer","")
d = c.replace("dream","")
if d == "":
    print("YES")
else:
    print("NO")
I = input()

import re
if re.match("^(dream|dreamer|erase|eraser)+$", I):
    print("YES")
else:
    print("NO")
s = input()
div = ["dream", "dreamer", "erase", "eraser"]
rev = []
t = ""
s_rev = s[::-1]
for d in div:
    rev.append(d[::-1])

result = True
i = 0
while i < len(s):
    can_divide = False
    for d in rev:
        if len(s_rev) - i >= len(d) and s_rev[i:i + len(d)] == d:
            can_divide = True
            i += len(d)
            break
    if not can_divide:
        result = False
        break

print("YES" if result else "NO")
import queue

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

S = input()

BFS = queue.Queue()

can = False

BFS.put(0)

while not BFS.empty():
    t = BFS.get()
    if (t == len(S)):
        can = True
        break
    for s in divide:
        if s == S[t: t + len(s)]:
            BFS.put(t + len(s))

if can is True:
    print("YES")
else:
    print("NO")
s = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
print('YES' if s=='' else 'NO')
S = input()
dp = [0] * (len(S) + 1)
dp[0] = 1

words = ["dream", "dreamer", "erase", "eraser"]
done = '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:
        done = 'YES'

print(done)
#abc049 c
s=input()
divide=["dream","dreamer","erase","eraser"]

s=s[::-1]
for i,x in enumerate(divide):
    divide[i]=x[::-1]

ans=True
i=0
while i<len(s):
    flag=False
    for x in divide:
        lx=len(x)
        if s[i:i+lx] in divide:
             flag=True
             i+=lx
    if flag==False:
        ans=False
        break
if flag:
     print("YES")
else:
     print("NO")
S = input()

words = ["dream", "dreamer", "erase", "eraser"]
ans = "YES"
r = len(S)

while r > 0:
    ok = False
    for w in words:
        l = r - len(w)
        if l < 0:
            continue
        if S[l:r] == w:
            r = l
            ok = True
            break
    if not ok:
        ans = "NO"
        break

print(ans)
S=input()
W=("dream","dreamer","erase","eraser")
s=[0]
while s:
  i=s.pop()
  if i==len(S):
    print("YES")
    break
  for w in W:
    if S[i:i+len(w)]==w:
      s.append(i+len(w))
else:
  print("NO")
s = input()
flag = "NO"
s = s[::-1]
for i in range(len(s)//5+1):
    if s[0:5] == "maerd":
        s = s[5:]
    if s[0:7] == "remaerd":
        s = s[7:]
    if s[0:5] == "esare":
        s = s[5:]
    if s[0:6] == "resare":
        s = s[6:]
            
    if s == '':
        flag = "YES"
        
print(flag)
s = input()[::-1]
while True:
    if len(s) == 0:
        print ("YES")
        exit ()

    if s[0:5] == "maerd" or s[0:5] == "esare":
        s = s[5:]
    else:
        if s[0:6] == "resare":
            s = s[6:]
        else:
            if s[0:7] == "remaerd":
                s = s[7:]
            else:
                print ("NO")
                exit ()
s = 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")
        exit()

if len(s) == 0:
    print("YES")
S = input()

ind = len(S)
flg = True
while ind > 0:
    if S[ind-7:ind] in ["dreamer"]:
        ind -= 7
    elif S[ind-6:ind] in ["eraser"]:
        ind -= 6
    elif S[ind-5:ind] in ["dream", "erase"]:
        ind -= 5
    else:
        flg = False
        break

if flg:
    print('YES')
else:
    print('NO')
def resolve():
	s = input()
	K = ['dream', 'dreamer', 'erase', 'eraser']
	for i in range(len(K)):
		K[i] = K[i][::-1]
	r = ''
	for i in s[::-1]:
		r += i
		if r in K:
			r = ''
	if len(r):
		print("NO")
	else:
		print("YES")
resolve()
s=input()


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

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

# 単転したら分解は一意
S = S[::-1]

while S != "":
    if S[:5] == "maerd":
        S = S[5:]
    elif S[:5] == "esare":
        S = S[5:]
    elif S[:6] == "resare":
        S = S[6:]
    elif S[:7] == "remaerd":
        S = S[7:]
    else:
        print("NO")
        exit()

print("YES")
s = t = input()
a = 'dream'
b = 'dreamer'
c = 'erase'
d = 'eraser'

while t:
    if t[-7:] == b:
        t = t[:-7]
    elif t[-6:] == d:
        t = t[:-6]
    elif t[-5:] in (a, c):
        t = t[:-5]
    else:
        break

if t:
    print('NO')
else:
    print('YES')
S = input()
reverse = S[::-1]
devide = ["dream", "erase", "dreamer", "eraser"]
r_devide = [devide[i][::-1] for i in range(len(devide))]
i=0
while i < len(S):
  can = False
  for j in r_devide:
    if j in reverse[i:i+len(j)] :
      can = True
      i += len(j)
  
  if can == False:
    break
    
if can == True:
  print("YES")
else:
  print("NO")
A = input()
A = A[::-1]
divide = [i[::-1] for i  in ["dream", "dreamer", "erase", "eraser"]]

flag = 1
while flag and A:
  flag = 0
  for word in divide:
    if A.startswith(word):
      A = A[len(word):]
      flag = 1

if len(A) == 0:
  print('YES')
else:
  print('NO')
def main():
    text = input()
    words = ['dreamer', 'eraser', 'dream', 'erase']
    length = len(text)
    while text:
        for word in words:
            if text.endswith(word):
                text = text[:-len(word)]
        else:
            if (new := len(text)) != length:
                length = new
            else:
                return 'NO'
    return 'YES'


if __name__ == '__main__':
    ans = main()
    print(ans)
#9
S = input()[::-1]
for i in range(0, len(S)//5+1):
    if S[0:5] == 'maerd' or S[0:5] == 'esare':
        S = S[5:]
    elif S[0:6] == 'resare':
        S = S[6:]
    elif S[0:7] == 'remaerd':
        S = S[7:]
    else:
        break
print('YES' if len(S)==0 else 'NO')
import re
s=input()
s=s[::-1]
#print(s)

#dream|dreamer|erase|eraser

#maerd|remaerd|esare|resare
t=re.split('maerd|remaerd|esare|resare', s)
#print(len(t))
#print(t.count(''))
if len(t)==t.count(''):
    print('YES')
else:
    print('NO')
S = input()
S = S[::-1]
candidacies = ["dream", "dreamer", "erase", "eraser"]
candidacies = [c[::-1] for c in candidacies]

fi_flg = False
while fi_flg is False:
  if S[:7] in candidacies:
    S = S[7:]
  elif S[:6] in candidacies:
    S = S[6:]
  elif S[:5] in candidacies:
    S = S[5:]
  else:
    fi_flg = True

if len(S) == 0:
  print("YES")
else:
  print("NO")
S = input()
S_r = S[::-1]

Ss = ["remaerd","resare","esare","maerd"]

ind = 0
while ind < len(S):
    flg = False
    for s in Ss:
        n = len(s)
        if S_r[ind:ind+n] == s:
            ind += n
            flg = True
    if not flg:
        print("NO")
        exit()
print("YES")
S = input()
k = ["dream", "dreamer" ,"erase", "eraser"]
ans = "NO"

while len(S) > 0:
  a = len(S)
  for i in k:
    if S[-1*len(i):] == i:
      S = S[0:-1*len(i)]
      break
  if a == len(S):
    break
  elif len(S) == 0:
    ans="YES"
print(ans)
S = input()
words = ['dreameraser','dreamerase','dreamer','dream','eraser','erase']
i = 0
while i < len(S):
    update = False
    for w in words:
        if S[i:].startswith(w):
            i += len(w)
            update =True
            break
    if not update:
        break
print('YES' if i == len(S) else 'NO')
import re
print("YES" if re.fullmatch("(eraser?|dream(er)?)+", input()) else "NO")
s = input()[::-1]
while s:
    if s[:5] == "dream"[::-1] or s[:5] == "erase"[::-1]:
        s = s[5:]
    elif s[:6] == "eraser"[::-1]:
        s = s[6:]
    elif s[:7] == "dreamer"[::-1]:
        s = s[7:]
    else:
        break
else:
    print("YES")
    exit()
print("NO")
s=input()+'#'
n=len(s)
i=0
while i<n:
  if s[i]=='#':
    i=n
  elif s[i:i+11]=='dreameraser':
    i+=11
  elif s[i:i+10]=='dreamerase':
    i+=10
  elif s[i:i+7]=='dreamer':
    i+=7
  elif s[i:i+6]=='eraser':
    i+=6
  elif s[i:i+5]=='dream' or s[i:i+5]=='erase':
    i+=5
  else:
    print('NO')
    exit()
print('YES')
S = input()

a = 'dreamer'
b = 'eraser'
c = 'dream'
d = 'erase'
key = [a,b,c,d]

st = S[::]

while len(st):
    for i in range(4):
        tmp = st[-len(key[i]):]
        if tmp == key[i]:
            st = st[:-len(key[i])]
            if not len(st):
                print('YES')
                exit(0)
            break
        if i == 3:
            print('NO')
            exit(0)
lst = ["dream", "dreamer", "erase", "eraser"]
S = str(input())

while len(S) != 0:
    if S[len(S)-5:] == lst[0]:
        S = S[:len(S)-5]
    elif S[len(S)-7:] == lst[1]:
        S = S[:len(S)-7]
    elif S[len(S)-5:] == lst[2]:
        S = S[:len(S)-5]
    elif S[len(S)-6:] == lst[3]:
        S = S[:len(S)-6]
    else:
        break

if len(S) == 0:
    print("YES")
else:
    print("NO")
s = list(input())
s.reverse()
str = ""
for i in s:
    str+=i
str = str.replace("resare","")
str = str.replace("esare","")
str = str.replace("remaerd","")
str = str.replace("maerd","")
if len(str)==0:
    print("YES")
else:
    print("NO")
S = input()
if (len(S) > 0) and (len(S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')) == 0):
  print('YES')
else:
  print('NO')
s = input()

dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


while s != "":
    if s.endswith(dreamer):
        s = s[:-7]
    elif s.endswith(eraser):
        s = s[:-6]
    elif s.endswith(dream):
        s = s[:-5]
    elif s.endswith(erase):
        s = s[:-5]
    else:
        print("NO")
        exit()

print("YES")
import re

s = input()
s = re.sub("eraser","",s)
s = re.sub("erase","",s)
s = re.sub("dreamer","",s)
s = re.sub("dream","",s)

if len(s) == 0:
    print("YES")
else:
    print("NO")
s = input()
s = s[::-1]
t = ["dream", "dreamer", "erase", "eraser"]

i = 0
while i < len(s) - 7 + 1:
    for j in t:
        if s[i:i + len(j)] == j[::-1]:
            i += len(j)
            break
    else:
        print("NO")
        break
else:
    for j in t:
        if s[i:] == j[::-1] or s[i:] == "":
            print("YES")
            break
    else:
        print("NO")
# ABC049 C

def main():
    s = input()

    if s.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', ''):
        print('NO')
    else:
        print('YES')

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

    
if __name__ == '__main__':
    ans = solve()
    print(ans)
s=input()
t=""
i=len(s)
five=["dream","erase"]
flag=0
while s!=t:
  if i>=7 and s[i-7:i]=="dreamer":
    t=s[i-7:i]+t
    i-=7
  elif  i>=6 and s[i-6:i]=="eraser":
    t=s[i-6:i]+t
    i-=6
  elif i>=5 and (s[i-5:i] in five):
    t=s[i-5:i]+t
    i-=5
  else:
    flag=1
    break
if flag==0:
  print("YES")
else:
  print("NO")
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
print("YES" if len(s)==0 else "NO")
s = input()

while len(s) > 7:
  if s[-5:] in ["dream", "erase"]:
    s = s[:-5]
  elif s[-6:] in ["eraser"]:
    s = s[:-6]
  elif s[-7:] in ["dreamer"]:
    s = s[:-7]
  else:
    break

if (len(s)==5 and s in ["dream", "erase"]) or (len(s)==6 and s in ["eraser"]) or (len(s)==7 and s in ["dreamer"]):
  print("YES")
else:
  print("NO")
S = input()

T = ["dream","dreamer","erase","eraser"]
flag = True
for i in range(len(S)):
    if (flag == False) or (len(S) == 0):
        break
    if S[-5:] in T:
        S = S[:-5]
    elif S[-6:] in T:
        S = S[:-6]
    elif S[-7:] in T:
        S = S[:-7]
    else:
        print("NO")
        flag = False
if flag == True:
    print("YES")
def main():
  s=input()
  q=[0]
  m=len(s)
  l=["dream","dreamer","erase","eraser"]
  while q:
    i=q.pop()
    if i==m:
      print("YES")
      return
    for j in l:
      nj=len(j)
      if i+nj<=m and s[i:i+nj]==j:
        q.append(i+nj)
  print("NO")

main()
s=str(input())
s=s[::-1]
stack=""
for i in s:
  stack=i+stack
  if stack=="dream"or stack=="dreamer"or stack=="erase"or stack=="eraser":
    stack=""
  elif len(stack)>7:
    print("NO")
    exit()
print("YES")
S = input()
while len(S)>0:
    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:
        break
print("YES" if len(S)==0 else "NO")
WORDS = ['dream', 'dreamer', 'erase', 'eraser']
REVERSED_WORDS = [word[::-1] for word in WORDS]


def main(s):
    i = 0
    while i < len(s):
        for word in REVERSED_WORDS:
            if s[i:].startswith(word):
                i += len(word)
                break
        else:
            print('NO')
            break
    else:
        print('YES')


if __name__ == "__main__":
    main(input()[::-1])
def main(S):
    listdreamereraser = ['dreamer','eraser','dream','erase']
    while True:
        for i in listdreamereraser:
            if i == S[-len(i):]:
                S = S[:-len(i)]
                break
        else:
            return False
        if len(S) == 0:
            return True

S = input()
print('YES' if main(S) else 'NO')
S = input()

while True:
  if S[-5:] == 'dream':
    S = S[:-5]
    continue
  elif S[-7:] == 'dreamer':
    S = S[:-7]
    continue
  elif S[-5:] == 'erase':
    S = S[:-5]
    continue
  elif S[-6:] == 'eraser':
    S = S[:-6]
    continue
  break

answer = 'YES' if not S else 'NO'
print(answer)
S = input()

words = ["dream", "dreamer", "erase", "eraser"]
S_rv = S[::-1]
words_rv = [word[::-1] for word in words]

for i in range(len(S_rv)):
    for word_rv in words_rv:
        if S_rv[: len(word_rv)] == word_rv:
            S_rv = S_rv[len(word_rv) :]

if len(S_rv) == 0:
    print("YES")
else:
    print("NO")
s = input().replace("eraser",'').replace('erase','').replace('dreamer','').replace('dream','')
print('YES' if len(s) == 0 else 'NO')
def main():
    S = input()
    if S.replace("eraser", "").replace("erase", "")\
            .replace("dreamer", "").replace("dream", "") == "":
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()
S=input()
 
S=S.replace('eraser','')
S=S.replace('erase','')
S=S.replace('dreamer','')
S=S.replace('dream','')
 
if S=='':
    print('YES')
else:
    print('NO')
s=input()[::-1]
T=["dream","dreamer","erase","eraser"]
l,n=0,len(s)

while l!=n:
    flag=0
    for i in T:
        word=i[::-1]
        if s[l:l+len(word)]==word:
            l +=len(word)
            flag=1
            break
    if flag==0:print("NO");exit()
print("YES")
S = input()
divide = ['dream', 'dreamer', 'erase', 'eraser']
line = ['','','','']

for i in range(4):
    char = divide[i][::-1]
    line[i] = char
s_str = S[::-1]
char = ''
for i in range(len(s_str)):
    char += s_str[i]
    if char in line:
        char = ''
if char == '':
    print('YES')
else:
    print('NO')
str = input()
words = ["dream", "dreamer", "erase", "eraser"]

def replace(S, s):
    reversedS = S[::-1]
    reverseds = s[::-1]
    replaced = reversedS.replace(reverseds, "", 1)
    return replaced[::-1]

while True:
    tmp = str
    for word in words:
        if str.endswith(word):
            str = replace(str, word)
            break
    if tmp == str:
        print("NO")
        break
    if str == "":
        print("YES")
        break
    tmp = str
s = input()

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

while len(s) > 0:
    for word in words:
        flg = False

        if s.endswith(word):
            s = s[:(len(s) - len(word))]
            flg = True
            break

    if not flg:
        break

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

S = input()

if re.match('^(dream|dreamer|erase|eraser)+$', S):
    print('YES')
else:
    print('NO')
s = str(input())
no = 0
while 1:
    for data in ["erase", "eraser", "dream", "dreamer"]:
        if s.endswith(data):
            s = s[: - len(data)]
        else:
            no += 1
    if not s:
        break
    if no == 4:
        print("NO")
        exit()
    else:
        no = 0
print("YES")
import re

s = input()

if re.match('^(dream|dreamer|erase|eraser)+$', s):
  print('YES')
else:
  print('NO')
S = input()
tmp = ''.join(list(reversed(S)))
s = 0
ans = 'YES'

for i in range(len(S)):
    if tmp[s:i] == 'maerd' or tmp[s:i] == 'remaerd'or tmp[s:i] == 'esare' or tmp[s:i] == 'resare':
        s = i
        ans = 'YES'
        continue
    
    if len(tmp[s:i]) > 7:
        ans = 'NO'
        break
        
print(ans)
import re
def resolve():
	s = input()
	if re.search("^(dream|dreamer|erase|eraser)+$", s):
		print("YES")
	else:
		print("NO")
resolve()
S= input()
while len(S) >=0:
    if len(S) ==0:
        print("YES")
        break
    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
S = input()

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

DP = [0] * 100000

DP[0] = 1

for s in range(len(S)):
    if DP[s] != 1:
        continue

    for i in range(4):
        tmp = S[s: s+len(dire[i])]
        if tmp == dire[i]:
            DP[s + len(dire[i])] = 1

if DP[len(S)] == 1:
    print('YES')
else:
    print('NO')
import re

print("YES" if re.match("^(dream|dreamer|erase|eraser)+$", input()) else "NO")
s = input()[::-1]
r = 'YES'
while len(s):
    if s[:5] == 'dream'[::-1] or s[:5] == 'erase'[::-1]:
        s = s[5:]
    elif s[:6] == 'eraser'[::-1]:
        s = s[6:]
    elif  s[:7] == 'dreamer'[::-1]:
        s = s[7:]
    else:
        r = 'NO'
        break
print(r)
s = input()
ans = "YES"
while s != "":
    if len(s) < 5:
        ans = "NO"
        break
    elif s[len(s) - 5:] == "dream" or s[len(s) - 5:] == "erase":
        s = s[:len(s) - 5]
    elif s[len(s) - 6:] == "eraser":
        s = s[:len(s) - 6]
    elif s[len(s) - 7:] == "dreamer":
        s = s[:len(s) - 7]
    else:
        ans = "NO"
        break
print(ans)
s = input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s:
 print("NO")
else:
 print("YES")
def main():
    S = input()
    for word in ["eraser", "erase", "dreamer", "dream"]:
        S = S.replace(word, ".")
    # print(S)
    if len(set(S)) == 1:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()
s = input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s:
    print('NO')
else:
    print('YES')
s = input()
words = ["dreamer", "dream", "eraser", "erase"]
while len(s) > 0:
    match = [s.endswith(i) for i in words]
    if True in match:
        ans = words[match.index(True)]
        s = s[:-len(ans)]
        if len(s) == 0:
            print("YES")
            break
    
    else:
        print("NO")
        break
import sys
S = input()
S = S[::-1]
while S != '':
    if S[:5] == 'maerd':
        S = S[5:]
    elif S[:5] == 'esare':
        S = S[5:]
    elif S[:6] == 'resare':
        S = S[6:]
    elif S[:7] == 'remaerd':
        S = S[7:]
    else:
        print('NO')
        exit()
print('YES')
S = input()
S = S[::-1]
a = 'dream'[::-1]
b = 'dreamer'[::-1]
c = 'erase'[::-1]
d = 'eraser'[::-1]
words = [a, b, c, d]
t = 0
for i in range(1, len(S) + 1):
    if S[t:i] in words:
        t = i
if t == len(S):
    print('YES')
else:
    print('NO')
s = input()
def solve(query):
    while 1:
        for frag in ("erase", "eraser", "dream", "dreamer"):
            if query.endswith(frag):
                query = query[:-len(frag)]
                break
        else:
            print("NO")
            break
        if not query:
            print("YES")
            break

solve(s)
s = input()
s = s.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
print('YES' if len(s) == 0 else 'NO')
s=input()
cnt=0
for i in range(len(s)):
    if s[-7:] == 'dreamer':
        s=s[:-7]
    elif s[-6:] == 'eraser':
        s=s[:-6]
    elif s[-5:] =='erase'or s[-5:]=='dream':
        s=s[:-5]
    elif s=='':
        break
    else:
        cnt+=1
        break
if cnt==0:
    print('YES')
else:
    print('NO')
s = input()
flag = True
while 1:
    if s[-7:] == "dreamer":
        s = s[:-7]
    elif s[-6:] == "eraser":
        s = s[:-6]
    elif s[-5:] == "dream" or s[-5:] == "erase":
        s = s[:-5]
    else:
        flag = False
        break
    if s == "":
        break
if flag:
    print("YES")
else:
    print("NO")
s = input()
lst = ["eraser","erase","dreamer","dream"]
for w in lst:
    s = s.replace(w,"")

if len(s) == 0:
    ans = "YES"
else:
    ans = "NO"

print(ans)