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())
t = ["dream","dreamer","erase","eraser"]
s = s[::-1]
t1=[]
for i in t:
    t1.append(i[::-1])

count = 0
while True:
    check = False
    for i in t1:
        
        if s[count:min(count+len(i),len(s))] == list(i):
            count += len(i)
            check = True
            if count == len(s):
                print("YES")
                exit()
            break
    if count == len(s):
        print("Yes")
        exit()
    if check == False:
        print("NO")
        exit()

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

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

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

Solution (Python):
import re

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

if __name__ == '__main__':
    resolve()

Solution (Python):
import re;print("YNEOS"[re.match(r"^(dream(er)?|eraser?)+$",input())==None::2])

Solution (Python):
def ans2():
    s = input()
    flag = True
    while flag:
        if (s[-7:])=='dreamer':
            s = s[:-7]
        elif (s[-5:])=='dream':
            s = s[:-5]
        elif (s[-6:])=='eraser':
            s = s[:-6]
        elif (s[-5:])=='erase':
            s = s[:-5]
        else:
            flag = False
    
    if not s:
        print("YES")
    else:
        print("NO")
ans2()

Solution (Python):
def main():
    s = input()
    ref = ['eraser','erase','dreamer','dream']
    for i in range(4):
        s = s.replace(ref[i], '')
    if not s:
        print("YES")
    else:
        print("NO")
main()

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)

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

Solution (Python):

def main():
    s = input()
    flag = True 
    while flag:
        flag = False
        if s[-7:] == "dreamer":
            s = s[:-7]
            flag = True
        if s[-6:] == "eraser":
            s = s[:-6]
            flag = True
        if s[-5:] == "erase":
            s = s[:-5]
            flag = True
        if s[-5:] == "dream":
            s = s[:-5]
            flag = True
    if not s:
        print("YES")
    else:
        print("NO")

main()

Solution (Python):
s = input()

flg = 0

for i in range(20001):
    len(s)
    if s[-5:] == "dream":
        s = s[:len(s) - 5]
    elif s[-7:] == "dreamer":
        s = s[:len(s) - 7]
    elif s[-5:] == "erase":
        s = s[:len(s) - 5]
    elif s[-6:] == "eraser":
        s = s[:len(s) - 6]
    elif s == "":
        flg = 1
    else:
        flg = 0
        break

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

Solution (Python):

def main():
    s = input()
    p = ['eraser', 'erase', 'dreamer', 'dream']
    for i in range(4):
        s = s.replace(p[i], '')
    if not s:
        print('YES')
    else:
        print('NO')
main()

Solution (Python):
import re
s = input()

if re.fullmatch(r'(dream|dreamer|erase|eraser)*', s):
    print("YES")
else:
    print("NO")

Solution (Python):
s = input()

num = len(s)

while len(s)>=5:
    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:
        break

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

Solution (Python):
S = input()

elements = ["maerd", "remaerd", "esare", "resare"]
reverseS = S[::-1]

ans = "NO"
i = 0
while True:
    flg = 0
    for element in elements:
        l = len(element)
        if element == reverseS[i:i+l]:
            i += l
            flg = 1
            break
    if flg == 0:
        break
    elif i == len(reverseS):
        ans = "YES"
        break

print(ans)

Solution (Python):
s = input()
while len(s) > 0:
    for a in ('dreamer', 'dream', 'eraser', 'erase'):
        if s[-len(a):] == a:
            s = s[:-len(a)]
            break
    else:
        break
if len(s) == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
S = input()
case =True
while(case == True):
    if len(S) <5:
        case = False
    
    elif S[0:5] == 'dream': 
        if S[0:10] == 'dreamerase':
            S = S[5:]
        elif S[0:7] == 'dreamer':
            S = S[7:]
        else:
            S = S[5:]

    elif S[0:5] == 'erase': 
        if len(S) > 5 and S[5] == 'r':
            S = S[6:]
        else:
            S = S[5:]
    
    else:
        case =False

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

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

Solution (Python):
S = input()

S = S[::-1]

index = 0


while index < len(S):
    if S[index] == 'm':
        if S[index:index+5] == 'maerd':
            index += 5
            continue
        else:
            break
    elif S[index] == 'e':
        if S[index:index+5] == 'esare':
            index += 5
            continue
        else:
            break
    elif S[index] == 'r':
        if S[index:index+6] == 'resare':
            index += 6
            continue
        elif S[index:index+7] == 'remaerd':
            index += 7
            continue
        else:
            break

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

Solution (Python):
def main():
    S = input()[::-1]
    s1 = "dream"[::-1]
    s2 = "dreamer"[::-1]
    s3 = "erase"[::-1]
    s4 = "eraser"[::-1]
    ans = "NO"
    while True:
        match_flag = False
        for c in [s1, s2, s3, s4]:
            if S[0:len(c)] == c:
                match_flag = True
                S = S.replace(c, "", 1)
                break
        if match_flag is False:
            break
        if S == "":
            ans = "YES"
            break
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
S=input()
flag=True
while len(S)>7:
    if S[-7:]=="dreamer":
        S=S[:-7]
    elif S[-5:]=="dream" or S[-5:]=="erase":
        S=S[:-5]
    elif S[-6:]=="eraser":
        S=S[:-6]
    else:
        flag=False
        break
if S=="dreamer" or S=="dream" or S=="erase" or S=="eraser" or 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 = input().replace("eraser", "").replace("erase","").replace("dreamer", "").replace("dream", "")
if s:
    print("NO")
else:
    print("YES")

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

Solution (Python):
s=input()
a='dream'
b='dreamer'
c='erase'
d='eraser'
i=0

while(True):
	if i==len(s):
		print("YES")
		exit()
	if s[-7-i:len(s)-i]==b:
		i+=7
	elif s[-5-i:len(s)-i]==a:
		i+=5
	elif s[-6-i:len(s)-i]==d:
		i+=6
	elif s[-5-i:len(s)-i]==c:
		i+=5
	else :
		print("NO")
		exit()

Solution (Python):
s = input()
flag = True
while 1:
    if s[-7:] == "dreamer":
        s = s[:-7]
    elif s[-6:] == "eraser":
        s = s[:-6]
    elif s[-5:] == "dream" or s[-5:] == "erase":
        s = s[:-5]
    else:
        flag = False
        break
    if s == "":
        break
if flag:
    print("YES")
else:
    print("NO")

Solution (Python):
S=input()

while(1):
    length = len(S)
    if length==0:
        break
    if S[length-5:length]=="dream":
        S = S[:length-5]
    elif S[length-5:length]=="erase":
        S = S[:length-5]
    elif S[length-6:length]=="eraser":
        S = S[:length-6]
    elif S[length-7:length]=="dreamer":
        S = S[:length-7]
    else:
        print("NO")
        exit(0)
print("YES")

Solution (Python):
def main():
    s = input()

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

    for word in words:
        s = s.replace(word, "")

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


if __name__ == "__main__":
    main()

Solution (Python):
S = input().strip()


i=len(S)
while i >= 0:

    if S[(i-7):i] == "dreamer":
        i=i-7
    elif S[(i-6):i] == "eraser":
        i=i-6
    elif S[(i-5):i] == "dream" or S[(i-5):i] == "erase":
        i=i-5
    else:
        print("NO")
        break

    if i == 0:
        print("YES")
        break

Solution (Python):
def main(S):
    listdreamereraser = ['dreamer','eraser','dream','erase']
    while True:
        for i in listdreamereraser:
            if i == S[-len(i):]:
                S = S[:-len(i)]
                break
        else:
            return False
        if len(S) == 0:
            return True

S = input()
print('YES' if main(S) else 'NO')

Solution (Python):
def main(S):
    listdreamereraser = ['dreamer','eraser','dream','erase']
    while True:
        for i in listdreamereraser:
            if i in S[-len(i):]:
                S = S[:-len(i)]
                break
        else:
            return False
        if len(S) == 0:
            return True

S = input()
print('YES' if main(S) else 'NO')

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

Solution (Python):
S = input()


S = S[::-1]

S = S.replace("resare","")
S = S.replace("esare","")
S = S.replace("remaerd","")
S = S.replace("maerd","")

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

Solution (Python):
S=input()[::-1]
T=""
L=["dream","dreamer","erase","eraser"] 
for s in S:
    T=s+T
    if T in L:
        T=""
    elif len(T)>6:
        break
print("YES" if T=="" else "NO")

Solution (Python):
def solve():
    S = input()
    S = S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
    return 'YES' if S == '' else 'NO'

print(solve())

Solution (Python):
S=input()

l = len(S)
ans = True

while(l>0):
    if l<=4:
        ans=False
        break
    if l>=5:
        if S[-5:] == "erase" or S[-5:]=="dream":
            S = S[:-5]
            l = l-5
            continue
    if l>=6:
        if S[-6:] == "eraser":
            S = S[:-6]
            l = l-6
            continue
    if l>=7:
        if S[-7:] == "dreamer":
            S = S[:-7]
            l = l-7
            continue
    ans = False
    break

if not ans:
    print("NO")
else:
    print("YES")

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

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

Solution (Python):
s=input()

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

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

Solution (Python):
S = input()

T = ["dream","dreamer","erase","eraser"]
flag = True
for i in range(len(S)):
    if (flag == False) or (len(S) == 0):
        break
    if S[-5:] in T:
        S = S[:-5]
    elif S[-6:] in T:
        S = S[:-6]
    elif S[-7:] in T:
        S = S[:-7]
    else:
        print("NO")
        flag = False
if flag == True:
    print("YES")

Solution (Python):
import sys
s = input()
s = s[::-1]
A = ['dreamer','dream','eraser', 'erase']
for i in range(len(A)):
    A[i] = A[i][::-1]
while(len(s)!=0):
    cs = s
    for i in range(len(A)):
        if (s.startswith(str(A[i]))):
            
            s = s[len(A[i]):]
            
            break
    if (cs == s):
        print('NO')
        sys.exit()
print('YES')

Solution (Python):
s = input()

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

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

"""対象文字列
dream
erase
eraser
dreamer
"""

flg = True
while flg:
  if S[-7:] == 'dreamer':
    S = S[:-7]
  elif S[-6:] == 'eraser':
    S = S[:-6]
  elif S[-5:] == 'erase':
    S = S[:-5]
  elif S[-5:] == 'dream':
    S = S[:-5]
  else:
    flg = False


if len(S) == 0:
  ans = 'YES'
else:
  ans = 'NO'


print(ans)

Solution (Python):
s = input()
i=len(s)-1
while i > 0:
    if i<4:
        print("NO")
        exit()
    check=s[i-2:i+1]

    if check == "eam": 
        if s[i-4:i+1] == "dream":
            i-=5
            continue
    elif check == "mer": 
        if i > 5 and s[i-6:i+1] == "dreamer":
            i-=7
            continue
    elif check == "ase": 
        if s[i-4:i+1] == "erase":
            i-=5
            continue
    elif check == "ser": 
        if i > 4 and s[i-5:i+1] == "eraser":
            i-=6
            continue

    print("NO")
    exit()

print("YES")

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

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

Solution (Python):
S = input()
l = ['maerd','remaerd', 'esare', 'resare']

def test(S,l):
    while len(S) > 0:
        if S[::-1] in l:
            print('YES')
            return
        elif S[-1:-6:-1] in l:
            S = S[:-5]
        elif S[-1:-7:-1] in l:
            S = S[:-6]
        elif S[-1:-8:-1] in l:
            S = S[:-7]
        else:
      	    print('NO')
      	    return
  
test(S,l)

Solution (Python):
s = input()

pos = len(s)
while pos > 0:
    
    if s[pos-1] == 'e':
        if s[pos-5:pos] == 'erase':
            
            pos -= 5
        else:
            break
    elif s[pos-1] == 'm':
        if s[pos-5:pos] == 'dream':
            
            pos -= 5
        else:
            break
    elif s[pos-6:pos] == 'eraser':
        
        pos -= 6
    elif s[pos-7:pos] == 'dreamer':
        
        pos -= 7
    else:
        break
print('YES' if pos <= 0 else 'NO')

Solution (Python):
s = input()
devide = ["maerd", "remaerd", "esare", "resare"]

reverse_input = "".join(list(reversed(s)))
can = False
point = 0

for i in range(len(s)+1) :
    slice = reverse_input[point:i]
    if slice in devide :
        point += len(slice)
        can = True
    else :
        can = False

if can == True :
    print("YES")
else :
    print("NO")

Solution (Python):
S = input()
reverse = S[::-1]
devide = ["dream", "erase", "dreamer", "eraser"]
r_devide = [devide[i][::-1] for i in range(len(devide))]
i=0
while i < len(S):
  can = False
  for j in r_devide:
    if j in reverse[i:i+len(j)] :
      can = True
      i += len(j)
  
  if can == False:
    break
    
if can == True:
  print("YES")
else:
  print("NO")

Solution (Python):
def main(s):
    e = ["dreamer","eraser","dream","erase"]
    
    t = [""]
    
    while len(t) > 0:
        val = t.pop(0)
        for i in e:
            tar = val + i
            
            if s[:len(tar)] == tar:
                if s == tar:
                    return True
                else:
                    t.append(tar)
    return False

s = input()
print("YES" if main(s) else "NO")

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

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

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

Solution (Python):
s1 = input()
s = s1 + '111111111111'
index = 0
while index < len(s):
    word = s[index:index + 5]
    
    if word == '11111':
        break
    if '1' in word:
        print("NO")
        exit()

    if word == 'dream':
        index += 5

        if s[index:index + 2] == 'er':
            if s[index:index + 5] == 'erase':
                pass
            else:
                index += 2

    elif word == 'erase':
        index += 5
        if s[index] == 'r':
            index += 1

    else:
        print('NO')
        exit()

print("YES")

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):
def main():
  s=input()
  q=[0]
  m=len(s)
  l=["dream","dreamer","erase","eraser"]
  while q:
    i=q.pop()
    if i==m:
      print("YES")
      return
    for j in l:
      nj=len(j)
      if i+nj<=m and s[i:i+nj]==j:
        q.append(i+nj)
  print("NO")

main()

Solution (Python):
S = input()[::-1]
N = len(S)
T = ""
n = 0
C = ["maerd","remaerd","esare","resare"]
while n<N:
    if S[n]=="m":
        T+=C[0]
        n+=5
    elif S[n]=="e":
        T+=C[2]
        n+=5
    elif S[n]=="r":
        if N-n<6:break
        if S[n+2]=="m":
            T+=C[1]
            n+=7
        elif S[n+2]=="s":
            T+=C[3]
            n+=6
        else:break
    else:break
print("YES" if S==T else "NO")

Solution (Python):
import re
S = input()
'''
メタ文字：
^ = 文字列の先頭、
| = OR
+ = 直前のパターンを1回以上繰り返し、
$ = 文字列の末尾
'''
if re.match("^(dream|dreamer|erase|eraser)+$", S):
    print('YES')
else:
    print('NO')

Solution (Python):
import re
s = input()
m = re.fullmatch(r"(dreamer|dream|erase|eraser)+", s)

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

Solution (Python):
s = input()
s = s[::-1]
ans = ["maerd","remaerd","esare","resare"]
flag = 1
while len(s) != 0 and flag == 1:
    flag = 0
    if s[:5] in ans:
        s = s[5:]
        flag = 1
    elif s[:7] in ans:
        s = s[7:]
        flag = 1
    elif s[:6] in ans:
        s = s[6:]
        flag = 1
        
if flag == 0:
    print("NO")
else:
    print("YES")

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

Solution (Python):
from itertools import permutations

S = input()

def is_passed(s, ws):
    for w in ws:
        s = ''.join(s.split(w))
        if len(s) == 0:
            return True
    return False

def main():
    l = ['dreamer', 'eraser', 'dream', 'erase']
    pm = permutations(l, len(l))
    passed = False
    for ws in pm:
        passed = is_passed(S, ws)
        if passed:
            break
    print('YNEOS'[not passed::2])

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    S = input()
    T = set("dream dreamer erase eraser".split())
    
    p = ""
    for i in range(len(S)):
        p = S[~i] + p
        if p in T:
            p = ""
        elif len(p) > 7:
            print("NO")
            return

    print("YES")

main()

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

Solution (Python):
S = input()
str_list = ['dream','dreamer','erase','eraser']
fl = True
while fl:
    if S[-5:] in str_list:
        S = S[0:-5]
    elif S[-6:] in str_list:
        S = S[0:-6]
    elif S[-7:] in str_list:
        S = S[0:-7]
    elif S=="":
        fl = False
    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()

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


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

Solution (Python):
s = input()
y = 0
while y < len(s):
    if s[y:y+11] == "dreameraser":
        y += 11
    elif s[y:y+10] == "dreamerase":
        y += 10
    elif s[y:y+7] == "dreamer":
        y += 7
    elif s[y:y+6] == "eraser":
        y += 6
    elif s[y:y+5] == "dream" or s[y:y+5] == "erase":
        y += 5
    else: 
        print("NO")
        break
else: print("YES")

Solution (Python):
S = input()

def check(t):
  if len(t) >= 5 and (t[-5:] == 'dream' or t[-5:] == 'erase'):
    return True,t[:-5]
  elif len(t) >=6 and t[-6:] == 'eraser':
    return True,t[:-6]
  elif len(t) >= 7 and t[-7:] == 'dreamer':
    return True,t[:-7]
  else:
    return False,t

while(len(S) > 0):
  flag,S = check(S)
  if not flag:
    print('NO')
    exit()
print('YES')

Solution (Python):
S = input()

def check(t):
  if len(t) >= 5 and (t[-5:] == 'dream' or t[-5:] == 'erase'):
    return True,t[:-5]
  elif len(t) >=6 and t[-6:] == 'eraser':
    return True,t[:-6]
  elif len(t) >= 7 and t[-7:] == 'dreamer':
    return True,t[:-7]
  else:
    return False,t

while(len(S) > 0):
  flag,S = check(S)
  if not flag:
    print('NO')
    exit()
print('YES')

Solution (Python):
s = input()
dp = [0 for i in range(len(s)+1)]
dp[0] = 1
words = ['eraser', 'erase', 'dreamer', 'dream']

for i in range(len(s)):
  i += 1
  for sent in words:
    before = i - len(sent)
    if before < 0:
      continue
    if dp[before] == 1 and s[before:i] == sent:
      dp[i] = 1
print('YES' if dp[-1] else 'NO')

Solution (Python):
S = input()

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

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

Solution (Python):
S = input()[::-1]
D = ["dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1]]
while True:
    for d in D:
        if S.startswith(d):
            S = S.replace(d, "", 1)
            break
    else:
        break
print("YNEOS"[S!=""::2])

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()[::-1]
T=["dream","dreamer","erase","eraser"]
l,n=0,len(s)

while l!=n:
    flag=0
    for i in T:
        word=i[::-1]
        if s[l:l+len(word)]==word:
            l +=len(word)
            flag=1
    if flag==0:print("NO");exit()
print("YES")

Solution (Python):
s=input()[::-1]
T=["dream","dreamer","erase","eraser"]
l,n=0,len(s)

while l!=n:
    flag=0
    for i in T:
        word=i[::-1]
        if s[l:l+len(word)]==word:
            l +=len(word)
            flag=1
            break
    if flag==0:print("NO");exit()
print("YES")

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=list(S())

  a1=list('dream')
  a2=list('dreamer')
  a3=list('erase')
  a4=list('eraser')

  while len(s)>4:
    if s[-5:]==a1:
      for _ in range(5):
        s.pop()
    elif s[-7:]==a2:
      for _ in range(7):
        s.pop()
    elif s[-5:]==a3:
      for _ in range(5):
        s.pop()
    elif s[-6:]==a4:
      for _ in range(6):
        s.pop()
    else:
      break

  if s==[]:
    return 'YES'
  return 'NO'


print(main())

Solution (Python):
s=input()
while len(s)>0:
  
  if s[:5]=="dream" and (len(s)==5 or s[5]=="d" or s[5:8]=="era"):
    s=s[5:]
  elif s[:7]=="dreamer" and (len(s)==7 or s[7]=="d" or s[7]=="e"):
    
    s=s[7:]
  elif s[:5]=="erase" and (len(s)==5 or s[5]=="d" or s[5]=="e"):
    
    s=s[5:]
  elif s[:6]=="eraser" and (len(s)==6 or s[6]=="d" or s[6]=="e"):
    s=s[6:]
  else:
    print("NO")
    exit()
print("YES")

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

Solution (Python):

S = input()
T = ""

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

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

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

Solution (Python):
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):
def main():
    s = input()

    st = [s]
    while st:
        x = st.pop()
        if x == '':
            print('YES')
            return

        for w in ('dream', 'dreamer', 'erase', 'eraser'):
            if x.endswith(w):
                st.append(x[:-len(w)])

    print('NO')


if __name__ == '__main__':
    main()

Solution (Python):
s=list(input())
s.reverse()
s=''.join(s)

i=0
while i<len(s):
    if s[i:i+5]=='esare' or  s[i:i+5]=='maerd':
        i+=5
    elif s[i:i+6]=='resare':
        i+=6
    elif s[i:i+7]=='remaerd':
        i+=7
    else:
        print('NO')
        exit()
print('YES')

Solution (Python):
S = input().replace('dream', 'A').replace('erase', 'B').replace('er', 'C').replace('r', 'D')
N = len(S)

for i in range(N):
    if S[i] in 'AB':
        continue
    elif S[i] == 'C':
        if i == 0 or S[i-1] != 'A':
            print('NO')
            exit()
    elif S[i] == 'D':
        if i == 0 or S[i-1] != 'B':
            print('NO')
            exit()
    else:
        print('NO')
        exit()
print('YES')

Solution (Python):
import queue

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

S = input()

BFS = queue.Queue()

can = False

BFS.put(0)

while not BFS.empty():
    t = BFS.get()
    if (t == len(S)):
        can = True
        break
    for s in divide:
        if s == S[t: t + len(s)]:
            BFS.put(t + len(s))

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

Solution (Python):
import re

def solve(s):
    return 'YES' if re.match('^((dream(er)?)|(erase(r)?))*$', s) else 'NO'

_s = input()
print(solve(_s))

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

Solution (Python):
S = input()

new_S = "".join(list(reversed(S)))
string_list = ["dream", "dreamer", "erase", "eraser"]
reverse_string_list = []
for i in range(len(string_list)):
    reverse_string_list.append("".join(list(reversed(string_list[i]))))

can = True
index = 0
for i in range(len(new_S)):
    if index >= len(new_S):
        break
    can2 = False
    for each_string in reverse_string_list:
        if new_S[index:index + len(each_string)] == each_string:
            index += len(each_string) - 1
            can2 = True
    if can2 is False:
        can = False
        break
    index += 1

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

Solution (Python):
S = input()

a = 'dreamer'
b = 'eraser'
c = 'dream'
d = 'erase'
key = [a,b,c,d]

st = S[::]

while len(st):
    for i in range(4):
        tmp = st[-len(key[i]):]
        if tmp == key[i]:
            st = st[:-len(key[i])]
            if not len(st):
                print('YES')
                exit(0)
            break
        if i == 3:
            print('NO')
            exit(0)

Solution (Python):
S = input()
hikari = ['maerd','remaerd','esare','resare']

a = True

while a:
    length = len(S)
    go = ''
    roku = ''
    nana = ''

    if length >= 5:
        for i in range(length-1,length-6,-1):
            go += S[i]
    if length >= 6:
        for i in range(length-1,length-7,-1):
            roku += S[i]
    if length >= 7:
        for i in range(length-1,length-8,-1):
            nana += S[i]

    if go in hikari:
        
        S = S[:-5]
        a = True
    elif roku in hikari:
        
        S = S[:-6]
        a = True
    elif nana in hikari:
        
        S = S[:-7]
        a = True
    else:
        a = False

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

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

Solution (Python):
S = input()

S0 = S.replace("dream", "A")
S1 = S0.replace("erase", "B")
S2 = S1.replace("Aer", "A")
S3 = S2.replace("Br", "B")


check = True
for i in range(len(S3)):
    if S3[i] != "A" and S3[i] != "B":
        check = False

print("YES" if check == True else "NO")

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

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

S = S[::-1]
for i in Mozi:
    S = S.replace(i,"")
if not S:
    print("YES")
else:
    print("NO")

Solution (Python):
S = input()

stack = []

for s in S[::-1]:
    stack.append(s)
    n = len(stack)
    if n == 5 and (stack == ['e', 's', 'a', 'r', 'e'] or stack == ['m', 'a', 'e', 'r', 'd']):
        stack = []
    elif n == 6 and stack == ['r', 'e', 's', 'a', 'r', 'e']:
        stack = []
    elif n == 7 and stack == ['r', 'e', 'm', 'a', 'e', 'r', 'd']:
        stack = []
    elif n == 8:
        print('NO')
        break
else:
    print('YES')

Solution (Python):
S = input()
sc = ["eraser", "erase", "dreamer", "dream"]
for i in sc:
    S = S.replace(i, "")
if S:
    print("NO")
else:
    print("YES")

Solution (Python):
S = input()

sc = ["eraser", "erase", "dreamer", "dream"]
for i in sc:
    S = S.replace(i, "")
if len(S) == 0:
    print("YES")
else:
    print("NO")

Solution (Python):

from collections import deque

divide = ["dream", "dreamer", "erase", "eraser"];

s = input()
que = deque()

can = "NO"

que.append(0)

while(len(que) > 0):
  t = que.pop()
  if (t == len(s)):
    can = "YES"
    break
  for e in divide:
    if s[t:t+len(e)] == e:
      que.append(t+len(e))
print(can)

Solution (Python):
S = input()

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

S = S.replace("p", "")

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