Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
# S = list("dreameraser"*2*10**5)
strs = ["dream","dreamer","erase","eraser"]
ind = 0
while True:
    if S[ind] == "e":
        if S[ind:ind+5] == list("erase"):
            if ind+5 == len(S): 
                print("YES")
                exit()
            if S[ind+5] == "r": 
                if ind + 6 ==len(S):
                    print("YES")
                    exit()
                ind+=6 #eraserで確定
            elif S[ind+5] == "d" or S[ind+5]=="e": 
                ind+=5 #dreamかeraser
            else:
                print("NO")
                exit()
        else:
            print("NO")
            exit()
    elif S[ind] == "d":
        if S[ind:ind+5] == list("dream"):
            if ind + 5 == len(S):
                print("YES")
                exit()
            if S[ind+5] == "d" : ind += 5 #"dreamで確定"
            elif S[ind+5] == "e":
                if S[ind+6] == "r":
                    if ind + 7 == len(S):
                        print("YES")
                        exit()
                    if S[ind+7] == "e" or S[ind+7] =="d": ind += 7 #dreamerで確定
                    elif S[ind+7] == "a": ind += 5 #"dream->eraseで確定"
                else:
                    print("NO")
                    exit()
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()
    # print(ind,S[ind])


# S = input()
# strs = ["dream","dreamer","erase","eraser"]
# ind = 0
# while True:
#     if S[ind] == "e":
#         if S[ind:ind+5] == "erase":
#             if ind+5 == len(S): 
#                 print("YES")
#                 exit()
#             if S[ind+5] == "r": 
#                 if ind + 6 ==len(S):
#                     print("YES")
#                     exit()
#                 ind+=6 #eraserで確定
#             elif S[ind+5] == "d" or S[ind+5]=="e": 
#                 ind+=5 #dreamかeraser
#             else:
#                 print("NO")
#                 exit()
#         else:
#             print("NO")
#             exit()
#     elif S[ind] == "d":
#         if S[ind:ind+5] == "dream":
#             if ind + 5 == len(S):
#                 print("YES")
#                 exit()
#             if S[ind+5] == "d" : ind += 5 #"dreamで確定"
#             if S[ind+5] == "e":
#                 if S[ind+6] == "r":
#                     if ind + 7 == len(S):
#                         print("YES")
#                         exit()
#                     if S[ind+7] == "e" or S[ind+7] =="d": ind += 7 #dreamerで確定
#                     elif S[ind+7] == "a": ind += 5 #"dream->eraseで確定"
#                 else:
#                     print("NO")
#                     exit()
#         else:
#             print("NO")
#             exit()
#     else:
#         print("NO")
#         exit()
#     # print(ind,S[ind])

Fixed submission:
S = input()
strs = ["erase", "eraser", "dreamer","dream"]
rtss = [s[::-1] for s in strs]
S = S[::-1]

ind = 0
while True:
    # print(ind,S[ind])
    if S[ind:ind+5] in rtss:
        ind += 5
    elif S[ind:ind+6] in rtss:
        ind += 6
    elif S[ind:ind+7] in rtss:
        ind +=7
    else:
        print("NO")
        exit()
    if ind == len(S):
        print("YES")
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
strs = ["dream","dreamer","erase","eraser"]
ind = 0
while True:
    if S[ind] == "e":
        if S[ind:ind+5] == list("erase"):
            if ind+5 == len(S): 
                print("YES")
                exit()
            if S[ind+5] == "r": 
                if ind + 6 ==len(S):
                    print("YES")
                    exit()
                ind+=6 #eraserで確定
            elif S[ind+5] == "d" or S[ind+5]=="e": 
                ind+=5 #dreamかeraser
            else:
                print("NO")
                exit()
        else:
            print("NO")
            exit()
    elif S[ind] == "d":
        if S[ind:ind+5] == list("dream"):
            if ind + 5 == len(S):
                print("YES")
                exit()
            if S[ind+5] == "d" : ind += 5 #"dreamで確定"
            if S[ind+5] == "e":
                if S[ind+6] == "r":
                    if ind + 7 == len(S):
                        print("YES")
                        exit()
                    if S[ind+7] == "e" or S[ind+7] =="d": ind += 7 #dreamerで確定
                    elif S[ind+7] == "a": ind += 5 #"dream->eraseで確定"
                else:
                    print("NO")
                    exit()
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()

Fixed submission:
S = input()
strs = ["erase", "eraser", "dreamer","dream"]
rtss = [s[::-1] for s in strs]
S = S[::-1]

ind = 0
while True:
    # print(ind,S[ind])
    if S[ind:ind+5] in rtss:
        ind += 5
    elif S[ind:ind+6] in rtss:
        ind += 6
    elif S[ind:ind+7] in rtss:
        ind +=7
    else:
        print("NO")
        exit()
    if ind == len(S):
        print("YES")
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
strs = ["dream","dreamer","erase","eraser"]
ind = 0
while True:
    # print(ind,S[ind])
    if S[ind] == "e":
        if S[ind:ind+5] == "erase":
            if ind+5 == len(S): 
                print("YES")
                exit()
            if S[ind+5] == "r": 
                if ind + 6 ==len(S):
                    print("YES")
                    exit()
                ind+=6 #eraserで確定
            elif S[ind+5] == "d" or S[ind+5]=="e": 
                ind+=5 #dreamかeraser
            else:
                print("NO")
                exit()
        else:
            print("NO")
            exit()
    elif S[ind] == "d":
        if S[ind:ind+5] == "dream":
            if ind + 5 == len(S):
                print("YES")
                exit()
            if S[ind+5] == "d" :ind += 5 #"dreamで確定"
            if S[ind+5] == "e":
                if S[ind+6] == "r":
                    if ind + 7 == len(S):
                        print("YES")
                        exit()
                    if S[ind+7] == "e" or S[ind+7] =="d": ind += 7 #dreamerで確定
                    elif S[ind+7] == "a": ind += 5 #"dream->eraseで確定"
                else:
                    print("NO")
                    exit()
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()
    # print(ind,S[ind])

Fixed submission:
S = input()
strs = ["erase", "eraser", "dreamer","dream"]
rtss = [s[::-1] for s in strs]
S = S[::-1]

ind = 0
while True:
    # print(ind,S[ind])
    if S[ind:ind+5] in rtss:
        ind += 5
    elif S[ind:ind+6] in rtss:
        ind += 6
    elif S[ind:ind+7] in rtss:
        ind +=7
    else:
        print("NO")
        exit()
    if ind == len(S):
        print("YES")
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
strs = ["dream","dreamer","erase","eraser"]
ind = 0
while True:
    # print(ind,S[ind])
    if S[ind] == "e":
        if S[ind:ind+5] == "erase":
            if ind+5 == len(S): 
                print("YES")
                exit()
            if S[ind+5] == "r": 
                if ind + 6 ==len(S):
                    print("YES")
                    exit()
                ind+=6 #eraserで確定
            elif S[ind+5] == "d" or S[ind+5]=="e": 
                ind+=5 #dreamかeraser
            else:
                print("NO")
                exit()
        else:
            print("NO")
            exit()
    elif S[ind] == "d":
        if S[ind:ind+5] == "dream":
            if ind + 5 == len(S):
                print("YES")
                exit()
            if S[ind+5] == "d" :ind += 5 #"dreamで確定"
            if S[ind+5] == "e":
                if S[ind+6] == "r":
                    if ind + 7 == len(S):
                        print("YES")
                        exit()
                    if S[ind+7] == "e" or S[ind+7] =="d": ind += 7 #dreamerで確定
                    elif S[ind+7] == "a": ind += 5 #"dream->eraseで確定"
                else:
                    print("NO")
                    exit()
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()
    # print(ind,S[ind])

Fixed submission:
S = input()
strs = ["erase", "eraser", "dreamer","dream"]
rtss = [s[::-1] for s in strs]
S = S[::-1]

ind = 0
while True:
    # print(ind,S[ind])
    if S[ind:ind+5] in rtss:
        ind += 5
    elif S[ind:ind+6] in rtss:
        ind += 6
    elif S[ind:ind+7] in rtss:
        ind +=7
    else:
        print("NO")
        exit()
    if ind == len(S):
        print("YES")
        exit()