import numpy as np

import sys

sys.setrecursionlimit(10 **9)





S = str(eval(input()))

dp = [0] * (2 * len(S))



#再帰関数

def check(i): #i最初の文字

    flag0 = False

    flag1 = False

    flag2 = False

    flag3 = False

    flag4 = False

    flag5 = False

    if dp[i+5] != 0 or dp[i+6] != 0 or dp[i+7] != 0:

        return dp[i+5] or dp[i+6] or dp[i+7]

    #S[i:]=残りが条件を満たす

    if S[i:] == 'dream' or S[i:] == 'dreamer' or S[i:] == 'erase' or S[i:] == 'eraser':

        return True

    if S[i:i+7] == 'dreamer': #dreamerを使った時に、条件を満たすかを再帰で計算

        dp[i+7] = check(i+7)

        flag2 = dp[i+7]

    if S[i:i+5] == 'dream':

        dp[i+5] =  check(i+5)

        flag3 =  dp[i+5]

    if S[i:i+6] == 'eraser':

        dp[i+6] =  check(i+6)

        flag4 =  dp[i+6]

    if S[i:i+5] == 'erase':

        dp[i+5] =  check(i+5)

        flag5 = dp[i+5]

    return flag0 or flag1 or flag2 or flag3 or flag4 or flag5 #どれかがTrueならOK



if check(0):

    print ('YES')

else:

    print ('NO')
import sys

# input = sys.stdin.readline

sys.setrecursionlimit(10 ** 9)

MOD = 10 ** 9 + 7



S = list(eval(input()))

i = len(S) - 1



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



while i > 0:

    if S[i] == 'm':

        for j in range(5):

            if S[i - j] == T[0][4 - j]:

                continue

            else:

                print ('NO')

                exit()

        i -= 5

    elif S[i] == 'r':

        if S[i - 2] == 'm':

            for j in range(7):

                if S[i - j] == T[1][6 - j]:

                    continue

                else:

                    print ('NO')

                    exit()

            i -= 7

        else:

            for j in range(6):

                if S[i - j] == T[3][5 - j]:

                    continue

                else:

                    print ('NO')

                    exit()

            i -= 6

    else:

        for j in range(5):

            if S[i - j] == T[2][4 - j]:

                continue

            else:

                print ('NO')

                exit()

        i -= 5



if i == -1:

    print ('YES')

else:

    print ('NO')
import numpy as np
import sys

sys.setrecursionlimit(10**9)
S = str(eval(input()))
dp = [0] * (2 * len(S))
# 再帰関数
def check(i):  # i最初の文字
    flag0 = False
    flag1 = False
    flag2 = False
    flag3 = False
    flag4 = False
    flag5 = False
    if dp[i + 5] != 0 or dp[i + 6] != 0 or dp[i + 7] != 0:
        return dp[i + 5] or dp[i + 6] or dp[i + 7]
    # S[i:]=残りが条件を満たす
    if S[i:] == "dream" or S[i:] == "dreamer" or S[i:] == "erase" or S[i:] == "eraser":
        return True
    if S[i : i + 7] == "dreamer":  # dreamerを使った時に、条件を満たすかを再帰で計算
        dp[i + 7] = check(i + 7)
        flag2 = dp[i + 7]
    if S[i : i + 5] == "dream":
        dp[i + 5] = check(i + 5)
        flag3 = dp[i + 5]
    if S[i : i + 6] == "eraser":
        dp[i + 6] = check(i + 6)
        flag4 = dp[i + 6]
    if S[i : i + 5] == "erase":
        dp[i + 5] = check(i + 5)
        flag5 = dp[i + 5]
    return flag0 or flag1 or flag2 or flag3 or flag4 or flag5  # どれかがTrueならOK


if check(0):
    print("YES")
else:
    print("NO")

import sys

# input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 10**9 + 7
S = list(eval(input()))
i = len(S) - 1
T = ["dream", "dreamer", "erase", "eraser"]
while i > 0:
    if S[i] == "m":
        for j in range(5):
            if S[i - j] == T[0][4 - j]:
                continue
            else:
                print("NO")
                exit()
        i -= 5
    elif S[i] == "r":
        if S[i - 2] == "m":
            for j in range(7):
                if S[i - j] == T[1][6 - j]:
                    continue
                else:
                    print("NO")
                    exit()
            i -= 7
        else:
            for j in range(6):
                if S[i - j] == T[3][5 - j]:
                    continue
                else:
                    print("NO")
                    exit()
            i -= 6
    else:
        for j in range(5):
            if S[i - j] == T[2][4 - j]:
                continue
            else:
                print("NO")
                exit()
        i -= 5
if i == -1:
    print("YES")
else:
    print("NO")

-import numpy as np +# input = sys.stdin.readline -S = str(eval(input())) -dp = [0] * (2 * len(S)) -# 再帰関数 -def check(i):  # i最初の文字 -    flag0 = False -    flag1 = False -    flag2 = False -    flag3 = False -    flag4 = False -    flag5 = False -    if dp[i + 5] != 0 or dp[i + 6] != 0 or dp[i + 7] != 0: -        return dp[i + 5] or dp[i + 6] or dp[i + 7] -    # S[i:]=残りが条件を満たす -    if S[i:] == "dream" or S[i:] == "dreamer" or S[i:] == "erase" or S[i:] == "eraser": -        return True -    if S[i : i + 7] == "dreamer":  # dreamerを使った時に、条件を満たすかを再帰で計算 -        dp[i + 7] = check(i + 7) -        flag2 = dp[i + 7] -    if S[i : i + 5] == "dream": -        dp[i + 5] = check(i + 5) -        flag3 = dp[i + 5] -    if S[i : i + 6] == "eraser": -        dp[i + 6] = check(i + 6) -        flag4 = dp[i + 6] -    if S[i : i + 5] == "erase": -        dp[i + 5] = check(i + 5) -        flag5 = dp[i + 5] -    return flag0 or flag1 or flag2 or flag3 or flag4 or flag5  # どれかがTrueならOK - - -if check(0): +MOD = 10**9 + 7 +S = list(eval(input())) +i = len(S) - 1 +T = ["dream", "dreamer", "erase", "eraser"] +while i > 0: +    if S[i] == "m": +        for j in range(5): +            if S[i - j] == T[0][4 - j]: +                continue +            else: +                print("NO") +                exit() +        i -= 5 +    elif S[i] == "r": +        if S[i - 2] == "m": +            for j in range(7): +                if S[i - j] == T[1][6 - j]: +                    continue +                else: +                    print("NO") +                    exit() +            i -= 7 +        else: +            for j in range(6): +                if S[i - j] == T[3][5 - j]: +                    continue +                else: +                    print("NO") +                    exit() +            i -= 6 +    else: +        for j in range(5): +            if S[i - j] == T[2][4 - j]: +                continue +            else: +                print("NO") +                exit() +        i -= 5 +if i == -1: