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()
n=len(s)
i=1
for j in range(n//5):
    if s[-i:-i-5:-1]=="maerd":
        i+=5
 
    if s[-i:-i-5:-1]=="esare":
        i+=5

    if s[-i:-i-6:-1]=="resare":
        i+=6

    if s[-i:-i-7:-1]=="remaerd":
        i+=7

    if i==n+1:
        print("YES")
        break

if i != n+1:
    print("NO")

Solution (Python):
s=input()
n=len(s)
i=1
for j in range(n):
    if s[-i:-i-5:-1]=="maerd":
        i+=5
 
    if s[-i:-i-5:-1]=="esare":
        i+=5

    if s[-i:-i-6:-1]=="resare":
        i+=6

    if s[-i:-i-7:-1]=="remaerd":
        i+=7

    if i==n+1:
        print("YES")
        break

if i != n+1:
    print("NO")

Solution (Python):
s=input()
n=len(s)
dp=list('false'*n)
dp[0]="true"
if s[0:5]=="dream" or s[0:5]=="erase":
    for i  in range(5):
        dp[i]="true"
if s[0:6]=="eraser":
    for i  in range(6):
        dp[i]="true"
if s[0:7]=="dreamer":
    for i in range(7):
        dp[i]="true"


for i in range(5,n):

    if dp[i-5]=="true" and (s[i-4:i+1]=="dream" or s[i-4:i+1]=="erase"):
        dp[i]="true"
    if dp[i-6]=="true" and s[i-5:i+1]=="eraser":
        dp[i]="true"
    if dp[i-7]=="true" and s[i-6:i+1]=="dreamer":
        dp[i]="true"

if dp[n-1]=="true":
    print("YES")
else:
    print("NO")

Solution (Python):
s=input()
cnt=0
for i in range(len(s)):
    if s[-7:] == 'dreamer':
        s=s[:-7]
    elif s[-6:] == 'eraser':
        s=s[:-6]
    elif s[-5:] =='erase'or s[-5:]=='dream':
        s=s[:-5]
    elif s=='':
        break
    else:
        cnt+=1
        break
if cnt==0:
    print('YES')
else:
    print('NO')

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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
g=[]

def  jdream(l,i):
    if len(l)>=i+5:

        if l[i:i+5]=="dream":
            i=i+5
            if i==len(l):
                g.append("Y")
                return
     
            else:
                jer(l,i)
                jdream(l,i)
                return
        else:
            
            return
    else:
        
        return

def jerase(l,i):
    if len(l)>=i+5:

        if l[i:i+5]=="erase":
            i=i+5
            if i==len(l):
                g.append("Y")
                return
            else:
                jr(l,i)
                jerase(l,i)
                jdream(l,i)
                return
        else:
            
            return
    else:
        
        return

def jer(l,i):
    if len(l)>=i+2:

        if l[i:i+2]=="er":
            i=i+2
            if i==len(l):
                g.append("Y")
                return
            else:
                jase(l,i)
                jerase(l,i)
                jdream(l,i)
                return
        else:
            
            return
    else:
        
        return

def jase(l,i):
    if len(l)>=i+3:

        if l[i:i+3]=="ase":
            i=i+3
            if i==len(l):
                g.append("Y")
                return
            else:
                jdream(l,i)
                jerase(l,i)
                jr(l,i)
                return
        else:
            
            return
    else:
        
        return

def jr(l,i):
    if len(l)>=i+1:

        if l[i:i+1]=="r":
            i=i+1
            if i==len(l):
                g.append("Y")
                return
            else:
                jdream(l,i)
                jerase(l,i)
                return
        else:
            
            return

    else:
        
        return

s=input()
n=0
jerase(s,n)
n=0
jdream(s,n)


if 'Y' in g:
    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 not S:
    print("YES")
else:
    print("NO")

Solution (Python):

s=input()
divide=["dream","dreamer","erase","eraser"]

s=s[::-1]
for i,x in enumerate(divide):
    divide[i]=x[::-1]

ans=True
i=0
while i<len(s):
    flag=False
    for x in divide:
        lx=len(x)
        if s[i:i+lx] in divide:
             flag=True
             i+=lx
    if flag==False:
        ans=False
        break
if flag:
     print("YES")
else:
     print("NO")

Solution (Python):
s = input()

lis = ['dream', 'dreamer', 'erase', 'eraser']
rev_lis = []

for e in lis:
	rev_lis.append(e[::-1])

rev_s = s[::-1]

while True:
	if rev_s == '':
		print('YES')
		exit()
	tmp1 = rev_s[0:5]
	tmp2 = rev_s[0:6]
	tmp3 = rev_s[0:7]
	if tmp1 in rev_lis:
		rev_s = rev_s[5:]
	elif tmp2 in rev_lis:
		rev_s = rev_s[6:]
	elif tmp3 in rev_lis:
		rev_s = rev_s[7:]
	else:
		print('NO')
		exit()

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 0<len(s):
    if s[-5:]=='erase' or s[-5:]=='dream':
        s=s[0:-5]
    elif s[-6:]=='eraser':
        s=s[0:-6]
    elif s[-7:]=='dreamer':
        s=s[0:-7]
    else:
        print("NO")
        exit()
print("YES")

Solution (Python):
S = input()
i = len(S)
while i > 0:
    if S[i - 5:i] in {'dream', 'erase'}:
        i -= 5
    elif S[i - 6:i] == 'eraser':
        i -= 6
    elif S[i - 7:i] == 'dreamer':
        i -= 7
    else:
        print('NO')
        break
else:
    print('YES')

Solution (Python):
s_init = input()
s_list = list(reversed(s_init))
s = ''.join(s_list)
t = ""
words = ["maerd", "remaerd", 'esare', 'resare']
s_list = list(s)
t_list = list(t)
while s != t:
    t_fixed = t
    if len(s_list) < len(t_list):
        break
    elif t == 'gameover':
        break
    else:
        for word in words:
            if s.startswith(t + word):
                t = t + word
                break
        if t == t_fixed:
            t = 'gameover'
if s == t:
    print('YES')
else:
    print('NO')

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

Solution (Python):
S = input()
words = ['dream', 'dreamer', 'erase', 'eraser']
dp = [0] * (len(S) + 1)
dp[0] = 1
ans = '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:
        ans = 'YES'
        break
print(ans)

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

Solution (Python):

s = input()

r = ''
for i in range(len(s)-1, -1, -1):
    r = s[i] + r
    if r == 'dream':
        r = ''
    if r == 'dreamer':
        r = ''
    if r == 'erase':
        r = ''
    if r == 'eraser':
        r = ''
        
if r == '':
    print('YES')
else:
    print('NO')

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

ind = 0
while True:
    
    if S[ind:ind+5] in rtss:
        ind += 5
    elif S[ind:ind+6] in rtss:
        ind += 6
    elif S[ind:ind+7] in rtss:
        ind +=7
    else:
        print("NO")
        exit()
    if ind == len(S):
        print("YES")
        exit()

Solution (Python):
S = input()
Sr = S[::-1]
token = ['dream', 'dreamer', 'erase', 'eraser']
tokenr = list(map(lambda x:x[::-1], token))
t = ''
while(len(Sr)>0):
    notFound = True
    for w in tokenr:
        if w==Sr[:len(w)]:
            Sr = Sr[len(w):]
            t+=w
            notFound = False
    if notFound:
        break
if Sr == '':
    print('YES')
else:
    print('NO')

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    
    S = Scanner.string()

    def solve(S):
        while len(S) > 0:
            if len(S) >= 7:
                if S[-7:] == 'dreamer':
                    S = S[:-7]
                    continue
            if len(S) >= 6:
                if S[-6:] == 'eraser':
                    S = S[:-6]
                    continue
            if len(S) >= 5:
                if S[-5:] == 'erase':
                    S = S[:-5]
                    continue
                elif S[-5:] == 'dream':
                    S = S[:-5]
                    continue
            return False
        return True
    print('YNEOS'[not solve(S)::2])


if __name__ == "__main__":
    main()

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

Solution (Python):
S = input()[::-1]
Tl = ["dream", 'dreamer', 'erase', 'eraser']
flg = 0

for i in range(len(Tl)):
    Tl[i] = Tl[i][::-1]
while True:
    Sl = len(S)
    for i in range(len(Tl)):
        if S.find(Tl[i]) == 0:
            S = S[len(Tl[i]):]
    if len(S) == 0:
        flg = 1
        break
    elif len(S) == Sl:
        break
    else:
        pass

if flg == 1:
    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):
c = input().rstrip('\n')

str1 = "eraser"
str2 = "erase"
str3 = "dreamer"
str4 = "dream"



c = c.replace(str1, "")
c = c.replace(str2, "")
c = c.replace(str3, "")
c = c.replace(str4, "")

if (c == ""):
  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 = input()
S = ''.join(list(reversed([c for c in S])))

while S:
    if S[:7] == 'remaerd':
        S = S[7:]
    elif S[:6] == 'resare':
        S = S[6:]
    elif S[:5] == 'maerd':
        S = S[5:]
    elif S[:5] == 'esare':
        S = S[5:]
    else:
        print('NO')
        exit()

print('YES')

Solution (Python):
s = input()

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

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

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

Solution (Python):
import sys
s=input()
i=len(s)-1
while True:
    if i<0:
        print('YES')
        sys.exit()
    if i>=4:
        if s[i-4:i+1]=='dream':
            i-=5
            continue
        elif s[i-4:i+1]=='erase':
            i-=5
            continue
    if i>=5 and s[i-5:i+1]=='eraser':
        i-=6
        continue
    if i>=6 and s[i-6:i+1]=='dreamer':
        i-=7
        continue
    print('NO')
    sys.exit()

Solution (Python):
s=input()
search=['eraser', 'erase','dreamer', 'dream']
for i in range(4):
    t=s.split(search[i])
    s=''.join(s.split(search[i]))

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

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

s = s.replace('/', '')
if len(s) == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
def we_can(s):
    ptr = 0
    while True:
        if len(s) == abs(ptr):
            return True
        else:
            if ptr == 0:
                if s[ptr-5:] == 'dream' or s[ptr-5:] == 'erase':
                    ptr -= 5
                    continue
                elif s[ptr-6:] == 'eraser':
                    ptr -= 6
                    continue
                elif s[ptr-7:] == 'dreamer':
                    ptr -= 7
                    continue
            if s[ptr-5:ptr] == 'dream' or s[ptr-5:ptr] == 'erase':
                ptr -= 5
                continue
            elif s[ptr-6:ptr] == 'eraser':
                ptr -= 6
                continue
            elif s[ptr-7:ptr] == 'dreamer':
                ptr -= 7
                continue
            return False


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

Solution (Python):
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


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

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

    pass


if __name__ == "__main__":
    main()

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

    while True:
        match = False
        for ss in T:
            if s.endswith(ss) :
                s = s[:-1*len(ss)]
                if not s:
                    print('YES')
                    return
                match = True
                break
        if not match:
            print('NO')
            return

solution()

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

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

Solution (Python):
s=input()
s=s[::-1]
t=""
flag=False

while(len(s)>0):
  if(s[0:5]=="maerd" or s[0:5]=="esare"):
    s=s[5:]
  elif(s[0:7]=="remaerd"):
    s=s[7:]
  elif(s[0:6]=="resare"):
    s=s[6:]
  else:
    break
  if(len(s)==0):
    flag=True
    
if(flag):
  print("YES")
else:
  print("NO")

Solution (Python):
import sys
S="".join(reversed(input()))
i=0
while i<len(S):
    if i+4<len(S) and (S[i:i+5]=="maerd" or S[i:i+5]=="esare"):
        i+=5
    elif i+5<len(S) and (S[i:i+6]=="resare"):
        i+=6
    elif i+6<len(S) and (S[i:i+7]=="remaerd"):
        i+=7
    else:
        print("NO")
        sys.exit()
print("YES")

Solution (Python):
S=input()
dp=[False]*(len(S)+1)
dp[0]=True
for i in range(len(S)):
    if i>=4 and S[i-4:i+1]=="dream":
        dp[i+1]|=dp[i-4]
    if i>=4 and S[i-4:i+1]=="erase":
        dp[i+1]|=dp[i-4]
    if i>=6 and S[i-6:i+1]=="dreamer":
        dp[i+1]|=dp[i-6]
    if i>=5 and S[i-5:i+1]=="eraser":
        dp[i+1]|=dp[i-5]
print("YES" if dp[len(S)] else "NO")

Solution (Python):

S = input()
T = ''
S = S[::-1]
words = ["dream","dreamer","erase","eraser"]
rev_words = [w[::-1] for w in words]

flag = False
i=0
while(1):
	for w in rev_words:
		s = S[i:i+len(w)]
		if s == w:
			flag = True
			T += w
			i += len(w)
			break
	if T == S:
		ans = "YES"
		break
	if flag == False:
		ans = 'NO'
		break
	flag = False

print(ans)

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

Solution (Python):
S = input()[::-1]
devide = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
    devide[i] = devide[i] [::-1]
    
flag = True
i = 0
while i < len(S):
    flag2 = False
    for j in range(4):
        if devide[j] == S[i : i+len(devide[j])]:
            flag2 = True
            i += len(devide[j])
    
    if not flag2:
        flag = False
        break

print('YES' if flag == True else 'NO')

Solution (Python):
S=list(input())
n=len(S)-1
a=0
while n>=0:
  if S[n]=="m":
    if n<4:
      a=1
      break
    if S[n-4:n+1]==["d","r","e","a","m"]:
      n=n-5
    else:
      a=1
      break
  elif S[n]=="e":
    if n<4:
      a=1
      break
    if S[n-4:n+1]==["e","r","a","s","e"]:
      n=n-5
    else:
      a=1
      break
  elif S[n]=="r":
    if n<5:
      a=1
      break
    if n==5:
      if S[0:n+1]==["e","r","a","s","e","r"]:
        n=n-6
    else:
      if S[n-5:n+1]==["e","r","a","s","e","r"]:
        n=n-6
      elif S[n-6:n+1]==["d","r","e","a","m","e","r"]:
        n=n-7
      else:
        a=1
        break
  else:
    a=1
    break
if a==0:
  print("YES")
else:
  print("NO")

Solution (Python):
def main():
    S = input()
    N = len(S)
    ok = set(['dream','erase','dreamer','eraser'])
    if N < 8 and S not in ok:
        print("NO")
        exit()
    i = 0
    while i < N-5:
        tmp = S[i:i+5]
        if tmp == 'dream':
            if i+6 < N and S[i+5:i+7] == 'er':
                if i+7<N and S[i+7] == 'a':
                    i += 5
                else:
                    i += 7
            else:
                i += 5
        elif tmp == 'erase':
            if i+5<N and S[i+5] == 'r':
                i += 6
            else:
                i += 5
        else:
            print('NO')
            exit()
    if i < N and S[i:] not in ok:
        print('NO')
        exit()
    print('YES')

if __name__ == "__main__":
    main()

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

l5 = ["dream"[::-1], "erase"[::-1]]
l6 = ["eraser"[::-1]]
l7 = ["dreamer"[::-1]]

ans = "YES"

while len(s) > 4:
    if s[:5] in l5:
        s = s[5:]
    elif s[:6] in l6:
        s = s[6:]
    elif s[:7] in l7:
        s = s[7:]
    else:
        ans = "NO"
        break

print(ans)

Solution (Python):
S = input()
a = 'dream'
b = 'dreamer'
c = 'erase'
d = 'eraser'
T = S
while len(T) > 4:
    if S[len(T)-5:len(T)] == a:
        T = T[0:len(T)-5]
    elif S[len(T)-7:len(T)] == b:
        T = T[0:len(T)-7]
    elif S[len(T)-5:len(T)] == c:
        T = T[0:len(T)-5]
    elif S[len(T)-6:len(T)] == d:
        T = T[0:len(T)-6]
    else:
        break
if T == '':
    print('YES')
else:
    print('NO')

Solution (Python):
S=input()

for i in range(100000):
  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:
    pass
  if S=="":
    print("YES")
    break
else:
  print("NO")

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

kari = ['dream', 'dreamer', 'erase', 'eraser']
 
words = [i[::-1] for i in kari]
 
l = len(S)
cnt = ''

for i in range(l):
    cnt += S[i]
    if cnt in words:
        cnt = ''

if cnt!='':
    print('NO')
else:
    print('YES')

Solution (Python):
S = input()

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

i = len(S)

while True:
    if S[i-5:i]==words[0] or S[i-5:i]==words[2]:
        i -= 5
    elif S[i-6:i]==words[3]:
        i -= 6
    elif S[i-7:i]==words[1]:
        i -= 7
    else:
        print('NO')
        exit()
    if i == 0:
        print('YES')
        exit()

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

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

words = [i[::-1] for i in kari]

l = len(S)
i = 0

while True:
    if S[i:i+5]==words[0] or S[i:i+5]==words[2]:
        i += 5
    elif S[i:i+6]==words[3]:
        i += 6
    elif S[i:i+7]==words[1]:
        i += 7
    else:
        print('NO')
        exit()
    if i == l:
        print('YES')
        exit()

Solution (Python):

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

tmp = 0
flg = True
while tmp < len(s):
    check = False
    for x in k:
        if s[tmp: tmp + len(x)] == x:
            check = True
            tmp += len(x)
    if check == False:
        flg = False
        break
        
print('YES' if flg else 'NO')

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

t = 0
while t <= len(s):
    if s[t:t+5] == 'maerd':
        t += 5
        continue
    elif s[t:t+7] == 'remaerd':
        t += 7
        continue
    elif s[t:t+5] == 'esare':
        t += 5
        continue
    elif s[t:t+6] == 'resare':
        t += 6
        continue
    elif t == len(s):
        print('YES')
        quit()
    else:
        break
print('NO')

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

t = 0
while t <= len(s):
    if s[t:t+5] == 'maerd':
        t += 5
        continue
    elif s[t:t+7] == 'remaerd':
        t += 7
        continue
    elif s[t:t+5] == 'esare':
        t += 5
        continue
    elif s[t:t+6] == 'resare':
        t += 6
        continue
    elif t == len(s):
        print('YES')
        quit()
    else:
        break
print('NO')

Solution (Python):
s=input()
s1=s.replace("eraser","0").replace("erase","0").replace("dreamer","0").replace("dream","0")
n=len(s1)
flag=False
for  i in range(0,n):
    if s1[i]!='0':
        flag=True
        break
        
if flag==False:
    print("YES")
else:
    print("NO")

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

Solution (Python):
def main():
    S = input()
    Si = S[::-1]
    a = ['maerd', 'remaerd', 'esare', 'resare']
    temp = str()
    cnt = 0
    for i in Si:
        temp += i
        if temp in a:
            cnt += len(temp)
            temp = str()
    print('YES' if cnt == len(S) else 'NO')

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()[::-1]
while s:
  start = len(s)
  for t in ['maerd', 'remaerd', 'esare', 'resare']:
    if t == s[:len(t)]:
      s = s[len(t):]
  if start == len(s):
    break
print("YNEOS"[len(s)>0::2])

Solution (Python):
s = input()
reverse_str = s[::-1]
word_list = ["maerd","remaerd","esare","resare"]
while(True):
    start_len = len(reverse_str)
    for word in word_list:
        if reverse_str.startswith(word):
            reverse_str = reverse_str[len(word):]
    if start_len == len(reverse_str) and start_len != 0:
        print("NO")
        exit()
    elif len(reverse_str) == 0:
        print("YES")
        exit()

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

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

Solution (Python):
S = input()

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

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

Solution (Python):
s=input()
for w in('eraser','erase','dreamer','dream'):s=s.replace(w,'')
print('YNEOS'[s>''::2])

Solution (Python):
print('YNEOS'[input().replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')>''::2])

Solution (Python):
s=str(input())
s=s[::-1]
stack=""
for i in s:
  stack=i+stack
  if stack=="dream"or stack=="dreamer"or stack=="erase"or stack=="eraser":
    stack=""
  elif len(stack)>7:
    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):
txt = input()
cands = ["dream", "dreamer", "erase", "eraser"]

success = True
while len(txt) > 0:
    flag = False

    for cand in cands:
        subtxt = txt[len(txt) - len(cand):]
        if subtxt == cand:
            txt = txt[:len(txt) - len(cand)]
            flag = True
            break

    if not flag:
        success = False
        break

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

Solution (Python):

import sys
from io import StringIO
import unittest

def yn(b):
    print("YES" if b==1 else "NO")
    return

def resolve():
    readline=sys.stdin.readline
    ss=readline().strip()
    
    
    
    ss=ss.replace("dream","D")
    ss=ss.replace("erase","E")
    ss=ss.replace("Der","DR")
    ss=ss.replace("Er","ER")
    for s in ss:
        if s not in ["D","E","R"]:
            print("NO")
            return
    print("YES")

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Solution (Python):
import re
s = input()
if re.fullmatch(r"(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):
import re
S = input()
if re.match("^(dream|dreamer|erase|eraser)+$",S):
    print("YES")
else:
    print("NO")

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

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

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

Solution (Python):
data = input()

tmp = data.replace('eraser', '')
tmp = tmp.replace('erase', '')
tmp = tmp.replace('dreamer', '')
tmp = tmp.replace('dream', '')
if tmp == '':
  print('YES')
  exit()
print('NO')

Solution (Python):
S = str(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):
import re
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$", input()) else "NO")

Solution (Python):
import re
s = input()
m = re.fullmatch(r'(dream(er)?|erase(r)?)+', s)


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

Solution (Python):
if __name__ == "__main__":
    s = input()

    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:
            print('NO')
            exit()

    print('YES')

Solution (Python):
S=input()

l=len(S)

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]

    if l==len(S):
        break
    else:
        l=len(S)


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

Solution (Python):
S = input()
i = len(S)
flag = True
while i>=0:
    if i >= 7 and S[i-7:i] == 'dreamer':
        i -= 7
        continue
    elif i >= 6 and S[i-6:i] == 'eraser':
        i -= 6
        continue
    elif i >= 5 and (S[i-5:i] == 'dream' or S[i-5:i] == 'erase'):
        i -= 5
        continue
    else:
        if i == 0:
            break
        else:
            flag = False
            break
if flag:
    print('YES')
else:
    print('NO')

Solution (Python):

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    L=["dream","dreamer","erase","eraser"]
    S=input()
    N=len(S)
    f=1
    pos=N-1
    while f:
        for i in range(len(L)):
            t=L[i]
            temp=1
            for i in range(len(t)):
                if pos-i<0:
                    temp=0
                    break
                if t[-1-i]==S[pos-i]:
                    continue
                else:
                    temp=0
                    break
                
            if temp:
                pos-=len(t)
                break
        if pos==-1:
            break
        if temp==0:
            f=0
            
    if f==1:
        print("YES")
    else:
        print("NO")
                

main()

Solution (Python):
import re

s = input()
era = 'eraser'
er = 'erase'
dr = 'dream'
drm = 'dreamer'

s1 = re.sub(era,'',s)
s2 = re.sub(er,'',s1)
s3 = re.sub(drm,'',s2)
s4 = re.sub(dr,'',s3)

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

Solution (Python):
S=input()
div=["maerd","remaerd","esare","resare"]
S=S[::-1]
judge=True
cnt=0
while cnt<len(S):
    can=False
    for j in range(4):
        d=div[j]
        if S[cnt:len(d)+cnt]==d:
            can=True
            cnt+=len(d)
    if not can:
        judge=False
        break
if judge:
    print("YES")
else:
    print("NO")