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()
import sys
while True:
    if(len(S)==0):
        print("YES")
        sys.exit()
    if S.endswith("dreamer"):
        S = S[:-7]
    elif S.endswith("eraser"):
                S = S[:-6]
    elif S.endswith("dream"):
        S = S[:-5]
    elif S.endswith("erase"):
        S = S[:-5]
    else:
        print("NO")
        sys.exit()

Solution (Python):
import sys
input = sys.stdin.readline

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

    n = len(S)

    while n > 0:
        if S[n - 5:n] == "dream":
            n -= 5
        elif S[n - 5:n] == "erase":
            n -= 5
        elif S[n - 7:n] == "dreamer":
            n -= 7
        elif S[n - 6:n] == "eraser":
            n -= 6
        else:
            print("NO")
            return
    else:
        print("YES")


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline

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

    s = list(S)
    n = len(s)

    while n > 0:
        if "".join(s[n - 5:n]) == "dream":
            n -= 5
        elif "".join(s[n - 5:n]) == "erase":
            n -= 5
        elif "".join(s[n - 7:n]) == "dreamer":
            n -= 7
        elif "".join(s[n - 6:n]) == "eraser":
            n -= 6
        else:
            print("NO")
            return
    else:
        print("YES")


if __name__ == '__main__':
    main()

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

while len(S) != 0:
    if S[len(S)-5:] == lst[0]:
        S = S[:len(S)-5]
    elif S[len(S)-7:] == lst[1]:
        S = S[:len(S)-7]
    elif S[len(S)-5:] == lst[2]:
        S = S[:len(S)-5]
    elif S[len(S)-6:] == lst[3]:
        S = S[:len(S)-6]
    else:
        break

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

Solution (Python):
s = input()
res = -1

while len(s) > 0 :

    if len(s) - 5 >= 0 and s[len(s)-5:len(s)] == "erase" :
      
      if len(s) - 5 > 0 :
        s = s[0:len(s)-5]
      else :
          res = 1
          s = s[0:len(s)-5]

    elif len(s) - 5 >= 0 and s[len(s)-5:len(s)] == "dream" :
      
      if len(s) - 5 > 0 :
        s = s[0:len(s)-5]
      else :
          res = 1
          s = s[0:len(s)-5]

    elif len(s) - 6 >= 0 and s[len(s)-6:len(s)] == "eraser" :
      
      if len(s) - 6 > 0 :
        s = s[0:len(s)-6]
      else :
          res = 1
          s = s[0:len(s)-6]

    elif len(s) - 7 >= 0 and s[len(s)-7:len(s)] == "dreamer" :
      
      if len(s) - 7 > 0 :
        s = s[0:len(s)-7]
      else :
          res = 1
          s = s[0:len(s)-7]

    else :
        res = 0
        s = ""


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

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

arr = ['dream', 'dreamer', 'erase', 'eraser']
arr_reversed = list(map(lambda item: item[::-1], arr))
able = True
t = ""
while s_reverse != t and able:
    for i in range(len(arr_reversed)):
        item = arr_reversed[i]
        if s_reverse[len(t): len(t) + len(item)] == item:
            t += item
            break
        elif i == len(arr_reversed) - 1:
            able = False

print("YES" if s_reverse == t else "NO")

Solution (Python):
S=input()[::-1]
W=("dream"[::-1],"dreamer"[::-1],"erase"[::-1],"eraser"[::-1])
ind=0
while ind<len(S):
  for w in W:
    if S[ind:ind+len(w)]==w:
      ind+=len(w)
      break
  else:
    print("NO")
    break
else:
  print("YES")

Solution (Python):
S = input()

num_5 = ["dream", "erase"]
num_6 = ["eraser"]
num_7 = ["dreamer"]
while len(S) != 0:
    if S[0:7] in num_7:
        if S[5:11] in num_6:
            S = S[5:]
        elif S[5:10] in num_5:
            S = S[5:]
        else:
            S = S[7:]
    elif S[0:6] in num_6:
        if S[5:10] in num_5:
            S = S[5:]
        else:
            S = S[6:]
    elif S[0:5] in num_5:
        S = S[5:]
    else:
        print("NO")
        exit()

print("YES")

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

while t:
    if t[-7:] == b:
        t = t[:-7]
    elif t[-6:] == d:
        t = t[:-6]
    elif t[-5:] in (a, c):
        t = t[:-5]
    else:
        break

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

Solution (Python):
s = input()
a = 0
t = ("")

while a < len(s):
    if s[a+0:a+5] == ("dream") and s[a+5+0:a+5+2] != ("er"):
        a += 5

    elif s[a+0:a+5] == ("dream") and s[a+5+0:a+5+2] == ("er"):
        if s[a+7+0:a+7+3] != ("ase"):
            a += 7

        elif s[a+7+0:a+7+3] == ("ase") and s[a+10+0:a+10+1] != ("r"):
            a += 10

        elif s[a+7+0:a+7+3] == ("ase") and s[a+10+0:a+10+1] == ("r"):
            a += 11

    elif s[a+0:a+5] == ("erase") and s[a+5+0:a+5+1] != ("r"):
        a += 5

    elif s[a+0:a+5] == ("erase") and s[a+5+0:a+5+1] == ("r"):
        a += 6

    else:
        break

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

Solution (Python):
s = input().strip()
words = ["dream", "dreamer", "erase", "eraser"]
i = len(s)
while i > 0:
    b = False
    for w in words:
        if w == s[i-len(w):i]:
            b = True
            i -= len(w)
            break
    if not b:
        break

print("YES" if i == 0 else "NO")

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

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

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

word_list = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
while i != len(s):
    a = s[i:i+5]
    a = ''.join(a)
    b = s[i:i+6]
    b = ''.join(b)
    c = s[i:i+7]
    c = ''.join(c)
    if a in word_list:
        i += 5
    elif b in word_list:
        i += 6
    elif c in word_list:
        i += 7
    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","-")
S = S.replace("-","")
if len(S) == 0:
    print("YES")
else:
    print("NO")

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

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





t=re.split('maerd|remaerd|esare|resare', s)


if len(t)==t.count(''):
    print('YES')
else:
    print('NO')

Solution (Python):
import sys
input = sys.stdin.readline
S = input().rstrip()

while S:
    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:
        print("NO")
        sys.exit()
print("YES")

Solution (Python):
s = input()

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



while True:
    if s[-5:] in li:
        s = s[0:-5]
    elif s[-6:] in li:
        s = s[0:-6]
    elif s[-7:] in li:
        s = s[0:-7]
    else:
        print('NO')
        exit()
    if s=='':
        break
print('YES')

Solution (Python):
s = input()

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

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

Solution (Python):
import collections
def solve(S):
    r_ix = len(S)
    while len(S):
        is_hit = False

        for word in ['dream', 'dreamer', 'erase', 'eraser']:
            l_ix = r_ix - len(word)
            if S[l_ix:r_ix] == word:
                S = S[:l_ix]
                r_ix = l_ix
                is_hit = True

        if not is_hit:
            return "NO"
                
    return "YES"


def solve2(S):
    word = ['dream', 'dreamer', 'erase', 'eraser']
    buf = []
    for ch in S:
        buf.append(ch)
    curchar = ''
    while len(buf) > 0:
        c = buf.pop()
        curchar = c + curchar
        if curchar in word:
            curchar = ''

    if curchar == '':
        return "YES"

    return "NO"

if __name__ == "__main__":
    S = input()
    print(solve(S))

Solution (Python):
import collections
def solve(S):
    r_ix = len(S)
    while len(S):
        is_hit = False

        for word in ['dream', 'dreamer', 'erase', 'eraser']:
            l_ix = r_ix - len(word)
            if S[l_ix:r_ix] == word:
                S = S[:l_ix]
                r_ix = l_ix
                is_hit = True

        if not is_hit:
            return "NO"
                
    return "YES"


def solve2(S):
    word = ['dream', 'dreamer', 'erase', 'eraser']
    buf = []
    for ch in S:
        buf.append(ch)
    curchar = ''
    while len(buf) > 0:
        c = buf.pop()
        curchar = c + curchar
        if curchar in word:
            curchar = ''

    if curchar == '':
        return "YES"

    return "NO"

if __name__ == "__main__":
    S = input()
    print(solve2(S))

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

Solution (Python):
s = input()
s2 = s.split('eraser')
s3 = ''.join(s2).split('erase')
s4 = ''.join(s3).split('dreamer')
s5 = ''.join(s4).split('dream')
s5 = list(set(s5))
if len(s5) == 1 and s5[0] == '':
  print("YES")
else:
  print("NO")

Solution (Python):
s=input()
s=s.replace('eraser','')
s=s.replace('erase','')
s=s.replace('dreamer','')
s=s.replace('dream','')
 
if 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','')

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

Solution (Python):
s = input()
flag = True
while flag:
    if s=='':
        flag==False
    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:
        break


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

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

Solution (Python):
S = list(input())
S.reverse()
N = len(S)
i = 0
ans = "YES"


while i != N:
    if "".join(map(str,S[i:i+5])) == "maerd":
        i += 5
    elif "".join(map(str,S[i:i+5])) == "esare":
        i += 5
    elif "".join(map(str,S[i:i+6])) == "resare":
        i += 6
    elif "".join(map(str,S[i:i+7])) == "remaerd":
        i += 7
    else:
        ans = "NO"
        break

print(ans)

Solution (Python):
S=input()
W=("dream","dreamer","erase","eraser")
s=[0]
while s:
  i=s.pop()
  if i==len(S):
    print("YES")
    break
  for w in W:
    if S[i:i+len(w)]==w:
      s.append(i+len(w))
else:
  print("NO")

Solution (Python):
s_1 = "dream"
s_2 = "dreamer"
s_3 = "erase"
s_4 = "eraser"

S = input()

while True:
  if S[-5:] == s_1:
    S = S[:-5]
  elif S[-7:] == s_2:
    S = S[:-7]
  elif S[-5:] == s_3:
    S = S[:-5]
  elif S[-6:] == s_4:
    S = S[:-6]
  else :
    break

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

Solution (Python):

"""AtCoder Beginner Contest 049: C - 白昼夢 / Daydream
https://atcoder.jp/contests/abc049/tasks/arc065_a
"""

__author__ = 'bugttle <bugttle@gmail.com>'

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


def match_word(S):
    for word in WORDS:
        if S.endswith(word):
            return word
    return None


def check(S):
    while True:
        word = match_word(S)
        if word is None:
            return 'NO'
        S = S[:S.rfind(word)]
        if S == '':
            return 'YES'


def main():
    S = input()
    print(check(S))


if __name__ == '__main__':
    main()

Solution (Python):
s = input()

while s:
    if s.endswith('dream'):
        s = s[:-5]
        continue
    if s.endswith('erase'):
        s = s[:-5]
        continue
    if s.endswith('dreamer'):
        s = s[:-7]
        continue
    if s.endswith('eraser'):
        s = s[:-6]
        continue
    print('NO')
    exit()
print('YES')

Solution (Python):
S = input()

while True:
    for word in ('dream', 'dreamer', 'erase', 'eraser'):
        if S.endswith(word):
            S = S[:len(S) - len(word)]
            break
    else:
        print('NO')
        break
    if len(S) == 0:
        print('YES')
        break

Solution (Python):
import sys
input = sys.stdin.readline

s=input().strip()
n=len(s)
s+="
i=0
while n-i>=1:
    """print(n-i)
    print(s[i:i+5])"""

    if s[i:i+5]=="dream":
        if s[i+5:i+7]=="er":
            
            if s[i+7:i+10]=="ase":
                if s[i+10]=="r":
                    i+=11
                else:
                    i+=10    
            else:
                i+=7
        else:
            i+=5

    elif s[i:i+5]=="erase":
        
        if s[i+5]=="r":
            i+=6
        else:
            i+=5
    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):
import re

S = input()




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

Solution (Python):
import re

S = input()



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

Solution (Python):
import re

S = input()

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

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

a = 'dream'[::-1]
b = 'dreamer'[::-1]
c = 'erase'[::-1]
d = 'eraser'[::-1]

idx = 1
for _ in range(len_s):
    if s[:idx] in [a, b, c, d]:
        s = s[idx:]
        idx = 0
    idx += 1
if s[:idx] in [a, b, c, d]:
    s = []

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

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

s = S[::]
a = 'dream'[::-1]
b = 'dreamer'[::-1]
c = 'erase'[::-1]
d = 'eraser'[::-1]


idx = 1
for i in range(1, len(S)):
    if s[:idx] in [a, b, c, d]:
        
        
        
        
        
        s = s[idx:]
        
        
        idx = 0
    idx += 1
    
if s[:idx] in [a, b, c, d]:
    s = []

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

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

Solution (Python):
import re

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

if __name__ == '__main__':
    main()

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

while s != "":
    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:
        print("NO")
        break
else:
    print("YES")

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

Solution (Python):
a="dream"
b="dreamer"
c="erase"
d="eraser"

ar=a[::-1]
br=b[::-1]
cr=c[::-1]
dr=d[::-1]

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


Sr=Sr.replace(dr,'')
Sr=Sr.replace(cr,'')
Sr=Sr.replace(br,'')
Sr=Sr.replace(ar,'')

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

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

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

i = 0
can = True
while(i < len(S)):
    can_local = False
    for j in range(4):
        d = divide[j]
        if S[i:i+len(d)] == d:
            can_local = True        
            i += len(d)
            
    if not can_local:
        can = False
        break

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

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()
L = ['eraser','erase','dreamer','dream']
for e in L:
    S = S.replace(e,"")
if len(S) == 0:
    print('YES')
else:
    print('NO')

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

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

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

Solution (Python):
S = input()

list = ["eraser","erase","dreamer","dream"]
for x in list:
    S = S.replace(x,"")

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

Solution (Python):
S = input()

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

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

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

Solution (Python):
S = input()
while len(S) > 0:
    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):
S = input()
dp = [False for _ in range(len(S)+1)]
char_list = ['dream', 'dreamer', 'erase', 'eraser']
dp[0] = True

for i in range(len(S)):
  if dp[i] == False:
    continue
  for char in char_list:
    if S[i:i+len(char)] == char:
      dp[i+len(char)] = True

if dp[len(S)]:
  print('YES')
else:
  print('NO')

Solution (Python):
s = input()

flag = True

while s != "":
    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:
        flag = False
        break

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

Solution (Python):

S = str(input()) 




i = len(S) - 5
if i < 0:
    print("NO")
else:
    while i >= 0:
        end_5_char = S[i:i+5]

        

        if end_5_char == "eamer":
            
            if i < 2 or S[i-2:i] != "dr":
                print("NO")
                break
            else:
                i -= 2
        elif end_5_char == "raser":
            
            if i < 1 or S[i-1:i] != "e":
                print("NO")
                break
            else:
                i -= 1
        elif end_5_char != "dream" and end_5_char != "erase":
            print("NO")
            break

        i -= 5
    else:
        print("YES")

Solution (Python):

import re

S = input()

pattern = '^(dream|dreamer|erase|eraser)+$'
result = re.match(pattern, S)
if result:
    print('YES')
else:
    print('NO')

Solution (Python):
s = list(input())
s= s[::-1]
s += list("qqqqqqqq")
li = [list("maerd"),list("remaerd"),list("esare"),list("resare")]

memo = 0
while(1):
    a = s[memo:memo+5]
    b = s[memo:memo+6]
    c = s[memo:memo+7]
    
    if a==li[0] or a==li[2]:
        memo += 5
        continue
    elif b==li[3]:
        memo += 6
        continue
    elif c==li[1]:
        memo += 7
        continue
    elif memo >= len(s)-8:
        print("YES")
        break
    else:
        print("NO")
        break
    



    pass

Solution (Python):
S = input()

import re

pattern = r"^(dream|dreamer|erase|eraser)+$"
target = S

if re.match(pattern, target):
	print("YES")
else:
	print("NO")

Solution (Python):
s = list(input());tmp = ""
t = ["maerd", "remaerd", "esare", "resare"]
while s:
    tmp += s.pop()
    if tmp in t: tmp = ""
if len(tmp)>=7: print("NO")
else: print("YES")

Solution (Python):
import sys


def solve(inp):
    S = inp.readline().rstrip()

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

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

    while len(S) > 0:
        f = 0
        for p in P:
            p_str = ''.join(reversed(p))
            if S.startswith(p_str):
                f = 1
                S = S[len(p):]
                break
        if f == 0:
            return "NO"

    return "YES"


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()
N = len(S)


dp = [0] * (N + 9)
dp[0] = 1
for i in range(N):
    if dp[i]:
        if S[i:i+5] == 'dream':
            dp[i+5] = 1
        if S[i:i+7] == 'dreamer':
            dp[i+7] = 1
        if S[i:i+5] == 'erase':
            dp[i+5] = 1
        if S[i:i+6] == 'eraser':
            dp[i+6] = 1
if dp[N]:
    YES()
else:
    NO()

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

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

Solution (Python):
s = input()
lst = ["eraser","erase","dreamer","dream"]
for w in lst:
    s = s.replace(w,"")

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

print(ans)

Solution (Python):
s = "".join(input().split("eraser"))
s = "".join(s.split("erase"))
s = "".join(s.split("dreamer"))
s = "".join(s.split("dream"))
if len(s) == 0:
    ans = "YES"
else:
    ans = "NO"

print(ans)

Solution (Python):


import sys

S = input()

i = 0
while i < len(S):
	if i + 4 < len(S) and S[i : i + 5] == "dream":
		if i + 6 < len(S) and S[i + 5 : i + 7] == "er":
			if i + 9 < len(S) and S[i + 7 : i + 10] == "ase":
				if i + 10 < len(S) and S[i + 10] == "r":
					i += 11
				else:
					i += 10
			else:
				i += 7
		else:
			i += 5
	else:
		if i + 4 < len(S) and S[i : i + 5] == "erase":
			if i + 5 < len(S) and S[i + 5] == "r":
				i += 6
			else:
				i += 5
		else:
			print("NO")
			sys.exit()

print("YES")

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

while len(s) > 0:
    if s[-5:] in words:
        s = s[:-5]
    elif s[-6:] in words:
        s = s[:-6]
    elif s[-7:] in words:
        s = s[:-7]
    else:
        print("NO")
        exit()

print("YES")

Solution (Python):
s = input()


s = s[::-1]



comp_eraser = "eraser"
comp_dreamer = "dreamer"
comp_erase = "erase"
comp_dream = "dream"


comp_eraser = comp_eraser[::-1] 
comp_dreamer = comp_dreamer[::-1]
comp_erase = comp_erase[::-1] 
comp_dream = comp_dream[::-1]



while len(s)>0:
  
  if s.find(comp_eraser) == 0:
    s=s[len(comp_eraser):]

  elif s.find(comp_dreamer) == 0:

    s=s[len(comp_dreamer):]
  elif s.find(comp_erase) == 0:

    s=s[len(comp_erase):]
  elif s.find(comp_dream) == 0:

    s=s[len(comp_dream):]
  else:
    print("NO")
    break

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

Solution (Python):
s = str(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):
dr ="dream" 
dre = "dreamer" 
er ="erase" 
ere = "eraser" 
a = input()
ret = "YES"
while len(a) != 0:
    if (a.endswith(dr) or a.endswith(er)):
        a = a[:len(a)-5]
    elif(a.endswith(dre)):
        a = a[:len(a)-7]
    elif(a.endswith(ere)):
        a = a[:len(a)-6]
    else:
        ret = "NO"
        break
        
print(ret)

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

Solution (Python):
S = input()

S_ = (S
    .replace('eraser', '')
    .replace('erase', '')
    .replace('dreamer', '')
    .replace('dream', '')
)

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

Solution (Python):
s = input()
ans = ''
while 1:
    if s[-7:] == 'dreamer':
        s = s[:-7]
        continue
    if s[-6:] == 'eraser':
        s = s[:-6]
        continue
    if s[-5:] == 'dream':
        s = s[:-5]
        continue
    if s[-5:] == 'erase':
        s = s[:-5]
        continue
    if s == '':
        ans = 'YES'
        break
    else:
        ans = 'NO'
        break
print(ans)

Solution (Python):
t=input()

def right(text):
  li=["dream","dreamer","erase","eraser"]
  for te in li:
    if text[-len(te):] == te:
      return text[:len(text)-len(te)]
  return text

flag=True
while flag:
  temp=right(t)
  if not temp:
    print("YES")
    break
  elif temp==t:
    print("NO")
    break
  t=temp

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::-1]
word = ['resare','esare','remaerd','maerd',]
for i in word:
    s = s.replace(i,'')
if s:
    print('NO')
else:
    print('YES')

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

Solution (Python):
s = input()
s = s[-1::-1]
word = ['resare','esare','remaerd','maerd',]
for i in word:
    s = s.replace(i,'')
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):
T=[]
S=input()
Sr=list(reversed(S))
w1=list(reversed('dream'))
w2=list(reversed('dreamer'))
w3=list(reversed('erase'))
w4=list(reversed('eraser'))

while True:
    if Sr[:5]==w1:
        del(Sr[:5])
    elif Sr[:5]==w3:
        del(Sr[:5])
    elif Sr[:6]==w4:
        del(Sr[:6])
    elif Sr[:7]==w2:
        del(Sr[:7])
    else:
        break
if Sr==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):
def main():
    s=input()
    while len(s)>0:
        if s[-5:]=='dream':
            s=s[:-5]
        elif s[-7:]=='dreamer':
            s=s[:-7]
        elif s[-5:]=='erase':
            s=s[:-5]
        elif s[-6:]=='eraser':
            s=s[:-6]
        else:
            print('NO')
            exit()
    print('YES')
main()

Solution (Python):
S=str(input())
'dream' 'dreamer' 'erase' 'eraser'
hantei=True
while S:
  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:
    hantei=False
    break
print('YES' if hantei else 'NO')

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

Solution (Python):
T = input()

S = T[::-1]
i = 0
while i <= len(S) - 1:
    if S[i] == "r":
        if S[i:i+7] == "remaerd":
            i += 7
        elif S[i:i+6] == "resare":
            i += 6
        else:
            print("NO")
            exit()
    elif S[i] == "m":
        if S[i:i+5] == "maerd":
            i += 5
        else:
            print("NO")
            exit()
    elif S[i] == "e":
        if S[i:i+5] == "esare":
            i += 5
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()
print("YES")

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

Solution (Python):
import re

regex = r'(dream|dreamer|erase|eraser)+$'

s = input()

if re.match(regex, s):
  print("YES")
else:
  print("NO")

Solution (Python):
import re

regex = r'(dream|dreamer|erase|eraser)+$'

s = input()

if re.match(regex, s):
  print("YES")
else:
  print("NO")

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

lenT = [len(i) for i in T]
Trev = [t[::-1] for t in T]

i = 0
while i < len(S):
    for j, t in enumerate(Trev):
        if Srev[i:i+lenT[j]] == t:
            i += lenT[j]     
            break
    else:
        print('NO')
        break
else:
    print('YES')

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

Solution (Python):
S = input()
rep_S = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")

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

Solution (Python):
s = list(input())
t = ['dream','dreamer','erase','eraser']
ans = 0
for i in range(100000):
    check = 0
    
    for j in t:
        
        if s[-1 * (len(j)):] == list(j):
            del s[-1 * (len(j)):]
            check = 1
            break
    if len(s) == 0:
        ans = 1
        break
if ans == 1:
    print('YES')
else:
    print('NO')

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

S = input()

T = ['dream', 'dreamer', 'erase', 'eraser']
lenT = [len(i) for i in T]

def dayDream(pin):
    global isGoal               
    for i, d in enumerate(T):
        if isGoal:
            return
        
        if S[pin:pin+lenT[i]] == d:            
            pout = pin + lenT[i] 
            if pout == len(S):                
                isGoal = True    
                return 
            else:
                dayDream(pout)
    
    return
    
isGoal = False
dayDream(0)
if isGoal:
    print('YES')
else:
    print('NO')