peterverebics/CodeNet_Python_118 huggingface dataset:
S = input()

idx = 0
while True:
    if S[idx:idx+5] == 'dream':
        idx += 5
    elif S[idx:idx+6] == 'eraser':
        idx += 6
    elif S[idx:idx+5] == 'erase':
        idx += 5
    elif S[idx:idx+7] == 'dreamer':
        idx += 7
    else:
        print('NO')
        break

    if idx == len(S):
        print('YES')
        break
s = input()
s=s[::-1]
A=["dream","dreamer","erase","eraser"]
for i in range(len(A)):
    A[i]=A[i][::-1]

i=0
while True:
    if len(s)==i:
        ans="Yes"
        break
    elif s[i:i+5]==A[0]:
        i+=5
    elif s[i:7]==A[1]:
        i+=7
    elif s[i:i+5]==A[2]:
        i+=5
    elif s[i:i+6]==A[3]:
        i+=6
    else:
        ans="No"
        break
print(ans)
words = ['maerd', 'remaerd', 'esare', 'resare']
S = input()
T = ''
for a in S[::-1]:
  T += a
  for s in words:
    if T == s:
      T = ''
if T == '':
    print('Yes')
else:
    print('No')
s = ''.join(list(reversed(input())))

s = s.replace('resaremaerd', '')
s = s.replace('remaerd', '').replace('resare', '')
s = s.replace('maerd', '').replace('esare', '')
if len(s) == 0:
    print('YES')
else:
    print('NO')
s=input()
n=len(s)
t=n-1
for i in range(n):
    if t>=4 and s[t-4:t+1]=="dream":
        t-=5
    elif t>=6 and s[t-6:t+1]=="dream":
        t-=7
    elif t>=4 and s[t-4:t+1]=="erase":
        t-=5
    elif t>=5 and s[t-5:t+1]=="eraser":
        t-=6
    if t<0:
        break
if t==-1:
    print("YES")
else:
    print("NO")
string = input()
 
flg = True
while len(string) > 0:
  if string.endswith('dream'):
    string = string[:-5]
  elif string.endswith('dreamer'):
    string = string[:-7]
  elif string.endswith('erase'):
    string = string[:-6]
  elif string.endswith('eraser'):
    string = string[:-6]
  else:
    print('NO')
    flg = False
    break
if flg:
  print('YES')
S = input()
T = ''

a = S.replace('eraser', '').replace('dreamer', '').replace('erase', '').replace('dream', '')

if len(a) == 0:
  print("YES")
else:
  print("NO")
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("NO")
  exit(0)
#print(i)
if i == len(S):
  print("YES")
else:
  print("NO")
def hantei(S):
  if S == 'dream' or S == 'dreamer' or S == 'erase' or S == 'eraser':
    return 1
  if S[:5] == 'dream':
    return hantei(S[5:]) | hantei(S[7:])
  if S[:7] == 'dreamer':
    return hantei(S[5:]) | hantei(S[7:])
  if S[:5] == 'erase':
    return hantei(S[5:]) | hantei(S[7:])
  if S[:7] == 'eraser':
    return hantei(S[5:]) | hantei(S[7:])
  else:
    return 0

S = input()
if(hantei(S)):
  print('YES')
else:
  print('NO')
S = input()
day_dream_word = ["eraser", "erase", "dreamer", "dream"]
for replace_word in day_dream_word:
  S.replace(replace_word, "")
if S == "":
  print('YES')
else:
  print('NO')
s = input()
s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
print("YES") if s == "" else print("NO")
s=input()
s=s[::-1]
#print(s[:5],s[:7])

for i in range(100000):
    if s[:5] == 'maerd' or s[:6] == 'esare':
        s = s[5:]
    if s[:6] == 'resare':
        s = s[6:]
    if s[:7] == 'remaerd':
        s = s[7:]

#print(s)
if len(s)==0:
    print('YES')
else:
    print('N0')
import itertools

input_moji = input()

count = 0

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

for i, _ in enumerate(lis, 1):     
    for j in itertools.permutations(lis, r=i):  # rには1、2、3と渡される
        total = "".join([str(_) for _ in j])
        if input_moji == total:
            count += 1
            print('Yes')

if count == 0:
    print('No')
s = input()
word = ['dreamer', 'dream', 'eraser', 'erase']
for i in word:
    s = s.replace(i,'')
if s:
    print('NO')
else:
    print('YES')
import re;
s = input();
print("Yes" if re.fullmatch(r'^(dream|dreamer|eraser|erase)*$', s) else "NO")
#9
S = input()
for i in range(0, len(S)//5+1):
    if S[0:5] == 'dream' or S[0:5] == 'erase':
        S = S[5:]
    elif S[0:6] == 'eraser':
        S = S[6:]
    elif S[0:7] == 'dreamer':
        S = S[7:]
print('YES' if len(S)==0 else 'NO')
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(t)
  print("YES" if obtainable(s) else "NO")

if __name__ ==  '__main__':
  main()
s = str(input())
l = len(s)
s = s[::-1]
i = 0
while i < l:
    if (s[i:min(l,i+7)] == "remaerd"):
        i += 7
    elif (s[i:min(l,i+6)] == "resare"):
        i += 6    
    elif (s[i:min(l,i+5)] == "maerd" or "esare"):
        i += 5   
    else:
        print('NO')
        break

else:
    print('YES')
s = input()

t = ''

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

if s == t:
    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+7]=='dreamer':
      cnt+=7
    elif s[cnt:cnt+5]=='dream':
      cnt+=5
    else:
      print('NO')
      exit()
    if cnt==len(s):
      print('YES')
      exit()

judge()
#import random
S = input()
#Mozi_f = ["eraser","erase","dreamer","dream"]
Mozi = ["resare","esare","remaerd","maerd"]
#S = random.choice(Mozi_f)
#S = "".join([random.choice(Mozi_f) for x in range(10)])
S = S[::-1]

for i in Mozi:
    S = S.replace(i,"")
if not S:
    print("Yes")
else:
    print("No")
def hantei(S):
  if S == 'dream' or S == 'dreamer' or S == 'erase' or S == 'eraser':
    return 1
  if S[:5] == 'dream' or S[:5] == 'erase':
    if S[:7] == 'dreamer' or S[:7] == 'eraser':
      return hantei(S[5:]) | hantei(S[7:])
    else:
      return hantei(S[5:])
  else:
    return 0

S = input()
if(hantei(S)):
  print('YES')
else:
  print('NO')
s = input()
s=s[::-1]
A=["dream","dreamer","erase","eraser"]
for i in range(len(A)):
    A[i]=A[i][::-1]

i=0
ans="Yes"
while True:
    if len(s)==i:
        break
    if s[i:i+5]==A[0]:
        i+=5
    elif s[i:i+7]==A[1]:
        i+=7
    elif s[i:i+5]==A[2]:
        i+=5
    elif s[i:i+6]==A[3]:
        i+=6
    else:
        ans="No"
        break
print(ans)
S = input()
L = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(L)):
    L[i] = L[i][::-1]
S = S[::-1]
T = ''
for s in S:
    T += s
    for i in L:
        if T == i:
            T = ''
if T == '':
    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" or 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
        
print(res)
S = input()
S = S.replace('eraser', '#', S.count('eraser'))
S = S.replace('dreamer', '#', S.count('dreamer'))
S = S.replace('erase', '#', S.count('erase'))
S = S.replace('dream', '#', S.count('dream'))
# print(S)
if len(S) == S.count('#'):
    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")
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
s = input()
r = 'YES'
while len(s):
    if s[:6] == 'dreamer' or s[:6] == 'eraser':
        s = s[6:]
    elif s[:5] == 'dream' or s[:5] == 'erase':
        s = s[5:]
    else:
        r = 'NO'
        break
print(r)
s = input()

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

while s:
  flg = True
  for w in a:
    if s.startswith(w):
      s = s.lstrip(w)
      flg = False
  if flg:
    break
      
      
if s == '':
  print('YES')
else:
  print('NO')
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']
T = set([s[::-1] for s in T])

A = ''
for s in S[::-1]:
    A += s
print('YES' if A == '' else 'NO')
S = input()[::-1]

S = S.replace("dream"[::-1], "")
S = S.replace("dreamer"[::-1], "")
S = S.replace("erase"[::-1], "")
S = S.replace("eraser"[::-1], "")

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

while 1:
    for x in ('dream', 'dreamer', 'erase', 'eraser'):
        if s.endswith(x):
            s = s[:-len(x)]
            break
    else:
        print('NO')
        break
    if not s:
        print('YES')
s = list(input())
s.reverse()
str = ""
for i in s:
    str+=i
str = str.replace("resare","")
str = str.replace("remaerd","")
str = str.replace("maerd","")
str = str.replace("esare","")
if str == "":
    print("YES")
else:
    print("NO")
# 動的計画法(DP)
s=input()
words = {"dream", "dreamer", "erase", "eraser"}

dp = dict()
for i in range(0, len(s)):
    if not dp.get(i):
        continue
    for word in words:
        if s[i:i+len(word)] == word:
            dp[i+len(word)] = 1

print("YES" if dp.get(len(s)) else "NO")
s = input()
lst = ["eraser","erase","dreamer","dream"]
for w in lst:
    s.replace(w,"")
    
if len(s) == 0:
    ans = "YES"
else:
    ans = "NO"

print(ans)
S = input()
list=['dream', 'dreamer', 'erase', 'eraser']

T = S.replace('eraser','')
U = T.replace('dreamer','')
V = U.replace('erase','')
W = V.replace('dream','')

if W =='':
    print('YES')
else:
    print("NO")
def main():
    print('YES' if not input().replace('eraser', '').replace(
        'dreamer', '').replace('dream', '').replace('erase', '') else 'NO')


if __name__ == "__main__":
    main()
s = input()
length = len(s)

i = 0
res = "YES"

       
print(res)
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()
s=s[::-1]
A=["dream","dreamer","erase","eraser"]
for i in range(len(A)):
    A[i]=A[i][::-1]

i=0
while True:
    if len(s)==i:
        print("Yes")
        break
    elif s[i:i+5]==A[0]:
        i+=5
    elif s[i:7]==A[1]:
        i+=7
    elif s[i:i+5]==A[2]:
        i+=5
    elif s[i:i+6]==A[3]:
        i+=6
    else:
        print("No")
        break
s = input().replace("erase","").replace("eraser","").replace("dreamer","").replace("dream","")
if s:
    print('NO')
else:
    print('YES')
s=input()
ans=0
ones=s.split("eraser")
for one in ones:
    twos=one.split("erase")
    for two in twos:
        three=two.split("dreamer")
        if set(three)==set(["dream"]) or set(three)==set(["dream",""]) or set(three)==set([""]):
            pass
        else:
            ans+=1
if ans==0:
    print("YES")
else:
    print("NO")
data = ['dream','dreamer','erase','eraser']
word = input()
for i in data:
  while i in word:
    word = word.strip(i)
if word =="":
  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')
#049_C
s = input()

s = s.replace('dream', '').replace('dreamer', '').replace('erase', '').replace('eraser', '')
print('YES' if s == '' else 'NO')
S = input()[::-1]
dividor = ['dream','dreamer','erase','eraser']
j=0
while True:
    flag = 0
    for d in dividor:
        print(S[j:j+len(d)])
        if S[j:j+len(d)]==d[::-1]:
            flag = 1
            j+=len(d)
            if j==len(S):
                print("YES")
                quit()
    if flag==0:
        print("NO")
        quit()
S = input()
S = S.replace("dreamer", "0").replace("eraser", "1").replace("dream", "2").replace("erase", "3")
try:
    int(S)
    print("YES")
except:
    print("NO")
s = input()
s = s.replace("eraser", "X")
s = s.replace("dreamer", "X")
s = s.replace("erase", "X")
s = s.replace("dream", "X")
 
count = s.count("X")
if len(s) == count:
    print("YES")
else:
    print("NO")
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]=="remeard":
        i+=7

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

if i != n+1:
    print("NO")
import re
moji=str(input())
if "eraser" in moji:
  moji=re.sub("eraser", "", moji)

if "dreamer" in moji:
  moji=re.sub("dreamer", "", moji)

if "dream" in moji:
  moji=re.sub("dream", "", moji)

if "erase" in moji:
  moji=re.sub("erase", "", moji)

print("YES" if moji=="" else "NO")
s = input()
u = ['dreamer', 'eraser', 'dream', 'erase']
while len(s) > 0:
    for i in u:
        if s[0:len(i)] == i:
            s = s.lstrip(i)
    else:
        print("NO")
        exit()
print("YES")
s = input()
s = s.replace('dreameraser', '').replace('dreamerse', '')
s = s.replace('dreamer', '').replace('eraser', '')
s = s.replace('dream', '').replace('erase', '')
if len(s) == 0:
    print('YES')
else:
    print('NO')
S = str(input())

while len(S) > 0:
  if S[-5:] == 'dream' or S[-5:] == 'erase':
    S = S[:-5]
  elif S[-7:] == 'dreamer' or S[-7:] == 'eraser':
    S = S[:-7]
  else:
    break

if len(S) == 0:
  print('YES')
else:
  print('NO')
word = input()
b = word
d = word
f = word
h = word
if 'eraser' in word:
  a = word.split('eraser')
  b = ''.join(a)
  h = b
if 'erase' in h:
  c = h.split('erase')
  d = ''.join(c)
  h = d
if 'dream' in h:
  e = h.split('dream')
  f = ''.join(e)
  h = f
if 'dreamer' in h:
  g = h.split('dreamer')
  h = ''.join(g)
if h == (''):
  print('YES')
else:
  print('NO')
import re
s = input()
re.sub('eraser','0',s)
re.sub('erase','0',s)
re.sub('dreamer','0',s)
re.sub('dream','0',s)


print('YES' if set(s) == set('0') else 'NO')
s=input()

s=s.replace("eraser","")
s=s.replace("dreamer","")
s=s.replace("dream","")
s=s.replace("erase","")
if s=="":
    print("YES")
else:
    print("NO")
import re
moji=str(input())
temp=""
for i in range(-1,-(len(moji))-1 , -1):
  temp+=moji[i]
if "resare" in temp:
  temp=re.sub("resare", "", temp)
if "remaerd" in temp:
  temp=re.sub("remaerd", "", temp)
if "maerd" in temp:
  temp=re.sub("maerd", "", temp)
if "esare" in temp:
  temp=re.sub("esare", "", temp)

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

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

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

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

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

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


if flag:
    print('YES')
else:
    print('NO')
def we_can(s):
    if len(s) == 0:
        return True
    else:
        if s[-5:] == 'dream' or s[-5:] == 'erase':
            if we_can(s[:-5]):
                return True
        elif s[-6:] == 'dreamer' or s[-6:] == 'eraser':
            if we_can(s[:-6]):
                return True
    return False


s = input()
if we_can(s):
    print('YES')
else:
    print('NO')
import re
print("Yes" if re.match("^(dream|dreamer|erase|eraser)+$",input()) else "No")
from collections import deque

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

while q:
  try:
    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()
     
  except:
    print('NO')
    exit()
    
print('YES')
s = input()[::-1]

l5 = ["dream"[::-1], "erase"[::-1]]
l6 = ["dreamer"[::-1], "eraser"[::-1]]

ans = "YES"

while len(s) > 4:
    if s[:5] in l5:
        s = s[5:]
    elif s[:6] in l6:
        s = s[6:]
    else:
        ans = "NO"
        break

print(ans)
c = input()

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

tmpstr = ""

endflag = False

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

if (endflag):
  print("NO")
else:
  print("YES")
s = input()
ans = "YES"
while s != "":
    if len(s) < 5:
        ans = "NO"
        break
    elif s[len(s) - 5:] == "dream" or s[len(s) - 5:] == "erase":
        s = s[:len(s) - 5]
    elif s[len(s) - 6:] == "eraser":
        s = s[:len(s) - 6]
    elif s[len(s) - 7] == "dreamer":
        s = s[:len(s) - 7]
    else:
        ans = "NO"
        break
print(ans)
s = input()
s = s.replace("eraser","")
s = s.replace("erase","")
s = s.replace("dreamerr","")
s = s.replace("dream","")
if len(s)==0:
    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()

while True:
    if S[-3:] == "mer": 
        S = S[:-7]
    elif S[-3:] == "ser": 
        S = S[:-6]
    elif S[-3:] == "eam": 
        S = S[:-5]
    elif S[-3:] == "ase": 
        S = S[:-5]
    else:
        break
print("NO") if S else print("YES")
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()
Mozi = ["dreamer","eraser","dream","erase"]

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

if not S:
    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

print(S)
if len(S) == 0:
    print('YES')
else:
    print('NO')
words = {"eraser" , "erase" , "dreamer" , "dream"}
s = input()
n = len(s)
now=""
for i in range(0 ,n):
	now = now+s[i]
	if now in words:
		now=""
if now in words or now =="":
	print("YES")
else:
	print("NO")
S = input()
db = ["dream", "erase"]
offset = 0
key = True
while key:
  if offset >= len(S): key = False
  if S[offset:offset+5] == db[0]:
    if S[offset:offset+2] == db[0]+"er": offset += 7
    else: offset += 5
  elif S[offset:offset+5] == db[1]:
    if S[offset:offset+6] == db[1]+"r": offset += 6
    else: offset += 5
  else: break
print("YNEOS"[key::2])
s = input()
s = s.replace('eraser', '').replace('dreamer', '')
s = s.replace('dream', '').replace('erase', '')
print('YES' if len(s) == 0 else 'NO')
l = input()
l = l.replace('eraser','')
l = l.replace('erase','')
l = l.replace('dream','')
l = l.replace('dreamer','')

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

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

solve(S)
import sys
s = input()
A = ['dream','dreamer','erase', 'eraser']
while(len(s)!=0):
    cs = s
    for i in range(len(A)):
        if (s.startswith(str(A[i]))):
            #print(A[len(A[i])+1:])
            s = s[len(A[i]):]
    if (cs == s):
        print('NO')
        sys.exit()
print('YES')
S=input()[::-1]
num=(len(S)//5)+1
while num > 0:
  for i in ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]:
    if S[:len(i)] == i:
      S = S[len(i):]
    if S == '':
      print('YES')
      exit()
  num -= 1
print('No')
import re
s = input()
if re.fullmatch(r"(dream|dreamer|erase|eraser)+",s):
  print("Yes")
else:
  print("No")
S = input()
while len(S)>0:
    if S[-7:] == "deamer":
        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:
        break
print("YES" if len(S)==0 else "NO")
s = input()

while(len(s)!=0):
    if s[-5:] == 'dream' or s[-5:] == 'erase':
        s = s[:-5]
    elif s[-6:]== 'eraser':
        s = s[:-6]
    elif s[-7:0]=='dreamer':
        s = s[:-7]
    else:
        print('N0')
        break
print('YES')
s=input()[::-1]
words = {"dream", "dreamer", "erase", "eraser"}

while len(s)!=0:
    for i in words:
        l = len(i)
        print(s[0:l], i[::-1])
        if s[0:l] == i[::-1]:
            s = s[l::]
            break
    else:
        break

print("NO"if len(s)!=0else "YES")
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()
s = s.replace("eraser", "X")
s = s.replace("dreamer", "X")
s = s.replace("erase", "X")
s = s.replace("dream", "X")

count = s.count("X")
if len(s) == count:
    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()

slen = len(s)
now=0

while(1):
    if s[now:now+5] == "erase":
        now += 5
    elif s[now:now+6] == "eraser":
        now += 6
    elif s[now:now+5] == "dream":
        now += 5
    if s[now:now+6] == "dreamer":
        now += 7
    else:
        print('NO')
        break
    if now == slen:
        print('YES')
        break
s = input()[::-1]
res = "Yes"
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):
    res = "No"
    break
print(res)
def solve():

    S = input()

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

    while(True):
        if(len(S) == 0):
            break
        flag = False
        for w in words:
            if(S.endswith(w)):
                S = S[0:len(S) - len(w)]
                flag = True
        
        if(not flag):
            return
            
        
    print('YES')
    
solve()
#9
S = input()
while len(S)!=0:
    if S[0:5] == 'dream' or S[0:5] == 'erase':
        S = S[5:]
    elif S[0:6] == 'eraser':
        S = S[6:]
    elif S[0:7] == 'dreamer':
        S = S[7:]

print('Yes' if len(S)==0 else 'No')
S=input()
reversed(S)

T = S.replace('remaerd','')
U = T.replace('resare','')
V = U.replace('maerd','')
W = V.replace('esare','')

if W =='':
    print('YES')
else:
    print("NO")
s = input()

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

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


count = 0

while(count < len(c)):
  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")
from itertools import permutations

s = input()

words = ["dream", "dreamer", "erase", "eraser"]
words_combinations = ["".join(j) for i in range(1, len(words)+1) for j in permutations(words, i)]

if s in words_combinations:
    print("YES")
else:
    print("NO")
S = input()

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