import sys



def text_match_word(text, words):

    for word in words:

        if word == text[:len(word)]:

            return word



words_next = (("dream", "er"), ("erase", "r"))

words_next_dict = dict(words_next)



s = eval(input())



before_match_word = ""

while "" != s:

    search_words = list(words_next_dict.keys())

    if before_match_word in words_next_dict:

        search_words.append(words_next_dict[before_match_word])

    match_word = text_match_word(s, search_words)

    if match_word != None:

        s = s[len(match_word):]

    else:

        print("NO")

        sys.exit()

    before_match_word = match_word

    

print("YES")

    
s = eval(input())



while s != "":

	is_match = False

	for word in ("dream", "dreamer", "erase", "eraser"):

		if s[-len(word):] == word:

			s = s[:-len(word)]

			is_match = True

	if is_match == False:

		print("NO")

		exit()

print("YES")
import sys


def text_match_word(text, words):
    for word in words:
        if word == text[: len(word)]:
            return word


words_next = (("dream", "er"), ("erase", "r"))
words_next_dict = dict(words_next)
s = eval(input())
before_match_word = ""
while "" != s:
    search_words = list(words_next_dict.keys())
    if before_match_word in words_next_dict:
        search_words.append(words_next_dict[before_match_word])
    match_word = text_match_word(s, search_words)
    if match_word != None:
        s = s[len(match_word) :]
    else:
        print("NO")
        sys.exit()
    before_match_word = match_word
print("YES")

s = eval(input())
while s != "":
    is_match = False
    for word in ("dream", "dreamer", "erase", "eraser"):
        if s[-len(word) :] == word:
            s = s[: -len(word)]
            is_match = True
    if is_match == False:
        print("NO")
        exit()
print("YES")

-import sys - - -def text_match_word(text, words): -    for word in words: -        if word == text[: len(word)]: -            return word - - -words_next = (("dream", "er"), ("erase", "r")) -words_next_dict = dict(words_next) -before_match_word = "" -while "" != s: -    search_words = list(words_next_dict.keys()) -    if before_match_word in words_next_dict: -        search_words.append(words_next_dict[before_match_word]) -    match_word = text_match_word(s, search_words) -    if match_word != None: -        s = s[len(match_word) :] -    else: +while s != "": +    is_match = False +    for word in ("dream", "dreamer", "erase", "eraser"): +        if s[-len(word) :] == word: +            s = s[: -len(word)] +            is_match = True +    if is_match == False: -        sys.exit() -    before_match_word = match_word +        exit()