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)]
                break
        else:
            print("NO")
            break
        if not query:
            print("YES")
            break



solve(s)
S = input()
a = 'dream'
b = 'dreamer'
c = 'erase'
d = 'eraser'
T = S
while len(T) > 4:
    if S[len(T)-5:len(T)] == a:
        T = T[0:len(T)-5]
    elif S[len(T)-7:len(T)] == b:
        T = T[0:len(T)-7]
    elif S[len(T)-5:len(T)] == c:
        T = T[0:len(T)-5]
    elif S[len(T)-6:len(T)] == d:
        T = T[0:len(T)-6]
    else:
        break
if T == '':
    print('YES')
else:
    print('NO')
S = input()
dp = [0] * (len(S) + 1)
dp[0] = 1

words = ["dream", "dreamer", "erase", "eraser"]
done = 'NO'

for i in range(len(S)):
    if dp[i] == 0:
        continue
    for w in words:
        if S[i:i+len(w)] == w:
            dp[i+len(w)] = 1
    
    if dp[len(S)] == 1:
        done = 'YES'
        break

print(done)
import re
s = input()
if re.match("(dream|dreamer|erase|eraser)+$", s):
    print("YES")
else:
    print("NO")
def main():
	S = input()

	border = len(S)

	while True:
		if S[border - 5: border] == "dream":
			border -= 5
		elif S[border - 7: border] == "dreamer":
			border -= 7
		elif S[border - 5: border] == "erase":
			border -= 5
		elif S[border - 6: border] == "eraser":
			border -= 6
		else:
			break

	if border == 0:
		print("YES")
	else:
		print("NO")
 
 
if __name__ == "__main__":
  	main()
S = list(input())
S.reverse()
S = ''.join(S)
st = ['maerd','remaerd','esare','resare']
ans = 'YES'
while S != '':
    if S[0:5] in st:
        S = S[5:]
    elif S[0:6] in st:
        S = S[6:]
    elif S[0:7] in st:
        S = S[7:]
    else:
        ans = 'NO'
        break
print(ans)
divide = ["dream", "dreamer", "erase", "eraser"]
S = input()[::-1]
for i in range(4): divide[i] = divide[i][::-1]

can = True
i = 0
while i < len(S):
  can2 = False
  for d in divide:
    if S[i:i+len(d)] == d:
      can2 = True
      break
  i += len(d)*(can2)
  if not can2:
    can = False
    break
print("YNEOS"[~can%2::2])
def check():
  S = input()
  n = len(S)
  dp = [False]*(n+10)
  dp[0] = True
  for i in range(n+1):
    if S[i:i+5]=='dream':
      dp[i+5] |= dp[i]
    if S[i:i+7]=='dreamer':
      dp[i+7] |= dp[i]
    if S[i:i+5]=='erase':
      dp[i+5] |= dp[i]
    if S[i:i+6]=='eraser':
      dp[i+6] |= dp[i]
  if dp[n]==True:
    return 'YES'
  return 'NO'
print(check())
# dfs
import sys
sys.setrecursionlimit(10**6)

C = ['dream', 'dreamer', 'erase', 'eraser']
S = input()
L = len(S)


def dfs(x, l):
    if l == L:
        return True
    elif l > L:
        return False

    match = S[l:l+7]
    for c in C:
        if match.find(c) == 0:
            if dfs(c, l+len(c)):
                return True
    return False


print('YES' if dfs('', 0) else 'NO')
s=input()
import re
#re.match は複数を対象にすればマッチする該当のものが返される。一つの時ifの後に持ってくると条件式として利用可能。
if re.match("^(dream|dreamer|erase|eraser)+$",s) :
       print("YES")
else:
       print("NO")
import sys 
sys.setrecursionlimit(10**6)
s = input()
def dfs(s):
    while True:
        f = True
        for i in ['dream', 'dreamer', 'erase', 'eraser']:
            if s[-len(i):]==i:
                s = s[:-len(i)]
                if s=='':
                    return True
                f = False
        if f: return False
    
if dfs(s):
    print('YES')
else:
    print('NO')
s = input()

while s!="":
    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")
        exit()
print("YES")
def main():
    s = input()

    st = [s]
    while st:
        x = st.pop()
        if x == '':
            print('YES')
            return

        for w in ('dream', 'dreamer', 'erase', 'eraser'):
            if x.endswith(w):
                st.append(x[:-len(w)])

    print('NO')


if __name__ == '__main__':
    main()
import re
S = input()
if re.match("^(dream|dreamer|erase|eraser)+$", S):
  print("YES")
else:
  print("NO")
s = list(input())

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

pointer = len(s)
while pointer > 0:
    if s[pointer-5: pointer] == list(words[0]):
        pointer -= 5
    elif s[pointer-5: pointer] == list(words[2]):
        pointer -= 5
    elif s[pointer-7: pointer] == list(words[1]):
        pointer -= 7
    elif s[pointer-6: pointer] == list(words[3]):
        pointer -= 6
    else:
        ans = 'NO'
        break

print(ans)
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()
import sys
S = input()
while len(S)>5:
  if S[-7:] == "dreamer":
    S = S[:-7]
  elif S[-6:] == "eraser":
    S = S[:-6]
  elif S[-5:] == "dream" or S[-5:] == "erase":
    S = S[:-5]
  else:
    print("NO")
    sys.exit()
print("YES")
import re

s = input()

m = re.match(r"^(dream|dreamer|erase|eraser)+$", s)

print("NO" if m is None else "YES")
S = input()
x = S.replace('eraser', '').replace('erase', '').replace('dreamer','').replace('dream','')
print('YES' if not x else 'NO')
s,f=input()[::-1],-1
while f<0:
    if s:
        if s[:5]=='maerd':
            s=s[5:]
        elif s[:5]=='esare':
            s=s[5:]
        elif s[:6]=='resare':
            s=s[6:]
        elif s[:7]=='remaerd':
            s=s[7:]
        else:
            f=0
    else:
        f=1
print(['NO','YES'][f])
S = input().replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')
if S == '':
    print('YES')
else:
    print('NO')
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']


def reverse(t):
    return t[::-1]


RT = [reverse(t) for t in T]
RS = reverse(S)
can = True
i = 0
while i < len(RS):
    can2 = False
    for j in range(4):
        sizeT = len(RT[j])
        if RT[j] == RS[i:i + sizeT]:
            i += sizeT
            can2 = True
            break

    if not can2:
        can = False
        break

if can:
    print('YES')
else:
    print('NO')
S = input().replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if S:
    print("NO")
else:
    print("YES")
s = list(input());tmp = ""
t = ["maerd", "remaerd", "esare", "resare"]
while s:
    tmp += s.pop()
    if tmp in t: tmp = ""
if len(tmp)>=7: print("NO")
else: print("YES")
S = input()
C = ['dream', 'dreamer', 'erase', 'eraser']

while S:
    for c in C:
        if S.endswith(c):
            S = S[:-len(c)]
            break
    else:
        print('NO')
        break
else:
    print('YES')
S = input()

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

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

if S == "":
        print("YES")
else:
        print("NO")
s = str(input())
alist = ["dream", "dreamer", "erase", "eraser"]
ans = False

def backwards(x):
  return x[::-1]
s = backwards(s)
alist = [backwards(i) for i in alist]

t = ""
start = 0
for i in range(len(s)+1):
  if s[start:i] in alist:
    t+=s[start:i]
    start = i
if s==t:
  print("YES")
else:
  print("NO")
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")
s=input()
List=["eraser","erase","dreamer","dream"]
for item in List:
  s = s.replace(item,'')
if len(s)==0:
  print('YES')
else:
  print('NO')
s = input()

s1 = s.replace("eraser", 'xxx')
s2 = s1.replace("erase", 'xxx')
s3 = s2.replace("dreamer", 'xxx')
s4 = s3.replace("dream", 'xxx')

s5 = s4.strip('x')

if (s5 == ''):
    print('YES')
else:
    print('NO')
S = input()
dp = [False for _ in range(len(S)+1)]
char_list = ['dream', 'dreamer', 'erase', 'eraser']
dp[0] = True

for i in range(len(S)):
  if dp[i] == False:
    continue
  for char in char_list:
    if S[i:i+len(char)] == char:
      dp[i+len(char)] = True

if dp[len(S)]:
  print('YES')
else:
  print('NO')
s = input()
s_1 = s.replace('eraser', '').replace('erase', '').replace('dreamer','').replace('dream','')
if s_1 == '':
    print("YES")
else:
    print("NO")
S = input()
S = S[::-1]
pattern = ["dream","dreamer","erase","eraser"]
for i in range(len(pattern)):
  pattern[i] = pattern[i][::-1]
while True:
  flag = False
  for v in pattern:
    if S[:len(v)] == v:
      S = S[len(v):]
      flag = True
  if S == "":
    print("YES")
    break
  elif not flag:
    print("NO")
    break
S = input()[::-1]
D = ["dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1]]
while True:
    for d in D:
        if S.startswith(d):
            S = S.replace(d, "", 1)
            break
    else:
        break
print("YNEOS"[S!=""::2])
import re;print("YNEOS"[re.match("(erase(r)?|dream(er)?)+$",input())is None::2])
s3=s=input()[::-1]
l=["maerd","remaerd","esare","resare"]
s2=""
for i in range(len(s)):
 s2+=s[i]
 if s2 in l:
  s3=s3[len(s2):]
  s2=""
print("YES"if s2==""else "NO")
S = input()
idx = len(S)
ans = 'YES'
while idx > 0:
    if S[idx-5:idx] == 'dream':
        idx -= 5
    elif S[idx-5:idx] == 'erase':
        idx -= 5
    elif S[idx-7:idx] == 'dreamer':
        idx -= 7
    elif S[idx-6:idx] == 'eraser':
        idx -= 6
    else:
        ans = 'NO'
        break
print(ans)
S = input()
i = 0
n = len(S)
while i <= n-5:
    if S[i:i+5] == "dream":
        i += 5
        if S[i:i+2] == "er" and S[i:i+5] != "erase":
            i += 2
    elif S[i:i+5] == "erase":
        i += 5
        if S[i:i+1] == "r":
            i += 1
    else:
        break
if i != len(S):
    print("NO")
else:
    print("YES")
S = input()

while 1:
    for target in ["dream", "dreamer", "erase", "eraser"]:
        if S.endswith(target):
            S = S[:-len(target)]
            break
    else:
        print("NO")
        break
    if len(S) == 0:
        print("YES")
        break
patterns = [[5, "dream"], [7, "dreamer"], [5, "erase"], [6, "eraser"]]

s = input()

idx = len(s)
while idx > 0:
    for sub, pat in patterns:
        n_idx = idx - sub
        if pat == s[n_idx:idx]:
            idx = n_idx
            break
        else:
            continue
    if idx != n_idx:
        break

print("YES" if idx == 0 else "NO")
S = input()

num_eraser = S.count('eraser')
num_erase = S.count('erase') - num_eraser
num_dreamer = S.count('dreamer') - S.count('dreamerase')
num_dream = S.count('dream') - num_dreamer
# dream + erase(r) で dreamer が含まれるのに注意

# print(num_eraser, num_erase, num_dreamer, num_dream)
cnt = num_eraser * 6 + num_erase * 5 + num_dreamer * 7 + num_dream * 5
# print('cnt', cnt)
if len(S) == cnt:
    print('YES')
else:
    print('NO')
s = input()[::-1]
n = len(s)
l = 0
ok = True
while l <n:
    ok_list = ["maerd","remaerd","resare","esare"]
    if s[l:l+5] in ok_list:
        l +=5
    elif s[l:l+6] in ok_list:
        l+=6
    elif s[l:l+7] in ok_list:
        l+=7
    else:
        ok = False
        break
if ok:print('YES')
else:print('NO')
s = input()
words = ['eraser',  'erase', 'dreamer', 'dream']
for w in words:
    s = s.replace(w, '')
print('NO' if s else 'YES')
import re
S = input()

if re.match("^(dream|dreamer|erase|eraser)+$", S):
    print('YES')
else:
    print('NO')
import sys
S=list(input())
S.reverse()
S="".join(S)
#print(S)

while S:
  if len(S)<5:
    print("NO")
    sys.exit(0)  
  
  if S[:5]=="maerd":
    S=S[5:]
  elif S[:7]=="remaerd":
    S=S[7:]
  elif S[:5]=="esare":
    S=S[5:]
  elif S[:6]=="resare":
    S=S[6:]
  else:
    print("NO")
    sys.exit(0)
    
print("YES")
# dfs
import sys
sys.setrecursionlimit(10**6)

C = ['dream', 'dreamer', 'erase', 'eraser']
S = input()
L = len(S)

def dfs(l):
    if l == L:
        return True
    elif l > L:
        return False

    for c in C:
        if S.find(c, l, l+7) == l:
            if dfs(l+len(c)):
                return True
    return False

print('YES' if dfs(0) else 'NO')
s = input()
y = 0
while y < len(s):
    if s[y:y+11] == "dreameraser":
        y += 11
    elif s[y:y+10] == "dreamerase":
        y += 10
    elif s[y:y+7] == "dreamer":
        y += 7
    elif s[y:y+6] == "eraser":
        y += 6
    elif s[y:y+5] == "dream" or s[y:y+5] == "erase":
        y += 5
    else: 
        print("NO")
        break
else: print("YES")
S = input()[::-1]
Tl = ["dream", 'dreamer', 'erase', 'eraser']
flg = 0

for i in range(len(Tl)):
    Tl[i] = Tl[i][::-1]
while True:
    Sl = len(S)
    for i in range(len(Tl)):
        if S.find(Tl[i]) == 0:
            S = S[len(Tl[i]):]
    if len(S) == 0:
        flg = 1
        break
    elif len(S) == Sl:
        break
    else:
        pass

if flg == 1:
    print("YES")
else:
    print("NO")
s = str(input())
s = ''.join(list(reversed(s)))

t = 0
while t <= len(s):
    if s[t:t+5] == 'maerd':
        t += 5
        continue
    elif s[t:t+7] == 'remaerd':
        t += 7
        continue
    elif s[t:t+5] == 'esare':
        t += 5
        continue
    elif s[t:t+6] == 'resare':
        t += 6
        continue
    elif t == len(s):
        print('YES')
        quit()
    else:
        break
print('NO')
S = input()

list = ["eraser","erase","dreamer","dream"]
for x in list:
    S = S.replace(x,"")

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

while True:
  if s == "":
    print('YES')
    break
  elif s[-7:] == 'dreamer':
    s = s[:-7]
  elif s[-6:] == 'eraser':
    s = s[:-6]
  elif s[-5:] == 'dream' or s[-5:] == 'erase':
    s = s[:-5]
  else:
    print('NO')
    break
import re
s = input()
s = s[::-1]
#print(s)
match = re.match('((remaerd)|(maerd)|(resare)|(esare))*',s)
#print(match)
#print(match.group())
if match.group() == s:
    print('YES')
else:
    print('NO')
s = list(input())
s.reverse()
s_r = ""
for i in s:
    s_r+=i
s_r = s_r.replace("resare","")
s_r = s_r.replace("esare","")
s_r = s_r.replace("remaerd","")
s_r = s_r.replace("maerd","")
if len(s_r)==0:
    print("YES")
else:
    print("NO")
s = input()
flag = True
while(flag):
    if(len(s)==0):
        flag = False
    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:
        break
if(flag):
    print('NO')
else:
    print('YES')
s = input()

lst = ['dreameraser', 'dreamerase', 'dreamer', 'dream', 'eraser', 'erase']
while s:
  flag = 0
  for elem in lst:
    if elem in s:
      s = s.replace(elem, '')
      flag = 1
      break
  if flag == 0:
    print('NO')
    quit()
print('YES')
def solve(n):

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

    return "YES" if len(n) == 0 else "NO"

if __name__ == "__main__":
    n = input()
    print(solve(n))
S = input()[::-1]
T = ""

cand = ["dream", "dreamer", "erase", "eraser"]
cand = [c[::-1] for c in cand]

while S:
    for c in cand:
        if S.startswith(c):
            S = S[len(c):]
            break
    else:
        break

print("YES") if S == "" else print("NO")
S = input()
S = S.replace("eraser","-")
S = S.replace("erase","-")
S = S.replace("dreamer","-")
S = S.replace("dream","-")
S = S.replace("-","")
if len(S) == 0:
    print("YES")
else:
    print("NO")
# -*- coding: utf-8 -*-


S = input()
import sys
while True:
    if(len(S)==0):
        print("YES")
        sys.exit()
    if S.endswith("dreamer"):
        S = S[:-7]
    elif S.endswith("eraser"):
                S = S[:-6]
    elif S.endswith("dream"):
        S = S[:-5]
    elif S.endswith("erase"):
        S = S[:-5]
    else:
        print("NO")
        sys.exit()
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 = ''
print('YES' if T == '' else 'NO')
s = input()
words = ['eraser', 'erase', 'dreamer', 'dream']

for w in words:
    s = s.replace(w, '')

ans = 'YES' if s == '' else 'NO'
print(ans)
S = input()

s = ['dream', 'dreamer', 'erase', 'eraser']
R = len(S)
while(R > 0):
    for i in range(4):
        if R >= len(s[i]):
            if S[R-len(s[i]):R] == s[i]:
                R -= len(s[i])
                break
        if i == 3:
            print("NO")
            exit(0)
print("YES")
S = input()

T = ""

while True:
    T_len = len(T)
    for word in ["dream", "dreamer", "erase", "eraser"]:
        if word + T == S[-1 * len(word + T):]:
            T = word + T
            if T == S:
                print("YES")
                exit()
    if T_len == len(T):
        print("NO")
        exit()
init = input()

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

def reverseWord(str):
  return str[::-1]

def elimTheWord(str):
  for word in reversed_words:
    if str.find(word) == 0:
      str = str[len(word):]
  return str

reversed_words = list(map(reverseWord, words))

# main
target = reverseWord(init)

while True:
  pivot = elimTheWord(target)
  if pivot == '':
    print('YES')
    break
  if pivot == target:
    print('NO')
    break
  target = pivot
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
    elif s[:6] in ans:
        s = s[6:]
        flag = 1
        
if flag == 0:
    print("NO")
else:
    print("YES")
s=input()
a='dream'
b='dreamer'
c='erase'
d='eraser'
i=0

while(True):
	if i==len(s):
		print("YES")
		exit()
	if s[-7-i:len(s)-i]==b:
		i+=7
	elif s[-5-i:len(s)-i]==a:
		i+=5
	elif s[-6-i:len(s)-i]==d:
		i+=6
	elif s[-5-i:len(s)-i]==c:
		i+=5
	else :
		print("NO")
		exit()
s = input().replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if s:
    print("NO")
else:
    print("YES")
s = input().replace("eraser","").replace("erase","").replace("dreamer","").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("YES")
else:
	print("NO")
s = input()
s = s[::-1]
while s != "":
    if s[:5] == "esare" or s[:5] == "maerd":
        s = s[5:]
    elif s[:6] == "resare":
        s = s[6:]
    elif s[:7] == "remaerd":
        s = s[7:]
    else:
        print("NO")
        exit()
print("YES")
s = input()[::-1]
l = [ 'dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
	s1 = l[i][::-1]
	l[i] = s1

n = len(s)
i = 0
t = tuple(l)

while i < n:
	judge = 0
	s_l = []
	for j in (5,6,7):
		if n-i >= j:
			s1 = s[i:i+j]
			if s1 in t:
				i += j
				judge = 1
	
	if judge == 0:
		break

if i == n:
	print('YES')
else:
	print('NO')
S = str(input())
A = "dream"
B = "dreamer"
C = "erase"
D = "eraser"
while len(S) >= 5:
  if len(S) >= 7 and S[-7:] == B:
    S = S[:-7]
  elif len(S) >=6 and S[-6:] == D:
    S = S[:-6]
  elif S[-5:] == A or S[-5:] == C:
      S = S[:-5]
  else:
    break
if len(S) == 0:
  print("YES")
else:
  print("NO")
# C - 白昼夢
S = input()
S2 = S
W_L = ["dream","dreamer","erase","eraser"]
while True:
    cnt = 0
    for w in W_L:
        if S2.endswith(w):
            S2 = S2[:-(len(w))]
            cnt+=1
    if cnt ==0:
        print('NO')
        exit()
            
    if len(S2)<=7:
        break
    
if S2 ==''or S2 in W_L:
    print('YES')
else:
    print('NO')
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
            break

    if not flag:
        success = False
        break

if success:
    print("YES")
else:
    print("NO")
s = input()
n = len(s)
s=s[::-1]
while n:
    if s.startswith("maerd"):
        n -= 5
        s = s[5:]
    elif s.startswith("remaerd"):
        n -= 7
        s = s[7:]
    elif s.startswith("esare"):
        n -= 5
        s = s[5:]
    elif s.startswith("resare"):
        n -= 6
        s = s[6:]
    else:
        break
print("YES" if n == 0 else "NO")
S = input()[::-1]

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

res = 'YES'

while len(S):
    orig = S
    for w in cand:
        if S.startswith(w):
            S = S[len(w):]
    if orig == S:
        res = 'NO'
        break

print(res)
S = str(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:
    break

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

divide = True
while len(S) > 0:
    if S[-5:] in ["dream", "erase"]:
        S = S[:-5]
    elif S[-6:] == "eraser":
        S = S[:-6]
    elif S[-7:] == "dreamer":
        S = S[:-7]
    else:
        divide = False
        break
        
if divide:
    print("YES")
else:
    print("NO")
s = input()
s = s[::-1]
while len(s) > 0:
  if s[:5] == 'maerd':
    s = s[5:]
  elif s[:7] == 'remaerd':
    s = s[7:]
  elif s[:5] == 'esare':
    s = s[5:]
  elif s[:6] == 'resare':
    s = s[6:]
  else:
    print('NO')
    exit()
print('YES')
from collections import deque

def bfs(string):
    can = ["dream", "dreamer", "erase", "eraser"]
    queue = deque([])
    queue.append("dream")
    queue.append("dreamer")
    queue.append("erase")
    queue.append("eraser")
    while queue:
        judge = queue.popleft()
        if judge == string:break
        for temp in can:
            ans = judge + temp
            if ans == string[:len(ans)]:
                queue.append(ans)
    return "YES" if judge == string else "NO"

if __name__ == '__main__':
    s = input()
    print(bfs(s))
s = input()[::-1]
n = len(s)
words = ['maerd', 'remaerd', 'esare', 'resare']
while True:
    if s[:5] == words[0]:
        s = s[5:]
        continue
    elif s[:7] == words[1]:
        s = s[7:]
        continue
    elif s[:5] == words[2]:
        s = s[5:]
        continue
    elif s[:6] == words[3]:
        s = s[6:]
        continue
    break
print('NO' if s else 'YES')
S = input()[::-1]
W = ('dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1])

i = 0
while i < len(S):
    for w in W:
        if S[i:].startswith(w):
            i += len(w)
            break
    else:
        print('NO')
        exit()
print('YES')
import sys
s = input()
while True:
  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:
    print('NO')
    sys.exit()
  if s == '':
    print('YES')
    sys.exit()
S = input()
while len(S) > 0:
    if S[-5::1] == 'dream' or S[-5::1] == 'erase':
        S = S[:-5:1]
    elif S[-6::1] == 'eraser':
        S = S[:-6:1]
    elif S[-7::1] == 'dreamer':
        S = S[:-7:1]
    else:
        print('NO')
        break

if len(S) == 0:
    print('YES')
s = str(input())
no = 0
while 1:
    for data in ["erase", "eraser", "dream", "dreamer"]:
        if s.endswith(data):
            s = s[: - len(data)]
        else:
            no += 1
    if not s:
        print("YES")
        exit()
    if no == 4:
        print("NO")
        exit()
    else:
        no = 0
S = input()
buff = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
    buff[i] = buff[i][::-1]
S = S[::-1]
while len(S) > 0:
    if S[:7] == buff[1]:
        S = S[7:]
    elif S[:6] == buff[3]:
        S = S[6:]
    elif S[:5] == buff[0] or S[:5] == buff[2]:
        S = S[5:]
    else:
        break
if S: print('NO')
else: print('YES')
words=["eraser","erase","dreamer","dream"]
S=input()
for i in range(0,4):
    S=S.replace(words[i],"",len(S)//4)
if S=="":
    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("NO")
else:
    print("YES")