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

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

t = len(s)
hiki = 1
while t > 0 and hiki == 1:
    hiki = 0
    for i in range(len(V)):
        # print(len(V[i]), s[:t], s[t-len(V[i]):t], V[i])
        if t >= len(V[i]) and s[t-len(V[i]):t] == V[i]:
            t -= len(V[i])
            hiki = 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

a = ['dream','dreamer','erase','eraser']
for i,ch in enumerate(a):
  a[i] = ch[::-1]

S = S[::-1]

flag = True
while flag:
  if len(S)==0:
    ans  = 'YES'
    flag = False
  elif S[:5] in a:
    S = S[5:]
  elif S[:6] in a:
    S = S[6:]
  elif S[:7] in a:
    S = S[7:]
  else:
    ans  = 'NO'
    flag = False
  
print(ans)

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

print('YES')

Submission status: Accepted

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

def main():
    t1 = "dream"[::-1]
    t2 = "dreamer"[::-1]
    t3 = "erase"[::-1]
    t4 = "eraser"[::-1]

    s = input().strip()[::-1]

    while True:
        ok = False
        if len(s) >= 7:
            if s[:7] == t2:
                s = s[7:]
                ok = True
        if len(s) >= 6:
            if s[:6] == t4:
                s = s[6:]
                ok = True
        if len(s) >= 5:
            if s[:5] == t1 or s[:5] == t3:
                s = s[5:]
                ok = True
        
        if len(s) < 5 or not ok:
            break
    
    if s != "":
        print("NO")
    else:
        print("YES")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s=input()

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

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()
flg=0
while len(s)>0:
  f1=s[-5:]
  f2=s[-6:]
  f3=s[-7:]
  if f3 == 'dreamer':
    s=s[:-7]
  elif f2 =='eraser':
    s=s[:-6]
  elif f1 =='dream' or f1 =='erase':
    s=s[:-5]
  else:
    print('NO')
    flg=1
    break
if flg==0:
  print('YES')

Submission status: Accepted

Solution code:
import time

S = input()[::-1]
keywords = ["dream", "dreamer", "erase", "eraser"]
keywords = [x[::-1] for x in keywords]
# start_time = time.time()
start = 0
while True:
    flag = False
    end = None
    for key in keywords:
        key_len = len(key)
        end = start + key_len
        if S[start:end] == key:
            flag = True
            break

    start = end

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

    if flag and start == len(S):
        print("YES")
        exit()

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()
L = len(S)

while L:
  f = True
  if L >= 7:
    if S[L-7:L] == "dreamer":
      L -= 7
      f = False
  if L >= 6:
    if S[L-6:L] == "eraser":
      L -= 6
      f = False
  if L >= 5:
    if S[L-5:L] == "dream" or S[L-5:L] == "erase":
      L -= 5
      f = False
  if f:
    break

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

Submission status: Accepted

Solution code:
S = input()

S1 = S.replace("eraser", "")
S2 = S1.replace("erase", "")
S3 = S2.replace("dreamer", "")
S4 = S3.replace("dream", "")

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

Submission status: Accepted

Solution code:
s = input()

s = s[::-1]

tmp = 0
for i in range(len(s)):
    #print(tmp)
    if tmp == len(s):
        print('YES')
        exit()
    if s[tmp:tmp+6] == 'resare':
        tmp += 6
        continue
    if s[tmp:tmp+5] == 'esare':
        tmp += 5
        continue
    if s[tmp:tmp+5] == 'maerd':
        tmp += 5
        continue
    if s[tmp:tmp+7] == 'remaerd':
        tmp += 7
        continue
    else:
        print('NO')
        exit()

Submission status: Accepted

Solution code:
s = input()

d = s.count("dream")
dr = s.count("dreamer")
e = s.count("erase")
er = s.count("eraser")
de = s.count("dreamerase")

l = (d + e) * 5 + (dr - de) * 2 + er

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

Submission status: Accepted

Solution code:
s = input()

d = s.count("dream")
dr = s.count("dreamer")
e = s.count("erase")
er = s.count("eraser")
de = s.count("dreamerase")
der = s.count("dreameraser")

l = (d + e) * 5 + (dr - de) * 2 + er
print("YES" if l == len(s) else "NO")

Submission status: Accepted

Solution code:
S=input()
i=len(S)-1
flag=0
T1='dream'
T2='dreamer'
T3='erase'
T4='eraser'

while i>=0:
    if S[i]=='m':
        k=0
        for j in reversed(range(i-4,i+1)):
            #print(S[j],T1[4-k])
            if S[j]!=T1[4-k]:
                flag=1
            k+=1
        i-=5
    elif S[i]=='e':
        kk=0
        for j in reversed(range(i-4,i+1)):
            #print(S[j], T3[4 - kk])
            if S[j]!=T3[4-kk]:
                flag=1
            kk+=1
        i-=5
    elif S[i]=='r' and S[i-1]=='e':
        if S[i-2]=='m':
            kkk=0
            for j in reversed(range(i-6,i+1)):
                #print(S[j], T2[6 - kkk])
                if S[j] != T2[6-kkk]:
                    flag = 1
                kkk+=1
            i-=7
        elif S[i-2]=='s':
            kkkk=0
            for j in reversed(range(i-5,i+1)):
                #print(S[j], T4[5 - kkkk])
                if S[j] != T4[5-kkkk]:
                    flag = 1
                kkkk+=1
            i-=6
        else:
            i-=1
    else:
        i-=1
if flag==0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import re;print("YNEOS"[(re.fullmatch(r"(erase|dream|eraser|dreamer)*",input())==None)::2])

Submission status: Accepted

Solution code:
def chk(S):
    n = len(S)
    i = n
    while i > 0:
        if S[i-5:i] == 'dream' or S[i-5:i] == 'erase':
            i -= 5
        elif S[i-6:i] == 'eraser':
            i -= 6
        elif S[i-7:i] == 'dreamer':
            i -= 7
        else:
            return False
    return True

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

Submission status: Accepted

Solution code:
words = ["dream", "dreamer", "erase", "eraser"]
reverse_words = []
for i in words:
  word = list(reversed(i))
  word = "".join(word)
  reverse_words.append(word)
# print(reverse_words)  

S = input()
# print(S)
while S != "":
  T = S
  length = len(S)
  for j in reverse_words:
    p = (S[:-(len(j)+1):-1])
    if p == j:
      S = (S[:len(T)-len(p)])
  # print(S)
  if S == T:
    print("NO")
    exit()
print("YES")

Submission status: Accepted

Solution code:
S=input()

T=''
S=S[::-1]
l,r=0,7
while l<len(S):
  if S[l:r]=='remaerd':
    l=r
    r+=7
  elif S[l:r-1]=='resare':
    l=r-1
    r+=6
  elif S[l:r-2]=='maerd':
    l=r-2
    r+=5
  elif S[l:r-2]=='esare':
    l=r-2
    r+=5
  else:
    print('NO')
    exit()
print('YES')

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

s = ns()[::-1]
ans = "YES"

while len(s) > 1:
    if s[:5] == "maerd":
        s = s[5:]
    elif s[:7] == "remaerd":
        s = s[7:]
    elif s[:5] == "esare":
        s = s[5:]
    elif s[:6] == "resare":
        s = s[6:]
    else:
        ans = "NO"
        s = ""

print(ans)

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()
p = s.replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')
if len(p) != 0:
  print("NO")
else:
  print("YES")

Submission status: Accepted

Solution code:
# sys.stdin.readline
import re
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()
        print('YES' if re.match('^(dream(er)?|eraser?)*$', S) else 'NO')


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Accepted

Solution code:
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()
        dp = [False] * (len(S) + 1)

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

        dp[0] = True
        for i in range(len(S)):
            if not dp[i]:
                continue
            for word in words:
                if S[i:i + len(word)] == word:
                    dp[i + len(word)] = True

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


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Accepted

Solution code:
S = list(input())

false_flag = 0
N = len(S)
while N:
    if N >= 7:
        if S[-1] == 'r' and S[-2] == 'e' and S[-3] == 'm' and S[-4] == 'a' and S[-5] == 'e' and S[-6] == 'r' and S[-7] == 'd':
            for i in range(7):
                S.pop()
        elif S[-1] == 'r' and S[-2] == 'e' and S[-3] == 's' and S[-4] == 'a' and S[-5] == 'r' and S[-6] == 'e':
            for i in range(6):
                S.pop()
        elif S[-1] == 'm' and S[-2] == 'a' and S[-3] == 'e' and S[-4] == 'r' and S[-5] == 'd':
            for i in range(5):
                S.pop()
        elif S[-1] == 'e' and S[-2] == 's' and S[-3] == 'a' and S[-4] == 'r' and S[-5] == 'e':
            for i in range(5):
                S.pop()
        else:
            false_flag = 1
            break
    elif N >= 6:
        if S[-1] == 'r' and S[-2] == 'e' and S[-3] == 's' and S[-4] == 'a' and S[-5] == 'r' and S[-6] == 'e':
            for i in range(6):
                S.pop()
        elif S[-1] == 'm' and S[-2] == 'a' and S[-3] == 'e' and S[-4] == 'r' and S[-5] == 'd':
            for i in range(5):
                S.pop()
        elif S[-1] == 'e' and S[-2] == 's' and S[-3] == 'a' and S[-4] == 'r' and S[-5] == 'e':
            for i in range(5):
                S.pop()
        else:
            false_flag = 1
            break
    elif N >= 5:
        if S[-1] == 'm' and S[-2] == 'a' and S[-3] == 'e' and S[-4] == 'r' and S[-5] == 'd':
            for i in range(5):
                S.pop()
        elif S[-1] == 'e' and S[-2] == 's' and S[-3] == 'a' and S[-4] == 'r' and S[-5] == 'e':
            for i in range(5):
                S.pop()
        else:
            false_flag = 1
            break
    else:
        false_flag = 1
        break
    N = len(S)

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

Submission status: Accepted

Solution code:
S = input()

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

damm = True

T = ''

while damm:
    damm = False
    for test in words:
        if S.endswith(test+T):
            T = test + T
            damm = True
            break
    if S == T:
        damm = True
        break

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

Submission status: Accepted

Solution code:
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()

        while len(S) > 0:
            if S[:11] == 'dreameraser':
                S = S[11:]
            elif S[:10] == 'dreamerase':
                S = S[10:]
            elif S[:7] == 'dreamer':
                S = S[7:]
            elif S[:6] == 'eraser':
                S = S[6:]
            elif S[:5] == 'dream' or S[:5] == 'erase':
                S = S[5:]
            else:
                print('NO')
                exit()
        print('YES')


# Run main
if __name__ == '__main__':
    AtCoder().main()

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)

s = input()

words = ['dream', 'dreamer', 'erase', 'eraser']
def dfs(idx):
    if idx == len(s):
        return True
    ans = False
    for word in words:
        if s[idx:idx+len(word)] == word:
            ans = ans or dfs(idx + len(word))

    return ans

if dfs(0):
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

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

for i in word_list:
        S = S.replace(i, '')
if S == '':
    print('YES')
else:
    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 S!="":
    if S[-1]=="m":
        if S[-5]=="d" and S[-4]=="r" and S[-3]=="e" and S[-2]=="a":
            S=S[:-5]
            continue
    elif S[-1]=="e":
        if S[-5]=="e" and S[-4]=="r" and S[-3]=="a" and S[-2]=="s":
            S=S[:-5]
            continue
    elif S[-2]=="e" and S[-1]=="r":
        if S[-3]=="m":
            if S[-7]=="d" and S[-6]=="r" and S[-5]=="e" and S[-4]=="a":
                S=S[:-7]
                continue
        elif S[-3]=="s":
            if S[-6]=="e" and S[-5]=="r" and S[-4]=="a":
                S=S[:-6]
                continue
    print("NO")
    break
else:
    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:
dest = input().rstrip("\n")

suffixes = ["dream", "dreamer", "erase", "eraser"]
cut_lens = [-5, -7, -5, -6]

while True:
    for suffix, cut_len in zip(suffixes, cut_lens):
        if dest.endswith(suffix):
            dest = dest[:cut_len]
            break
    else:
        break

print("YES" if not dest else "NO")

Submission status: Accepted

Solution code:
s = input()[::-1]
words = ["dream", "dreamer", "erase", "eraser"]
while True:
    match = False
    for w in words:
        if s.startswith(w[::-1]):
            s = s[len(w)::]
            match = True
    if match == False:
        break
print("NO" if len(s) else "YES")

Submission status: Accepted

Solution code:
S = input()

result = "NO"

while True:
    if S[-5:] == "dream":
        if len(S) == 5:
            result = "YES"
            break
        S = S[:-5]
    elif S[-5:] == "erase":
        if len(S) == 5:
            result = "YES"
            break
        S = S[:-5]
    elif S[-6:] == "eraser":
        if len(S) == 6:
            result = "YES"
            break
        S = S[:-6]
    elif S[-7:] == "dreamer":
        if len(S) == 7:
            result = "YES"
            break
        S = S[:-7]
    else:
        break

print(result)

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 'NO')

Submission status: Accepted

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

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

while s != '':
    for j in range(len(t)):
        if s[0:len(t[j])] == t[j]:
            s = s[len(t[j]):]
            break
    else:
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

Solution code:
S=str(input())
w=["dream", "dreamer", "erase", "eraser" ]
rw=[]

rs = S[::-1]
for i in w:
    rw.append(i[::-1])


res=False
while len(rs)>0:
    resin = False
    for i in rw:
        if i == rs[0:len(i)]:
            resin=True
            break

    if resin == True:
        rs=rs[len(i):]
        res=True
        continue
    else:
        res=False
        break
        

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

Submission status: Accepted

Solution code:
S=''.join(list(reversed(str(input()))))
words=["maerd","remaerd","esare","resare"]
flag = False
while(True):
    if(len(S) == 0):
        print("YES")
        break
    elif(S[0:len(words[0])] == words[0]):
        S = S[len(words[0]):]
    elif(S[0:len(words[1])] == words[1]):
        S = S[len(words[1]):]
    elif(S[0:len(words[2])] == words[2]):
        S = S[len(words[2]):]
    elif(S[0:len(words[3])] == words[3]):
        S = S[len(words[3]):]
    else:
        print("NO")
        break

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
li = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(li)):
    li[i] = li[i][::-1]

i = 0
can = True
while i < len(S):
    can2 = False
    # print("i: {}, len(S): {}".format(i, len(S)))
    for j in range(4):
        d = li[j]
        # print("d:{}".format(d))
        # print("len(d): {}".format(len(d)))
        # print("S[i:i+len(d)]: {}".format(S[i:i+len(d)]))
        if S[i:(i+len(d))] == d:
            can2 = True
            i += len(d)
            # print("成功, i:{}".format(i))
            break
        # print("失敗")

    if can2 == False:
        # print("失敗, i:{}".format(i))
        can = False
        break

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

Submission status: Accepted

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

while s != '':
    if s[-1]  == 'r':
        now = s[-7:]
        #print(now)
        if now == 'dreamer':
            #print(now)
            s = s[:len(s)-7]
        elif now[-6:] == 'eraser':
            #print(now)
            s = s[:len(s)-6]
        else:
            print('NO')
            exit()
    else:
        now = s[-5:]
        #print(now)
        if now in u:
            #print(now)
            s = s[:len(s)-5]
        else:
            print('NO')
            exit()

print('YES')

Submission status: Accepted

Solution code:
s = input()

if len(s) < 5:
    print("NO")
    exit()

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("NO")
else:
    print("YES")

Submission status: Accepted

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

ansB = True

while True:
    if index == 0:
        break
    elif index < 0:
        ansB = False
        break

    if S[index - 5: index] == 'dream' or S[index - 5: index] == 'erase':
        index -= 5
    elif S[index - 6: index] == 'eraser':
        index -= 6
    elif S[index - 7: index] == 'dreamer':
        index -= 7
    else:
        ansB = False
        break

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

Submission status: Accepted

Solution code:
from sys import exit
s = input()[::-1]
while True:
  if s == '':
    print('YES')
    exit()
  for w in ['maerd', 'remaerd', 'esare', 'resare']:
    if s.startswith(w):
      s = s[len(w):]
      break
  else:
    print('NO')
    exit()

Submission status: Accepted

Solution code:
from sys import exit
s = input()
ts = ['']
while True:
  nts= []
  for t in ts:
    for w in ['dreamer', 'eraser', 'dream', 'erase']:
      tw = t + w
      if s == tw:
        print('YES')
        exit()
      if s.startswith(tw):
        nts.append(tw)
  if len(nts) == 0:
    print('NO')
    exit()
  ts = nts

Submission status: Accepted

Solution code:
S = str(input())
i = 0
count = 0
a = ["dream","dreamer","erase","eraser"]

if S in a:
  print("YES")
  quit()


while i < len(S) - 7:
  if S[i] == "d":
    if S[i: i+6] == "dreamd":
      i += 5
    elif S[i:i+8] == "dreamera":
      i += 5
    elif S[i:i+8] == "dreamerd":
      i += 7
    elif S[i:i+8] == "dreamere":
      i += 7
    else:
      count += 1
      break
  elif S[i] == "e":
    if (S[i:i+6] == "erasee") or (S[i:i+6] == "erased"):
      i += 5
    elif (S[i:i+7] == "erasere") or (S[i:i+7] == "eraserd"):
      i += 6
    else:
      count += 1
      break
  else:
    count += 1
    break
      
S2 = S[::-1]
#print(count)
if count == 0:
  if (S2[0:5] == "maerd") or (S2[0:7] == "remaerd") or (S2[0:5] == "esare") or (S2[0:6] == "resare"): 
    print("YES")
    quit()
  
print("NO")

Submission status: Accepted

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