peterverebics/CodeNet_Python_118 huggingface dataset:
s = input()


def solve(query):
    while 1:
        for frag in ("erase", "eraser", "dream", "dreamer"):
            if query.endswith(frag):
                query = query[:-len(frag)]
                print("cut", frag)
                break
        else:
            print("NO", query)
            break
        if not query:
            print("YES")
            break



solve(s)
S=input()
str_list=["dream","dreamer","erase","eraser"]

S_tmp=""
while True:
  S_tmp=S
  for str in str_list:
    S=S.replace(str,"") #rstrip(str)はだめ
  
  if S_tmp==S:
    break

if S=="":
  print("Yes")
if S!="":
  print("No")
S = input().replace("eraser","").replace("erase","").replace("dream","").replace("dreamer","")

if S =="":
    print("YES")
else:
    print("NO")
# C - 白昼夢
S = input()
S2 = S
W_L = ["dream","dreamer","erase","eraser"]
while True:
    
    for w in W_L:
        if S2.endswith(w):
            S2 = S2[:-(len(w))]
        else:
            print('NO')
            exit()
            
    if len(S2)<=7:
        break
    
if S2 ==''or S2 in W_L:
    print('YES')
else:
    print('NO')
s = input()
s = s.replace("dreamer", "")
s = s.replace("dream", "")
s = s.replace("erase", "")
s = s.replace("eraser", "")
if len(s) == 0:
    print("YES")
else:
    print("NO")
t=input()
trigger=1
app=['dream','dreamer','erase','eraser']
while len(t)>0 and trigger:
    for i in range(4):
        key=app[i]
        if key==t[:len(key)]:
            t=t[len(key):]
            trigger+=1
            break
    trigger-=1
if t=='':
    print('YES')
else:
    print('NO')
s = input()
strset = {'dream': 5, 'dreamer': 7, 'erase': 5, 'eraser': 6}

while len(s)>0:
    if s[0:6] == 'eraser':
        s = s[6:]
        print(s)
    elif s[0:7] == 'dreamer':
        s = s[7:]
        print(s)
    elif s[0:5] == 'dream' or s[0:5] == 'erase':
        s = s[5:]
        print(s)
    else:
        print('NO')
        exit()

print('YES')
s=input()
while len(s)>7:
    if s[-5:]=='dream' or s[-5:]=='erase':
        s=s[-5:]
    elif s[-6:]=='eraser':
        s=s[-6:]
    else:
        s=s[-7:]
print('YES' if s=='erase' or s=='dreamer' or s=='dream' or s=='eraser' or s=='' else 'NO')
s=input()
s=s.replace("eraser","")
s=s.replace("erase","")
s=s.replace("dreamer","")
s=s.replace("dream,","")
if s:
    print("NO")
else:
    print("YES")
s = input()
s = list(s)
s = s[::-1]

word_list = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
while i != len(s):
    a = s[i:i+5]
    a = ''.join(a)
    b = s[i:i+6]
    b = ''.join(b)
    if a in word_list:
        i += 5
    elif b in word_list:
        i += 6
    else:
        print('NO')
        exit()

print('YES')
import re
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$",input()) else "No")
s=input()
ans='YES'
while s!='':
  if s[:7]=='dreamer':
    s=s.lstrip('dreamer')
  elif s[:5]=='dream':
    s=s.lstrip('dream')
  elif s[:6]=='eraser':
    s=s.lstrip('eraser')
  elif s[:5]=='erase':
    s=s.lstrip('erase')
  else:
    ans='NO'
    break
print(ans)
s=str(input())
x=len(s)
a=s.count("dream")
b=s.count("dreamer")
c=s.count("erase")
d=s.count("eraser")
e=s.count("dreameraser")
a-=b
c-=d
if 5*(a+c)+6*(b+d)-e==x:
  print("YES")
else:
  print("NO")
s = input()
u = ['dreamer', 'eraser', 'dream', 'erase']
while len(s) > 0:
    for i in u:
        if s[-len(i):-0] == i:
            s = s.rstrip(i)
            break
    else:
        print('No')
        exit()
else:
    print("YES")
s=input()
s=s.replace("eraser","")
s=s.replace("erase","")
s=s.replace("dreamer","")
s=s.replace("drea,","")
if s:
    print("NO")
else:
    print("YES")
q = ['dream','dreamer','erase','eraser']
s = input()

while True:
  if len(s) == 5 or len(s) == 7 or len(s) == 6:
    break
  if s[-5:] in q:
    s = s[0:-5]
  elif s[-7:] in q:
    s = s[0:-7]
  elif s[-6:] in q:
    s = s[0:-6]
  else:
    print('N0')
    exit()
    
if s in q:
  print('YES')
else:
  print('NO')
S = input()

# Greedyアルゴリズム
S = S[::-1]
print(S)

S = S.replace("resare","")
S = S.replace("esare","")
S = S.replace("remaerd","")
S = S.replace("maerd","")

if S == "":
        print("YES")
else:
        print("NO")
S = input()
if len(S) == 0:
  print('NO')
else:
  if len(S.replace('dreamer', '').replace('dream', '').replace('eraser', '').replace('erase', '')) == 0:
    print('YES')
  else:
    print('NO')
s=input().replace("eraser","").replace("dreamer","").replace("erase","").replace("dream","")
if s=="":print('YES')
else:print('NO')
S = input()
replaced_t = S.replace('dreamer','').replace('dream', '').replace('eraseer', '').replace('erase', '')
if replaced_t:
    print('NO')
else:
    print('YES')
s="dreamerer"

s=s.replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')

if len(s)==0:print("YES")
else:print("NO")
import sys
s = input()
t = s[::-1]
while len(t) != 0:
    if t[:5] == "maerd" or t[:5] == "esare":
        t = t[5:]
    elif t[:6] == "resare":
        t = t[6:]
    elif t[:7] == "remaerd":
        t = t[6:]
    else:
        print("NO")
        sys.exit()
print("YES")
import re
print("Yes" if re.match("^(dream|dreamer|erase|eraser)+$", input()) else "No")
# C - 白昼夢
S = input()
S2 = S
W_L = ["dream","dreamer","erase","eraser"]
while True:
    
    for w in W_L:
        if S2.endswith(w):
            S2 = S2[:-(len(w))]
            
    if len(S2)<=7 or not S2.endswith(w):
        break
    
if S2 ==''or S2 in W_L:
    print('YES')
else:
    print('NO')
s=input()
s1=s.replace("eraser","0").replace("erase","0").replace("dreamer","0").replace("dream","0")
n=len(s1)
flag=False
for  i in range(0,n):
    if s1[i]!='0':
        flag=True
        break
        
if flag==False:
    print("Yes")
else:
    print("No")
S = input()
s = reversed(S)

T = ''

for i in s:
    T += i
    if T in ['maerd', 'remaerd', 'esare', 'resare']:
       T = ''
    if len(T) >= 6:
        print('NO')
        break
if len(T) == 0:
    print('YES')
s = input()
s=s[::-1]
i=0
ans="YES"
while True:
    if len(s)==i:
        break
    elif s[i:i+5]=="maerd":
        i+=5
    elif s[i:i+7]=="remared":
        i+=7
    elif s[i:i+5]=='esare':
        i+=5
    elif s[i:i+6]=='resare':
        i+=6
    else:
        ans="NO"
        break
print(ans)
s = input()
a = s.count("dream")
b = s.count("dreamer")
c = s.count("erase")
d = s.count("eraser")
e = s.count("dreamera")
f = s.count("erasera")
b = b-e
d = d-f
a = a-b
c = c-e
if (a+c)*5 + b*7 + d*6 == len(s):
  print("Yes")
else:
  print("No")
s = input()

while s!="":
    if s[-5:]=="dream" or s[-5:]=="erase":
        s = s[:-5]
    elif s[-6:]=="dreamer" or s[-6:]=="eraser":
        s = s[:-6]
    else:
        print("NO")
        exit()
print("YES")
import re
S = input()
if re.match("^(dreamer|dream|erase|eraser)+$", S):
    print("Yes")
else:
    print("No")
s = input()
length = len(s)

i = 0
res = "YES"

while i < length:
  if i+4 <= length and s[i:i+5] == "dream":
    i += 5
    if i+1 <= length and s[i:i+2] == "er" and s[i+2] != "a":
      i += 2
  else:
    res = "NO"
    break
      
  if i+4 <= length and s[i:i+5] == "erase":
    i += 5
    if i+1 <= length and s[i:i+2] == "er" and s[i+2] != "a":
      i += 2
  else:
    res = "NO"
    break
        
print(res)
s = input()
d = { "eam":5, "mer":7, "ase":5, "ser":6}
index = len(s)
while index != 0:
  tmp = s[index-3:index]
  if tmp not in d.keys():
    break
  index -= d[tmp]
  if index < 0:
    break
else:
  print("YES")
  exit()
print("NO")
S = input()
while True :
  if S[0:7] == "dreamer":
    S = S.replace("dreamer","")
  elif S[0:6] == "eraser":
    S = S.replace("eraser","")
  elif S[0:5] == "dream":
    S = S.replace("dream","")
  elif S[0:5] == "erase":
    S = S.replace("erase","")
  elif len(S) == 0:
    print("YES")
    break
  else:
    print("NO")
    break
s = input()

while len(s) >= 5:
    if len(s) >= 5 and s[-5:] == 'dream':
        s = s[:-5]

    elif len(s) >= 7 and s[-7:] == 'dreamer':
        s = s[:-7]

    elif len(s) >= 5 and s[-5:] == 'erase':
        s = s[:-5]

    elif len(s) >= 6 and s[-6:] == 'eraser':
        s = s[:-6]

    else:
        break

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


def solve(query):
    while 1:
        for frag in ("erase", "eraser", "dream", "dreamer"):
            if query.endswith(frag):
                query = query.rstrip("frag")
                break
        else:
            print("NO")
            break
        if not query:
            print("YES")
            break



solve(s)
#049_C
s = input()

s = s.replace('dreamer', '').replace('dream', '').replace('eraser', '').replace('erase', '')
print('YES' if s == '' else 'NO')
s = input()
D = ['dream', 'dreamer']
E = ['erase', 'eraser']
T = ['dream', 'dreamer', 'erase', 'eraser']

if s[0] == 'd':
    for d in D:
        for t in T:
            if s == d+t:
                print('YES')
                exit()

if s[0] == 'e':
    for e in E:
        for t in T:
            if s == e+t:
                print('YES')
                exit()

print('NO')
S = list(input())
S.reverse()
S = ''.join(S)
st = ['maerd','remeard','esare','resare']
ans = 'YES'
while S != '':
    if S[0:5] in st:
        S = S[5:]
    elif S[0:4] in st:
        S = S[4:]
    elif S[0:6] in st:
        S = S[6:]
    else:
        ans = 'NO'
        break
print(ans)
c = input().rstrip('\n')

str1 = "dreamer"
str2 = "dream"
str3 = "eraser"
str4 = "erase"

tmpstr = ""

endflag = False

while(c != ""):
  tmpstr = c
  c = c.replace(str1, "")
  c = c.replace(str2, "")
  c = c.replace(str3, "")
  c = c.replace(str4, "")
  
  print("tmpstr:" + tmpstr)
  print("c:" + c)
  
  if (c == tmpstr):
    endflag = True
    break

if (c == ""):
  print("YES")
else:
  print("NO")
# coding: utf-8
# Your code here!
s = input()

word_list = ["dreamer","dream","eraser","erase"]
for i in word_list:
    s = s.replace(i,".")

if len(set(s)) == 1:
    print("YES")
else:
    print("NO")
import sys
input = sys.stdin.readline
S = input().rstrip()

while S:
    if S[-5:] == "dream":
        S = S[:-5]
    elif S[-5] == "erase":
        S = S[:-5]
    elif S[-6:] == "eraser":
        S = S[:-6]
    elif S[-7:] == "dreamer":
        S = S[:-7]
    else:
        print("NO")
        sys.exit()
print("YES")
s = input()
s = s.replace("erase", "")
s = s.replace("eraser", "")
s = s.replace("dreamer", "")
s = s.replace("dream", "")
if len(s) == 0:
    print("YES")
else:
    print("NO")
s=input().strip()
s=s.replace("eraser","")
s=s.replace("erase","")
s=s.replace("dreamer","")
s=s.replace("dream","")
print("YES" if s else "NO")
S = input().strip()
#-----

i=0
while i <= len(S)-5:

    if S[i:(i+7)] == "dreamer":
        i=i+7
    elif S[i:(i+6)] == "eraser":
        i=i+6
    elif S[i:(i+5)] == "dream" or S[i:(i+5)] == "erase":
        i=i+5
    else:
        print("NO")
        break
s=input()
f=0
l=['dream' ,'dreamer', 'erase','eraser']
while(f==0):
    if(s[:7] in l):
        s=s[7:]
    elif(s[:6] in l):
        s=s[6:]
    elif(s[:5] in l):
        s=s[5:]
    else:
        f=1
        break
if(len(s)==0):
    print("YES")
else:
    print("NO")
import re
S = input()
print("YES" if re.match("dream|dreamer|erase|eraser", S) else "NO")
s = input()

import re
output ="NO"
s = re.sub('dreameraser', '', s)
s = re.sub('dreamerase', '', s)
s = re.sub('eraser', '', s)
s = re.sub('dreamer', '', s)
s = re.sub('dream', '', s)
s = re.sub('erase', '', s)
if s == "":
    output = "YES"
print(output)
s = input()
s = s[::-1]
n = len(s)

cur = 0
while cur < n:

  if s[cur:cur+5:] == "maerd" or "esare":
    cur += 5
    continue
  if s[cur:cur+6:] == "resare":
    cur += 6
    continue
  if s[cur:cur+7:] == "remaerd":
    cur += 7
    continue
  print("NO")
  exit()

print("YES")
S= input()
i=0

while True:
    flag = False
    if S[i:i+7] == "dreamer":
        i += 7
        flag = True

    if S[i:i+6] == "eraser":
        i += 6
        flag = True
    
    if S[i:i+5] == "erase" or S[i:i+5] == "dream":
        i += 5
        flag = True

    if not flag:
        break

if i == len(S):
    print("YES")
else:
    print("NO")
s = input()

while True:
  if len(s) == 0:
    print("YES")
    break
  elif len(s) < 5:
    print("NO")
    break
  else:
    if s[:5] == "dream":
      s = s.replace("dream", "", 1)
    elif s[:5] == "erase":
      s = s.replace("erase", "", 1)
    elif s[:7] == "dreamer" :
      s = s.replace("dreamer", "", 1)
    elif s[:6] == "eraser":
      s = s.replace("eraser", "", 1)
    else:
      print("NO")
      break
s = input()
a = 'dream'
b = 'dreamer'
c = 'erase'
d = 'eraser'
for i in range(len(s)):  
  if not s[i] == a[i//4] or s[i] == b[i//5] or s[i] == c[i//4] or s[i] == d[i//5]:
    print('NO')
    exit()
print('YES')
s = input()
s = s.replace("eraser", "")
s = s.replace("dreamer", "")
s = s.replace("erase", "")
s = s.replace("dream", "")
if len(s) == 0:
    print("YES")
else:
    print("NO")
s = input()
s = s.replace('dreamer', '')
s = s.replace('dream', '')
s = s.replace('eraser', '')
s = s.replace('erase', '')
if s == '':
    print('YES')
else:
    print('NO')
data = ['dream','dreamer','erase','eraser']
word = input()
for i in data:
  while i in word:
    word = word.replace(i,"")
if word == "":
  print("YES")
else :
  print("NO")
import re
S = input()
print("YES" if re.match("(dream|dreamer|erase|eraser)", S) else "NO")
text = "".join(reversed(input()))
words = map(lambda word: "".join(reversed(word)), ["dreamer", "dream", "eraser", "erase"])

for word in words:
  text = text.replace(word, " ")

print("YES" if text.strip() == "" else "NO")
s = input()

t_list = ['dreamdream', 'dreamdreamer', 'dreamerase', 'dreameraser', 'dreamerdream', 'dreamerdreamer', 'dreamererase', 'dreamereraser', 'erasedream', 'erasedreamer', 'eraseerase', 'eraseeraser', 'eraserdream', 'eraserdreamer', 'erasererase', 'erasereraser']

if s in t_list:
    print('YES')
else:
    print('NO')
s=input()
s=s.replace("eraser","")
s=s.replace("dreamer","")
s=s.replace("dream","")
s=s.replace("erase","")
# print(s)
if s=="":
    print("YES")
else :
    print("NO")
s = input()[::-1]
n = len(s)
words = ['maerd', 'remaerd', 'esare', 'resare']
p = 1
while p <= n:
    if s[:p] in words:
        s = s[p:]
    p += 1
print('NO' if s else 'YES')
S = input()[::-1]
string = list(map(
    lambda x: x[::-1],
    [
        "dream",
        "dreamer",
        "erase",
        "eraser"

    ]))
index = 0
while 1:
    for x in string:
        match = S.find(x, index)
        if match == -1:
            continue
        elif match > -1:
            index += match + len(x)
        if index == len(S):
            print("YES")
            exit()
c = input().rstrip('\n')

str1 = "dreamer"
str2 = "dream"
str3 = "eraser"
str4 = "erase"


count = 0

while(count < len(c)-1):
  if(c[count:count+len(str1)] == str1):
    count += len(str1)
  elif(c[count:count+len(str2)] == str2):
    count += len(str2)
  elif(c[count:count+len(str3)] == str3):
    count += len(str3)
  elif(c[count:count+len(str4)] == str4):
    count += len(str4)
  else:
    print("NO")
    exit()

print("YES")
s=input()
import re
#re.match は複数を対象にすればマッチする該当のものが返される。一つの時ifの後に持ってくると条件式として利用可能。
if re.match("(dream|dreamer|erase|eraser)+",s) :
       print("YES")
else:
       print("NO")
import re

S = input()

list_string = ['dream', 'dreamer', 'erase', 'eraser']
regex = r'(dream(er)?eraser?)+|(eraser?dream(er)?)+|(((dream(er)?)|(eraser?))+)'

def check(list_string, regex, S):
    while S:
        if re.search(regex, S):
            S =  re.sub(regex, '', S)

        else:
            return 'NO'
    return 'YES'

print(check(list_string, regex, S))
def main():
  S = input()
  while len(S)>=5:
    if len(S)>=7 and S[:-7]=="dreamer":
      S = S[-7:]
      continue
    
    elif 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()
s = input()

flag = 0

while(len(s)>0):
  if (s[:6] == 'eraser'):
    s = s[6:]
  elif (s[:5] == 'erase'):
    s = s[5:]
  elif (s[:5] == 'dream'):
    if (s[5:8] == 'ere' or s[5:8] == 'erd'):
      s = s[7:]
    else:
      s = s[5:]
  else:
    flag = 1
    break

if (flag == 0):
  print('Yes')
else:
  print('No')
S=input()
S=S.replace('dreamer','')
S=S.replace('aser','')
S=S.replace('ace','')
S=S.replace('eraser','')
S=S.replace('erase','')
S=S.replace('dream','')
if S=='':
  print('YES')
else:
  print('NO')
s = input()
s2 = s.split('dream')
s3 = ''.join(s2).split('erase')
try:
  s3.remove('er')
  s3.remove('r')
except ValueError:
  pass
if s3[0] != '':
  print("NO")
else:
  print("YES")
S = input()

def solve(T) :
    while 1:
        flag = True
        for i in ("dream", "dreamer", "erase", "eraser"):
            if T.endswith(i):
                T = T[: -len(i)]
                flag = False
                break
        
        if flag:
            print("NO")
            break
        
        if len(T) == 0:
            print("Yes")
            break

solve(S)
s = input()

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

s = s.replace(kouho[1], "").replace(kouho[0], "").replace(kouho[3], "").replace(kouho[2], "")

if s == "":
    print("YES")
else:
    print("NO")
s = list(input())
s.reverse()
str = ""
for i in s:
    str+=i

str_list = ["maerd", "remaerd", "esare", "resare"]

while True:
    flag=0
    for l in str_list:
        if str.startswith(l):
            #print("str:{},l:{}".format(str,l))
            str=str.lstrip(l)
            #print("str:{},l:{}".format(str,l))
            flag+=1
    if flag==0:
        break


if str == "":
    print("YES")
else:
    print("NO")
S = input()
temp = ['dream', 'dreamer', 'erase', 'eraser']

while(1):
    for i in temp:
        if S.startswith(i):
            S = S.lstrip(i)
            break
    else:
        break

if len(S) == 0:
    print('YES')
else:
    print('NO')
S = input()
T = ''
words = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(words)):
    words[i] = words[i][::-1]
for i in S[::-1]:
    T += i
    for q in words:
        if T == q:
            T = ''
if T == '':
    print('Yes')
else:
    print('No')
s = input()
a = 'dream'
b = 'dreamer'
c = 'erase'
d = 'eraser'
for i in range(len(s)):  
  if not s[i] == a[i//5] or s[i] == b[i//7] or s[i] == c[i//5] or s[i] == d[i//6]:
    print('NO')
    exit()
print('YES')
S = input()
strs = ["erase", "eraser", "dreamer","dream"]
rtss = [s[::-1] for s in strs]
S_r = S[::-1]
for rts in rtss:
    S_r = S_r.replace(rts, "")
if len(S_r) == 0:
    print("YES")
else:
    print("NO")
import re
sin = input()
match = re.match(r"^.*(dream|dreamer|erase|eraser)+$",sin)
print("YES" if match else "NO")
s = input()
for p in range(1000):
  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]
  if s == '':
    break
if s == '':
  print('YES')
else:
  print('NO')
s = input()
s = s[::-1]
ans = ["maerd","remaerd","esare","resare"]
flag = 1
while len(s) != 0 and flag == 1:
    flag = 0
    if s[:5] in ans:
        s = s[5:]
        flag = 1
    elif s[:7] in ans:
        s = s[7:]
        flag = 1
        
if flag == 0:
    print("NO")
else:
    print("YES")
S = input()
R = ''.join(list(reversed(list(S))))
#print(R)

while R:
    if R[:5]=='maerd':
        R = R[5:]
    elif R[:7]=='remaerd':
        R = R[7:]
    elif R[:5]=='esare':
        R = R[5:]
    elif R[:6]=='resare':
        R = R[6:]
    else:
        print('No')
        break
else:
    print('YES')
s = input()
u = ['dreamer', 'eraser', 'dream', 'erase']
while s:
    start = len(s)
    for i in u:
        if s[-len(i):len(s)] == i:
            s = s[:len(s)-len(i)]
    if start == len(s):
        print('No')
        exit()
print("YES")
def hantei(S):
  if S == 'dream' or S == 'dreamer' or S == 'erase' or S == 'eraser':
    return True
  if S[:5] == 'dream':
    return hantei(S[5:])
  if S[:7] == 'dreamer':
    return hantei(S[7:])
  if S[:5] == 'erase':
    return hantei(S[5:])
  if S[:7] == 'eraser':
    return hantei(S[7:])
  else:
    return False

S = input()
if(hantei(S)):
  print('YES')
else:
  print('NO')
S = input()

num_5 = ["dream", "erase"]
num_6 = ["dreamer", "eraser"]
while len(S) != 0:
    if S[0:6] in num_6:
        S = S[6:]
    elif S[0:5] in num_5:
        S = S[5:]
    else:
        print("NO")
        exit()

print("YES")
s = input()

t_list = ['dreamdream', 'dreamdreamer', 'dreamerase', 'dreameraser', 'dreamerdream', 'dreamerdreamer', 'dreamererase', 'dreamereraser', 'erasedream', 'erasedreamer', 'eraseerase', 'eraseeraser', 'eraserdream', 'eraserdreamer', 'erasererase', 'erasereraser']

try:
    t_list.index(s)
    print('YES')
except:
    print('NO')
s = input()


def solve(query):
    while 1:
        for frag in ("erase", "eraser", "dream", "dreamer"):
            if query.endswith(frag):
                query = query.rstrip(frag)
                break
        else:
            print("NO")
            break
        if not query:
            print("YES")
            break



solve(s)
S=input()
while len(S) >=5:
	if S[-7:]=='dreamer':
		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')
		break
if len(S)==0:
	print('YES')
if 1<=len(S)<=4:
	print('NO')
words=["eraser","erase","dreanmer","dream"]
S=input()
for i in range(4):
    S=S.strip(words[i])
if S=="":
    print("Yes")
else:
    print("No")
import re
S = input()
"""
metacharacter
^ = 文字列の先頭
| = or
+ = 直前のパターンを1回以上繰り返す
$ = 文字列の末尾
"""
if re.match("^(dream|dreamer|erase|eraser)+$", S):
    print("Yes")
else:
    print("No")
S = list(input())
while True:
  if len(S) >= 5:
    if S[:5] == ["d", "r", "e", "a", "m"]:
      del S[:5]
    elif S[:5] == ["e", "r", "a", "s", "e"]:
      del S[:5]
    elif S[:6] == ["e", "r", "a", "s", "e", "r"]:
      del S[:6]
    elif S[:7] == ["d", "r", "e", "a", "m", "e", "r"]:
      del S[:7]
    else:
      print("NO")
      break
  elif len(S) == 0:
    print("YES")
    break
  else:
    print("NO")
    break
import re
S = input()
print("YES" if re.match("(dream|dreamer|erase|erase)+", S) else "NO")
S = input()
temp = ['eraser', 'erase', 'dreamer', 'dream']

while(1):
    for i in temp:
        if S.startswith(i):
            S = S.replace(i, '')
            break
    else:
        break
if len(S) == 0:
    print('YES')
else:
    print('NO')
s = list(input())
s.reverse()

while len(s) > 5:
    if s[:5] == list("maerd"):
        del s[:5]
        continue
    elif s[:7] == list("remaerd"):
        del s[:7]
        continue
    elif s[:5] == list("esare"):
        del s[:5]
        continue
    elif s[:6] == list("resare"):
        del s[:6]
        continue
    else:
        break

if s == []:
    print("YES")
else:
    print("NO")
# -*- coding: utf-8 -*-

S = input()

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


if len(S) ==0:
    print("NO")
else:
    print("YES")
from collections import deque

s = input()
q = deque(list(s))

while q:
  if len(q) >= 5:
    subs = q.popleft()+q.popleft()+q.popleft()+q.popleft()+q.popleft()
    if subs != 'erase' and subs != 'dream':
      print('NO')
      exit()
    if len(q) != 0 and q[0] == 'r':
      q.popleft()
  else:
    print('NO')
    exit()
    
print('YES')
S = input()
flag = 0
S = S[::-1]
print(S)
while True:
    if S.startswith("maerd") or S.startswith("esare"):
        S = S[5:]
    elif S.startswith("remaerd"):
        S = S[7:]
    elif S.startswith("resare"):
        S = S[6:]
    elif S == "":
        break
    else:
        flag = 1
        break
print("YES" if flag == 0 else "NO")
import re
S = input()
if re.match("^(dream|dreamer|erase|eraser)+$", S):
    print("Yes")
else:
    print("No")
import sys

t = set('dream, dreamer, erase, eraser'.split(', '))

def obtainable(s):
  while True:
    if s[-5:] in t:
      s = s[:-5]
    elif s[-6:] in t:
      s = s[:-6]
    else:
      return False
    if not s:
      return True
    
s = sys.stdin.readline().rstrip()

def main():
  print("YES" if obtainable(s) else "NO")

if __name__ ==  '__main__':
  main()