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:
strings = input()

rev_list = ["maerd", "esare", "remaerd", "resare"]

match = ""

for s in reversed(strings):  
  match += s
  
  if match in rev_list:
    match = ""

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

Submission status: Accepted

Solution code:
s = input()

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

while len(s) != 0:
    is_matched = False
    for p in pattern:
        if s.endswith(p):
            s = s[:-len(p)]
            is_matched = True
            break
    if not is_matched:
        break

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

Submission status: Accepted

Solution code:
s=str(input())
t=''
len1=0
flag=0
l=len(s)
while len1<=len(s):
    if s[l-(len1+7):]=='dreamer'+t:
        t='dreamer'+t
        flag+=1
        len1+=7
    else:
        if s[l-(len1+5):]=='dream'+t:
            t='dream'+t
            flag+=1
            len1+=5
        else:
            if s[l-(len1+6):]=='eraser'+t:
                t='eraser'+t
                flag+=1
                len1+=6
            else:
                if s[l-(len1+5):]=='erase'+t:
                    t='erase'+t
                    flag+=1
                    len1+=5
                else:
                    pass
 
    if flag==0:
        break
    else:
        if s==t:
            print('YES')
            break
        else:
            flag=0
if s==t:
    pass
else:
    print('NO')

Submission status: Accepted

Solution code:

S = input()

S_inv = S[::-1]

def judge(S):
    cursor = 0
    len_S = len(S)
    
    while cursor < len_S:
        next_str = S[cursor:cursor+7]
        if next_str[:] == "remaerd":
            cursor += 7
        elif next_str[:6] == "resare":
            cursor += 6
        elif next_str[:5] == "esare":
            cursor += 5
        elif next_str[:5] == "maerd":
            cursor += 5
        else:
            return False
        
    if cursor != len_S:
        return False
    
    return True

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

Submission status: Accepted

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 (next_str[:5] == "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: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
a = ''.join(S.split('eraser'))
b = ''.join(a.split('erase'))
c = ''.join(b.split('dreamer'))
d = ''.join(c.split('dream'))
if (d):
	print('NO')
else:
	print('YES')

Submission status: Accepted

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

    while True:
        if S[-7:] == 'dreamer':
            n -= 7
            S = S[:-7]
        elif 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: Accepted

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

Submission status: Accepted

Solution code:
S = input()
keywords = ["dream", "dreamer", "erase", "eraser"]
while(True):
    if len(S) == 0:
        print("YES")
        break
    for key in keywords:
        if S.endswith(key):
            S = S[:-len(key)]
            break
    else:
        print("NO")
        break

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

if (((S.replace("eraser", "")).replace("erase", "")).replace("dreamer", "")).replace("dream", "") == "" :
    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()

a = s.split('eraser')

for i in a:
    b = i.split('erase')
    for j in b:
        c = j.split('dreamer')
        for k in c:
            d = k.split('dream')
            for l in d:
                if l != '':
                    print('NO')
                    exit()
print('YES')

Submission status: Accepted

Solution code:
s = input()

while len(s) >= 5:
    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()
        
if len(s) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
import sys

def text_match_word(text, words):
    for word in words:
        if word == text[:len(word)]:
            return word

words_next = (("dream", "er"), ("erase", "r"))
words_next_dict = dict(words_next)

s = input()

before_match_word = ""
while "" != s:
    search_words = list(words_next_dict.keys())
    if before_match_word in words_next_dict:
        search_words.append(words_next_dict[before_match_word])
    match_word = text_match_word(s, search_words)
    if match_word != None:
        s = s[len(match_word):]
    else:
        print("NO")
        sys.exit()
    before_match_word = match_word
    
print("YES")

Submission status: Accepted

Solution code:
import re

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

Submission status: Accepted

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):
        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: Accepted

Solution code:
S = list(input())
S = S[::-1]
is_NO = 0
i = 0
while i<len(S):
    if S[i] == 'm':
        if S[i+1] == 'a' and S[i+2] == 'e' and S[i+3] == 'r' and S[i+4] == 'd':
            i += 5
        else:
            is_NO = 1
            break
    elif S[i] == 'r' and S[i+1] == 'e' and S[i+2] == 'm':
        if  S[i+3] == 'a' and S[i+4] == 'e' and S[i+5] == 'r' and S[i+6] == 'd':
            i += 7
        else:
            is_NO = 1
            break
    elif S[i] == 'e':
        if S[i+1] == 's' and S[i+2] == 'a' and S[i+3] == 'r' and S[i+4] == 'e':
            i += 5
        else:
            is_NO = 1
            break
    elif S[i] == 'r' and S[i+1] == 'e' and S[i+2] == 's':
        if S[i+3] == 'a' and S[i+4] == 'r' and S[i+5] == 'e':
            i += 6
        else:
            is_NO = 1
            break
    else:
        is_NO = 1
        break
print("NO" if is_NO else "YES")

Submission status: Accepted

Solution code:
S = input()

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

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

Submission status: Accepted

Solution code:
import re
d = input()
if re.match("(dream|dreamer|erase|eraser)+$",d):
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
import sys
S = input()[::-1]
ls = ["maerd", "remaerd", "esare", "resare"]
n = 0
while n != len(S):
    flag = False
    for i in ls:
        tmp_n = len(i)
        if S[n:n+tmp_n] == i:
            n += len(i)
            flag = True
            break
    if not flag:
        print("NO")
        sys.exit()
print("YES")

Submission status: Accepted

Solution code:
s = raw_input()

while len(s) > 0:
	if s[-5:] == 'erase' :
		s = s[:-5]

	elif s[-5:] == 'dream' :
		s = s[:-5]

	elif s[-7:] == 'dreamer' :
		s = s[:-7]

	elif s[-6:] == 'eraser' :
		s = s[:-6]

	else :
		print 'NO'
		break

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

Submission status: Accepted

Solution code:
S = input()
flag = False
is_dream, is_erase = False, False

while len(S) >= 5:
    is_dream = S[:5] == 'dream'
    is_erase = S[:5] == 'erase'

    if len(S) == 5:
        if is_dream or is_erase:
            flag = True
        else:
            flag = False
        break

    if len(S) == 6:
        if is_erase and S[-1] == 'r':
            flag = True
        else:
            flag = False
        break

    if len(S) == 7:
        if is_dream and S[-2:] == 'er':
            flag = True
        else:
            flag = False
        break


    if len(S) in [8, 9]:
        flag = False
        break

    if len(S) >= 10:
        S1 = S[5:10]

        if S1 in ['dream', 'erase']:
            S = S[5:]
            continue
        elif is_erase:
            if S[5] == 'r':
                S = S[6:]
                continue
        elif is_dream:
            if S[5:7] == 'er':
                S = S[7:]
                continue
        else:
            flag = False
            break
    flag = False
    break

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

Submission status: Accepted

Solution code:
import sys
S = sys.stdin.readline().strip()
dp = [False] * (len(S) + 1)
dp[0] = True

ws = ['dream', 'dreamer' ,'erase' ,'eraser']
for i, c in enumerate(S):
    for w in ws:
        j = i-len(w) + 1
        if j >= 0 and dp[j] and S[j:i+1] == w:
            dp[i+1] = True
        if dp[i+1]:
            break
print('YES' if dp[len(S)] else 'NO')

Submission status: Accepted

Solution code:
S = input()

S = S.replace("dream",'/*/').replace('erase','/+/')
S = [i for i in S.split('/') if i != '']
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: Accepted

Solution code:
def m():
    s = str(input())
    d = ["dream", "dreamer"]
    e = ["erase", "eraser"]
    i = len(s)
    while i >= 5:
        if s[i-5:i] == d[0]:
            i -= 5
            continue
        if s[i-5:i] == e[0]:
            i -= 5
            continue
        if s[i-7:i] == d[1]:
            i -= 7
            continue
        if s[i-6:i] == e[1]:
            i -= 6
            continue
        return "NO"
    return "YES"

print(m())

Submission status: Accepted

Solution code:
import re
print(['NO','YES'][''==''.join(re.split('maerd|remaerd|esare|resare',input()[::-1]))])

Submission status: Accepted

Solution code:
S = input()[::-1]
A = ["dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1]]
s = 0
t = 1
while(s != len(S)):
    t2 = 0
    for a in A:
        if S[s:s+len(a)] == a:
            s += len(a)
            t2 = 1

    if t2 ==0:
        t = 0
        break
    
if t:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = input()
 
stack = []
for c in reversed(s):
  stack.append(c)
  if len(stack) > 7:
    print('NO')
    break  
  if len(stack) >= 5 and ''.join(reversed(stack)) in ('erase', 'dream', 'eraser', 'dreamer'):
    stack = []
else:
  print('NO' if stack else 'YES')

Submission status: Accepted

Solution code:
s = input()

stack = []
for c in reversed(s):
  stack.append(c)
  if len(stack) > 7:
    print('NO')
    break  
  if ''.join(reversed(stack)) in ('erase', 'dream', 'eraser', 'dreamer'):
    stack = []
else:
  print('NO' if stack else 'YES')

Submission status: Accepted

Solution code:
S = input()
T = ''
t = ''
result = 'YES'
dream_list = ['maerd', 'remaerd', 'esare', 'resare']

for i in range(1, len(S)+1):
    t += S[-i]
    if t in dream_list:
        T += t
        t = ''

    if len(t) >7:
        result = 'NO'
        break

if t != '':
    result = 'NO'

print(result)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S = input()

while 1:
    if S == "":
        print("YES")
        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:
        print("NO")
        break

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

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

S_rev = ""
div_rev = []

S_rev = S[::-1] #reverse input string
for i in range(4):
    div_rev.append(div[i][::-1]) #reverse divider words

str_len = len(S)
div_len = 0
cnt = 0
temp = cnt
flag = True

while(cnt < str_len):
    temp = cnt
    for j in range(4):
        div_len = len(div_rev[j])
        if(S_rev[cnt:(cnt+div_len)] == div_rev[j]):
            cnt += div_len
    if(temp == cnt):
        flag = False
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
T=""
Vocab=["dream", "dreamer", "erase", "eraser"]
Reverse=[]
for word in Vocab:
    Reverse.append(word[::-1])

SReverse = S[::-1]

def searchWord(TargetString, WordList):
    for word in WordList:
        index=TargetString.find(word)
        if index == 0:
            return True, index+len(word)
        else:
            pass
    return False, index

def cutString(TargetString, slicePoint):
    replacement = TargetString[slicePoint:]
    return replacement

while True:
    if searchWord(SReverse, Reverse)[0]:
        index = searchWord(SReverse, Reverse)[1]
        SReverse = cutString(SReverse, index)
    else:
        break

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

Submission status: Accepted

Solution code:
S = input()
ws = ['dream','dreamer','erase','eraser']

while S:
    for w in ws:
        if S.endswith(w):
            S = S[:-len(w)]
            break
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
s=input()
while True:
    if len(s)==0:
        print("YES")
        break
    elif s[:7]=="dreamer":
        if s[7:11]=="aser":
            s=s[11:]
        elif s[7:10]=="ase":
            s=s[10:]
        #順番に注意
        else:
            s=s[7:]
    elif s[:6]=="eraser":
        s=s[6:]
    elif s[:5]=="dream" or s[:5]=="erase":
        s=s[5:]
    else:
        print("NO")
        break

Submission status: Accepted

Solution code:
def main():
    s = str(input())
    while(len(s) != 0):
        if s[-6:] == "eraser":
            s = s[:-6]
            continue
        elif s[-7:] == "dreamer":
            s = s[:-7]
            continue
        elif s[-5:] == "erase":
            s = s[:-5]
            continue
        elif s[-5:] == "dream":
            s = s[:-5]
            continue
        else:
            return print("NO")
    print("YES")
    


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import re
s = input()

s = s.replace("eraser", "").replace("erase","")\
	.replace("dreamer", "").replace("dream","")

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    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()
a = ['dream', 'dreamer', 'erase', 'eraser']

while s:
    tmp = s
    for b in a:
        if s[-len(b):] == b:
            s = s[:-len(b)]
    if tmp == s:
        break

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

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
kws = ['dream','dreamer','erase','eraser']
kws = [kw[::-1] for kw in kws]

i = 0
while i < len(S):
    for kw in kws:
        if S[i:i+len(kw)] == kw:
            i += len(kw)
            break
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
import math
import numpy as np

S = str(input())

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

S_reverse = S[::-1]
can = 1
i = 0

while i < len(S):
    can2 = 0
    for j in range(4):
        d = divider[j]
        if S_reverse[i:i+len(d)] == d:
            can2 = 1
            i += len(d)
            break
    if can2 == 0:
        can = 0
        break

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

Submission status: Accepted

Solution code:
from sys import stdin

S = stdin.readline().rstrip()[::-1]

result = ''

while True:
    if 'remaerd' == S[:7]:
        S = S[7:]
    elif 'maerd' == S[:5]:
        S = S[5:]
    elif 'esare' == S[:5]:
        S = S[5:]
    elif 'resare' == S[:6]:
        S = S[6:]
    else:
        if len(S) == 0:
            result = 'YES'
        else:
            result = 'NO'
        break;
print(result)

Submission status: Accepted

Solution code:
s = input().rstrip()
d = ['dream', 'dreamer']
e = ['erase', 'eraser']
ch = d + e

st = [s]

def search_(s, st, ch):
    if len(s) == 0:
        return
    if len(s) < len(ch):
        return
    else:
        if s[:len(ch)] == ch:
            st.append(s[len(ch):])

def search(s):
    if len(s) == 0:
        return True
    if s[0] == 'd' or s[0] == 'e':
        for ci in ch:
            if search_(s, ci):
                return True
    return False

while st:
    s = st.pop(0)
    if len(s) == 0:
        print('YES')
        exit()
    if s[0] == 'd' or s[0] == 'e':
        for ci in ch:
            search_(s, st, ci)
print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
ok = True
while len(S) > 0:
    if S[0] == 'd':
        if len(S) >= 7 and S[:7] == 'dreamer':
            if len(S) == 7 or S[7] != 'a':
                S = S[7:]
            else:
                S = S[5:]
        elif S[:5] == 'dream':
            S = S[5:]
        else:
            ok = False
    elif S[0] == 'e':
        if len(S) >= 6 and S[:6] == 'eraser':
            if len(S) == 6 or S[6] != 'a':
                S = S[6:]
            else:
                S = S[5:]
        elif S[:5] == 'erase':
            S = S[5:]
        else:
            ok = False
    else:
        ok = False
    if not ok:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
s = input()
words = ["dreamer", "dream", "eraser", "erase"]
while len(s) > 0:
    judge = [s.endswith(word) for word in words]
    if any(judge):
        s = s[:-len(words[judge.index(True)])]
        if len(s)==0:
            print("YES")
            break
    else:
        print("NO")
        break

Submission status: Accepted

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)
                break
        else:
            ans = 'NO'
            break
    return ans

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

Submission status: Accepted

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

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

count = 0
while True:
    if s[count:count+5] == words[0]:
        count += 5
    elif s[count:count+7] == words[1]:
        count += 7
    elif s[count:count+5] == words[2]:
        count += 5
    elif s[count:count+6] == words[3]:
        count += 6
    else:
        ans = "NO"
        break
    if count == len(s):
        ans = "YES"
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
wl = ['dream','dreamer','erase','eraser']
S = input()
i = 0
for i in range(4):
    S = S.replace(wl[3-i],'')
if len(S) == 0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Solution code:
S = input()[::-1]
T = ["maerd", "remaerd", "esare", "resare"]

while len(S)>0:
    if 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")
        exit()

print("YES")

Submission status: Accepted

Solution code:
# 10th
s = input()
#sの後ろから文字列を取り除いていく方針だが,
#文字列自体を操作するのではなく,indexを減らす方法を取った。
t = len(s)
flag = True
while t > 0:
    if s[t-5:t] == "erase" or s[t-5:t] == "dream":
        t -= 5
    elif s[t-6:t] == "eraser":
        t -= 6
    elif s[t-7:t] == "dreamer":
        t -= 7
    else:
        flag = False
        print("NO")
        break

if flag:
    print("YES")

Submission status: Accepted

Solution code:
import re
S = input()
S = re.sub(r'erase(r)?', '',S)
S = re.sub(r'dream(er)?', '', S)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
String = input()
t = ['dream', 'dreamer', 'erase', 'eraser']

N=len(String)
index =0 
flag = 'True'
count = 0
while flag=='True':
    count = 0
    for i in t:
        count+=1
        if String.rfind(i)==N-len(i) and String.rfind(i)!=-1:
            String=String[0:N-len(i)]
            N=N-len(i)

            if N==0:
                flag = 'Complete'
            break


        if count==4:
            flag = 'Never'

if flag=='Complete':
    print('YES')
if flag=='Never':
    print('NO')

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

while len(s) >= 5:
    if s[-5:] == 'dream':
        s = s[:-5]
        continue
    elif s[-7:] == 'dreamer':
        s = s[:-7]
        continue
    elif s[-5:] == 'erase':
        s = s[:-5]
        continue
    elif s[-6:] == 'eraser':
        s = s[:-6]
        continue
    else:
        break
if len(s):
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
s = input()

while len(s) >= 5:

    if s[-5:] == 'dream':
        s = s[:-5]
        continue

    elif s[-7:] == 'dreamer':
        s = s[:-7]
        continue

    elif s[-5:] == 'erase':
        s = s[:-5]
        continue

    elif s[-6:] == 'eraser':
        s = s[:-6]
        continue

    else:
        break

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

Submission status: Accepted

Solution code:
S = input()
ans = 0
while len(S)>0:
  if S[:9] == 'dreamerer':#dreamer
    S = S[7:]
  elif S[:8] == 'dreamerd':#dreamer
    S = S[7:]
  elif S[:8] == 'dreamera':#dream
    S = S[5:]
  elif S[:6] == 'dreamd':#dream
    S = S[5:]
  elif S[:7] == 'eraserd':#eraser
    S = S[6:]
  elif S[:7] == 'erasere':#eraser
    S = S[6:]
  elif S[:6] == 'erasee':#erase
    S = S[5:]
  elif S[:6] == 'erased':#erase
    S = S[5:]
  elif S[:] == 'dreamer':
    S = S[7:]
  elif S[:] == 'dream':
    S = S[5:]
  elif S[:] == 'eraser':
    S = S[6:]
  elif S[:] == 'erase':
    S = S[5:]
  else:
    ans += 1
    break
if ans == 0:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
S = input()

while True:
    if S.endswith("dream") or S.endswith("erase"):
        S = S[:-5]
    elif S.endswith("dreamer"):
        S = S[:-7]
    elif S.endswith("eraser"):
        S = S[:-6]
    else:
        break
        
if S == "":
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input()

candidate_string_list = ['dream', 'dreamer', 'erase', 'eraser']
candidate_string_list_reverse = [elem[::-1] for elem in candidate_string_list]

buffer = ''
for character in S[::-1]:
    buffer += character
    if buffer in candidate_string_list_reverse:
        buffer = ''
        continue

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

Submission status: Accepted

Solution code:
s = 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: Accepted

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


S = input()
T_s = ["dream", "dreamer", "erase", "eraser"]

while len(S):
    for T in T_s:
        if T == S[-len(T):]:
            S = S[:-len(T)]
            break
    else:
        print("NO")
        break
else:
    print("YES")

Submission status: Accepted

Solution code:
a = input()
a = a[::-1]
b = ['maerd','remaerd','esare','resare']
flag = 0
while flag >= 0:
    flag = 0
    if a[:5] == b[0]:
        a = a[5:]
    elif a[:5]==b[2]:
        a = a[5:]
    elif a[:7] == b[1]:
        a = a[7:]
    elif a[:6] == b[3]:
        a = a[6:]
    elif a == '':
        print('YES')
        break
    else:
        flag = -1
        print('NO')

Submission status: Accepted

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:6] in T:
        S = S[6:]
        continue
    elif S[0:7] in T:
        S = S[7:]
        continue
    else:
        Ans = "NO"
        break
print(Ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
R = S[::-1]
dic = ['maerd','remaerd','esare','resare']
i = 0
while i < N:
    for w in dic:
        if R[i:].startswith(w):
            i += len(w)
            break
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]
n = len(s)
#dream dreamer erase eraser
i = 0
ans = True
while True:
    if i >= n:
        break
    if s[i:i+7] == "remaerd":
        i += 7
    elif s[i:i+6] == "resare":
        i += 6
  
    elif s[i:i+5] == "maerd" or s[i:i+5] == "esare":
        i += 5
    else:
        ans = False
        break

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

Submission status: Accepted

Solution code:
divide = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
    divide[i] = divide[i][::-1]
s = input()[::-1]
can = True
i = 0
while i < len(s):
    can2 = False
    for j in range(4):
        d = divide[j]
        if s[i:i+len(d)] == d:
            can2 = True
            i += len(d)
    if not can2:
        can = False
        break

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

Submission status: Accepted

Solution code:
N = input()

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

Submission status: Accepted

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

Solution code:
import sys
S = input()
S = S[::-1]
substring_list = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
while i < len(S):
    ok = False
    for substring in substring_list:
        if S[i:i+len(substring)] == substring:
            i += len(substring)
            ok = True
            break
    if not ok:
        print('NO')
        sys.exit()
print('YES')

Submission status: Accepted

Solution code:
s = input()
judge = True
while 0<len(s): 
    if s[:5]=='dream':
        s = s[5:]
        if s[:2]=='er' and not s[:5]=='erase':
            s = s[2:]
    elif s[:5]=='erase':
        s = s[5:]
        if s[:1]=='r':
            s = s[1:]
    else:
        judge = False
        break
print('YES' if judge else 'NO')