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()[::-1]
templates = [s[::-1] for s in ["dream", "dreamer", "erase", "eraser"]]
while s:
    for template in templates:
        if s.startswith(template):
            s = s.replace(template, "", 1)
            break
    else:
        break
print("YES" if not s else "NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s0=input()
s1="maerd"
s2="remaerd"
s3="esare"
s4="resare"
s=""
for i in range(len(s0)):
    s+=s0[-1-i]
num=0
num2=len(s)
ans=0
for i in range(num2):
    if num==num2:
        ans=1
        break
    if num2-num<=4:
        break
    if num2-num<=7:
        s13=s[num:]
        if s13==s1 or s13==s2 or s13==s3 or s13==s4:
            ans=1
        break
    if s[num:num+5]==s1 or s[num:num+5]==s3:
        num+=5
    elif s[num:num+6]==s4:
        num+=6
    elif s[num:num+7]==s2:
        num+=7
    else:
        break
if ans==0:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = input()

i = len(S)
ok = True

while ok and i > 0:
    if i - 7 >= 0 and S[i - 7:i] == "dreamer":
        i = i - 7
    elif i - 5 >= 0 and S[i - 5:i] == "dream":
        i = i - 5
    elif i - 6 >= 0 and S[i - 6:i] == "eraser":
        i = i - 6
    elif i - 5 >= 0 and S[i - 5:i] == "erase":
        i = i - 5
    else:
        ok = False

print("YES" if i == 0 else "NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
A = "".join(list(reversed(S)))
i = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
s = s.replace("eraser", "")

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def h(temp):
    if temp[0] == "m":
        a = 0
    elif temp[0] == "r":
        if temp[2] == "m":
            a = 1
        else:
            a = 3
    else:
        a = 2
    return a 

def H(temp,y,a):
    c = 0
    if a == 0 or a == 2:
        for j in range(5):
            if y[a][4-j] != temp[0]:
                return c
            temp.remove(temp[0])
        c = 1
    elif a == 3:
        for j in range(6):
            if y[a][5-j] != temp[0]:
                return c
            temp.remove(temp[0])
        c = 1
    else:
        for j in range(7):
            if y[a][6-j] != temp[0]:
                return c
            temp.remove(temp[0])
        c = 1
    return c


s = input()
y = ['dream','dreamer','erase','eraser'] 
temp = []
t = []
k = len(s)
for i in range(k):
    temp.append(s[k-i-1])
c = 1
while len(temp) != 0 and c == 1:
    a = h(temp)
    c = H(temp,y,a)
if c == 1:
    print("YES")
else :
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import math
s = input()

while len(s) > 0:
    if s.endswith("dream"):
        s = s[:len(s) - 5]
    elif s.endswith("dreamer"):
        s = s[:len(s) - 7]
    elif s.endswith("erase"):
        s = s[:len(s) - 5]
    elif s.endswith("eraser"):
        s = s[:len(s) - 6]
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC_049_C_Daydream.py
S = input()
Srev = S[::-1]
# List=["dream","dreamer","erase","eraser"]
Listrev = ["maerd", "remaerd", "esare", "resare"]
can = True
while can == True:
	if Srev == "":
		break
	can = False
	for i in range(4):
		rev=Listrev[i]
		length = len(rev)
		if Srev[0:length] == rev:
			can = True
			Srev=Srev[length:]
if can == True:
	print("YES")
else:
	print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
s=len(S)
T=""
i=0
while True:
    if S[i:i+5]=="dream":
        if i+5==s or S[i+5:i+7]!="er":
            T+="dream"
            i+=5
        elif S[i+5:i+7]=="er":
            if i+7==s or S[i+7]!="a":
                T+="dreamer"
                i+=7
            else:
                T+="dream"
                i+=5
    elif S[i:i+6]=="eraser":
        T+="eraser"
        i+=6
    elif S[i:i+5]=="erase":
        T+="erase"
        i+=5
    else:
        print("NO")
        exit()
    #print(T)
    if len(T)>=len(S):
        break
print("YES")

Submission status: Accepted

Solution code:
S = input()

while 1:

    flag = 0
    if S[-5:] == "erase":
        S = S[:-5]
        flag = 1
    if S[-6:] == "eraser":
        S = S[:-6]
        flag = 1
    if S[-5:] == "dream":
        S = S[:-5]
        flag = 1
    if S[-7:] == "dreamer":
        S = S[:-7]
        flag = 1

    if flag == 0:
        break

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

Submission status: Accepted

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

words = ["eraser","erase","dreamer","dream"]
for i in words:
  s = s.replace(i[::-1], "")
if s == "": print("YES")
else: print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input().strip()
N = len(S)
cur = 0
flag = 0
while cur<N:
    if S[cur:cur+5]=="dream":
        if cur+5==N:
            cur += 5
        elif cur+5<N and S[cur+5]=="d":
            cur += 5
        elif S[cur:cur+7]=="dreamer":
            if cur+7==N:
                cur += 7
            elif S[cur+7] in ["d","e"]:
                cur += 7
            elif S[cur+7]=="a":
                cur += 5
            else:
                flag = 1
                break
        else:
            flag=1
            break
    elif S[cur:cur+5]=="erase":
        if cur+5==N:
            cur += 5
        elif cur+5<N and S[cur+5]=="r":
            cur += 6
        elif cur+5<N and S[cur+5] in ["d","e"]:
            cur += 5
        else:
            flag = 1
            break
    else:
        flag=1
        break
if flag==0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = input()
s = s.replace("dream", "D")
s = s.replace("erase", "E")
s = s.replace("Der", "D")
s = s.replace("Er", "E")

s = list(set(s))
ok = True
for i in range(len(s)):
    if s[i] not in ["D","E"]:
        ok = False
print("YES" if ok else "NO")

Submission status: Accepted

Solution code:
s = input()
n = len(s)

ans = ""
i = 0
for _ in range(n):
    if i > n or ans == s: break
    if s[i:i+5] == "erase":
        i += 5
        ans += "erase"
        if s[i:i+1] == "r":
            i += 1
            ans += "r"
    elif s[i:i+5] == "dream":
        i += 5
        ans += "dream"
        if s[i:i+3] == "era": continue
        elif s[i:i+2] == "er":
            i += 2
            ans += "er"
print("YES" if ans == s else "NO")

Submission status: Accepted

Solution code:
S = str(input())
A = "dream"
B = "dreamer"
C = "erase"
D = "eraser"
while len(S) >= 5:
  if len(S) >= 7 and S[-7:] == B:
    S = S[:-7]
  elif len(S) >=6 and S[-6:] == D:
    S = S[:-6]
  elif S[-5:] == A or S[-5:] == C:
      S = S[:-5]
  else:
    break
if len(S) == 0:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
S = str(input())

counter = 0

T = len(S)
K = T//5+1

for i in range (0, K+1):
	T = len(S)
	if S[-5::] == 'dream':
		S = S[0:T-5]
	elif S[-5::] == 'erase':
		S = S[0:T-5]
	elif S[-7::] == 'dreamer':
		S = S[0:T-7]
	elif S[-6::] == 'eraser':
		S = S[0:T-6]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
s = S[::-1]
a = "dream"[::-1]
b = "dreamer"[::-1]
c = "erase"[::-1]
d = "eraser"[::-1]

idx = 0
ans = "YES"
while idx < len(s):
    if s[idx] == "m":
        if s[idx : idx + 5] == a:
            idx = idx + 5
        else:
            ans = "NO"
            break

    elif s[idx] == "e":
        if s[idx : idx + 5] == c:
            idx = idx + 5
        else:
            ans = "NO"
            break

    elif s[idx] == "r":
        if s[idx : idx + 7] == b:
            idx = idx + 7
        elif s[idx : idx + 6] == d:
            idx = idx + 6
        else:
            ans = "NO"
            break

    else:
        ans = "NO"
        break

print(ans)

Submission status: Accepted

Solution code:
import re
s = input()

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

Submission status: Accepted

Solution code:
import re
print ('YES' if re.search(r'\A(?:dream(?:er)?|eraser?)+\Z', input()) else 'NO')

Submission status: Accepted

Solution code:
def main():
    s=input()
    dp=[0]*len(s)
    dp[0]=1
    for i,v in enumerate(s):
        if dp[i] == 0 or i+5 > len(s):
            continue
        s5 = s[i:i+5]
        if s5 == "dream" or s5 == "erase":
            if len(s) == i+5:
                break
            dp[i+5]=1
        if i+6 <= len(s) and s[i:i+6] == "eraser":
            if len(s) == i+6:
                break
            dp[i+6]=1
        if i+5 <= len(s) and s[i:i+7] == "dreamer":
            if len(s) == i+7:
                break
            dp[i+7]=1
    else:
        print("NO")
        return
    print("YES")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import re

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

main()

Submission status: Accepted

Solution code:
from sys import exit

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

pos = len(s) - 1
while pos >= 0:
    flag = False

    for string in l:
        length = len(string)
        if pos >= length - 1 and s[pos-length+1:pos+1] == string:
            pos -= length
            flag = True

    if not flag:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()


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

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

Submission status: Accepted

Solution code:
S = input()
S_inv = S[::-1]
i=0
flg = True
while i<len(S):
    if S_inv[i:i+5]=='dream'[::-1]:
        i = i + 5
    elif S_inv[i:i+7]=='dreamer'[::-1]:
        i = i + 7
    elif S_inv[i:i+5]=='erase'[::-1]:
        i = i + 5
    elif S_inv[i:i + 6] == 'eraser'[::-1]:
        i = i + 6
    else:
        flg = False
        break

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

Submission status: Accepted

Solution code:
def main():
    import sys

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

    s = input()
    word = ['eraser', 'erase', 'dreamer', 'dream']
    for x in word:
        s = s.replace(x, '')
    if s == '':
        print('YES')
    else:
        print('NO')
        
        
        
            
        
    
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
l=len(s)
def len_s(l,n):
    return l-n+1

def get_tail(s,n,number):
    if n==0:
        return s[-number:]
    else:
        return s[-number-n:-n]


    
def check(s,n):
    tail=get_tail(s,n,3)
    if tail=="eam" and len_s(l,n)>=5:
        if get_tail(s,n,5)=="dream":
            return True,n+5
        else:
            return False,None
    elif tail=="mer" and len_s(l,n)>=7:
        if get_tail(s,n,7)=="dreamer":
            return True,n+7
        else:
            return False,None
    elif tail=="ase" and len_s(l,n)>=5:
        if get_tail(s,n,5)=="erase":
            return True,n+5
        else:
            return False,None
    elif tail=="ser" and len_s(l,n)>=6:
        if get_tail(s,n,6)=="eraser":
            return True,n+6
        else:
            return False,None
    else:
        return False,None
ans=0
tail=0
while True:
    bool,tail=check(s,tail)
    if bool:
        if tail==l:
            break
    else:
        ans+=1
        break   
if ans==0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

while 1:
    flag=0
    for p in pat_list:
        if s.endswith(p):
            flag=1
            s = s[:-len(p)]
    if not s:
        print("YES")
        break
    if not flag:
        print("NO")
        break

Submission status: Accepted

Solution code:
s = input()

while len(s) > 7:
  if s[-5:] in ["dream", "erase"]:
    s = s[:-5]
  elif s[-6:] in ["eraser"]:
    s = s[:-6]
  elif s[-7:] in ["dreamer"]:
    s = s[:-7]
  else:
    break

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

Submission status: Accepted

Solution code:
S = list(input())
S.reverse()

D = [['m','a','e','r','d'],['r','e','m','a','e','r','d'],['e','s','a','r','e'],['r','e','s','a','r','e']]
can = True

while len(S) != 0:
    can2 = False
    for i in range(4):
        d = D[i]
        if S[:len(d)] == d:
            can2 = True
            for j in range(len(d)):
                S.pop(0)
            break
    if can2 == False:
        can = False
        break

if can == True:
    print('YES')
elif can == False:
    print('NO')

Submission status: Accepted

Solution code:
s = ''.join(list(reversed(input())))
t = ''

while True:
    n = len(t)
    if len(s) <= n:
        if s == t:
            print('YES')
        else:
            print('NO')
        break
    if s[n] == 'm':
        t += ''.join(list(reversed('dream')))
    elif s[n] == 'e':
        t += ''.join(list(reversed('erase')))
    elif s[n:n+3] == 'rem':
        t += ''.join(list(reversed('dreamer')))
    elif s[n:n+3] == 'res':
        t += ''.join(list(reversed('eraser')))
    else:
        print('NO')
        break

Submission status: Accepted

Solution code:
s = input()
s_reverse = ''.join(list(reversed(s)))
t = ''

while True:
    n = len(t)
    if len(s) <= n:
        if s_reverse == t:
            print('YES')
        else:
            print('NO')
        break
    if s_reverse[n] == 'm':
        t += ''.join(list(reversed('dream')))
    elif s_reverse[n] == 'e':
        t += ''.join(list(reversed('erase')))
    elif s_reverse[n:n+3] == 'rem':
        t += ''.join(list(reversed('dreamer')))
    elif s_reverse[n:n+3] == 'res':
        t += ''.join(list(reversed('eraser')))
    else:
        print('NO')
        break

Submission status: Accepted

Solution code:
s = input()
s_reverse = ''.join(list(reversed(s)))
t = ''

while True:
    n = len(t)
    if s_reverse == t:
        print('YES')
        break
    if len(s) <= n:
        print('NO')
        break
    if s_reverse[n] == 'm':
        t += ''.join(list(reversed('dream')))
    elif s_reverse[n] == 'e':
        t += ''.join(list(reversed('erase')))
    elif s_reverse[n:n+3] == 'rem':
        t += ''.join(list(reversed('dreamer')))
    elif s_reverse[n:n+3] == 'res':
        t += ''.join(list(reversed('eraser')))
    else:
        print('NO')
        break

Submission status: Accepted

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

lt = [w[::-1] for w in lt]
s = s[::-1]
cond = True
i = 0
while i < len(s):
    for t in lt:
        if s[i:].startswith(t):
            i += len(t)
            break
    else:
        cond = False
        break

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

Submission status: Accepted

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

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

while index<N:
    word1=S[index:index+5]
    word2=S[index:index+6]
    word3=S[index:index+7]
    if word1 in words:
        index+=5
    elif word2 in words:
        index+=6
    elif word3 in words:
        index+=7
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
S = input()
li = ['dream','dreamer','erase','eraser']
li_len=[5,7,5,6]

while S:
    for i,moji in enumerate(li):
        if S[-li_len[i]:] == moji:
            S = S[:-li_len[i]]
            break
    else:
        print('NO')
        break
if not S:print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
while 1:
    n = len(s)
    if n==0:
        print("YES")
        exit()
    elif 1<=n<=4:
        print("NO")
        exit()
    else:
        if s[n-5:n]=="dream" or s[n-5:n]=="erase":
            s=s[:n-5]
        elif s[n-6:n]=="eraser":
            s=s[:n-6]
        elif s[n-7:n]=="dreamer":
            s=s[:n-7]
        else:
            print("NO")
            exit()

Submission status: Accepted

Solution code:
import re
print('NYOE S'[bool(re.match('^(dream|dreamer|erase|eraser)+$',input()))::2])

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]
j = 0
p = len(s)
while True:
    if s[j:j+5] == 'maerd':
        j += 5
    elif s[j:j+7] == 'remaerd':
        j += 7
    elif s[j:j+5] == 'esare':
        j += 5
    elif s[j:j+6] == 'resare':
        j += 6
    else:
        print('NO')
        break
    if j == p:
        print('YES')
        break

Submission status: Accepted

Solution code:
words = {"resare" , "esare" , "remaerd" , "maerd",""}
s = input()
n = len(s)
now=""
f=0
s=s[::-1]
for i in range(0 ,n):
	now = now+s[i]
	if now in words:
		now = ""
if now in words:
	print("YES")
else:
	print("NO")

Submission status: Accepted

Solution code:
s = input()

while len(s) > 0:
    if s[-5:] == "dream":
        s = s[:-5]
    elif s[-7:] == "dreamer":
        s = s[:-7]
    elif s[-5:] == "erase":
        s = s[:-5]
    elif s[-6:] == "eraser":
        s = s[:-6]
    else:
        print("NO")
        exit()

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

Submission status: Accepted

Solution code:
from sys import stdin
import sys

s = stdin.readline().rstrip()

A = 'dream'
B = 'dreamer'
C = 'erase'
D = 'eraser'

s = s[::-1]
A = A[::-1]
B = B[::-1]
C = C[::-1]
D = D[::-1]

while True:
    if len(s) >= 5 and s[:5] == A:
        s = s[5:]
    elif len(s) >= 7 and s[:7] == B:
        s = s[7:]
    elif len(s) >= 5 and s[:5] == C:
        s = s[5:]
    elif len(s) >= 6 and s[:6] == D:
        s = s[6:]
    else:
        print("NO")
        sys.exit()

    if s == '':
        print ("YES")
        sys.exit()

Submission status: Accepted

Solution code:
S = input()

words = ["dream", "dreamer", "erase", "eraser"]
S_rv = S[::-1]
words_rv = [word[::-1] for word in words]

for i in range(len(S_rv)):
    for word_rv in words_rv:
        if S_rv[: len(word_rv)] == word_rv:
            S_rv = S_rv[len(word_rv) :]

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

Submission status: Accepted

Solution code:
WORDS = ['dream', 'dreamer', 'erase', 'eraser']
REVERSED_WORDS = [word[::-1] for word in WORDS]


def main(s):
    i = 0
    while i < len(s):
        for word in REVERSED_WORDS:
            if s[i:].startswith(word):
                i += len(word)
                break
        else:
            print('NO')
            break
    else:
        print('YES')


if __name__ == "__main__":
    main(input()[::-1])

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

    S = S[::-1]
    word = ['dream', 'dreamer', 'erase', 'eraser']
    word = [w[::-1] for w in word]

    ok = True
    i = 0
    while i < len(S):
        j = i
        for w in word:
            if all(w[j] == S[i + j] for j in range(len(w))):
                j += len(w)
                break
        if i == j:
            ok = False
            break
        i = j

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

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

s = ['dream','dreamer','erase','eraser'] 
s = [_[::-1] for _ in s]

idx = 0
ans='YES'
while idx < len(S):
    if S[idx] == 'm':
        if S[idx:idx+5] == s[0]:
            idx=idx+5
        else:
            ans='NO'
            break
        
    elif S[idx] == 'e':
        if S[idx:idx+5] == s[2]:
            idx=idx+5
        else:
            ans='NO'
            break
        
    elif S[idx] == 'r':
        if S[idx:idx+7] == s[1]:
            idx=idx+7
        elif S[idx:idx+6] == s[3]:
            idx=idx+6
        else:
            ans='NO'
            break
        
    else:
        ans='NO'
        break
        
print(ans)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
dp=[False]*(n+1)
c=["dream","dreamer","erase","eraser"]
if s[:5] in c:
    dp[5]=True
if s[:6] in c:
    dp[6]=True
if s[:7] in c:
    dp[7]=True
for i in range(n+1):
    if dp[i]:
        l=""
        if i+5<=n:
            for idx in range(5):
                l+=s[i+idx]
            if l in c:
                dp[i+5]=True
        if i+6<=n:
            l+=s[i+5]
            if l in c:
                dp[i+6]=True
        if i+7<=n:
            l+=s[i+6]
            if l in c:
                dp[i+7]=True
#print(dp)
if dp[n]:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input()
C = ["maerd","remaerd","esare","resare"]
ans = ""
a = "YES"
x = len(S)
for i in range(x):
    ans = ans + S[x - 1 -i]
    if ans == C[0]:
        ans = ""
    elif ans == C[1]:
        ans = ""
    elif ans == C[2]:
        ans = ""
    elif ans == C[3]:
        ans = ""
if len(ans) != 0:
    a = "NO"
print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
I = input()

import re
if re.match("^(dream|dreamer|erase|eraser)+$", I):
    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 len(s) == 0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = input()
    words = ["dream","erase"]
    wordsr = ["dreamer", "eraser"]
    while s:
        if s[-7:] == "dreamer":
            s = s[:-7]
        elif s[-6:] == "eraser":
            s = s[:-6]
        elif s[-5:] in words:
            s = s[:-5]
        else:
            print('NO')
            sys.exit()
    print('YES')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
st = input()
S = st[::-1]
words ={"remaerd","resare","maerd","esare"}

lenT = 0
flag = 0
ans = "NO"

while flag < 5:
  for i in range(5, 8):
    if S[0:i] in words:
      S = S[i:]
      flag = 0
      
    elif S == "":
      flag = 5
      ans = "YES"
      break
    else:
      flag += 1
    
print(ans)

Submission status: Accepted

Solution code:
s = input()

s = s[::-1]
lis = ['dreamer', 'dream', 'eraser', 'erase']
nlis = []
for i in lis:
    nlis.append(i[::-1])


for i in range(10**5 + 1):
    for j in nlis:
        if s.startswith(j):
            s = s[len(j):]


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

Submission status: Accepted

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

f = True
while f:
    os = s
    for i in a:
        if s.endswith(i):
            s = s[:-len(i)]
            if len(s) == 0:
                print("YES")
                f = False
    if len(os) == len(s):
        print("NO")
        f = False

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

tmp = ""
cnt = 0
for c in reversed(s):
  tmp = c + tmp
  if tmp in ["dream", "dreamer", "erase", "eraser"]:
    cnt += len(tmp)
    tmp = ""
    
if cnt == len(s):
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
S=input()
N=len(S)

idx=N-1
ans="YES"
while idx>=0:
    now=S[idx]
    if now=="m":
        if S[idx-4:idx+1]!="dream":
            ans="NO"
            break
        else:idx-=5
    elif now=="e":
        if S[idx-4:idx+1]!="erase":
            ans="NO"
            break
        else:idx-=5
    elif now=="r":
        if S[idx-5:idx+1]=="eraser":
            idx-=6
        elif S[idx-6:idx+1]=="dreamer":
            idx-=7
        else:
            ans="NO"
            break
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import re
print('YES' if re.match('^(dream|dreamer|erase|eraser)+$', input()) else 'NO')

Submission status: Accepted

Solution code:
input_str = input()

while(True):
  if input_str[0:11] == "dreameraser":
    input_str = input_str[11:]
  elif input_str[0:10] == "dreamerase":
    input_str = input_str[10:]
  elif input_str[0:7] == "dreamer":
    input_str = input_str[7:]
  elif input_str[0:6] == "eraser":
    input_str = input_str[6:]
  elif input_str[0:5] == "dream" or input_str[0:5] == "erase":
    input_str = input_str[5:]
  else:
    print("NO")
    break
  
  if len(input_str) == 0:
    print("YES")
    break

Submission status: Accepted

Solution code:
# S = "erasedream"
#
# ARR = ['dream', 'dreamer', 'erase', 'eraser']

# S = "erasedream"
# S = "dreameraser"
# S = "dreamerer"

S = input()
def calculate(s):

    index = 0
    isOK = True
    while index < len(s):

        #p1 = 'dreameraser'
        p1 = s[index:index + 11]
        if p1 == 'dreameraser':
            index += 11
            continue
        #p2 = 'dreamerase'

        p2 = s[index:index + 10]
        if p2 == 'dreamerase':
            index += 10
            continue

        s1 = s[index:index+7]

        if s1 == 'dreamer':
            index += 7
            continue

        s2 = s[index:index+6]

        if s2 == 'eraser':
            index += 6
            continue

        s3 = s[index:index+5]

        if s3 == 'erase':
            index += 5
            continue

        if s3 == 'dream':
            index += 5
            continue

        isOK = False
        break

    if isOK:
        print("YES")
    else:
        print("NO")
calculate(S)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = str(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:
s = input()[::-1]
a = "maerd"
b = "remaerd"
c = "esare"
d = "resare"
while len(s)!=0:
  if s[:5]==a:
    s = s[5:]
  elif s[:7]==b:
    s = s[7:]
  elif s[:5]==c:
    s = s[5:]
  elif s[:6]==d:
    s = s[6:]
  else:
    print("NO")
    exit()
print("YES")

Submission status: Accepted

Solution code:
s=input()
a=["dreamer", "dream", "eraser", "erase"]
while s:
  for i in a:
    k=len(i)
    if s[-k:]==i:
      s=s[:-k]
      break
  else:
  	break

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