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

words_list = ["dream", "dreamer", "erase", "eraser"]
reversed_words_list = [ word[::-1] for word in words_list ]
reversed_phrase = phrase[::-1]

can1 = True
for i in range(len(reversed_phrase)):
    can2 = False
    if len(reversed_phrase) == 0:
        can2 = True
        break
    for checker in reversed_words_list:
        if reversed_phrase[0:len(checker)] == checker:
            can2 = True
            reversed_phrase = reversed_phrase[len(checker):]
            break
    if not can2:
        can1 = False
        break

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

Submission status: Accepted

Solution code:
# ABC049C - 白昼夢 / Daydream
s = (
    input()
    .replace("eraser", "")
    .replace("erase", "")
    .replace("dreamer", "")
    .replace("dream", "")
)
print("NO" if s else "YES")

Submission status: Accepted

Solution code:
s = input()

dp = [False]*(len(s)+1)

dp[0] = True

words = ['dream','dreamer','erase','eraser']
for i in range(len(s)+1):
    if dp[i]:
        for w in words:
            if s[i:i+len(w)]==w:
                dp[i+len(w)] = True
if dp[len(s)]:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s = input()
 
x = s.count("dreamerase")
a = s.count("dreamer") - x
b = s.count("dream") - a 
c = s.count("eraser")
d = s.count("erase") - c

if a*7 + b*5 + c*6 + d*5 == len(s):
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
#
# abc049 c
#
s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']

s = s[::-1]
while len(s) > 0:
    flag = 0
    for w in words:
        w = w[::-1]
        if s[0:len(w)] == w:
            s = s[len(w)::]
            # s = s.replace(w, "").lstrip()
            flag = 1
            break
    if flag == 0:
        print("NO")
        exit()

print("YES")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
target = input()
rev = target[::-1]
n = 0
prev = n
result = "YES"
while(n<len(rev)):
    for i in ["maerd", "esare", "resare", "remaerd"]:
        if rev[n:n+len(i)] == i:
            n += len(i)
    if prev == n:
        result = "NO"
        break
    prev = n
print(result)

Submission status: Accepted

Solution code:
# 2019/05/05
# AtCoder Beginner Contest 049 - C

# Input
s = input()
s = s + " "

# Init
sl = ["dream", "dreamer", "erase", "eraser"]

ans = "NO"
i = len(s)

# Check str
while(i > 1):
    wtflg = False
    for j in range(len(sl)):
        st = (len(s) - i + 1+ len(sl[j])) * -1
        ed = (len(s) - i + 1) * -1
        subs = s[st:ed]
            
        if subs == sl[j]:
            wtflg = True
            break
    
    if wtflg == False:
        break
    
    i = i - len(sl[j])

if i <= 1:
    ans = "YES"

# Output
print(ans)

Submission status: Accepted

Solution code:
S = input()
P = ['dream', 'dreamer', 'erase', 'eraser']
s = S
for i in range(10**5):
    flg = True
    for p in P:
        if s[len(s)-len(p):] == p:
            s = s[:len(s)-len(p)]
            flg = False
            break
    if flg:
         print('NO')
         quit()
    if len(s) == 0:
        break
print('YES')

Submission status: Accepted

Solution code:
words = {"dream": "A", "dreamer": "A", "erase": "A", "eraser": "A"}
 
ans = []
 
inputs = str(input())
 
inputs = inputs.replace("eraser", "").replace("erase", "")
inputs = inputs.replace("dreamer", "").replace("dream", "")

if len(list(inputs)) > 0:
  print("NO")
else:
  print("YES")

Submission status: Accepted

Solution code:
words = {"dream": "A", "dreamer": "A", "erase": "A", "eraser": "A"}
 
ans = []
 
inputs = str(input())
 
inputs = inputs.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")

if len(list(inputs)) > 0:
  print("NO")
else:
  print("YES")

Submission status: Accepted

Solution code:
def main():
  a = input()
  
  flg = "YES"
  index = 0
  while True:
    if index == len(a):
      break
    
    if a.find("dreameraser", index) == index:
      index += len("dreameraser")
    elif a.find("dreamerase", index) == index:
      index += len("dreamerase")
    elif a.find("dreamer", index) == index:
      index += len("dreamer")
    elif a.find("dream", index) == index:
      index += len("dream")
    elif a.find("eraser", index) == index:
      index += len("eraser")
    elif a.find("erase", index) == index:
      index += len("erase")
    else:
      flg = "NO"
      break
      
  print(flg)
  
main()

Submission status: Accepted

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

while len(s) > 4:
    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:
        break

if len(s) > 0:
    print('NO')
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:

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 re

s = input()
if re.match("(dream|dreamer|erase|eraser)*$", s):
    print("YES")
else:
    print("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:
# Atcoder C - 白昼夢 / Daydream

def main():
    S = input()

    while len(S) >= 5:
        if len(S) >= 7 and S[-7:] == "dreamer":
            S = S[:-7]
            continue

        if len(S) >= 6 and S[-6:] == "eraser":
            S = S[:-6]
            continue

        elif S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue

        else:
            break

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

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
booler=True
while s!=[] and booler==True:
  if s[-5]=="d" and s[-4]=="r" and s[-3]=="e" and s[-2]=="a" and s[-1]=="m":
    for i in range(5):
      del s[-1]
  elif s[-5]=="e" and s[-4]=="r" and s[-3]=="a" and s[-2]=="s" and s[-1]=="e":
    for i in range(5):
      del s[-1]
  elif s[-6]=="e" and s[-5]=="r" and s[-4]=="a" and s[-3]=="s" and s[-2]=="e" and s[-1]=="r":
    for i in range(6):
      del s[-1]
  elif s[-7]=="d" and s[-6]=="r" and s[-5]=="e" and s[-4]=="a" and s[-3]=="m" and s[-2]=="e" and s[-1]=="r":
    for i in range(7):
      del s[-1]
  else:
    booler=False
if booler:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
s = input()
ans = "YES"
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:
    ans = "NO"
    break
print(ans)

Submission status: Accepted

Solution code:
def main():
	S = input()
	pattern_exist = True
	while S:
		if S.startswith("dreamer"):
			if len(S) == 7:
				break
			if S[7:].startswith("dream") or S[7:].startswith("erase"):
				S = S[7:]
				continue
		if S.startswith("dream"):
			S = S[5:]
			continue
		if S.startswith("eraser"):
			if len(S) == 6:
				break
			if S[6:].startswith("dream") or S[6:].startswith("erase"):
				S = S[6:]
				continue
		if S.startswith("erase"):
			S = S[5:]
			continue
		pattern_exist = False
		break
	if pattern_exist:
		print("YES")
	else:
		print("NO")


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
s = input()
ans = "YES"
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:
        ans = "NO"
        break
print(ans)

Submission status: Accepted

Solution code:
S = input().replace('eraser', '').replace('erase', '')
chk = S.replace('dreamer', '').replace('dream', '')
print(['YES', 'NO'][len(chk) > 0])

Submission status: Accepted

Solution code:
S = input()
SS = S
T = ""
while(1):
    if T == SS:
        print("YES")
        break
    if S[len(S)-5:len(S)] == "dream":    
        T = "dream" + T
        S = S[0:len(S)-5]
    elif S[len(S)-7:len(S)] == "dreamer":
        T = "dreamer" + T
        S = S[0:len(S)-7]
    elif S[len(S)-5:len(S)] == "erase":
        T = "erase" + T
        S = S[0:len(S)-5]
    elif S[len(S)-6:len(S)] == "eraser":
        T = "eraser" + T
        S = S[0:len(S)-6]
    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:
def check(s: str):
  if len(s) >= 5 and s[-5:] in ['dream', 'erase']:
    return s[:-5]
  elif len(s) >= 6 and s[-6:] in ['eraser']:
    return s[:-6]
  elif len(s) >= 7 and s[-7:] in ['dreamer']:
    return s[:-7]
  return None

s = input()
matched = True
while len(s) > 0:
  s = check(s)
  if s is None:
    matched = False
    break
if matched:
  print('YES')
else:
  print('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()

from collections import deque

q = deque()
if len(S) > 5: #4文字以下ならそもそもバツ→入れない
  q.append((len(S), S))
#ここに、次にチェックする文字列を入れていく
#今回はque(fi-fo)として使うので、popleftを使う

flag = False
while(q):
  nowlen, nows = q.popleft()
  nows5 = nows[0:5]
  nowsfrom5 = nows[5:]
  if nows5 == 'dream':
    if nowlen == 5:
      flag = True
      break
    else:
      if nowlen>=10: q.append((nowlen-5, nowsfrom5))
    if nows[0:7] == 'dreamer':
      if nowlen == 7:
        flag = True
        break
      else:
        if nowlen>=12: q.append((nowlen-7, nows[7:]))
  elif nows5 == 'erase':
    if nowlen == 5:
        flag = True
        break
    else:
      if nowlen>=10: q.append((nowlen-5, nowsfrom5))
    if nows[0:6] == 'eraser':
      if nowlen == 6:
        flag = True
        break
      else: 
        if nowlen>=11: q.append((nowlen-6, nows[6:]))

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

Submission status: Accepted

Solution code:
#coding:utf-8
import re

if __name__ == "__main__":
    patterns = ["dream", "dreamer", "erase" ,"eraser"]
    S = input()

    while True:
        flag = False
        if S[-5:] == "dream":
            S = S[:-5]
            flag = True
        if S[-7:] == "dreamer":
            S = S[:-7]
            flag = True
        if S[-5:] == "erase":
            S = S[:-5]
            flag = True
        if S[-6:] == "eraser":
            S = S[:-6]
            flag = True

        if flag == False:
            print("NO")
            break

        if S == "":
            print("YES")
            break

Submission status: Accepted

Solution code:
def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    i = 0
    while 1:
        temp = []
        bool = True
        for t in T:
            if S[:len(t)] == t:
                S = S[len(t):]
                bool = False
        if bool:
            break
    if len(S) > 0:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    i = 0
    while 1:
        temp = []
        bool = True
        for t in T:
            if S[i:len(t) + i] == t:
                i += len(t)
                bool = False
        if bool:
            break
    if len(S) != i:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:


def read_input():
    s = input().strip()
    return s

def submit():
    s = read_input()
    rev_s = s[::-1]

    targets = ['dream', 'dreamer', 'erase', 'eraser']
    rev_targets = [t[::-1] for t in targets]

    while True:
        if not rev_s:
            print('YES')
            return

        for t in rev_targets:
            if rev_s.startswith(t):
                rev_s = rev_s[len(t):]
                break
        else:
            print('NO')
            return

if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
s=input()

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
words = ['dream', 'dreamer', 'erase', 'eraser']
while True:
    flag = False
    for i in words:
        n = len(i)
        if S[N-n:N] == i:
            flag = True
            N -= n
            break
    if not flag:
        ans = 'NO'
        break
    if N == 0:
        ans = 'YES'
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = str(input())[::-1]
d1 = 'dream'[::-1]
d2 = 'dreamer'[::-1]
d3 =  'erase'[::-1]
d4 =  'eraser'[::-1]

result = True
i = 0
while i < len(S):
  if S[i:i+5] == d1:
    i += 5
  elif S[i:i+7] == d2:
    i += 7
  elif S[i:i+5] == d3:
    i += 5
  elif S[i:i+6] == d4:
    i += 6
  else:
    result = False
    break

if result:
  print('YES')
else:
  print('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()

ct_1 = S.count('dream')
ct_2 = S.count('erase')
ct_3 = S.count('dreamerase')
ct_4 = S.count('dreamer')
ct_5 = S.count('eraser')
ct_dream = ct_1 - ct_4 + ct_3
ct_erase = ct_2 - ct_5
ct_dreamer = ct_4 - ct_3
ct_eraser = ct_5

length = 5*(ct_dream+ct_erase) + 6*(ct_eraser) + 7*(ct_dreamer)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

S = input()
T = []

a = re.split('eraser', S)
a1 = ''.join(a)
a2 = re.split('erase', a1)
a3 = ''.join(a2)
a4 = re.split('dreamer|dream', a3)
a5 = ''.join(a4)

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

Submission status: Accepted

Solution code:
s = input()
while(1):
    if s.endswith('dream'):
        s = s[:-5]
    elif s.endswith('dreamer'):
        s = s[:-7]
    elif s.endswith('eraser'):
        s = s[:-6]
    elif s.endswith('erase'):
        s = s[:-5]
    else:
        print("NO")
        quit()
    if s == '':
        break
print("YES")

Submission status: Accepted

Solution code:
import re;print(re.match('(dreame*|erase|r)*$',input())and'YES'or'NO')

Submission status: Accepted

Solution code:
import re;print(re.match('^(dream|dreamer|erase|eraser)*$',input())and'YES'or'NO')

Submission status: Accepted

Solution code:
import sys

def main():
    S = input()

    S = S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
    print('YES' if len(S)==0 else 'NO')

if __name__ == '__main__':
    main()

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

Submission status: Accepted

Solution code:
s = input()[::-1]
l = ['dream'[::-1],'dreamer'[::-1],'erase'[::-1],'eraser'[::-1]]
k = 0
while k<len(s):
    flag = 1
    for w in l:
        if s[k:k+len(w)]==w:
            k+=len(w)
            flag = 0
    if flag:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:

s = input()
d = ["dream","dreamer","erase","eraser"]

while s:
    if s[-5:] == d[0] or s[-5:] == d[2]:
        s = s[0:-5]
    elif s[-6:] == d[3]:
        s = s[0:-6]
    elif s[-7:] == d[1]:
        s = s[0:-7]
    else:
        break

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

Submission status: Accepted

Solution code:
s=input()
ans=1
i=0
while 1:
  if i>=len(s):
    break
  if s[i:i+5]=="dream":
    i+=5
  elif s[i:i+5]=="erase":
    if s[i:i+6]=="eraser":
      i+=6
    else:
      i+=5
  elif s[i-5:i+2]=="dreamer":
    i+=2
  else:
    ans=0
    break
if ans:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
import sys
s = input()
while len(s)>7:
    if s[:6]=="dreamd":
        s = s.replace("dream","",1)
        continue
    if s[:6]=="erased":
        s = s.replace("erase","",1)
        continue
    if s[:6]=="eraser":
        s = s.replace("eraser","",1)
        continue
    if s[:6]=="erasee":
        s = s.replace("erase","",1)
        continue
    if s[:8]=="dreamerd":
        s = s.replace("dreamer","",1)
        continue
    if s[:8]=="dreamera":
        s = s.replace("dream","",1)
        continue
    if s[:8]=="dreamere":
        s = s.replace("dreamer","",1)
        continue
    break
if s in ["dream","dreamer","erase","eraser"]:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input()
string = ['dream', 'dreamer', 'erase', 'eraser']
string = [i[::-1] for i in string]
S = S[::-1]
i = 0
while i < len(S):
    can = False
    for word in string:
        d = S[i:i+len(word)]
        if word == d:
            can = True
            i += len(word)
            break
    else:
        break

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

Submission status: Accepted

Solution code:
S = input()

# Sから文字を抜いていって、空文字列になればいいはず
# *erとerase*の先頭がぶつかるのでeraserから調べる
# dreamerを巻き込んでもdreamで拾えるので
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 = 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:
# -*- coding: utf-8 -*-

s = input()
s=s[::-1] #文字列の反転
words = ["maerd", "remaerd", "esare", "resare"]
while len(s) > 4:
    if s[:5] == words[0]:
        s = s[5:]
        continue
    elif s[:7] == words[1]:
        s = s[7:]
        continue
    elif s[:5] == words[2]:
        s = s[5:]
        continue
    elif s[:6] == words[3]:
        s = s[6:]
        continue
    else:
        break
if len(s) > 0:
    print('NO')
else:
    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:
S = input()

char = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if char:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
S = input()
lst_str = ["maerd", "remaerd", "esare", "resare"]
char = ""

for c in S[::-1]:
    char += c
    if char in lst_str:
        char = ""
if char:
    print("NO")
else:
    print("YES")

Submission status: Accepted

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

r=0
while r < len(s):
    if s[r:r+3] == "mae":
        if s[r:r+5] == "maerd":
            r += 5
        else:
            print("NO")
            exit()
    elif s[r:r+3] == "rem":
        if s[r:r+7] == "remaerd":
            r += 7
        else:
            print("NO")
            exit()
    elif s[r:r+3] == "esa":
        if s[r:r+5] == "esare":
            r += 5
        else:
            print("NO")
            exit()
    elif s[r:r+3] == "res":
        if s[r:r+6] == "resare":
            r += 6
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()

print("YES")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input().split()[0]
word_list = ['dream', 'dreamer', 'erase', 'eraser']

# erasedream
work_s = s
kumiawase = []

def check_end(text: str, k_word_list):
    ok_word = []
    for word in k_word_list:
        if text.endswith(word):
            ok_word.append(word)
    return ok_word

answer = 'NO'

while work_s:
    ok_word = check_end(work_s, word_list)
    if not ok_word:
        break

    # 後ろから見た場合かぶらないので、これは1回しか動かないはず
    for next_word in ok_word:
        work_s = work_s[:-len(next_word)]
else:
    answer = 'YES'

print(answer)

Submission status: Accepted

Solution code:
s = input()
  
while len(s) > 4:
  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 s:
  print("NO")
else:
  print("YES")

Submission status: Accepted

Solution code:
import sys
from collections import deque

def main():
    input = sys.stdin.readline
    S = str(input().strip())
    stock = ['dream', 'dreamer', 'erase', 'eraser']

    q = deque()
    q.append(S)
    while len(q) > 0:
        s = q.popleft()
        if len(s) == 0:
            return 'YES'

        if s[:5] in stock:
            q.append(s[5:])
        if s[:6] in stock:
            q.append(s[6:])
        if s[:7] in stock:
            q.append(s[7:])

    return 'NO'


if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
s=input()
while 1:
    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:break
print(["NO","YES"][s==""])

Submission status: Accepted

Solution code:

s = input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s: # s に何か残りがあればTrue
    print("NO")
else:
    print("YES")

"""
# =>わからなかった
s = input()
list = ['dream', 'dreamer', 'erase', 'eraser']
# print(s)

for j in range(22):
    for i in range(len(list)):
#        print(list[i])
#        print(s[-5:])
#        print(s[-7:])
#        print(s)
        if s[-5:] == list[i]:
            s = s.rstrip(list[i])
            if s == "":
                print("YES")
                exit()
        elif s[-7:] == list[i]:
            s = s.rstrip(list[i])
#            print(s)
            if s == "":
                print("YES")
                exit()
        else:
            pass
if s:
    print("NO")
"""

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

while "eraser" in S:
  S = S.replace("eraser", "")
while "erase" in S:
  S = S.replace("erase", "")
while "dreamer" in S:
  S = S.replace("dreamer", "")
while "dream" in S:
  S = S.replace("dream", "")
  
if S == "":
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
S = input()

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

#入力が文字列でABCDを満たすならTrueとその文字数，満たさないならFalseと0を返す関数
def ABCD(moziretu):
    bool = False
    x = 0
    if moziretu[-5:] == "dream":
        bool = True
        x = 5
    elif moziretu[-7:] == "dreamer":
        bool = True
        x = 7
    elif moziretu[-5:] == "erase":
        bool = True
        x = 5
    elif moziretu[-6:] == "eraser":
        bool = True
        x = 6
    return [bool,x]

while ABCD(S)[0]:
    x = ABCD(S)[1]
    S = S[:-x]

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

Submission status: Accepted

Solution code:
S = input()
N = ["dream", "dreamer", "erase", "eraser"]
bool = True

while bool:
  if len(S) == 0:
    break
 
  bool = False
  for n in N:
    
    if S.endswith(n):
      L = S.rsplit(n,1)
      S = L[0]
      bool = True
      break
  

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

Submission status: Accepted

Solution code:
s = input()
s_rev = s[::-1]
while s_rev[0:1]:
    if s_rev.startswith("maerd"):
        s_rev = s_rev[5::1]
    elif s_rev.startswith("remaerd"):
        s_rev = s_rev[7::1]
    elif s_rev.startswith("esare"):
        s_rev = s_rev[5::1]
    elif s_rev.startswith("resare"):
        s_rev = s_rev[6::1]
    else:
        print("NO")
        break
if bool(s_rev[0:1]) == False:
    print("YES")

Submission status: Accepted

Solution code:
#049 C

S = input()
A = 'dream'
B = 'dreamer'
C = 'erase'
D = 'eraser'

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

tmp =""
for i in S:
    tmp +=i
    for j in [A,B,C,D]:
        if tmp == j:
            S=S.replace(tmp,"",1)
            tmp=""
if len(S)==0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s=str(input())
flag=True
while len(s)>0 :
  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:
    flag=False
    break
if flag:
  print('YES')
else:
  print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
while s:
    flg = 0
    if s[-5:] in ['dream', 'erase']:
        s = s[:-5]
    elif s[-6:] == 'eraser':
        s = s[:-6]
    elif s[-7:] == 'dreamer':
        s = s[:-7]
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
T = ''
i = 0

while len(T) < len(S):
    if S[i:i+6] == 'eraser':
        T += 'eraser'
        i += 6
    elif S[i:i+5] == 'erase':
        T += 'erase'
        i += 5
    elif S[i:i+5] == 'dream':
        if S[i+5:i+6] == 'd':
            T += 'dream'
            i += 5
        elif S[i+5:i+8] == 'era':
            T += 'dream'
            i += 5
        elif S[i+5:i+6] == '':
            T += 'dream'
            i += 5
        elif S[i+5:i+8] == 'ere':
            T += 'dreamer'
            i += 7
        elif S[i+5:i+8] == 'erd':
            T += 'dreamer'
            i += 7
        elif S[i+5:i+8] == 'er':
            T += 'dreamer'
            i += 7
        else:
            T += 'dream'
            i += 5
    else:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

Solution code:
s=input()
for _ in range(20000):
    s=s.replace("eraser"," ").replace("erase"," ").replace("dreamer"," ").replace("dream"," ")
if s.rstrip():print("NO")
else:print("YES")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import re, sys

s = input()

regex = re.compile(r'^(dream|dreamer|erase|eraser)+$')

result = 'YES' if re.search(regex, s) else 'NO'
print(result)

Submission status: Accepted

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

flag1 = True
i = 0
while i < len(S):
    flag2 = False
    for d in div:
        if S[i:i + len(d)] == d:
            flag2 = True
            i += len(d)
            break

    if not flag2:
        flag1 = False
        break

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

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
a = ["dream", "dreamer", "erase", "eraser"]
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

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

def solve():
    s = ""
    for i in range(len(a)):
        a[i] = a[i][::-1]


    end = 0
    lent = len(t)
    while(len(s)<len(t)):
        ok = False
        for i in a:
            if len(s) + len(i) <= lent and i == t[len(s): len(s) + len(i)]:
                s += i
                ok = True

        if ok == False:
            print("NO")
            return
    
    print("YES")

solve()