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:
# -*- coding: utf-8 -*-
s = input()
t = ''
keywords = ['dream', 'erase', 'dreamer', 'eraser']

wk = ''
wk2 = ''
while (s != t):
  for keyword in keywords:
    wk = keyword + t
    if s == wk:
      t = wk
      break
    elif s.endswith(wk):
      t = wk
      break
  if wk2 == t:
    t = ''
    break
  wk2 = t

print('YES') if t != '' else print('NO')

Submission status: Accepted

Solution code:
s = input()

say = "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:
        say = "NO"
        break
    
print(say)

Submission status: Accepted

Solution code:
import sys
s=input()
l=[ "dream", "dreamer", "erase", "eraser" ]
while True:
    for i in l:
        if s.endswith(i):
            s=s[:-len(i)]
            #print(s)
            break
    else:
        if len(s) ==0:
            print("YES")
        else:
            print("NO")
        sys.exit()

Submission status: Accepted

Solution code:
N = list(input())
n = len(N)
N.reverse()
ans = 0

i = 0

while i < n:
    if N[i] == 'm':
        if N[i+1]=='a' and N[i+2]=='e' and N[i+3]=='r' and N[i+4]=='d':
            i += 5
            continue
        else:
            ans = 1
            break

    elif N[i] == 'e':
        if N[i+1]=='s' and N[i+2]=='a' and N[i+3]=='r' and N[i+4]=='e':
            i += 5
            continue
        else:
            ans = 1
            break

    elif N[i] == 'r':
        if N[i+1]=='e' and N[i+2]=='m':
            if N[i + 3] == 'a' and N[i + 4] == 'e' and N[i + 5] == 'r' and N[i + 6] == 'd':
                i += 7
                continue
            else:
                ans = 1
                break
        elif N[i+1]=='e' and N[i+2]=='s':
            if N[i + 3] == 'a' and N[i + 4] == 'r' and N[i + 5] == 'e':
                i += 6
                continue
            else:
                ans = 1
                break
        else:
            ans = 1
            break
    i += 1

if ans == 0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input()

S = S[::-1]

L = ['dream', 'dreamer', 'erase', 'eraser']
L = [[l[::-1], len(l)] for l in L]


can = True
ind = 0
S_max = len(S)

while can:
    
    if ind == S_max:
        break

    for l in L:
        if ind + l[1] > S_max:
            pass
        else:
            if l[0] == S[ind: ind+l[1]]:
                ind += l[1]
                break
    else:
        can = False

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

Submission status: Accepted

Solution code:
S = input()

S = S[::-1]

L = ['dream', 'dreamer', 'erase', 'eraser']
L = [l[::-1] for l in L]

can = True
ind = 0
S_max = len(S)

while can:
    
    # print(ind)
    if ind == S_max:
        break

    for l in L:
        if ind + len(l) > S_max:
            pass
        else:
    #        print(S[ind: ind+len(l)])
            if l == S[ind: ind+len(l)]:
                ind += len(l)
    #             print(1)
                break
    else:
    #     print(2)
        can = False

if can:
    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 = input()
T = ['dreamer', 'eraser', 'erase', 'dream']

ans = None

while S:
  n = len(S)
  found = False
  
  for t in T:
    x = len(t)
    if n >= x:
      s1 = S[-x:]
      if s1 == t:
        S = S[:-x]
        found = True
        break
  if not found:
    ans = "NO"
    break
    
if ans is None:
  ans = "YES"
print(ans)

Submission status: Accepted

Solution code:
import re

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

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    target = S
    while len(target) > 0:
        n = len(target)
        candidate1 = target[n-5:]
        candidate2 = target[n-6:]
        candidate3 = target[n-7:]
        if candidate1 == 'dream' or candidate1 == 'erase':
            target = target[:n-5]
        elif candidate2 == 'eraser':
            target = target[:n-6]
        elif candidate3 == 'dreamer':
            target = target[:n-7]
        else:
            return 'NO'
    return 'YES'


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

Solution code:
S = input()[::-1]
s1 = "dream"[::-1]
s2 = "dreamer"[::-1]
s3 = "erase"[::-1]
s4 = "eraser"[::-1]
index = 0
ret = False
while True:
    if S[index : index + len(s2) :] == s2:
        index += len(s2)
    elif S[index : index + len(s4) :] == s4:
        index += len(s4)
    elif S[index : index + len(s1) :] == s1 or S[index : index + len(s3) :] == s3:
        index += len(s1)
    else:
        break
    if index == len(S):
        ret = True
        break
print("YES" if ret else "NO")

Submission status: Accepted

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

s1 = 'dream'[::-1]
s2 = 'dreamer'[::-1]
s3 = 'erase'[::-1]
s4 = 'eraser'[::-1]

index = 0

while True:
    if S[index:index+len(s2):] == s2:
        index += len(s2)
    elif S[index:index+len(s4):] == s4:
        index += len(s4)
    elif S[index:index+len(s1):] == s1 or S[index:index+len(s3):] == s3:
        index += len(s1)
    else:
        break
    if index == len(S):
        break
if index == len(S):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s = input()

while(len(s)>0):
    flag = False
    if s.endswith("dream"):
        s = s[:-5]
        flag = True
    if s.endswith("dreamer"):
        s = s[:-7]
        flag = True
    if s.endswith("erase"):
        s = s[:-5]
        flag = True
    if s.endswith("eraser"):
        s = s[:-6]    
        flag = True
    if not(flag):
        break

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

Submission status: Accepted

Solution code:
dbflag=""

def debug(*args):
	if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
	if ""!=dbflag:return _INDATA.readline()
	else: return input()


result = -1

S = readline().rstrip()

import re
#pat = re.compile(pattern)
#pat.match(content)
ismatch = re.match(r'^(dream|dreamer|erase|eraser)*$',S)

if ismatch:
	result = "YES"
else:
	result = "NO"

print(result)

Submission status: Accepted

Solution code:
input_text = input()

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

while True:
  if input_text == "":
      print("YES")
      break
  for keyword in keywords:
    if input_text.endswith(keyword):
      input_text = input_text[:-len(keyword)]
      break
  else:
    print("NO")
    exit(0)

Submission status: Accepted

Solution code:
S=list(input())
n=len(S)

S.reverse()
putl=["dream","dreamer","erase","eraser"]
for i in range(4):
  tempstr=putl[i]
  putl[i]=tempstr[::-1]
#print(putl)
pos=0
can=True
while (pos < n):
  ifdivide=False
  for substr in putl:
    substr_size=len(substr)
    chk=S[pos:(pos+substr_size)]
    #print(chk)
    if chk==list(substr):
      ifdivide=True
      #print(chk)
      break
  if ifdivide:
    pos+=substr_size
  else:
    can=False
    break
if can:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
print("YNEOS"[bool(input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream",""))::2])

Submission status: Accepted

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

while True:
    if len(S) >= 7 and S[:7] =='remaerd':
        S = S[7:]
    elif len(S) >= 6 and S[:6] =='resare':
        S = S[6:]
    elif len(S) >= 5 and S[:5] =='maerd':
        S = S[5:]
    elif len(S) >= 5 and S[:5] =='esare':
        S = S[5:]
    else:
        print("NO")
        exit()
    if len(S) == 0:
        print("YES")
        exit()

Submission status: Accepted

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

t_t = []
for i in t:
    i = i[::-1]
    t_t.append(i)

s = s[::-1]

while s:
    if s[:len(t_t[0])] == t_t[0]:
        s = s[len(t_t[0]):]
    elif s[:len(t_t[1])] == t_t[1]:
        s = s[len(t_t[1]):]
    elif s[:len(t_t[2])] == t_t[2]:
        s = s[len(t_t[2]):]
    elif s[:len(t_t[3])] == t_t[3]:
        s = s[len(t_t[3]):]
    else:
        break
    if not s:
        ans = 'YES'

print(ans)

Submission status: Accepted

Solution code:
s = input()[::-1]
while True:
    end_flg = False
    if s[:5] == "maerd":
        s = s.replace("maerd", "", 1)
        end_flg = True
    elif s[:5] == "esare":
        s = s.replace("esare", "", 1)
        end_flg = True
    elif s[:7] == "remaerd":
        s = s.replace("remaerd", "", 1)
        end_flg = True
    elif s[:6] == "resare":
        s = s.replace("resare", "", 1)
        end_flg = True    

    if end_flg == False:
        break
        
if s == "":
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
re = ['dream','dreamer','erase','eraser']
devide = False

T = []

for l in range(len(S)):
    T.insert(0,S.pop(-1))
    if len(T) >= 5:
        if ''.join(T) in re:
            T = []
    if len(T) > 7:
        break

if T == []:
    devide = True

if devide == False:
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
from sys import stdin

s = stdin.readline().rstrip()

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:
# -*- coding: utf-8 -*-

import numpy
import scipy
#import sys


S = input()

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

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

Submission status: Accepted

Solution code:
import sys
s=input()
s=s[::-1]
l=list(["maerd","remaerd","esare","resare"])
i=0
while i < len(s):
  ok=0
  for j in l:
    if s[i:i+len(j)] == j:
      ok=1
      i += len(j)
      break
  if ok == 0:
    print("NO")
    sys.exit()
print("YES")

Submission status: Accepted

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

for i in a:
	s = s.replace(i, "")
if s == "":
	print ("YES")
else:
	print ("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
s.reverse()
judge=True
i=0
while i<=len(s)-5:
	box=[]
	for j in range(5):
		box+=s[i+j]
	if box==["m","a","e","r","d"] or box==["e","s","a","r","e"]:
		i+=5
		#print(box)
	else:
		box+=s[i+5]
		#print(box)
		if box==["r","e","s","a","r","e"]:
			i+=6
		else:
			box+=s[i+6]
			if box==["r","e","m","a","e","r","d"]:
				i+=7
			else:
				judge=False
				break
if judge:
	print("YES")
else:
	print("NO")

Submission status: Accepted

Solution code:
S = str(input())

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

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

k = 0
suc = True
while k < len(S):
    suc2 = False
    for t in tlist:
        if S[k:k+len(t)] == t:
            suc2 = True
            k += len(t)
    if not suc2:
        suc = False
        break

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

Submission status: Accepted

Solution code:
s=input()
i=0 #文字の判定
while i==0:
  if len(s)==0:
    print("YES")
    exit()

  if s[0:5]=="dream":
    if s[0:7]=="dreamer":
      if s[5:11]=="eraser":
        s=s[11:]
      elif s[5:10]=="erase":
        s=s[10:]
      else:
        s=s[7:]
    else:
      s=s[5:]
  elif s[0:5]=="erase":
    if s[0:6]=="eraser":
      s=s[6:]
    else:
      s=s[5:]
  else:
    i+=1
print("NO")

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 = s[::-1]
wards = ["maerd","remaerd","esare","resare"]
can = True
while can:
    can = False
    for i in wards:
        if s.startswith(i):
            s = s.replace(i,"",1)
            can = True
if s == "":
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S=input()
datas=["dream","dreamer","erase","eraser"]
stack=[]
stack.append(0)
while stack:
  index=stack.pop()
  if index==len(S):
    print("YES")
    break
  for data in datas:
    if index+len(data)>len(S):
      continue
    if S[index:index+len(data)]==data:
      stack.append(index+len(data))
else:
  print("NO")

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
T = ''
U = ['maerd', 'remaerd', 'esare', 'resare']
while True:
    S1 = S[:5]
    S2 = S[:6]
    S3 = S[:7]
    if S1 == U[0] or S1 == U[2]:
        S = S[5:]
    elif S2 == U[3]:
        S = S[6:]
    elif S3 == U[1]:
        S = S[7:]
    else:
        print('NO')
        exit()
    if S == '':
        print('YES')
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
T = ''
count = len(S)
while True:
    if S[0:count].rfind('dream') == count-5 and count-5 != -1:
        T = 'dream' + T
        count = count - 5
    elif S[0:count].rfind('dreamer') == count-7 and count-7 != -1:
        T = 'dreamer' + T
        count = count - 7
    elif S[0:count].rfind('erase') == count-5 and count-5 != -1:
        T = 'erase' + T
        count = count - 5
    elif S[0:count].rfind('eraser') == count-6 and count-6 != -1:
        T = 'eraser' + T
        count = count - 6
    else:
        break
if S == T:
    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:
s = str(input())[::-1]

while(len(s) >= 5):
    if s[:5] == 'maerd':
        s = s.replace('maerd', '', 1)
    elif s[:7] == 'remaerd':
        s = s.replace('remaerd', '', 1)
    elif s[:5] == 'esare':
        s = s.replace('esare', '', 1)
    elif s[:6] == 'resare':
        s = s.replace('resare', '', 1)
    else:
        print('NO')
        exit()

else:
    print('YES')

Submission status: Accepted

Solution code:
S = input()[::-1]
while len(S) != 0:
    if S[:5] == "maerd":
        S = S.replace("maerd", "", 1)
    elif S[:5] == "esare":
        S = S.replace("esare", "", 1)
    elif S[:7] == "remaerd":
        S = S.replace("remaerd", "", 1)
    elif S[:6] == "resare":
        S = S.replace("resare", "", 1)
    else:
        print("NO")
        break
else:
    print("YES")

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()
rev_s = list(reversed(s))
temp=''
for i in rev_s:
    if(temp==''):
        temp=i
    else:
        temp+=i
    if(temp=='maerd' or temp=='remaerd' or temp=='esare' or temp=='resare'):
        temp=''
if(temp==''):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s = input()
while len(s) != 0:
    if s[:5] == "dream":
        # s[5:7]がerであったら分岐
        if s[5:7] == "er":
            # dreameraseの場合 -> dreamとして認識
            if s[5:10] == "erase":
                s = s[5:]
            # dreamerXXXXX(dreamerdream, dreamererase, dreamereraser)の場合 -> dreamerとして認識
            else:
                s = s[7:]
        else:
            s = s[5:]
    elif (s[:5] == "erase")&(s[:6] != "eraser"):
        s = s[5:]
    elif s[:6] == "eraser":
        s = s[6:]
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
S = input()

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

find_flag = 0
rest_S = S
while True:
#     print(rest_S[-5:], rest_S[-7:]) 
    if len(rest_S) == 0:
        find_flag = 1
        break
    elif (len(rest_S) >= 7) & (rest_S[-7:] in candidates):
        rest_S = rest_S[:-7]
    elif (len(rest_S) >= 6) & (rest_S[-6:] in candidates):
        rest_S = rest_S[:-6]
    elif (len(rest_S) >= 5) & (rest_S[-5:] in candidates):
        rest_S = rest_S[:-5]
    else:
        break

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

Submission status: Accepted

Solution code:
import re

s = input()
s = re.sub('eraser', '', s)
s = re.sub('erase', '', s)
s = re.sub('dreamer', '', s)
s = re.sub('dream', '', s)
print('YES' if len(s) == 0 else 'NO')

Submission status: Accepted

Solution code:
S = input()
while True:
    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
    break

print('YES' if not S else 'NO')

Submission status: Accepted

Solution code:
s = input()

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

while True:
    flag = False
    for _e in e:
        if s[-len(_e):] == _e or s == _e:
            s = s[:len(s)-len(_e)]
            flag = True
    else:
        if flag:
            continue

        break

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

Submission status: Accepted

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

while True:
    S_len=len(S)
    if S_len<5:
        break
    else:
        for i in Word:
            S = S.replace(i,"")
        if len(S)==S_len: #一つも文字が消えなかった時break
            break
           
if len(S)==0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input()[::-1]
 
T = ['dream'[::-1],'dreamer'[::-1],'erase'[::-1],'eraser'[::-1]]
size = 0

while size < len(S):
	if S[size:size+5] == T[0] or S[size:size+5] == T[2]:
		size += 5
	elif S[size:size+6] == T[3]:
		size += 6
	elif S[size:size+7] == T[1]:
		size += 7
	else :
		print('NO')
		exit()
print('YES')

Submission status: Accepted

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

while cursor:
    if S[cursor - 5: cursor] in ['dream', 'erase']:
        cursor -= 5
        continue
    elif S[cursor - 6: cursor] in ['eraser']:
        cursor -= 6
        continue
    elif S[cursor - 7: cursor] in ['dreamer']:
        cursor -= 7
    else:
        break

if cursor == 0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
strings = ['dream', 'dreamer', 'erase', 'eraser']

reverse_candidates = [s[::-1] for s in strings]
# ['maerd', 'remaerd', 'esare', 'resare']
S = str(input())[::-1]

pointa = 0
while pointa != len(S):
    if S[pointa:pointa+5] in ('maerd', 'esare'):
        pointa += 5
    elif S[pointa:pointa+6] in ('resare'):
        pointa += 6
    elif S[pointa:pointa+7] in ('remaerd'):
        pointa += 7
    else:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

Solution code:
s = input()

ans = 1
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:
        s = ""
        ans = 0
if ans > 0:
    print("YES")
else:    
    print("NO")

Submission status: Accepted

Solution code:
S = str(input())
pntr = 0
flg = 1


while pntr <= len(S) - 1:
	if S[pntr] == "d":
		if pntr + 7 <= len(S) - 1 and S[pntr + 7] == "a":
			if S[pntr : pntr + 5] == "dream":
				pntr += 5
			else:
				flg = 0
				break
		elif pntr + 6 <= len(S) - 1 and S[pntr : pntr + 7] == "dreamer":
			pntr += 7
		elif pntr + 4 <= len(S) - 1 and S[pntr : pntr + 5] == "dream":
			pntr += 5
		else:
			flg = 0
			break
			
	elif S[pntr] == "e":
		if pntr + 5 <= len(S) - 1 and S[pntr : pntr + 6] == "eraser":
			pntr += 6
			# print("eraser")
		elif pntr + 4 <= len(S) - 1 and S[pntr : pntr + 5] == "erase":
			pntr += 5
			# print("erase")
		else:
			flg = 0
			break
	else:
		flg = 0
		break
		
if flg:
	print("YES")
else:
	print("NO")

Submission status: Accepted

Solution code:
# Me
def check(s):
    words = [
            'dream',
            'dreamer',
            'erase',
            'eraser',
            ]

    while len(s) != 0:
        flag = False
        for w in words:
            if s[-len(w):] == w:
                s = s[:-len(w)]
                flag = True
                break
        if not flag:
            return 'NO'
    return 'YES'


print(check(input()))

Submission status: Accepted

Solution code:
# Me
def check(s):
    words = [
            'dream',
            'dreamer',
            'erase',
            'eraser',
            ]

    while len(s) != 0:
        flag = False
        for w in words:
            if s[-len(w):] == w:
                s = s[:-len(w)]
                flag = True
                break
        if not flag:
            return 'NO'
    return 'YES'


print(check(input()))

Submission status: Accepted

Solution code:
def check(s):
    s = s.replace('eraser', '')
    s = s.replace('erase', '')
    s = s.replace('dreamer', '')
    s = s.replace('dream', '')
    if len(s) != 0:
        return 'NO'
    return 'YES'


print(check(input()))

Submission status: Accepted

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

Submission status: Accepted

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

words = ("dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1])

index = 0

while True:
    flag = False
    for word in words:
        if S[index:index + len(word)] == word:
            index += len(word)
            flag = True

    if index == len(S):
        print("YES")
        exit()

    if flag is False:
        break

print("NO")

Submission status: Accepted

Solution code:
S = input()

s_i = 0
flag = True
while s_i < len(S) and flag:
    
    if S[s_i:s_i+7] == 'dreamer' and S[s_i:s_i+10]  != 'dreamerase':
        s_i += 7
    elif S[s_i:s_i+5] == 'dream':
        s_i += 5
    elif S[s_i:s_i+6] == 'eraser':
        s_i += 6
    elif S[s_i:s_i+5] == 'erase':
        s_i += 5
    else:
        flag = False
if flag:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input()[::-1]
W = []
for w in ['dreamer', 'eraser', 'erase', 'dream']:
    W.append(w[::-1])
idx = 0
while 1:
    flg = False
    for w in W:
        if S.startswith(w, idx):
            idx += len(w)
            flg = True

    if not flg:
        print('NO')
        exit()
    if len(S) <= idx:
        break

print('YES')

Submission status: Accepted

Solution code:
S = input()[::-1]
W = []
for w in ['dreamer', 'eraser', 'erase', 'dream']:
    W.append(w[::-1])
while 1:
    flg = False
    for w in W:
        if S.startswith(w):
            S = S[len(w):]
            flg = True

    if not flg:
        print('NO')
        exit()
    if not S:
        break

print('YES')

Submission status: Accepted

Solution code:
def solve():
    S = input()
    # print(S, len(S))

    S = S[::-1]
    words = ("dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1])

    i = 0
    while True:
        can = False
        for word in words:
            if S[i:i + len(word)] == word:
                i += len(word)
                can = True

        if i == len(S):
            return True

        if can is False:
            return False


if __name__ == '__main__':
    res = solve()
    if res:
        print("YES")
    else:
        print("NO")

Submission status: Accepted

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

def solve():
    S = input()
    # print(S, len(S))

    S = S[::-1]
    words = ("dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1])

    def recur(i):
        if i >= len(S):
            return True

        for word in words:
            if S[i:i + len(word)] == word:
                if recur(i + len(word)):
                    return True
        return False

    ans = recur(0)

    return ans


if __name__ == '__main__':
    res = solve()
    if res:
        print("YES")
    else:
        print("NO")

Submission status: Accepted

Solution code:
def main():
    S = input()
    w1 = 'dream'[::-1]
    w2 = 'dreamer'[::-1]
    w3 = 'erase'[::-1]
    w4 = 'eraser'[::-1]
    S = S[::-1]
    words = [w1, w2, w3, w4]

    i = 0
    while i != len(S):
        for w in words:
            if S[i:].startswith(w):
                i += len(w)
                break
        else:
            print("NO")
            exit()

    print("YES")



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    S = input()
    w1 = 'dream'[::-1]
    w2 = 'dreamer'[::-1]
    w3 = 'erase'[::-1]
    w4 = 'eraser'[::-1]
    S = S[::-1]
    words = [w1, w2, w3, w4]

    flag = False
    i = 0
    while i != len(S):
        for w in words:
            if S[i:].startswith(w):
                i += len(w)
                flag = True
                break

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

    print("YES")



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    S = input()
    w1 = 'dream'[::-1]
    w2 = 'dreamer'[::-1]
    w3 = 'erase'[::-1]
    w4 = 'eraser'[::-1]
    S = S[::-1]
    words = [w1, w2, w3, w4]

    flag = False
    i = 0
    while i < len(S):
        for w in words:
            if S[i:].startswith(w):
                i += len(w)
                flag = True
                break

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

    print("YES")



if __name__ == "__main__":
    main()

Submission status: Accepted

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

i=0
while i < lenS:
  if S[i:i+5] =='dream':
    i+=5
    if S[i:i+2] == 'er' and S[i:i+5] != 'erase':i+=2
  elif S[i:i+6] == 'eraser': i+=6
  elif S[i:i+5] == 'erase': i+=5
  else:
    print('NO')
    exit()
print('YES')

Submission status: Accepted

Solution code:
def main():
    S = input()
    w1 = 'dream'[::-1]
    w2 = 'dreamer'[::-1]
    w3 = 'erase'[::-1]
    w4 = 'eraser'[::-1]
    # print(w1,w2,w3,w4)
    S = S[::-1]
    # print(S)

    # words = ['dream', 'dreamer', 'erase', 'eraser']
    words = [w1, w2, w3, w4]
    T = ''
    while S != T:
        cand = []
        for w in words:
            new_t = T + w
            cand.append(new_t) 
        # print('cand', cand)
        ans = False
        for c in cand:
            if c == S[:len(c)]:
                T = c
                ans = True

        if not ans:
            break

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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


def solve():
    S = input()
    # print(S, len(S))

    words = {0: "dream", 1: "dreamer", 2: "erase", 3: "eraser"}

    TABLE = [[-1 for x in range(len(S) + 1)] for y in range(len(words) + 1)]

    def recur(i, w):
        if not TABLE[w][i] == -1:
            return TABLE[w][i]

        if i >= len(S):
            # print("jey", log)
            return True

        r1, r2, r3, r4 = False, False, False, False
        if S[i:i + 5] == words[0]:
            r1 = recur(i + 5, 0)
        if S[i:i + 7] == words[1]:
            r2 = recur(i + 7, 1)
        if S[i:i + 5] == words[2]:
            r3 = recur(i + 5, 2)
        if S[i:i + 6] == words[3]:
            r4 = recur(i + 6, 3)

        TABLE[w][i] = r1 or r2 or r3 or r4 or False

        return TABLE[w][i]

    ans = recur(0, 0)

    return ans


if __name__ == '__main__':
    res = solve()
    if res:
        print("YES")
    else:
        print("NO")

Submission status: Accepted

Solution code:
#dreamerを消した時にerが消えてしまわないように、先にeraserから消す。
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
#全部消し切れてなければNo
if s:
    print("NO")
else:
    print("YES")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
T = input()
S = ''
p,q,r,s = 'maerd','esare','remaerd','resare'
for i in range(len(T)):
    S += T[len(T)-i-1]
while len(S) >= 5:
    x = S[:5]
    y = S[:6]
    z = S[:7]
    if x == p or x == q:
        if len(S) > 5:
            S = S[5:]
        else:
            S = ''
    elif y == s:
        if len(S) > 6:
            S = S[6:]
        else:
            S = ''
    elif z == r:
        if len(S) > 7:
            S = S[7:]
        else:
            S = ''
    else:
        break
ans = 'NO'
if len(S) == 0:
    ans = 'YES'
print(ans)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
#後ろから見たら一意
"""
tryブロックでsys.exit()を呼ぶと強制終了しない。
"""
import sys
i = l-1
try:
    while i>-1:
        if s[i]=="r":
            if s[i-5:i+1]=="eraser":
                i-=6
            elif s[i-6:i+1]=="dreamer":
                i-=7
            else:
                print("NO")###
                sys.exit()
        else:
            if s[i-4:i+1]=="erase":
                i-=5
            elif s[i-4:i+1]=="dream":
                i -= 5
            else:
                print("NO")###
                sys.exit()
    print("YES")
except:
    pass