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:
import re;
str = input()
if re.match(r"^(dream|dreamer|erase|eraser)+$",str):
    print("YES")
    exit(0)
print("NO")

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
s = ["eraser","erase","dreamer","dream"]
for i in s:
    S = S.replace(i,"")

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

Submission status: Accepted

Solution code:
S = input()

lists = ['dream', 'dreamer', 'erase', 'eraser']
for i, word in enumerate(lists[:]):
    lists[i] = word[::-1]
S = S[::-1]

while len(S) > 0:
    if S[:7] in lists:
        S = S[7:]
    elif S[:6] in lists:
        S = S[6:]
    elif S[:5] in lists:
        S = S[5:]
    else:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

Solution code:
s = input()
#s = 'erasedream'

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

end = False
while (not end) and (len(s) > 0):
    if s.endswith(a1):
        s = s[:-len(a1)]
    elif s.endswith(a2):
        s = s[:-len(a2)]
    elif s.endswith(a3):
        s = s[:-len(a3)]
    elif s.endswith(a4):
        s = s[:-len(a4)]
    else:
        end = True

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

Submission status: Accepted

Solution code:
s = input()
#s = 'erasedream'

a1 = 'dreamerase'
a2 = 'dreamer'
a4 = 'dream'
a3 = 'eraser'
a5 = 'erase'

end = False
while (not end) and (len(s) > 0):
    if s.endswith(a1):
        s = s[:-len(a1)]
    elif s.endswith(a2):
        s = s[:-len(a2)]
    elif s.endswith(a3):
        s = s[:-len(a3)]
    elif s.endswith(a4):
        s = s[:-len(a4)]
    elif s.endswith(a5):
        s = s[:-len(a5)]
    else:
        end = True

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = input()
add =['dreamer','eraser','erase','dream']
t = ''
i = len(a)-1
while(i<len(a)):
    p=0
    for v in add:
        s = i-len(v)+1;
        if s>=0:
            if a[s:i+1]==v:
                t=a[s:i+1]+t
                i=s-1
                p=1
    if p==0:
        break
print('YES' if t==a else 'NO')

Submission status: Accepted

Solution code:
S=input()
A=S.replace("eraser","").replace("erase","").replace('dreamer','').replace('dream','')

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

Submission status: Accepted

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

i = 0
flg = False
while i < len(S):
  flg = False
  for t in T:
    if S[i:i+len(t)] == t:
      i += len(t)
      flg = True
  if not flg:
    break

if flg:
  print('YES')
else:
  print('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()
i = len(S) - 1
while i > 0:
    if S[i] == 'm':
        if i < 4 or S[i - 4:i + 1] != "dream":
            print("NO")
            exit(0)
        i -= 5

    elif S[i] == 'e':
        if i < 4 or S[i - 4:i + 1] != "erase":
            print("NO")
            exit(0)
        i -= 5

    else:
        if i >= 6 and S[i - 6:i + 1] == "dreamer":
            i -= 7
            continue
        elif i >= 5 and S[i - 5:i + 1] == "eraser":
            i -= 6
            continue
        print("NO")
        exit(0)

print("YES")

Submission status: Accepted

Solution code:
S = input()

T = ""
items = ["dream", "dreamer", "erase", "eraser"]
candidates = [""]

for i in range(int(len(S)/5) + 1):
  new_candidates = []
  for candidate in candidates:
    for item in items:
      tmp = candidate + item
      # print(tmp)
      if len(tmp) > len(S):
        continue
      elif S == tmp:
        print("YES")
        exit()
      elif S[:len(tmp)] == tmp:
        new_candidates.append(tmp)
  candidates = new_candidates
  # print(candidates)
  if candidates == []:
    print("NO")
    exit()

Submission status: Accepted

Solution code:
S = input()
voc=['dream','dreamer','erase','eraser']
S = S[::-1]
newvoc=[]
for v in voc:
    newvoc.append(v[::-1])
can1= True
i=0
while i<len(S):
    can2 = False
    for v in newvoc:
        if S[i:i+len(v)] == v:
            can2 = True
            i+= len(v)
            break
    if not can2:
        can1= False
        break
if can1:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = str(input())
T = ''
cnt = 0
while True:
    if S[cnt:cnt+5] == 'dream':
        try:
            if S[cnt:cnt+7] == 'dreamer' and (S[cnt+7] != 'a'):
                cnt += 7
                T = T + 'dreamer'
            else:
                T = T + 'dream'
                cnt += 5
        except IndexError:
            cnt += 7
            T = T + 'dreamer'

    elif S[cnt:cnt+5] == 'erase':
        try:
            if S[cnt:cnt+6] == 'eraser' and S[cnt+6] != 'a':
                cnt += 6
                T = T + 'eraser'
            else:
                cnt += 5
                T = T + 'erase'
        except IndexError:
            cnt += 6
            T = T + 'eraser'
    else:
        break

    if len(S) <= cnt:
        break

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

Submission status: Accepted

Solution code:
S = input()

T = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace(
    "dream", "")

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

Submission status: Accepted

Solution code:
creds = [i[::-1] for i in ['dreamer', 'eraser', 'dream', 'erase']]
s = input()[::-1]
t = ""
index = 0
done_ = False
while len(s) != 0:
    done = False
    for cred in creds:
        if s.startswith(cred):
            s = s[len(cred):]
            done = True
            continue
    if not done:
        done_ = True
        break


if not done_:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re
s = input()
print('YES') if re.fullmatch('(maerd|remaerd|esare|resare)+', s[::-1]) else print('NO')

Submission status: Accepted

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

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

count = 0
end = False
yes = False

while 1:
    judge = 0
    for i in range(4):
        if S[count:(len(d[i])+count)] == d[i]:
            count += len(d[i])
            if count == L:
                end = True
                yes = True
        else:
            judge += 1
    if end or judge == 4:
        break

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

Submission status: Accepted

Solution code:
s = input()

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

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

Submission status: Accepted

Solution code:
s = input()

t = s.replace("dreameraser","1")
t = t.replace("dreamerase","2")
t = t.replace("dreamer","3")
t = t.replace("eraser","4")
t = t.replace("dream","5")
t = t.replace("erase","6")

try:
    int(t)
    print("YES")
except :
    print("NO")

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit
setrecursionlimit(100000)

s = stdin.readline().rstrip()
cand = ['eraser', 'erase', 'dreamer', 'dream']

for t in cand:
  s = s.replace(t, '')

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

Submission status: Accepted

Solution code:
s = input()
ans = 'YES'
while True:
  if len(s) == 0:
    break
  elif len(s) < 5:
    ans='NO'
    break
  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:
    ans = 'NO'
    break
print(ans)

Submission status: Accepted

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

cut = 0
for n in range(len(S)):
    if cut == len(S):
        break

    for m in range(len(l)):
        if S[cut:cut + len(l[m])] == l[m]:
            cut += len(l[m])
            break

print("YES" if cut == len(S) else "NO")

Submission status: Accepted

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

S = S.replace(d, '')  # dの並びはa,b,cのみでは再現不可（文字列にdの並びがあった際に再現できるのはdのみ）
S = S.replace(c, '')  # dの並びが存在しない文字列について、cの並びは、a,bのみでは再現不可
S = S.replace(b, '')  # c,dの並びが存在しない文字列について、bの並びは、aでは再現不可
S = S.replace(a, '')  # b,c,dの存在しない文字列がaのみで実現できる場合、replace結果は''となる
print('YES') if S == '' else print('NO')

Submission status: Accepted

Solution code:
import sys

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

# words = 'dream dreamer erase eraser'.split()
# words_ = {w[::-1] for w in words}

index = 0
index_max = len(S)

while True:
    if index == index_max:
        print('YES')
        sys.exit()
    elif S_[index:].startswith('maerd'):
        index += 5
        continue
    elif S_[index:].startswith('remaerd'):
        index += 7
        continue
    elif S_[index:].startswith('esare'):
        index += 5
        continue
    elif S_[index:].startswith('resare'):
        index += 6
        continue
    else:
        print('NO')
        sys.exit()

Submission status: Accepted

Solution code:
import re
S = input()

S = re.sub(r'eraser', '', S)
S = re.sub(r'erase', '', S)
S = re.sub(r'dreamer', '', S)
S = re.sub(r'dream', '', S)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for x in target:
    s = s.replace(x, "")

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

Submission status: Accepted

Solution code:
s = input()
while True:
    if s[-7:] == 'dreamer':
        s = s[:-7]
    elif s[-6:] == 'eraser':
        s = s[:-6]
    elif s[-5:] == 'dream':
        s = s[:-5]
    elif s[-5:] == 'erase':
        s = s[:-5]
    else:
        print('NO')
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input().rstrip()

while len(S) >= 5:
    if S[-5:] in ['dream', 'erase']:
        S = S[:-5]
        continue
    if S[-6:] == 'eraser':
        S = S[:-6]
        continue
    if S[-7:] == 'dreamer':
        S = S[:-7]
        continue
    print('NO')
    exit()

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
x = input()
n = len(x)
ans = "NO"

def f(i):
    if n==i:
        global ans
        ans = "YES"
    else:
        if x[i:i+5] == "dream":
            f(i+5)
        if x[i:i+7] == "dreamer":
            f(i+7)
        if x[i:i+5] == "erase":
            f(i+5)
        if x[i:i+6] == "eraser":
            f(i+6)
f(0)
print(ans)

Submission status: Accepted

Solution code:
a = input()
num = len(a)
ans = ''
while num>0:
    if a[num-1] == 'm':
        ans = 'dream' + ans
        num -= 5
    elif a[num-1] == 'e':
        ans = 'erase' + ans
        num -=5
    elif a[num-3:num] == 'mer':
        ans = 'dreamer'+ans
        num -=7
    elif a[num-3:num] == 'ser':
        ans = 'eraser'+ans
        num -= 6
    else:
        break
if ans == a:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
#解説解答
s = input()
n = len(s)
here = n
t = ''
while here > 0:
  try:
    if s[here-1:here] == 'm':
      t = 'dream' + t
      here -= 5
    elif s[here-1:here] == 'e':
      t = 'erase' + t
      here -= 5
    elif s[here-3:here] == 'mer':
      t = 'dreamer' + t
      here -= 7
    elif s[here-3:here] == 'ser':
      t = 'eraser' + t
      here -= 6
    else:
      break
  except:
    break
if s == t:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
S = input()
T = ["eraser", "erase", "dreamer", "dream"]
def daydream(S, T):
    for word in T:
        S = S.replace(word, " ")
    return "YES" if len(S.replace(" ", "")) == 0 else "NO"
 
print(daydream(S, T))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
s=input()
n=len(s)
ks={'eam':'dream','mer':'dreamer','ase':'erase','ser':'eraser'}
while n > 0:
    if n < 3:
        break
    e=s[n-3:n]
    if e not in ks:
        break
    if n < len(ks[e]):
        break
    if s[n-len(ks[e]):n] != ks[e]:
        break
    n-=len(ks[e])
else:
    print('YES')
    sys.exit()
print('NO')

Submission status: Accepted

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

for tg in targets:
    S = S.replace(tg, '')

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

Submission status: Accepted

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

i = len(S)
while True:
    if i == 0:
        print('YES')
        exit()
    for tg in targets:
        if S[i - len(tg):i][::-1] == tg[::-1]:
            i -= len(tg)
            break
    else:
        print('NO')
        exit()

Submission status: Accepted

Solution code:
import sys
s=input()
k="dream"
l="erase" #5文字ペア
m="eraser" #6文字
n="dreamer" #7文字
while True:
    if s=="":
        print("YES")
        sys.exit()
    elif k in s[-5:]:
        s=s[:-5]            
    elif l in s[-5:]:
        s=s[:-5]
    elif m in s[-6:]:
        s=s[:-6]
    elif n in s[-7:]:
        s=s[:-7]
    else:
        print("NO")
        sys.exit()

Submission status: Accepted

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

while any([s.endswith(word) for word in words]):
    for word in words:
        if s.endswith(word):
            s = s[:-len(word)]
            break

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

Submission status: Accepted

Solution code:

s = str(input())[::-1]

li=['dream'[::-1],'dreamer'[::-1],'erase'[::-1],'eraser'[::-1]]
i = 0
N = len(s)
while i<N:
    d = 0
    for l in li:
        if (s.startswith(l,i)):
            d = len(l)
            break
    if (d>0):
        i += d
        continue
    print("NO")
    break
else:
    print("YES")

Submission status: Accepted

Solution code:
s = input().replace('eraser',"").replace('erase',"").replace('dreamer',"").replace('dream',"")
print(['YES','NO'][0<len(s)])

Submission status: Accepted

Solution code:
s = input()

s1 = s.replace('eraser', '')
s2 = s1.replace('erase', '')
s3 = s2.replace('dreamer', '')
s4 = s3.replace('dream', '')

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

Submission status: Accepted

Solution code:
s = input()
str = s.replace('eraser','').replace('erase','').replace('dreamer','').replace('dream', '')
if len(str) == 0:
    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:
string = input()

rstr = string[::-1]
rstr = (((rstr.replace("resare", "")).replace("esare", "")).replace("remaerd", "")).replace("maerd", "")
if len(rstr) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:

s = input()
while s != '':
    if s[-7:] == 'dreamer':
        s = s[:-7]
    elif s[-6:] == 'eraser':
        s = s[:-6]
    elif s[-5:] == 'dream' or s[-5:] == 'erase':
        s = s[:-5]
    else:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

Solution code:
S=input()
l=len(S)
r=0
list5 = ['dream', 'erase']
list81 = ['dreamdre', 'dreamera', 'erasedre', 'eraseera']
list82 = ['dreamerd', 'dreamere']
list83 = ['eraserdr', 'eraserer']
if l<=4:
    print('NO')

while l>=5:
    if S[r:r+5] in list5:
        if r+5==l:
            print('YES')
            break
        elif r+5 == l-1:
            if S[r:r+6] == 'eraser':
                print('YES')
            else:
                print('NO')
            break
        elif r+5 == l-2:
             if S[r:r+7] == 'dreamer':
                 print('YES')
             else:
                 print('NO')
             break
        elif r+5 == l-3 or r+5 == l-4:
            print('NO')
            break
        else:
            if S[r:r+8] in list81:
                r=r+5
            elif S[r:r+8] in list82:
                r=r+7
            elif S[r:r+8] in list83:
                r=r+6
            else:
                print('NO')
                break
    else:
        print('NO')
        break

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    S = str(input())
    T = ''
    while True:
        if len(S) == 0:
            print('YES')
            break
        elif S[len(S)-7:len(S)] == 'dreamer':
            S = S[:len(S)-7]
            continue
        elif S[len(S)-6:len(S)] == 'eraser':
            S = S[:len(S)-6]
            continue
        elif S[len(S)-5:len(S)] == 'dream':
            S = S[:len(S)-5]
            continue
        elif S[len(S)-5:len(S)] == 'erase':
            S = S[:len(S)-5]
            continue
        else:
            print('NO')
            break

Submission status: Accepted

Solution code:
S = input()[::-1]
# maerd
# remaerd
# esera
# resera
L = ["dream"[::-1],
"dreamer"[::-1],
"erase"[::-1],
"eraser"[::-1]]

i = 0
N = len(S)
while i < N:
  d = 0
  for l in L:
    if S.startswith(l, i):
      d = len(l)
      break
  if d > 0:
    i += d
    continue
  print("NO")
  break
else:
  print("YES")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools

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

def solve(S: str):
    R = list(reversed(list(S)))
    tmp = ''
    for r in R:
        tmp = r + tmp
        if tmp in ['dream', 'dreamer', 'erase', 'eraser']:
            tmp = ''
        else:
            if len(tmp) >= 7:
                print('NO')
                return
    print('YES')
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
stack = [0]
while True:
  if len(stack) <= 0:
    break
  i = stack.pop()
  if i == len(S):
    print('YES')
    exit()
  if i+5 > len(S):
    continue
  if S[i:i+5] == 'dream':
    stack.append(i+5)
  if S[i:i+5] == 'erase':
    stack.append(i+5)
  if i+6 <= len(S):
    if S[i:i+6] == 'eraser':
      stack.append(i+6)
  if i+7 <= len(S):
    if S[i:i+7] == 'dreamer':
      stack.append(i+7)
print('NO')

Submission status: Accepted

Solution code:
word=input()

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



while 1:
  if word[len(word)-5:]==wordList[0]:
    word=word[:len(word)-5]
  elif word[len(word)-7:]==wordList[1]:
    word=word[:len(word)-7]
  elif word[len(word)-5:]==wordList[2]:
    word=word[:len(word)-5]
  elif word[len(word)-6:]==wordList[3]:
    word=word[:len(word)-6]
  else:
    print("NO")
    break
  if word=="":
    print("YES")
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 確認

S = str(input())
words = ['dream', 'dreamer', 'erase', 'eraser']
dp = [0] * 100010

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

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

Submission status: Accepted

Solution code:
import sys

s = sys.stdin.read().strip()
words = ["dream", "dreamer", "erase", "eraser"]

stack = [0]
match = False
while not match and stack:
  i = stack.pop()
  for w in words:
    if s.startswith(w, i):
      n = i + len(w)
      if n == len(s):
        match = True
        break
      stack.append(n)
print("YES" if match else "NO")

Submission status: Accepted

Solution code:
import re
S = input()
Snew = S[::-1]
result = re.sub('maerd|remaerd|resare|esare',"",Snew)
if  result == "":
    print("YES")
else: 
    print("NO")

Submission status: Accepted

Solution code:
S = input()
while True:
  if len(S) == 0:
    print("YES")
    break
  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")
    break

Submission status: Accepted

Solution code:
def solve():
    s = ''.join(reversed(input()))
    words = [''.join(reversed(substr)) for substr in ["dream", "dreamer", "erase", "eraser"]]
    while True:
        word = [w for w in words if s.startswith(w)]
        if word:
            s = s[len(word[0]):]
            if not s:
                return "YES"
        else:
            return "NO"


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
import re

s = input()

candidates = ["dream", "dreamer", "erase", "eraser"]
ok = False
t = ""

pattern = r"^(dream|dreamer|erase|eraser)*$"
repatter = re.compile(pattern)
match_obj = repatter.match(s)

if match_obj:
    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:
s = list(input())
words = ["dream", "dreamer", "erase", "eraser"]
ans = True
while True:
    if s == []:
        print("YES")
        break
    if "".join(s[-5:]) == "dream":
        del s[-5:]
    elif "".join(s[-7:]) == "dreamer":
        del s[-7:]
    elif "".join(s[-5:]) == "erase":
        del s[-5:]
    elif "".join(s[-6:]) == "eraser":
        del s[-6:]
    else:
        print("NO")
        break

Submission status: Accepted

Solution code:
S = input()
S = list(S)
S.reverse()
T = []
n = len(S)
for i in range(n):
  T.append(S[i])
  mojiretu = ''.join(T)
  m = len(mojiretu)
  if mojiretu == "maerd" or mojiretu == "remaerd" or mojiretu == "esare" or mojiretu == "resare":
    T =[]
  elif m==8:
      break
N = len(T)
if N == 0:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
S = input()
for k in range(int(len(S)/5)):
    for word in ["dream", "dreamer", "erase", "eraser"]:
        if S.endswith(word):
            S=S[:-len(word)]
if len(S)==0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
#### import ####
import sys
sys.setrecursionlimit(10**7)
import math
from collections import defaultdict

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return map(list,zip(*read_all))

#################

S = str(input())
while S:
  ls = len(S)
  if ls>=7:
    if S[-7:]=='dreamer':
      S = S[:-7]
      continue
    elif S[-6:]=='eraser':
      S = S[:-6]
      continue
    elif S[-5:]=='dream':
      S = S[:-5]
      continue
    elif S[-5:]=='erase':
      S = S[:-5]
      continue
    else:
      print('NO')
      exit()
  if ls>=6:
    if S[-6:]=='eraser':
      S = S[:-6]
      continue
    elif S[-5:]=='dream':
      S = S[:-5]
      continue
    elif S[-5:]=='erase':
      S = S[:-5]
      continue
    else:
      print('NO')
      exit()
  if ls>=5:
    if S[-5:]=='dream':
      S = S[:-5]
      continue
    elif S[-5:]=='erase':
      S = S[:-5]
      continue
    else:
      print('NO')
      exit()
  print('NO')
  exit()

print('YES')

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()
words = "eraser", "erase", "dreamer", "dream"

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

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

Submission status: Accepted

Solution code:
words = ["dream", "dreamer", "erase", "eraser"]
s = input()
dp = [0] * (len(s)+1)
dp[0] = 1

for i in range(len(s)+1):
  if dp[i]!=1: continue
  for word in words:
    if word in s[i:i+len(word)]:
      dp[i+len(word)] = 1
      
print("YES" if dp[len(s)] else "NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:

S = input()

start = len(S)

while 0<start:

    if start < 5:
        print("NO")
        exit()
    elif start == 7 and S[start-7:start] == "dreamer":
        print("YES")
        exit()
    elif start == 6 and S[start-6:start] == "eraser":
        print("YES")
        exit()
    elif start == 5 and S[start-5:start] == "erase":
        print("YES")
        exit()
    elif start == 5 and S[start-5:start] == "dream":
        print("YES")
        exit()
    elif S[start-6:start] == "eraser":
        start -=6
    elif S[start-5:start] == "erase":
        start -=5
    elif S[start-5:start] == "dream":
        start -=5
    elif S[start-7:start] == "dreamer":
        start -=7
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
S = list(input())
ans = 'NO'
while len(S)!=0:
    if(''.join(S[-5:])=='dream' or ''.join(S[-5:])=='erase'):
        del S[-5:]
    elif(''.join(S[-6:])==(('eraser'))):
        del S[-6:]
    elif(''.join(S[-7:])==(('dreamer'))):
        del S[-7:]
    else:
        break

if len(S)==0:
    ans = 'YES'

print(ans)

Submission status: Accepted

Solution code:
S = input()

start = 0

while start < len(S):

    if start == len(S)-8 or start > len(S)-5:
        print("NO")
        exit()
    elif start == len(S)-7 and S[start:start+7] == "dreamer":
        print("YES")
        exit()
    elif start == len(S)-6 and S[start:start+6] == "eraser":
        print("YES")
        exit()
    elif start == len(S)-5 and S[start:start+5] == "erase":
        print("YES")
        exit()
    elif start == len(S)-5 and S[start:start+5] == "dream":
        print("YES")
        exit()
    elif S[start:start+6] == "eraser":
        start +=6
    elif S[start:start+5] == "erase":
        start +=5
    elif S[start:start+8] == "dreamera":
        start +=5
    elif S[start:start+7] == "dreamer":
        start +=7
    elif S[start:start+5] == "dream":
        start +=5
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
INPUT_STR = input()


match_patterns = [
    ''.join(list(reversed('dream'))),
    ''.join(list(reversed('dreamer'))),
    ''.join(list(reversed('erase'))),
    ''.join(list(reversed('eraser')))
]

string = ''.join(list(reversed(INPUT_STR)))


def is_concatted_string(string):
    string = ''.join(list(reversed(string)))
    while len(string) != 0:
        for pattern in match_patterns:
            if string.startswith(pattern):
                string = string[len(pattern):]
                if len(string) == 0:
                    return True
                break
        else:
            return False
    return False


if INPUT_STR != '' and is_concatted_string(INPUT_STR):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input()
words = ['dream', 'dreamer', 'erase', 'eraser']
while len(S) > 0:
  judge = [S.endswith(w) for w in words]
  # 逆から考えることで単語の重複をなくすのがポイント！
  if any(judge):
    hit_word = words[judge.index(True)]
    S = S[:-len(hit_word)]
    if len(S) == 0:
      print('YES')
      break
  else:
    print('NO')
    break

Submission status: Accepted

Solution code:
def check(str):
	for i in range(len(str)//5+1):
		if str=="":
			return "YES"
		elif str[-5:]=="dream" or str[-5:]=="erase" :
			str=str[:-5]
		elif str[-6:]=="eraser":
			str=str[:-6]
		elif str[-7:]=="dreamer":
			str=str[:-7]
		else:
			return "NO"

str=input()
print(check(str))