peterverebics/CodeNet_Python_118 huggingface dataset:
s=input()
f=0
l=['dream' ,'dreamer', 'erase','eraser']
while(f==0):
    if(s[:7] in l):
        s=s[7:]
    elif(s[:6] in l):
        s=s[6:]
    elif(s[:5] in l):
        s=s[5:]
    else:
        f=1
    
if(len(s)==0):
    print("YES")
else:
    print("NO")
lt = ["dream", "dreamer", "erase", "eraser"]
s = input()

lt = [w[::-1] for w in lt]
s = s[::-1]
cond = True
i = 0
while i < len(s):
    for t in lt:
        if s[i:].startswith(t):
            i += len(t)
            break
    else:
        cond = False
        break

print("Yes" if cond else "No")
s=input()
a=('dream','dreamer','erase','eraser')


s_2=s[::-1]
a_2=(a[0][::-1],a[1][::-1],a[2][::-1],a[3][::-1])

#print(s_2)
#print(a_2)

while len(s_2) > 0:
    judge = [s_2.startswith(i) for i in a_2]
    #print(judge)
    if any(judge)==True:
        target=a[judge.index(True)]
        s_2=s_2[len(target):]
        if len(s_2)==0:
            print('Yes')
    else:
        print('NO')
        break
s = input()

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

if len(s) > 0:
  print('NO')
else:
  print('YES')
S = str(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")
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
else:
    print('YES')
s = input()
# s = 'dreamerasererase'
while True:
    if s == '':
        print('YES')
        break
    if s.endswith('eraser'):
        s = s.rstrip('eraser')
    elif s.endswith('dreamer'):
        s = s.rstrip('dreamer')
    elif s.endswith('dream'):
        s = s.rstrip('dream')
    elif s.endswith('erase'):
        s = s.rstrip('erase')
    else:
        print('NO')
        break
s = input()

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

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

if s == "":
    print("YES")
else:
    print("NO")
def main():
    s = input()
    while len(s) > 0:
        if s[-6:] == "dreamer":
            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:
            print("NO")
            break
    else:
        print("YES")


if __name__ == '__main__':
    main()
S=input()
L=["dream","dreamer","erase","eraser"] 
for l in L:
    S=S.replace(l,"")
print("YES" if S=="" else "NO")
s = input()
list_pool = ["dream", "dreamer", "erase", "eraser"]

continue_flag = True

# 文字列sにlist_poolのどれかの単語と一致する部分があるか後方からチェック
while continue_flag is True and len(s) > 0:
    continue_flag = False
    for word in list_pool:
        if s.endswith(word):
            s = s.replace(word, '')
            continue_flag = True

if continue_flag is True:
    print("YES")
else:
    print("NO")
def solve():
    S = input()
    i = 0
    while i < len(S):
        if S[i:i+5] not in ['dream', 'erase']:
            return 'NO'
        i += 5
        if S[i:i+6] == 'eraser':
            i += 6
        if S[i:i+5] == 'erase':
            i += 5
        if S[i:i+2] == 'er':
            i += 2
    return 'YES'

    
if __name__ == '__main__':
    ans = solve()
    print(ans)
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')))

print(d)
if d == '':
  print('YES')
else:
  print('NO')
s = input().replace("eracer",'').replace('erace','').replace('dreamer','').replace('dreame','')
print('YES' if len(s) == 0 else 'NO')
S = input()
flag = 0
while True:
    if S.startswith("dream") or S.startswith("erase"):
        S = S[5:]
        if S.startswith("ase"):
            S = S[3:]
        if S.startswith("aser"):
            S = S[4:]
    if S.startswith("dreamer"):
        S = S[7:]
    if S.startswith("eraser"):
        S = S[6:]
    elif S == "":
        break
    else:
        flag = 1
        break
print("YES" if flag == 0 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)
            break
    else:
        print('No')
        exit()
else:
    print("YES")
S = input ()
Z = ''.join(list(reversed(S)))
Z = Z.replace('resare', '')
Z = Z.replace('esare', '')
Z = Z.replace('remaerd', '')
Z = Z.replace('maerd', '')
z = len (Z)
if z == 0:
    print ('Yes')
else:
    print ('No')
s = input()

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

if len(s) > 0:
    print("NO")
else:
    print("YES")
s = input()
 
kouho = ["dream", "dreamer", "erase", "eraser"]
 
s = s.replace(kouho[1], "").replace(kouho[3], "").replace(kouho[0], "").replace(kouho[2], "")
 
if s == "":
    print("YES")
else:
    print("NO")
c = input().rstrip('\n')
if (len(c) == 0):
  c = "f"
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()
ch = ["dream", "dreamer", "erase", "eraser"]
while S:
  N = len(S)
  if S[N-5:N] == ch[0] or S[N-5:N] == ch[2]:
    S = S[:N-5]
  elif S[N-6:N] == ch[1] or S[N-6:N] == ch[3]:
    S = S[:N-6]
  else:
    print("NO")
    exit()
print("YES")
s = input()
a = s.count("dream")
b = s.count("dreamer")
c = s.count("erase")
d = s.count("eraser")
e = s.count("dreamera")
f = s.count("erasera")
b = b-e
d = d-f
a = a-b
c = c-e
if (a+c)*5 + b*7 + d*6 == len(s):
  print("YES")
else:
  print("N0")
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, '')
        else:
            break
    
    if s == '':
        flag = 1
        break


if flag:
    print('YES')
else:
    print('NO')
s=input()[::-1]
words = {"dream", "dreamer", "erase", "eraser"}

for i in words:
    s = s.replace(i[::-1],'')
    print(s[::-1], i)

print("NO"if len(s)!=0else "YES")
s = input()
A=["","dream","dreamer","erase","eraser"]
flag=0
for a in range(1,5):
    for b in range(0,5):
        for c in range(0,5):
            for d in range(0,5):
                for e in range(0,5):
                    T=A[a]+A[b]+A[c]+A[d]+A[e]
                    if s==T:
                        flag=1

                
if flag==1:
    print("Yes")
else:
    print("No")
s = input()[::-1]
r = 'YES'
while len(s):
    if s[:6] == 'dreamer'[::-1] or s[:6] == 'eraser'[::-1]:
        s = s[6:]
    elif s[:5] == 'dream'[::-1] or s[:5] == 'erase'[::-1]:
        s = s[5:]
    else:
        r = 'NO'
        break
print(r)
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']


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


RT = [reverse(t) for t in T]
RS = reverse(S)


for i in range(len(RS)):
    can = False
    for j in range(4):
        sizeT = len(RT[j])
        if RT[j] == RS[i:sizeT]:
            i += sizeT
            can = True
            break

    if can:
        break

if can:
    print('YES')
else:
    print('NO')
s = input()
s.replace("eraser","")
s.replace("erase","")
s.replace("dreamer","")
s.replace("dream","")
if s:
    print("NO")
else:
    print("YES")
s = input()
A=["","dream","dreamer","erase","eraser"]
flag=0
for a in range(0,5):
    for b in range(0,5):
        for c in range(0,5):
            for d in range(0,5):
                T=A[a]+A[b]+A[c]+A[d]
                if s==T:
                     flag=1
if flag==1:
    print("Yes")
else:
    print("No")
s = str(input())

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

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

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

if len(S) == 0:
  print("Yes")
else:
  print("No")
import re;
s = input();
print("Yes" if re.match(r'^(dream|dreamer|eraser|erase)+$', s) else "NO")
S=input()

S=S.replace('eraser','')
S=S.replace('erase','')
S=S.replace('dreamer','')
S=S.replace('dream','')
if S=='':
  print('Yes')
else:
  print('No')
s = input()

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 == '':
    print('YES')
else:
    print('NO')
from collections import deque

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

while q:
  print(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 = 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+7] == 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 = str(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')
import re
moji=str(input())
for i in range(4):
  if "eraser" in moji:
    moji=re.sub("eraser", "", moji)
  elif "dreamer" in moji:
    moji=re.sub("dreamer", "", moji)
  elif "dream" in moji:
    moji=re.sub("dream", "", moji)
  elif "erase" in moji:
    moji=re.sub("erase", "", moji)

print("YES" if moji=="" else "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)
  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")
S = input()
strs = ["erase", "eraser", "dreamer","dream"]
rtss = [s[::-1] for s in strs]
S = S[::-1]

ind = 0
while True:
    print(ind,S[ind])
    if S[ind:ind+5] in rtss:
        ind += 5
    elif S[ind:ind+6] in rtss:
        ind += 6
    elif S[ind:ind+7] in rtss:
        ind +=7
    else:
        print("NO")
        exit()
    if ind == len(S):
        print("YES")
        exit()
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')
a = input().replace("eraser", "").replace("erase","").replace("dreamer","").replace("dream","")
if len(a) == 0:
    print("Yes")
else:
    print("No")
s = input()
s = s.strip()
list_pool = ["dream", "dreamer", "erase", "eraser"]

continue_flag = True

# 文字列sにlist_poolのどれかの単語と一致する部分があるか後方からチェック
while continue_flag is True and len(s) > 0:
    continue_flag = False
    for word in list_pool:
        if s.endswith(word):
            s = s.replace(word, '')
            continue_flag = True

if continue_flag is True:
    print("YES")
else:
    print("NO")
import re

S = input()

s = re.sub(r"(dreamer)|(eraser)", "", S)
s = re.sub(r"(dream)|(erase)", "", s)

if len(s) == 0:
    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
ans = ''
for _ in range(10):
    for j in nlis:
        if s.startswith(j):
            ans += j
            s = s.replace(j, '')
            
    
    if ans == s:
        flag = 1
        break

if flag:
    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":
    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()
str_list=["dreamer","eraser"]
str_list_2=["dream","erase"]

S_tmp=""
while True:
  S_tmp=S
  for str in str_list:
    if S[:7]=="dreamer":
      S=S.rstrip("dreamer")
    if S[:6]=="eraser":
      S=S.rstrip("eraser")
        
  if S_tmp==S:
    break

while True:
  S_tmp=S
  for str in str_list_2:
    if S[:5]==str:
    	S=S.rstrip(str)
    
  if S_tmp==S:
    break    
    
if S=="":
  print("YES")
if S!="":
  print("NO")
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")
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()
i=0

while True:
    flag = False
    if S[i:i+7] == "dreamer":
        i += 7
        flag = True

    if S[i:i+6] == "eraser":
        i += 6
        flag = True
    
    if S[i:i+5] == "erase" or S[i:i+5] == "dream":
        i += 5
        flag = True

    if not flag:
        break

if i == len(S):
    print("Yes")
else:
    print("No")
input_str = input()

while(True):
  if input_str[0:7] == "dreamer":
    input_str = input_str[7:]
  elif input_str[0:6] == "eraser":
    input_str = input_str[6:]
  elif input_str[0:5] == "dream" or input_str[0:5] == "erase":
    input_str = input_str[5:]
  else:
    print("NO")
    break
  
  if len(input_str) == 0:
    print("YES")
    break
S = input().replace("dreamer", "1").replace("dream", "1").replace(
    "eraser", "1").replace("erase", "1").replace("1", "")
if len(S) == 0:
    print("YES")
else:
    print("NO")
import re

s = input()
print('Yes' if re.match('^(dream|dreamer|erase|eraser)+$', s) else 'No')
s=str(input())
s=s[::-1]
print(s)
stack=""
for i in s:
  stack=i+stack
  if stack=="dream"or stack=="dreamer"or stack=="erase"or stack=="eraser":
    stack=""
  elif len(stack)>7:
    print("NO")
    exit()
print("YES")
S=input()

while(1):
    length = len(S)
    if length==0:
        break
    if S[length-3:length]=="eam":
        S = S[:length-5]
    elif S[length-3:length]=="mer":
        S = S[:length-7]
    elif S[length-3:length]=="ase":
        S = S[:length-5]
    elif S[length-3:length]=="ser":
        S = S[:length-6]
    else:
        print("NO")
        exit(0)
print("YES")
s = input()[::-1]
t =['maerd', 'remae', 'esare', 'resar']

if s[0:-5] in t:
    print('YES')
else:
    print('NO')
S = input()
while True:
    if S[-3:] == "mer": 
        S = S.replace("dreamer", "")
    elif S[-3:] == "ser": 
        S = S.replace("eraser", "")
    elif S[-3:] == "eam": 
        S = S.replace("dream", "")
    elif S[-3:] == "ase": 
        S = S.replace("erase", "")
    else:
        break
print("NO") if S else print("YES")
d=raw_input().strip()
l=["dreamer", "eraser", "dream", "erase"]
loop=True
while loop:
  match=False
  for i in l:
    if d.startswith(i):
      match=True
      d = d[len(i):]
      if not d:
        loop=False
        break
  if not match:
    break

if d:
  print("NO")
else:
  print("YES")
s = input()[::-1]
t =['maerd', 'remae', 'esare', 'resar']

if s[0:5] in t:
    print('YES')
else:
    print('NO')
t = ["dream","dreamer","erase","eraser"]

# 反転

t_r = []
for i in range(len(t)):
    t_r.append(t[i][::-1])
    
s = input()
s_r = s[::-1]

flag = True
for i in range(len(s_r)):
    flag2 = False
    for j in t_r:
        tmp_s = s_r[i:len(j)]       
        if(tmp_s == j):
            flag2 = True
            i += len(j)
    if flag2 == False:
        flag = False
        break

if flag==True:
    print("YES")
else:
    print("NO")
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))
MOD = 10 ** 9 + 7


S = input()
S = ''.join(list(reversed(S)))
while len(S) > 0:
    if S[:6] in ['resare', 'remaerd']:
        S = S[6:]
    elif S[:5] in ['esare', 'maerd']:
        S = S[5:]
    else:
        print('NO')
        exit(0)
print('YES')
s = input().replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if s:
    print("YES")
else:
    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)
  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")
S=input()
S=S[::-1]
N=len(S)

index=0
words=["maerd","remaerd","esare","resare"]
while index<N:
    word1=S[index:index+5]
    word2=S[index:index+7]
    if word1 in words:
        index+=5
    elif word2 in words:
        index+=7
    else:
        print("NO")
        exit()
print("YES")
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
    elif "".join(s[index:index+4]) == "aser":
        index += 4
    else:
        print("NO")
        exit()
print("YES")
s = input()
d = { "eam":5, "mer":7, "ase":5, "ser":6}
index = len(s)
while index != 0:
  tmp = s[index-3:index]
  if tmp not in d.keys():
    break
  index -= d[tmp]
else:
  print("YES")
  exit()
print("NO")
s = input().replace('eraser', '').replace('erace', '').replace('dreamer', '').replace('dream', '')
if s:
    print('no')
else:
    print('yes')
s = input()

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

print('NO' if len(s) > 0 else 'YES')
S=input()
n=len(S)
while n>0:
    print(S)
    if S[n-4:n+1]=='dream':
        n-=5
    elif S[n-4:n+1]=='erase':
        n-=5
    elif S[n-6:n+1]=='dreamer':
        n-=7
    elif S[n-5:n+1]=='eraser':
        n-=6
    else:
        print('NO')
        exit()
print('YES')
s = input()[::-1]
d = {'maerd', 'remaerd', 'esare', 'resare'}

cnt = 0
while cnt  < 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()
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:0]=='dreamer':
        s = s[:-7]
    else:
        break
if(flag):
    print('NO')
else:
    print('YES')
s = input()

import re
output ="NO"
s = re.sub('dreamer', '', s)
s = re.sub('eraser', '', s)
s = re.sub('dream', '', s)
s = re.sub('erase', '', s)
if s == "":
    output = "YES"
print(output)
s = input().replace("eracer",'').replace('erace','').replace('dreamer','').replace('dream','')
print('YES' if len(s) == 0 else 'NO')
s = input()
s = s[::-1]
s = s.replace('maerd','/')
s = s.replace('esare', '/')
s = s.replace('remaerd','/')
s = s.replace('resare','/')

s = s.replace('/', '')
if len(s) == 0:
    print('YES')
else:
    print('NO')
s = input()

flag = 0

while(len(s)>0):
  if (s[:6] == 'eraser'):
    s = s[6:]
  elif (s[:5] == 'erase'):
    s = s[5:]
  elif (s[:5] == 'dream'):
    if (s[5:8] == 'ere' or s[5:8] == 'erd'):
      s = s[7:]
    else:
      s = s[5:]
  else:
    flag = 1
    break

if (flag == 0):
  print('YES')
else:
  print('NO')
s = input()
erase = s.count("erase")
eraser = s.count("eraser")
dreameraser = s.count("dreameraser")
dream = s.count("dream")
dreamer = s.count("dreamer")
erase -= eraser
dream -= dreamer
dreamer -= dreameraser
eraser -= dreameraser
if (eraser * 6 + erase * 5 + dream * 5 + dreamer * 6 + dreameraser*11) == len(s):
    print("YES")
else:
    print("NO")
S = input()
K = S.replace("dream","")
L = K.replace("erase","")
M = L.replace("er","")
if M == "":
  print("YES")
else:
  print("NO")
S = input()
flag = 0
S = S[::-1]
while True:
    if S.startswith("maerd") or S.startswith("esare"):
        S = S[5:]
    elif S.startswith("remaerd"):
        S = S[7:]
    elif S.startswith("reesare"):
        S = S[6:]
    elif S == "":
        break
    else:
        flag = 1
        break
print("YES" if flag == 0 else "NO")
s=input()
s=s[::-1]
voc=['dream','dreamer','erase','eraser']
for i in range(len(voc)):
  voc[i]=voc[i][::-1]
while True:
  flag=False
  for v in voc:
    if s[:len(v)]==v:
      s=s[len(v):]
      flag=True
  if s=='':
    print('Yes')
    break
  elif not flag:
    print('No')
    break
s = input()
s = s.replace("dream","")
s = s.replace("dreamer","")
s = s.replace("erase","")
s = s.replace("eraser","")
if len(s)==0:
  print("YES")
else:
  print("NO")
s = input()

import re
output ="NO"
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)
import sys
import resource
sys.setrecursionlimit(100000)

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')
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:]
      
    elif S == "":
      flag = 5
      ans = "YES"
      break
    else:
      flag += 1
    
print(ans)
#ABC049

s = input()

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

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

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

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

if can:
    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:
    print("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('eraser', '', s)
s = re.sub('erase', '', s)
s = re.sub('dream', '', s)
if s == "":
    output = "YES"
print(output)
s = input()
s2 = s.split('eraser')
s3 = ''.join(s2).split('erase')
s4 = ''.join(s3).split('dreamer')
s5 = ''.join(s4).split('dream')

if len(s5) == 1 and s5[0] == '':
  print("YES")
else:
  print("NO")