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`.
s = input()
i = len(s) - 1
flag = False
while i > 0:
    flag = False
    if s[i] == "m" and s[i - 4:i + 1] == "dream":
        flag = True
        i -= 5
    elif s[i] == "e" and s[i - 4: i + 1] == "erase":
        i -= 5
        flag = True
    elif s[i] == "r":
        if s[i - 5: i + 1] == "eraser":
            flag = True
            i -= 6
        elif s[i - 6: i + 1] == "dreamer":
            flag = True
            i -= 7
    if flag == False:
        break
print("Yes" if flag else "No")
s = input()
i = len(s) - 1
flag = False
while i > 0:
    flag = False
    if s[i] == "m" and s[i - 4:i + 1] == "dream":
        flag = True
        i -= 5
    elif s[i] == "e" and s[i - 4: i + 1] == "erase":
        i -= 5
        flag = True
    elif s[i] == "r":
        if s[i - 5: i + 1] == "eraser":
            flag = True
            i -= 6
        elif s[i - 6: i + 1] == "dreamer":
            flag = True
            i -= 7
    if flag == False:
        break
print("YES" if flag else "NO")