peterverebics/CodeNet_Python_118 huggingface dataset:
import re
S = input()
'''
メタ文字：
^ = 文字列の先頭、
| = OR
+ = 直前のパターンを1回以上繰り返し、
$ = 文字列の末尾
'''
if re.match("^(dream|dreamer|erase|eraser)+$", S):
    print('YES')
else:
    print('NO')
S = input()
k=0
t=len(S)
while k<len(S):
    if(S[-(k+5):t-k] == 'dream' or S[-(k+5):t-k] == 'erase')and k+5<len(S)+1:
        k+=5
        continue
    elif(S[-(k+6):t-k] == 'eraser')and k+6<len(S)+1:
        k+=6
        continue
    elif(S[-(k+7):t-k] == 'dreamer')and k+7<len(S)+1:
        k+=7
        continue
    else:
        print('NO')
        break
else:
    print('YES')
s = input()
n = len(s)
yn = "YES"

while(len(s) > 0):
    if(s.endswith("dream") or s.endswith("erase")):
        s = s[:(len(s)-5)]
    elif(s.endswith("eraser")):
        s = s[:(len(s)-6)]
    elif(s.endswith("dreamer")):
        s = s[:(len(s)-7)]
    else:
        yn = "NO"
        break

print(yn)
s = input()[::-1]
templates = [s[::-1] for s in ["dream", "dreamer", "erase", "eraser"]]
while s:
    for template in templates:
        if s.startswith(template):
            s = s.replace(template, "", 1)
            break
    else:
        break
print("YES" if not s else "NO")
import re
S = input()
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$", S) else "NO")
#ABC 049 C
S = input()
T = ''
S = S[::-1]
words = ["dream","dreamer","erase","eraser"]
rev_words = [w[::-1] for w in words]

flag = False
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)
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))
MOD = 10 ** 9 + 7


S = input()
S = ''.join(list(reversed(S)))
while len(S) > 0:
    if S[:7] == 'remaerd':
        S = S[7:]
    elif S[:6] == 'resare':
        S = S[6:]
    elif S[:5] in ['esare', 'maerd']:
        S = S[5:]
    else:
        print('NO')
        exit(0)
print('YES')
import re
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$",input()) else "NO")
#!/user/bin/env pypy3
import itertools
import sys


def fast_input():
    return sys.stdin.readline()[:-1]


def print_format(b: bool) -> str:
    return "YES" if b else "NO"


def solve(s: str) -> bool:
    for p in itertools.permutations(["dreamer", "eraser", "dream", "erase"]):
        work = s
        for token in p:
            work = work.replace(token, '')
        if work == "":
            return True
    return False


def main():
    result = solve(fast_input())
    print(print_format(result))


main()
def main():
    s = input()
    w = ["dream", "dreamer", "erase", "eraser"]
    last = len(s)
    for _ in range(len(s)):
        if last < 1:
            break
        for ww in w:
            if s[last - len(ww):] == ww:
                s = s[:last - len(ww)]
                last -= len(ww)
    print("YES" if last < 1 else "NO")


if __name__ == '__main__':
    main()
data = input()
data = data.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if data:
    print("NO")
else:
    print("YES")
S = input()
while len(S) > 0:
  if S[-5:] == 'dream':
    S = S[:-5]
  elif S[-5:] == 'erase':
    S = S[:-5]
  elif S[-7:] == 'dreamer':
    S = S[:-7]
  elif S[-6:] == 'eraser':
    S = S[:-6]
  else:
    print('NO')
    exit()
print("YES")
s = input()
t = ''
result = 'NO'

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

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

s_rev = s[::-1]

while len(s) > 0:
    for script in scripts:
        if s_rev[:len(script)] == script:
            s_rev = s_rev[len(script):]
            break
    else:
        break

if s_rev == '':
    result = 'YES'
print(result)
# C 白昼夢

s = input()[::-1]

cnt = 0
while cnt < len(s):
  if not s[cnt:cnt+7] == "remaerd":
    if not s[cnt:cnt+6] == "resare":
      if not s[cnt:cnt+5] in ["maerd", "esare"]:
        print("NO")
        exit()
      else:
        cnt += 5
    else:
      cnt += 6
  else:
    cnt += 7
print("YES")
S = str(input())[::-1]
words = ['maerd', 'esare', 'remaerd', 'resare']

leng = len(S)
while leng>=5:
    if S[:5] in words:
        S = S[5:]
        leng -= 5
    elif leng>=7 and S[:7] in words:
        S = S[7:]
        leng -= 7
    elif leng>=6 and S[:6] in words:
        S = S[6:]
        leng -= 6
    else:
        print('NO')
        break

if leng==0:
    print('YES')
# coding: utf-8
"""this is python work script"""

def solver(word):
    """solve this problem"""
    check_result = word.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')

    answer = 'YES'
    if check_result:
        answer = 'NO'

    return answer

def main():
    """main function"""
    input_word = input().rstrip()
    answer = solver(input_word)
    print(answer)

if __name__ == '__main__':
    main()
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")
S = input()
a = ['maerd', 'remaerd', 'esare', 'resare']
tmp =''
for s in S[::-1]:
    tmp += s
    if tmp in a: tmp=''
print('YES' if len(tmp)==0 else'NO')
s=input()

s=s.replace("eraser","")
s=s.replace("erase","")
s=s.replace("dreamer","")
s=s.replace("dream","")
if s=="":
    print("YES")
else:
    print("NO")
S=input()
A=S.replace("eraser","").replace("erase","").replace("dreamer","dream").replace("dream","")
if A=="":
	print("YES")
else:
	print("NO")
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s:
    print("NO")
else:
    print("YES")
S = input()[::-1]
W = [s[::-1] for s in ('dream', 'dreamer', 'erase', 'eraser')]

def isOk():
    now = 0
    while now < len(S):
        for w in W:
            if S[now: now + len(w)] == w:
                now += len(w)
                break
        else:
            return False
    return True

print('YES' if isOk() else 'NO')
import re
s = input()
match = re.match(r"^(dream|dreamer|erase|eraser)+$",s)
print("YES" if match else "NO")
a,b,c,d=[i[::-1] for i in ['dream','dreamer','erase','eraser']]
s,j=input()[::-1],True
while j:
  j=False
  for i in [a,b,c,d]:
    if s.startswith(i): s=s[len(i):];j=True
print('YNEOS'[len(s)>0::2])
s = input()
x = s.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if x:
    print("NO")
else:
    print("YES")
S=input()
i=0
ans="YES"
while i<len(S) or ans=="Yes":
    if S[i:i+7]=="dreamer" and S[i+5:i+10]!="erase":
        i+=7
    elif S[i:i+6]=="eraser":
        i+=6
    elif S[i:i+5] == "dream" or S[i:i+5] == "erase":
        i+=5
    else:
        ans="NO"
        break
if i<len(S)-1:
    ans="NO"
print(ans)
S = input()

S = S[::-1]

cand = {'maerd', 'remaerd', 'esare', 'resare'}

can = True

while S not in cand:
    ok = False
    for x in cand:
        if S[:len(x)] == x:
            S = S[len(x):]
            ok = True
            break
    if ok == False:
        can = False
        break

if can == True:
    print('YES')
else:
    print('NO')
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")
#input
S = input()
S = S.replace('eraser','') # 文字列の置き換えeraser を空文字に
S = S.replace('erase','')
S = S.replace('dreamer','')
S = S.replace('dream','')

#
if S:
    print('NO')
else:
    print('YES')
S=input()
W=[0]*(len(S)+1)
W[0]=1
words=['dream','dreamer','erase','eraser' ]
for i in range(len(S)):
  if W[i]==0:
    continue
  for k in words:
    if S[i:i+len(k)]==k:
      W[i+len(k)]=1
if W[len(S)]==1:
  print("YES")
  exit()
else:
  print("NO")
s=input()
newstring=''.join(list(reversed(s)))

while len(newstring)>0:
    if newstring[:5]=="maerd":
        newstring=newstring[5:]

    elif newstring[:7]=="remaerd":
        newstring=newstring[7:]

    elif newstring[:5]=="esare":
        newstring=newstring[5:]

    elif newstring[:6]=="resare":
        newstring=newstring[6:]

    else:
        print("NO")
        exit()

print("YES")
text = "".join(reversed(input()))
words = ["".join(reversed(x)) for x in ["dreamer", "eraser", "dream", "erase"]]

while text != "":
  has_striped = False
  for word in words:
    if text.find(word) != 0: continue
    text = text[len(word):]
    has_striped = True
  if not has_striped: break

print("YES" if text == "" else "NO")
S = input()
S = S.replace('eraser', ' ').replace('erase', ' ').replace('dreamer', ' ').replace('dream', ' ').replace(' ', '')
if S == '':
    print('YES')
else:
    print('NO')
s = list(input())
n = len(s)
temp = ['maerd', 'remaerd', 'esare', 'resare']
s.reverse()

i = 0
while i < n:
    flag = False
    for t in temp:
        if s[i:i+len(t)] == list(t):
            i += len(t)
            flag = True
            break

    if not flag:
        print("NO")
        exit()

print("YES")
s=input()
n=len(s)
i=1
for j in range(n):
    if s[-i:-i-5:-1]=="maerd":
        i+=5
 
    if s[-i:-i-5:-1]=="esare":
        i+=5

    if s[-i:-i-6:-1]=="resare":
        i+=6

    if s[-i:-i-7:-1]=="remaerd":
        i+=7

    if i==n+1:
        print("YES")
        break

if i != n+1:
    print("NO")
import re  # 正規表現

s = input()

# re.sub(pattern, word, line) はlineのうち、patternに一致する部分をwordに変換します。
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')
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    s = input()
    word = ['eraser', 'erase', 'dreamer', 'dream']
    for x in word:
        s = s.replace(x, '')
    if s == '':
        print('YES')
    else:
        print('NO')
        
        
        
            
        
    
    
if __name__ == '__main__':
    main()
#!/usr/bin/env python
# coding: utf-8

# In[1]:


S = input()


# In[4]:


f = True
s_reversed = S[::-1]
words = ['maerd', 'remaerd', 'esare', 'resare']
while s_reversed:
    length = len(s_reversed)
    for i in [7,6,5]:
        while s_reversed[:i] in words:
            s_reversed = s_reversed[i:]
    if length == len(s_reversed):
        print("NO")
        f = False
        break
if f:
    print("YES")


# In[ ]:
s = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')

if s:
    print('NO')
else:
    print('YES')
import re
s = input()
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$", s) else "NO")
print('NO' if input().replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','') else 'YES')
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


S = S()

while 1:
    for flag in ("erase", "eraser", "dream", "dreamer"):
        if S.endswith(flag):
            S = S[:-len(flag)]
            break
    else:
        print('NO')
        break
    if not S:
        print('YES')
        break
def resolve():
    S = list(input())
    S.reverse()
    substr = ''
    p = ['dream', 'dreamer', 'erase', 'eraser']
    for i in S:
        substr = i + substr
        if substr in p:
            substr = ''
    ans = 'YES' if substr == '' else 'NO'
    print(ans)


if __name__ == "__main__":
    resolve()
#!/usr/bin/env python3

vocab = set(['dream', 'dreamer', 'erase', 'eraser'])

def parse(s):
    stack = [0]
    while stack:
        i = stack.pop()
        if i == len(s):
            return True
        for w in vocab:
            if s[i:].startswith(w):
                stack.append(i + len(w))
    return False

s = input()
if parse(s):
    print('YES')
else:
    print('NO')
s = input()[::-1]
word = ["dream", "dreamer", "erase", "eraser"]
dream = "dream"[::-1]
dreamer = "dreamer"[::-1]
erase = "erase"[::-1]
eraser = "eraser"[::-1]
while True:
    if s[:5] == dream or s[:5] == erase:
        s = s[5:]
        continue
    elif s[:6] == eraser:
        s = s[6:]
        continue
    elif s[:7] == dreamer:
        s = s[7:]
        continue
    break
if len(s) == 0:
    print("YES")
else:
    print("NO")
s=input().strip()
s=s.replace("eraser","A")
s=s.replace("erase","A")
s=s.replace("dreamer","A")
s=s.replace("dream","A")
print("YES" if not s.replace("A","") else "NO")
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')
S = input()[::-1]
ss = ['maerd', 'remaerd', 'esare', 'resare']

while True:
    for s in ss:
        if S.startswith(s):
            S = S[len(s):]
            break
    else:
        if S != '':
            print('NO')
            break

    if S == '':
        print('YES')
        break
import sys

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

def obtainable(s):
  while True:
    for i in range(5, 8):
      if s[-i:] in t:
        s = s[:-i]
        break
    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()
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = input()
words = ('dream', 'dreamer', 'erase', 'eraser')

while True:
    if S == '':
        print("YES")
        break

    for word in words:
        if S.endswith(word):
            S = S[:-len(word)]
            break
    else:
        print("NO")
        break
S = input()[::-1]
W = ['dream','dreamer','erase','eraser']
i = 0
while i < len(S):
    for w in W:
        if S[i:i+len(w)] == w[::-1]:
            i += len(w)
            break
    else:
        print('NO')
        exit()
print('YES')
S = input()

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

S = S[::-1]
for i in range(4):
    T[i] = T[i][::-1]

can = True
i = 0
while i < len(S):
    can2 = False
    for t in T:
        if S[i:i + len(t)] == t:
            can2 = True
            i += len(t) - 1
    if can2 == False:
        can = False
        break
    i += 1

if can:
    print("YES")
else:
    print("NO")
print("NO" if input().replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "") else "YES")
S = str(input())
S = S.replace('eraser', '')
S = S.replace('erase', '')
S = S.replace('dreamer', '')
S = S.replace('dream', '')
if S == '':
  print('YES')
else:
  print('NO')
s = input()[::-1]
while s:
  start = len(s)
  for t in ['maerd', 'remaerd', 'esare', 'resare']:
    if t == s[:len(t)]:
      s = s[len(t):]
  if start == len(s):
    break
print("YNEOS"[len(s)>0::2])
S = input()
if len(S) == 0:
  print('NO')
else:
  if len(S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')) == 0:
    print('YES')
  else:
    print('NO')
s = input()

i = len(s)

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

print('YES')
import re
s = input()
m = re.fullmatch(r"(dreamer|dream|erase|eraser)+", s)

if m:
    print("YES")
else:
    print("NO")
S = input()[::-1]

kari = ['dream', 'dreamer', 'erase', 'eraser']
 
words = [i[::-1] for i in kari]
 
l = len(S)
cnt = ''

for i in range(l):
    cnt += S[i]
    if cnt in words:
        cnt = ''

if cnt!='':
    print('NO')
else:
    print('YES')
words = ["dream", "dreamer", "erase", "eraser"]
            #5      #7          #5      #6
s = input()

while len(s) > 0:
    if s[-5:] in words:
        s = s[:-5]
    elif s[-6:] in words:
        s = s[:-6]
    elif s[-7:] in words:
        s = s[:-7]
    else:
        print("NO")
        exit()

print("YES")
s=input().replace("eraser","0").replace("erase","0").replace("dreamer","0").replace("dream","0").replace("0", "")
if s:
    print("NO")
else:
    print("YES")
#!/usr/bin/env python3
import re
s = input()
s = re.sub(r'erase(r|)',"", s)
s = re.sub(r'dream(er|)',"", s)
print('YNEOS'[s!=""::2])
s = input()
s = s[::-1]
i = 0
check = True
while i < len(s):
  if s[i:i+5] == "maerd" or s[i:i+5] =="esare":
    i += 5
  elif s[i:i+6] == "resare":
    i += 6
  elif s[i:i+7] == "remaerd":
    i += 7
  else:
    check = False
    break
    
if check == True:
  print("YES")
else:
  print("NO")
import re
sin = input()
match = re.match(r"^(dream|dreamer|erase|eraser)+$",sin)
print("YES" if match else "NO")
check = ['dream', 'dreamer', 'erase', 'eraser']
    
s=input()

end = len(s)

while 0 < end:
    if s[end-5:end] in check:
        end -= 5
    elif s[end-6:end] in check:
        end -= 6
    elif s[end-7:end] in check:
        end -= 7
    else:
        print('NO')
        exit()
print('YES')
S = input()

t1 = "dream"
t2 = "dreamer"
t3 = "erase"
t4 = "eraser"

while True:
    if S[-5:] == t1 or S[-5:] == t3:
        S = S[0:-5]
    elif S[-6:] == t4:
        S = S[0:-6]
    elif S[-7:] == t2:
        S = S[0:-7]
    elif len(S) == 0:
        print("YES")
        break
    else:
        print("NO")
        break
#白昼夢
s = input()
words = ['dream','dreamer','erase','eraser']
#evaluate
while True:
  for i in range(4):
    if s.endswith(words[i]):
      s = s[:-len(words[i])]
      break #inner loop
  else:
    print('NO')
    break #outerloop
  if not s: 
    print('YES')
    break #outerloop
s = list(input())

a = list("dream")
b = list("dreamer")
c = list("erase")
d = list("eraser")
flag = 0

while(flag == 0):
    if s[-7:] == b:
        del s[-7:]
    elif s[-6:] == d:
        del s[-6:]
    elif s[-5:] == a or s[-5:] == c:
        del s[-5:]
    elif s == []:
        print("YES")
        flag = 1
    else:
        print("NO")
        flag = 1
S = input()
words = ["dream", "dreamer", "erase", "eraser"]
i = len(S)

while i > 0:
    if S[i - 5 : i] in words:
        i = i - 5
    elif S[i - 6 : i] in words:
        i = i - 6
    elif S[i - 7 : i] in words:
        i = i - 7
    else:
        break

if i > 0:
    print("NO")
else:
    print("YES")
words = ['maerd', 'remaerd', 'esare', 'resare']
S = input()
T = ''
for a in S[::-1]:
  T += a
  for s in words:
    if T == s:
      T = ''
print('YES' if T == '' else 'NO')
import sys

s=input()

lens=len(s)

while lens>0:
    lens0=lens
    if s[lens-7:lens]=="dreamer":
        lens=lens-7
    elif s[lens-5:lens]=="dream":
        lens=lens-5
    elif s[lens-6:lens]=="eraser":
        lens=lens-6
    elif s[lens-5:lens]=="erase":
        lens=lens-5
    if lens0==lens:
        print("NO")
        sys.exit()

print("YES")
s = input()
s = s.replace("eraser", "X")
s = s.replace("erase", "X")
s = s.replace("dreamer", "X")
s = s.replace("dream", "X")
 
count = s.count("X")
if len(s) == count:
    print("YES")
else:
    print("NO")
S = input()
candidates = ['dream', 'dreamer', 'erase', 'eraser']

while S:
    for candidate in candidates:
        if S.endswith(candidate):
            S = S[:-len(candidate)]
            break
    else:
        break

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

def check(t):
  if len(t) >= 5 and (t[-5:] == 'dream' or t[-5:] == 'erase'):
    return True,t[:-5]
  elif len(t) >=6 and t[-6:] == 'eraser':
    return True,t[:-6]
  elif len(t) >= 7 and t[-7:] == 'dreamer':
    return True,t[:-7]
  else:
    return False,t

while(len(S) > 0):
  flag,S = check(S)
  if not flag:
    print('NO')
    exit()
print('YES')
a = input()

b = a[::-1]

i = 0
while i  < len(b):
    if b[i:i+5] == "esare":
        i += 5
    elif b[i:i+5] == "maerd":
        i += 5
    elif b[i:i+6] == "resare":
        i += 6
    elif b[i:i+7] == "remaerd":
        i += 7
    else:
        ans = "NO"
        break

if i  == len(b):
    ans = "YES"
else:
    ans = "NO"

print(ans)
s = input()

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

if s == '':
    print('YES')
else:
    print('NO')
S = input().replace('eraser', '!').replace('erase', '!').replace('dreamer', '!').replace('dream', '!').replace('!', '')
if len(S) == 0:
    print('YES')
else:
    print('NO')
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')
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 = S[::-1]
T = ['dream', 'dreamer', 'erase', 'eraser']

T_rev = []

for i in range(len(T)):
	T_rev.append(T[i][::-1])

flag = True
i = 0
while i < len(S):
	for j in range(len(T)):
		ed = i + len(T_rev[j])
		# print(S[i:ed])
		if (S[i:(i + len(T_rev[j]))] == T_rev[j]):
			i += len(T[j])
			flag = True
			break
		else:
			flag = False

	if(flag == False):
		break

if(flag):
	print('YES')
else:
	print('NO')
s=input()
l=len(s)
def judge():
  cnt=0
  while True:
    if s[l-cnt-6:l-cnt]=='eraser':
      cnt+=6
    elif s[l-cnt-5:l-cnt]=='erase':
      cnt+=5
    elif s[l-cnt-7:l-cnt]=='dreamer':
      cnt+=7
    elif s[l-cnt-5:l-cnt]=='dream':
      cnt+=5
    else:
      print('NO')
      exit()
    if cnt==len(s):
      print('YES')
      exit()

judge()
s = input()
temp = s
while len(temp) > 4:
    if temp[len(temp) - 3:] == 'eam' and temp[len(temp) - 5:] == 'dream': temp = temp[: len(temp) - 5]
    elif temp[len(temp) - 3:] == 'mer' and temp[len(temp) - 7:] == 'dreamer': temp = temp[: len(temp) - 7]
    elif temp[len(temp) - 3:] == 'ase' and temp[len(temp) - 5:] == 'erase': temp = temp[: len(temp) - 5]
    elif temp[len(temp) - 3:] == 'ser' and temp[len(temp) - 6:] == 'eraser': temp = temp[: len(temp) - 6]
    else: break
if len(temp) > 4: print('NO')
else: print('YES')
s = input()[::-1]
x = ["dream", "dreamer", "erase", "eraser"]
can = True
i = 0
for a in range(4):
    x[a] = x[a][::-1]
while(True):
    if(i == len(s)):
        break
    can2 = False
    for j in range (4):
        if(s[i:i+len(x[j])] == x[j]):
            can2 = True
            i += len(x[j])
    if(can2 == False):
        can = False
        break
print("YES" if can == True else "NO")
s = input()[::-1]  # 反転
template = list('dream dreamer erase eraser'.split())
template = [c[::-1] for c in template]  # 反転

while s:
    for c in template:
        if s.startswith(c):
            s = s[len(c):]
            break
    else:
        break
print("YES") if s == "" else print("NO")
import sys

S = sys.stdin.readline().strip()

S = S[::-1]
i = 0
while i < len(S):
    if S[i:i+5] == "maerd":
        i += 5
    elif S[i:i+7] == "remaerd":
        i += 7
    elif S[i:i+5] == "esare":
        i += 5
    elif S[i:i+6] == "resare":
        i += 6
    else:
        break

if i == len(S):
    print("YES")
else:
    print("NO")
s = input()
ans = 'YES'
 
while len(s) > 0:
    if s.endswith('dreamer'):
        s = s[:-7]
    elif s.endswith('dream'):
        s = s[:-5]
    elif s.endswith('eraser'):
        s = s[:-6]
    elif s.endswith('erase'):
        s = s[:-5]
    else:
        ans = 'NO'
        break
 
print(ans)
n = input()
t = ["dream", "dreamer", "erase", "eraser"]

while True:
  if not n:
    status = "YES"
    break

  elif n[-5:] in t:
    n = n[:-5]
    
  elif n[-6:] in t:
    n = n[:-6]
  
  elif n[-7:] in t:
    n = n[:-7]
    
  else:
    status = "NO"
    break
    
print(status)
def main():
    s = input()

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

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

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


if __name__ == "__main__":
    main()
s = input()
a = s.replace('eraser','')
b = a.replace('erase','')
c = b.replace('dreamer','')
d = c.replace('dream','')
if d == '':
    print('YES')
else:
    print('NO')