You are given a string S consisting of lowercase English letters.
Another string T is initially empty.
Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:
 - Append one of the following at the end of T: dream, dreamer, erase and eraser.

-----Constraints-----
 - 1≦|S|≦10^5
 - S consists of lowercase English letters.

-----Input-----
The input is given from Standard Input in the following format:
S

-----Output-----
If it is possible to obtain S = T, print YES. Otherwise, print NO.

-----Sample Input-----
erasedream

-----Sample Output-----
YES

Append erase and dream at the end of T in this order, to obtain S = T.

Difficulty: MEDIUM_HARD

Solutions:
S = input()
S = ''.join(list(reversed(S)))
str_list = ['dream', 'dreamer', 'erase', 'eraser']
rev_str = []
for i in str_list:
	rev_str.append(''.join(list(reversed(i))))
is_OK = True
while len(S) > 0:
	if S[0:5] in rev_str:
		S = S[5:]
	elif S[0:6] in rev_str:
		S = S[6:]
	elif S[0:7] in rev_str:
		S = S[7:]
	else:
		is_OK = False
		break
if is_OK:
	print('YES')
else:
	print('NO')


s = input()
i = 0
n = len(s)
while i < n:
	if s[i:i + 10] == 'dreamerase':
		i += 5
	elif s[i:i + 7] == 'dreamer':
		i += 7
	elif s[i:i + 5] == 'dream':
		i += 5
	elif s[i:i + 6] == 'eraser':
		i += 6
	elif s[i:i + 5] == 'erase':
		i += 5
	else:
		break
print('YES' if i == n else 'NO')


S = input()
while S:
	if S[-5:] == 'dream' or S[-5:] == 'erase':
		S = S[:-5]
	elif S[-6:] == 'eraser':
		S = S[:-6]
	elif S[-7:] == 'dreamer':
		S = S[:-7]
	else:
		print('NO')
		break
else:
	print('YES')


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


s = input()
x = 0
a = s.count('dream')
b = s.count('dreamer')
c = s.count('erase')
d = s.count('eraser')
reigai1 = s.count('dreamerase')
reigai2 = s.count('dreameraser')
reigai1 = reigai1 - reigai2
b = b - reigai1 - reigai2
a = a - reigai1 - reigai2
c = c - reigai1 - reigai2
d = d - reigai2
a2 = a - b
c2 = c - d
if a2 * 5 + b * 7 + c2 * 5 + d * 6 + reigai1 * 10 + reigai2 * 11 == len(s):
	print('YES')
else:
	print('NO')


S = input()
S = S[::-1]
ws = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
while i < len(S):
	for w in ws:
		if w == S[i:i + len(w)]:
			i += len(w)
			break
	else:
		print('NO')
		return
print('YES')


import sys
read = sys.stdin.read
readline = sys.stdin.readline
s = [*input()]
a = [*'dream']
b = [*'dreamer']
c = [*'erase']
d = [*'eraser']
while True:
	if not s:
		print('YES')
		break
	elif s[-5:] == a:
		for _ in range(5):
			s.pop()
	elif s[-5:] == c:
		for _ in range(5):
			s.pop()
	elif s[-7:] == b:
		for _ in range(7):
			s.pop()
	elif s[-6:] == d:
		for _ in range(6):
			s.pop()
	else:
		print('NO')
		break


S = input()
S = S[::-1]
key = ['dream'[::-1], 'erase'[::-1], 'dreamer'[::-1], 'eraser'[::-1]]
f = False
while S != '':
	f = False
	for i in range(4):
		tmp = S[0:len(key[i])]
		if tmp == key[i]:
			S = S[len(key[i]):]
			f = True
			break
	if not f:
		break
if f:
	print('YES')
else:
	print('NO')


S = input()
i = 3
while i <= len(S):
	if i == 3:
		if S[-3:] == 'eam':
			i += 2
			if S[-i:-i + 2] == 'dr':
				i += 3
			else:
				print('NO')
				break
		elif S[-3:] == 'mer':
			i += 4
			if S[-i:-i + 4] == 'drea':
				i += 3
			else:
				print('NO')
				break
		elif S[-3:] == 'ase':
			i += 2
			if S[-i:-i + 2] == 'er':
				i += 3
			else:
				print('NO')
				break
		elif S[-3:] == 'ser':
			i += 3
			if S[-i:-i + 3] == 'era':
				i += 3
			else:
				print('NO')
				break
		else:
			print('NO')
			break
	elif S[-i:-i + 3] == 'eam':
		i += 2
		if S[-i:-i + 2] == 'dr':
			i += 3
		else:
			print('NO')
			break
	elif S[-i:-i + 3] == 'mer':
		i += 4
		if S[-i:-i + 4] == 'drea':
			i += 3
		else:
			print('NO')
			break
	elif S[-i:-i + 3] == 'ase':
		i += 2
		if S[-i:-i + 2] == 'er':
			i += 3
		else:
			print('NO')
			break
	elif S[-i:-i + 3] == 'ser':
		i += 3
		if S[-i:-i + 3] == 'era':
			i += 3
	else:
		print('NO')
		break
else:
	print('YES')


import sys
LS = [list('dream')[::-1], list('dreamer')[::-1], list('erase')[::-1], list('eraser')[::-1]]
S = list(input())[::-1]
while S:
	if S[:7] == LS[1]:
		for l in LS[1]:
			S.remove(l)
	elif S[:6] == LS[3]:
		for l in LS[3]:
			S.remove(l)
	elif S[:5] == LS[0]:
		for l in LS[0]:
			S.remove(l)
	elif S[:5] == LS[2]:
		for l in LS[2]:
			S.remove(l)
	else:
		print('NO')
		return
print('YES')


s = list(input())
c = 0
while len(s) > 0:
	p = '1'
	q = '1'
	r = '1'
	if len(s) < 5:
		break
	if len(s) <= 7:
		if len(s) == 5:
			if s == list('dream') or s == list('erase'):
				c = 1
				break
		elif len(s) == 6:
			if s == list('eraser'):
				c = 1
				break
		elif len(s) == 7:
			if s == list('dreamer'):
				c = 1
				break
	else:
		p = s[len(s) - 5:len(s)]
		q = s[len(s) - 6:len(s)]
		r = s[len(s) - 7:len(s)]
		if p == list('dream') or p == list('erase'):
			del s[len(s) - 5:len(s)]
		elif q == list('eraser'):
			del s[len(s) - 6:len(s)]
		elif r == list('dreamer'):
			del s[len(s) - 7:len(s)]
		else:
			break
print('YES' if c == 1 else 'NO')


l = ['maerd', 'remaerd', 'esare', 'resare']
flag = False
S = input()
S = ''.join(list(reversed(S)))
j = 0
for i in range(len(S) + 1):
	if S[j:i] in l:
		j = i
		flag = True
	else:
		flag = False
print('YES' if flag else 'NO')


S = list(input())
d = list('dream')
e = list('erase')
er = list('er')
r = list('r')
c = 0
while c < len(S):
	if S[c:c + 5] == d:
		c += 5
		if S[c:c + 5] == e:
			c += 5
			if S[c:c + 1] == r:
				c += 1
		elif S[c:c + 2] == er:
			c += 2
	elif S[c:c + 5] == e:
		c += 5
		if S[c:c + 1] == r:
			c += 1
	else:
		print('NO')
		return
print('YES')


s = input()
s = s.replace('eraser', '*')
s = s.replace('erase', '*')
s = s.replace('dreamer', '*')
s = s.replace('dream', '*')
f = 1
for i in s:
	if i != '*':
		f = 0
		break
if f:
	print('YES')
else:
	print('NO')


S = input()
lst = ['dreamer', 'dream', 'eraser', 'erase']
lst = [''.join(list(reversed(k))) for k in lst]
S = ''.join(list(reversed(S)))
i = 0
while i < len(S):
	found = False
	for k in lst:
		try:
			if S[i:].index(k) == 0:
				found = True
				i += len(k)
				break
		except:
			continue
	if not found:
		print('NO')
		return
print('YES')


from collections import deque

def solve(s):
	stack = deque()
	stack.append(s)
	while len(stack) > 0:
		top = stack.pop()
		if top == '':
			return 'YES'
		if top[:5] == 'dream':
			if top[5:7] == 'er':
				stack.append(top[7:])
			stack.append(top[5:])
		elif top[:5] == 'erase':
			if len(top) > 5 and top[5] == 'r':
				stack.append(top[6:])
			else:
				stack.append(top[5:])
	return 'NO'
print(solve(input()))


S = input()
a = len(S)
while a != 0:
	if a - 5 < 0:
		print('NO')
		return
	elif S[a - 1] == 'm' and S[a - 5:a] == 'dream':
		a -= 5
	elif S[a - 1] == 'e' and S[a - 5:a] == 'erase':
		a -= 5
	elif S[a - 3:a] == 'mer' and a - 7 >= 0 and (S[a - 7:a] == 'dreamer'):
		a -= 7
	elif S[a - 3:a] == 'ser' and a - 6 >= 0 and (S[a - 6:a] == 'eraser'):
		a -= 6
	else:
		print('NO')
		return
print('YES')


S = input()
T = ''
SS = S[::-1]
d = 'maerd'
dd = 'remaerd'
e = 'esare'
ee = 'resare'
cnt1 = 0
cnt2 = 5
for i in range(4, len(S)):
	if SS[cnt1:cnt2] == dd:
		T += dd
		cnt1 = cnt2
		cnt2 += 1
	elif SS[cnt1:cnt2] == ee:
		T += ee
		cnt1 = cnt2
		cnt2 += 1
	elif SS[cnt1:cnt2] == d:
		T += d
		cnt1 = cnt2
		cnt2 += 1
	elif SS[cnt1:cnt2] == e:
		T += e
		cnt1 = cnt2
		cnt2 += 1
	else:
		cnt2 += 1
print('YES' if S == T[::-1] else 'NO')


s = str(input())
isYES = True
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:
		isYES = False
		break
if isYES:
	print('YES')
else:
	print('NO')


s = input()
i = len(s)
while True:
	if i == 0:
		print('YES')
		break
	if 6 < i and s[i - 7:i] == 'dreamer':
		i -= 7
		continue
	if 5 < i and s[i - 6:i] == 'eraser':
		i -= 6
		continue
	if 4 < i and s[i - 5:i] in ['dream', 'erase']:
		i -= 5
		continue
	print('NO')
	break


ar = list(input())
l = len(ar)
if l < 5:
	print('NO')
else:
	while True:
		if l == 0:
			print('YES')
			return
		if ''.join(ar[l - 5:l]) == 'dream' or ''.join(ar[l - 5:l]) == 'erase':
			l -= 5
		elif ''.join(ar[l - 6:l]) == 'eraser':
			l -= 6
		elif ''.join(ar[l - 7:l]) == 'dreamer':
			l -= 7
		else:
			print('NO')
			return


S = list(input())
A = ['dream', 'dreamer', 'erase', 'eraser']
ans = 'YES'
l = len(S)
while l >= 5:
	if S[l - 5:l] == list(A[0]):
		l -= 5
	elif S[l - 5:l] == list(A[2]):
		l -= 5
	elif l == 5:
		break
	elif S[l - 6:l] == list(A[3]):
		l -= 6
	elif l == 6:
		break
	elif S[l - 7:l] == list(A[1]):
		l -= 7
	else:
		ans = 'NO'
		break
if l != 0:
	ans = 'NO'
print(ans)


S = str(input())
S = S.replace('dream', '#')
S = S.replace('erase', '.')
S = S.replace('#er', '')
S = S.replace('.r', '')
S = S.replace('#', '')
S = S.replace('.', '')
if len(S) == 0:
	print('YES')
else:
	print('NO')


S = input()
i = len(S)
ans = 'NO'
while True:
	if i == 0:
		ans = 'YES'
		break
	if i >= 5 and S[i - 5:i] == 'dream':
		i -= 5
	elif i >= 5 and S[i - 5:i] == 'erase':
		i -= 5
	elif i >= 6 and S[i - 6:i] == 'eraser':
		i -= 6
	elif i >= 7 and S[i - 7:i] == 'dreamer':
		i -= 7
	else:
		break
print(ans)


def db(x):
	nonlocal debug
	if debug:
		print(x)

def gen(tstr):
	if len(tstr) <= len(S):
		for w in words:
			yield (tstr + w)
			for w2 in gen(tstr + w):
				yield w2

def solve():
	ans = False
	for genstr in gen(''):
		db(genstr)
		if genstr == S:
			ans = True
			break
	return ans

def solve2():
	stack = list(words)
	while stack != []:
		str = stack.pop()
		db(('pop', str))
		if len(str) < len(S):
			for w in words:
				stack.append(str + w)
		elif len(str) == len(S) and str == S:
			return True
	return False

def solve3():
	string = S + ' '
	n = len(string)
	while n > 1:
		for w in words:
			db((string.rfind(w, 0, n), len(w), n))
			if string.rfind(w, 0, n) + len(w) + 1 == n:
				break
		else:
			return False
		db((n, w))
		n -= len(w)
	return True
debug = False
words = ('dream', 'dreamer', 'erase', 'eraser')
S = input()
db(S)
if solve3():
	print('YES')
else:
	print('NO')


daydream = ['dream', 'dreamer', 'erase', 'eraser']
s = input()
import sys
while s:
	for i in daydream:
		if s.endswith(i):
			s = s[:-len(i)]
			break
	else:
		break
else:
	print('YES')
	return
print('NO')


S = input()
last_ind = len(S)
yes = True
for i in range(len(S) - 1, -1, -1):
	if S[i:last_ind] == 'dream' or S[i:last_ind] == 'erase' or S[i:last_ind] == 'eraser' or (S[i:last_ind] == 'dreamer'):
		last_ind = i
		continue
	if last_ind - i > 7 or i == 0:
		yes = False
		break
if yes:
	print('YES')
else:
	print('NO')


S = input()
S = S[::-1]
S = S.replace('resare', '')
S = S.replace('esare', '')
S = S.replace('remaerd', '')
S = S.replace('maerd', '')
if S:
	print('NO')
else:
	print('YES')


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


s = input()
n = len(s)
idx = 0
while idx < n:
	if idx + 5 > n:
		break
	if s[idx:idx + 5] == 'dream':
		idx += 5
		if idx + 2 <= n and s[idx:idx + 2] == 'er' and (idx + 2 == n or s[idx + 2:idx + 3] != 'a'):
			idx += 2
	elif s[idx:idx + 5] == 'erase':
		idx += 5
		if idx + 1 <= n and s[idx:idx + 1] == 'r':
			idx += 1
	else:
		break
if idx == n:
	print('YES')
else:
	print('NO')


S = input()
for i in range(100000):
	if S[len(S) - 5:] == 'dream' or S[len(S) - 5:] == 'erase':
		S = S[:len(S) - 5]
	elif S[len(S) - 7:] == 'dreamer':
		S = S[:len(S) - 7]
	elif S[len(S) - 6:] == 'eraser':
		S = S[:len(S) - 6]
	elif S == '':
		print('YES')
		break
	else:
		print('NO')
		break


S = input()
pnt = len(S)
while pnt:
	tmp = pnt
	if pnt >= 7:
		if S[pnt - 7:pnt] == 'dreamer':
			pnt -= 7
	if pnt >= 6:
		if S[pnt - 6:pnt] == 'eraser':
			pnt -= 6
	if pnt >= 5:
		if S[pnt - 5:pnt] == 'dream' or S[pnt - 5:pnt] == 'erase':
			pnt -= 5
	if tmp == pnt:
		break
if pnt:
	print('NO')
else:
	print('YES')


S = input()
word_lst = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(word_lst)):
	word_lst[i] = word_lst[i][::-1]
S = S[::-1]
ans = ''
while len(ans) < len(S) - 4:
	if S[len(ans)] == 'm':
		ans = ans + word_lst[0]
	elif S[len(ans):len(ans) + 3] == 'rem':
		ans = ans + word_lst[1]
	elif S[len(ans)] == 'e':
		ans = ans + word_lst[2]
	elif S[len(ans):len(ans) + 3] == 'res':
		ans = ans + word_lst[3]
	else:
		break
if ans == S:
	print('YES')
else:
	print('NO')


import sys
S = input()
index = len(S)
while index > 7:
	five = S[index - 5:index]
	six = S[index - 6:index]
	seven = S[index - 7:index]
	if five == 'dream' or five == 'erase':
		index -= 5
	elif six == 'eraser':
		index -= 6
	elif seven == 'dreamer':
		index -= 7
	else:
		print('NO')
		return
last = S[:index]
if last == 'dream' or last == 'erase' or last == 'eraser' or (last == 'dreamer'):
	print('YES')
else:
	print('NO')


import copy
import sys
hoge = input()
n = len(hoge)
while 1:
	n = len(hoge)
	if n == 0:
		print('YES')
		return
	if n <= 4:
		print('NO')
		return
	elif hoge[-5:] == 'dream':
		tmp = copy.copy(hoge[0:-5])
		hoge = tmp
	elif hoge[-5:] == 'erase':
		tmp = copy.copy(hoge[0:-5])
		hoge = tmp
	elif n <= 5:
		print('NO')
		return
	elif hoge[-6:] == 'eraser':
		tmp = copy.copy(hoge[0:-6])
		hoge = tmp
	elif n <= 6:
		print('NO')
		return
	elif hoge[-7:] == 'dreamer':
		tmp = copy.copy(hoge[0:-7])
		hoge = tmp
	else:
		print('NO')
		return


S = input()
rS = S[::-1]
keys = ['dream', 'dreamer', 'erase', 'eraser']
reversed_keys = [keys[i][::-1] for i in range(len(keys))]
i = 0
while i < len(rS):
	if rS[i:i + 5] in reversed_keys:
		i += 5
	elif rS[i:i + 6] in reversed_keys:
		i += 6
	elif rS[i:i + 7] in reversed_keys:
		i += 7
	else:
		break
if i == len(rS):
	print('YES')
else:
	print('NO')


S = input()
N = len(S)
i = 0
while i < N:
	sig = 0
	S5 = S[i:i + 5]
	if S5 == 'dream':
		sig = 1
		if S[i + 5:i + 7] == 'er' and S[i + 7:i + 8] != 'a':
			i += 2
		i += 5
	elif S5 == 'erase':
		sig = 1
		if S[i + 5:i + 6] == 'r':
			i += 1
		i += 5
	if sig == 0:
		sig = 2
		Answer = 'NO'
		break
if sig != 2:
	Answer = 'YES'
print(Answer)


import sys
sys.setrecursionlimit(10 ** 9)
s1 = 'maerd'
s2 = 'remaerd'
s3 = 'esare'
s4 = 'resare'
i = input()
s = ''
for c in reversed(i):
	s += c
l = len(s)
i = 0

def dfs(i):
	if i == l:
		print('YES')
		return
	if i + 5 <= l and s[i:i + 5] == s1:
		dfs(i + 5)
	elif i + 7 <= l and s[i:i + 7] == s2:
		dfs(i + 7)
	elif i + 5 <= l and s[i:i + 5] == s3:
		dfs(i + 5)
	elif i + 6 <= l and s[i:i + 6] == s4:
		dfs(i + 6)
	else:
		print('NO')
		return
dfs(0)


a = input()
a = a.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if len(a) == 0:
	print('YES')
else:
	print('NO')


import sys
sys.setrecursionlimit(4100000)
import math
import fractions
S = input()
check = len(S) - 1
while check >= 0:
	if S[check] == 'r':
		if S[check - 2] == 'm':
			remove = S[check - 6:check + 1]
			if remove == 'dreamer':
				check -= 7
			else:
				print('NO')
				return
		elif S[check - 2] == 's':
			remove = S[check - 5:check + 1]
			if remove == 'eraser':
				check -= 6
			else:
				print('NO')
				return
		else:
			print('NO')
			return
	elif S[check] == 'e':
		remove = S[check - 4:check + 1]
		if remove == 'erase':
			check -= 5
		else:
			print('NO')
			return
	elif S[check] == 'm':
		remove = S[check - 4:check + 1]
		if remove == 'dream':
			check -= 5
		else:
			print('NO')
			return
	else:
		print('NO')
		return
print('YES')


def main():
	S = input()[::-1]
	d1 = 'dream'[::-1]
	d2 = 'dreamer'[::-1]
	e1 = 'erase'[::-1]
	e2 = 'eraser'[::-1]
	while len(S) > 0:
		if S[:5] == d1:
			S = S[5:]
		elif S[:7] == d2:
			S = S[7:]
		elif S[:5] == e1:
			S = S[5:]
		elif S[:6] == e2:
			S = S[6:]
		else:
			print('NO')
			return
	print('YES')

def __starting_point():
	main()
__starting_point()


def main():
	import sys
	input = sys.stdin.readline
	S = input().rstrip()
	limit = len(S) // 5
	while limit > 0 and len(S) > 0:
		if S.endswith('dreamer'):
			S = S[:len(S) - 7]
		elif S.endswith('eraser'):
			S = S[:len(S) - 6]
		elif S.endswith('dream'):
			S = S[:len(S) - 5]
		elif S.endswith('erase'):
			S = S[:len(S) - 5]
		limit -= 1
	print('NO' if S else 'YES')

def __starting_point():
	main()
__starting_point()


def YESNO(ans, yes='YES', no='NO'):
	print([no, yes][ans])
II = lambda : int(input())
MI = lambda : list(map(int, input().split()))
MIL = lambda : list(MI())
MIS = lambda : input().split()

def check(s):
	if s == '':
		return True
	if s[:5] in ['dream', 'erase']:
		return True
	return False

def main():
	S = input()
	i = 0
	l = len(S)
	while i < l:
		if S[i:i + 7] == 'dreamer' and check(S[i + 7:]):
			i += 7
		elif S[i:i + 6] == 'eraser' and check(S[i + 6:]):
			i += 6
		elif check(S[i:]):
			i += 5
		else:
			return False
	return True

def __starting_point():
	YESNO(main())
__starting_point()


s = input()
import sys
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')
		return
print('YES')


s = input()
t = s[::-1]
i = 0
k = len(s)
while i <= k - 5:
	if k - i >= 7:
		if t[i] != 'r':
			if t[i:i + 5] == 'maerd':
				i += 5
			elif t[i:i + 5] == 'esare':
				i += 5
			else:
				i = k + 1
		elif t[i:i + 6] == 'resare':
			i += 6
		elif t[i:i + 7] == 'remaerd':
			i += 7
		else:
			i = k + 1
	elif k - i == 6:
		if t[i:i + 6] == 'resare':
			i = k
		else:
			i = k + 1
	elif t[i:i + 5] == 'esare':
		i = k
	elif t[i:i + 5] == 'maerd':
		i = k
	else:
		i = k + 1
if i == k:
	print('YES')
else:
	print('NO')


s = input()[::-1]
T = ['dream', 'dreamer', 'erase', 'eraser']
T = [x[::-1] for x in T]
cur = ''
for e in s:
	cur += e
	if cur in T:
		cur = ''
print('YES' if cur == '' else 'NO')


S = input()
C = S[::-1]
while C:
	if C[:5] == 'maerd':
		C = C[5:]
	elif C[:7] == 'remaerd':
		C = C[7:]
	elif C[:5] == 'esare':
		C = C[5:]
	elif C[:6] == 'resare':
		C = C[6:]
	else:
		print('NO')
		return
print('YES')


import re
print('YES' if re.compile('^(dream|dreamer|erase|eraser)+$').match(input()) else 'NO')


S = input()
L = ['eraser', 'erase', 'dreamer', 'dream']
while len(S) > 0:
	for i in range(len(L)):
		if L[i] in S:
			S = S.replace(L[i], '')
	else:
		break
if len(S) == 0:
	print('YES')
else:
	print('NO')


s = input()
while len(s) > 0:
	if s[-5:] in ['dream', 'erase']:
		s = s[:-5]
	elif s[-6:] == 'eraser':
		s = s[:-6]
	elif s[-7:] == 'dreamer':
		s = s[:-7]
	else:
		break
print('YES' if s == '' else 'NO')


s = list(input())
n = len(s)
c = 0
k = 0
while c == 0:
	if k == n:
		c = 1
	elif k + 7 <= n - 1 and s[k] == 'd' and (s[k + 1] == 'r') and (s[k + 2] == 'e') and (s[k + 3] == 'a') and (s[k + 4] == 'm') and (s[k + 5] == 'e') and (s[k + 6] == 'r') and (s[k + 7] == 'a'):
		k += 5
	elif k + 6 <= n - 1 and s[k] == 'd' and (s[k + 1] == 'r') and (s[k + 2] == 'e') and (s[k + 3] == 'a') and (s[k + 4] == 'm') and (s[k + 5] == 'e') and (s[k + 6] == 'r'):
		k += 7
	elif k + 4 <= n - 1 and s[k] == 'd' and (s[k + 1] == 'r') and (s[k + 2] == 'e') and (s[k + 3] == 'a') and (s[k + 4] == 'm'):
		k += 5
	elif k + 6 <= n - 1 and s[k] == 'e' and (s[k + 1] == 'r') and (s[k + 2] == 'a') and (s[k + 3] == 's') and (s[k + 4] == 'e') and (s[k + 5] == 'r') and (s[k + 6] == 'a'):
		k += 5
	elif k + 5 <= n - 1 and s[k] == 'e' and (s[k + 1] == 'r') and (s[k + 2] == 'a') and (s[k + 3] == 's') and (s[k + 4] == 'e') and (s[k + 5] == 'r'):
		k += 6
	elif k + 4 <= n - 1 and s[k] == 'e' and (s[k + 1] == 'r') and (s[k + 2] == 'a') and (s[k + 3] == 's') and (s[k + 4] == 'e'):
		k += 5
	else:
		c = 1
if k == n:
	print('YES')
else:
	print('NO')


S = input()
d = ['dream', 'dreamer', 'erase', 'eraser']
d = [i[::-1] for i in d]
S = S[::-1]
i = 0
while i < len(S):
	ok = False
	for j in d:
		if S[i:i + len(j)] == j:
			i += len(j)
			ok = True
			break
	if ok is False:
		print('NO')
		import sys
		return
print('YES')


s = list(input())
s.reverse()
s = ''.join(map(str, s))
count = 0
word = ['maerd', 'remaerd', 'resare', 'esare']
while count <= len(s) - 8:
	counttemp = count
	for i in range(4):
		w = word[i]
		if s[count:count + len(w)] == w:
			count += len(w)
	if counttemp == count:
		break
if s[count:] in word or s[count:] == '':
	print('YES')
else:
	print('NO')


S = input()
while True:
	if S == '':
		print('YES')
		break
	else:
		a = S[-5:] in ('dream', 'erase')
		b = S[-6:] in 'eraser'
		c = S[-7:] in 'dreamer'
		if not (a or b or c):
			print('NO')
			break
		elif a:
			S = S[:-5]
		elif b:
			S = S[:-6]
		elif c:
			S = S[:-7]


import sys
S = input()
num = len(S)
S = S + 'zzzzzzzzzzzzzzzzzzzzzz'
cur = 0
while cur < num:
	if S[cur] == 'd':
		if S[cur:cur + 11] == 'dreameraser':
			cur += 11
		elif S[cur:cur + 10] == 'dreamerase':
			cur += 10
		elif S[cur:cur + 7] == 'dreamer':
			cur += 7
		elif S[cur:cur + 5] == 'dream':
			cur += 5
		else:
			print('NO')
			return
	elif S[cur] == 'e':
		if S[cur:cur + 6] == 'eraser':
			cur += 6
		elif S[cur:cur + 5] == 'erase':
			cur += 5
		else:
			print('NO')
			return
	else:
		print('NO')
		return
	if cur == num:
		print('YES')
		return


S = input()
N = len(S)
words = ['dream', 'dreamer', 'erase', 'eraser']
stack = [0]
ans = 'NO'
while stack:
	ind = stack.pop()
	if ind == N:
		ans = 'YES'
		break
	for w in words:
		end = ind + len(w)
		if S[ind:end] == w:
			stack.append(end)
print(ans)


s = input()
s = s[::-1]
top = 0
while top < len(s):
	if s[top:top + 5] == 'maerd':
		top += 5
	elif s[top:top + 7] == 'remaerd':
		top += 7
	elif s[top:top + 5] == 'esare':
		top += 5
	elif s[top:top + 6] == 'resare':
		top += 6
	else:
		print('NO')
		return
print('YES')


from itertools import product, takewhile

def main():
	words = ['eraser', 'erase', 'dreamer', 'dream']
	S = input()[::-1]
	for word in words:
		S = S.replace(word[::-1], '')
	if len(S) > 0:
		print('NO')
	else:
		print('YES')

def __starting_point():
	main()
__starting_point()


import sys
input = sys.stdin.readline

def main():
	s = input().strip()[::-1]
	while True:
		ok = False
		if len(s) >= 7:
			if s[:7] == 'remaerd':
				s = s[7:]
				ok = True
		if len(s) >= 6:
			if s[:6] == 'resare':
				s = s[6:]
				ok = True
		if len(s) >= 5:
			if s[:5] == 'esare' or s[:5] == 'maerd':
				s = s[5:]
				ok = True
		if not ok:
			break
	if len(s) > 0:
		print('NO')
	else:
		print('YES')

def __starting_point():
	main()
__starting_point()


S = input().strip()
L = len(S)
poss = [False for _ in range(L + 1)]
poss[0] = True
wds = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(L):
	if not poss[i]:
		continue
	for s in wds:
		if i + len(s) <= L:
			if S[i:i + len(s)] == s:
				poss[i + len(s)] = True
if poss[L]:
	print('YES')
else:
	print('NO')


S = input()
given = ['dream', 'dreamer', 'erase', 'eraser']
while True:
	if len(S) == 0:
		break
	judge = [S.endswith(i) for i in given]
	if True in judge:
		index = judge.index(True)
		length = len(given[index])
		S = S[:-length]
	else:
		print('NO')
		return
print('YES')


s = input()
s = s[::-1]
hoge = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
j = 0
while i < len(s):
	ans = ''
	while j < len(s):
		ans += s[j]
		if len(ans) > 7:
			print('NO')
			return
		if ans in hoge:
			break
		else:
			j += 1
	j += 1
	i = j
print('YES')


s = input(str())
lst = ['eraser', 'erase', 'dreamer', 'dream']
for t in lst:
	s = s.replace(t, '')
if s == '':
	print('YES')
else:
	print('NO')


s = input()
s = s[::-1]
tmp = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
	tmp[i] = tmp[i][::-1]
while 1:
	if len(s) >= 5:
		if s[:5] == tmp[0]:
			if len(s) > 5:
				s = s[5:]
			else:
				s = []
			continue
		if s[:5] == tmp[2]:
			if len(s) > 5:
				s = s[5:]
			else:
				s = []
			continue
		if len(s) >= 6:
			if s[:6] == tmp[3]:
				if len(s) > 6:
					s = s[6:]
				else:
					s = []
				continue
			if len(s) >= 7:
				if s[:7] == tmp[1]:
					if len(s) > 7:
						s = s[7:]
					else:
						s = []
					continue
	break
if s == []:
	print('YES')
else:
	print('NO')


import re
S = input()
flag = True
while flag:
	if len(S) == 0:
		flag = False
	if S[-5:] == 'dream' or S[-5:] == 'erase':
		S = S[:-5]
	elif S[-6:] == 'eraser':
		S = S[:-6]
	elif S[-7:] == 'dreamer':
		S = S[:-7]
	else:
		break
if flag:
	print('NO')
else:
	print('YES')


reverse_s = input().strip()[::-1]
while True:
	if len(reverse_s) == 0:
		print('YES')
		return
	if reverse_s.startswith('maerd'):
		reverse_s = reverse_s[len('maerd'):]
	elif reverse_s.startswith('remaerd'):
		reverse_s = reverse_s[len('remaerd'):]
	elif reverse_s.startswith('esare'):
		reverse_s = reverse_s[len('esare'):]
	elif reverse_s.startswith('resare'):
		reverse_s = reverse_s[len('resare'):]
	else:
		print('NO')
		return


import sys
import math
import itertools
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
input = sys.stdin.readline

def RD():
	return input().rstrip()

def F():
	return float(input().rstrip())

def I():
	return int(input().rstrip())

def MI():
	return map(int, input().split())

def MF():
	return map(float, input().split())

def LI():
	return list(map(int, input().split()))

def TI():
	return tuple(map(int, input().split()))

def LF():
	return list(map(float, input().split()))

def Init(H, W, num):
	return [[num for i in range(W)] for j in range(H)]

def main():
	word = ['dream', 'dreamer', 'erase', 'eraser']
	word = [i[::-1] for i in word]
	S = input().rstrip()
	S = S[::-1]
	while True:
		length = len(S)
		for w in word:
			length2 = len(w)
			if length >= length2 and S[0:length2] == w:
				S = S[length2:length]
		if len(S) == length:
			break
	if len(S) == 0:
		print('YES')
	else:
		print('NO')

def __starting_point():
	main()
__starting_point()


import sys
INF = float('inf')
sys.setrecursionlimit(10 ** 5)

def yes():
	print('YES')

def no():
	print('NO')
template = ['dream', 'dreamer', 'erase', 'eraser']

def dfs(s, i):
	if i == len(s):
		return True
	for t in template:
		if s[i:].startswith(t):
			if dfs(s, i + len(t)):
				return True
	return False

def solve(S: str):
	if dfs(S, 0):
		yes()
	else:
		no()
	return

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	S = next(tokens)
	solve(S)

def __starting_point():
	main()
__starting_point()


S = input()
S = S[::-1]
snipetts = [s[::-1] for s in ['dream', 'dreamer', 'erase', 'eraser']]
found = True
index = 0
while found:
	found = False
	for s in snipetts:
		if S[index:index + len(s)] == s:
			index += len(s)
			found = True
			break
if index == len(S):
	print('YES')
else:
	print('NO')


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


def II():
	return int(input())

def MII():
	return list(map(int, input().split()))

def LII():
	return list(map(int, input().split()))

def main():
	S = input()
	S = S[::-1]
	d = ['maerd', 'remaerd', 'esare', 'resare']
	f = False
	while True:
		for di in d:
			if S.startswith(di):
				f = False
				S = S.replace(di, '', 1)
		if f:
			break
		f = True
	if len(S) == 0:
		print('YES')
	else:
		print('NO')

def __starting_point():
	main()
__starting_point()


def solve(S):
	N = len(S)
	i = 0
	while i < N:
		if N - i < 5:
			return False
		if S[i:i + 5] == 'dream':
			if i + 7 <= N and S[i + 5:i + 7] == 'er':
				if i + 7 == N or S[i + 7] != 'a':
					i += 7
				else:
					i += 5
			else:
				i += 5
		elif S[i:i + 5] == 'erase':
			if i + 5 < N and S[i + 5] == 'r':
				i += 6
			else:
				i += 5
		else:
			return False
	return True
S = input()
print('YES' if solve(S) else 'NO')


import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin:

	def int():
		return int(sys.stdin.readline().rstrip())

	def string():
		return sys.stdin.readline().rstrip()

	def mapInt():
		return [int(x) for x in cin.string().split()]

	def stringList(n):
		return [input() for i in range(n)]

	def intListList(n):
		return [cin.mapInt() for i in range(n)]

	def intColsList(n):
		return [int(input()) for i in range(n)]

class Math:

	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	def roundUp(a, b):
		return -(-a // b)

	def toUpperMultiple(a, x):
		return Math.roundUp(a, x) * x

	def toLowerMultiple(a, x):
		return a // x * x

	def nearPow2(n):
		if n <= 0:
			return 0
		if n & n - 1 == 0:
			return n
		ret = 1
		while n > 0:
			ret <<= 1
			n >>= 1
		return ret

	def isPrime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True
MOD = int(1000000000.0) + 7

def main():
	S = cin.string()
	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')
			return
	print('YES')
	return

def __starting_point():
	main()
__starting_point()


S = input()
S = S[::-1]
while True:
	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:
		break
if len(S) == 0:
	print('YES')
else:
	print('NO')


s = input()
while s:
	m = [t for t in ['dream', 'dreamer', 'erase', 'eraser'] if s.endswith(t)]
	if not m:
		print('NO')
		return
	s = s[:-len(m[0])]
print('YES')


S = input()
t = len(S)
L = [('dream', 5), ('dreamer', 7), ('erase', 5), ('eraser', 6)]
while t > 0:
	for (w, l) in L:
		if S.rfind(w, 0, t) == t - l:
			t -= l
			break
	else:
		print('NO')
		break
else:
	print('YES')


S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']
rS = str(S[::-1])
rT = [str(t[::-1]) for t in T]
now = 0
while now < len(S):
	for t in rT:
		if t == rS[now:now + len(t)]:
			now += len(t)
			break
	else:
		print('NO')
		return
print('YES')


ar = list(input())
while True:
	a = len(ar)
	if a == 0:
		print('YES')
		break
	if ''.join(ar[a - 5:a]) == 'dream' or ''.join(ar[a - 5:a]) == 'erase':
		del ar[a - 5:a]
	elif ''.join(ar[a - 6:a]) == 'eraser':
		del ar[a - 6:a]
	elif ''.join(ar[a - 7:a]) == 'dreamer':
		del ar[a - 7:a]
	else:
		print('NO')
		break


S = list(input())
i = len(S) - 1
while i >= 4:
	if S[i - 4:i + 1] == ['d', 'r', 'e', 'a', 'm'] or S[i - 4:i + 1] == ['e', 'r', 'a', 's', 'e']:
		i -= 5
	elif i - 5 >= 0 and S[i - 5:i + 1] == ['e', 'r', 'a', 's', 'e', 'r']:
		i -= 6
	elif i - 6 >= 0 and S[i - 6:i + 1] == ['d', 'r', 'e', 'a', 'm', 'e', 'r']:
		i -= 7
	else:
		break
if i == -1:
	print('YES')
else:
	print('NO')


s = input()
search = []
search.append(s)
found = False
while len(search) > 0:
	se = search[0]
	search = search[1:]
	if se in ('dream', 'dreamer', 'erase', 'eraser'):
		print('YES')
		found = True
		break
	if len(se) < 5:
		continue
	if se[0:5] in ('dream', 'erase'):
		search.append(se[5:])
	if se[0:6] in 'eraser':
		search.append(se[6:])
	if se[0:7] in 'dreamer':
		search.append(se[7:])
if not found:
	print('NO')


s = input()
s = s[::-1]
lis = ['remaerd', 'resare', 'esare', 'maerd']
i = 0
j = 0
while i < len(s):
	tmp = ''
	while j < len(s):
		tmp += s[j]
		if len(tmp) == 8:
			print('NO')
			return
		elif tmp in lis:
			i = j + 1
			j = i
			break
		else:
			j += 1
print('YES')


S = input()
T = ''
l = ['maerd', 'remaerd', 'esare', 'resare']
flag = True
for i in range(len(S)):
	T = T + S[len(S) - 1 - i]
	if T in l:
		T = ''
	if len(T) > 7:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


import sys
input = sys.stdin.readline
S = input()[:-1]
dp = [0] * (len(S) + 1)
dp[0] = 1
for i in range(len(S)):
	if i + 5 <= len(S):
		if S[i:i + 5] == 'dream':
			dp[i + 5] += dp[i]
		if S[i:i + 5] == 'erase':
			dp[i + 5] += dp[i]
	if i + 7 <= len(S):
		if S[i:i + 7] == 'dreamer':
			dp[i + 7] += dp[i]
	if i + 6 <= len(S):
		if S[i:i + 6] == 'eraser':
			dp[i + 6] += dp[i]
if dp[-1]:
	print('YES')
else:
	print('NO')


S = input()
a = ['dream', 'dreamer', 'erase', 'eraser', 'dreamerase', 'dreameraser']
numlist = [0, 0, 0, 0, 0, 0]
for i in range(len(a)):
	numlist[i] = S.count(a[i])
numlist[0] -= numlist[1]
numlist[2] -= numlist[3]
numlist[4] -= numlist[5]
numlist[1] -= numlist[4] + numlist[5]
numlist[0] += numlist[4] + numlist[5]
total = numlist[0] * 5 + numlist[1] * 7 + numlist[2] * 5 + numlist[3] * 6
if total == len(S):
	print('YES')
else:
	print('NO')


s = input()
a = ''
for i in s[::-1]:
	a = i + a
	if a in ['dream', 'dreamer', 'erase', 'eraser']:
		a = ''
print('NO' if len(a) else 'YES')


S = input()[::-1]
n = len(S)
count = 0
flag = True
while count < n:
	if S[count:count + 5] == 'dream'[::-1]:
		count += 5
	elif S[count:count + 7] == 'dreamer'[::-1]:
		count += 7
	elif S[count:count + 5] == 'erase'[::-1]:
		count += 5
	elif S[count:count + 6] == 'eraser'[::-1]:
		count += 6
	else:
		flag = False
		break
print('YES') if flag else print('NO')