Problem:
 Score : 300 points    Problem Statement You are given a string S consisting of lowercase English letters.
Another string T is initially empty.
Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:   Append one of the following at the end of T : dream , dreamer , erase and eraser .       Constraints  1≦|S|≦10^5  S consists of lowercase English letters.         Input The input is given from Standard Input in the following format:  S       Output If it is possible to obtain S = T , print YES . Otherwise, print NO .        Sample Input 1 erasedream      Sample Output 1 YES  Append erase and dream at the end of T in this order, to obtain S = T .       Sample Input 2 dreameraser      Sample Output 2 YES  Append dream and eraser at the end of T in this order, to obtain S = T .       Sample Input 3 dreamerer      Sample Output 3 NO

Solution (Python):
S = list(input())
import re
S.reverse()
D1 = "maerd"
D2 = "remaerd"
E1 = "esare"
E2 = "resare"
S = "".join(S)
S = re.split('maerd|remaerd|esare|resare', S)
if len(S) == S.count("") :
  print("YES")
else:
  print("NO")

Solution (Python):
import sys
s = str(input())
ls = ["dream","dreamer","erase","eraser"]
while True:
    k = s[-5:]
    if k not in ls:
        t = s[-6:]
        if t not in ls:
            l = s[-7:]
            if l not in ls:
                print("NO")
                sys.exit()
            else:
                s = s[:-7]
                if s == "":
                    print("YES")
                    break
        else:
            s = s[:-6]
            if s == "":
                print("YES")
                break
    else:
        s = s[:-5]
        if s == "":
            print("YES")
            break

Solution (Python):
import sys

S = input()
S = S[::-1]
temp = ''

for a in S:
    temp += a
    
    if temp == "maerd" or temp == "remaerd" or temp == "esare" or temp == "resare":
        temp = ""
    if len(temp)>7:
        print("NO")
        sys.exit()
print("YES")

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

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

for _ in range((len(S) + 4) // 5):
    for word in words:
        if S.endswith(word):
            S = S[: -len(word)]
print("NO") if S else print("YES")

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

Solution (Python):
s = input()[::-1]
x = ["dream", "dreamer", "erase", "eraser"]
can = True
i = 0
for a in range(4):
    x[a] = x[a][::-1]
while(True):
    if(i == len(s)):
        break
    can2 = False
    for j in range (4):
        if(s[i:i+len(x[j])] == x[j]):
            can2 = True
            i += len(x[j])
    if(can2 == False):
        can = False
        break
print("YES" if can == True else "NO")

Solution (Python):
s = input()
n = len(s)
i = 0
flag = 0
while(True):
    if(s[i:i+5]) == "dream":
        if(i+5==n):
            break
        elif(s[i+5:i+10] =="dream"):
            i += 5
        elif(s[i+5:i+10] == "erase"):
            i += 5
        elif(s[i+5:i+7] == "er"):
            i += 7
            if(i==n):
                break
        else:
            flag = 1
            break

    elif(s[i:i+5]) == "erase":
        if(i+5==n):
            break
        elif(s[i+5:i+10] =="dream"):
            i += 5
        elif(s[i+5:i+10] == "erase"):
            i += 5
        elif(s[i+4:i+6] == "er"):
            i += 6
            if(i==n):
                break
        else:
            flag = 1
            break
    else:
        flag = 1
        break
print("YES" if flag == 0 else "NO")

Solution (Python):
import sys
S = input().rstrip()
S = S[::-1]
S1 = "dream"
S2 = "dreamer"
S3 = "erase"
S4 = "eraser"
S1 = S1[::-1]
S2 = S2[::-1]
S3 = S3[::-1]
S4 = S4[::-1]
while len(S) > 0:
  if S[0:len(S1)] == S1:
    S = S[len(S1):]
  elif S[0:len(S2)] == S2:
    S = S[len(S2):]
  elif S[0:len(S3)] == S3:
    S = S[len(S3):]
  elif S[0:len(S4)] == S4:
    S = S[len(S4):]
  else:
    print("NO")
    sys.exit()
print("YES")

Solution (Python):
s = input()

while True:
    if 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]

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

Solution (Python):
S = input()

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

is_updated = True
while is_updated and len(S) > 0:
  is_updated = False
  for text in TEXTS:
    if S[len(S) - len(text):] == text:
      S = S[:len(S) - len(text)]
      is_updated = True

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

Solution (Python):

"""this is python work script"""

def solver(word):
    """solve this problem"""
    check_result = word.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')

    answer = 'YES'
    if check_result:
        answer = 'NO'

    return answer

def main():
    """main function"""
    input_word = input().rstrip()
    answer = solver(input_word)
    print(answer)

if __name__ == '__main__':
    main()

Solution (Python):

"""this is python work script"""

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

def check_word(word, check_word_list):
    find_word = False

    
    for i, cw in enumerate(check_word_list):
        find_result = word.find(cw)
        

    
    
    

    
        if find_result == 0:
            word_length = len(cw)
            word = word[word_length:]
            find_word = True
        

    return find_word, word

def solver(word, check_word_list):
    """solve this problem"""
    wip = True
    while wip:
        wip, word = check_word(word, check_word_list)

    answer = 'NO'
    if len(word) == 0:
        answer = 'YES'
    return answer

def reverse_string_list(string_list):
    answer_list = []
    for word in string_list:
        answer_list.append(word[::-1])

    return answer_list

def main():
    """main function"""
    word = input().rstrip()[::-1]
    word_list = reverse_string_list(CHECK_WORDS)
    answer = solver(word=word, check_word_list=word_list)
    print(answer)

if __name__ == '__main__':
    main()

Solution (Python):



import os
import sys






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


def find(s):
    while True:
        for term in d:
            if s.endswith(term):
                s = s[:-1 * len(term)]
                break
        else:
            print("NO")
            break
        if len(s) == 0:
            print("YES")
            break
    return


def main():
    find(input())
    return


if __name__ == '__main__':
    main()

Solution (Python):



import os
import sys






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


def find(s):
    while True:
        for term in d:
            if s.endswith(term):
                s = s[:-1 * len(term)]
                break
        else:
            print("NO")
            break
        if len(s) == 0:
            print("YES")
            break
    return


def main():
    find(input())
    return


if __name__ == '__main__':
    main()

Solution (Python):
s = input()

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

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

Solution (Python):
s = list(input())
s = s[::-1]
ans = 1
while len(s):
    if len(s) <= 4:
        ans = 0
        break
    elif s[0:5] == list("maerd"):
        del s[0:5]
    elif s[0:5] == list("esare"):
        del s[0:5]
    elif len(s) <= 5:
        ans = 0
        break
    elif s[0:6] == list("resare"):
        del s[0:6]
    elif len(s) <= 6:
        ans = 0
        break
    elif s[0:7] == list("remaerd"):
        del s[0:7]
    else:
        ans = 0
        break
print(["NO","YES"][ans])

Solution (Python):
S = input()
s = S[::-1]
s1 = s.replace('resare', '').replace('esare', '')
s2 = s1.replace('remaerd', '').replace('maerd', '')

print('YES' if s2 == '' else 'NO')

Solution (Python):
s = input()

lst = ['dreameraser', 'dreamerase', 'dreamer', 'dream', 'eraser', 'erase']
while s:
  flag = 0
  for elem in lst:
    if elem in s:
      s = s.replace(elem, '')
      flag = 1
      break
  if flag == 0:
    print('NO')
    quit()
print('YES')

Solution (Python):
S = input()
dp = [0] * (len(S) + 1)
dp[0] = 1

words = ["dream", "dreamer", "erase", "eraser"]
done = 'NO'

for i in range(len(S)):
    if dp[i] == 0:
        continue
    for w in words:
        if S[i:i+len(w)] == w:
            dp[i+len(w)] = 1
    
    if dp[len(S)] == 1:
        done = 'YES'
        break

print(done)

Solution (Python):
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


S = S()

while 1:
    for flag in ("erase", "eraser", "dream", "dreamer"):
        if S.endswith(flag):
            S = S[:-len(flag)]
            break
    else:
        print('NO')
        break
    if not S:
        print('YES')
        break

Solution (Python):
import re

s = input()

s = s[::-1]

while s:
    if re.match("resare",s):
        s = s[6:]
    elif re.match("esare",s):
        s = s[5:]
    elif re.match("remaerd",s):
        s = s[7:]
    elif re.match("maerd",s):
        s = s[5:]
    else:
        break
    
if len(s) == 0:
    print("YES")
else:
    print("NO")

Solution (Python):
s3=s=input()[::-1]
l=["maerd","remaerd","esare","resare"]
s2=""
for i in range(len(s)):
 s2+=s[i]
 if s2 in l:
  s3=s3[len(s2):]
  s2=""
print("YES"if s2==""else "NO")

Solution (Python):
S = input()

num_eraser = S.count('eraser')
num_erase = S.count('erase') - num_eraser
num_dreamer = S.count('dreamer') - S.count('dreamerase')
num_dream = S.count('dream') - num_dreamer



cnt = num_eraser * 6 + num_erase * 5 + num_dreamer * 7 + num_dream * 5

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

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

def main():
    s = input()
    while True:
        if len(s) >= 5:
            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')
                return
            if s == '':
                print('YES')
                return
        else:
            print('NO')
            return

if __name__ == '__main__':
    main()

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

Solution (Python):
S = input()

tmp = len(S)

while len(S) > 0:
  if len(S) < 5:
    print('NO')
    exit()
  elif len(S) == 5:
    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 len(S) == 6:
    if S[len(S)-6:len(S)] == 'eraser':
      S = S[:len(S)-6]
  elif len(S) == 7:
    if S[len(S)-7:len(S)] == 'dreamer':
      S = S[:len(S)-7]
  else:
    if 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]
    elif 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]
      
  if tmp == len(S):
    print('NO')
    exit()
  else:
    tmp = len(S)
    
print('YES')

Solution (Python):


S = input()[::-1]

Moji = ['maerd', 'remaerd', 'resare', 'esare']

while len(S)!=0:

    if S[:5] == Moji[0] or S[:5] == Moji[3]:
        S = S[5:]
    elif S[:6] == Moji[2]:
        S = S[6:]
    elif S[:7] == Moji[1]:
        S = S[7:]
    else:
        print('NO')
        exit()

print('YES')

Solution (Python):
import numpy as np
import math
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

s = list(input())
s.reverse()
v = []
v.append(list("dream"))
v.append(list("erase"))
v.append(list("eraser"))
v.append(list("dreamer"))
for i in range(4):
    v[i].reverse()

now = 0
while(1):
    check = False
    for i in range(4):
        if now+len(v[i]) > len(s): continue
        tmp = ''.join(s[now:now+len(v[i])])
        x = ''.join(v[i])
        if tmp == x:
            check = True
            now += len(v[i])
        if check: break
    if not check: break
    if now == len(s): break

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

Solution (Python):
n = input()
t = ["dream", "dreamer", "erase", "eraser"]

while True:
  if not n:
    status = "YES"
    break

  elif n[-5:] in t:
    n = n[:-5]
    
  elif n[-6:] in t:
    n = n[:-6]
  
  elif n[-7:] in t:
    n = n[:-7]
    
  else:
    status = "NO"
    break
    
print(status)

Solution (Python):
s = input()

while True:
    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]
    elif len(s) == 0:
        print('YES')
        break
    else:
        print("NO")
        break

Solution (Python):
S = input()[::-1]
f = False
while True:
  if S[:5]=="maerd":
    S = S[5:]
    continue
  elif S[:5]=="esare":
    S = S[5:]
    continue
  elif S[:7]=="remaerd":
    S = S[7:]
    continue
  elif S[:6]=="resare":
    S = S[6:]
    continue
  elif S == "":
    f = True
    break
  else:
    break
print("YES" if f else "NO")

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    S = rl().rstrip()
    
    i = 0
    while i < len(S):
        sub_str = S[i:i + 5]
        if sub_str == 'dream':
            i += 5
            if i < len(S) - 2 and S[i:i + 2] == 'er' and S[i + 2] != 'a' or \
               i == len(S) - 2 and S[i:i + 2] == 'er':
                i += 2
        elif sub_str == 'erase':
            i += 5
            if i < len(S) and S[i] == 'r':
                i += 1
        else:
            print('NO')
            return
    print('YES')


if __name__ == '__main__':
    solve()

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

while len(newstring)>0:
    if newstring[:5]=="maerd":
        newstring=newstring[5:]

    elif newstring[:7]=="remaerd":
        newstring=newstring[7:]

    elif newstring[:5]=="esare":
        newstring=newstring[5:]

    elif newstring[:6]=="resare":
        newstring=newstring[6:]

    else:
        print("NO")
        exit()

print("YES")

Solution (Python):
s = input()
while True:
    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]
    elif not s:
        print("YES")
        break
    else:
        print("NO")
        break

Solution (Python):
def main():
    S = input()
    D = ['dream', 'dreamer', 'erase', 'eraser']
    D = [d[::-1] for d in D]
    tmp = ''
    for s in S[::-1]:
        tmp = ''.join([tmp, s])
        if tmp in D:
            tmp = ''
        if len(tmp) > 7:
            print('NO')
            exit()
    if tmp == '':
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Solution (Python):
S = input()
flag = 0
S = S[::-1]
while True:
    if S.startswith("maerd") or S.startswith("esare"):
        S = S[5:]
    elif S.startswith("remaerd"):
        S = S[7:]
    elif S.startswith("resare"):
        S = S[6:]
    elif S == "":
        break
    else:
        flag = 1
        break
print("YES" if flag == 0 else "NO")

Solution (Python):
s = input()
s = s[::-1]
while len(s) > 0:
  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:
    print('NO')
    exit()
print('YES')

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

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

Solution (Python):
divide = ["dream", "dreamer", "erase", "eraser"]
S = input()[::-1]
for i in range(4): divide[i] = divide[i][::-1]

can = True
i = 0
while i < len(S):
  can2 = False
  for d in divide:
    if S[i:i+len(d)] == d:
      can2 = True
      break
  i += len(d)*(can2)
  if not can2:
    can = False
    break
print("YNEOS"[~can%2::2])

Solution (Python):
import sys
import re

input = sys.stdin.readline

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

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


def read():
    S = input().strip()
    return S,


def solve(S):
    N = len(S)
    
    def dfs(i):
        enable = False
        if i == N:
            return True
        elif i > N:
            return False
        if S[i:i+7] == "dreamer":
            enable |= dfs(i+7)
        if S[i:i+6] == "eraser":
            enable |= dfs(i+6)
        if S[i:i+5] in ["dream", "erase"]:
            enable |= dfs(i+5)
        return enable
    
    return "YES" if dfs(0) else "NO"


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

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

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    S = SI()
    l = len(S)
    S = S[::-1] + "ppppppp"
    W = ["maerd", "remaerd", "esare", "resare"]
    idx = 0
    while idx < l:
        no_flag = True
        for w in W:
            if S[idx: idx+len(w)] == w:
                idx += len(w)
                no_flag = False

        if no_flag:
            print("NO")
            exit()

    if idx == l:
        print("YES")
    else:
        print("NO")



if __name__ == "__main__":
    main()

Solution (Python):
S = input()
T = ''
U = ['dreamer', 'dream', 'eraser', 'erase']
answer = 'NO'
list = [T]
done = 0

while done == 0:
    for l in list:
        list.remove(l)
        for u in U:
            if S.startswith(l + u):
                if S == l + u:
                    answer = 'YES'
                    done = 1
                list.append(l + u)
    if list == []:
        done = 1
print(answer)

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

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

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

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

        else:
            break

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

main()

Solution (Python):


S = str(input())
S = S[::-1]
l = len(S)
i = 0
ans = 'YES'
while True:
    if S[i:i+5] == 'maerd' or S[i:i+5] == 'esare':
        i += 5
        if i == l:
            break
    elif S[i:i+6] == 'resare':
        i += 6
        if i == l:
            break
    elif S[i:i+7] == 'remaerd':
        i += 7
        if i == l:
            break
    else:
        ans = 'NO'
        break
print(ans)

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    s = input()
    s=s[::-1]

    t = ["dream", "dreamer", "erase", "eraser"]
    table = [ti[::-1] for ti in t]

    while len(s) > 0:
        flg = True
        for ti in table:
            if s[:len(ti)] == ti:
                s = s[len(ti):]
                flg = False
                break
        if flg:
            break

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys
s = input()
while True:
  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')
    sys.exit()
  if s == '':
    print('YES')
    sys.exit()

Solution (Python):
s = input()
s_rev = s[::-1]
T_list = ['maerd', 'remaerd', 'esare', 'resare']
 
def mojicut(s, r):
    n = s.replace(r, "", 1)
    return n
 
 
while len(s_rev) > 0:
    s_len = len(s_rev)
    for i in T_list:
        if s_rev.startswith(i):
            s_rev = mojicut(s_rev, i)
            break
    if len(s_rev) == s_len:
        break
 
if len(s_rev) > 0:
    print("NO")
else:
    print("YES")

Solution (Python):


s = input()

word_list = ["eraser","erase","dreamer","dream"]
for i in word_list:
    s = s.replace(i,".")

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

Solution (Python):
s = str(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')
        break
else:
    print('YES')

Solution (Python):

"""
Created on Wed Jun  3 18:19:05 2020

@author: NEC-PCuser
"""

S = input()

i = len(S)
ans = "YES"
while i > 0:
    if i >= 5 and (S[i-5:i] == 'dream' or S[i-5:i] == 'erase'):
        i -= 5
    elif i >= 7 and S[i-7:i] == 'dreamer':
        i -= 7
    elif i >= 6 and S[i-6:i] == 'eraser':
        i -= 6
    else:
        ans = "NO"
        break

print(ans)

Solution (Python):
init = input()

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

def reverseWord(str):
  return str[::-1]

def elimTheWord(str):
  for word in reversed_words:
    if str.find(word) == 0:
      str = str[len(word):]
  return str

reversed_words = list(map(reverseWord, words))


target = reverseWord(init)

while True:
  pivot = elimTheWord(target)
  if pivot == '':
    print('YES')
    break
  if pivot == target:
    print('NO')
    break
  target = pivot

Solution (Python):
s = input()

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

Solution (Python):
S = input()

ret = set()
for i in range(len("dreamer")):
    ret.add("dreamer"[i:])
for i in range(len("eraser")):
    ret.add("eraser"[i:])
for i in range(len("dream")):
    ret.add("dream"[i:])
for i in range(len("erase")):
    ret.add("erase"[i:])

word = ""

for i in reversed(range(len(S))):
    word = S[i] + word
    if word not in ret:
        print("NO")
        exit()
    elif word == "dreamer" or word == "eraser":
        word = ""
    elif word == "dream" or word == "erase":
        word = ""
    else:
        continue

if word == "":
    print("YES")

Solution (Python):
s = input()
for word in ["eraser","erase","dreamer","dream"]:
    s = s.replace(word,".")
if len(set(s)) == 1:
    print("YES")
else:
    print("NO")

Solution (Python):
def main():
    S = input()
    for word in ["eraser", "erase", "dreamer", "dream"]:
        S = S.replace(word, ".")
    
    if len(set(S)) == 1:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()

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

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

S_re = list(reversed(S))
for i in range(0, 4):
    A_re.append(''.join(list(reversed(A[i]))))

can = True
i = 0

while i < len(S):
    can2 = False
    for j in range(0, 4):
        d = A_re[j]
        S_word = ''.join(S_re[i:(i + len(d))])
        if S_word == d:
            can2 = True
            i += len(d)
            break

    if can2 == False:
        can = False
        break

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

Solution (Python):
S = input()
i = len(S)
w1 = 'dream'
w2 = 'dreamer'
w3 = 'erase'
w4 = 'eraser'
a,b,c,d = 0,5,2,1
answer = ''
flag = True

while flag:
    if S[a:b] == w1:
        if i == b :
            answer = 'YES'
            break
        elif S[a:b + c] == w2:
            if i == b + c:
                answer = 'YES'
                break
            
            if S[b :b + 5] == w3:
                if i == b + 5 :
                    answer = 'YES'
                    break
                if S[b :b + 6] == w4:
                    if i == b + 6:
                        answer = 'YES'
                        break
                    a += len(w4)+len(w1)
                    b += len(w4)+len(w1)
                    
                else:
                    a += len(w3)+len(w1)
                    b += len(w3)+len(w1)
            
            else:
                a += len(w2)
                b += len(w2)
        else:
            a += len(w1)
            b += len(w1)
    elif S[a:b] == w3:
        if i == b :
            answer = 'YES'
            break

        if S[a:b + d] == w4:
            if i == b + d :
                answer = 'YES'
                break
            a += len(w4)
            b += len(w4)
        else:
            a += len(w3)
            b += len(w3)
    else:
        answer = 'NO'
        break

print(answer)

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

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

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

Solution (Python):
from sys import stdin
def S(): return stdin.readline().rstrip()

a = S()
strl = ['dream','dreamer','erase','eraser']
t = ''
for i in range(len(a)-1,-1,-1):
    if 7<len(t):
        print('NO')
        exit()
    else:
        t = a[i]+t
        if t in strl:
            t = ''

print('YES')

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

Solution (Python):
S = input()
dp = [0]*(len(S) + 1)
dp[0] = 1

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

for i in range(len(S)):
    if dp[i] == 0:
        continue
    for w in words:
        if S[i:i + len(w)] == w:
            dp[i + len(w)] = 1
            
    if dp[len(S)] ==1:
        done = 'YES'
        break
        
print(done)

Solution (Python):
import re

s = input()

m = re.match(r"^(dream|dreamer|erase|eraser)+$", s)

print("NO" if m is None else "YES")

Solution (Python):
def solve():

    S = input()

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

    while(True):
        if(len(S) == 0):
            break
        flag = False
        for w in words:
            if(S.endswith(w)):
                S = S[0:len(S) - len(w)]
                flag = True
        
        if(not flag):
            print('NO')
            return
            
        
    print('YES')
    
solve()

Solution (Python):




import sys
from fractions import gcd
import math
from math import ceil,floor
import collections











S = input()



S = S[::-1]

i = 0 
while i < len(S):
    if S[i:i+7]=="remaerd":
        i = i + 7
    elif S[i:i+6]=="resare":
        i = i + 6
    elif S[i:i+5]=="maerd":
        i = i + 5
    elif S[i:i+5]=="esare":
        i = i + 5
    else:
        print("NO")
        sys.exit()
print("YES")

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

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

for str in array:
    S = S.replace(str," ")
ans = S.replace(" ","")
if len(ans) == 0:
    print("YES")
else:
    print("NO")

Solution (Python):
s = input()
s = s[::-1]
i = 0
check = True
while i < len(s):
  if s[i:i+5] == "maerd" or s[i:i+5] =="esare":
    i += 5
  elif s[i:i+6] == "resare":
    i += 6
  elif s[i:i+7] == "remaerd":
    i += 7
  else:
    check = False
    break
    
if check == True:
  print("YES")
else:
  print("NO")

Solution (Python):

s = input()

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

while len(s) > 0:
    for word in words:
        flg = False

        if s.endswith(word):
            s = s[:(len(s) - len(word))]
            flg = True
            break

    if not flg:
        break

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

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

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

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

S = S[::-1]
for i in range(len(words)):
    words[i] = words[i][::-1]

fin = True
com1 = False
cont = 0

for i in range(len(S)):
    if cont > 0:
        cont -= 1
        continue
    for j in range(len(words)):
        if words[j] == S[i:i+len(words[j])]:
            com1 = True
            cont = len(words[j]) - 1
            break
    if com1 == False:
        fin = False
        break
    com1 = False

if fin == True:
    print('YES')
else:
    print('NO')

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

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

S = S[::-1]
for i in range(len(words)):
    words[i] = words[i][::-1]

fin = True
com1 = False
cont = 0

for i in range(len(S)):
    if cont > 0:
        cont -= 1
        continue
    for j in range(len(words)):
        if words[j] == S[i:i+len(words[j])]:
            com1 = True
            cont = len(words[j]) - 1
            break
    if com1 == False:
        fin = False
        break
    com1 = False

if fin == True:
    print('YES')
else:
    print('NO')

Solution (Python):
S=input()
str_list=["dreamer","eraser","dream","erase"]
     
while True:
  S_tmp=S
  for str in str_list:
    if S[-len(str):]==str:
      S=S[0:len(S)-len(str)]
        
  if S_tmp==S:
    break    
        
if S=="":
  print("YES")
if S!="":
  print("NO")