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 = input()[::-1]
W = [w[::-1] for w in ['dream', 'dreamer', 'erase', 'eraser']]
L = len(S)
ans = 'YES'
i = 0
while i < L:
    f = 1
    for w in W:
        if w == S[i : i + len(w)]:
            i += len(w)
            f = 0
            break
    if f:
        ans = 'NO'
        break
print(ans)

Solution (Python):
def daydream(S: str) -> bool:
    while True:
        if S.endswith('dream'):
            S = S[:-5]
        elif S.endswith('dreamer'):
            S = S[:-7]
        elif S.endswith('erase'):
            if S[:-5].endswith('eras'):
                S = S[:-4]
            else:
                S = S[:-5]
        elif S.endswith('eraser'):
            if S[:-6].endswith('eras'):
                S = S[:-5]
            else:
                S = S[:-6]
        else:
            break

    return S == ''


if __name__ == "__main__":
    S = input()
    ans = daydream(S)
    print('YES' if ans else 'NO')

Solution (Python):
import re
s = input()[::-1]
ss = re.split("maerd|remaerd|esare|resare", s)
if any(ss):
  print("NO")
else:
  print("YES")

Solution (Python):
S = list(input())
S.reverse()
gyaku = "".join(S)
ans = gyaku.replace("resare","")
ans = ans.replace("esare","")
ans = ans.replace("remaerd","")
ans = ans.replace("maerd","")

if ans == "":
  print("YES")
else:
  print("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('NO')
else:
    print('YES')

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

output = "NO"

S = S.replace('eraser', '')
S = S.replace('erase', '')
S = S.replace('dreamer', '')
S = S.replace('dream', '')
if S == "":
    output = "YES"

print(output)

Solution (Python):
from functools import reduce

def main():
    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    T = [
        ['d','r','e','a','m'],
        ['d','r','e','a','m','e','r'],
        ['e','r','a','s','e'],
        ['e','r','a','s','e','r']
    ]
    
    S = input()
    S = S[::-1]
    
    

    for i in range(4):
        T[i].reverse()
    while len(S)>0:
        if(''.join(S[0:len(T[0])]) == ''.join(T[0])):
            S = S[len(T[0]):]
            
            
        elif(''.join(S[0:len(T[1])]) == ''.join(T[1])):
            S = S[len(T[1]):]
            
            
        elif(''.join(S[0:len(T[2])]) == ''.join(T[2])):
            S = S[len(T[2]):]
            
            
        elif(''.join(S[0:len(T[3])]) == ''.join(T[3])):
            S = S[len(T[3]):]
            
            
        else:
            print('NO')
            break
        
    if(len(S) ==0):
        print('YES')

    
if __name__ == '__main__':
    main()

Solution (Python):
from functools import reduce

def main():
    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    T = [
        ['d','r','e','a','m'],
        ['d','r','e','a','m','e','r'],
        ['e','r','a','s','e'],
        ['e','r','a','s','e','r']
    ]
    S = list(_ for _ in input())
    S.reverse()

    for i in range(4):
        T[i].reverse()
    while len(S)>0:
        if(''.join(S[0:len(T[0])]) == ''.join(T[0])):
            for i in range(len(T[0])):
                S.pop(0)
        elif(''.join(S[0:len(T[1])]) == ''.join(T[1])):
            for i in range(len(T[1])):
                S.pop(0)
        elif(''.join(S[0:len(T[2])]) == ''.join(T[2])):
            for i in range(len(T[2])):
                S.pop(0)
        elif(''.join(S[0:len(T[3])]) == ''.join(T[3])):
            for i in range(len(T[3])):
                S.pop(0)
        else:
            print('NO')
            break
        
    if(len(S) ==0):
        print('YES')

    
if __name__ == '__main__':
    main()

Solution (Python):
from functools import reduce

def main():
    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    T = [
        ['d','r','e','a','m'],
        ['d','r','e','a','m','e','r'],
        ['e','r','a','s','e'],
        ['e','r','a','s','e','r']
    ]
    S = list(_ for _ in input())
    S.reverse()

    for i in range(4):
        T[i].reverse()
    while len(S)>0:
        if(S[0:len(T[0])] == T[0]):
            for i in range(len(T[0])):
                S.pop(0)
        elif(S[0:len(T[1])] == T[1]):
            for i in range(len(T[1])):
                S.pop(0)
        elif(S[0:len(T[2])] == T[2]):
            for i in range(len(T[2])):
                S.pop(0)
        elif(S[0:len(T[3])] == T[3]):
            for i in range(len(T[3])):
                S.pop(0)
        else:
            print('NO')
            break
        
    if(len(S) ==0):
        print('YES')

    
if __name__ == '__main__':
    main()

Solution (Python):
s = list(input())
while s:
    if ''.join(s[-5:]) == 'erase' or ''.join(s[-5:]) == 'dream':
        for i in range(5):
            s.pop()
    elif ''.join(s[-6:]) == 'eraser':
        for i in range(6):
            s.pop()
    elif ''.join(s[-7:]) == 'dreamer':
        for i in range(7):
            s.pop()
    else:
        print('NO')
        exit()
    
    if len(s) == 0:
        print('YES')
        exit()

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

Solution (Python):
S = input()
S = S[::-1]
_ = ["dream", "dreamer", "erase", "eraser"]
_ = [_[i][::-1] for i in range(4)]
i = 0
while i < len(S):
    can = False
    for k in _:
        if S[i:i + len(k)] == k:
            can = True
            i += len(k)
    if not can:
        print("NO")
        exit()
print("YES")

Solution (Python):
S = input()
ans = 'NO'

while True:
    if S[-7:] == 'dreamer':
        S = S[:-7]
        if S == '':
            ans = 'YES'
            break
    elif S[-6:] == 'eraser':
        S = S[:-6]
        if S == '':
            ans = 'YES'
            break
    elif S[-5:] == 'dream' or S[-5:] == 'erase':
        S = S[:-5]
        if S == '':
            ans = 'YES'
            break
    else:
        break

print(ans)

Solution (Python):
er = ["dreamer", "eraser"]
noter = ["dream", "erase"]
words = er + noter
s = input()
while len(s) > 0:
  flag = True
  for word in words:
    if s.endswith(word):
      s = s[:-len(word)]
      flag = False
  if flag:
    print("NO")
    exit()
print("YES")

Solution (Python):
a=("dream","erase");ans="YES"
s=input()
while s!="":
  if s[-7:]=="dreamer":s=s[:-7]
  elif s[-6:]=="eraser":s=s[:-6]
  elif s[-5:]in a:s=s[:-5]
  else:ans="NO";break
print(ans)

Solution (Python):
S = input()

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

ans = 'YES'

while(len(S) > 4):
    a = S[-5:]
    if a == 'dream' or a == 'erase':
        S = S[:-5]
        continue
    a = S[-6:]
    if a == 'eraser':
        S = S[:-6]
        continue
    a = S[-7:]
    if a == 'dreamer':
        S = S[:-7]
        continue
    ans = 'NO'
    break

print(ans)

Solution (Python):


s = input()[::-1]

while True:
  if s[:5] == "maerd":
    s = s[5:]
  elif s[:7] == "remaerd":
    s = s[7:]
  elif s[:5] == "esare":
    s = s[5:]
  elif s[:6] == "resare":
    s = s[6:]
  else:
    break

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

Solution (Python):
S = input()
index = 0
while True:
    if S.find("eraser", index) == index:
        index += len("eraser")

    elif S.find("erase", index) == index:
        index += len("erase")

    elif S.find("dreamer", index) == index and S.find("ase", index + len("dreamer")) != index + len("dreamer"):
        index += len("dreamer")

    elif S.find("dream", index) == index:
        index += len("dream")

    elif index == len(S):
        print("YES")
        break
    else:
        print("NO")
        break

Solution (Python):
S = input()

d = ["dream", "dreamer", "erase", "eraser"]
rs = S[::-1]
ls = len(S)
rd = [(s[::-1], len(s)) for s in d]
i = 0
while True:
    if i == ls:
        print("YES")
        break
    for s, l in rd:
        if rs[i:i+l] == s:
            i += l
            break
    else:
        print("NO")
        break

Solution (Python):
s = input()
li = {"dream": 5, "dreamer": 7, "erase": 5, "eraser": 6}
flag = 0
while len(s) > 0:
    ct = 0
    if flag == 1:
        break
    for key in li.keys():
        ct += 1
        if s.endswith(key):
            s = s[:-(li[key])]
            break
        if ct == 4:
            flag = 1
            print("NO")
            break
if flag == 0:
    print("YES")

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

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

Solution (Python):
s = input()
for i in range(10**5):
    s = s.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
print("YES") if s == '' else print("NO")

Solution (Python):
s = input()
moji = ["dream", "dreamer", 'erase', 'eraser']
while s != "":
    if s[-5:] == moji[0]:
        s = s[:-5]
    elif s[-7:] == moji[1]:
        s = s[:-7]
    elif s[-5:] == moji[2]:
        s = s[:-5]
    elif s[-6:] == moji[3]:
        s = s[:-6]
    else:
        break
if s == "":
    print("YES")
else:
    print("NO")

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

for _ in range(10**5):
    before_s = s
    if s[:5]=="maerd" or s[:5] =="esare":
        s = s[5:]
    elif s[:7]=="remaerd" :
        s = s[7:]
    elif s[:6] == "resare":
        s = s[6:]
    if s == "":
        ans = "YES"
        break
    if s == before_s:
        ans ="NO"
        break
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(50000)

S = input()
S_len = len(S)

def dd(i):
  if i >= S_len: return True
  for ex in ("dream","dreamer","erase","eraser"):
    length = i + len(ex)
    if ex == S[i:length]:
      if dd(length): return True
  return False

print("YES" if dd(0) else "NO")

Solution (Python):
s=input()

s=s[::-1]

X=['maerd','remaerd','esare','resare']
ans='YES'
i=0
while i<=len(s)-5:
    if s[i:i+5] in X:
        i+=5
    else:
        if s[i:i+6] in X:
            i+=6
        else:
            if s[i:i+7]  in X:
                i+=7
            else:
                ans='NO'
                break

print(ans)

Solution (Python):

S = input()
s =len(S)
t=0

def endcheck(t,s):
  if t==s:
    print("YES")
    
while t < s:
  if S[-t-5:s-t] =="dream":
    t += 5
    endcheck(t,s)
  elif S[-t-7:s-t] =="dreamer":
    t += 7
    endcheck(t,s)
  elif S[-t-5:s-t] =="erase":
    t += 5
    endcheck(t,s)
  elif S[-t-6:s-t] =="eraser":
    t += 6
    endcheck(t,s)
  else:
    print("NO")
    break

Solution (Python):
import sys
def p(*a):
  s=" ".join(map(str,a))
  
  sys.stderr.write(s+"\n")

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

def solv(s):
  while len(s)>0:
    x=s
    for y in l:
      i=-1*len(y)
      if y==s[i:]: s=s[:i]
    p(x,s)
    if x==s:
      print("NO")
      exit()
  print("YES")

Q=1
for i in range(Q):
  s=input()
  p(i,s,s[-5:],s[:-5])
  solv(s)

Solution (Python):










S = input()
S = S[::-1] 
n = len(S)
while len(S) != 0:
    if S[:6] == "resare":
        S = S[6:]
    elif S[:7] == "remaerd":
        S = S[7:]
    elif S[:5] == "esare":
        S = S[5:]
    elif S[:5] == "maerd":
        S = S[5:]
    else:
        print("NO")
        quit()
print("YES")

Solution (Python):
data = [str(input()), True]

def check(string):
    if string[len(string)-6:] == 'eraser':
        string = string[:len(string)-6]
        return [string,True]
    elif string[len(string)-5:] == 'erase':
        string = string[:len(string)-5]
        return [string,True]
    elif string[len(string)-7:] == 'dreamer':
        string = string[:len(string)-7]
        return [string,True]
    elif string[len(string)-5:] == 'dream':
        string = string[:len(string)-5]
        return [string,True]
    else:
        return [string,False]
        
while (data[1] == True):
    data = check(data[0])
    if data[0] == '':
        print('YES')
        break
    elif data[1] == False:
        print('NO')
        break

Solution (Python):
s = input()

L = ["eraser", "dreamer", "erase", "dream"]
i = 0
f = 0
while i < len(s):
    if s[i:i+6] == "eraser" and (len(s) == i+6 or s[i+6:i+8] != "as"):
        i += 6
    elif s[i:i+7] == "dreamer" and (len(s) == i+7 or s[i+7:i+9] != "as"):
        i += 7
    elif s[i:i+5] == "erase" or s[i:i+5] == "dream":
        i += 5
    else:
        f = 1
        break

if f == 0:
    print("YES")
else:
    print("NO")

Solution (Python):
s = input()
a = s

for i in range(10**4):
    a = a.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')

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

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007



def A():
    a,b = LI()
    if not (a*b)%2:
        print("Even")
    else:
        print("Odd")
    return


def B():
    s = S()
    print(s.count("1"))
    return


def C():
    n = I()
    a = LI()
    f = 0
    for j in range(100000):
        for i in range(n):
            if a[i]%2:
                f = 1
                break
            a[i] //= 2
        if f:break
    print(j)
    return


def D():
    a,b,c,x = IR(4)
    su = 0
    for i in range(a+1):
        for j in range(b+1):
            for k in range(c+1):
                if 500*i+100*j+50*k == x:su += 1
    print(su)
    return


def E():
    n,y = LI()
    for i in range(n+1):
        for j in range(n+1-i):
            k = n-i-j
            if 10000*i+5000*j+1000*k == y:
                print(i,j,k)
                quit()
    print(-1,-1,-1)
    return


def F():
    s = input()
    while s:
        if s[:11] == "dreameraser":
            s = s[11:]
        elif s[:10] == "dreamerase":
            s = s[10:]
        elif s[:7] == "dreamer":
            s = s[7:]
        elif s[:6] == "eraser":
            s = s[6:]
        elif s[:5] == "dream":
            s = s[5:]
        elif s[:5] == "erase":
            s = s[5:]
        else:
            print("NO")
            quit()
    print("YES")
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    F()

Solution (Python):

S = input()
revS = S[::-1]
addStrings = ['dream', 'dreamer', 'erase', 'eraser']

T = ""
counter = 0
while True:
    existFlg = False
    for i in range(4):
        if revS[counter:counter + len(addStrings[i])] == addStrings[i][::-1]:
            existFlg = True
            T = T + addStrings[i][::-1]
            counter += len(addStrings[i])
            
    if not existFlg:
        break

if revS == T:
    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()
s=s[::-1] 
words = ["maerd", "remaerd", "esare", "resare"]
while len(s) > 4:
    if s[:5] == 'maerd':
        s = s[5:]
        continue
    elif s[:7] == 'remaerd':
        s = s[7:]
        continue
    elif s[:5] == 'esare':
        s = s[5:]
        continue
    elif s[:6] == 'resare':
        s = s[6:]
        continue
    else:
        break
if len(s) > 0:
    print('NO')
else:
    print('YES')

Solution (Python):
s = input()
s=s[::-1]
words = ['maerd','remaerd','esare','resare']
s_long=len(s)
i=0
flag = 1
while i<s_long:
    flag2 = 0
    for j in range(4):
        words_long=len(words[j])
        if s[i:i+words_long]==words[j]:
            i += words_long
            break
        else:
            flag2 += 1
    if flag2 == 4:
        flag = 0
    if not flag:
        break
if flag:
    print('YES')
else:
    print('NO')

Solution (Python):
s = input()


def f():
    global s
    while True:
        if len(s) <= 9:
            if s in ["dream","dreamer","erase","eraser"]:
                return "YES"
            else:
                return "NO"

        if s[:5] == "dream":
            if s[5:7] == "er" and s[7] != "a":
                s = s[7:]
            else:
                s = s[5:]
        elif s[:5] == "erase":
            if s[5] == "r":
                s = s[6:]
            else:
                s = s[5:]
        else:
            return "NO"
            

print(f())

Solution (Python):
S = input()
S = S[::-1]
i = 0
while len(S) > 0:
    if S.startswith('maerd'):
        S = S[5:]
    elif S.startswith('remaerd'):
        S = S[7:]
    elif S.startswith('esare'):
        S = S[5:]
    elif S.startswith('resare'):
        S = S[6:]
    else:
        print('NO')
        exit()
else:
    print('YES')

Solution (Python):
s = input()[::-1]
words = ['maerd', 'remaerd', 'esare', 'resare']
flag = 0
for _ in range(25000):
    if flag==4 or len(s)==0:
        break
    else:
        flag=0
    for word in words:
        l = len(word)
        if s[0:l] == word:
            s = s[l:]
        else:
            flag+=1
if flag==4:
    print('NO')
else:
    print('YES')

Solution (Python):
def main():
    S = input()
    words = ["dream", "dreamer", "erase", "eraser"]
    while len(S):
        ok = False
        for w in words:
            if S.endswith(w):
                S = S[:-len(w)]
                ok = True
                break
        if not ok:
            print("NO")
            return
    print("YES")


if __name__ == "__main__":
    main()

Solution (Python):
words = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(words)) :
    words[i] = words[i][::-1]

S = input()[::-1]

ans = True

i = 0

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

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

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

i=0
while True:
    for d in sample:
        if s[:len(d)] == d:
            s = s[len(d):]
            break
    
    if d =='':
        print ("NO")
        break

    if len(s) ==0:
        print("YES")
        break

Solution (Python):
S = input()

S = S[::-1]

headers = ["resare","esare","remaerd","maerd"]

result = True
while True:
    if S=="":
        result = True
        break
    result = False
    for header in headers:
        if S.startswith(header):
            S = S[len(header):]
            result = True
    if not result:
        break

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

Solution (Python):
S = input()

import re
pattern = r'^((dream)|(dreamer)|(erase)|(eraser))*$'

repatter = re.compile(pattern)

if repatter.match(S):
  print('YES')
else:
  print('NO')

Solution (Python):
S = input()

idx_end = len(S)
while True:
    if idx_end >= 5 and S[idx_end-5:idx_end] == "dream":
        idx_end -= 5
    elif idx_end >= 7 and S[idx_end-7:idx_end] == "dreamer":
        idx_end -= 7
    elif idx_end >= 5 and S[idx_end-5:idx_end] == "erase":
        idx_end -= 5
    elif idx_end >= 6 and S[idx_end-6:idx_end] == "eraser":
        idx_end -= 6
    else:
        break

    if idx_end == 0:
        break

if idx_end == 0:
    print("YES")
else:
    print("NO")

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

Solution (Python):
S = input()
T = ''
idx = 0

while(len(T) < len(S)):
    
    try:
        if(S[idx: idx + 7] == 'dreamer' and S[idx + 5: idx + 10] != 'erase'):
            T += 'dreamer'
            idx += 7

        elif(S[idx: idx + 5] == 'dream'):
            T += 'dream'
            idx += 5

        elif(S[idx: idx + 6] == 'eraser'):
            T += 'eraser'
            idx += 6

        elif(S[idx: idx + 5] == 'erase'):
            T += 'erase'
            idx += 5

        else:
            break
    
    except IndexError:
        pass

if(S == T):
    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()
n=0
while True:
    if S[n:n+5]=="dream":
        if S[n:n+7]=="dreamer":
            if n+7<len(S) and S[n+7]=="a":
                n = n+5
            else:
                n = n+7
        else:
            n = n+5
    elif S[n:n+5]=="erase":
        if S[n:n+6]=="eraser":
            if n+6<len(S) and S[n+6]=="a":
                n = n+5
            else:
                n = n+6
        else:
            n = n+5
    else:
        print("NO")
        break
    if n==len(S):
        print("YES")
        break

Solution (Python):
n = input()
n = n[::-1]
a = "dream"
a = a[::-1]
b = "dreamer"
b = b[::-1]
c = "eraser"
c = c[::-1]
d = "erase"
d = d[::-1]
co = 0
su = 0

for i in range(len(n)):
    co += 1
    if co == 5:
        if n[su:su+co] == a or n[su:su+co] == d:
            su += 5
            co = 0
    elif co == 6:
        if n[su:su+co] == c:
            su += 6
            co = 0
    elif co == 7:
        if n[su:su+co] == b:
            su += 7
            co = 0
    elif co >= 8:
        break
if su == len(n):
    print("YES")
else:
    print("NO")

Solution (Python):
S = input()
i = 0
while S:
    S = S.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
    i += 1
    if i == 10**5+1:
        print("NO")
        exit()

print("YES")

Solution (Python):


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



def aaa(a) :
  point = 0
  while point < len(a) :
    if a[point:point + 7] == 'remaerd' :
      point += 7
      continue
    elif a[point:point + 6] == 'resare' :
      point += 6
      continue
    elif a[point:point + 5] == 'maerd' or a[point:point + 5] == 'esare' :
      point += 5
      continue
    else :
      print("NO")
      return False
  print("YES")

aaa(a)

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

def solve(S):
    sl = 0
    while True:
        if len(S) == sl:
            return True
        if S[sl:sl+7] in {"remaerd"}:
            sl += 7
        elif S[sl:sl+6] in {"resare"}:
            sl += 6
        elif S[sl:sl+5] in {"maerd","esare"}:
            sl += 5
        else:
            return False
if solve(S):
    print("YES")
else:
    print("NO")

Solution (Python):
S = input()

S = S[::-1]


def solve(S):
    point = 0
    while S:
        if len(S) == point:
            print('YES')
            return False
        if S[point:point + 7] in {'remaerd'}:
            point += 7
        elif S[point:point + 6] in {'resare'}:
            point += 6
        elif S[point:point + 5] in {'esare', 'maerd'}:
            point += 5
        else:
            return True


if solve(S):
    print('NO')

Solution (Python):
S = raw_input()

p = len(S)-1
while p>=0:
  if p<2:
    print "NO"
    exit(0)
  if S[p]=="m":
    c = "dream"
  elif S[p]=="e":
    c = "erase"
  elif S[p-2]=="m":
    c = "dreamer"
  else:
    c = "eraser"
  if p>=len(c)-1 and S[p-len(c)+1:p+1]==c:
    p -= len(c)
  else:
    print "NO"
    exit(0)
print "YES"

Solution (Python):
str = input()
str = str[::-1]
devide = ['dream', 'dreamer', 'erase', 'eraser']
devide = [s[::-1] for s in devide]
flag = True
length = []

for i in range(len(devide)):
    length.append(len(devide[i]))
maxlen = max(length)

while len(str) >= maxlen:
    delete = False
    for s in devide:
        if str[0:len(s)] == s:
            str = str[len(s):]
            delete = True
    if not delete:
        flag = False
        break

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

Solution (Python):
s = input()
if s.find("1") != -1:
    print("NO")
elif s.find("2") != -1:
    print("NO")
else:
    a = s.replace("dream", "11111").replace("erase", "22222").replace("11111er", "1111111").replace("22222r", "111111").replace("22222", "11111")
    if a.count("1") == len(a):
        print("YES")
    else:
        print("NO")

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

Solution (Python):
S = input()

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

while True:
	for subS in ["dream","dreamer","erase","eraser"]:
		if S[-len(subS):] == subS:
			S = S[:-len(subS)]
			break
		else:
			continue
			
		
	else:
		print("NO")
		exit()
		
	if S == "":
		print("YES")
		exit()

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

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

while s != "":
  if s.endswith(dic[0]):
    s = s[:-5]
  elif s.endswith(dic[1]):
    s = s[:-7]
  elif s.endswith(dic[2]):
    s = s[:-5]
  elif s.endswith(dic[3]):
    s = s[:-6]
  else:
    break
else:
  print("YES")
  exit()
print("NO")

Solution (Python):

def erase_end(string):
    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]
    elif string == "":
        string = "YES"
    else:
        string = "NO"
    return string
    
string = input()

while True:
    if string == "YES" or string == "NO":
        break
    string = erase_end(string)

print(string)

Solution (Python):
s=input()
s=s.split('eraser')
if s.count('')>0:
  s.remove('')
s=''.join(s)
s=s.split('erase')
if s.count('')>0:
  s.remove('')
s=''.join(s)
s=s.split('dreamer')
if s.count('')>0:
  s.remove('')
s=''.join(s)
s=s.split('dream')
if s.count('')>0:
  s.remove('')
s=''.join(s)
if s=='':
  print('YES')
else:
  print('NO')

Solution (Python):
S=input()
i=len(S)
while(1):
    flag=0
    if i==0:
        print('YES')
        break
    if 0<=i-5:
        if S[i-5:i]=='dream' or S[i-5:i]=='erase':
            i-=5
            flag=1
    if 0<=i-6:
        if S[i-6:i]=='eraser':
            i-=6
            flag=1
    if 0<=i-7:
        if S[i-7:i]=='dreamer':
            i-=7
            flag=1
    if flag==0:
        print('NO')
        break

Solution (Python):
S = input()
A,B,C,D='dream','dreamer','erase','eraser'
flag = -1

while(1):
    if len(S)==0:
        flag = 1
        break
    elif S[-7:]==B:
        S=S[:-7]
    elif S[-5:]==A:
        S=S[:-5]
    elif S[-6:]==D:
        S=S[:-6]
    elif S[-5:]==C:
        S=S[:-5]
    else:
        break

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

Solution (Python):
s = input()
t = ["maerd","remaerd","esare","resare"]
s = s[::-1]
while True:
    if len(s) == 0:
        print("YES")
        break
    elif 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")
        break

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.split("eraser")
S="".join(S)
S=S.split("erase")
S="".join(S)
S=S.split("dreamer")
S="".join(S)
S=S.split("dream")
S="".join(S)
print("YES") if S=="" else print("NO")

Solution (Python):
s = input()

def calc(s):
    if s == "":
        return print("YES")
    if s.find("dreameraser") != -1:
        s = s.replace("dreameraser", "")
        return calc(s)
    elif s.find("dreamerase") != -1:
        s = s.replace("dreamerase", "")
        return calc(s)        
    elif s.find("dreamer") != -1:
        s = s.replace("dreamer", "")
        return calc(s)
    elif s.find("dream") != -1:
        s = s.replace("dream", "")
        return calc(s)
    elif s.find("eraser") != -1:
        s = s.replace("eraser", "")
        return calc(s)
    elif s.find("erase") != -1:
        s = s.replace("erase", "")
        return calc(s)
    return print("NO")

calc(s)

Solution (Python):
T = input()
lenT = len(T)
ac = T.count("eraser")
T = T.replace("eraser","xxxxxx",ac)
cc = T.count("erase")
T = T.replace("erase","xxxxx",cc)
bc = T.count("dreamer")
T = T.replace("dreamer","xxxxxxx",bc)
dc = T.count("dream")
T = T.replace("dream","xxxxx",dc)
D = T.count("x")
if D == lenT:
  print("YES")
elif lenT > D:
  print("NO")
else :
  print("error")

Solution (Python):
S=str(input()) 
Smojisuu=len(S)
c=S.count("eraser")
S=S.replace("eraser","xxxxxx",c)
d=S.count("erase")
S=S.replace("erase","xxxxx",d)
e=S.count("dreamer")
S=S.replace("dreamer","xxxxxxx",e)
f=S.count("dream")
S=S.replace("dream","xxxxx",f)
g=S.count("x")
if len(S)>g:
  print("NO")
elif len(S)==g:
  print("YES")
else:
  print("error")

Solution (Python):
S=str(input()) 
Smojisuu=len(S)
c=S.count("eraser")
S=S.replace("eraser","xxxxxx",c)
d=S.count("erase")
S=S.replace("erase","xxxxx",d)
e=S.count("dreamer")
S=S.replace("dreamer","xxxxxxx",e)
f=S.count("dream")
S=S.replace("dream","xxxxx",f)
g=S.count("x")
if len(S)>g:
  print("NO")
elif len(S)==g:
  print("YES")
else:
  print("error")

Solution (Python):
import re

def main():
    s = input()
    pat = re.compile(r'^(?:dream|dreamer|erase|eraser)*$')
    if pat.match(s):
        print('YES')
    else:
        print('NO')

main()

Solution (Python):
str = input()
moji = ('resare', 'esare', 'remaerd', 'maerd')
str = str[::-1]
for i in range(len(moji)):
    str = str.replace(moji[i], "")
    
print("YES") if str == "" else print("NO")