Problem:
 Score : 300 points    Problem Statement 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 1 erasedream      Sample Output 1 YES  Append erase and dream at the end of T in this order, to obtain S = T .       Sample Input 2 dreameraser      Sample Output 2 YES  Append dream and eraser at the end of T in this order, to obtain S = T .       Sample Input 3 dreamerer      Sample Output 3 NO

Solution (Python):
S = list(input())
re = ['dream','dreamer','erase','eraser']
devide = False

T = []

for l in range(len(S)):
    T.insert(0,S.pop(-1))
    if len(T) >= 5:
        if ''.join(T) in re:
            T = []
    if len(T) > 7:
        break

if T == []:
    devide = True

if devide == False:
    print('NO')
else:
    print('YES')

Solution (Python):
from sys import stdin

s = stdin.readline().rstrip()

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

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

Solution (Python):


import numpy
import scipy



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")

Solution (Python):
import sys
s=input()
s=s[::-1]
l=list(["maerd","remaerd","esare","resare"])
i=0
while i < len(s):
  ok=0
  for j in l:
    if s[i:i+len(j)] == j:
      ok=1
      i += len(j)
      break
  if ok == 0:
    print("NO")
    sys.exit()
print("YES")

Solution (Python):
s = input()
a = ["eraser", "erase", "dreamer", "dream"]

for i in a:
	s = s.replace(i, "")
if s == "":
	print ("YES")
else:
	print ("NO")

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

Solution (Python):
s=list(input())
s.reverse()
judge=True
i=0
while i<=len(s)-5:
	box=[]
	for j in range(5):
		box+=s[i+j]
	if box==["m","a","e","r","d"] or box==["e","s","a","r","e"]:
		i+=5
		
	else:
		box+=s[i+5]
		
		if box==["r","e","s","a","r","e"]:
			i+=6
		else:
			box+=s[i+6]
			if box==["r","e","m","a","e","r","d"]:
				i+=7
			else:
				judge=False
				break
if judge:
	print("YES")
else:
	print("NO")

Solution (Python):
S = str(input())

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

S = S[::-1]
for i in range(len(tlist)):
    tlist[i] = tlist[i][::-1]

k = 0
suc = True
while k < len(S):
    suc2 = False
    for t in tlist:
        if S[k:k+len(t)] == t:
            suc2 = True
            k += len(t)
    if not suc2:
        suc = False
        break

if suc:
    print('YES')
else:
    print('NO')

Solution (Python):
s=input()
i=0 
while i==0:
  if len(s)==0:
    print("YES")
    exit()

  if s[0:5]=="dream":
    if s[0:7]=="dreamer":
      if s[5:11]=="eraser":
        s=s[11:]
      elif s[5:10]=="erase":
        s=s[10:]
      else:
        s=s[7:]
    else:
      s=s[5:]
  elif s[0:5]=="erase":
    if s[0:6]=="eraser":
      s=s[6:]
    else:
      s=s[5:]
  else:
    i+=1
print("NO")

Solution (Python):
import re
print("YES" if re.match("(dream|dreamer|erase|eraser)+$",input()) else "NO")

Solution (Python):
s = input()
s = s[::-1]
wards = ["maerd","remaerd","esare","resare"]
can = True
while can:
    can = False
    for i in wards:
        if s.startswith(i):
            s = s.replace(i,"",1)
            can = True
if s == "":
    print("YES")
else:
    print("NO")

Solution (Python):
S=input()
datas=["dream","dreamer","erase","eraser"]
stack=[]
stack.append(0)
while stack:
  index=stack.pop()
  if index==len(S):
    print("YES")
    break
  for data in datas:
    if index+len(data)>len(S):
      continue
    if S[index:index+len(data)]==data:
      stack.append(index+len(data))
else:
  print("NO")

Solution (Python):
S = input()
S = S[::-1]
T = ''
U = ['maerd', 'remaerd', 'esare', 'resare']
while True:
    S1 = S[:5]
    S2 = S[:6]
    S3 = S[:7]
    if S1 == U[0] or S1 == U[2]:
        S = S[5:]
    elif S2 == U[3]:
        S = S[6:]
    elif S3 == U[1]:
        S = S[7:]
    else:
        print('NO')
        exit()
    if S == '':
        print('YES')
        exit()

Solution (Python):
S = input()
i = len(S)
while i > 0:
  if S[i-5:i] in ["dream", "erase"]:
    i -= 5
  elif S[i-6:i] == "eraser":
    i -= 6
  elif S[i-7:i] == "dreamer":
    i -= 7
  else:
    print("NO")
    exit()
print("YES")

Solution (Python):
S = input()
T = ''
count = len(S)
while True:
    if S[0:count].rfind('dream') == count-5 and count-5 != -1:
        T = 'dream' + T
        count = count - 5
    elif S[0:count].rfind('dreamer') == count-7 and count-7 != -1:
        T = 'dreamer' + T
        count = count - 7
    elif S[0:count].rfind('erase') == count-5 and count-5 != -1:
        T = 'erase' + T
        count = count - 5
    elif S[0:count].rfind('eraser') == count-6 and count-6 != -1:
        T = 'eraser' + T
        count = count - 6
    else:
        break
if S == T:
    print('YES')
else:
    print('NO')

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

Solution (Python):
s = str(input())[::-1]

while(len(s) >= 5):
    if s[:5] == 'maerd':
        s = s.replace('maerd', '', 1)
    elif s[:7] == 'remaerd':
        s = s.replace('remaerd', '', 1)
    elif s[:5] == 'esare':
        s = s.replace('esare', '', 1)
    elif s[:6] == 'resare':
        s = s.replace('resare', '', 1)
    else:
        print('NO')
        exit()

else:
    print('YES')

Solution (Python):
S = input()[::-1]
while len(S) != 0:
    if S[:5] == "maerd":
        S = S.replace("maerd", "", 1)
    elif S[:5] == "esare":
        S = S.replace("esare", "", 1)
    elif S[:7] == "remaerd":
        S = S.replace("remaerd", "", 1)
    elif S[:6] == "resare":
        S = S.replace("resare", "", 1)
    else:
        print("NO")
        break
else:
    print("YES")

Solution (Python):
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if len(s)== 0:
    print("YES")
else:
    print("NO")

Solution (Python):
s=input()
rev_s = list(reversed(s))
temp=''
for i in rev_s:
    if(temp==''):
        temp=i
    else:
        temp+=i
    if(temp=='maerd' or temp=='remaerd' or temp=='esare' or temp=='resare'):
        temp=''
if(temp==''):
    print('YES')
else:
    print('NO')

Solution (Python):
s = input()
while len(s) != 0:
    if s[:5] == "dream":
        
        if s[5:7] == "er":
            
            if s[5:10] == "erase":
                s = s[5:]
            
            else:
                s = s[7:]
        else:
            s = s[5:]
    elif (s[:5] == "erase")&(s[:6] != "eraser"):
        s = s[5:]
    elif s[:6] == "eraser":
        s = s[6:]
    else:
        print("NO")
        exit()
print("YES")

Solution (Python):
S = input()

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

find_flag = 0
rest_S = S
while True:

    if len(rest_S) == 0:
        find_flag = 1
        break
    elif (len(rest_S) >= 7) & (rest_S[-7:] in candidates):
        rest_S = rest_S[:-7]
    elif (len(rest_S) >= 6) & (rest_S[-6:] in candidates):
        rest_S = rest_S[:-6]
    elif (len(rest_S) >= 5) & (rest_S[-5:] in candidates):
        rest_S = rest_S[:-5]
    else:
        break

if find_flag:
    print("YES")
else:
    print("NO")

Solution (Python):
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')

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

Solution (Python):
S = input()
while True:
    if S[-5:] == 'dream':
        S = S[:-5]
        continue
    elif S[-7:] == 'dreamer':
        S = S[:-7]
        continue
    elif S[-5:] == 'erase':
        S = S[:-5]
        continue
    elif S[-6:] == 'eraser':
        S = S[:-6]
        continue
    break

print('YES' if not S else 'NO')

Solution (Python):
s = input()

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

while True:
    flag = False
    for _e in e:
        if s[-len(_e):] == _e or s == _e:
            s = s[:len(s)-len(_e)]
            flag = True
    else:
        if flag:
            continue

        break

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

Solution (Python):
S=input()
Word=['eraser','erase','dreamer','dream']

while True:
    S_len=len(S)
    if S_len<5:
        break
    else:
        for i in Word:
            S = S.replace(i,"")
        if len(S)==S_len: 
            break
           
if len(S)==0:
    print('YES')
else:
    print('NO')

Solution (Python):
S = input()[::-1]
 
T = ['dream'[::-1],'dreamer'[::-1],'erase'[::-1],'eraser'[::-1]]
size = 0

while size < len(S):
	if S[size:size+5] == T[0] or S[size:size+5] == T[2]:
		size += 5
	elif S[size:size+6] == T[3]:
		size += 6
	elif S[size:size+7] == T[1]:
		size += 7
	else :
		print('NO')
		exit()
print('YES')

Solution (Python):
S = input()
cursor = len(S)

while cursor:
    if S[cursor - 5: cursor] in ['dream', 'erase']:
        cursor -= 5
        continue
    elif S[cursor - 6: cursor] in ['eraser']:
        cursor -= 6
        continue
    elif S[cursor - 7: cursor] in ['dreamer']:
        cursor -= 7
    else:
        break

if cursor == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
strings = ['dream', 'dreamer', 'erase', 'eraser']

reverse_candidates = [s[::-1] for s in strings]

S = str(input())[::-1]

pointa = 0
while pointa != len(S):
    if S[pointa:pointa+5] in ('maerd', 'esare'):
        pointa += 5
    elif S[pointa:pointa+6] in ('resare'):
        pointa += 6
    elif S[pointa:pointa+7] in ('remaerd'):
        pointa += 7
    else:
        print('NO')
        exit()

print('YES')

Solution (Python):
s = input()

ans = 1
while(len(s)>0):
    if s[-5:] == "dream" or s[-5:] == "erase":
        s = s[:-5]
    elif s[-7:] == "dreamer":
        s = s[:-7]
    elif  s[-6:] == "eraser":
        s = s[:-6]
    else:
        s = ""
        ans = 0
if ans > 0:
    print("YES")
else:    
    print("NO")

Solution (Python):
S = str(input())
pntr = 0
flg = 1


while pntr <= len(S) - 1:
	if S[pntr] == "d":
		if pntr + 7 <= len(S) - 1 and S[pntr + 7] == "a":
			if S[pntr : pntr + 5] == "dream":
				pntr += 5
			else:
				flg = 0
				break
		elif pntr + 6 <= len(S) - 1 and S[pntr : pntr + 7] == "dreamer":
			pntr += 7
		elif pntr + 4 <= len(S) - 1 and S[pntr : pntr + 5] == "dream":
			pntr += 5
		else:
			flg = 0
			break
			
	elif S[pntr] == "e":
		if pntr + 5 <= len(S) - 1 and S[pntr : pntr + 6] == "eraser":
			pntr += 6
			
		elif pntr + 4 <= len(S) - 1 and S[pntr : pntr + 5] == "erase":
			pntr += 5
			
		else:
			flg = 0
			break
	else:
		flg = 0
		break
		
if flg:
	print("YES")
else:
	print("NO")

Solution (Python):

def check(s):
    words = [
            'dream',
            'dreamer',
            'erase',
            'eraser',
            ]

    while len(s) != 0:
        flag = False
        for w in words:
            if s[-len(w):] == w:
                s = s[:-len(w)]
                flag = True
                break
        if not flag:
            return 'NO'
    return 'YES'


print(check(input()))

Solution (Python):

def check(s):
    words = [
            'dream',
            'dreamer',
            'erase',
            'eraser',
            ]

    while len(s) != 0:
        flag = False
        for w in words:
            if s[-len(w):] == w:
                s = s[:-len(w)]
                flag = True
                break
        if not flag:
            return 'NO'
    return 'YES'


print(check(input()))

Solution (Python):
def check(s):
    s = s.replace('eraser', '')
    s = s.replace('erase', '')
    s = s.replace('dreamer', '')
    s = s.replace('dream', '')
    if len(s) != 0:
        return 'NO'
    return 'YES'


print(check(input()))

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

Solution (Python):
S = input()[::-1]

words = ("dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1])

index = 0

while True:
    flag = False
    for word in words:
        if S[index:index + len(word)] == word:
            index += len(word)
            flag = True

    if index == len(S):
        print("YES")
        exit()

    if flag is False:
        break

print("NO")

Solution (Python):
S = input()

s_i = 0
flag = True
while s_i < len(S) and flag:
    
    if S[s_i:s_i+7] == 'dreamer' and S[s_i:s_i+10]  != 'dreamerase':
        s_i += 7
    elif S[s_i:s_i+5] == 'dream':
        s_i += 5
    elif S[s_i:s_i+6] == 'eraser':
        s_i += 6
    elif S[s_i:s_i+5] == 'erase':
        s_i += 5
    else:
        flag = False
if flag:
    print('YES')
else:
    print('NO')

Solution (Python):
S = input()[::-1]
W = []
for w in ['dreamer', 'eraser', 'erase', 'dream']:
    W.append(w[::-1])
idx = 0
while 1:
    flg = False
    for w in W:
        if S.startswith(w, idx):
            idx += len(w)
            flg = True

    if not flg:
        print('NO')
        exit()
    if len(S) <= idx:
        break

print('YES')

Solution (Python):
S = input()[::-1]
W = []
for w in ['dreamer', 'eraser', 'erase', 'dream']:
    W.append(w[::-1])
while 1:
    flg = False
    for w in W:
        if S.startswith(w):
            S = S[len(w):]
            flg = True

    if not flg:
        print('NO')
        exit()
    if not S:
        break

print('YES')

Solution (Python):
def solve():
    S = input()
    

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

    i = 0
    while True:
        can = False
        for word in words:
            if S[i:i + len(word)] == word:
                i += len(word)
                can = True

        if i == len(S):
            return True

        if can is False:
            return False


if __name__ == '__main__':
    res = solve()
    if res:
        print("YES")
    else:
        print("NO")

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

def solve():
    S = input()
    

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

    def recur(i):
        if i >= len(S):
            return True

        for word in words:
            if S[i:i + len(word)] == word:
                if recur(i + len(word)):
                    return True
        return False

    ans = recur(0)

    return ans


if __name__ == '__main__':
    res = solve()
    if res:
        print("YES")
    else:
        print("NO")

Solution (Python):
def main():
    S = input()
    w1 = 'dream'[::-1]
    w2 = 'dreamer'[::-1]
    w3 = 'erase'[::-1]
    w4 = 'eraser'[::-1]
    S = S[::-1]
    words = [w1, w2, w3, w4]

    i = 0
    while i != len(S):
        for w in words:
            if S[i:].startswith(w):
                i += len(w)
                break
        else:
            print("NO")
            exit()

    print("YES")



if __name__ == "__main__":
    main()

Solution (Python):
def main():
    S = input()
    w1 = 'dream'[::-1]
    w2 = 'dreamer'[::-1]
    w3 = 'erase'[::-1]
    w4 = 'eraser'[::-1]
    S = S[::-1]
    words = [w1, w2, w3, w4]

    flag = False
    i = 0
    while i != len(S):
        for w in words:
            if S[i:].startswith(w):
                i += len(w)
                flag = True
                break

        if not flag:
            print("NO")
            exit()
        flag = False

    print("YES")



if __name__ == "__main__":
    main()

Solution (Python):
def main():
    S = input()
    w1 = 'dream'[::-1]
    w2 = 'dreamer'[::-1]
    w3 = 'erase'[::-1]
    w4 = 'eraser'[::-1]
    S = S[::-1]
    words = [w1, w2, w3, w4]

    flag = False
    i = 0
    while i < len(S):
        for w in words:
            if S[i:].startswith(w):
                i += len(w)
                flag = True
                break

        if not flag:
            print("NO")
            exit()
        flag = False

    print("YES")



if __name__ == "__main__":
    main()

Solution (Python):
S = input()
lenS = len(S)

i=0
while i < lenS:
  if S[i:i+5] =='dream':
    i+=5
    if S[i:i+2] == 'er' and S[i:i+5] != 'erase':i+=2
  elif S[i:i+6] == 'eraser': i+=6
  elif S[i:i+5] == 'erase': i+=5
  else:
    print('NO')
    exit()
print('YES')

Solution (Python):
def main():
    S = input()
    w1 = 'dream'[::-1]
    w2 = 'dreamer'[::-1]
    w3 = 'erase'[::-1]
    w4 = 'eraser'[::-1]
    
    S = S[::-1]
    

    
    words = [w1, w2, w3, w4]
    T = ''
    while S != T:
        cand = []
        for w in words:
            new_t = T + w
            cand.append(new_t) 
        
        ans = False
        for c in cand:
            if c == S[:len(c)]:
                T = c
                ans = True

        if not ans:
            break

    if S == T:
        print('YES')
    else:
        print("NO")

if __name__ == "__main__":
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)


def solve():
    S = input()
    

    words = {0: "dream", 1: "dreamer", 2: "erase", 3: "eraser"}

    TABLE = [[-1 for x in range(len(S) + 1)] for y in range(len(words) + 1)]

    def recur(i, w):
        if not TABLE[w][i] == -1:
            return TABLE[w][i]

        if i >= len(S):
            
            return True

        r1, r2, r3, r4 = False, False, False, False
        if S[i:i + 5] == words[0]:
            r1 = recur(i + 5, 0)
        if S[i:i + 7] == words[1]:
            r2 = recur(i + 7, 1)
        if S[i:i + 5] == words[2]:
            r3 = recur(i + 5, 2)
        if S[i:i + 6] == words[3]:
            r4 = recur(i + 6, 3)

        TABLE[w][i] = r1 or r2 or r3 or r4 or False

        return TABLE[w][i]

    ans = recur(0, 0)

    return ans


if __name__ == '__main__':
    res = solve()
    if res:
        print("YES")
    else:
        print("NO")

Solution (Python):

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

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

Solution (Python):
S = input()
words = ["dream", "dreamer", "erase", "eraser"]

id = len(S)
while(id > 0):
    if S[:id].endswith("dream"):
        id -= 5
    elif S[:id].endswith("dreamer"):
        id -= 7
    elif S[:id].endswith("erase"):
        id -= 5
    elif S[:id].endswith("eraser"):
        id -= 6
    else:
        print("NO")
        exit(0)
print("YES")

Solution (Python):
T = input()
S = ''
p,q,r,s = 'maerd','esare','remaerd','resare'
for i in range(len(T)):
    S += T[len(T)-i-1]
while len(S) >= 5:
    x = S[:5]
    y = S[:6]
    z = S[:7]
    if x == p or x == q:
        if len(S) > 5:
            S = S[5:]
        else:
            S = ''
    elif y == s:
        if len(S) > 6:
            S = S[6:]
        else:
            S = ''
    elif z == r:
        if len(S) > 7:
            S = S[7:]
        else:
            S = ''
    else:
        break
ans = 'NO'
if len(S) == 0:
    ans = 'YES'
print(ans)

Solution (Python):
s = input()
l = len(s)

"""
tryブロックでsys.exit()を呼ぶと強制終了しない。
"""
import sys
i = l-1
try:
    while i>-1:
        if s[i]=="r":
            if s[i-5:i+1]=="eraser":
                i-=6
            elif s[i-6:i+1]=="dreamer":
                i-=7
            else:
                print("NO")
                sys.exit()
        else:
            if s[i-4:i+1]=="erase":
                i-=5
            elif s[i-4:i+1]=="dream":
                i -= 5
            else:
                print("NO")
                sys.exit()
    print("YES")
except:
    pass

Solution (Python):
L=["dream","dreamer","erase","eraser"]
S=input()
t=""
a,b=0,0

while len(t)<len(S):
  if S[a:a+7]=="dreamer" and S[a+5:a+8]!="era":
    t=t+"dreamer"
    a=a+7
  elif S[a:a+6]=="eraser":
    t=t+"eraser"
    a=a+6
  elif S[a:a+5]=="dream":
    t=t+"dream"
    a=a+5
  elif S[a:a+5]=="erase":
    t=t+"erase"
    a=a+5
  else:
    print("NO")
    break

if len(t)==len(S):
  print("YES")

Solution (Python):
s=input()
s=s.replace("dream","D")
s=s.replace("erase","E")
s=s.replace("Der","M")
s=s.replace("Er","M")
s=s.replace("D","M")
s=s.replace("E","M")
s=s.replace("M","")
if s:
    print("NO")
else:
    print("YES")

Solution (Python):
import sys

s = input()
s = s[::-1]

d ='maerd'
dr = 'remaerd'
e = 'esare'
er = 'resare'

i = 0
while True:
    try:
        if s[i:i+5] == d or s[i:i+5] == e:
            i += 5
            if i == len(s):
                print('YES')
                sys.exit(0)
        
        elif s[i:i+6] == er:
            i += 6
            if i == len(s):
                print('YES')
                sys.exit(0)
        
        elif s[i:i+7] == dr:
            i += 7
            if i == len(s):
                print('YES')
                sys.exit(0)
            
        else:
            print('NO')
            sys.exit(0)
            
    except Exception as err:
        print('NO')
        sys.exit(0)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    S = read().decode('utf-8')
    S = list(S.replace('\n', ''))[::-1]
    T = [
            list('dream')[::-1],
            list('dreamer')[::-1],
            list('erase')[::-1],
            list('eraser')[::-1]
        ]

    while len(S) != 0:
        if S[0:5] == T[0] or S[0:5] == T[2]:
            del S[0:5]
        elif S[0:7] == T[1]:
            del S[0:7]
        elif S[0:6] == T[3]:
            del S[0:6]
        else:
            print('NO')
            sys.exit()

    print('YES')


main()

Solution (Python):

import sys
input = sys.stdin.readline


S = input().rstrip()
S = S[::-1]

words = ["dream","dreamer","erase","eraser"]
for i in range(4):
    words[i] = words[i][::-1]

i = 0
while i < len(S):
    for w in words:
        l = len(w)
        if w == S[i:i+l]:
            i += l
            break
    else:
        print("NO")
        sys.exit()

print("YES")

Solution (Python):
def rev (s):
    _re=''.join(list(reversed(s)))
    return _re

name = ['dream','dreamer','eraser','erase']
S = input()
S_re = rev(S)
i=0
can = True
while i < len(S_re):
    for div in name:
        can2 = False
        if len(S_re[i:]) >= len(div):
           if S_re[i:i+len(div)]==rev(div) :
                i+=len(div)
                can2 = True
                break
    if not can2 :
        can = False
        break


if can :
    print('YES')
else :
    print('NO')

Solution (Python):
s=input()[::-1]
words=["dreamer","eraser","dream","erase"]
add=0
while add!=len(s):
    cnt=0
    for i in words:
        length=len(i)
        word=s[add:add+length][::-1]
        if word==i:
            add +=length
            break
        else:cnt +=1
    if cnt==4:print("NO");exit()
print("YES")

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

Solution (Python):
def examC():
    St = S()
    t = ["dream", "dreamer", "erase", "eraser"]
    i = len(St)-1
    cur = ""
    while i>=0:

        cur = St[i] + cur
        i -=1
        if cur in t:
            cur = ""
    if len(cur)==0:
        ans = "YES"
    else:
        ans = "NO"
    print(ans)


import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Solution (Python):

T = ["dream", "dreamer", "erase", "eraser"]
S = input()

while len(S) >= 5:
    S_len = len(S)
    key1 = S[S_len-5:]
    key2 = S[S_len-6:]
    key3 = S[S_len-7:]

    if key1 == T[0] or key1 == T[2]:
        S = S[:S_len-5]
    elif key2 == T[3]:
        S = S[:S_len-6]
    elif key3 == T[1]:
        S = S[:S_len-7]
    else:
        break

if S == '':print("YES")
else:print("NO")

Solution (Python):
import sys

def main():
    S = list(input())
    S.reverse()
    words = ['resare', 'esare', 'remaerd', 'maerd']
    while len(S) > 0:
        deleted = False
        for word in words:
            if len(S) >= len(word) and ''.join(S[0:len(word)]) == word:
                del S[0:len(word)]
                deleted = True
        if deleted is False:
            print('NO')
            sys.exit()

    print('YES')

main()

Solution (Python):
s= input()
u= s[::-1]
 
k=["resare","esare","remaerd","maerd"]
 
l=u.replace("resare","")
d=l.replace("esare","")
h=d.replace("remaerd","")
w=h.replace("maerd","")
  
    
if w:
  print("NO")
  
else:
  print("YES")

Solution (Python):


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

if not s:
    print("YES")
elif s:
    print("NO")

Solution (Python):
s = list(input())
x = []
i = 0
while(len(x)<len(s)):
    if s[i] == 'd':
        x += ['d','r','e','a','m']
        i = min(i+5,len(s)-1)
        if s[i] == 'e':
            x += ['e','r']
            i += 2
    elif s[i] == 'e':
        x += ['e','r','a','s','e']
        i = min(i+5,len(s)-1)
        if s[i] == 'r':
            x += 'r'
            i += 1
    elif s[i] == 'a':
        x += ['a','s','e']
        i = min(i+3,len(s)-1)
        if s[i] == 'r':
            x += 'r'
            i += 1
    else:
        break
print('YES' if s == x else 'NO')

Solution (Python):
S=input()
f=True
while len(S)>0:
    if S.endswith('dream') or S.endswith('erase'):
        S=S[:-5]
    elif S.endswith('eraser'):
        S=S[:-6]
    elif S.endswith('dreamer'):
        S=S[:-7]
    else:
        f=False
        break
print('YES' if f else 'NO')

Solution (Python):
S = input()[::-1]
i = 0
flag = True
while i < len(S):
    if S[i:i+5] == "maerd":
        i += 5
    elif S[i:i+7] == "remaerd":
        i += 7
    elif S[i:i+5] == "esare":
        i += 5
    elif S[i:i+6] == "resare":
        i += 6
    else:
        flag = False
        break

print("YES" if flag else "NO")

Solution (Python):
print("YES" if len(input().replace("eraser", "").replace("erase", "").replace("dreamer", "").replace(
    "dream", "")) == 0 else "NO")

Solution (Python):
S = input()
while S:
    for x in ['dreamer', 'eraser', 'dream', 'erase']:
        if S.endswith(x):
            S = S[:-len(x)]
            break
    else:
        print('NO')
        exit()
print('YES')

Solution (Python):
if input().replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "") == "":
  print("YES")
else:
  print("NO")

Solution (Python):
s=input()
s=s.replace('eraser','z').replace('erase','z').replace('dreamer','z').replace('dream','z')
print('YES' if set(list(s))=={'z'} else 'NO')

Solution (Python):
A = str(input())
s_len = len(A)
A = A.replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')
if len(A) == 0:
  print('YES')
else:
  print('NO')

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

Solution (Python):
S = input()
rev_S = list(reversed(S))


while len(rev_S) >= 5:
    if rev_S[0] == "m" and rev_S[0:5] == ['m', 'a', 'e', 'r', 'd']:
        del rev_S[:5]
    elif rev_S[0] == "e" and rev_S[0:5] == ['e', 's', 'a', 'r', 'e']:
        del rev_S[:5]
    elif rev_S[0] == "r" and rev_S[0:7] == ['r', 'e', 'm', 'a', 'e','r', 'd']:    
        del rev_S[:7]
    elif rev_S[0] == "r" and rev_S[0:6] == ['r', 'e', 's', 'a','r', 'e']:    
        del rev_S[:6]
    else:
        break
if len(rev_S) == 0:
    print("YES")
else:
    print("NO")

Solution (Python):
s = input()

i = 0
while i < len(s):
    if s[i:i+11] == 'dreameraser':
        i += 11
    elif s[i:i+10] == 'dreamerase':
        i += 10        
    elif s[i:i+7] == 'dreamer':
        i += 7
    elif s[i:i+6] == 'eraser':
        i += 6
    elif s[i:i+5] == 'dream' or s[i:i+5] == 'erase':
        i += 5
    else:
        print('NO')
        exit()

print('YES')

Solution (Python):
S = input()
divide = ["dream", "dreamer", "erase", "eraser"]
S = S[::-1]
divide = [divide[i][::-1] for i in range(4)]
 
while len(S) > 0:
    for i in range(4):
        if S[:len(divide[i])] == divide[i]:
            flag = "YES"
            S = S[len(divide[i]):]
            break
        else:
            flag = "NO"
    if flag == "NO":
        break

print(flag)

Solution (Python):
a=input()
l=["dreamer","eraser","dream","erase"]
for i in range(len(a)//5):
    for i in l:
        if a[-7:]==i:
            a=a[:-7]
        elif a[-6:]==i:
            a=a[:-6]
        elif a[-5:]==i:
            a=a[:-5]
        else:
            pass
if len(a)==0: 
    print("YES")
else:
    print("NO")

Solution (Python):
S=list(reversed(input()))
N=len(S)
i=0
while i<N:
  if N-i<=4:
    print("NO")
    exit()
    
  elif N-i<=5:
    if S[i]=="m" and S[i+1]=="a" and S[i+2]=="e" and S[i+3]=="r" and S[i+4]=="d":
      i+=5
    elif S[i]=="e" and S[i+1]=="s" and S[i+2]=="a" and S[i+3]=="r" and S[i+4]=="e":
      i+=5
    else:
      print("NO")
      exit()
  
  elif N-i<=6:
    if S[i]=="m" and S[i+1]=="a" and S[i+2]=="e" and S[i+3]=="r" and S[i+4]=="d":
      i+=5
    elif S[i]=="e" and S[i+1]=="s" and S[i+2]=="a" and S[i+3]=="r" and S[i+4]=="e":
      i+=5
    elif S[i]=="r" and S[i+1]=="e" and S[i+2]=="s" and S[i+3]=="a" and S[i+4]=="r" and S[i+5]=="e":
      i+=6
    else:
      print("NO")
      exit()
      
  else:
    if S[i]=="m" and S[i+1]=="a" and S[i+2]=="e" and S[i+3]=="r" and S[i+4]=="d":
      i+=5
    elif S[i]=="e" and S[i+1]=="s" and S[i+2]=="a" and S[i+3]=="r" and S[i+4]=="e":
      i+=5
    elif S[i]=="r" and S[i+1]=="e" and S[i+2]=="s" and S[i+3]=="a" and S[i+4]=="r" and S[i+5]=="e":
      i+=6
    elif S[i]=="r" and S[i+1]=="e" and S[i+2]=="m" and S[i+3]=="a" and S[i+4]=="e" and S[i+5]=="r" and S[i+6]=="d":
      i+=7
    else:
      print("NO")
      exit()
  
    
print("YES")

Solution (Python):
s = str(input())
l = ['eraser', 'erase', 'dreamer', 'dream']

for i in l:
  s = s.replace(i,'')

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

Solution (Python):
s = input()

flag = 0
while(1):
  if len(s) == 0:
    flag = 1
    break
  elif s[-7:] == "dreamer":
    s = s[0:-7]
  elif s[-6:] == "eraser":
    s = s[0:-6]
  elif s[-5:] == "dream":
    s = s[0:-5]
  elif s[-5:] == "erase":
    s = s[0:-5]
  else:
    break

if flag == 1:
  print("YES")
else:
  print("NO")

Solution (Python):
import sys


		
def main():
	s = input()
	ww=['dream','dreamer','erase','eraser']
	
	s=s[::-1]
	wwr=[w[::-1] for w in ww]
	
	while len(s)>0:
		
		is_ok=False
		for w in wwr:
			ll=len(w)
			ss=s[:ll]
			
			if ss == w:
				is_ok=True
				
				s=s[ll:]
		if not is_ok:
			print('NO')
			return 
		
	print('YES')
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
import re
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$",input()) else "NO")