Problem:


Score : 300 points

Problem Statement

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.

Constraints

1≦|S|≦10^5

S consists of lowercase English letters.

Input

The input is given from Standard Input in the following format:

S

Output

If it is possible to obtain S = T, print YES. Otherwise, print NO.

Sample Input 1

erasedream

Sample Output 1

YES

Append erase and dream at the end of T in this order, to obtain S = T.

Sample Input 2

dreameraser

Sample Output 2

YES

Append dream and eraser at the end of T in this order, to obtain S = T.

Sample Input 3

dreamerer

Sample Output 3

NO



Sample input:
erasedream


Sample output:
YES

Submission status: Runtime Error

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    S = input().rstrip()

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

    res = 'YES'

    pre = S
    now = S

    while True:
        for i in range(4):
            word = words[i]
            N = len(word)
            M = len(now)
            if N <= M:
                # l = now[:N]
                r = now[M-N:]
                # if l == word:
                    # now = now[N:]
                if r == word:
                    now = now[:M-N]
            print(now)
        if now == '':
            break
        elif now == pre:
            res = 'NO'
            break
        else:
            pre = now

    print(res)



main()

Submission status: Runtime Error

Solution code:
s = input()
a = 'dream'
b = 'dreamer'
c = 'erase'
d = 'eraser'
while True:
    # 後ろから文字列検索
    # 合ったらその文字を削除
    D = hantei(s, d)
    if D > -1:
        s = s[:-len(d)]
        continue
    B = hantei(s, b)
    if B > -1:
        s = s[:-len(b)]
        continue
    C = hantei(s, c)
    if C > -1:
        s = s[:-len(c)]
        continue
    A = hantei(s, a)
    if A > -1:
        s = s[:-len(a)]
        continue
    if len(s) == 0:
        print('YES')
    else:
        print('NO')
    break


def hantei(s, h):
    try:
        slen = len(s)
        hlen = len(h)
        res = s.index(h, slen - hlen, slen + 1)
        return res
    except ValueError as e:
        return -1

Submission status: Runtime Error

Solution code:
    s = input()
    a = 'dream'
    b = 'dreamer'
    c = 'erase'
    d = 'eraser'
    while True:
        # 後ろから文字列検索
        # 合ったらその文字を削除
        D = hantei(s, d)
        if D > -1:
            s = s[:-len(d)]
            continue
        B = hantei(s, b)
        if B > -1:
            s = s[:-len(b)]
            continue
        C = hantei(s, c)
        if C > -1:
            s = s[:-len(c)]
            continue
        A = hantei(s, a)
        if A > -1:
            s = s[:-len(a)]
            continue
        if len(s) == 0:
            print('YES')
        else:
            print('NO')
        break

Submission status: Runtime Error

Solution code:
g=[]

def  jdream(l,i):
    if len(l)>=i+5:

        if l[i:i+5]=="dream":
            i=i+5
            if i==len(l):
                g.append("Y")
                return
     
            else:
                jer(l,i)
                jdream(l,i)
                return
        else:
            
            return
    else:
        
        return

def jerase(l,i):
    if len(l)>=i+5:

        if l[i:i+5]=="erase":
            i=i+5
            if i==len(l):
                g.append("Y")
                return
            else:
                jr(l,i)
                jerase(l,i)
                jdream(l,i)
                return
        else:
            
            return
    else:
        
        return

def jer(l,i):
    if len(l)>=i+2:

        if l[i:i+2]=="er":
            i=i+2
            if i==len(l):
                g.append("Y")
                return
            else:
                jase(l,i)
                jerase(l,i)
                jdream(l,i)
                return
        else:
            
            return
    else:
        
        return

def jase(l,i):
    if len(l)>=i+3:

        if l[i:i+3]=="ase":
            i=i+3
            if i==len(l):
                g.append("Y")
                return
            else:
                jdream(l,i)
                jerase(l,i)
                jr(l,i)
                return
        else:
            
            return
    else:
        
        return

def jr(l,i):
    if len(l)>=i+1:

        if l[i:i+1]=="r":
            i=i+1
            if i==len(l):
                g.append("Y")
                return
            else:
                jdream(l,i)
                jerase(l,i)
                return
        else:
            
            return

    else:
        
        return

s=input()
n=0
jerase(s,n)
n=0
jdream(s,n)


if 'Y' in g:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
g=[]

def  jdream(l,i):
    if len(l)>=i+5:

        if l[i:i+5]=="dream":
            i=i+5
            if i==len(l):
                g.append("Y")
                return
     
            else:
                jer(l,i)
                jdream(l,i)
                return
        else:
            
            return
    else:
        
        return

def jerase(l,i):
    if len(l)>=i+5:

        if l[i:i+5]=="erase":
            i=i+5
            if i==len(l):
                g.append("Y")
                return
            else:
                jr(l,i)
                jerase(l,i)
                jdream(l,i)
                return
        else:
            
            return
    else:
        
        return

def jer(l,i):
    if len(l)>=i+2:

        if l[i:i+2]=="er":
            i=i+2
            if i==len(l):
                g.append("Y")
                return
            else:
                jase(l,i)
                jerase(l,i)
                jdream(l,i)
                return
        else:
            
            return
    else:
        
        return

def jase(l,i):
    if len(l)>=i+3:

        if l[i:i+3]=="ase":
            i=i+3
            if i==len(l):
                g.append("Y")
                return
            else:
                jdream(l,i)
                jerase(l,i)
                jr(l,i)
                return
        else:
            
            return
    else:
        
        return

def jr(l,i):
    if len(l)>=i+1:

        if l[i:i+1]=="r":
            i=i+1
            if i==len(l):
                g.append("Y")
                return
            else:
                jdream(l,i)
                jerase(l,i)
                return
        else:
            
            return

    else:
        
        return

s=input()
n=0
jerase(s,n)
n=0
jdream(s,n)


if 'Y' in g:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
g=[]

def  jdream(l,i):
    if len(l)>=i+5:

        if l[i:i+5]=="dream":
            i=i+5
            if i==len(l):
                g.append("Y")
                return
     
            else:
                jer(l,i)
                jdream(l,i)
                return
        else:
            g.append("N")
            return
    else:
        g.append("N")
        return

def jerase(l,i):
    if len(l)>=i+5:

        if l[i:i+5]=="erase":
            i=i+5
            if i==len(l):
                g.append("Y")
                return
            else:
                jr(l,i)
                jerase(l,i)
                jdream(l,i)
                return
        else:
            g.append("N")
            return
    else:
        g.append("N")
        return

def jer(l,i):
    if len(l)>=i+2:

        if l[i:i+2]=="er":
            i=i+2
            if i==len(l):
                g.append("Y")
                return
            else:
                jase(l,i)
                jerase(l,i)
                jdream(l,i)
                return
        else:
            g.append("N")
            return
    else:
        g.append("N")
        return

def jase(l,i):
    if len(l)>=i+3:

        if l[i:i+3]=="ase":
            i=i+3
            if i==len(l):
               g.append("Y")
               return
            else:
                jdream(l,i)
                jerase(l,i)
                jr(l,i)
                return
        else:
            g.append("N")
            return
    else:
        g.append("N")
        return

def jr(l,i):
    if len(l)>=i+1:

        if l[i:i+1]=="r":
            i=i+1
            if i==len(l):
                g.append("Y")
                return
            else:
                jdream(l,i)
                jerase(l,i)
                return
        else:
            g.append("N")
            return

    else:
        g.append("N")
        return

s=input()
n=0
jerase(s,n)
n=0
jdream(s,n)


if 'Y' in g:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
g=[]

def  jdream(l,i):
    if len(l)>=i+4:

        if l[i:i+5]=="dream":
            i=i+5
            if i==len(l):
                g.append("Y")
                return
     
            else:
                jer(l,i)
                jdream(l,i)
                return
        else:
            g.append("N")
            return
    else:
        g.append("N")
        return

def jerase(l,i):
    if len(l)>=i+4:

        if l[i:i+5]=="erase":
            i=i+5
            if i==len(l):
                g.append("Y")
                return
            else:
                jr(l,i)
                jerase(l,i)
                jdream(l,i)
                return
        else:
            g.append("N")
            return
    else:
        g.append("N")
        return

def jer(l,i):
    if len(l)>=i+1:

        if l[i:i+2]=="er":
            i=i+2
            if i==len(l):
                g.append("Y")
                return
            else:
                jase(l,i)
                jerase(l,i)
                jdream(l,i)
                return
        else:
            g.append("N")
            return
    else:
        g.append("N")
        return

def jase(l,i):
    if len(l)>=i+2:

        if l[i:i+3]=="ase":
            i=i+3
            if i==len(l):
               g.append("Y")
               return
            else:
                jdream(l,i)
                jerase(l,i)
                jr(l,i)
                return
        else:
            g.append("N")
            return
    else:
        g.append("N")
        return

def jr(l,i):
    if len(l)>=i:

        if l[i:i+1]=="r":
            i=i+1
            if i==len(l):
                g.append("Y")
                return
            else:
                jdream(l,i)
                jerase(l,i)
                return
        else:
            g.append("N")
            return

    else:
        g.append("N")
        return

s=input()
n=0
jerase(s,n)
n=0
jdream(s,n)


if 'Y' in g:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
g=[]

def  jdream(l,i):
    if l[i:i+5]=="dream":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
     
        else:
            jer(l,i)
            jdream(l,i)
            return  
    else:
        g.append("N")
        return

def jerase(l,i):
    if l[i:i+5]=="erase":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
        else:
            jr(l,i)
            jerase(l,i)
            jdream(l,i)
            return
    else:
        g.append("N")
        return

def jer(l,i):
    if l[i:i+2]=="er":
        i=i+2
        if i==len(l):
            g.append("Y")
            return
        else:
            jase(l,i)
            jerase(l,i)
            jdream(l,i)
            return
    else:
        g.append("N")
        return

def jase(l,i):
    if l[i:i+3]=="ase":
        i=i+3
        if i==len(l):
               g.append("Y")
               return
        else:
            jdream(l,i)
            jerase(l,i)
            jr(l,i)
            return
    else:
        g.append("N")
        return

def jr(l,i):
    if l[i:i+1]=="r":
        i=i+1
        if i==len(l):
                g.append("Y")
                return
        else:
            jdream(l,i)
            jerase(l,i)
            return
    else:
        g.append("N")
        return

s=input()
n=0
jerase(s,n)
n=0
jdream(s,n)


if 'Y' in g :
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
g=[]

def  jdream(l,i):
    if l[i:i+5]=="dream":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
     
        else:
            jer(l,i)
            jdream(l,i)
            return  
    else:
        g.append("N")
        return

def jerase(l,i):
    if l[i:i+5]=="erase":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
        else:
            jr(l,i)
            jerase(l,i)
            jdream(l,i)
            return
    else:
        g.append("N")
        return

def jer(l,i):
    if l[i:i+2]=="er":
        i=i+2
        if i==len(l):
            g.append("Y")
            return
        else:
            jase(l,i)
            jerase(l,i)
            jdream(l,i)
            return
    else:
        g.append("N")
        return

def jase(l,i):
    if l[i:i+3]=="ase":
        i=i+3
        if i==len(l):
               g.append("Y")
               return
        else:
            jdream(l,i)
            jerase(l,i)
            jr(l,i)
            return
    else:
        g.append("N")
        return

def jr(l,i):
    if l[i:i+1]=="r":
        i=i+1
        if i==len(l):
                g.append("Y")
                return
        else:
            jdream(l,i)
            jerase(l,i)
            return
    else:
        g.append("N")
        return

s=input()
n=0
jdream(s,n)
n=0
jerase(s,n)


if 'Y' in g :
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
g=[]

def  jdream(l,i):
    if l[i:i+5]=="dream":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
     
        else:
            jer(l,i)
            jdream(l,i)
            return  
    else:
        g.append("N")
        return

def jerase(l,i):
    if l[i:i+5]=="erase":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
        else:
            jr(l,i)
            jerase(l,i)
            jdream(l,i)
            return
    else:
        g.append("N")
        return

def jer(l,i):
    if l[i:i+2]=="er":
        i=i+2
        if i==len(l):
            g.append("Y")
            return
        else:
            jase(l,i)
            jerase(l,i)
            jdream(l,i)
            return
    else:
        g.append("N")
        return

def jase(l,i):
    if l[i:i+3]=="ase":
        i=i+3
        if i==len(l):
               g.append("Y")
               return
        else:
            jdream(l,i)
            jerase(l,i)
            jr(l,i)
            return
    else:
        g.append("N")
        return

def jr(l,i):
    if l[i:i+1]=="r":
        i=i+1
        if i==len(l):
                g.append("Y")
                return
        else:
            jdream(l,i)
            jerase(l,i)
            return
    else:
        g.append("N")
        return

s=input()
n=0
jdream(s,n)
n=0
jerase(s,n)

print(g)
if 'Y' in g :
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
g=[]

def  jdream(l,i):
    if l[i:i+5]=="dream":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
     
        else:
            jer(l,i)
            jdream(l,i)
            return  
    else:
        g.append("N")
        return

def jerase(l,i):
    if l[i:i+5]=="erase":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
        else:
            jr(l,i)
            jerase(l,i)
            jdream(l,i)
            return
    else:
        g.append("N")
        return

def jer(l,i):
    if l[i:i+2]=="er":
        i=i+2
        if i==len(l):
            g.append("Y")
            return
        else:
            jase(l,i)
            jerase(l,i)
            jdream(l,i)
            return
    else:
        g.append("N")
        return

def jase(l,i):
    if l[i:i+3]=="ase":
        i=i+3
        if i==len(l):
               g.append("Y")
               return
        else:
            jdream(l,i)
            jerase(l,i)
            jr(l,i)
            return
    else:
        g.append("N")
        return

def jr(l,i):
    if l[i:i+1]=="r":
        i=i+1
        if i==len(l):
                g.append("Y")
                return
        else:
            jdream(l,i)
            jerase(l,i)
            return
    else:
        g.append("N")
        return

l=input()
n=0

jdream(l,n)
jerase(l,n)

print(g)
if 'Y' in g :
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
g=[]

def  jdream(l,i):
    if l[i:i+5]=="dream":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
     
        else:
            jer(l,i)
            jdream(l,i)
            return  
    else:
        g.append("N")
        return

def jerase(l,i):
    if l[i:i+5]=="erase":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
        else:
            jr(l,i)
            jerase(l,i)
            jdream(l,i)
            return
    else:
        g.append("N")
        return

def jer(l,i):
    if l[i:i+2]=="er":
        i=i+2
        if i==len(l):
            g.append("Y")
            return
        else:
            jase(l,i)
            jerase(l,i)
            jdream(l,i)
            return
    else:
        g.append("N")
        return

def jase(l,i):
    if l[i:i+3]=="ase":
        i=i+3
        if i==len(l):
               g.append("Y")
               return
        else:
            jdream(l,i)
            jerase(l,i)
            jr(l,i)
            return
    else:
        g.append("N")
        return

def jr(l,i):
    if l[i:i+1]=="r":
        i=i+1
        if i==len(l):
                g.append("Y")
                return
        else:
            jdream(l,i)
            jerase(l,i)
            return
    else:
        g.append("N")
        return

s=input()
n=0
m=len(s)


jdream(s,n)
jerase(s,n)

print(g)
if 'Y' in g :
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
g=[]

def  jdream(l,i):
    if l[i:i+5]=="dream":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
     
        else:
            jer(l,i)
            jdream(l,i)
            return  
    else:
        g.append("N")
        return

def jerase(l,i):
    if l[i:i+5]=="erase":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
        else:
            jr(l,i)
            jerase(l,i)
            jdream(l,i)
            return
    else:
        g.append("N")
        return

def jer(l,i):
    if l[i:i+2]=="er":
        i=i+2
        if i==len(l):
            g.append("Y")
            return
        else:
            jase(l,i)
            jerase(l,i)
            jdream(l,i)
            return
    else:
        g.append("N")
        return

def jase(l,i):
    if l[i:i+3]=="ase":
        i=i+3
        if i==len(l):
               g.append("Y")
               return
        else:
            jdream(l,i)
            jerase(l,i)
            jr(l,i)
            return
    else:
        g.append("N")
        return

def jr(l,i):
    if l[i:i+1]=="r":
        i=i+1
        if i==len(l):
                g.append("Y")
                return
        else:
            jdream(l,i)
            jerase(l,i)
            return
    else:
        g.append("N")
        return

s=input()
n=0
m=len(s)


jdream(s,n)
jerase(s,n)

if "Y" in g :
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
g=[]

def  jdream(l,i):
    if l[i:i+5]=="dream":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
     
        else:
            return(jer(l,i),jdream(l,i))    
    else:
        g.append("N")
        return

def jerase(l,i):
    if l[i:i+5]=="erase":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
        else:
            return(jr(l,i),jerase(l,i),jdream(l,i))
    else:
        g.append("N")
        return

def jer(l,i):
    if l[i:i+2]=="er":
        i=i+2
        if i==len(l):
            g.append("Y")
            return
        else:
            return(jase(l,i),jerase(l,i),jdream(l,i))
    else:
        g.append("N")
        return

def jase(l,i):
    if l[i:i+3]=="ase":
        i=i+3
        if i==len(l):
               g.append("Y")
               return
        else:
            return(jdream(l,i),jerase(l,i),jr(l,i))
    else:
        g.append("N")
        return

def jr(l,i):
    if l[i:i+1]=="r":
        i=i+1
        if i==len(l):
                g.append("Y")
                return
        else:
            return(jdream(l,i),jerase(l,i))
    else:
        g.append("N")
        return

s=input()
n=0
m=len(s)


jdream(s,n)
jerase(s,n)

if "Y" in g :
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
g=[]

def  jdream(l,i):
    if l[i:i+5]=="dream":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
     
        else:
            return(jer(l,i),jdream(l,i))    
    else:
        g.append("N")
        return

def jerase(l,i):
    if l[i:i+5]=="erase":
        i=i+5
        if i==len(l):
            g.append("Y")
            return
        else:
            return(jr(l,i),jerase(l,i),jdream(l,i))
    else:
        g.append("N")
        return

def jer(l,i):
    if l[i:i+2]=="er":
        i=i+2
        if i==len(l):
            g.append("Y")
            return
        else:
            return(jase(l,i),jerase(l,i),jdream(l,i))
    else:
        g.append("N")
        return

def jase(l,i):
    if l[i:i+3]=="ase":
        i=i+3
        if i==len(l):
               g.append("Y")
               return
        else:
            return(jdream(l,i),jerase(l,i),jr(l,i))
    else:
        g.append("N")
        return

def jr(l,i):
    if l[i:i+1]=="r":
        i=i+1
        if i==len(l):
                g.append("Y")
                return
        else:
            return(jdream(l,i),jerase(l,i))
    else:
        g.append("N")
        return

s=input()
n=0
m=len(s)


jdream(s,n)
jerase(s,n)

if "Y" in g :
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2000)

S = input()
pos = False
add = ["dream", "dreamer", "erase", "eraser"]
def recur(T):
    global pos
    if T == S:
        pos = True
        return
    for a in add:
        if len(T + a) <= len(S):
            recur(T + a)
recur("")
if pos:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
S = input()
pos = False
add = ["dream", "dreamer", "erase", "eraser"]
def recur(T):
    global pos
    if T == S:
        pos = True
        return
    for a in add:
        if len(T + a) <= len(S):
            recur(T + a)
recur("")
if pos:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s_init = input()
s_list = list(reversed(s_init))
s = ''.join(s_list)
t = ""
words = ["maerd", "remaerd", 'esare', 'resare']
s_list = list(s)
t_list = list(t)
while s != t:
    t_fixed = t
    if len(s_list) < len(t_list):
        break
    elif t == 'gameover':
        break
    else:
        for word in words:
            if s.startswith(t + word):
                t = t + word
                break
        if t = t_fixed:
            t == 'gameover'
if s == t:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
S = input()

while S:
    if S[:7] == 'dreamer' and S[7] != 'a':
        S = S[7:]
    elif S[:6] == 'eraser':
        S = S[6:]
    elif S[:5] == 'dream':
        S = S[5:]
    elif S[:5] == 'erase':
        S = S[5:]
    else:
        print('No')
        exit()

print('Yes')

Submission status: Runtime Error

Solution code:
s = input()
T = ['dream', 'dreamer', 'erase', 'eraser']

def solution():
    while True:
        match = False
        for ss in T:
            if s.startswith(ss):
                s = s.lstrip(ss)
                if not s:
                    print('YES')
                    return
                match = True
                break
        if not match:
            print('NO')
            return

solution()

Submission status: Runtime Error

Solution code:
S = input()
T = ""

i = 0
while i <= len(S) - 7:
    if  S[i] == "d":
        if S[i+5] == "d" or S[i+7] == "a":
            T += "dream"
            i += 5
        else:
            T += "dreamer"
            i += 7
    else:
        if S[i+5] == "r":
            T += "eraser"
            i += 7
        else:
            T += "erase"
            i += 5

if S == T+"dream" or S == T+"dreamer" or S == T+"erase" or S == T+"eraser":
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
#ABC 049 C
S = input()
T = ''
S = S[::-1]
words = ["dream","dreamer","erase","eraser"]
rev_words = [w[::-1] for w in words]

i=0
while(1):
	for w in rev_words:
		s = S[i:i+len(w)]
		if s == w:
			flag = True
			T += w
			i += len(w)
			break
	if T == S:
		ans = "YES"
		break
	if flag == False:
		ans = 'NO'
		break
	flag = False
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
T = ''

S = S[::-1]
words = ["dream","dreamer","erase","eraser"]
rev_words = [w[::-1] for w in words]

i=0
while(1):
	for w in rev_words:
		s = S[i:i+len(w)]
		if s == w:
			flag = True
			T += w
			i += len(w)
			break
	if T == S:
		ans = "YES"
		break
	if flag == False:
		ans = 'NO'
		break
	flag = False

print(ans)

Submission status: Runtime Error

Solution code:
S = input()
Temp = ''

def Tcmp(T, moji):
	T += moji
	
	if (S == T):
		return 1
	if len(T) > len(S):
		return 0
	
	if (moji == "dream"):
		return max(Tcmp(T,""),Tcmp(T,"er"))
	elif(moji == "eras"):
		return max(Tcmp(T,"e"),Tcmp(T,"er"))
	else:
		return max(Tcmp(T,"dream"),Tcmp(T,"eras"))

if(Tcmp(Temp,"")):
	print("YES")
else:
	print("NO")

Submission status: Runtime Error

Solution code:
S = input()
T = ''

def Tcmp(T, moji):
	T += moji
	
	if (S == T):
		return 1
	if len(T) > len(S):
		return 0
	
	if (moji == "dream"):
		return max(Tcmp(T,""),Tcmp(T,"er"))
	elif(moji == "eras"):
		return max(Tcmp(T,"e"),Tcmp(T,"er"))
	else:
		return max(Tcmp(T,"dream"),Tcmp(T,"eras"))

if(Tcmp(T,"")):
	print("YES")
else:
	print("NO")

Submission status: Runtime Error

Solution code:
S = input()
T = ''

def Tcmp(T, moji):
	
	T += moji
	
	if (S == T):
		return 1
	if len(T) > len(S):
		return 0
	
	if (moji == "dream"):
		return max(Tcmp(T,""),Tcmp(T,"er"))
	elif(moji == "eras"):
		return max(Tcmp(T,"e"),Tcmp(T,"er"))
	else:
		return max(Tcmp(T,"dream"),Tcmp(T,"eras"))

if(Tcmp(T,"")):
	print("YES")
else:
	print("NO")

Submission status: Runtime Error

Solution code:
S=input()

for i in range(10000):
  if S[-6:]=="dreamer" or S[-6:]=="eraser":
    S=S[:-6]
  elif S[-5:]=="dream" or S[-5:]=="erase":
    S=S[:-5]
  else:
    pass
  if S=[]:
    print("YES")
    break
else:
  print("NO")

Submission status: Runtime Error

Solution code:
#049_C
s = input()

def dfs(x):
    if x == s:
        return True
    if len(x) > len(s):
        return False

    if any (dfs(x + k) for k in ['dream', 'dreamer', 'erase', 'eraser']):
        return True
    
    return False

print('YES' if dfs('') else 'NO')

Submission status: Runtime Error

Solution code:
def check(string):
  l = len(string)

  if l == 0:
    return True
  
  if l < 5:
    return False

  if string[0:5] == 'dream':
    if check(string[5:]):
      return True
    if l >= 7 and string[0:7] == 'dreamer':
      if check(string[7:]):
        return True
  elif string[0:5] == 'erase':
    if check(string[5:]):
      return True
    if l >= 6 and string[0:6] == 'eraser':
      if check(string[6:]):
        return True
  
  return False

S = input()
if check(S):
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
patterns = ['dream', 'dreamer' , 'erase', 'eraser'] 

def check(string):
  l = len(string)

  if l == 0:
    return True
  
  if l < 5:
    return False

  if string[0:5] == 'dream':
    if check(string[5:]):
      return True
    if l >= 7 and check(string[7:]):
      return True
  elif string[0:5] == 'erase':
    if check(string[5:]):
      return True
    if l >= 6 and check(string[6:]):
      return True
  else:
    return False
  
  return False

S = input()
if check(S):
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
patterns = ['dream', 'dreamer' , 'erase', 'eraser'] 

def check(string):
  if len(string) == 0:
    return True
  if string[0:5] == 'dream':
    if check(string[5:]):
      return True
    if check(string[7:]):
      return True
  elif string[0:5] == 'erase':
    if check(string[5:]):
      return True
    if check(string[6:]):
      return True
  else:
    return False
  
  return False

S = input()
if check(S):
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
S = input()

if S.replace("dream"," ").replace("dreamer"," ").replace("erase"," ").replace("eraser"," "):
  print("NO")
else:
  print("YES

Submission status: Runtime Error

Solution code:
S = input()

if S.replace("dream"," ").replace("dreamer"," ").replace.("erase"," ").replace("eraser"," "):
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
S = input()

if S.replace("dream",).replace("dreamer",).replace.("erase",).replace("eraser",):
  print("NO")
else:
  print("YES")

Submission status: Runtime Error

Solution code:
txt = input()
cands = ["dream", "dreamer", "erase", "eraser"]

success = True
while len(txt) > 0:
    flag = False

    for cand in cands:
        subtxt = txt[len(txt) - len(cand):]
        if subtxt == cand:
            txt = txt[:len(txt) - len(cand)]
            flag = True
            print(txt)
            break

    if not flag:
        success = False
        break

if success:
    print("YES")
else:
    print("No")

Submission status: Runtime Error

Solution code:
S=input()

def func(S):
    if S[:7]=="dreamer":
        return min(func(S[5:]),func(S[7:]))
    elif S[:6]=="eraser":
        return min(func(S[5:]),func(S[6:]))
    elif S[:5]=="dream":
        return func(S[5:])
    elif S[:5]=="erase":
        return func(S[5:])
    
    return len(S) 
    

if func(S)==0:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s = inpput()
while True:
	S = s
	if len(S) < 5:
		print('NO')
		break
	if S == 'dream' or S == 'erase':
		print('YES')
		break
	else:
		if S[0] == 'd':
			if S[7] == 'a':
				T ='dream'
				if S[:5] == T:
					S = S[5:]
					T = ""
					if S == "":
						print('YES')
						break
					s = S
				else:
					print('NO')
					break
			else:
				T = 'dreamer'
				if S[:7] == T:
					S = S[7:]
					T = ""
					if S == "":
						print('YES')
						break
					s = S
				else:
					print('NO')
					break
		if S[0] == 'e':
			if len(S) >= 6 and S[5] == 'r':
				T = 'eraser'
				if S[:6] == T:
					S = S[6:]
					T = ""
					if S == "":
						print('YES')
						break
					s = S
				else:
					print('NO')
					break
			else:
				T = 'erase'
				if S[:5] == T:
					S = S[5:]
					T = ""
					if S == "":
						print('YES')
						break
					s = S
				else:
					print('NO')
					break
		else:
			print('NO')
			break