peterverebics/CodeNet_Python_118 huggingface dataset:
s = input()
while 1:
    flag = False
    if s[-5:] in ['dream', 'erase']:
        s = s[:-5]
        flag = True
    elif s[-6:] == 'eraser':
        s = s[:-6]
        flag = True
    elif s[-7:] == 'dreamer':
        s = s[:-7]
        flag = True
    if not flag:
        break
if not s:
    print('YES')
else:
    print('NO')
s = input()[::-1]

now = 0
while now < len(s):
    if s[now:now + 7] == 'dreamer'[::-1]:
        now += 7
    elif s[now:now + 6] == 'eraser'[::-1]:
        now += 6
    elif s[now:now + 5] == 'dream'[::-1]:
        now += 5
    elif s[now:now + 5] == 'erase'[::-1]:
        now += 5
    else:
        print('NO')
        exit()

print('YES')
import sys 
sys.setrecursionlimit(10**6)
s = input()
def dfs(s):
    while True:
        f = True
        for i in ['erase', 'eraser', 'dream', 'dreamer']:
            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()[::-1]
words = {"dream", "dreamer", "erase", "eraser"}

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

print("NO"if len(s)!=0else "YES")
def resolve():
	s = input()
	w = ['dream', 'dreamer', 'erase', 'eraser']
	h = dict()
	for i in range(len(w)):
		h[w[i][::-1]] = True
	s = s[::-1]
	c = ''
	for i in s:
		c += i
		if h.get(c):
			c = ''
	if not len(c):
		print('YES')
	else:
		print('NO')
resolve()
s = input()[::-1]
ls = ['dream', 'dreamer', 'erase', 'eraser']
ls = [ls[i][::-1] for i in range(4)]
ans = 'YES'
i = 0
while i < len(s):
    ng = 1
    for j in range(4):
        if s[i:i+len(ls[j])] == ls[j]:
            i += len(ls[j])
            ng = 0
    if ng:
        ans = 'NO'
        break
print(ans)
import sys
cin = lambda: sys.stdin.readline().strip()
cout = sys.stdout.write

s = cin()

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

if(s == ''):
	cout(f"YES"+'\n')
else:
	cout(f"NO"+'\n')
S = input()
SFlag = True
while S:
    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:
        SFlag = False
        break
print(['NO','YES'][SFlag])
s = input()
n = 0
while n == 0:
  if s[len(s)-5:len(s)] == "dream":
    s = s[:len(s)-5]
  elif s[len(s)-5:len(s)] == "erase":
    s = s[:len(s)-5]
  elif s[len(s)-7:len(s)] == "dreamer":
    s = s[:len(s)-7]
  elif s[len(s)-6:len(s)] == "eraser":
    s = s[:len(s)-6]
  else:
    if len(s) == 0:
      n = 1
      print("YES")
    else:
      n = -1
      print("NO")
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()
t = len(S)
words = ['dream', 'dreamer', 'erase', 'eraser']
while True:
  flg = True
  for i in range(t, -1, -1):
    if S[i:t] in words:
      t = i 
      flg = False
  if flg:
    print('NO')
    break
  if t == 0:
    print('YES')
    break
S = input()
words = ("dream", "dreamer", "erase", "eraser")

for _ in range((len(S) + 4) // 5):
    for word in words:
        if S.endswith(word):
            S = S[: -len(word)]
print("NO") if S else print("YES")
st = input()
S = st[::-1]
words ={"remaerd","resare","maerd","esare"}

lenT = 0
flag = 0
ans = "NO"

while flag < 5:
  for i in range(5, 8):
    if S[0:i] in words:
      S = S[i:]
      flag = 0
      
    elif S == "":
      flag = 5
      ans = "YES"
      break
    else:
      flag += 1
    
print(ans)
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')
S=input()
word=["dream", "dreamer", "erase", "eraser"]
dp=[0]*(len(S)+1)
dp[0]=1
done="NO"

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

print(done)
import re
S = input()
if re.match("^(dream|dreamer|erase|eraser)+$", S):
    print('YES')
else:
    print('NO')
S = input()[::-1]
text = ['dream','dreamer','erase','eraser']
text = [t[::-1] for t in text]

while len(S) > 0:
  for t in text:
    if S.find(t) == 0:
      S = S[len(t):]
      break
  else:
    print('NO')
    break
else:
  print('YES')
import re
N = str(input())

words = re.findall("^(dream|dreamer|erase|eraser)+$", N)
print('NO') if words == [] else print('YES')
s = input()[::-1]

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

ans = "YES"

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

print(ans)
s=input().strip()
s=s.replace("eraser","")
s=s.replace("erase","")
s=s.replace("dreamer","")
s=s.replace("dream","")
print("YES" if not s else "NO")
S = input()

# 後ろから削除したいので、反転して前から削除する
S = S[::-1] 
words = {'maerd', 'remaerd', 'esare', 'resare'}

while len(S) > 0:
  orig = S
  for w in words:
    if S.startswith(w):
      S = S[len(w):]
      break
  if orig == S:
    break

if len(S) == 0: print('YES')
else: print('NO')
s = str(input())
s = s[-1::-1]

while True :
    if len(s) == 0:
        print('YES')
        break
    elif s[0:5] == 'esare':
        s = s[5:]
    elif s[0:6] == 'resare':
        s = s[6:]
    elif s[0:5] == 'maerd':
        s = s[5:]
    elif s[0:7] == 'remaerd' :
        s = s[7:]
    else :
        print('NO')
        break
def main():
    s = input()
    ref = ['eraser','erase','dreamer','dream']
    for i in range(4):
        s = s.replace(ref[i], '')
    if not s:
        print("YES")
    else:
        print("NO")
main()
s = input()

tmp = ""
cnt = 0
for c in reversed(s):
  tmp = c + tmp
  if tmp in ["dream", "dreamer", "erase", "eraser"]:
    cnt += len(tmp)
    tmp = ""
    
if cnt == len(s):
  print("YES")
else:
  print("NO")
s = input()[::-1]

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

if s == "":
  print("YES")
else:
  print("NO")
#049_C
s = input()[::-1]
k = ['maerd', 'remaerd', 'esare', 'resare']

tmp = 0
flg = True
while tmp < len(s):
    check = False
    for x in k:
        if s[tmp: tmp + len(x)] == x:
            check = True
            tmp += len(x)
    if check == False:
        flg = False
        break
        
print('YES' if flg else '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.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)
import sys

s = input()
data = {"dream","dreamer","erase","eraser"}

while True:
    for i in data:
        if s.endswith(i):
            s = s[:-len(i)]
            break
    else:break

if s == "":
    print("YES")
    sys.exit()
else:
    print("NO")
    sys.exit()
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)
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[:-5]
  elif string.endswith('eraser'):
    string = string[:-6]
  else:
    print('NO')
    flg = False
    break
if flg:
  print('YES')
S=input()

dp=[False]* (len(S)+1)

dp[0] = True

for i in range(1, len(dp)):
  for w in [ 'dream', 'dreamer', 'erase', 'eraser']:
    if dp[i-len(w)] and w == S[i-len(w):i]:
      dp[i] = True

if dp[-1]:
  print('YES')
else:
  print('NO')
S = input()

idx = len(S)
while idx > 0:
    if S[idx-7:idx] == "dreamer":
        idx -= 7
    elif S[idx-6:idx] == "eraser":
        idx -= 6
    elif S[idx-5:idx] in ["dream", "erase"]:
        idx -= 5
    else:
        print("NO")
        break
else:
    print("YES")
s = str(input())
s = s[::-1]  #sを逆にする

l = ['resare', 'esare', 'remaerd', 'maerd']

f = 0

if len(s) == 0:
    f = 1

while len(s) != 0:
    if s[:7] == 'remaerd':
        s = s[7::]
    elif s[:6] == 'resare':
        s = s[6::]
    elif s[:5] == 'esare':
        s = s[5:]
    elif s[:5] == 'maerd':
        s = s[5:]
    else:
        f = 1
        break

if f == 1:
    print("NO")
else:
    print("YES")
S = input()

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

is_updated = True
while is_updated and len(S) > 0:
  is_updated = False
  for text in TEXTS:
    if S[len(S) - len(text):] == text:
      S = S[:len(S) - len(text)]
      is_updated = True

if S == '':
  print('YES')
else:
  print('NO')
import sys
from collections import deque
s = input()

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

index = 0
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))
print('NO')
s = input()
s = s[::-1]
while s:
    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')
s = input()
ans = ''
while 1:
    if s[-7:] == 'dreamer':
        s = s[:-7]
        continue
    if s[-6:] == 'eraser':
        s = s[:-6]
        continue
    if s[-5:] == 'dream':
        s = s[:-5]
        continue
    if s[-5:] == 'erase':
        s = s[:-5]
        continue
    if s == '':
        ans = 'YES'
        break
    else:
        ans = 'NO'
        break
print(ans)
S=input()
n=len(S)
while n>0:
    if S[n-5:n]=='dream':
        n-=5
    elif S[n-5:n]=='erase':
        n-=5
    elif S[n-7:n]=='dreamer':
        n-=7
    elif S[n-6:n]=='eraser':
        n-=6
    else:
        print('NO')
        exit()
print('YES')
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=input()
while(len(S)>=5):
    if(len(S)>=7 and S[len(S)-7:len(S)]=='dreamer'):
        S=S[:len(S)-7]
    elif(len(S)>=6 and S[len(S)-6:len(S)]=='eraser'):
        S=S[:len(S)-6]
    elif(S[len(S)-5:len(S)]=='dream' or S[len(S)-5:len(S)]=='erase'):
        S=S[:len(S)-5]
    else:
        print("NO")
        exit()
if(len(S)!=0):
    print("NO")
else:
    print("YES")
s = input()
n = len(s)
dp = [0] * (n+1)
dp[0] = 1
for i in range(1,n+1):
    if i >= 5:
        if s[i-5:i] == "dream" or s[i-5:i] == "erase":
            dp[i] = dp[i-5]
    if i >= 6:
        if s[i-6:i] == "eraser":
            dp[i] = dp[i-6]
    if i >= 5:
        if s[i-7:i] == "dreamer":
            dp[i] = dp[i-7]
if dp[n]:
    print('YES')
else:
    print('NO')
S=input()
check=["dream","dreamer","erase","eraser"]
S=S[::-1]
for i in range(len(check)):
  check[i]=check[i][::-1]
nagasa=len(S)
cur=0
while cur<nagasa:
  flag=False
  for x in check:
    find_pos=S.find(x,cur)
    if cur==find_pos:
      flag=True
      cur=find_pos+len(x)
      break
  if flag==False:
    print("NO")
    exit()
print("YES")
def main():
  s = input()
  dream = False
  erase = False

  while s:
    if s.startswith('dream'):
      s = s[5:]
      dream = True
      erase = False
    elif s.startswith('erase'):
      s = s[5:]
      dream = False
      erase = True
    elif s.startswith('er') and dream:
      s = s[2:]
      dream = False
    elif s.startswith('r') and erase:
      s = s[1:]
      erase = False
    else:
      return False
  
  return True

if main():
  print('YES')
else:
  print('NO')
S = input()
s = S.split("a")
H = S.split("a",1)
h=H[0]
B = S.rsplit("a",1)
b=B[1]
X = set(s)
if h in ["dre","er"]:
  if b in ["m","mer","se","ser"]:
    if X <= {"dre","er","m","mer","se","ser","mdre","merdre","mer","merer","sedre","serdre","seer","serer"}:
      print("YES")
    else:
      print("NO")  
  else:
    print("NO")
else:
  print("NO")
s = str(input())

dream = 'dream'
dreamer = 'dreamer'
erase = 'erase'
eraser = 'eraser'

while s !='':
  if s.endswith(dream):
    s = s[:-5]
  elif s.endswith(dreamer):
    s = s[:-7]
  elif s.endswith(erase):
    s = s[:-5]
  elif s.endswith(eraser):
    s = s[:-6]
  else:
    print('NO')
    exit()
 
print('YES')
S = input()
'''
dp[i]はSのi文字目（1~Sの長さ)までを表せるかどうか
'''
dp = [0] * (len(S) + 1)
dp[0] = 1
check = "NO"

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

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:
        check = "YES"
        break

print(check)
S=input()
T=["dream","dreamer","erase","eraser"]
S=S.replace(T[3],"0000000").replace(T[2],"00000").replace(T[1],"0000000").replace(T[0],"00000")
U=""
for k in range(len(S)):
    U+="0"
if S==U:
    print("YES")
else:
    print("NO")
S = input()[::-1]
devide = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
    devide[i] = devide[i] [::-1]
    
flag = True
i = 0
while i < len(S):
    flag2 = False
    for j in range(4):
        if devide[j] == S[i : i+len(devide[j])]:
            flag2 = True
            i += len(devide[j])
    
    if not flag2:
        flag = False
        break

print('YES' if flag == True else 'NO')
import re;print(re.match('(dream|dreamer|erase|eraser)*$',input())and'YES'or'NO')
S=input()
while 1:
    l=len(S)
    if S[-7:]   =="dreamer":
        S=S[0:l-7]
    elif S[-5:] =="dream":
        S=S[0:l-5]
    elif S[-6:] =="eraser":
        S=S[0:l-6]
    elif S[-5:] =="erase":
        S=S[0:l-5]
    else:break
if S=="":
    print("YES")
else:
    print("NO")
s = input()
n = len(s)
while 0 < n:
    if s[n-5:n] == 'dream' or s[n-5:n] == 'erase':
        n -= 5
        continue
    elif s[n-6:n] == 'eraser':
        n -= 6
        continue
    elif s[n-7:n] == 'dreamer':
        n -= 7
        continue
    print('NO')
    exit()
print('YES')
# coding: utf-8
# Your code here!
s = input()

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

if len(set(s)) == 1:
    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")
def main():
    S = input()
    T = set("dream dreamer erase eraser".split())
    
    p = ""
    for i in range(len(S)):
        p = S[~i] + p
        if p in T:
            p = ""
        elif len(p) > 7:
            print("NO")
            return

    print("YES")

main()
S = input()
T = ""

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

tmp = ""
for s in S[::-1]:
  tmp = s + tmp
  if tmp in U:
    T = tmp + T
    tmp = ""

if T == 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')
a = list(input())
 
while len(a) >= 5:
    if a[-5:] == list('dream'):
        del a[-5:]
        continue
    if a[-7:] == list('dreamer'):
        del a[-7:]
        continue
    if a[-5:] == list('erase'):
        del a[-5:]
        continue
    if a[-6:] == list('eraser'):
        del a[-6:]
        continue
    break
 
if a == []:
    print('YES')
else:
    print('NO')
def resolve():
    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:
            break
    print("YES" if len(S) == 0 else "NO")
resolve()
s=input()
n=len(s)
i=1
for j in range(n//5):
    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")
s = input()

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

if len(s) > 0:
    print("NO")
else:
    print("YES")
S = input()
results = True
while results:
    for key_word in ["erase", "eraser", "dream", "dreamer"]:
        if S.endswith(key_word):
            S = S[:-len(S)]
            continue
    if S == '':
        print("YES")
        results = False
        break
    else:
        print("NO")
        results = False
        break
S = input()
l = ['maerd','remaerd', 'esare', 'resare']

def test(S,l):
    tmpS = S
    while len(tmpS) > 0:
        if tmpS[::-1] in l:
            print('YES')
            return
        if tmpS[-1:-6:-1] in l:
            tmpS = tmpS[:-5]
        elif tmpS[-1:-7:-1] in l:
            tmpS = tmpS[:-6]
        else:
      	    print('NO')
      	    return
    print('YES')
    return
  
test(S,l)
words=["eraser","erase","dreamer","dream"]
S=input()
for i in range(0,4):
    S=S.replace(words[i],"",)
if S=="":
    print("Yes")
else:
    print("No")
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]
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
    elif 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()
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()
s.replace("eraser","")
s.replace("erase","")
s.replace("dreamer","")
s.replace("dream","")

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

sc = ["dreameraser", "dreamerase", "dreamer", "dream", "eraser", "erase"]
for i in sc:
    S = S.replace(i, '')

if len(S) == 0:
    print("YES")
else:
    print("NO")
S = input()
ls = {"dream","dreamer","erase","eraser"}
now = ""
for i in range(len(S)):
  now += S[i]
  if now in ls:
    now = ""
if now == "":
  print("YES")
else:
  print("NO")
s = input()

sc = ["dreameraser", "dreamerase", "dreamer", "dream", "eraser", "erase"]
for i in sc:
    s = s.replace(i, '')

if len(s) == 0:
    print("YES")
else:
    print("NO")
S = input()
S_r = S[::-1]

Ss = ["maerd","remaerd","esare","resare"]
for s in Ss:
    S_r = S_r.replace(s,"") 

if S_r == "":
    print("YES")
else:
    print("NO")
S = input()
strs = ["erase", "eraser", "dreamer","dream"]
rtss = [s[::-1] for s in strs]
S_r = S[::-1]
for rts in rtss:
    S_r = S_r.replace(rts, "")
if len(S_r) == 0:
    print("Yes")
else:
    print("No")
s = input()

import re
output ="NO"
s = re.sub('dreamer', '', s)
s = re.sub('dream', '', s)
s = re.sub('eraser', '', s)
s = re.sub('erase', '', s)
if s == "":
    output = "YES"
print(output)
#049_C
s = input()

s = s.replace('dream', '').replace('dreamr', '').replace('erase', '').replace('eraser', '')
print('YES' if s == '' else 'NO')
import re
flag = re.match('^(deram|dreamer|erase|eraser)+$',input())
if flag:
    print('YES')
else:
    print('NO')
# coding: utf-8
# Your code here!
s = input()

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

if len(set(s)) == 1:
    print("YES")
else:
    print("NO")
import sys
s = input()
a = 'dream'
b = 'dreamer'
c = 'erase'
d = 'eraser'
for i in range(len(s)):  
  if not s[i] == a[i//4] or s[i] == b[i//5] or s[i] == c[i//4] or s[i] == d[i//5]:
    print('NO')
    sys.exit( )
print('YES')
listseer =['dreameraser', 'dreamerase', 'dreamer', 'eraser', 'dream', 'erase']
S = input()
for i in listseer:
    S = S.replace(i, '')
print('YES' if len(S) == 0 else 'NO')
from collections import deque

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

while q:
  if len(q) >= 5:
    subs = q.popleft()+q.popleft()+q.popleft()+q.popleft()+q.popleft()
    if subs != 'erase' and subs != 'dream':
      print('NO')
      exit()
    if subs == 'erase' and len(q) != 0 and q[0] == 'r':
      q.popleft()
  else:
    print('NO')
    exit()
    
print('YES')
s = str(input())
i = 0
while(1):
    if len(s) - i < 5:
        break
    if s[i:i+5] == "erase" or s[i:i+5] == "dream":
        i += 5
        if s[i:i+2] == "er":
            i += 2
    else:
        print("No")
        exit()
print("YES" if i == len(s) else "NO")
s = input()

import re
output ="NO"
s = re.sub('dreameraser', '', s)
s = re.sub('dreamerase', '', s)
s = re.sub('dreamer', '', s)
s = re.sub('dream', '', s)
s = re.sub('eraser', '', s)
s = re.sub('erase', '', s)
if s == "":
    output = "YES"
print(output)
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')
S = input()[::-1]
S = S.replace('dream'[::-1], '').replace('dreamer'[::-1], '').replace(
    'eraser'[::-1], '').replace('erase'[::-1], '')

if len(S) == 0:
    print('YES')
else:
    print('NO')
li = input()
list = ['dream','dreamer','erase','eraser']
flag = 'NO'
for x in list:
  for y in list:
    z = x + y
    if z == li:
      flag = 'YES'
      
print(flag)
S = input()
strs = list(reversed(S))
rev_S = ''.join(strs)
while True:
  if len(rev_S)< 5:
    break
  elif rev_S[:6] == 'resare'or rev_S[:6] == 'remaerd':
    rev_S = rev_S[6:]
    continue
  elif rev_S[:5] == 'esare' or rev_S[:5] == 'maerd':
    rev_S = rev_S[5:]
    continue
  else:
    break

if rev_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("NO" if len(S)>0 else "YES")
S = input().replace("eraser","").replace("erase","").replace("dream","").replace("dreamer","")

if S:
    print("YES")
else:
    print("NO")
S = input()
T = ''
words = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(words)):
    words[i] = words[i][::-1]
for i in S[::-1]:
    T += i
    for q in words:
        if T == q:
            T = ''
if T == '':
    print('YES')
else:
    print('No')
S = input()
while True :
  if S[0:5] == "dream":
    S = S.replace("dream","")
  elif S[0:6] == "eraser":
    S = S.replace("eraser","")
  elif S[0:7] == "dreamer":
    S = S.replace("dreamer","")
  elif S[0:5] == "erase":
    S = S.replace("erase","")
  elif len(S) == 0:
    print("YES")
    break
  else:
    print("NO")
    break