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










"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:
    return a
  return gcd_(a,a % b) 
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


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

def main():
  s = input().replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')
  print('YES' if len(s) == 0 else 'NO')
if __name__ == '__main__':
  main()

Solution (Python):
import re
S = input()
'''
メタ文字：
^ = 文字列の先頭、
| = OR
+ = 直前のパターンを1回以上繰り返し、
$ = 文字列の末尾
'''
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):
S = input()

S = S[::-1]

def solve(s):
  words = [
    'dreamer'[::-1],
    'eraser'[::-1],
    'dream'[::-1],
    'erase'[::-1],
  ]
  while s:
    for w in words:
      if s.startswith(w):
        s = s[len(w):]
        break
    else:
      return False
  return True

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

Solution (Python):
if __name__ == "__main__":
    
    
    S = input()
    S = S[::-1]
    while True:
        if S == '':
            print("YES")
            break
        elif S.startswith('dreamer'[::-1]):
            S = S[7:]
        elif S.startswith('eraser'[::-1]):
            S = S[6:]
        elif S.startswith('dream'[::-1]) or S.startswith('erase'[::-1]):
            S = S[5:]
        else:
            print("NO")
            break

Solution (Python):
S = input()


while len(S) > 8:
    if S.endswith('dream'):
        S = S[:-5]
    elif S.endswith('dreamer'):
        S = S[:-7]
    elif S.endswith('erase'):
        S = S[:-5]
    elif S.endswith('eraser'):
        S = S[:-6]
    else:
        print('NO')
        break
else:
    if S in ['dream', 'dreamer', 'erase', 'eraser']:
        print('YES')
    else:
        print('NO')

Solution (Python):
s = input()

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

s0 = s
while len(s0) > 0:
    is_divided = False
    for divide in divides:
        if len(s0) > 7 and s0[-len(divide):] == divide:
            s0 = s0[:-len(divide)]
            is_divided = True
            break
        elif s0 == divide:
            s0 = ''
            is_divided = True
            break
        
    if not is_divided:
        break

if len(s0) > 0:
    print('NO')
else:
    print('YES')

Solution (Python):
import sys

s=input()

lens=len(s)

while lens>0:
    lens0=lens
    if s[lens-7:lens]=="dreamer":
        lens=lens-7
    elif s[lens-5:lens]=="dream":
        lens=lens-5
    elif s[lens-6:lens]=="eraser":
        lens=lens-6
    elif s[lens-5:lens]=="erase":
        lens=lens-5
    if lens0==lens:
        print("NO")
        sys.exit()

print("YES")

Solution (Python):
S = input()
a = ['maerd', 'remaerd', 'esare', 'resare']
tmp =''
for s in S[::-1]:
    tmp += s
    if tmp in a: tmp=''
print('YES' if len(tmp)==0 else'NO')

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
size = len(s)
cnt = size
flag = False
for i in range(size):
    if s[cnt - 1] == 'r':
        if cnt >= 7:
            if s[cnt - 7:cnt] == 'dreamer':
                cnt -= 7
            elif s[cnt - 6:cnt] == 'eraser':
                cnt -= 6
            else:
                flag = True
                break
        elif cnt >= 6:
            if s[cnt - 6:cnt] == 'eraser':
                cnt -= 6
            else:
                flag = True
                break
        else:
            flag = True
            break
    elif s[cnt - 1] == 'e' and cnt >= 5:
        if s[cnt - 5:cnt] == 'erase':
            cnt -= 5
        else:
            flag = True
            break
    elif s[cnt - 1] == 'm' and cnt >= 5:
        if s[cnt - 5:cnt] == 'dream':
            cnt -= 5
        else:
            flag = True
            break
    else:
        flag = True
        break
    if cnt == 0:
        break
    elif cnt < 0:
        flag = True
        break
if flag:
    print('NO')
else:
    print('YES')

Solution (Python):
S = input()
day_dream_word = ["eraser", "erase", "dreamer", "dream"]
for replace_word in day_dream_word:
  S = S.replace(replace_word, "")

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

Solution (Python):
S = input()[::-1]
day_dream_word = ["dreamer", "dream", "eraser", "erase"]
day_dream_word = list(map(lambda s: s[::-1], day_dream_word))
T = ""
Tindex = 0
res = False
partial_res = True
while not res and partial_res:
  partial_res = False
  for add_word in day_dream_word:
    nextTindex = Tindex + len(add_word)
    
    if S[Tindex:nextTindex] == add_word:
      if len(S) == nextTindex:
        res = True
        break
      else:
        partial_res = True
        break
  Tindex = nextTindex

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

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

Solution (Python):










  











      









s = input()
 
while len(s) > 4:
    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' if len(s) > 0 else 'YES')

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

S = S[::-1]

t = []
i = 0
T = ''

if len(S) < 3:
    print('No')
else:
    while i<len(S):
        if S[i] == 'm' and S[i+1] == 'a' and S[i+2] == 'e':
            letter = 'dream'
            i += 4
        elif S[i] ==  'r' and S[i+1] == 'e' and S[i+2] == 'm':
            letter = 'dreamer'
            i += 6
        elif S[i] == 'e' and S[i+1] == 's' and S[i+2] == 'a':
            letter = 'erase'
            i += 4
        elif S[i] == 'r' and S[i+1] == 'e' and S[i+2] == 's':
            letter = 'eraser'
            i += 5
        else:
            break
        i += 1
        t.append(letter)



    for x in t[::-1]:
        T += x



    if S == T[::-1]:
        print('YES')
    else:
        print('NO')

Solution (Python):
s = input()

while len(s) != 0:
    if s[:6] == 'dreamd' or s[:8] == 'dreamera':
        s = s[5:]
    elif s[:7] == 'dreamer':
        s = s[7:]
    elif s[:6] == 'erased' or s[:6] == 'erasee':
        s = s[5:]
    elif s[:6] == 'eraser':
        s = s[6:]
    elif s[:5] == 'dream' or s[:5] == 'erase':
        s = s[5:]
    else:
        print('NO')
        exit()
print('YES')

Solution (Python):
s=input()
while len(s)>7:
    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:
        break
if s in ["dreamer","dream","eraser","erase"]:
    print("YES")
else:
    print("NO")

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

while i > 0:
    if S[i - 5 : i] in words:
        i = i - 5
    elif S[i - 6 : i] in words:
        i = i - 6
    elif S[i - 7 : i] in words:
        i = i - 7
    else:
        break

if i > 0:
    print("NO")
else:
    print("YES")

Solution (Python):
s=input().replace("eraser","0").replace("erase","0").replace("dreamer","0").replace("dream","0").replace("0", "")
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()
S = S[::-1]





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

def func():
    i = 0
    while True:
        flag = False
        for t in t_sub:
            ret = (S.find(t, i) == i)
            
            if ret ==True:
                if (i+len(t) == len(S)):
                    return "YES"
                else:
                    i += len(t)
                    flag = True
                    break
        if flag != True:
            return "NO"

print(func())

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

end = len(s)

while 0 < end:
    if s[end-5:end] in check:
        end -= 5
    elif s[end-6:end] in check:
        end -= 6
    elif s[end-7:end] in check:
        end -= 7
    else:
        print('NO')
        exit()
print('YES')

Solution (Python):


S=input()

S=S[::-1]
s1="maerd"
s2="remaerd"
s3="esare"
s4="resare"
i=0

while i<len(S):
    if S[i:i+5] == s1 or S[i:i+5] == s3:
        i+=5
    elif S[i:i+6] == s4:
        i+=6
    elif S[i:i+7] ==s2:
        i+=7
    else:
        print("NO")
        break
else:
    print("YES")

Solution (Python):
def main():
    Ss = input()
    S = list(Ss)
    now = 0
    T = ''
    Sr = []
    for i in range(1,len(S)+1):
        Sr.append(S[-i])
    ans = []
    while True:
        tmp5 = Sr[now:now+5]
        tmp6 = Sr[now:now+6]
        tmp7 = Sr[now:now+7]
        if tmp5[0] == 'e' and tmp5 == ['e','s','a','r','e']:
            ans.append('erase')
            now += 5
        elif tmp5[0] == 'm' and tmp5 == ['m','a','e','r','d']:
            ans.append('dream')
            now += 5
        elif tmp6[0] == 'r' and tmp6 == ['r','e','s','a','r','e']:
            ans.append('eraser')
            now += 6
        elif tmp7[0] == 'r' and tmp7 == ['r','e','m','a','e','r','d']:
            ans.append('dreamer')
            now += 7
        else:
            print('NO')
            
            return

        if now >= len(S):
            break
    for i in range(1,len(ans)+1):
        T += ans[-i]
    if Ss == T:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    Ss = input()
    S = list(Ss)
    now = 0
    T = ''
    Sr = []
    for i in range(1,len(S)+1):
        Sr.append(S[-i])
    ans = []
    while True:
        tmp5 = Sr[now:now+5]
        tmp6 = Sr[now:now+6]
        tmp7 = Sr[now:now+7]
        if tmp5[0] == 'e' and tmp5 == ['e','s','a','r','e']:
            ans.append('erase')
            now += 5
        elif tmp5[0] == 'm' and tmp5 == ['m','a','e','r','d']:
            ans.append('dream')
            now += 5
        elif tmp6[0] == 'r' and tmp6 == ['r','e','s','a','r','e']:
            ans.append('eraser')
            now += 6
        elif tmp7[0] == 'r' and tmp7 == ['r','e','m','a','e','r','d']:
            ans.append('dreamer')
            now += 7
        else:
            print('NO')
            
            return

        if now >= len(S):
            break
    for i in range(1,len(ans)+1):
        T += ans[-i]
    if Ss == T:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

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

Solution (Python):

s = list(str(input()))

s = s[::-1]
n = len(s)


ans = "YES"
i = 0
while i < n:
    
    if i + 7 <= n and s[i:i+7] ==  ['r', 'e', 'm', 'a', 'e', 'r', 'd']:
        i += 7
    elif i + 6 <= n and s[i:i+6] == ['r', 'e', 's', 'a', 'r', 'e']:
        i += 6
    elif i + 5 <= n and s[i:i+5] == ['m', 'a', 'e', 'r', 'd']:
        i += 5
    elif i + 5 <= n and s[i:i+5] == ['e', 's', 'a', 'r', 'e']:
        i += 5
    else:
        ans = "NO"
        
        break
print(ans)

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

Solution (Python):
s = input()[::-1]
L = set(["dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1]])
pos = 0
while pos < len(s):
    if s[pos] == "e" or s[pos] == "m":
        if s[pos: pos + 5] in L:
            pos += 5
        else:
            print("NO")
            exit()
    elif s[pos] == "r":
        if s[pos: pos + 6] in L:
            pos += 6
        elif s[pos: pos + 7] in L:
            pos += 7
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()

print("YES")

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

Solution (Python):
S = input()

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

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

Solution (Python):
S = input()[::-1]
W = [s[::-1] for s in ('dream', 'dreamer', 'erase', 'eraser')]

def isOk():
    now = 0
    while now < len(S):
        for w in W:
            if S[now: now + len(w)] == w:
                now += len(w)
                break
        else:
            return False
    return True

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

Solution (Python):
s = input()[::-1]
n = len(s)
l = 0
ok = True
while l <n:
    ok_list = ["maerd","remaerd","resare","esare"]
    if s[l:l+5] in ok_list:
        l +=5
    elif s[l:l+6] in ok_list:
        l+=6
    elif s[l:l+7] in ok_list:
        l+=7
    else:
        ok = False
        break
if ok:print('YES')
else:print('NO')

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

Solution (Python):


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

def check(w):
    return word in words

while s:
    word = ''.join([s.pop() for _ in range(5)][::-1])
    if check(word): continue
    
    for _ in range(2):
        word = s.pop() + word
        if check(word): break
    else:
        print('NO')
        exit()
print('YES')

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

left = 0
right = 5
ok = True
while left <n:
    if left >n-1 or right > n:break
    if s[left:right] == "dream":
        
        if s[right:right+2] == "er" and s[right:right+5] != "erase" and s[right:right+6] != "eraser": 
            left = right+2
            right = min(left+5,n)
        else:
            left = right
            right = min(n,left+5)
    
    elif s[left:right] == "erase":
        
        if right < n and s[right] == 'r':
         
            left = right+1
            right = min(n,left+5)
        else:
            left = right
            right = min(n,left+5)
    else:
        ok = False
        break
if ok:print("YES")
else:print("NO")

Solution (Python):
s = input()

while len(s) > 4:
    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' if len(s) > 0 else 'YES')

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

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

Solution (Python):
def resolve():

    S=str(input())[::-1]
    flag='YES'
    i=0

    while i<len(S):
        if S[i:i+5]=='maerd' or S[i:i+5]=='esare':
            i+=5
            continue
        if S[i:i+6]=='resare':
            i+=6
            continue
        if S[i:i+7]=='remaerd':
            i+=7
        else:
            flag='NO'
            break

    print(flag)









resolve()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

s = STR()
i = 0
l = len(s)
debug(l)
while i < l:
    debug(i, s[i])
    if i + 4 >= l:
        print('NO')
        exit()
    if s[i] == 'd':
        if s[i:i + 5] != 'dream':
            print('NO')
            exit()
        if i + 5 >= l:
            i += 5
        elif i + 6 == l - 1 and s[i:i + 7] == 'dreamer':
            i += 7
        elif i + 6 < l and s[i:i + 7] == 'dreamer':
            if s[i + 7] == 'a':
                i += 5
            else:
                i += 7
        else:
            i += 5
    elif s[i] == 'e':
        if s[i:i + 5] != 'erase':
            print('NO')
            exit()
        if i + 5 >= l:
            i += 5
        elif i + 5 == l - 1 and s[i:i + 6] == 'eraser':
            i += 6
        elif i + 6 < l and s[i:i + 6] == 'eraser':
            if s[i + 6] == 'a':
                i += 5
            else:
                i += 6
        else:
            i += 5
    else:
        print('NO')
        exit()
print('YES')

Solution (Python):
S = input()
R = ''.join(list(reversed(list(S))))


cursol=0
while cursol <= len(S)-1:
    if R[cursol:cursol+5]=='maerd':
        cursol += 5
    elif R[cursol:cursol+7]=='remaerd':
        cursol += 7
    elif R[cursol:cursol+5]=='esare':
        cursol += 5
    elif R[cursol:cursol+6]=='resare':
        cursol += 6
    else:
        print('NO')
        break
else:
    print('YES')

Solution (Python):
s = input()

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

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

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

Solution (Python):
S=input()
ans = True
while S:
    if S.endswith("dream"): S = S[:-len("dream")]
    elif S.endswith("dreamer"): S = S[:-len("dreamer")]
    elif S.endswith("erase"): S = S[:-len("erase")]
    elif S.endswith("eraser"): S = S[:-len("eraser")]
    else:
        ans = False
        break
print('YES' if ans else 'NO')

Solution (Python):
S = input()

ops = ('dream', 'dreamer', 'erase', 'eraser')

import sys
sys.setrecursionlimit(200000)

memo = [None] * (len(S) + 1)

def dp(pos):
    if pos > len(S): return 0
    elif pos == len(S): return 1
    elif memo[pos] != None: return memo[pos]
    
    ret = 0
    for op in ops:
        
        if S[pos : pos + len(op)] == op:
            ret = max(ret, dp(pos + len(op)))
    
    memo[pos] = ret
    return ret

if dp(0) == 1:
    print('YES')
else:
    print('NO')

Solution (Python):
def ABC67_B():
    N, K = LI()
    L = LI()
    L.sort(reverse=True)
    ans = sum(L[:K])
    print(ans)
    return

def ABC100_C():
    def factorization_2(n):
        arr = defaultdict(int)
        temp = n
        i = 2
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
        if temp != 1:
            arr[temp] = 1
        if arr == []:
            arr[n] = 1
        return arr[2]
    N = I()
    A = LI()
    ans = 0
    for a in A:
        ans += factorization_2(a)
    print(ans)
    return

def ARC68_C():
    X = I()
    ans = 0
    ans += 2*(X//11)
    rest = X%11
    if rest>0:
        ans += 1
    if rest>=7:
        ans += 1
    print(ans)
    return

def ABC49_C():
    S = SI()
    T = {"maerd","remaerd","esare","resare"}
    stack = ""
    for s in S[::-1]:
        stack += s
        if stack in T:
            stack = ""
    if stack:
        print("NO")
    else:
        print("YES")
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    ABC49_C()

"""

"""

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 not S:
    print("YES")
else:
    print("NO")

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


if __name__ == '__main__':
    main()

Solution (Python):
def solve():
    S = input()
    N = len(S)
    Srev = []
    for i in reversed(range(N)): Srev.append(S[i])
    Srev = "".join(Srev)
    ti = 0
    while ti < N:
        if Srev[ti] == "m":
            if Srev[ti:min(N, ti + 5)] == "maerd": ti += 5
            else:
                print("NO")
                break
        elif Srev[ti] == "e":
            if Srev[ti:min(N, ti + 5)] == "esare": ti += 5
            else:
                print("NO")
                break
        elif Srev[ti] == "r":
            if Srev[ti:min(N, ti + 6)] == "resare": ti += 6
            elif Srev[ti:min(N, ti + 7)] == "remaerd": ti += 7
            else:
                print("NO")
                break
        else:
            print("NO")
            break
    else: print("YES")


    return 0

if __name__ == "__main__":
    solve()

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

Solution (Python):
rev_s = ''.join(list(reversed(input())))
rev_w = ['maerd', 'remaerd', 'esare', 'resare', 'END']

while rev_s != '':
    for item1 in rev_w:
        if rev_s.find(item1) == 0:
            rev_s = rev_s[len(item1):]
            break
    if item1 == 'END':
        break

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

Solution (Python):
S = input()

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

S = S[::-1]
for i in range(4):
    T[i] = T[i][::-1]

can = True
i = 0
while i < len(S):
    can2 = False
    for t in T:
        if S[i:i + len(t)] == t:
            can2 = True
            i += len(t) - 1
    if can2 == False:
        can = False
        break
    i += 1

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

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

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

Solution (Python):
S = input()

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

Solution (Python):
moji = 0
S = input()
Slen = len(S)
check = ["dreamer","eraser","dream","erase"]
flag = True
while flag:
  flag = False
  for i in range(4):
    if len(S) - moji >= len(check[i]) and S[Slen - moji - len(check[i]):Slen - moji] == check[i]:
      moji += len(check[i])
      flag = True
      break
if moji == len(S):
  print("YES")
else:
  print("NO")

Solution (Python):
from collections import deque

w = ["dream", "erase", "dreamer", "eraser"]
s = deque(list(input()))
c = 1
while s:
    u = deque()
    p = s.pop()
    u.append(p)
    if p == "r":
        for _ in range(5):
            u.appendleft(s.pop())
            if len(s) == 0:
                break
        if "".join(u) != w[3] and len(s) != 0:
            u.appendleft(s.pop())
            if "".join(u) != w[2]:
                c = 0
    else:
        for _ in range(4):
            u.appendleft(s.pop())
            if len(s) == 0:
                break
        if not "".join(u) in w:
            c = 0
    if c == 0:
        break
print("YES" if c == 1 else "NO")

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

Solution (Python):
from collections import deque
S=input()
N=len(S)
i=0
flag=1
ans=[]
buf=""
while i<N:
    if (i+9<N)and((S[i]=="d")and(S[i+1]=="r")and(S[i+2]=="e")and(S[i+3]=="a")and(S[i+4]=="m")and(S[i+5]=="e")and(S[i+6]=="r")and(S[i+7]=="a")and(S[i+8]=="s")and(S[i+9]=="e")):
        if i+10==N:
            break
        elif (S[i+10]=="d")or(S[i+10]=="e"):
            i=i+10
        elif (S[i+10]=="r"):
            i=i+5
        else:
            flag=0
            break
    elif (i+6<N)and((S[i]=="d")and(S[i+1]=="r")and(S[i+2]=="e")and(S[i+3]=="a")and(S[i+4]=="m")and(S[i+5]=="e")and(S[i+6]=="r")):
        if i+7==N:
            break
        elif (S[i+7]=="d")or(S[i+7]=="e"):
            i=i+7
        else:
            flag=0
            break
    elif (i+4<N)and((S[i]=="d")and(S[i+1]=="r")and(S[i+2]=="e")and(S[i+3]=="a")and(S[i+4]=="m")):
        if i+5==N:
            break
        elif (S[i+5]=="d"):
            i=i+5
        else:
            flag=0
            break
    elif (i+5<N)and((S[i]=="e")and(S[i+1]=="r")and(S[i+2]=="a")and(S[i+3]=="s")and(S[i+4]=="e")and(S[i+5]=="r")):
        if i+6==N:
            break
        elif (S[i+6]=="e")or(S[i+6]=="d"):
            i=i+6
        else:
            flag=0
            break
    elif (i+4<N)and((S[i]=="e")and(S[i+1]=="r")and(S[i+2]=="a")and(S[i+3]=="s")and(S[i+4]=="e")):
        if i+5==N:
            break
        elif (S[i+5]=="e")or(S[i+5]=="d"):
            i=i+5
        else:
            flag=0
            break
    else:
        flag=0
        break
    
    
if flag==1:
    print("YES")
else:
    print("NO")

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    s=SI()
    for t in ["eraser","erase","dreamer","dream"]:
        s=s.replace(t,"")
    if s:print("NO")
    else:print("YES")

main()

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()
subT = ['eraser', 'erase', 'dreamer', 'dream', ]
for i in subT:
    S = S.replace(i, '')

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

Solution (Python):




import sys
input = sys.stdin.readline



def main():
    S = input().rstrip()

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

    res = 'YES'

    pre = S
    now = S

    while True:
        for i in range(4):
            word = words[i]
            N = len(word)
            M = len(now)
            if N <= M:
                r = now[M-N:]
                if r == word:
                    now = now[:M-N]
        if now == '':
            break
        elif now == pre:
            res = 'NO'
            break
        else:
            pre = now

    print(res)



main()

Solution (Python):
def hantei(s, h):
    try:
        slen = len(s)
        hlen = len(h)
        res = s.index(h, slen - hlen, slen + 1)
        return res
    except ValueError as e:
        return -1


def resolve():
    s = input()
    a = 'dream'
    b = 'dreamer'
    c = 'erase'
    d = 'eraser'
    while True:
        
        
        D = hantei(s, d)
        if D > -1:
            s = s[:-len(d)]
            continue
        B = hantei(s, b)
        if B > -1:
            s = s[:-len(b)]
            continue
        C = hantei(s, c)
        if C > -1:
            s = s[:-len(c)]
            continue
        A = hantei(s, a)
        if A > -1:
            s = s[:-len(a)]
            continue
        if len(s) == 0:
            print('YES')
        else:
            print('NO')
        break
        
resolve()

Solution (Python):
X=input()

for i in range(len(X)):
    if X[-7:] == "dreamer":
        X = X[:-7]
    elif X[-6:] == "eraser":
        X = X[:-6]
    elif X[-5:] == "dream":
            X = X[:-5]
    elif X[-5:] == "erase":
        X = X[:-5]

print("YES" if X=="" else "NO")

Solution (Python):
import re

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

Solution (Python):
S=input().rstrip()
S=S[::-1]
T=["dream","dreamer","erase","eraser"]
for i in range(len(T)):
  T[i]=T[i][::-1]
while len(S):
  flag=False
  for t in T:
    if S.startswith(t):
      S=S[len(t):]
      flag=True
  if not flag: break
if len(S)==0:
  print("YES")
else:
  print("NO")

Solution (Python):
S = input()

R=''.join(list(reversed(S)))

N=len(S)

cursol=0

while True:
    if R[cursol:cursol+5] == 'maerd':
        cursol += 5
    elif R[cursol:cursol+5] == 'esare':
        cursol += 5
    elif R[cursol:cursol+7] == 'remaerd':
        cursol += 7
    elif R[cursol:cursol+6] == 'resare':
        cursol += 6
    else:
        print('NO')
        break
    if cursol == N:
        print('YES')
        break