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



Sample input:
erasedream


Sample output:
YES

Submission status: Accepted

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

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

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

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

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

        else:
            break
    
    except IndexError:
        pass

if(S == T):
    print('YES')

else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
n=0
while True:
    if S[n:n+5]=="dream":
        if S[n:n+7]=="dreamer":
            if n+7<len(S) and S[n+7]=="a":
                n = n+5
            else:
                n = n+7
        else:
            n = n+5
    elif S[n:n+5]=="erase":
        if S[n:n+6]=="eraser":
            if n+6<len(S) and S[n+6]=="a":
                n = n+5
            else:
                n = n+6
        else:
            n = n+5
    else:
        print("NO")
        break
    if n==len(S):
        print("YES")
        break

Submission status: Accepted

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

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

Submission status: Accepted

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

print("YES")

Submission status: Accepted

Solution code:
# dream dreamer erase eraser
# maerd remaerd esare resare
a = input()
a = a[::-1]



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

aaa(a)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = input()

S = S[::-1]


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


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

Submission status: Accepted

Solution code:
S = raw_input()

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

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

Submission status: Accepted

Solution code:
s = input()

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

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

Submission status: Accepted

Solution code:
s = input()

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

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

Submission status: Accepted

Solution code:

def erase_end(string):
    if string.endswith("dream"):
        string = string[:-5]
    elif string.endswith("dreamer"):
        string = string[:-7]
    elif string.endswith("erase"):
        string = string[:-5]
    elif string.endswith("eraser"):
        string = string[:-6]
    elif string == "":
        string = "YES"
    else:
        string = "NO"
    return string
    
string = input()

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

print(string)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
s = input()
t = ["maerd","remaerd","esare","resare"]
s = s[::-1]
while True:
    if len(s) == 0:
        print("YES")
        break
    elif s[:5] in t:
        s = s[5:]
    elif s[:6] in t:
        s = s[6:]
    elif s[:7] in t:
        s = s[7:]
    else:
        print("NO")
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
S=S.split("eraser")
S="".join(S)
S=S.split("erase")
S="".join(S)
S=S.split("dreamer")
S="".join(S)
S=S.split("dream")
S="".join(S)
print("YES") if S=="" else print("NO")

Submission status: Accepted

Solution code:
s = input()

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

calc(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

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

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
for i in range(len(s)//5+1):
    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]
    if len(s)==0:
        print('YES')
        exit()
print('NO')

Submission status: Accepted

Solution code:
s = input()[::-1]
flag = 1
i = 0
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:
        flag = 0
        break

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

Submission status: Accepted

Solution code:
st=input()
c="0"
j="0"
u="0"
for i in st:
    if i=="d" and u=="0" and c=="0":
        u="d"
        j="1"
    elif i=="r" and u=="d":
        u="r1"
    elif i=="e" and u=="r1":
        u="e1"
    elif i=="a" and u=="e1":
        u="a1"
    elif i=="m" and u=="a1":
        u="0"
        
    elif i=="e" and u=="0" and c=="0":
        u="e2"
        if j !="1":
            c="1"
    elif i=="r" and u=="e2":
        u="0"
        j="2"
    elif i=="a" and u=="0" and j=="2":
        u="a2"
    elif i=="s" and u=="a2":
        u="s"
    elif i=="e" and u=="s":
        u="0"
        c="0"
        j="3"
    elif i=="r" and u=="0" and j=="3":
        j="0"
    else:
        print("NO")
        exit(0)
if u=="0"and c=="0":
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
from sys import stdin

s = stdin.readline().rstrip().replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")

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

Submission status: Accepted

Solution code:
s=input()
while 'eraser' in s :
        s = s.replace('eraser', '')
while 'erase' in s :
        s = s.replace('erase', '')
while 'dreamer' in s :
        s = s.replace('dreamer', '')
while 'dream' in s :
        s = s.replace('dream', '')
if len(s) == 0:
        print('YES')
else:
        print('NO')

Submission status: Accepted

Solution code:
s = input()[::-1]
i = 0

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

print('YES' if i == len(s) else 'NO')

Submission status: Accepted

Solution code:
S = list(input())
a = list('dream')
b = list('dreamer')
c = list('erase')
d = list('eraser')

while True:
    if S[-5:] == a:
        del S[-5:]
    elif S[-7:] == b:
        del S[-7:]
    elif S[-5:] == c:
        del S[-5:]
    elif S[-6:] == d:
        del S[-6:]
    else:
        break
        
if len(S) == 0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
l = len(S)
while l > 0:
  if S[l-5:l] == 'erase' or S[l-5:l] == 'dream':
    l -= 5
  elif S[l-6:l] == 'eraser':
    l -= 6
  elif S[l-7:l] == 'dreamer':
    l -= 7
  else:
    l = -10
    
if l == 0:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
s = input()
s_rem = s
flag = 0
while len(s_rem) > 0:
    s_spl = s_rem[:5]
    if s_spl != "dream" and s_spl != "erase":
        flag = 1
        break
    s_rem = s_rem[5:]
    if s_rem[:1] == "":
        break
    elif s_spl == "dream" and (s_rem[:1] != "d" and s_rem[:1] != "e"):
        flag = 1
        break
    elif s_spl == "dream" and s_rem[:1] == "d":
        continue
    elif s_spl == "dream" and s_rem[:1] == "e":
        if s_rem[:5] == "erase":
            continue
        elif s_rem[:2] == "er":
            s_rem = s_rem[2:]
            continue
        else:
            flag = 1
            break
    elif s_spl == "erase" and (s_rem[:1] != "d" and s_rem[:1] != "e" and s_rem[:1] != "r"):
        flag = 1
        break
    elif s_spl == "erase" and s_rem[:1] == "r":
        s_rem = s_rem[1:]
        continue
    elif s_spl == "erase" and s_rem[:1] == "d":
        continue
    else:
        if s_rem[:5] == "erase":
            continue
        elif s_rem[:2] == "er":
            s_rem = s_rem[2:]
            continue
        else:
            flag = 1
            break

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

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

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
S = input()
while len(S) > 0:
    if 'dream' in S[-5:]:
        S = S[:-5]
        continue
    if 'dreamer' in S[-7:]:
        S = S[:-7]
        continue
    if 'erase' in S[-5:]:
        S = S[:-5]
        continue
    if 'eraser' in S[-6:]:
        S = S[:-6]
        continue
    break
if S == '':
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input()
dd = ['dream', 'dreamer', 'erase', 'eraser']
chara = ''.join(reversed(list(S)))
flag = True
while flag:
    cnt = 0
    for i in dd:
        r = ''.join(reversed(list(i)))
        if r in chara[:len(r)]:
            chara = chara[len(r):]
            break
        cnt += 1
    if cnt == 4:
        flag = False

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

Submission status: Accepted

Solution code:
import re
S = input()
if re.match(r"^(dream|dreamer|erase|eraser)*$", S):
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input().replace("eraser","")
#print(s)
s = s.replace("erase","")
#print(s)
s = s.replace("dreamer","")
#print(s)
s = s.replace("dream","")
#print(s)

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

Submission status: Accepted

Solution code:
s = input()

while True:
  if s[-5:]=="dream":
    s = s[0:-5]
    continue
  elif s[-7:]=="dreamer":
    s = s[0:-7]
    continue
  elif s[-5:]=="erase":
    s = s[0:-5]
    continue
  elif s[-6:]=="eraser":
    s = s[0:-6]
    continue
    
  if not s:
    print("YES")
  else:
    print("NO")
  break

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
l = ['dream','dreamer','erase','eraser']
L = []
pos = 0
f=True

for i in l:
    L.append(i[::-1])

while pos < len(S):
    no_match = True
    for candidate in L:
        if S[pos:pos+len(candidate)]==candidate:
            pos+=len(candidate)
            no_match =False
            break
    if no_match:
        f =False
        break


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
divide = ['dream','dreamer','erase','eraser']
dp = [0] * 100010
dp[0] = 1
for i in range(len(s)):
    # print(i)
    # print(dp)
    if dp[i] == False:
        continue
    for str in divide:
        # print(s[i:i+len(str)])
        if s[i:i+len(str)] == str:
            dp[i + len(str)] = 1

print("YES") if dp[len(s)] else print("NO")

Submission status: Accepted

Solution code:
import sys
s = list(input())
check =['dream','dreamer','erase','eraser']
while len(s) >= 8:
    if ''.join(s[-5:]) == check[0]:
        for _ in range(5): s.pop()
        continue
    if ''.join(s[-7:]) == check[1]:
        for _ in range(7): s.pop()
        continue
    if ''.join(s[-5:]) == check[2]:
        for _ in range(5): s.pop()
        continue
    if ''.join(s[-6:]) == check[3]:
        for _ in range(6): s.pop()
        continue
    print('NO')
    sys.exit()
if ''.join(s) == check[0] or ''.join(s) == check[1] or ''.join(s) == check[2] or ''.join(s) == check[3]:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s=input()
ll=['dream','dreamer', 'erase', 'eraser']

for w in ll[::-1]:
  s=s.replace(w, '')
if len(s)>0:
  print('NO')
else:
  print('YES')

Submission status: Accepted

Solution code:
s=input()
before=""
while len(s):
    if s[0:5]=="dream":
        if s[0:7]=="dreamer":
            before="er"
            s=s[7:]
        else:
            before=""
            s=s[5:]
    elif s[0:5]=="erase":
        if s[0:6]=="eraser":
            before="er"
            s=s[6:]
        else:
            before=""
            s=s[5:]
    elif before=="er":
        if s[0:3]=="ase":
            if s[0:4]=="aser":
                before="er"
                s=s[4:]
            else:
                before=""
                s=s[3:]
        else:
            break
    else:
        break
if len(s):
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
S=input()

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

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

e=0
f=0

while e==0:
    s=1
    for i in range(len(SS)):
        if S[f:f+len(SS[i])]==SS[i]:
            f+=len(SS[i])
            s=0
    if f==len(S):
        print('YES')
        e=1
    if s==1:
        print('NO')
        e=1

Submission status: Accepted

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

"""
#failed
import itertools

s=str(input())
add=["dream","dreamer","erase","eraser"]
t=[]

for i,_ in enumerate(add,1):
	for j in itertools.permutations(add,r=i):
		t.append("".join(j))

print(t)

temp=False
for i in range(len(t)):
	if(s==t[i]):
		temp=True
		break

if temp==True:
	print("Yes")
else:
	print("No")
	

"""

Submission status: Accepted

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

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

cnt = 0
while cnt < len(s):
    for w in words:
        if s[cnt: cnt + len(w)] == w:
            cnt += len(w)
            break
    else:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

Solution code:
s = str(input())
s = s.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if len(s)>1:
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
int_s = input()
str_sr = int_s[::-1]


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

str_r = list(map(lambda x: x[::-1], str_a))

result = True

while len(str_sr):
    currnt_flg = False
    for r in str_r:
        # print('r:' + r)
        if len(str_sr) >= len(r) and str_sr[:len(r)] == r:
            # print('ok')
            str_sr = str_sr[len(r):]
            # print(str_sr)
            current_flg = True
            break
    else:
        result = False
        break

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

Submission status: Accepted

Solution code:
s=input()

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

for w in words:
  s=s.replace(w, '')

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

Submission status: Accepted

Solution code:
S = input()
words = ['eraser', 'erase', 'dreamer', 'dream']
for w in words:
    S = S.replace(w,"")
print("YES" if len(S) == 0 else "NO")

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
divide = list(map(lambda phrase:phrase[::-1], ['dream', 'dreamer', 'erase', 'eraser']))

flag = False
i = 0
while i != len(S):
    flag = False
    for d in divide:
        if S[i:i+len(d)] == d:
            flag = True
            i += len(d)
            break

    if flag == False:
        break

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Daydream
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str

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

def solve(S: str):
    print(YES if is_valid2(S) else NO)
    return

def is_valid(S):
    if S == '':
        return True
    for token in tokens:
        sub = S[-len(token):]
        if sub == token:
            return is_valid(S[:-len(token)])
    return False

def is_valid2(S):
    import re
    x = r"^(dream|dreamer|erase|eraser)*$"
    return True if re.match(x, S) else False

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
S=S[::-1]
divide=['dream','dreamer','erase','eraser'] 
flag=False
for i in range(4):
  divide[i]=divide[i][::-1]

i=0
while i!=len(S):
  flag=False
  for d in divide:
    if S[i:i+len(d)]==d:   
      flag=True
      i+=len(d)
      break
    
  if flag==False:
     break
      
print('YES' if flag else 'NO')

Submission status: Accepted

Solution code:

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

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

pos = 0
possible = True

while pos < len(S):
    no_match = True
    for candidate in pattern:
        if S[pos : pos + len(candidate)] == candidate:
            pos += len(candidate)
            no_match = False
            break

    if no_match:
        possible = False
        break

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

Submission status: Accepted

Solution code:
s = input()
sr = s[::-1]
w = ["resare","esare","remaerd","maerd"]
for i in range(4):
    sr = sr.replace(w[i],"")
if sr == "":print("YES")
else:print("NO")

Submission status: Accepted

Solution code:
s=input()
w=""
for c in s[::-1]:
    w+=c
    if(w=="dreamer"[::-1] or w=="dream"[::-1] or w=="eraser"[::-1] or w=="erase"[::-1]):
        w=""
if(w==""):
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
strings=["dreamer","dream", "eraser","erase"]
i=-1
while len(s)!=0:
  if s[i-1:] in strings:
    s=s[:i-1]
    i=-1
  i-=1
  if i==-len(s):
    print('NO')
    exit()
if len(s)==0:
  print('YES')

Submission status: Accepted

Solution code:
S = list(raw_input())[::-1]

T = [list('dream')[::-1],list('dreamer')[::-1],list('erase')[::-1],list('eraser')[::-1]]

while True:
    flag = True
    if len(S) >= 5 and T[0] == S[0:5]:
        del S[0:5]
        flag = False
    if len(S) >= 7 and T[1] == S[0:7]:
        del S[0:7]
        flag = False
    if len(S) >= 5 and T[2] == S[0:5]:
        del S[0:5]
        flag = False
    if len(S) >= 6 and T[3] == S[0:6]:
        del S[0:6]
        flag = False
    if flag:
        break

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

Submission status: Accepted

Solution code:
import re
import sys
input = sys.stdin.readline

S = input()
regex = r'^(dream(er)?|erase(r)?)+$'
if re.match(regex, S) is None:
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
S = str(input())
def detect_dream(string):
    assert string[0] == "d"
    if string[:5] != "dream":
        return False, ""
    if len(string) >= 8:
        if string[:8] in ["dreamere", "dreamerd"]:
            return True, "dreamer"
    if string == "dreamer":
        return True, "dreamer"
    return True, "dream"

def detect_erase(string):
    assert string[0] == "e"
    if string[:5] != "erase":
        return False, ""
    if len(string) >= 6:
        if string[:6] == "eraser":
            return True, "eraser"
    return True, "erase"

while len(S) >= 5:
    if S[0] == "d":
        result, string = detect_dream(S)
    elif S[0] == "e":
        result, string = detect_erase(S)
    else:
        break
    if result:
        S = S.replace(string,"",1)
    else:
        break
if len(S) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
inp = input()
inp = inp[::-1]
li = ['dream','dreamer','erase','eraser']
li = [k[::-1] for k in li]
m = 0
while True:
    for i in li:
        if inp.startswith(i):
    	    inp = inp.replace(i,'',1)
    	    m = 0
    else:
    	if m == 1:
    		break
    	else:
    		m = 1
    		continue
    break
if inp == '':
	print("YES")
else:
	print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
flag=True
words={'dream','dreamer','erase','eraser'}
while flag:
    if S=="" :
        break
    if S[-7:] in words:
        S=S[0:-7]
        continue
    elif S[-6:] in words:
        S=S[0:-6]
        continue
    elif S[-5:] in words:
        S=S[0:-5]
        continue
    else :
        flag=False
if flag:
    print("YES")
else :
    print("NO")

Submission status: Accepted

Solution code:
s = input()
n = len(s) // 5
for i in range(n + 1):
   if len(s) == 0:
      print('YES')
      exit()
   if s[:6] == 'eraser':
      s = s[6:]
   elif s[:5] == 'erase':
      s = s[5:]
   elif ((s[:7] == 'dreamer') and (s[:10] != 'dreamerase') and (s[:11] != 'dreameraser')) or ((len(s) == 7) and (s == 'dreamer')):
      s = s[7:]
   elif (s[:5] == 'dream'):
      s = s[5:]
   else:
      print('NO')
      exit()

Submission status: Accepted

Solution code:
s = input()
t_list = ['dream', 'dreamer', 'erase', 'eraser']
ans = 'YES'
while len(s) > 0:
  for t in t_list:
    if s.endswith(t):
      s = s[:-len(t)]
      break
  else:
    ans = 'NO'
    break
print(ans)

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]
i = 0
while(i != len(s)):
    if s[i: i+5] == 'maerd':
        i = i + 5
        continue
    elif s[i: i+7] == 'remaerd':
        i = i + 7
        continue
    elif s[i: i+5] == 'esare':
        i = i + 5
        continue
    elif s[i: i+6] == 'resare':
        i = i + 6
        continue
    else:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

Solution code:
S = input()

flag = 1
while len(S):
    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:
        flag = 0
        break

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