Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
t=0
while t<len(s):
    if s[t]=='d':
        if t>len(s)-5:
            print('NO')
            exit()
        if s[t+1]=='r' and s[t+2]=='e' and s[t+3]=='a' and s[t+4]=='m':
            t+=5
            if t==len(s):
                print('YES')
                exit()
            elif t>len(s)-2:
                print('NO')
                exit()
            if s[t]=='e' and s[t+1]=='r':
                if t==len(s)-2:
                    print('YES')
                    exit()
                elif s[t+2]!='a':
                    t+=2
    elif s[t]=='e':
        if t>len(s)-5:
            print('NO')
            exit()
        if s[t+1]=='r' and s[t+2]=='a' and s[t+3]=='s' and s[t+4]=='e':
            t+=5
            if t==len(s):
                print('YES')
                exit()
            elif t>len(s)-1:
                print('NO')
                exit()
            if s[t]=='r':
                if t==len(s)-1:
                    print('YES')
                    exit()
                elif s[t+1]!='a':
                    t+=1
    else:
        print('NO')
        exit()
print('NO')

Fixed submission:
s=list(input())
n=len(s)
t=n-1
while t>=0:
    if s[t]=='r':
        if t<5:
            print('NO')
            exit()
        elif s[t-1]=='e' and s[t-2]=='s' and s[t-3]=='a' and s[t-4]=='r' and s[t-5]=='e':
            t-=6
        elif t<6:
            print('NO')
            exit()
        elif s[t-1]=='e' and s[t-2]=='m' and s[t-3]=='a' and s[t-4]=='e' and s[t-5]=='r' and s[t-6]=='d':
            t-=7
        else:
            print('NO')
            exit()
    elif s[t]=='e':
        if t<4:
            print('NO')
            exit()
        elif s[t-1]=='s' and s[t-2]=='a' and s[t-3]=='r' and s[t-4]=='e':
            t-=5
        else:
            print('NO')
            exit()
    elif s[t]=='m':
        if t<4:
            print('NO')
            exit()
        elif s[t-1]=='a' and s[t-2]=='e' and s[t-3]=='r' and s[t-4]=='d':
            t-=5
        else:
            print('NO')
            exit()
    else:
        print('NO')
        exit()
print('YES')

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
t=0
while t<len(s):
    if s[t]=='d':
        if t>len(s)-5:
            print('NO')
            exit()
        if s[t+1]=='r' and s[t+2]=='e' and s[t+3]=='a' and s[t+4]=='m':
            t+=5
            if t==len(s):
                print('YES')
                exit()
            elif t>len(s)-2:
                print('NO')
                exit()
            if s[t]=='e' and s[t+1]=='r':
                if t==len(s)-2:
                    print('YES')
                    exit()
                elif s[t+2]!='a':
                    t+=2
    elif s[t]=='e':
        if t>len(s)-5:
            print('NO')
            exit()
        if s[t+1]=='r' and s[t+2]=='a' and s[t+3]=='s' and s[t+4]=='e':
            t+=5
            if t==len(s):
                print('YES')
                exit()
            elif t>len(s)-1:
                print('NO')
                exit()
            if s[t]=='r':
                if t==len(s)-1:
                    print('YES')
                    exit()
                elif s[t+1]!='a':
                    t+=1
    else:
        print('NO')
        exit()

Fixed submission:
s=list(input())
n=len(s)
t=n-1
while t>=0:
    if s[t]=='r':
        if t<5:
            print('NO')
            exit()
        elif s[t-1]=='e' and s[t-2]=='s' and s[t-3]=='a' and s[t-4]=='r' and s[t-5]=='e':
            t-=6
        elif t<6:
            print('NO')
            exit()
        elif s[t-1]=='e' and s[t-2]=='m' and s[t-3]=='a' and s[t-4]=='e' and s[t-5]=='r' and s[t-6]=='d':
            t-=7
        else:
            print('NO')
            exit()
    elif s[t]=='e':
        if t<4:
            print('NO')
            exit()
        elif s[t-1]=='s' and s[t-2]=='a' and s[t-3]=='r' and s[t-4]=='e':
            t-=5
        else:
            print('NO')
            exit()
    elif s[t]=='m':
        if t<4:
            print('NO')
            exit()
        elif s[t-1]=='a' and s[t-2]=='e' and s[t-3]=='r' and s[t-4]=='d':
            t-=5
        else:
            print('NO')
            exit()
    else:
        print('NO')
        exit()
print('YES')