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

s = input()[::-1]
while len(s) > 0:
    for ptn in ['dream', 'dreamer', 'erase', 'eraser']:
        if re.match(ptn[::-1], s) is not None:
            s = s[len(ptn):]
            break
    else:
        break
print('YES' if len(s) == 0 else 'NO')

Submission status: Accepted

Solution code:
S = list(input())[::-1]
L,i = len(S),0
words = [list(word) for word in ['maerd', 'esare', 'remaerd', 'resare'] ]

while i < L-7:
    if S[i:i+5] in words[:2]:  i += 5
    elif S[i:i+6] == words[3]: i += 6
    elif S[i:i+7] == words[2]: i += 7
    else: break

if S[i:] in words:  print('YES')
else:   print('NO')

Submission status: Accepted

Solution code:
# 正規表現を用いた解法
from re import match


# f = open("./16/input_c2_2.txt")


# def input():
#     return f.readline().rstrip()


def main():
    S = input()

    if match('(dreamer|eraser|erase|dream)+$', S):
        print("YES")
    else:
        print("NO")

        # while True:
        #     result_1 = search('dreamer$', S)
        #     result_2 = search('eraser$', S)
        #     result_3 = search('erase$', S)
        #     result_4 = search('dream$', S)

        #     if result_1:
        #         S = S[:result_1.start()]
        #     elif result_2:
        #         S = S[:result_2.start()]
        #     elif result_3:
        #         S = S[:result_3.start()]
        #     elif result_4:
        #         S = S[:result_4.start()]
        #     else:
        #         print("NO")
        #         break

        #     if len(S) == 0:
        #         print("YES")
        #         break


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def main():
    S = input()
    while True:
        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:
            print("NO")
            break

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

def str_read(s):
    while True:
        if len(s) == 0:
            return True
        else:
            if s[0:5] in ['maerd', 'esare']:
                s = s[5:]
            elif s[0:6] in ['resare']:
                s = s[6:]
            elif s[0:7] in ['remaerd']:
                s = s[7:]
            else:
                return False


si = input()
if str_read(si[::-1]):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s = input()[::-1]
keys = ["dream", "dreamer", "erase", "eraser"]
keys_ = [i[::-1] for i in keys]
i = 0
t = ''

for _ in range(len(s)):
  for key in keys_:
    if s[i:].startswith(key):
      t += key
      i += len(key)
    if t == s:
      print('YES')
      exit()
else:
  print('NO')

Submission status: Accepted

Solution code:
import re
s=input()
pat=r'^(dream(er)?|erase(r)?)*$'
a=re.match(pat,s)
print('YES' if a else 'NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=list(input())
i=0
while i!=len(S):
    if i+6<=len(S) and S[i:i + 6] == ['e', 'r', 'a', 's', 'e', 'r']:
        i += 6
    elif i+5<=len(S) and S[i:i+5]==['e','r','a','s','e']:
        i+=5
    elif i+7<=len(S) and S[i:i+7]==['d','r','e','a','m','e','r'] and (len(S[i:])==7 or (S[i+7]!='a')):
        i+=7
    elif i+5<=len(S) and S[i:i+5]==['d','r','e','a','m']:
        i+=5
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()


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

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
def judge(n,s):
    if s[n-5:n] == "erase":
        return n-5
    elif s[n-5:n] == "dream":
        return n-5
    elif s[n-6:n] == "eraser":
        return n-6
    elif s[n-7:n] == "dreamer":
        return n-7
    else:
        return -1

while n>=5:
    n = judge(n,s)

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
e = 0
def judge(a,b,c):
    if c[a-5:a] == "erase":
        b = 5
        return b
    elif c[a-5:a] == "dream":
        b = 5
        return b
    elif c[a-6:a] == "eraser":
        b = 6
        return b
    elif c[a-7:a] == "dreamer":
        b = 7
        return b
    else:
        return 100
while n >= 5:
    e = judge(n,e,s)
    if e == 100:
        break
    else:
        n = n - e
if n == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
t = ["resare","esare","remaerd","maerd"]
s.reverse()
check = True
i = 0
while i < n:
    counter = 0 #不適合数
    for k in range(4):
        temp = True
        for j in range(len(t[k])):
            if s[i+j] != t[k][j]:
                temp = False
                break
        if temp == False:
            counter += 1
        else:
            add = len(t[k])
    if counter == 4:
        check = False
        break
    else:
        i += add
if check:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
s1=reversed(s)
l=["dream","dreamer","erase","eraser"]
s2=[]
for item in s1:
  s2.insert(0,item)
  str=''.join(s2)
  if str in l:
    s2=[]
  elif len(s2)>7:
    break
if len(s2)==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", "")
print("YES") if not S else print("NO")

Submission status: Accepted

Solution code:
s = input()[::-1]
words = [w[::-1] for w in ['dream', 'dreamer', 'erase', 'eraser']]

can = 'YES'
while s:
    match_any = False
    for w in words:
        if s.startswith(w):
            s = s.replace(w, '', 1)
            match_any = True
            break
    if not match_any:
        can = 'NO'
        break
print(can)

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

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

def solve():
    s = input()

    s = s[::-1]

    for i in range(4):
        a[i] = a[i][::-1]
    
    t = ''

    while t!=s:
        ok = False
        for i in a:
            temp = t+i
            if len(temp)<= len(s) and temp == s[:len(temp)]:
                t = temp
                ok = True
                continue
        if not ok:
            print('NO')
            return

        



    print('YES')



solve()

Submission status: Accepted

Solution code:
S = input()
targets = ["dream", "dreamer", "erase", "eraser"]
while True:
    isEndTarget = False
    for target in targets:
        if S.endswith(target):
            S = S[: -len(target)]
            isEndTarget = True
            break
    if not isEndTarget:
        print("NO")
        break
    elif S == "":
        print("YES")
        break

Submission status: Accepted

Solution code:
S = input()
targets = ['dream', 'dreamer', 'erase', 'eraser']
while True:
    isEndTarget = False
    for target in targets:
        if S.endswith(target):
            S = S[:-len(target)]
            isEndTarget = True
            break
    if not isEndTarget:
        print('NO')
        break
    elif S == '':
        print('YES')
        break

Submission status: Accepted

Solution code:
S = input()

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

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

Submission status: Accepted

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

valid = True
while len(s) > 0:
    if s[:6] == 'eraser'[::-1]:
        s = s[6:]
    elif s[:5] == 'erase'[::-1]:
        s = s[5:]
    elif s[:7] == 'dreamer'[::-1]:
        s = s[7:]
    elif s[:5] == 'dream'[::-1]:
        s = s[5:]
    else:
        valid = False
        break


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    S = input()

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

    while len(S) > 0:
        for word in word_list:
            flag = "NO"
            if S[len(S) - len(word):] == word:
                S = S[:len(S) - len(word)]
                flag = "YES"
                break

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

main()

Submission status: Accepted

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

S = S[::-1]
check = True
i = 0
while i < len(S):
  if S[i:i+7] == cands[1]:
    i += 7
  elif S[i:i+6] == cands[3]:
    i += 6
  elif S[i:i+5] in cands:
    i += 5
  else:
    check = False
    break   
  

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

Submission status: Accepted

Solution code:
#coding:utf-8
import sys
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
    if S[-5:] == "erase" or S[-5:] == "dream":
        S = S[:-5]
        continue
    else:
        print("NO")
        sys.exit()

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

Submission status: Accepted

Solution code:
from sys import stdin
S=(stdin.readline().rstrip())
while 1:
    cnt=4
    for i in ["dream","dreamer","erase","eraser"]:
        if S[-len(i):] == i:
            S = S[:(len(S)-len(i))]
        else:
            cnt-=1
            
    if S == "":
        print("YES")
        break
        
    if cnt == 0:
        print("NO")
        break

Submission status: Accepted

Solution code:
s = input()
t = ''
while s:
    a = ''
    for i in ['eraser', 'erase', 'dreamer', 'dream']:
        if s.endswith(i) : a = i; break
    if a == '' : print('NO');exit()
    s = s[:-len(a)]
print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
word_list = ("dream", "dreamer", "erase", "eraser")

s = input()

i = 0
while i < len(s):
    if s[i:i+11] == "dreameraser":
        i += 11
    elif s[i:i+10] == "dreamerase":
        i += 10
    elif s[i:i+7] == word_list[1]:
        i += 7
    elif s[i:i+6] == word_list[3]:
        i += 6
    elif s[i:i+5] == word_list[0] or s[i:i+5] == word_list[2]:
        i += 5
    else:
        print("NO")
        exit()

print("YES")

Submission status: Accepted

Solution code:
S = input()
flag = True
while flag:
    if S[:7] == 'dreamer':
        if S[:10] == 'dreamerase':
            S = S[5:]
        else:
            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:
        flag = False
if S:
    print('NO')
else:
    print('YES')

Submission status: Accepted

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

s_list = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]

while True:
  flag = False
  for l in s_list:
    if s[0:len(l)] == l:
      s = s[len(l):]
      flag = True
  if s == '':
    print('YES')
    sys.exit()
  if flag == False:
    print('NO')
    sys.exit()

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

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]
word_list = ['dream', 'dreamer', 'erase', 'eraser']
reversed_list = []
for w in word_list:
    reversed_list.append(w[::-1])

can_divide = True
i = 0
while i < len(s):
    # print(s[i:])
    temp_can = False
    for w in reversed_list:
        if s[i:i+len(w)] == w:
            temp_can = True
            i += len(w)
    if not temp_can:
        # print(s[i:])
        can_divide = False 
        break

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

Submission status: Accepted

Solution code:

def list_join(l: []):
    word_list = ['dream', 'dreamer', 'erase', 'eraser']
    nl = []
    for ele in l:
        for word in word_list:
            nl.append(ele + word)
    return nl


def main():
    S = str(input())
    # S = 'dreamerer'
    lst = ['']
    while True:
        lst = list_join(lst)
        lst = list(filter(lambda word: S.startswith(word), lst))
        if len(lst) == 0:
            print('NO')
            return
        if S in lst:
            print('YES')
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ls = ['dream', 'dreamer', 'erase', 'eraser']
ls = [word[::-1] for word in ls]
s = input().rstrip()[::-1]

can = 1
i = 0
while i < len(s):
    div = 0
    for word in ls:
        if s[i:i+len(word)] == word:
            div = 1
            i += len(word)
            break
    if div == 0:
        can = 0
        break

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

Submission status: Accepted

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

S = list(reversed(input().strip()))
P = [list(reversed(v)) for v in ["dream", "dreamer", "erase", "eraser"]]

n = 0
while n < len(S):
    if S[n:n+5] == P[0] or S[n:n+5] == P[2]:
        n += 5
    elif S[n:n+7] == P[1]:
        n += 7
    elif S[n:n+6] == P[3]:
        n += 6
    else:
        print("NO")
        exit()
        
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()
s = ''
ar = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(1, len(S)+1):
    s = S[-i] + s
    if s in ar:
        s = ''
    if len(s) > 10:
        break

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

Submission status: Accepted

Solution code:
import re

S = input()
S = S[::-1] # 文字列反転

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

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

fin = False
while not fin:
    if S == '':
        print("YES")
        exit()
    fin = True
    for x in pattern:
        if re.match(x, S):
            S = S.replace(x, "", 1)
            fin = False
            break

print("NO")

Submission status: Accepted

Solution code:
s=str(input())
while len(s)>=1:
    if s[-5:]=="erase":
        s=s[:-5]
    elif s[-5:]=="dream":
        s=s[:-5]
    elif s[-6:]=="eraser":
        s=s[:-6]
    elif s[-7:]=="dreamer":
        s=s[:-7]
    else:
        break

print("YNEOS"[len(s)>0::2])

Submission status: Accepted

Solution code:
S = input()

i = 0
while True:
    if i >= len(S):
        print('YES')
        break
    if S[i:i+5] == 'dream':
        if S[i+5:i+10] == 'erase':
            if S[i+10:i+11] == 'r':
                i += 11
            else:
                i += 10
        elif S[i+5:i+7] == 'er':
            i += 7
        else:
            i += 5
    elif S[i:i+5] == 'erase':
        if S[i+5:i+6] == 'r':
            i += 6
        else:
            i += 5
    else:
        print('NO')
        break

Submission status: Accepted

Solution code:
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

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

        break

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

main()

Submission status: Accepted

Solution code:
import sys

S = input()

S = S[::-1]

chars = ['dreamer', 'eraser', 'dream', 'erase']
chars = [char[::-1] for char in chars]

while 1:
    end_flag = 1
    for char in chars:
        if ( S.find(char) == 0):
            S = S[len(char):]
            end_flag = 0

            if S == '':
                print('YES')
                sys.exit()
    if end_flag ==1:
            print('NO')
            sys.exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 入力割り当て
S = str(input())
l = len(S)

# 文字列判定
flg = True
ans = 'YES'
i = 0
while flg:
	if S[i:i+11] == 'dreameraser':
		i +=11
	elif S[i:i+10] == 'dreamerase':
		i += 10
	elif S[i:i+7] == 'dreamer':
		i += 7
	elif S[i:i+6] == 'eraser':
		i += 6
	elif S[i:i+5] == 'dream' or S[i:i+5] == 'erase':
		i += 5
	elif i >= l:
		flg = False
	else:
		flg = False
		ans = 'NO'

# 結果の表示
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ss = input()
l = ["dream","dreamer","erase","eraser"]
    
for i_1 in range(4):
    for i_2 in range(4):
        for i_3 in range(4):
            for i_4 in range(4):
                s = ss
                while l[i_1] in s or l[i_2] in s or l[i_3] in s or l[i_4] in s:
                    s = s.replace(l[i_1],"").replace(l[i_2],"").replace(l[i_3],"").replace(l[i_4],"")
                    if s == "":
                        print("YES")
                        exit()

if s != "":
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=['dream','dreamer','erase','eraser']
def check(c):
    if c=='':
        return True
    size=len(c)
    n=len(c)
    while n>0:
        tmp=n
        for i in a:
            #print(-n-len(i),-n)
            if size>=len(i) and c[n-len(i):n]==i:
                n-=len(i)
        if tmp==n:
            return False
    return True

print('YES' if check(input()) else 'NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
while len(S) > 0:
    if ''.join(S[-5:]) == 'dream' or ''.join(S[-5:]) == 'erase':
        S = S[:-5]
    elif ''.join(S[-6:]) == 'eraser':
        S = S[:-6]
    elif ''.join(S[-7:]) == 'dreamer':
        S = S[:-7]
    else:
        print('NO')
        quit()
print('YES')

Submission status: Accepted

Solution code:
import re
print("YES" if re.match("^(eraser?|dream(er)?)*$",input()) else "NO")

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
s = input()

while s:
    if s[:6] == "eraser":
        s = s[6:]
    elif s[:5] == "erase":
        s = s[5:]
    elif s[:5] == "dream":
        if s[5:8] == "era":
            s = s[5:]
        elif s[5:7] == "er":
            s = s[7:]
        else:
            s = s[5:]
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
def isDaydream(s):
    while s != "":
        if s.endswith("dream"):
            s = s[:-5]
        elif s.endswith("dreamer"):
            s = s[:-7]
        elif s.endswith("erase"):
            s = s[:-5]
        elif s.endswith("eraser"):
            s = s[:-6]
        else :
            return False
    return True

if(isDaydream(input())):
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
w=["dream","dreamer","erase","eraser"]
q=[0]
while q:
    i = q.pop()
    s = S[i:]
    if s == "":
        print("YES")
        break
    for c in w:
        if c==s[:len(c)]:q.append(i+len(c))
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re
S = input()
num = []
l = []

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



"""
if ("eraser" in S)  == True:
	S.replace("eraser", "")

if ("erase" in S)   == True:
	S.replace("erase", "")

if ("dreamer" in S) == True:
	S.replace("dreamer", "")

if ("dream" in S)   == True:
	S.replace("dreamer", "")
"""

"""
if ("eraser" in S)  == True:
	num.append(S.count("eraser"))
	for i in range(S.count("eraser")):
		a.append(S.find("eraser"))
		S[S.find("eraser"):6]

if ("erase" in S)   == True:
	num.append(S.count("erase"))
	for i in range(S.count("erase")):
		a.append(S.find("erase"))
		S[S.find("erase"):5]

if ("dreamer" in S) == True:
	num.append(S.count("dreamer"))
	for i in range(S.count("dreamer")):
		a.append(S.find("dreamer"))
		S[S.find("dreamer"):7]

if ("dream" in S)   == True:
	num.append(S.count("dream"))
	for i in range(S.count("dream")):
		a.append(S.find("dream"))
		S[S.find("dream"):5]
"""

Submission status: Accepted

Solution code:
S=input()
n=0
#print(S)
while S[:]!=S[:n]:
    if S[n:n+7]=="dreamer" and S[n:n+8]!="dreamera":
        n+=7 #dreamer
    elif S[n:n+5]=="dream":
        n+=5 #dream
    elif S[n:n+5]=="erase" and S[n:n+6]!="eraser":
        n+=5 #erase
    elif S[n:n+6]=="eraser":
        n+=6 #eraser
    #elif S[:]==S[:n-1]:
        #print("YES")
        #exit()
    else:
        print("NO")
        exit()
else:
    print("YES")

Submission status: Accepted

Solution code:
S = input()[::-1]
words = {w[-1]:w[::-1] for w in ['dream', 'erase', 'er']}
i = 0
flag = True
#print(words)
while i < len(S):
  c = S[i]
  if c in words:
    if S[i:i+len(words[c])] == words[c]:
      i += len(words[c])
    else :
      flag = False
      break
    if c == 'r':
       if S[i:i+len(words['m'])] == words['m']:
         i += len(words['m'])
       elif S[i-1:i-1+len(words['e'])] == words['e']:
         i += len(words['e']) - 1
       else :
         flag = False
         break
  else :
    break
  if not flag:
    break
print('YES' if flag else 'NO')

Submission status: Accepted

Solution code:
#英小文字からなる文字列 S が与えられます。T が空文字列である状態から始めて、以下の操作を好きな回数繰り返すことで S=T とすることができるか判定してください。
#T の末尾に "dream", "dreamer", "erase", "eraser" のいずれかを追加する。


s=input()
s1="dream"
s2="dreamer"
s3="erase"
s4="eraser"
l=len(s)

rest="NO"

while l>4:
	if s[-5:]==s1 or s[-5:]==s3:
		s=s[0:-5]
		l=l-5
	elif s[-6:]==s4:
		s=s[0:-6]
		l=l-6
	elif s[-7:]==s2:
		l=l-7
		s=s[0:-7]
	else:
		break

if l==0:
	rest="YES"

print(rest)

Submission status: Accepted

Solution code:
from collections import deque

S = list(input())
S.reverse()
l = len(S)

def rev(x):
    x = list(x)
    x.reverse()
    return x

a = list(map(rev,['dream','dreamer','erase','eraser']))
q = deque()
q.append(["",0])

while len(q):
    b,i = q.pop()
    if i == l:
        print('YES')
        exit()
    x = 0
    f = True
    for B in b:
        if i+x >= l or S[i+x] != B:
            f = False
        x += 1
    if f:
        for A in a:
            q.append([A,i+x])

print('NO')

Submission status: Accepted

Solution code:
from collections import deque

S = input()
l = len(S)

a = list(map(list,['dream','dreamer','erase','eraser']))
q = deque()
q.append(["",0])

while len(q):
    b,i = q.pop()
    if i == l:
        print('YES')
        exit()
    x = 0
    f = True
    for B in b:
        if i+x >= l or S[i+x] != B:
            f = False
        x += 1
    if f:
        for A in a:
            q.append([A,i+x])

print('NO')

Submission status: Accepted

Solution code:
s =input()
s1 = "dream"
s2= "dreamer"
s3 = "eraser"
s4 = "erase"
n=len(s)
res="NO"
while len(s)!=0 or s>4:
    n=len(s)
    if s[-5:]==s1 or s[-5:]==s4:
        s=s[:n-5]
    elif s[-7:]==s2:
        s=s[:n-7]
    elif s[-6:]==s3:
        s=s[:n-6]
    else:
        break
    if len(s)==0:
        res="YES"
        break
print(res)

Submission status: Accepted

Solution code:
import re
text = input()
matche_str = re.compile(r'^(dream|dreamer|erase|eraser)+$')
mo = matche_str.search(text)
 
if mo != None:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
def judger(s):
    '''
    input:
    s = 5 target characters
    output:
    Predict word from the first 5 characters 
    '''
    if s == 'maerd':
        return 'maerd'
    elif s == 'remae':
        return 'remaerd'
    elif s == 'esare':
        return 'esare'
    elif s == 'resar':
        return 'resare'
    else:
        raise ValueError
        
s = input()
sT = s[::-1]

flag = 'YES'
while sT:
    try:
        target = judger(sT[0:5])
        if target == sT[0: len(target)]:
            sT = sT[len(target):]
        else:
            flag = 'NO'
            break
    except ValueError:
        flag = 'NO'
        break

print(flag)

Submission status: Accepted

Solution code:
import re
S = input()
pattern = re.compile(r'^(dream|dreamer|erase|eraser)+$')
result = pattern.search(S)
if result:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
import re
s = input()

p = re.compile(r'^(dream|dreamer|erase|eraser)*(dream|dreamer|erase|eraser)$')
x = p.search(s)

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

Submission status: Accepted

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

def solve(S):
    s = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")

    if(s==""):
        print("YES")
    else:
        print("NO")
    
if __name__ == '__main__':
    S = input()
  
    solve(S)

Submission status: Accepted

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

Submission status: Accepted

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

s = "".join(S[-1::-1].split(l[0][-1::-1]))

for i in range(1, 4):
    s = "".join(s.split(l[i][-1::-1]))

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

Submission status: Accepted

Solution code:
s = list(input())

#str.reverse()も可能
s = "".join(s[::-1])
dream = "dream"
dream_r = "".join(dream[::-1])
dreamer = "dreamer"
dreamer_r = "".join(dreamer[::-1])
erase = "erase"
erase_r = "".join(erase[::-1])
eraser = "eraser"
eraser_r = "".join(eraser[::-1])



# 部分一致があるから、erのついている方を先にreplaceを用いて削除する
# replaceは元のstrを書き換えないので、sに代入してあげる必要がある
# dreamerの逆からreplaceすると、eraserの逆の頭の部分のreがdreamの逆とくっついて消えることがあったので順番は注意
s = s.replace(eraser_r, "")
s = s.replace(erase_r, "")
s = s.replace(dreamer_r, "")
s = s.replace(dream_r, "")



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

Submission status: Accepted

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

length = len(S)
i = 0

while i < length:
    if S[i:i+5] == 'dream'[::-1]:
        i += 5
    elif S[i:i+7] == 'dreamer'[::-1]:
        i += 7
    elif S[i:i+5] == 'erase'[::-1]:
        i += 5
    elif S[i:i+6] == 'eraser'[::-1]:
        i += 6
    else:
        print('NO')
        sys.exit()
    
print('YES')