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):
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()

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

Solution (Python):

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

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

Solution (Python):
import re

s = input()
if re.match("(dream|dreamer|erase|eraser)*$", 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):


def main():
    S = input()

    while len(S) >= 5:
        if len(S) >= 7 and S[-7:] == "dreamer":
            S = S[:-7]
            continue

        if len(S) >= 6 and S[-6:] == "eraser":
            S = S[:-6]
            continue

        elif S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue

        else:
            break

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

main()

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

Solution (Python):
s=list(input())
booler=True
while s!=[] and booler==True:
  if s[-5]=="d" and s[-4]=="r" and s[-3]=="e" and s[-2]=="a" and s[-1]=="m":
    for i in range(5):
      del s[-1]
  elif s[-5]=="e" and s[-4]=="r" and s[-3]=="a" and s[-2]=="s" and s[-1]=="e":
    for i in range(5):
      del s[-1]
  elif s[-6]=="e" and s[-5]=="r" and s[-4]=="a" and s[-3]=="s" and s[-2]=="e" and s[-1]=="r":
    for i in range(6):
      del s[-1]
  elif s[-7]=="d" and s[-6]=="r" and s[-5]=="e" and s[-4]=="a" and s[-3]=="m" and s[-2]=="e" and s[-1]=="r":
    for i in range(7):
      del s[-1]
  else:
    booler=False
if booler:
  print("YES")
else:
  print("NO")

Solution (Python):
s = input()
ans = "YES"
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:
    ans = "NO"
    break
print(ans)

Solution (Python):
def main():
	S = input()
	pattern_exist = True
	while S:
		if S.startswith("dreamer"):
			if len(S) == 7:
				break
			if S[7:].startswith("dream") or S[7:].startswith("erase"):
				S = S[7:]
				continue
		if S.startswith("dream"):
			S = S[5:]
			continue
		if S.startswith("eraser"):
			if len(S) == 6:
				break
			if S[6:].startswith("dream") or S[6:].startswith("erase"):
				S = S[6:]
				continue
		if S.startswith("erase"):
			S = S[5:]
			continue
		pattern_exist = False
		break
	if pattern_exist:
		print("YES")
	else:
		print("NO")


if __name__ == '__main__':
	main()

Solution (Python):
s = input()
ans = "YES"
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:
        ans = "NO"
        break
print(ans)

Solution (Python):
S = input().replace('eraser', '').replace('erase', '')
chk = S.replace('dreamer', '').replace('dream', '')
print(['YES', 'NO'][len(chk) > 0])

Solution (Python):
S = input()
SS = S
T = ""
while(1):
    if T == SS:
        print("YES")
        break
    if S[len(S)-5:len(S)] == "dream":    
        T = "dream" + T
        S = S[0:len(S)-5]
    elif S[len(S)-7:len(S)] == "dreamer":
        T = "dreamer" + T
        S = S[0:len(S)-7]
    elif S[len(S)-5:len(S)] == "erase":
        T = "erase" + T
        S = S[0:len(S)-5]
    elif S[len(S)-6:len(S)] == "eraser":
        T = "eraser" + T
        S = S[0:len(S)-6]
    else:
        print("NO")
        break

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

Solution (Python):
def check(s: str):
  if len(s) >= 5 and s[-5:] in ['dream', 'erase']:
    return s[:-5]
  elif len(s) >= 6 and s[-6:] in ['eraser']:
    return s[:-6]
  elif len(s) >= 7 and s[-7:] in ['dreamer']:
    return s[:-7]
  return None

s = input()
matched = True
while len(s) > 0:
  s = check(s)
  if s is None:
    matched = False
    break
if matched:
  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()

from collections import deque

q = deque()
if len(S) > 5: 
  q.append((len(S), S))



flag = False
while(q):
  nowlen, nows = q.popleft()
  nows5 = nows[0:5]
  nowsfrom5 = nows[5:]
  if nows5 == 'dream':
    if nowlen == 5:
      flag = True
      break
    else:
      if nowlen>=10: q.append((nowlen-5, nowsfrom5))
    if nows[0:7] == 'dreamer':
      if nowlen == 7:
        flag = True
        break
      else:
        if nowlen>=12: q.append((nowlen-7, nows[7:]))
  elif nows5 == 'erase':
    if nowlen == 5:
        flag = True
        break
    else:
      if nowlen>=10: q.append((nowlen-5, nowsfrom5))
    if nows[0:6] == 'eraser':
      if nowlen == 6:
        flag = True
        break
      else: 
        if nowlen>=11: q.append((nowlen-6, nows[6:]))

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

Solution (Python):

import re

if __name__ == "__main__":
    patterns = ["dream", "dreamer", "erase" ,"eraser"]
    S = input()

    while True:
        flag = False
        if S[-5:] == "dream":
            S = S[:-5]
            flag = True
        if S[-7:] == "dreamer":
            S = S[:-7]
            flag = True
        if S[-5:] == "erase":
            S = S[:-5]
            flag = True
        if S[-6:] == "eraser":
            S = S[:-6]
            flag = True

        if flag == False:
            print("NO")
            break

        if S == "":
            print("YES")
            break

Solution (Python):
def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    i = 0
    while 1:
        temp = []
        bool = True
        for t in T:
            if S[:len(t)] == t:
                S = S[len(t):]
                bool = False
        if bool:
            break
    if len(S) > 0:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    i = 0
    while 1:
        temp = []
        bool = True
        for t in T:
            if S[i:len(t) + i] == t:
                i += len(t)
                bool = False
        if bool:
            break
    if len(S) != i:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()

Solution (Python):


def read_input():
    s = input().strip()
    return s

def submit():
    s = read_input()
    rev_s = s[::-1]

    targets = ['dream', 'dreamer', 'erase', 'eraser']
    rev_targets = [t[::-1] for t in targets]

    while True:
        if not rev_s:
            print('YES')
            return

        for t in rev_targets:
            if rev_s.startswith(t):
                rev_s = rev_s[len(t):]
                break
        else:
            print('NO')
            return

if __name__ == '__main__':
    submit()

Solution (Python):
s=input()

while True:
    if s.endswith('dream'):
        s = s[:-5]
    elif s.endswith('dreamer'):
        s = s[:-7]
    elif s.endswith('eraser'):
        s = s[:-6]
    elif s.endswith('erase'):
        s = s[:-5]
    else:
      print("NO")
      quit()
    if s=="":
      break
print("YES")

Solution (Python):
S = input()
N = len(S)
words = ['dream', 'dreamer', 'erase', 'eraser']
while True:
    flag = False
    for i in words:
        n = len(i)
        if S[N-n:N] == i:
            flag = True
            N -= n
            break
    if not flag:
        ans = 'NO'
        break
    if N == 0:
        ans = 'YES'
        break

print(ans)

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

Solution (Python):
S = str(input())[::-1]
d1 = 'dream'[::-1]
d2 = 'dreamer'[::-1]
d3 =  'erase'[::-1]
d4 =  'eraser'[::-1]

result = True
i = 0
while i < len(S):
  if S[i:i+5] == d1:
    i += 5
  elif S[i:i+7] == d2:
    i += 7
  elif S[i:i+5] == d3:
    i += 5
  elif S[i:i+6] == d4:
    i += 6
  else:
    result = False
    break

if result:
  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()

ct_1 = S.count('dream')
ct_2 = S.count('erase')
ct_3 = S.count('dreamerase')
ct_4 = S.count('dreamer')
ct_5 = S.count('eraser')
ct_dream = ct_1 - ct_4 + ct_3
ct_erase = ct_2 - ct_5
ct_dreamer = ct_4 - ct_3
ct_eraser = ct_5

length = 5*(ct_dream+ct_erase) + 6*(ct_eraser) + 7*(ct_dreamer)

if length == len(S):
    print('YES')
else:
    print('NO')

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

Solution (Python):
s = input()
s = s[::-1]
li = ['maerd', 'remaerd', 'esare', 'resare']
t = ''

for i in range(len(s)):
  t = t + s[i]
  for c in li:
    if t == c:
      t = ''

if t == '':
  print('YES')
else:
  print('NO')

Solution (Python):
import re

S = input()
T = []

a = re.split('eraser', S)
a1 = ''.join(a)
a2 = re.split('erase', a1)
a3 = ''.join(a2)
a4 = re.split('dreamer|dream', a3)
a5 = ''.join(a4)

if(a5 == ''):
    print('YES')
else:
    print('NO')

Solution (Python):
s = input()
while(1):
    if s.endswith('dream'):
        s = s[:-5]
    elif s.endswith('dreamer'):
        s = s[:-7]
    elif s.endswith('eraser'):
        s = s[:-6]
    elif s.endswith('erase'):
        s = s[:-5]
    else:
        print("NO")
        quit()
    if s == '':
        break
print("YES")

Solution (Python):
import re;print(re.match('(dreame*|erase|r)*$',input())and'YES'or'NO')

Solution (Python):
import re;print(re.match('(dreame*|erase|r)*$',input())and'YES'or'NO')

Solution (Python):
import re;print(re.match('(dream|dreamer|erase|eraser)*$',input())and'YES'or'NO')

Solution (Python):
import re;print(re.match('^(dream|dreamer|erase|eraser)*$',input())and'YES'or'NO')

Solution (Python):
import sys

def main():
    S = input()

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

if __name__ == '__main__':
    main()

Solution (Python):
s = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')

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

Solution (Python):
S = input()
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):
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s:
    print("NO")
else:
    print("YES")

Solution (Python):
s = input()[::-1]
l = ['dream'[::-1],'dreamer'[::-1],'erase'[::-1],'eraser'[::-1]]
k = 0
while k<len(s):
    flag = 1
    for w in l:
        if s[k:k+len(w)]==w:
            k+=len(w)
            flag = 0
    if flag:
        print('NO')
        exit()
print('YES')

Solution (Python):

s = input()
d = ["dream","dreamer","erase","eraser"]

while s:
    if s[-5:] == d[0] or s[-5:] == d[2]:
        s = s[0:-5]
    elif s[-6:] == d[3]:
        s = s[0:-6]
    elif s[-7:] == d[1]:
        s = s[0:-7]
    else:
        break

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

Solution (Python):
s=input()
ans=1
i=0
while 1:
  if i>=len(s):
    break
  if s[i:i+5]=="dream":
    i+=5
  elif s[i:i+5]=="erase":
    if s[i:i+6]=="eraser":
      i+=6
    else:
      i+=5
  elif s[i-5:i+2]=="dreamer":
    i+=2
  else:
    ans=0
    break
if ans:
  print("YES")
else:
  print("NO")

Solution (Python):
import sys
s = input()
while len(s)>7:
    if s[:6]=="dreamd":
        s = s.replace("dream","",1)
        continue
    if s[:6]=="erased":
        s = s.replace("erase","",1)
        continue
    if s[:6]=="eraser":
        s = s.replace("eraser","",1)
        continue
    if s[:6]=="erasee":
        s = s.replace("erase","",1)
        continue
    if s[:8]=="dreamerd":
        s = s.replace("dreamer","",1)
        continue
    if s[:8]=="dreamera":
        s = s.replace("dream","",1)
        continue
    if s[:8]=="dreamere":
        s = s.replace("dreamer","",1)
        continue
    break
if s in ["dream","dreamer","erase","eraser"]:
    print("YES")
else:
    print("NO")

Solution (Python):
S = input()
string = ['dream', 'dreamer', 'erase', 'eraser']
string = [i[::-1] for i in string]
S = S[::-1]
i = 0
while i < len(S):
    can = False
    for word in string:
        d = S[i:i+len(word)]
        if word == d:
            can = True
            i += len(word)
            break
    else:
        break

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

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

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

Solution (Python):


s = input()
s=s[::-1] 
words = ["maerd", "remaerd", "esare", "resare"]
while len(s) > 4:
    if s[:5] == words[0]:
        s = s[5:]
        continue
    elif s[:7] == words[1]:
        s = s[7:]
        continue
    elif s[:5] == words[2]:
        s = s[5:]
        continue
    elif s[:6] == words[3]:
        s = s[6:]
        continue
    else:
        break
if len(s) > 0:
    print('NO')
else:
    print('YES')

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

Solution (Python):
S = input()

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

Solution (Python):
S = input()
lst_str = ["maerd", "remaerd", "esare", "resare"]
char = ""

for c in S[::-1]:
    char += c
    if char in lst_str:
        char = ""
if char:
    print("NO")
else:
    print("YES")

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

r=0
while r < len(s):
    if s[r:r+3] == "mae":
        if s[r:r+5] == "maerd":
            r += 5
        else:
            print("NO")
            exit()
    elif s[r:r+3] == "rem":
        if s[r:r+7] == "remaerd":
            r += 7
        else:
            print("NO")
            exit()
    elif s[r:r+3] == "esa":
        if s[r:r+5] == "esare":
            r += 5
        else:
            print("NO")
            exit()
    elif s[r:r+3] == "res":
        if s[r:r+6] == "resare":
            r += 6
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()

print("YES")

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

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

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().split()[0]
word_list = ['dream', 'dreamer', 'erase', 'eraser']


work_s = s
kumiawase = []

def check_end(text: str, k_word_list):
    ok_word = []
    for word in k_word_list:
        if text.endswith(word):
            ok_word.append(word)
    return ok_word

answer = 'NO'

while work_s:
    ok_word = check_end(work_s, word_list)
    if not ok_word:
        break

    
    for next_word in ok_word:
        work_s = work_s[:-len(next_word)]
else:
    answer = 'YES'

print(answer)

Solution (Python):
s = input()
  
while len(s) > 4:
  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
  else:
    break
    
if s:
  print("NO")
else:
  print("YES")

Solution (Python):
import sys
from collections import deque

def main():
    input = sys.stdin.readline
    S = str(input().strip())
    stock = ['dream', 'dreamer', 'erase', 'eraser']

    q = deque()
    q.append(S)
    while len(q) > 0:
        s = q.popleft()
        if len(s) == 0:
            return 'YES'

        if s[:5] in stock:
            q.append(s[5:])
        if s[:6] in stock:
            q.append(s[6:])
        if s[:7] in stock:
            q.append(s[7:])

    return 'NO'


if __name__ == '__main__':
    print(main())

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

Solution (Python):
s=input()
while 1:
    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:break
print(["NO","YES"][s==""])

Solution (Python):

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

"""

s = input()
list = ['dream', 'dreamer', 'erase', 'eraser']


for j in range(22):
    for i in range(len(list)):




        if s[-5:] == list[i]:
            s = s.rstrip(list[i])
            if s == "":
                print("YES")
                exit()
        elif s[-7:] == list[i]:
            s = s.rstrip(list[i])

            if s == "":
                print("YES")
                exit()
        else:
            pass
if s:
    print("NO")
"""

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

Solution (Python):
S = input()

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

Solution (Python):
S = input()

A = "dream"
B = "dreamer"
C = "erase"
D = "eraser"


def ABCD(moziretu):
    bool = False
    x = 0
    if moziretu[-5:] == "dream":
        bool = True
        x = 5
    elif moziretu[-7:] == "dreamer":
        bool = True
        x = 7
    elif moziretu[-5:] == "erase":
        bool = True
        x = 5
    elif moziretu[-6:] == "eraser":
        bool = True
        x = 6
    return [bool,x]

while ABCD(S)[0]:
    x = ABCD(S)[1]
    S = S[:-x]

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

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

while bool:
  if len(S) == 0:
    break
 
  bool = False
  for n in N:
    
    if S.endswith(n):
      L = S.rsplit(n,1)
      S = L[0]
      bool = True
      break
  

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

Solution (Python):
s = input()
s_rev = s[::-1]
while s_rev[0:1]:
    if s_rev.startswith("maerd"):
        s_rev = s_rev[5::1]
    elif s_rev.startswith("remaerd"):
        s_rev = s_rev[7::1]
    elif s_rev.startswith("esare"):
        s_rev = s_rev[5::1]
    elif s_rev.startswith("resare"):
        s_rev = s_rev[6::1]
    else:
        print("NO")
        break
if bool(s_rev[0:1]) == False:
    print("YES")

Solution (Python):


S = input()
A = 'dream'
B = 'dreamer'
C = 'erase'
D = 'eraser'

S=S[::-1]
A=A[::-1]
B=B[::-1]
C=C[::-1]
D=D[::-1]

tmp =""
for i in S:
    tmp +=i
    for j in [A,B,C,D]:
        if tmp == j:
            S=S.replace(tmp,"",1)
            tmp=""
if len(S)==0:
    print('YES')
else:
    print('NO')

Solution (Python):
s=str(input())
flag=True
while len(s)>0 :
  if s[-7:] == 'dreamer':
    s=s[:-7]
    continue
  elif s[-6:] == 'eraser':
    s=s[:-6]
    continue
  elif s[-5:] == 'dream':
    s=s[:-5]
    continue
  elif s[-5:] == 'erase':
    s=s[:-5]
    continue
  else:
    flag=False
    break
if flag:
  print('YES')
else:
  print('NO')

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

Solution (Python):
s = input()
while s:
    flg = 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:
        print('NO')
        exit()
print('YES')

Solution (Python):
print("YES") if input().replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "") == "" 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()
T = ''
i = 0

while len(T) < len(S):
    if S[i:i+6] == 'eraser':
        T += 'eraser'
        i += 6
    elif S[i:i+5] == 'erase':
        T += 'erase'
        i += 5
    elif S[i:i+5] == 'dream':
        if S[i+5:i+6] == 'd':
            T += 'dream'
            i += 5
        elif S[i+5:i+8] == 'era':
            T += 'dream'
            i += 5
        elif S[i+5:i+6] == '':
            T += 'dream'
            i += 5
        elif S[i+5:i+8] == 'ere':
            T += 'dreamer'
            i += 7
        elif S[i+5:i+8] == 'erd':
            T += 'dreamer'
            i += 7
        elif S[i+5:i+8] == 'er':
            T += 'dreamer'
            i += 7
        else:
            T += 'dream'
            i += 5
    else:
        print('NO')
        exit()

print('YES')

Solution (Python):
s=input()
for _ in range(20000):
    s=s.replace("eraser"," ").replace("erase"," ").replace("dreamer"," ").replace("dream"," ")
if s.rstrip():print("NO")
else:print("YES")

Solution (Python):

import re, sys

s = input()

regex = re.compile(r'^(dream|dreamer|erase|eraser)+$')

result = 'YES' if re.search(regex, s) else 'NO'
print(result)

Solution (Python):
S = input()[::-1]
div = ["maerd", "remaerd", "esare", "resare"]

flag1 = True
i = 0
while i < len(S):
    flag2 = False
    for d in div:
        if S[i:i + len(d)] == d:
            flag2 = True
            i += len(d)
            break

    if not flag2:
        flag1 = False
        break

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

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
a = ["dream", "dreamer", "erase", "eraser"]
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

t = input().strip()
t = t[::-1]

def solve():
    s = ""
    for i in range(len(a)):
        a[i] = a[i][::-1]


    end = 0
    lent = len(t)
    while(len(s)<len(t)):
        ok = False
        for i in a:
            if len(s) + len(i) <= lent and i == t[len(s): len(s) + len(i)]:
                s += i
                ok = True

        if ok == False:
            print("NO")
            return
    
    print("YES")

solve()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()
S = S[::-1]
word = ["dream", "dreamer", "erase", "eraser"]
flag = 0
tmp = ""
while 1:
	if tmp == S:
		print("NO")
		break
	tmp = S
	for w in word:
			
			
			if len(S) <= 4:
				print("NO")
				flag = 1
			elif S[:5] == w[::-1]:
				if len(S) == 5:
					print("YES")
					flag = 1
					break
				else:
					S = S[5:]
			elif S[:6] == w[::-1]:
				if len(S) == 6:
					print("YES")
					flag = 1
					break
				else:
					S = S[6:]
			elif S[:7] == w[::-1]:
				if len(S) == 7:
					print("YES")
					flag = 1
					break
				else:
					S = S[7:]
	if flag == 1:
		break

Solution (Python):
S = input().rstrip()
S = S[::-1]
daydream = ['maerd', 'remaerd', 'esare', 'resare']
nextIndex = 0
flg = True
for i in range(10**5//5):
    if nextIndex == len(S):
        break
    for j in daydream:
        if j == S[nextIndex: nextIndex+len(j)]:
            nextIndex += len(j)
            flg = True
            break
        flg = False
    if flg == False:
        break
print("YES" if flg else "NO")

Solution (Python):
S = input()
s_list = ["dream", "dreamer", "erase", "eraser"]
S_r = S[::-1]
i_n=0
for i, j in enumerate(s_list):
    s_list[i] = j[::-1]
while i_n < len(S):
    f_can = False
    for j in s_list:
        if S_r[i_n:i_n+len(j)] == j:
            f_can = True
            i_n+=len(j)
        else:
            False
    if f_can == False:
        break
        
if f_can == False:
    print("NO")
else:
    print("YES")

Solution (Python):

S=str(input())
Slist=list(S)
Slen=len(Slist)
Srev=Slist[::-1]
kari=""
for i in range(Slen):
    if len(kari) == 5:
        if kari == "maerd":
            kari=Srev[i]
        elif kari == "esare":
            kari=Srev[i]
        else:
            kari+=Srev[i]
    elif len(kari) == 6:
        if kari == "resare":
            kari=Srev[i]
        else:
            kari+=Srev[i]
    elif len(kari) == 7:
        if kari == "remaerd":
            kari=Srev[i]
        else:
            break
    else:
        kari+=Srev[i]
if kari == "esare" or kari == "maerd" or kari == "resare" or kari == "remaerd":
    print("YES")
else:
    print("NO")

Solution (Python):
S = input()
flg = True
while flg:
    if S == "":
        flg = False
        print("YES")
    elif 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:
        flg = False
        print("NO")

Solution (Python):
S = input()

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

Solution (Python):
s = input()
words_r = ['eraser', 'erase', 'dreamer', 'dream']
for word_r in words_r:
    s = s.replace(word_r, '')
    
    
    
    
if (len(s) > 0):
    print('NO')
else:
    print('YES')

Solution (Python):
S = list(input())
N = len(S)

for i in range(10):
  S.append('')

judge = 1
s1,s2,prev_s1 = '','',''
i = 0
while(1):
 s1 = S[i]+S[i+1]+S[i+2]+S[i+3]+S[i+4]
 s2 = S[i]+S[i+1]
 s2_ = list(s2)
 if(s1 == ''):
  break
 if((s1 == 'erase')or(s1 == 'dream')): 
  i += 5
 elif(s2 == 'er'):
  if(prev_s1 == 'dream'):
    i += 2
  else: 
    judge = 0
    break
 elif(s2_[0] == 'r'):
  if(prev_s1 == 'erase'):
    i += 1
  else: 
    judge = 0
    break
 else:
    judge = 0
    break
 prev_s1 = s1

if(judge == 1):
  print('YES')
else:
  print('NO')

Solution (Python):
s = input()[::-1]
words_r = ['eraser'[::-1], 'erase'[::-1], 'dreamer'[::-1], 'dream'[::-1]]
for word_r in words_r:
    s = s.replace(word_r, '')

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

Solution (Python):
import re
s = (re.sub("eraser|erase", "", str(input())))
s = (re.sub("dreamer|dream", "", s))
print("YES") if  s == "" else print("NO")

Solution (Python):
def main():
    divs = ["dream", "dreamer", "erase","eraser"]

    S = input()

    rev_S = S[::-1]
    
    rev_divs = [div[::-1] for div in divs]
    
    i = 0
    while(1):
        can = False
        for rev_div in rev_divs:
            if rev_S[i:(i+len(rev_div))] == rev_div:
                can = True
                i += len(rev_div)

                if i == len(rev_S):
                    print("YES")
                    return 
        
        if not can:
            print("NO")
            return

main()

Solution (Python):
from collections import deque

def main():
    divide = ["dream", "dreamer", "erase", "eraser"]

    S = input()

    q = deque([0])

    while(q):
        beg_i = q.popleft()

        if beg_i == len(S):
            print("YES")
            return
        
        for div_i in divide:
            end_i = beg_i + len(div_i)
            if S[beg_i:end_i] == div_i:
                q.append(end_i)
    
    print("NO")
    return

main()

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

dream_r = 'dream'[::-1] 
dreamer_r = 'dreamer'[::-1] 
erase_r = 'erase'[::-1] 
eraser_r = 'eraser'[::-1] 

flag = True
i = 0

while flag:
    if S[i:i+len(dream_r)] == dream_r:
        i += len(dream_r)
    elif S[i:i+len(dreamer_r)] == dreamer_r:
        i += len(dreamer_r)
    elif S[i:i+len(erase_r)] == erase_r:
        i += len(erase_r)
    elif S[i:i+len(eraser_r)] == eraser_r:
        i += len(eraser_r)
    else:
        flag = False

    if i == len(S):
        flag = True
        break

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

Solution (Python):
S = input()

i = len(S)
while 0 < i:
	
	if S[i - 6:i] == "eraser":
		
		i -= 6
	elif S[i - 7:i] == "dreamer":
		
		i -= 7
	elif S[i - 5:i] == "erase" or S[i - 5:i] == "dream":
		
		i -= 5
	else:
		break
print(["YES", "NO"][not(i == 0)])

Solution (Python):
s = input()

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


for w in W:
  s = s.replace(w, '')

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

Solution (Python):
s = input()
li = ["maerd", "remaerd", "esare", "resare"]
p = list(reversed((s)))
j = ""
for i in p:
  j += i
  for h in li:
    if j == h:
      j = ""
      break
if j == "":
  print("YES")
else:
  print("NO")