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

Solution (Python):
s = input()
n = len(s)
e = 0
def judge(a,b,c):
    if c[a-5:a] == "erase":
        b = 5
        return b
    elif c[a-5:a] == "dream":
        b = 5
        return b
    elif c[a-6:a] == "eraser":
        b = 6
        return b
    elif c[a-7:a] == "dreamer":
        b = 7
        return b
    else:
        return 100
while n >= 5:
    e = judge(n,e,s)
    if e == 100:
        break
    else:
        n = n - e
if n == 0:
    print("YES")
else:
    print("NO")

Solution (Python):
s = list(input())
n = len(s)
t = ["resare","esare","remaerd","maerd"]
s.reverse()
check = True
i = 0
while i < n:
    counter = 0 
    for k in range(4):
        temp = True
        for j in range(len(t[k])):
            if s[i+j] != t[k][j]:
                temp = False
                break
        if temp == False:
            counter += 1
        else:
            add = len(t[k])
    if counter == 4:
        check = False
        break
    else:
        i += add
if check:
    print("YES")
else:
    print("NO")

Solution (Python):
s=input()
n=len(s)
e=n
while e>8:
    if(s[e-5:e]=="dream" or s[e-5:e]=="erase"):
        e-=5
    elif(s[e-6:e]=="eraser"):
        e-=6
    elif(s[e-7:e]=="dreamer"):
        e-=7
    else:
        print("NO")
        break
else:
    if(s[:e]=="dream" or s[:e]=="erase" or s[:e]=="eraser" or s[:e]=="dreamer"):
        print("YES")
    else:
        print("NO")

Solution (Python):
s=list(input())
s1=reversed(s)
l=["dream","dreamer","erase","eraser"]
s2=[]
for item in s1:
  s2.insert(0,item)
  str=''.join(s2)
  if str in l:
    s2=[]
  elif len(s2)>7:
    break
if len(s2)==0:
  print("YES")
else:
  print("NO")

Solution (Python):
S = input()
S = S.replace("eraser", "")
S = S.replace("erase", "")
S = S.replace("dreamer", "")
S = S.replace("dream", "")
print("YES") if not S else print("NO")

Solution (Python):
s = input()[::-1]
words = [w[::-1] for w in ['dream', 'dreamer', 'erase', 'eraser']]

can = 'YES'
while s:
    match_any = False
    for w in words:
        if s.startswith(w):
            s = s.replace(w, '', 1)
            match_any = True
            break
    if not match_any:
        can = 'NO'
        break
print(can)

Solution (Python):
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s:
    print("NO")
else:
    print("YES")

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

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

def solve():
    s = input()

    s = s[::-1]

    for i in range(4):
        a[i] = a[i][::-1]
    
    t = ''

    while t!=s:
        ok = False
        for i in a:
            temp = t+i
            if len(temp)<= len(s) and temp == s[:len(temp)]:
                t = temp
                ok = True
                continue
        if not ok:
            print('NO')
            return

        



    print('YES')



solve()

Solution (Python):
S = input()
targets = ["dream", "dreamer", "erase", "eraser"]
while True:
    isEndTarget = False
    for target in targets:
        if S.endswith(target):
            S = S[: -len(target)]
            isEndTarget = True
            break
    if not isEndTarget:
        print("NO")
        break
    elif S == "":
        print("YES")
        break

Solution (Python):
S = input()
targets = ['dream', 'dreamer', 'erase', 'eraser']
while True:
    isEndTarget = False
    for target in targets:
        if S.endswith(target):
            S = S[:-len(target)]
            isEndTarget = True
            break
    if not isEndTarget:
        print('NO')
        break
    elif S == '':
        print('YES')
        break

Solution (Python):
S = input()

result = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")

if result:
  print("NO")
else:
  print("YES")

Solution (Python):
s = input().strip()[::-1]

valid = True
while len(s) > 0:
    if s[:6] == 'eraser'[::-1]:
        s = s[6:]
    elif s[:5] == 'erase'[::-1]:
        s = s[5:]
    elif s[:7] == 'dreamer'[::-1]:
        s = s[7:]
    elif s[:5] == 'dream'[::-1]:
        s = s[5:]
    else:
        valid = False
        break


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

Solution (Python):
s=input()
s=s[::-1]
while True:
    if s[0:5]=="maerd":
        s=s[5:]
    elif s[0:7]=="remaerd":
        s=s[7:]
    elif s[0:5]=="esare":
        s=s[5:]
    elif s[0:6]=="resare":
        s=s[6:]
    else:
        break
if s=="":
    print("YES")
else:
    print("NO")

Solution (Python):
s=input()
seq_list=["dream","dreamer","erase","eraser"]
while s:
    for seq in seq_list:
        if s.endswith(seq):
            s=s[:-len(seq)]
            break
    else:
        print("NO")
        break
else:
    print("YES")

Solution (Python):
def main():
    S = input()

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

    while len(S) > 0:
        for word in word_list:
            flag = "NO"
            if S[len(S) - len(word):] == word:
                S = S[:len(S) - len(word)]
                flag = "YES"
                break

        if flag == "NO":
            break
    print(flag)

main()

Solution (Python):
S = input()
cands = ["dream", "dreamer", "erase", "eraser"]
cands = [cand[::-1] for cand in cands]

S = S[::-1]
check = True
i = 0
while i < len(S):
  if S[i:i+7] == cands[1]:
    i += 7
  elif S[i:i+6] == cands[3]:
    i += 6
  elif S[i:i+5] in cands:
    i += 5
  else:
    check = False
    break   
  

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

Solution (Python):

import sys
S = input()

while len(S) >= 5:
    if len(S) >= 7 and S[-7:] == "dreamer":
        S = S[:-7]
        continue
    if len(S) >= 6 and S[-6:] == "eraser":
        S = S[:-6]
        continue
    if S[-5:] == "erase" or S[-5:] == "dream":
        S = S[:-5]
        continue
    else:
        print("NO")
        sys.exit()

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

Solution (Python):
from sys import stdin
S=(stdin.readline().rstrip())
while 1:
    cnt=4
    for i in ["dream","dreamer","erase","eraser"]:
        if S[-len(i):] == i:
            S = S[:(len(S)-len(i))]
        else:
            cnt-=1
            
    if S == "":
        print("YES")
        break
        
    if cnt == 0:
        print("NO")
        break

Solution (Python):
s = input()
t = ''
while s:
    a = ''
    for i in ['eraser', 'erase', 'dreamer', 'dream']:
        if s.endswith(i) : a = i; break
    if a == '' : print('NO');exit()
    s = s[:-len(a)]
print('YES')

Solution (Python):
s = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
print('YES' if len(s) == 0 else 'NO')

Solution (Python):
word_list = ("dream", "dreamer", "erase", "eraser")

s = input()

i = 0
while i < len(s):
    if s[i:i+11] == "dreameraser":
        i += 11
    elif s[i:i+10] == "dreamerase":
        i += 10
    elif s[i:i+7] == word_list[1]:
        i += 7
    elif s[i:i+6] == word_list[3]:
        i += 6
    elif s[i:i+5] == word_list[0] or s[i:i+5] == word_list[2]:
        i += 5
    else:
        print("NO")
        exit()

print("YES")

Solution (Python):
S = input()
flag = True
while flag:
    if S[:7] == 'dreamer':
        if S[:10] == 'dreamerase':
            S = S[5:]
        else:
            S = S[7:]
    elif S[:5] == 'dream':
        S = S[5:]
    elif S[:6] == 'eraser':
        S = S[6:]
    elif S[:5] == 'erase':
        S = S[5:]
    else:
        flag = False
if S:
    print('NO')
else:
    print('YES')

Solution (Python):
s = input().replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')
if s:
    print('NO')
else:
    print('YES')

Solution (Python):
import sys
s = input()[::-1]

s_list = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]

while True:
  flag = False
  for l in s_list:
    if s[0:len(l)] == l:
      s = s[len(l):]
      flag = True
  if s == '':
    print('YES')
    sys.exit()
  if flag == False:
    print('NO')
    sys.exit()

Solution (Python):
S = input()
S = S.replace('eraser','')
S = S.replace('erase','')
S = S.replace('dreamer','')
S = S.replace('dream','')

if len(S) == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
s=input().replace('eraser' , '').replace('erase' , '').replace('dreamer' , '').replace('dream' , '')
if s:
	print('NO')
else:
	print('YES')

Solution (Python):
S = input()

while len(S) >= 5:
    if S[-5:] == 'dream':
        S = S[:-5]
    elif S[-7:] == 'dreamer':
        S = S[:-7]
    elif S[-5:] == 'erase':
        S = S[:-5]
    elif S[-6:] == 'eraser':
        S = S[:-6]
    else:
        break
print('YES' if S == '' else 'NO')

Solution (Python):
s = input()
s = s[::-1]
word_list = ['dream', 'dreamer', 'erase', 'eraser']
reversed_list = []
for w in word_list:
    reversed_list.append(w[::-1])

can_divide = True
i = 0
while i < len(s):
    
    temp_can = False
    for w in reversed_list:
        if s[i:i+len(w)] == w:
            temp_can = True
            i += len(w)
    if not temp_can:
        
        can_divide = False 
        break

if can_divide:
    print('YES')
else:
    print('NO')

Solution (Python):

def list_join(l: []):
    word_list = ['dream', 'dreamer', 'erase', 'eraser']
    nl = []
    for ele in l:
        for word in word_list:
            nl.append(ele + word)
    return nl


def main():
    S = str(input())
    
    lst = ['']
    while True:
        lst = list_join(lst)
        lst = list(filter(lambda word: S.startswith(word), lst))
        if len(lst) == 0:
            print('NO')
            return
        if S in lst:
            print('YES')
            return


if __name__ == '__main__':
    main()

Solution (Python):
ls = ['dream', 'dreamer', 'erase', 'eraser']
ls = [word[::-1] for word in ls]
s = input().rstrip()[::-1]

can = 1
i = 0
while i < len(s):
    div = 0
    for word in ls:
        if s[i:i+len(word)] == word:
            div = 1
            i += len(word)
            break
    if div == 0:
        can = 0
        break

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

Solution (Python):
import sys
input = sys.stdin.readline

S = list(reversed(input().strip()))
P = [list(reversed(v)) for v in ["dream", "dreamer", "erase", "eraser"]]

n = 0
while n < len(S):
    if S[n:n+5] == P[0] or S[n:n+5] == P[2]:
        n += 5
    elif S[n:n+7] == P[1]:
        n += 7
    elif S[n:n+6] == P[3]:
        n += 6
    else:
        print("NO")
        exit()
        
print("YES")

Solution (Python):
import re
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$", input()) else "NO")

Solution (Python):
import re
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$", input()) else 'NO')

Solution (Python):
S = input()
s = ''
ar = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(1, len(S)+1):
    s = S[-i] + s
    if s in ar:
        s = ''
    if len(s) > 10:
        break

if len(s) == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
import re

S = input()
S = S[::-1] 

pattern = ["dream", "dreamer", "erase", "eraser"]

for i in range(len(pattern)):
    pattern[i] = pattern[i][::-1]

fin = False
while not fin:
    if S == '':
        print("YES")
        exit()
    fin = True
    for x in pattern:
        if re.match(x, S):
            S = S.replace(x, "", 1)
            fin = False
            break

print("NO")

Solution (Python):
s=str(input())
while len(s)>=1:
    if s[-5:]=="erase":
        s=s[:-5]
    elif s[-5:]=="dream":
        s=s[:-5]
    elif s[-6:]=="eraser":
        s=s[:-6]
    elif s[-7:]=="dreamer":
        s=s[:-7]
    else:
        break

print("YNEOS"[len(s)>0::2])

Solution (Python):
S = input()

i = 0
while True:
    if i >= len(S):
        print('YES')
        break
    if S[i:i+5] == 'dream':
        if S[i+5:i+10] == 'erase':
            if S[i+10:i+11] == 'r':
                i += 11
            else:
                i += 10
        elif S[i+5:i+7] == 'er':
            i += 7
        else:
            i += 5
    elif S[i:i+5] == 'erase':
        if S[i+5:i+6] == 'r':
            i += 6
        else:
            i += 5
    else:
        print('NO')
        break

Solution (Python):
def main():
    S = input()

    while len(S) >= 5:
        if len(S) >= 7 and S[-7:] == "dreamer":
            S = S[:-7]
            continue

        if len(S) >= 6 and S[-6:] == "eraser":
            S = S[:-6]
            continue

        if S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue

        break

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

main()

Solution (Python):
def main():
    S = input()

    while len(S) >= 5:
        if len(S) >= 7 and S[-7:] == "dreamer":
            S = S[:-7]
            continue

        if len(S) >= 6 and S[-6:] == "eraser":
            S = S[:-6]
            continue

        elif S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue

        else:
            break

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

main()

Solution (Python):
import re
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$",input()) else "NO")

Solution (Python):
import sys

S = input()

S = S[::-1]

chars = ['dreamer', 'eraser', 'dream', 'erase']
chars = [char[::-1] for char in chars]

while 1:
    end_flag = 1
    for char in chars:
        if ( S.find(char) == 0):
            S = S[len(char):]
            end_flag = 0

            if S == '':
                print('YES')
                sys.exit()
    if end_flag ==1:
            print('NO')
            sys.exit()

Solution (Python):
s = input().replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
print("NO" if s else "YES")

Solution (Python):

S = str(input())
l = len(S)


flg = True
ans = 'YES'
i = 0
while flg:
	if S[i:i+11] == 'dreameraser':
		i +=11
	elif S[i:i+10] == 'dreamerase':
		i += 10
	elif S[i:i+7] == 'dreamer':
		i += 7
	elif S[i:i+6] == 'eraser':
		i += 6
	elif S[i:i+5] == 'dream' or S[i:i+5] == 'erase':
		i += 5
	elif i >= l:
		flg = False
	else:
		flg = False
		ans = 'NO'


print(ans)

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

Solution (Python):
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
print("NO" if s else "YES")

Solution (Python):
ss = input()
l = ["dream","dreamer","erase","eraser"]
    
for i_1 in range(4):
    for i_2 in range(4):
        for i_3 in range(4):
            for i_4 in range(4):
                s = ss
                while l[i_1] in s or l[i_2] in s or l[i_3] in s or l[i_4] in s:
                    s = s.replace(l[i_1],"").replace(l[i_2],"").replace(l[i_3],"").replace(l[i_4],"")
                    if s == "":
                        print("YES")
                        exit()

if s != "":
    print("NO")

Solution (Python):
s = input()
if s.replace("eraser"," ").replace("erase"," ").replace("dreamer"," ").replace("dream"," ").replace(" ", ""):
    print("NO")
else:
    print("YES")

Solution (Python):
import re
s = input()
print("YES" if re.match("^(eraser?|dream(er)?)*$", s) else "NO")

Solution (Python):
s = input()

while s:
    if s[:6] == "eraser":
        s = s[6:]
    elif s[:5] == "erase":
        s = s[5:]
    elif s[:5] == "dream":
        if s[5:8] == "era":
            s = s[5:]
        elif s[5:7] == "er":
            s = s[7:]
        else:
            s = s[5:]
    else:
        print("NO")
        exit()
print("YES")

Solution (Python):
s = input()
if s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream",""):
    print("NO")
else:
    print("YES")

Solution (Python):
import re
s=input()
print("YES") if re.match("^(dream|dreamer|erase|eraser)+$",s) else print("NO")

Solution (Python):
if not input().replace('eraser','').replace('erase','').replace('dreamer','').replace('dream',''):
  print('YES')
else:
  print('NO')

Solution (Python):
a=['dream','dreamer','erase','eraser']
def check(c):
    if c=='':
        return True
    size=len(c)
    n=len(c)
    while n>0:
        tmp=n
        for i in a:
            
            if size>=len(i) and c[n-len(i):n]==i:
                n-=len(i)
        if tmp==n:
            return False
    return True

print('YES' if check(input()) else 'NO')

Solution (Python):
S = input()
while len(S) > 0:
    if S[-5:] == 'dream' or S[-5:] == 'erase':
        S = S[:-5]
    elif S[-6:] == 'eraser':
        S = S[:-6]
    elif S[-7:] == 'dreamer':
        S = S[:-7]
    else:
        print('NO')
        quit()
print('YES')

Solution (Python):
S = input()
while len(S) > 0:
    if ''.join(S[-5:]) == 'dream' or ''.join(S[-5:]) == 'erase':
        S = S[:-5]
    elif ''.join(S[-6:]) == 'eraser':
        S = S[:-6]
    elif ''.join(S[-7:]) == 'dreamer':
        S = S[:-7]
    else:
        print('NO')
        quit()
print('YES')

Solution (Python):
S = input()
while len(S) > 0:
    if ''.join(S[-5:]) == 'dream' or ''.join(S[-5:]) == 'erase':
        S = S[:-5]
    elif ''.join(S[-6:]) == 'eraser':
        S = S[:-6]
    elif ''.join(S[-7:]) == 'dreamer':
        S = S[:-7]
    else:
        print('NO')
        quit()
print('YES')

Solution (Python):
S = list(input())
while len(S) > 0:
    if ''.join(S[-5:]) == 'dream' or ''.join(S[-5:]) == 'erase':
        S = S[:-5]
    elif ''.join(S[-6:]) == 'eraser':
        S = S[:-6]
    elif ''.join(S[-7:]) == 'dreamer':
        S = S[:-7]
    else:
        print('NO')
        quit()
print('YES')

Solution (Python):
import re
print("YES" if re.match("^(eraser?|dream(er)?)*$",input()) else "NO")

Solution (Python):
s = input().replace("eraser"," ").replace("erase"," ").replace("dreamer"," ").replace("dream"," ").replace(" ", "")
if s:
    print("NO")
else:
    print("YES")

Solution (Python):
import re
print("YES" if re.match("^(eraser?|dream(er)?)+$",input()) else "NO")

Solution (Python):
s = input()
if s.replace("eraser"," ").replace("erase"," ").replace("dreamer"," ").replace("dream"," ").replace(" ", ""):
    print("NO")
else:
    print("YES")

Solution (Python):
s = input()

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

Solution (Python):
s = input()

while s:
    if s[:6] == "eraser":
        s = s[6:]
    elif s[:5] == "erase":
        s = s[5:]
    elif s[:5] == "dream":
        if s[5:8] == "era":
            s = s[5:]
        elif s[5:7] == "er":
            s = s[7:]
        else:
            s = s[5:]
    else:
        print("NO")
        exit()
print("YES")

Solution (Python):
def isDaydream(s):
    while s != "":
        if s.endswith("dream"):
            s = s[:-5]
        elif s.endswith("dreamer"):
            s = s[:-7]
        elif s.endswith("erase"):
            s = s[:-5]
        elif s.endswith("eraser"):
            s = s[:-6]
        else :
            return False
    return True

if(isDaydream(input())):
    print("YES")
else:
    print("NO")

Solution (Python):
import re
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$",input()) else "NO")

Solution (Python):
import re
S = input()
answer = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if len(answer) == 0:
	print("YES")
else:
	print("NO")

Solution (Python):
s=input()
if s.replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')=='':
    print('YES')
else:
    print('NO')

Solution (Python):
S=input()
w=["dream","dreamer","erase","eraser"]
q=[0]
while q:
    i = q.pop()
    s = S[i:]
    if s == "":
        print("YES")
        break
    for c in w:
        if c==s[:len(c)]:q.append(i+len(c))
else:
    print("NO")

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

Solution (Python):
import re
S = input()
num = []
l = []

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



"""
if ("eraser" in S)  == True:
	S.replace("eraser", "")

if ("erase" in S)   == True:
	S.replace("erase", "")

if ("dreamer" in S) == True:
	S.replace("dreamer", "")

if ("dream" in S)   == True:
	S.replace("dreamer", "")
"""

"""
if ("eraser" in S)  == True:
	num.append(S.count("eraser"))
	for i in range(S.count("eraser")):
		a.append(S.find("eraser"))
		S[S.find("eraser"):6]

if ("erase" in S)   == True:
	num.append(S.count("erase"))
	for i in range(S.count("erase")):
		a.append(S.find("erase"))
		S[S.find("erase"):5]

if ("dreamer" in S) == True:
	num.append(S.count("dreamer"))
	for i in range(S.count("dreamer")):
		a.append(S.find("dreamer"))
		S[S.find("dreamer"):7]

if ("dream" in S)   == True:
	num.append(S.count("dream"))
	for i in range(S.count("dream")):
		a.append(S.find("dream"))
		S[S.find("dream"):5]
"""

Solution (Python):
S=input()
n=0

while S[:]!=S[:n]:
    if S[n:n+7]=="dreamer" and S[n:n+8]!="dreamera":
        n+=7 
    elif S[n:n+5]=="dream":
        n+=5 
    elif S[n:n+5]=="erase" and S[n:n+6]!="eraser":
        n+=5 
    elif S[n:n+6]=="eraser":
        n+=6 
    
        
        
    else:
        print("NO")
        exit()
else:
    print("YES")

Solution (Python):
S = input()[::-1]
words = {w[-1]:w[::-1] for w in ['dream', 'erase', 'er']}
i = 0
flag = True

while i < len(S):
  c = S[i]
  if c in words:
    if S[i:i+len(words[c])] == words[c]:
      i += len(words[c])
    else :
      flag = False
      break
    if c == 'r':
       if S[i:i+len(words['m'])] == words['m']:
         i += len(words['m'])
       elif S[i-1:i-1+len(words['e'])] == words['e']:
         i += len(words['e']) - 1
       else :
         flag = False
         break
  else :
    break
  if not flag:
    break
print('YES' if flag else 'NO')

Solution (Python):




s=input()
s1="dream"
s2="dreamer"
s3="erase"
s4="eraser"
l=len(s)

rest="NO"

while l>4:
	if s[-5:]==s1 or s[-5:]==s3:
		s=s[0:-5]
		l=l-5
	elif s[-6:]==s4:
		s=s[0:-6]
		l=l-6
	elif s[-7:]==s2:
		l=l-7
		s=s[0:-7]
	else:
		break

if l==0:
	rest="YES"

print(rest)

Solution (Python):
from collections import deque

S = list(input())
S.reverse()
l = len(S)

def rev(x):
    x = list(x)
    x.reverse()
    return x

a = list(map(rev,['dream','dreamer','erase','eraser']))
q = deque()
q.append(["",0])

while len(q):
    b,i = q.pop()
    if i == l:
        print('YES')
        exit()
    x = 0
    f = True
    for B in b:
        if i+x >= l or S[i+x] != B:
            f = False
        x += 1
    if f:
        for A in a:
            q.append([A,i+x])

print('NO')

Solution (Python):
from collections import deque

S = input()
l = len(S)

a = list(map(list,['dream','dreamer','erase','eraser']))
q = deque()
q.append(["",0])

while len(q):
    b,i = q.pop()
    if i == l:
        print('YES')
        exit()
    x = 0
    f = True
    for B in b:
        if i+x >= l or S[i+x] != B:
            f = False
        x += 1
    if f:
        for A in a:
            q.append([A,i+x])

print('NO')

Solution (Python):
s =input()
s1 = "dream"
s2= "dreamer"
s3 = "eraser"
s4 = "erase"
n=len(s)
res="NO"
while len(s)!=0 or s>4:
    n=len(s)
    if s[-5:]==s1 or s[-5:]==s4:
        s=s[:n-5]
    elif s[-7:]==s2:
        s=s[:n-7]
    elif s[-6:]==s3:
        s=s[:n-6]
    else:
        break
    if len(s)==0:
        res="YES"
        break
print(res)

Solution (Python):
import re
text = input()
matche_str = re.compile(r'^(dream|dreamer|erase|eraser)+$')
mo = matche_str.search(text)
 
if mo != None:
    print('YES')
else:
    print('NO')

Solution (Python):
def judger(s):
    '''
    input:
    s = 5 target characters
    output:
    Predict word from the first 5 characters 
    '''
    if s == 'maerd':
        return 'maerd'
    elif s == 'remae':
        return 'remaerd'
    elif s == 'esare':
        return 'esare'
    elif s == 'resar':
        return 'resare'
    else:
        raise ValueError
        
s = input()
sT = s[::-1]

flag = 'YES'
while sT:
    try:
        target = judger(sT[0:5])
        if target == sT[0: len(target)]:
            sT = sT[len(target):]
        else:
            flag = 'NO'
            break
    except ValueError:
        flag = 'NO'
        break

print(flag)

Solution (Python):
import re
S = input()
pattern = re.compile(r'^(dream|dreamer|erase|eraser)+$')
result = pattern.search(S)
if result:
  print('YES')
else:
  print('NO')

Solution (Python):
import re
s = input()

p = re.compile(r'^(dream|dreamer|erase|eraser)*(dream|dreamer|erase|eraser)$')
x = p.search(s)

if x :
    print("YES")
else:
    print("NO")

Solution (Python):
import re
s = input()

p = re.compile(r'^(dream|dreamer|erase|eraser)*(dream|dreamer|erase|eraser)$')
x = p.search(s)

if x :
    print("YES")
else:
    print("NO")

Solution (Python):


def solve(S):
    s = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")

    if(s==""):
        print("YES")
    else:
        print("NO")
    
if __name__ == '__main__':
    S = input()
  
    solve(S)

Solution (Python):
s=input()
if s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")=="":
    print("YES")
else:
    print("NO")

Solution (Python):
S = input()
l = ['eraser', 'erase', 'dreamer','dream']

s = "".join(S[-1::-1].split(l[0][-1::-1]))

for i in range(1, 4):
    s = "".join(s.split(l[i][-1::-1]))

print("YES") if s == "" else print("NO")

Solution (Python):
s = list(input())


s = "".join(s[::-1])
dream = "dream"
dream_r = "".join(dream[::-1])
dreamer = "dreamer"
dreamer_r = "".join(dreamer[::-1])
erase = "erase"
erase_r = "".join(erase[::-1])
eraser = "eraser"
eraser_r = "".join(eraser[::-1])






s = s.replace(eraser_r, "")
s = s.replace(erase_r, "")
s = s.replace(dreamer_r, "")
s = s.replace(dream_r, "")



ans = "YES" if s == "" else "NO"
print(ans)

Solution (Python):
import sys
S = input()[::-1]

length = len(S)
i = 0

while i < length:
    if S[i:i+5] == 'dream'[::-1]:
        i += 5
    elif S[i:i+7] == 'dreamer'[::-1]:
        i += 7
    elif S[i:i+5] == 'erase'[::-1]:
        i += 5
    elif S[i:i+6] == 'eraser'[::-1]:
        i += 6
    else:
        print('NO')
        sys.exit()
    
print('YES')

Solution (Python):
phrase = input()

words_list = ["dream", "dreamer", "erase", "eraser"]
reversed_words_list = [ word[::-1] for word in words_list ]
reversed_phrase = phrase[::-1]

can1 = True
for i in range(len(reversed_phrase)):
    can2 = False
    if len(reversed_phrase) == 0:
        can2 = True
        break
    for checker in reversed_words_list:
        if reversed_phrase[0:len(checker)] == checker:
            can2 = True
            reversed_phrase = reversed_phrase[len(checker):]
            break
    if not can2:
        can1 = False
        break

if can1:
    print("YES")
else:
    print("NO")

Solution (Python):

s = (
    input()
    .replace("eraser", "")
    .replace("erase", "")
    .replace("dreamer", "")
    .replace("dream", "")
)
print("NO" if s else "YES")

Solution (Python):
s = input()

dp = [False]*(len(s)+1)

dp[0] = True

words = ['dream','dreamer','erase','eraser']
for i in range(len(s)+1):
    if dp[i]:
        for w in words:
            if s[i:i+len(w)]==w:
                dp[i+len(w)] = True
if dp[len(s)]:
    print('YES')
else:
    print('NO')

Solution (Python):
s = input()
 
x = s.count("dreamerase")
a = s.count("dreamer") - x
b = s.count("dream") - a 
c = s.count("eraser")
d = s.count("erase") - c

if a*7 + b*5 + c*6 + d*5 == len(s):
  print("YES")
else:
  print("NO")

Solution (Python):



s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']

s = s[::-1]
while len(s) > 0:
    flag = 0
    for w in words:
        w = w[::-1]
        if s[0:len(w)] == w:
            s = s[len(w)::]
            
            flag = 1
            break
    if flag == 0:
        print("NO")
        exit()

print("YES")

Solution (Python):


s = input().replace("eraser","").replace("erase","")\
        .replace("dreamer","").replace("dream","")
if s:
        print("NO")
else:
        print("YES")

Solution (Python):
target = input()
rev = target[::-1]
n = 0
prev = n
result = "YES"
while(n<len(rev)):
    for i in ["maerd", "esare", "resare", "remaerd"]:
        if rev[n:n+len(i)] == i:
            n += len(i)
    if prev == n:
        result = "NO"
        break
    prev = n
print(result)

Solution (Python):




s = input()
s = s + " "


sl = ["dream", "dreamer", "erase", "eraser"]

ans = "NO"
i = len(s)


while(i > 1):
    wtflg = False
    for j in range(len(sl)):
        st = (len(s) - i + 1+ len(sl[j])) * -1
        ed = (len(s) - i + 1) * -1
        subs = s[st:ed]
            
        if subs == sl[j]:
            wtflg = True
            break
    
    if wtflg == False:
        break
    
    i = i - len(sl[j])

if i <= 1:
    ans = "YES"


print(ans)

Solution (Python):
S = input()
P = ['dream', 'dreamer', 'erase', 'eraser']
s = S
for i in range(10**5):
    flg = True
    for p in P:
        if s[len(s)-len(p):] == p:
            s = s[:len(s)-len(p)]
            flg = False
            break
    if flg:
         print('NO')
         quit()
    if len(s) == 0:
        break
print('YES')

Solution (Python):
words = {"dream": "A", "dreamer": "A", "erase": "A", "eraser": "A"}
 
ans = []
 
inputs = str(input())
 
inputs = inputs.replace("eraser", "").replace("erase", "")
inputs = inputs.replace("dreamer", "").replace("dream", "")

if len(list(inputs)) > 0:
  print("NO")
else:
  print("YES")

Solution (Python):
words = {"dream": "A", "dreamer": "A", "erase": "A", "eraser": "A"}
 
ans = []
 
inputs = str(input())
 
inputs = inputs.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")

if len(list(inputs)) > 0:
  print("NO")
else:
  print("YES")

Solution (Python):
def main():
  a = input()
  
  flg = "YES"
  index = 0
  while True:
    if index == len(a):
      break
    
    if a.find("dreameraser", index) == index:
      index += len("dreameraser")
    elif a.find("dreamerase", index) == index:
      index += len("dreamerase")
    elif a.find("dreamer", index) == index:
      index += len("dreamer")
    elif a.find("dream", index) == index:
      index += len("dream")
    elif a.find("eraser", index) == index:
      index += len("eraser")
    elif a.find("erase", index) == index:
      index += len("erase")
    else:
      flg = "NO"
      break
      
  print(flg)
  
main()

Solution (Python):


s = input()

while len(s) > 4:
    if s[-5:] == 'dream':
        s = s[:-5]
    elif s[-7:] == 'dreamer':
        s = s[:-7]
    elif s[-5:] == 'erase':
        s = s[:-5]
    elif s[-6:] == 'eraser':
        s = s[:-6]
    else:
        break

if len(s) > 0:
    print('NO')
else:
    print('YES')

Solution (Python):
import re

s = input()
s = re.sub('eraser', '', s)
s = re.sub('erase', '', s)
s = re.sub('dreamer', '', s)
s = re.sub('dream', '', s)
print('YES' if len(s) == 0 else 'NO')