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: Wrong Answer

Solution code:
def judge(S):
    cursor = 0
    len_S = len(S)
    while cursor < len_S:
        next_str = S[cursor:cursor+8]
        if next_str[:] == "dreamera":
            cursor += 5
        elif next_str[:7] == "dreamer":
            cursor += 7
        elif next_str[:6] == "eraser":
            cursor += 6
        elif next_str[:5] == "dream" or "erase":
            cursor += 5
        else:
            return False
        
    if cursor != len_S:
        return False
    
    return True


S = input()

if judge(S):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    L = ['dream', 'dreamer', 'erase', 'eraser']
    S = input()
    n = len(S)

    while True:
        if S[-6:] == 'dreamer' or S[-6:] == 'eraser':
            n -= 6
            S = S[:-6]
        elif S[-5:] == 'dream' or S[-5:] == 'erase':
            n -= 5
            S = S[:-5]
        else:
            break
    if len(S) == 0:
        print('YES')
    else:
        print('NO')

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    L = ['dream', 'dreamer', 'erase', 'eraser']
    S = input()
    n = len(S)

    while True:
        if S[-7:] == 'dreamer' or S[-7:] == 'eraser':
            n -= 7
            S = S[:-7]
        elif S[-5:] == 'dream' or S[-5:] == 'erase':
            n -= 5
            S = S[:-5]
        else:
            break
    if len(S) == -1:
        print('YES')
    else:
        print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
# import re

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

sys.setrecursionlimit(10000)

def text_match_words(text, words):
	match_words = []
	for word in words:
		if word == text[:len(word)]:
			match_words.append(word)
	return match_words

def is_match_for(text, words):
	if "" == text: 
		return True
	else:
		match_words = text_match_words(text, words)
		if [] == match_words:
			return False
		else:
			return any([is_match_for(text[len(match_word):], words) for match_word in match_words])

words = ("dream", "dreamer", "erase", "eraser")

s = "dream"*2000

if is_match_for(s, words):
	print("YES")
else:
	print("NO")

Submission status: Wrong Answer

Solution code:
def text_match_strs(text, strs):
	for str_ in strs:
		if str_ == text[:len(str_)]:
			return str_
	return None

s = input()

["dream", "dreamer", "erase", "eraser"]
words_and_next = {
	"": ("dream", "er"),
	"dream": ("dream", "er"),
	"er": ("dream", "ase"),
	"ase": ("dream", "r"),
	"r": ("dream", "er")
}

checkee_text = s
words = words_and_next[""]
match_word = text_match_strs(checkee_text, words)
while match_word:
	checkee_text = checkee_text[len(match_word):]
	words = words_and_next[match_word]
	match_word = text_match_strs(checkee_text, words)

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

Submission status: Wrong Answer

Solution code:
def text_match_strs(text, strs):
	for str_ in strs:
		if str_ == text[:len(str_)]:
			return str_
	return None

s = input()

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

match_word = text_match_strs(checkee_text, words)
while match_word:
	checkee_text = checkee_text[len(match_word):]
	match_word = text_match_strs(checkee_text, words)
	
if "" == checkee_text:
	print("YES")
else:
	print("NO")

Submission status: Wrong Answer

Solution code:
import sys

if __name__ == '__main__':
    S = sys.stdin.readline().rstrip()

    ls = ['dream', 'dreamer', 'erase', 'eraser']
    lenS = len(S)
    dp = [False for i in range(lenS + 10)]

    dp[0] = True

    for i in range(lenS):
        print([1 if d else 0 for d in dp])
        if not dp[i]:
            continue

        for w in ls:
            if S[i:i+len(w)] == w:
                dp[i+len(w)] = True

    r = 'YES' if dp[len(S)] else 'NO'

    print(r)

Submission status: Wrong Answer

Solution code:
import sys

if __name__ == '__main__':
    S = sys.stdin.readline().rstrip()

    ls = ['dream', 'dreamer', 'erase', 'eraser']
    ls = sorted(ls, key=lambda x: -len(x))

    while S != '':
        for w in ls:
            if S.find(w) == 0:
                S = S[len(w):]
                break
        else:
            print('NO')
            exit()

    print('YES')

Submission status: Wrong Answer

Solution code:
S = input()

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

for i in a:
    S = S.replace(i,'')
    if S == '':
        print('YES')
        exit()
print('NO')

Submission status: Wrong Answer

Solution code:
s = 'dreamdreamer'
# s = input()
tmps = [ 'dream', 'dreamer', 'erase', 'eraser' ]
lists = []
for tmp in tmps:
    lists.append(tmp[::-1])
s = s[::-1]

stack = ['']
rtn = 'NO'
while len(stack)>0:
    txt = stack.pop(0)
    for item in lists:
        tmp_txt = txt + item
        if tmp_txt == s:
            stack = []
            rtn = 'YES'
            break
        if(s.find(tmp_txt) == 0):
            stack.append(tmp_txt)

print(rtn)

Submission status: Wrong Answer

Solution code:
S = input()

S = S.replace("dream",'/*/').replace('erase','/+/')
S = S.split('/')
while '' in S:
    S.remove('')
print(S)
for i in range(len(S)):
    if S[i] == '*' or S[i] == '+':
        continue
    if S[i] == 'r':
        if i != 0 and S[i-1] == '+':
            continue
    elif S[i] == 'er':
        if i != 0 and S[i-1] == '*':
            continue
    print('NO')
    exit()
print('YES')

Submission status: Wrong Answer

Solution code:
import sys
S = input()
S = S.split("er")

#何もない文字列が2つ続いたらNO

flag = False
for s in S:
    if s not in {'asedream', 'dream', 'as'}:
        if s != '':
            print("NO")
            sys.exit()
    else:
        flag = False
    if s == "":
        if flag:
            print("NO")
            sys.exit()
        flag = True

print("YES")

Submission status: Wrong Answer

Solution code:
import re
S = input()

S = S.replace("dream",' ')
S = S.split()

for i in S:
    if re.match(r'^erer',i):
        i = i[2:]
    i = i.replace('erase',' ').split()
    if 'r' in i:
        i.remove('r')
    if i:
        print('NO')
        exit()
print('YES')

Submission status: Wrong Answer

Solution code:
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	#文字列を逆順にして、該当する単語を除いていく
	#eraseとeraserは"er"を決してしまうと判定できないので、先に消去
	s = input().replace("eraser", "").replace("erase", "").replace("dream", "").replace("dreamer", "")
	if s:
		print("NO")
	else:
		print("YES")

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	#文字列を逆順にして、該当する単語を除いていく
	s = input()[::-1].replace("eraser"[::-1], "").replace("erase"[::-1], "").replace("dream"[::-1], "").replace("dreamer"[::-1], "")
	if s:
		print("NO")
	else:
		print("YES")

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	#文字列を逆順にして、該当する単語を除いていく
	s = input()[::-1].replace("eraser"[:-1], "").replace("erase"[::-1], "").replace("dream"[::-1], "").replace("dreamer"[::-1], "")
	if s:
		print("NO")
	else:
		print("YES")

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()

while s != "":
  if len(s) < 5:
    print('NO')
    exit()
  if s.endswith('dream'):
    s = s.rstrip('dream')
  elif s.endswith('dreamer'):
    s = s.rstrip('dreamer')
  elif s.endswith('erase'):
    s = s.rstrip('erase')
  elif s.endswith('eraser'):
    s = s.rstrip('eraser')
  else:
    print('NO')
    exit()

print('YES')

Submission status: Wrong Answer

Solution code:
s = input()

while s != "":
  if len(s) < 5:
    print('No')
    exit()
  if s.endswith('dream'):
    s = s.rstrip('dream')
  elif s.endswith('dreamer'):
    s = s.rstrip('dreamer')
  elif s.endswith('erase'):
    s = s.rstrip('erase')
  elif s.endswith('eraser'):
    s = s.rstrip('eraser')
  else:
    print('No')
    exit()
  
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys

st = input()

def tree(str):
    if(str == ""):
        print("YES")
        sys.exit()
    if(str.startswith("d")):
        if(str.startswith("dream")):
            tree(str.replace("dream",""))
        if (str.startswith("dreamer")):
            tree(str.replace("dreamer",""))
    elif(str.startswith("e")):
        if (str.startswith("erase")):
            tree(str.replace("erase",""))
        if (str.startswith("eraser")):
            tree(str.replace("eraser",""))

tree(st)
print("NO")

Submission status: Wrong Answer

Solution code:
import sys

st = input()

if(st == ""):
    print("NO")
    sys.exit()

def tree(str):
    if(str == ""):
        print("YES")
        sys.exit()
    if(str.startswith("d")):
        if(str.startswith("dream")):
            tree(str.replace("dream",""))
        if (str.startswith("dreamer")):
            tree(str.replace("dreamer",""))
    elif(str.startswith("e")):
        if (str.startswith("erase")):
            tree(str.replace("erase",""))
        if (str.startswith("eraser")):
            tree(str.replace("eraser",""))
tree(st)
print("NO")

Submission status: Wrong Answer

Solution code:
import sys

st = input()

if(st == ""):
    print("NO")
    sys.exit()

def tree(str):
    if(str == ""):
        print("YES")
        sys.exit()
    if(str[0] == "d"):
        if(str[:5] == "dream"):
            temp = str.replace("dream","")
            tree(temp)
        if (str[:7] == "dreamer"):
            temp = str.replace("dreamer","")
            tree(temp)
    elif(str[0] == "e"):
        if (str[:5] == "erase"):
            temp = str.replace("erase","")
            tree(temp)
        if (str[:6] == "eraser"):
            temp = str.replace("eraser","")
            tree(temp)
tree(st)
print("NO")

Submission status: Wrong Answer

Solution code:
import sys

st = input()

if(st == ""):
    print("NO")
    sys.exit()

def tree(str):
    if(str == ""):
        print("YES")
        sys.exit()
    if(str[0] == "d"):
        if(str[:5] == "dream"):
            tree(str[:].replace("dream",""))
        if (str[:7] == "dreamer"):
            tree(str[:].replace("dreamer",""))
    elif(str[0] == "e"):
        if (str[:5] == "erase"):
            tree(str[:].replace("erase",""))
        if (str[:6] == "eraser"):
            tree(str[:].replace("eraser",""))
tree(st)
print("NO")

Submission status: Wrong Answer

Solution code:
import sys

st = input()

if(st == ""):
    print("NO")
    sys.exit()

def tree(str):
    if(str == ""):
        print("YES")
        sys.exit()
    if(str[0] == "d"):
        if(str[:5] == "dream"):
            tree(str.replace("dream",""))
        if (str[:7] == "dreamer"):
            tree(str.replace("dreamer",""))
    elif(str[0] == "e"):
        if (str[:5] == "erase"):
            tree(str.replace("erase",""))
        if (str[:6] == "eraser"):
            tree(str.replace("eraser",""))
tree(st)
print("NO")

Submission status: Wrong Answer

Solution code:
import sys

st = input()

if(st == ""):
    print("NO")
    sys.exit()

def tree(str):
    if(str == ""):
        print("YES")
        sys.exit()
    if(str.startswith("d")):
        if(str.startswith("dream")):
            tree(str.replace("dream",""))
        if (str.startswith("dreamer")):
            tree(str.replace("dreamer",""))
    elif(str.startswith("e")):
        if (str.startswith("erase")):
            tree(str.replace("erase",""))
        if (str.startswith("eraser")):
            tree(str.replace("eraser",""))
    else:
        print("NO")
        sys.exit()
tree(st)
print("NO")

Submission status: Wrong Answer

Solution code:
import sys

st = input()

def tree(str):
    if(str == ""):
        print("YES")
        sys.exit()
    if(str.startswith("d")):
        if(str.startswith("dream")):
            tree(str.replace("dream",""))
        if (str.startswith("dreamer")):
            tree(str.replace("dreamer",""))
    elif(str.startswith("e")):
        if (str.startswith("erase")):
            tree(str.replace("erase",""))
        if (str.startswith("eraser")):
            tree(str.replace("eraser",""))
    else:
        print("NO")
        sys.exit()
tree(st)
print("NO")

Submission status: Wrong Answer

Solution code:
import sys

st = input()

def tree(str):
    if(str == ""):
        print("YES")
        sys.exit()
    if(str.startswith("d")):
        if(str.startswith("dream")):
            tree(str.replace("dream",""))
        if (str.startswith("dreamer")):
            tree(str.replace("dreamer",""))
    elif(str.startswith("e")):
        if (str.startswith("erase")):
            tree(str.replace("erase",""))
        if (str.startswith("eraser")):
            tree(str.replace("eraser",""))
    else:
        pass
tree(st)
print("NO")

Submission status: Wrong Answer

Solution code:
import re
import sys

str = input()
pattern = ["dream","dreamer","erase","eraser"]
for i in pattern:
    str2 = re.sub(i,"",str)
    newpattern = pattern[:]
    newpattern.remove(i)
    for j in newpattern:
        str3 = re.sub(j,"",str2)
        newpattern.remove(j)
        for k in newpattern:
            str4 = re.sub(j,"",str3)
            newpattern.remove(k)
            for l in pattern:
                str5 = re.sub(j,"",str4)
                if(str5 == ""):
                    print("YES")
                    sys.exit()
print("NO")

Submission status: Wrong Answer

Solution code:
import re
import sys

str = input()
pattern = ["dream","dreamer","erase","eraser"]
for i in pattern:
    str2 = re.sub(i,"",str)
    for j in pattern:
        str3 = re.sub(j,"",str2)
        for k in pattern:
            str4 = re.sub(j,"",str3)
            for l in pattern:
                str5 = re.sub(j,"",str4)
                if(str5 == ""):
                    print("YES")
                    sys.exit()
print("NO")

Submission status: Wrong Answer

Solution code:
def c_daydream(S):
    # Sを逆にしたものから除いていき、空文字にできるか？
    s = S[::-1]
    word = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
    ans = 'YES'
    while s:
        for w in word:
            if s.startswith(w):  # 先頭が文字列wで始まっていたら、取り除く
                s = s.replace(w, '', 1)
                continue
        else:
            ans = 'NO'
            break
    return ans

S = input().strip()
print(c_daydream(S))

Submission status: Wrong Answer

Solution code:
s = input()
n_s = len(s)
S = ''
for i in range(n_s):
    S += s[-i-1]
words = ["maerd", "remaerd", "esare", "resare"]
cnt = 0
result = 'Yes'
while True:
    if S[cnt:cnt+5] == 'maerd':
        cnt += 5
    elif S[cnt:cnt+5] == 'esare':
        cnt += 5
    elif S[cnt:cnt+6] == 'resare':
        cnt += 6
    elif S[cnt:cnt+7] == 'remaerd':
        cnt += 7
    else:
        result = 'No'
        break
    if cnt == n_s:
        break
print(result)

Submission status: Wrong Answer

Solution code:
s = input()
n_s = len(s)
S = ''
for i in range(n_s):
    S += s[-i-1]
words = ["maerd", "remaerd", "esare", "resare"]
cnt = 0
result = 'Yes'
while True:
    
    if S[cnt:cnt+5] == 'maerd':
        cnt += 5
    elif S[cnt:cnt+5] == 'esare':
        cnt += 5
    elif S[cnt:cnt+6] == 'resare':
        cnt += 6
    elif S[cnt:cnt+7] == 'remaerd':
        cnt += 7
    else:
        result = 'No'
        break
    if cnt == n_s:
        break
print(result)

Submission status: Wrong Answer

Solution code:
s = input()
n_s = len(s)
S = ''
for i in range(n_s):
    S += s[-i-1]
words = ["maerd", "remaerd", "esare", "resare"]
cnt = 0
result = 'Yes'
print(S)
while True:
    
    if S[cnt:cnt+5] == 'maerd':
        cnt += 5
    elif S[cnt:cnt+5] == 'esare':
        cnt += 5
    elif S[cnt:cnt+6] == 'resare':
        cnt += 6
    elif S[cnt:cnt+7] == 'remaerd':
        cnt += 7
    else:
        result = 'No'
        break
    if cnt == n_s:
        break
print(result)

Submission status: Wrong Answer

Solution code:
import re
S = input()
S = re.sub(r'dream(er)?', '', S)
S = re.sub(r'erase(r)?', '',S)
if S == '':
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
s=list(input())
s.reverse()
s="".join(s)
s=s.replace("resare","").replace("remaerd","").replace("maerd","").replace("esare","")
if s=="":
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s=list(input())
s.reverse()
s="".join(s)
s=s.replace("resare","").replace("remnerd","").replace("maerd","").replace("esare","")
if s=="":
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s=list(input())
s.reverse()
s="".join(s)
s=s.replace("remnerd","").replace("resare","").replace("maerd","").replace("esare","")
if s=="":
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s=list(input())
s.reverse()
s="".join(s)
s=s.replace("resare","").replace("remnerd","").replace("maerd","").replace("esare","")
if s=="":
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s=list(input())
s.reverse()
s="".join(s)
s=s.replace("maerd","").replace("resare","").replace("remnerd","").replace("esare","")
if s=="":
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s = list(reversed(list(str(input()))))



for i in range(len(s)- 5):
    if s[i] == 'e' and s[i+1] == 'r' and s[i + 2] == 'a' and s[i + 3] == 's' and s[i + 4] == 'e' and s[i+5] == 'r':
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''
        s[i + 5] = ''
        
        
for i in range(len(s)- 4):
    if s[i] == 'e' and s[i+1] == 'r' and s[i + 2] == 'a' and s[i + 3] == 's' and s[i + 4] == 'e' :
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''
        

    
    
    
for i in range(len(s)- 6):
    if s[i] == 'd' and s[i+1] == 'r' and s[i + 2] == 'e' and s[i + 3] == 'a' and s[i + 4] == 'm' and s[i + 5] == 'e' and s[i + 6] == 'r':
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''
        s[i + 5] = ''
        s[i+6] = ''
        

    
for i in range(len(s)- 4):
    if s[i] == 'd' and s[i+1] == 'r' and s[i + 2] == 'e' and s[i + 3] == 'a' and s[i + 4] == 'm' :
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''

        
while '' in s:
    s.remove('')
    
if s == []:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
S = input()[::-1]
T = ["dream"[::-1],"dreamer"[::-1],"erase"[::-1],"eraser"[-1]]
Ans = "YES"
while len(S) > 0:
    if S[0:5] in T:
        S = S[5:]
        continue
    elif S[0:7] in T:
        S = S[7:]
        continue
    else:
        Ans = "NO"
        break
print(Ans)

Submission status: Wrong Answer

Solution code:
S = input()

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

a=[]

for i in range(len(wl)):
    for j in range(len(wl)):
        a.append(wl[i]+wl[j])

for k in a:
    if S in k:
        print("YES")
        break
    if k == a[-1:][0]:
        print("No")

Submission status: Wrong Answer

Solution code:
N = input()

if N.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '') == '':
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
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")

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
ls = [word[::-1] for word in ["dream", "dreamer", "erase", "eraser"]]

for word in ls:
    s = s.replace(word, "")

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
string = input()
erase = 'erase'
eraser = 'eraser'
dream = 'dream'
dreamer = 'dreamer'
er = 'er'
a = 'a'
r = 'r'
while True:
    if string[:5] == dream:
        if string[5:7] == er:
            if string[7:8] == a:
                string = string[5:]
            else:
                string = string[7:]
        else:
            string = string[5:]
    elif string[:5] == erase:
        if string[5:6]== r:
            if string[6:7] == a:
                string = string[5:]
            else:
                string = string[6:]
        else:
                string = string[5:]
    elif string == []:
        print('YES')
        break
    else:
        print('NO')
        break

Submission status: Wrong Answer

Solution code:
s=input()
w=["dream","dreamer","erase","eraser",""]
while True:
    

    if s[0:5]==w[0]:
        if s[5:7]=="er": #dremaerかeraserかerase
            if s[7]=="a": #erはeraseかeraserのer
                s=s[5:]
            else:
                s=s[7:]
        else:
            s=s[5:]

    elif s[0:5]==w[2]:
        if s[5]=="r": 
            s=s[6:]
        else:
            s=s[5:]
    else:
        print("NO")
        exit()

    if len(s)<=6:
        if s in w:
            print("YES")
            exit()
        else:
            print("NO")
            exit()
    if len(s)==7 or len(s)==8:
    
        print("NO")
        exit()
    #print(s)

Submission status: Wrong Answer

Solution code:
s = 'dreameraser'##input()
l = ['dream', 'dreamer', 'erase', 'eraser']
pos = 0
flg = True
can = False
while flg:
    flg = False
    for i in range(len(l)):
        st = len(l[i])+pos
        if st<=len(s):
            if s[st*(-1):len(s)-pos] == l[i]:
                pos += len(l[i])
                if pos == len(s):
                    can = True
                    break
                flg = True
if can == True:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
s = input()
l = ['dream', 'dreamer', 'erase', 'eraser']
l3 = list(_[-3:] for _ in l)
llen = [5, 7, 5, 6]
pos = 0
flg = True
can = False
while flg and (3+pos)<=len(s):
    flg = False
    for i in range(len(l)):
        if s[-3-pos:len(s)-pos] == l3[i]:
            pos += llen[i]
            if pos == len(s):
                can = True
                break
            flg = True
if can == True:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
s = input()
l = ['dream', 'dreamer', 'erase', 'eraser']
l3 = list(_[-3:] for _ in l)
llen = [5, 7, 5, 6]
pos = 0
flg = True
can = False
while flg:
    flg = False
    for i in range(len(l)):
        if s[-3-pos:len(s)-pos] == l3[i]:
            pos += llen[i]
            if pos == len(s):
                can = True
                break
            flg = True
if can == True:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

for i in l:
    s = s.replace(i,"")

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

def is_contains_word(s, words):
    for word in words:
        if s == '':
            return True
        if s.endswith(word):
            return is_contains_word(s.replace(word, ''), words)
    return False

def main():
    s = input()
    words = ('dream', 'dreamer', 'erase', 'eraser')

    print('YES') if is_contains_word(s, words) else print('NO')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
l = ['dream', 'dreamer', 'erase', 'eraser']

s = input()
for i in l:
    s = s.replace(i, '')
if s == '':
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys

s = input()

a1 = "dream"
a2 = "dreamer"
a3 = "erase"
a4 = "eraser"

while True:
    if len(s) < 5:
        print("NO")
        sys.exit(0)
    elif len(s) == 5:
        if s in ["dream", "erase"]:
            print("YES")
        else:
            print("NO")
        sys.exit(0)
    elif len(s) == 6:
        if s == "eraser":
            print("YES")
        else:
            print("NO")
        sys.exit(0)
    elif len(s) == 7:
        if s == "dreamer":
            print("YES")
        else:
            print("NO")
        sys.exit(0)
    else:
        if s[:7] in ["dreamerd", "dreamere"]:
            s = s[7:]
        elif s[:6] in ["dreamd", "dreame", "erasee", "erased"]:
            s = s[5:]
        elif s[:7] in ["eraserd", "erasere"]:
            s = s[6:]
        else:
            print("NO")
            sys.exit(0)

Submission status: Wrong Answer

Solution code:
s = input()
key = 1
i = 0

while i < len(s):
    if s[i:i+5] == "dream":
        if s[i+5:i+10] != "erase" and s[i+5:i+7] == "er":
            i += 7
        elif s[i+5:i+11] == "eraser":
            i += 11
        elif s[i+5:i+10] == "erase":
            i += 10
        else:
            i += 5
    elif s[i:i+5] == "erase":
        i += 5
    elif s[i:i+6] == "eraser":
        i += 6
    else:
        key = 0
        break
        
if key == 0:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
given = ["dreamer", "eraser", "dream", "erase"]
S = input()
while S != "":
    tmp = S
    for i in given:
        if S.endswith(i):
            S = S.replace(i, "")
            if len(S) == 0:
                print("YES")
                break
    if tmp == S:
        print("NO")
        break

Submission status: Wrong Answer

Solution code:
given = ["dream", "dreamer", "erase", "eraser"]
S = input()
while S != "":
    tmp = S
    for i in given:
        if S.endswith(i):
            S = S.replace(i, "")
            if len(S) == 0:
                print("YES")
                break
    if tmp == S:
        print("NO")
        break

Submission status: Wrong Answer

Solution code:
s = input()
i = 0
while True:
	if i == len(s):
		print('YES')
		break
	if len(s) - i < 5:
		print('NO')
		break
	if s[i] == 'd':
		if s[i:i+5] != 'dream':
			print('NO')
			break
		if len(s) - i < 7:
			i += 5
			continue
		if s[i:i+7] != 'dreamer':
			i += 5
			continue
		if len(s) - i == 7 or s[i+7] == 'a':
			i += 7
			continue
		i += 5
		continue
	if s[i] == 'e':
		if s[i:i+5] != 'erase':
			print('NO')
			break
		if len(s) - i < 6:
			i += 5
			continue
		if s[i:i+6] != 'eraser':
			i += 5
			continue
		if len(s) - i == 6 or s[i+6] != 'a':
			i += 6
			continue
		i += 5
		continue
	print('NO')
	break

Submission status: Wrong Answer

Solution code:
s = input() + "ZZZZZZZZZZZZZ"

i = 0
ans = "NO"

while(True):

 if s[i:i+5]=="dream" or s[i:i+7]=="dreamer":
  if s[i+5]=="d" or s[i+5]=="Z" or s[i+7]=="a":
   i += 5
  elif s[i+7]=="d" or s[i+7]=="e" or s[i+7]=="Z":
   i += 7
  else:
   break
 
 elif s[i:i+5]=="erase" or s[i:i+6]=="eraser":
  if s[i+5]=="d" or s[i+5]=="e" or s[i+5]=="Z":
   i += 5
  elif s[i+5]=="r":
   i += 6
  else:
   break

 elif s[i]=="Z":
  ans = "YES"
  break

 else:
  break

print(ans)

Submission status: Wrong Answer

Solution code:
sin = input()
n = len(sin)
s = sin + "ZZZZZZZZZZZZZ"

i = 0
ans = "NO"

while(True):

 if s[i]=="d":
  if s[i:i+5]!="dream" and s[i:i+7]!="dreamer":
   break
  if s[i+5]=="d" or s[i+5]=="Z" or s[i+7]=="a":
   i += 5
  elif s[i+7]=="d" or s[i+7]=="e" or s[i+7]=="Z":
   i += 7
  else:
   break
 
 elif s[i]=="e":
  if s[i:i+5]!="erase" and s[i:i+6]!="eraser":
   break
  if s[i+5]=="d" or s[i+5]=="e" or s[i+5]=="Z":
   i += 5
  elif s[i+5]=="r":
   i += 6
  else:
   break

 elif s[i]=="Z":
  ans = "YES"
  break

 else:
  break

print(ans)

Submission status: Wrong Answer

Solution code:
sin = input()
n = len(sin)
s = sin + "ZZZZZZZZZZZZZ"

i = 0
ans = "No"

while(True):

 if s[i]=="d":
  if s[i:i+5]!="dream" and s[i:i+7]!="dreamer":
   break
  if s[i+5]=="d" or s[i+5]=="Z" or s[i+7]=="a":
   i += 5
  elif s[i+7]=="d" or s[i+7]=="e" or s[i+7]=="Z":
   i += 7
  else:
   break
 
 elif s[i]=="e":
  if s[i:i+5]!="erase" and s[i:i+6]!="eraser":
   break
  if s[i+5]=="d" or s[i+5]=="e" or s[i+5]=="Z":
   i += 5
  elif s[i+5]=="r":
   i += 6
  else:
   break

 elif s[i]=="Z":
  ans = "Yes"
  break

 else:
  break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

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

s = ns()
length = len(s)
flag = 1
while length != 0:
    if s[-5:] == "dream" or s[-5:] == "erase":
        length -= 5
        continue
    elif s[-6:] == "eraser":
        length -= 6
        continue
    elif s[-7:] == "dreamer":
        length -= 7
        continue
    else:
        flag = 0
        break

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

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

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

s = ns()
length = len(s)
flag = 1
while length != 0:
    if s[-5:] == "dream" or s[-5:] == "erase":
        length -= 5
    elif s[-6:] == "eraser":
        length -= 6
    elif s[-7:] == "dreamer":
        length -= 7
    else:
        flag = 0
        break

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

Submission status: Wrong Answer

Solution code:
import sys
s=input()
while(s):
  if(s[:7]=="dreamer"):
    s=s[7:]
  elif(s[:5]=="dream"):
    s=s[5:]
  elif(s[:6]=="eraser"):
    s=s[6:]
  elif(s[:5]=="erase"):
    s=s[5:]
  else:
    print("NO")
    sys.exit()
print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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