peterverebics/CodeNet_Python_118 huggingface dataset:
import sys
import resource
sys.setrecursionlimit(10 ** 9)

S = input()
l = []
def dfs(n):
  print(n)
  if n == len(S):
    l.append("Yes")
  if n < len(S):
    if S[n:n+5] == "erase":
      dfs(n+5)    
    if S[n:n+5] == "dream":
      dfs(n+5)  
    if S[n:n+6] == "eraser":
      dfs(n+6)              
    if S[n:n+7] == "dreamer":
      dfs(n+7)
dfs(0)
if len(l) == 0:
  l.append("No")
print(l[0])
S = input()
S = S[::-1].replace("resare", "0").replace("remaerd", "0").replace("esare", "0").replace("maerd", "0")

try:
    int(S)
    print("YES")
except:
    print("NO")
import sys
from collections import deque
s = input()

queue = deque()
queue.append(0)
candidates = ['dream', 'dreamer', 'erase', 'eraser']

while queue:
    index = queue.popleft()
    match = False
    for candidate in candidates:
        if s[index:index + len(candidate)] == candidate:
            match = True
            if index + len(candidate) == len(s):
                print('YES')
                sys.exit(0)
            queue.append(index + len(candidate))
    if not match:
        print('NO')
        sys.exit(0)
s = input()

s = s[::-1]
lis = ['dream', 'dreamer', 'erase', 'eraser']
nlis = []
for i in lis:
    nlis.append(i[::-1])

flag = 0
ans = ''
for _ in range(10):
    for j in nlis:
        if s.startswith(j):
            s = s.replace(j, '')
            
    
    if ans == s:
        flag = 1
        break



if flag:
    print('YES')
else:
    print('NO')
#9
S = input()
for i in range(0, len(S)//5+1):
    if S[-5:-1] == 'dream' or S[-5:-1] == 'erase':
        S = S[:-6]
    elif S[-6:-1] == 'eraser':
        S = S[:-7]
    elif S[-7:-1] == 'dreamer':
        S = S[:-8]
    else:
        break
print('YES' if len(S)==0 else 'NO')
S = input()

if S.replace("dream"," ").replace("dreamer"," ").replace("erase"," ").replace("eraser"," "):
  print("NO")
else:
  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:]
    elif s[-7:]=='dreamer':
        s=s[-7:]
    else:
        print('NO')
        exit()
print('YES' if s=='erase' or s=='dreamer' or s=='dream' or s=='eraser' or s=='' else 'NO')
S = input()
while True :
  if S[0:7] == "dreamer":
    S = S.strip("dreamer")
  elif S[0:6] == "eraser":
    S = S.strip("eraser")
  elif S[0:5] == "dream":
    S = S.strip("dream")
  elif S[0:5] == "erase":
    S = S.strip("erase")
  elif len(S) == 0:
    print("YES")
    break
  else:
    print("NO")
    break
words = {"eraser" , "erase" , "dreamer" , "dream",""}
s = input()
n = len(s)
now=""
f=0
for i in range(0 ,n):
	now = now+s[i]
	if now =="dreamer":
		now = ""
	elif now =="eraser":
		now = ""
if now in words:
	print("YES")
else:
	print("NO")
s=input()

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

judge()
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

s=input().rstrip("\n")
e=len(s)
l=["dream","dreamer","erase","eraser"]
for i in range(len(s))[::-1]:
    #print(s[i:e])
    if s[i:e] in l:
        e-=i   
        continue
    if len(s[i:e])>7:
        print("NO")
        sys.exit()
print("YES")
S=input()

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

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

for i in list:
    s = s.replace(i, "")

if s == "":
    print("YES")
else:
    print("NO")
s = "".join(list(reversed(input())))
t_t = ["maerd", "remared", "esare", "resare"]

for _ in range(len(s)):
    for q in t_t:
        if q == s[:len(q)]:
            s = s[len(q):]

print("NO" if len(s) else "YES")
S=input()
str_list=["dreamer","eraser","dream","erase"]
     
S_tmp=""
while True:
  S_tmp=S
  for str in str_list:
    if S[-len(str):]==str:
      S=S.rstrip(str)
        
  if S_tmp==S:
    break    
        
if S=="":
  print("YES")
if S!="":
  print("NO")
c = input().rstrip('\n')

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


count = 0

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

print("YES")
s=input()
while True:
    if len(s) == 0:
        print("Yes")
        break
    elif 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")
        break
S = input()

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

if len(S) == 0:
  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 = input()
s = 'erasedream'
while True:
    # print(s)
    if s == '':
        print('YES')
        break
    if s.endswith('eraser'):
        s = s.replace('eraser', '')
    elif s.endswith('dreamer'):
        s = s.replace('dreamer', '')
    elif s.endswith('dream'):
        s = s.replace('dream', '')
    elif s.endswith('erase'):
        s = s.replace('erase', '')
    else:
        print('NO')
        break
s=input()+'#'
n=len(s)
i=0
while i<n:
  if s[i]=='#':
    i=n
  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
  else:
    print('NO')
    exit()
print('YES')
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):]
            print(t)
            trigger+=1
            break
    trigger-=1
if t=='':
    print('YES')
else:
    print('NO')
s = input()
for word in ["eraser","erase","dreamer","dream"]:
    s = s.replace(word,".")
    if len(set(s)) == 1:
        print("YES")
    else:
        print("NO")
S = input()
S = S.replace('dream'[::-1], '').replace('dreamer'[::-1], '').replace(
    'eraser'[::-1], '').replace('erase'[::-1], '')

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

lst = ['dream', 'dreamer', 'erase', 'eraser']
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')
s=input()
s=s[::-1]
divide=["dream", "dreamer", "erase", "eraser"]
c1=1
c2=0
for i in range(4):
    divide[i]==divide[i][::-1]
for i in range(len(s)):
    c2=0
    for j in range(4):
        d=divide[j]
        if s[i:i+len(d)]==d:
            c2=1
            i+=len(d)

    if c2==0:
        c1=0
        break

if c1==1:
    print("YES")
else:
    print("NO")
S=input()
flag=False
while True:
    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()

s = s[::-1] #文字の反転

t = 0;

while t ==0:
    a = s.find("maerd")
    b = s.find("remaerd")
    c = s.find("esare")
    d = s.find("resare")

    if a == 0 or c== 0:
        s = s[5:]
        continue
    if b == 0:
        s = s[7:]
        continue
    if d == 0:
        s = s[6:]
        continue
    t=1


if s == "":
    print("Yes")
else:
    print("No")
s = list(input())
index = 0
while index < len(s):
    if "".join(s[index:index+7]) == "dreamer":
        index += 7
    elif "".join(s[index:index+6]) == "eraser":
        index += 6
    elif "".join(s[index:index+5]) == "erase" or "".join(s[index:index+5]) == "dream":
        index += 5
    else:
        print("NO")
        exit()
print("YES")
S=input()
i=0
ans="YES"
while i<len(S):
    if len(S)-i<5:
        ans="NO"
        break
    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
    else:
        ans="NO"
        break
if i<len(S)-1:
    ans="NO"
print(ans)
t=input()
trigger=1
key=''
d=-1
app=['dreamer','eraser','dream','erase']
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
            d=i
            break
    trigger-=1
    if trigger==0 and d==0 and t[:3]=='ase':
        t='er'+t
        trigger+=1
if t=='':
    print('YES')
else:
    print('NO')
    print(t)
word = input()

list = ['dream','dreamer','erase','eraser']
count = 0
for i in list:
    a = i
    if a in word:
        word = word.replace(a, '')
        # print(word)
        
        
if word == "":
    print("YES")
    
else :
    print("NO")
q = ['dream','dreamer','erase','eraser']
s = input()

while True:
  if len(s) <= 7:
    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')
words = [w[::-1] for w in ['dream','dreamer', 'erase', 'eraser']]
s = raw_input()[::-1]
i = 0
while(i < len(s)):
	for w in words:
		if w == s[:len(w)]:
			i += len(w)
			break



print 'YES' if i == len(s) else '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')
S = input()
S = ''.join(list(reversed([c for c in S])))

while S:
    if S[:7] == 'remaerd':
        S = S[7:]
    elif S[:6] == 'resare':
        S = S[6:]
    elif S[:5] == 'maerd':
        S = S[5:]
    elif S[:5] == 'esare':
        S = S[5:]
    else:
        print('No')
        exit()

print('Yes')
S = str("dreamerase")

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()
def solve(query):
    while 1:
        if not query:
            print("Yes")
            break

        for frag in ("erase","eraser","dream","dreamer"):
            if query.endswith(frag):
                query=query[:-len(frag)]
                break
        else:
            print("No")
            break

solve(S)
S = input()
while S != '':
    if S[-5:] == 'dream':
        S = S[:-5]
    elif S[-5:] == 'erase':
        S = S[:-5]
    elif S[-6:] == 'dreamer':
        S = S[:-6]
    elif S[-6:] == 'eraser':
        S = S[:-6]
    else:
        print('NO')
        exit()
print('YES')
div = ['maerd', 'remaerd', 'esare', 'resare']
s = input()
rs = ''.join(list(reversed(s)))

can1 = True
cnt = 0
for i in range(len(s)):
    if cnt != 0:
        cnt -= 1
        continue
    can2 = False 
    for d in range(len(div)):
        if (rs.find(div[d])) == i:
            can2 = True
            cnt = len(div[d]) -1
    if can2 == False:
        can1 = False

if can1:
    print('YES')
else:
    print('NO')
import itertools

input_moji = input()

count = 0

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

origin_list = ['dream','dreamer', 'erase','eraser']
for i in itertools.product(origin_list, repeat=2):
    total = "".join([str(_) for _ in i])
    if input_moji == total:
        count += 1
        print('Yes')

if count == 0:
    print('No')
import re

def solve(s):
    return 'YES' if re.match('^((dream|erase)r?)*$', s) else 'NO'

_s = input()
print(solve(_s))
S=input()
T=["dream","dreamer","erase","eraser"]
S=S.replace(T[3],"").replace(T[2],"").replace(T[1],"").replace(T[0],"")
if S=="":
    print("Yes")
else:
    print("No")
S = input()
while True:
    if S[-6:] == "eraser" or S[-6:] == "dreamer":
        S = S[:-6]
        if len(S) == 0:
            print("YES")
            exit(0)
    elif S[-5:] == "dream" or S[-5:] == "erase":
        S = S[:-5]
        if len(S) == 0:
            print("YES")
            exit(0)
    else:
        print("NO")
        exit(0)
S=input()
str_list=["dreamer","dream","eraser","erase"]

S_tmp=""
while True:
  S_tmp=S
  for str in str_list:
    
    S=S.replace(str,"",1)
  
  if S_tmp==S:
    break

if S=="":
  print("YES")
if S!="":
  print("NO")
s=input()
t=['dream','dreamer','erase','eraser']
t=sorted(t,reverse=True)
a=0
for i in range(4):
  for j in range(4):
    if t[i]+t[j]==s: 
      a+=1
print("YES"if a>0 else "NO")
# -*- coding: utf-8 -*-

I = "dream dreamer erase eraser".split()
I2 = input()

if I2.replace(I[1], "").replace(I[0], "").replace(I[3], "").replace(I[2], "").strip() == "":
  print("YES")
else:
  print("NO")
s = input()

import re
output ="NO"
s = re.sub('dreameraser', '', 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()

# 前から順に消すと詰む
# 後ろから順に消すと一意に定まる
while True:
  if S[-5:] == 'erase': S = S[:-5]
  else:
    if S[-6:] == 'eraser': S = S[:-6]
    else:
      if S[-5:] == 'dream': S = S[:-5]
      else:
        if S[-7:] == 'dreamer': S = S[:-7]
        else: break

if len(S) == 0: print('Yes')
else: print('No')
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
t1 = (l[1],l[3])
t2 = (l[0],l[2])

while i < n:
	judge = 0
	if s[i] == 'r' and n-i >= 6:
		s1 = s[i:i+6]
		if s1 in t1:
			i += 6
			judge = 1
	elif n-i >= 4:
		s1 = s[i:i+5]
		if s1 in t2:
			i += 5
			judge = 1
	
	if judge == 0:
		break

if i == n:
	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(RT):
    can2 = False
    for j in range(4):
        sizeT = len(RT[j])
        if RT[j] == RS[i:sizeT]:
            i += sizeT
            can2 = True
            break

    if not can2:
        can = False
        break

if can:
    print('YES')
else:
    print('NO')
S = input()
S = S.replace('dream', '').replace('dreamer', '').replace(
    'eraser', '').replace('erase', '')

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

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

words = [i[::-1] for i in kari]

l = len(S)
i = 0

while True:
    if S[i:i+5]==words[0] or S[i:i+5]==words[2]:
        i += 5
    elif S[i:i+6]==words[3]:
        i += 6
    elif S[i-7:i+7]==words[1]:
        i += 7
    else:
        print('NO')
        exit()
    if i == l:
        print('YES')
        exit()
s=input()
s=s.replace('dream', '')
s=s.replace('dreamer', '')
s=s.replace('erase', '')
s=s.replace('eraser', '')

if s=="":
    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)

if len(s) == 0:
  print("Yes")
else:
  print("No")
s=input().replace('eraser',"").replace('eraser',"").replace('erase',"").replace('dreamer',"").replace('dream',"")
if s:
    print("No")
else:
    print("Yes")
word = input()
def gyaku(x):
  x = list(x)
  x.reverse()
  return ''.join(x)

a = ''.join(gyaku(word).split(gyaku('eraser')))
b = ''.join(a.split(gyaku('dreamer')))
c = ''.join(b.split(gyaku('dream')))
d = ''.join(c.split(gyaku('erase')))

if d == '':
  print('YES')
else:
  print('NO')
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()
s=s[::-1]
divide=["dream", "dreamer", "erase", "eraser"]
c1=1
c2=0
for i in range(4):
    divide[i]=divide[i][::-1]
for i in range(len(s)):
    for j in range(4):
        d=divide[j]
        if s[i:i+len(d)]==d:
            c2=1
            i+=len(d)

    if c2==0:
        c1=0
        break

if c1==1:
    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()

sc = ["dreameracer", "dreamerace", "dreamer", "dream", "eracer", "erace"]
for i in sc:
    s = s.replace(i, '')

if len(s) == 0:
    print("YES")
else:
    print("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

print("YES")
s=input()
L=len(s)
newstring=''.join(list(reversed(s)))

while L>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")
s = input()[::-1]
d = {'maerd', 'remaerd', 'esare', 'resare'}

cnt = 0
while cnt + 5 < len(s):
    if s[cnt:cnt + 5] in d:
        cnt = cnt + 5
    elif cnt + 6 < len(s) and s[cnt:cnt + 6] in d:
        cnt = cnt + 6
    elif cnt + 7 < len(s) and s[cnt:cnt + 7] in d:
        cnt = cnt + 7
    else:
        print('NO')
        break
else:
    print('YES')
s = input()
erase = s.count("erase")
eraser = s.count("eraser")
erase -= eraser
dream = s.count("dream")
dreamer = s.count("dreamer")
dream -= dreamer
if (eraser * 6 + erase * 5 + dream * 5 + dreamer * 6) >= len(s):
    print("YES")
else:
    print("NO")
l = input()
l = l.replace('eraser','')
l = l.replace('erase','')
l = l.replace('dreamer','')
l = l.replace('dream','')

if l == '':
    print('Yes')
else:
    print('No')
s = input()

dic = ['dreameraser', 'dreamerrase', 'dreamer', 'dream', 'eraser', 'erase']

def check():
    i = 0
    while i < len(s):
        found = False
        for k in dic:
            if s[i:i+len(k)] == k:
                found = True
                break
        if not found:
            return False
        i += len(k)
    return True


print('YES' if check() else 'NO')
words = ['dream','dreamer', 'eraser', 'erase']

s = input()

while True:
  chg_flg = False
  for w in words:
    if s.startswith(w):
      s = s[len(w):]
      chg_flg = True
  if not chg_flg:
    break

if len(s) == 0:
  print("YES")
else:
  print("NO")
# -*- coding:utf-8 -*-
from collections import deque

divide = ["dream", "dreamer", "erase", "eraser"];

s = input()
que = deque()

can = "NO"

que.append(0)

while(len(que) > 0):
  t = que[0]
  que.pop()
  if (t == len(s)):
    can = "YES"
    break
  for e in divide:
    if s[t:t+len(e)] == e:
      que.append(t+len(e))
print(can)
s=input()

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

if s=='':
  print('YES')

else:
  print('NO')
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, "")
  
  if (c == tmpstr):
    endflag = True
    break

if (c == ""):
  print("YES")
else:
  print("NO")
S = input()
C = ["maerd","remaerd","esare","resare"]
ans = ""
a = "YES"
x = len(S)
for i in range(x):
    ans = ans + S[x - 1 -i]
    if ans == C[0]:
        ans = ""
    elif ans == C[1]:
        ans = ""
    elif ans == C[2]:
        ans = ""
    elif ans == C[3]:
        ans = ""
if len(ans) != 0:
    a = "No"
print(a)
rev_s = ''.join(list(reversed(input())))
rev_w = ['maerd', 'remaerd', 'esare', 'resare']

while rev_s != '':
    for item1 in rev_w:
        if rev_s.find(item1) == 0:
            rev_s = rev_s[len(item1):]
            break
    if item1 == rev_w[-1]:
        break

if rev_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 S=='':
    print('Yes')
else:
    print('No')
s=input()
s=s.replace('dreamer','')
s=s.replace('eraser','')
s=s.replace('dream','')
s=s.replace('erase','')
if s=='':
  print('Yes')
else:
  print('No')
s = input()
# 文字の反転
s_rev = s[::-1]
T_list = ['maerd', 'remaerd', 'esare', 'resare']

def mojicut(s, r):
    n = s.replace(r, "", 1)
    return n

while len(s_rev) > 0:
    s_len = len(s_rev)
    for i in T_list:
        if s_rev.startswith(i):
            s_rev = mojicut(s_rev, i)
            break
    if len(s_rev) == s_len:
        break

if len(s_rev) > 0:
    print("No")
else:
    print("Yes")
S0 = input()
S = S0[::-1]
cands = ["dream"[::-1],"dreamer"[::-1],"erase"[::-1],"eraser"[::-1]]
i = 0
while i < len(S):
  for word in cands:
    #print(S[i:],word)
    if S[i:].startswith(word):
    	i += len(word)
    	continue
#print(i)
if i == len(S):
  print("True")
else:
  print("False")
S = input()
Mozi = ["resare","esare","remaerd","maerd"]

S = S[::-1]
for i in Mozi:
    S = S.replace(i,"")
if not S:
    print("Yes")
else:
    print("No")
words=["eraser","erase","dreamer","dream"]
S=input()
for i in range(4):
    S=S.strip(words[i])
if S=="":
    print("Yes")
else:
    print("No")
s = input().replace('eraser', '').replace('erase', '') \
    .replace('dreamer', '').replace('dream', '')
if s:
    print('NO')
else:
    print('YES')
print(s)
s=input()
# dream dreamer erase eraser 
while len(s)>0:
	if (s[-1]=="r") & (s[-7]=="dreamer"):
		s.rstrip("dreamer")
	elif (s[-1]=="r") & (s[-6]=="eraser"):
		s.rstrip("eraser")
	elif (s[-1]=="e") & (s[-5]=="erase"):
		s.rstrip("erase")
	elif (s[-1]=="m") & (s[-5]=="dream"):
		s.rstrip("dream")
	else:
		break
		
if len(s)>0:
	print("YES")
else:
	print("NO")
S = input()
Mozi = ["dreamer","eraser","dream","erase"]

if S not in "X":
    for i in Mozi:
        T = S.replace(i,"X")
        S = T.strip("X")

    if not S:
        print("Yes")
    else:
        print("No")
else:
    print("No")
S = input()
 
# 前から順に消すと詰む
# 後ろから順に消すと一意に定まる
while len(S) > 0:
  if S[-5:] == 'erase': S = S[:-5]
  else:
    if S[-6:] == 'eraser': S = S[:-6]
    else:
      if S[-5:] == 'dream': S = S[:-5]
      else:
        if S[-7:] == 'dreamer': S = S[:-7]
        else: break

if len(S) == 0: print('Yes')
else: print('No')
s = str(input())
t = s.replace('eraser', '').replace('dreamer', '').replace('erase', '').replace('dream', '')
if t == '':
    print('YES')
else:
    print('NO')
import re
print('YES' if re.match('^(dream|dremaer|erase|eraser)+$', input()) else 'NO')
word = input()

list = ['dream','dreamer','erase','eraser']
count = 0
for i in list:
    a = i
    if a in word:
        word = word.replace(a, '')
        # print(word)
        count += 1
        
if count >= 2:
    print("YES")
    
else :
    print("NO")
word = input()
x = word.replace('eraser', '').replace('dreamer', '').replace('dream', '').replace('erase', '')
if x == '':
  print('YES')
else:
  print('NO')