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:
words = ["dream", "dreamer", "erase", "eraser"]
            #5      #7          #5      #6
s = input()

while len(s) > 0:
    if s[-5:] in words:
        s = s[:-5]
    elif s[-6:] in words:
        s = s[:-6]
    elif s[-7:] in words:
        s = s[:-7]
    else:
        print("NO")
        exit()

print("YES")

Submission status: Accepted

Solution code:
s = input()

#reverse str
s = s[::-1]

#print(s)

comp_eraser = "eraser"
comp_dreamer = "dreamer"
comp_erase = "erase"
comp_dream = "dream"

#reverse
comp_eraser = comp_eraser[::-1] 
comp_dreamer = comp_dreamer[::-1]
comp_erase = comp_erase[::-1] 
comp_dream = comp_dream[::-1]

#print(comp_eraser)

while len(s)>0:
  
  if s.find(comp_eraser) == 0:
    s=s[len(comp_eraser):]
#    print(s,"eraser")
  elif s.find(comp_dreamer) == 0:
#    print(s,"dreamer")
    s=s[len(comp_dreamer):]
  elif s.find(comp_erase) == 0:
#    print(s,"erase")
    s=s[len(comp_erase):]
  elif s.find(comp_dream) == 0:
#    print(s,"dream")
    s=s[len(comp_dream):]
  else:
    print("NO")
    break

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

Submission status: Accepted

Solution code:
s = str(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:
dr ="dream" 
dre = "dreamer" 
er ="erase" 
ere = "eraser" 
a = input()
ret = "YES"
while len(a) != 0:
    if (a.endswith(dr) or a.endswith(er)):
        a = a[:len(a)-5]
    elif(a.endswith(dre)):
        a = a[:len(a)-7]
    elif(a.endswith(ere)):
        a = a[:len(a)-6]
    else:
        ret = "NO"
        break
        
print(ret)

Submission status: Accepted

Solution code:
s=input()+'#'
n=len(s)
i=0
while i<n:
  if s[i]=='#':
    i=n
  elif 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
  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_ == '':
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
t=input()

def right(text):
  li=["dream","dreamer","erase","eraser"]
  for te in li:
    if text[-len(te):] == te:
      return text[:len(text)-len(te)]
  return text

flag=True
while flag:
  temp=right(t)
  if not temp:
    print("YES")
    break
  elif temp==t:
    print("NO")
    break
  t=temp

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()
s = s[-1::-1]
word = ['resare','esare','remaerd','maerd',]
for i in word:
    s = s.replace(i,'')
if s:
    print('NO')
else:
    print('YES')

Submission status: Accepted

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

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:
T=[]
S=input()
Sr=list(reversed(S))
w1=list(reversed('dream'))
w2=list(reversed('dreamer'))
w3=list(reversed('erase'))
w4=list(reversed('eraser'))

while True:
    if Sr[:5]==w1:
        del(Sr[:5])
    elif Sr[:5]==w3:
        del(Sr[:5])
    elif Sr[:6]==w4:
        del(Sr[:6])
    elif Sr[:7]==w2:
        del(Sr[:7])
    else:
        break
if Sr==T:
    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:
def main():
    s=input()
    while len(s)>0:
        if s[-5:]=='dream':
            s=s[:-5]
        elif s[-7:]=='dreamer':
            s=s[:-7]
        elif s[-5:]=='erase':
            s=s[:-5]
        elif s[-6:]=='eraser':
            s=s[:-6]
        else:
            print('NO')
            exit()
    print('YES')
main()

Submission status: Accepted

Solution code:
S=str(input())
'dream' 'dreamer' 'erase' 'eraser'
hantei=True
while S:
  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:
    hantei=False
    break
print('YES' if hantei else 'NO')

Submission status: Accepted

Solution code:
T = input()

S = T[::-1]
i = 0
while i <= len(S) - 1:
    if S[i] == "r":
        if S[i:i+7] == "remaerd":
            i += 7
        elif S[i:i+6] == "resare":
            i += 6
        else:
            print("NO")
            exit()
    elif S[i] == "m":
        if S[i:i+5] == "maerd":
            i += 5
        else:
            print("NO")
            exit()
    elif S[i] == "e":
        if S[i:i+5] == "esare":
            i += 5
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
import re

regex = r'(dream|dreamer|erase|eraser)+$'

s = input()

if re.match(regex, s):
  print("YES")
else:
  print("NO")

Submission status: Accepted

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

lenT = [len(i) for i in T]
Trev = [t[::-1] for t in T]

i = 0
while i < len(S):
    for j, t in enumerate(Trev):
        if Srev[i:i+lenT[j]] == t:
            i += lenT[j]     #; print(i, j, t) 
            break
    else:
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = list(input())
t = ['dream','dreamer','erase','eraser']
ans = 0
for i in range(100000):
    check = 0
    #print(s)
    for j in t:
        #print(str(s[-1 * (len(j)):]),list(j))
        if s[-1 * (len(j)):] == list(j):
            del s[-1 * (len(j)):]
            check = 1
            break
    if len(s) == 0:
        ans = 1
        break
if ans == 1:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)

S = input()

T = ['dream', 'dreamer', 'erase', 'eraser']
lenT = [len(i) for i in T]

def dayDream(pin):
    global isGoal               #;print('dayDream: ', pin, S[pin:])
    for i, d in enumerate(T):
        if isGoal:
            return
        #print('i, d:', i, d)
        if S[pin:pin+lenT[i]] == d:            
            pout = pin + lenT[i] #;print(d, pout)
            if pout == len(S):                
                isGoal = True    #;print('YES')
                return 
            else:
                dayDream(pout)
    #print('dayDream return', pin)
    return
    
isGoal = False
dayDream(0)
if isGoal:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)

S = input()

T = ['dream', 'dreamer', 'erase', 'eraser']
lenT = [len(i) for i in T]

def dayDream(pin):
    global isDream               #;print('dayDream: ', pin, S[pin:])
    for i, d in enumerate(T):
        #print('d:', d)
        if S[pin:pin+lenT[i]] == d:            
            pout = pin + lenT[i] #; print(d, pout)
            if pout == len(S):                
                isDream = True   #; print('YES')
                return 
            else:
                dayDream(pout)
    #print('dayDream return', pin)
    return
    
isDream = False
dayDream(0)
if isDream:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
str = input()

str = str[::-1]

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

for i in range(4):
    str_list[i] = str_list[i][::-1]

result = "YES"

while len(str) >= 5:
    if str[:5] == str_list[0]:
        str = str[5:]
    elif str[:7] == str_list[1]:
        str = str[7:]
    elif str[:5] == str_list[2]:
        str = str[5:]
    elif str[:6] == str_list[3]:
        str = str[6:]
    else:
        result = "NO"
        break

if len(str) != 0:
    result = "NO"

print(result)

Submission status: Accepted

Solution code:
s = input()

while s:
   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')
      import sys
      sys.exit()

print('YES')

Submission status: Accepted

Solution code:

S = input()

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

while(S):

    if index > len(S):
        print("NO")
        break

    if S[-index:] in words:

        S = S[:-index]
        index = 1
        continue

    index += 1

if not S:
    print("YES")

Submission status: Accepted

Solution code:
S = input()
p = 0
while p == 0 and S != '':
  n = len(S)
  q = 0
  q5, q6, q7 = 0, 0, 0
  if n >= 5:
    if S[n-5:n] == 'dream' or S[n-5:n] == 'erase':
      q, q5 = 1, 1
  if n >= 6:
    if S[n-6:n] == 'eraser':
      q, q6 = 1, 1
  if n >= 7:
    if S[n-7:n] == 'dreamer':
      q, q7 = 1, 1
  if q5 == 1:
    S = S[:n-5]
  elif q6 == 1:
    S = S[:n-6]
  elif q7 == 1:
    S = S[:n-7]
  if q == 0:
    p += 1
    break
if p == 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()
word = ["dream","dreamer","erase","eraser"]

S = S[::-1] #入力文字を反転
for i in range(len(word)): word[i] = word[i][::-1] #4つのワードを反転

while True:
    for i in range(len(word)):
        flag2 = False
        if word[i] == S[:len(word[i])]:
            flag2 = True
            S = S[len(word[i]):]
            break
    if S == "":
        print("YES")
        break #全て一致して空文字になる
    elif flag2 == False:
        print("NO")
        break #一致しなかったとき

Submission status: Accepted

Solution code:
s = input()
s_origin = s
t = ""
word_list = ["dream", "dreamer", "erase", "eraser"]
while True:
    flag = True
    if len(s) <= 4:
        break

    if len(s) == 5:
        s_child_1 = s[-5:]
        if s_child_1 in word_list:
            t = s[-5:] + t
            s = s[:-5]
        break
    
    if len(s) == 6:
        s_child_1 = s[-6:]
        if s_child_1 in word_list:
            t = s[-6:] + t
            s = s[:-6]
        break

    s_child_2 = s[-7:]
    if s_child_2 in word_list:
        t = s[-7:] + t
        s = s[:-7]
        flag = False

    s_child_1 = s[-6:]
    if s_child_1 in word_list:
        t = s[-6:] + t
        s = s[:-6]
        flag = False

    s_child_1 = s[-5:]
    if s_child_1 in word_list:
        t = s[-5:] + t
        s = s[:-5]
        flag = False
    
    if flag:
        break

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

Submission status: Accepted

Solution code:
S = input()
# dream + eraser なのに dreamer を消さないように
# 先に dreamerase(r)を消しておく
# S = S.replace("dreameraser", "") #３回めの提出時に削除
# S = S.replace("dreamerase", "") #３回めの提出時に削除
# S = S.replace("dreamer", "") # ２回めの提出時にeraseの後ろへ
# S = S.replace("dream", "") # ２回めの提出時にeraseの後ろへ
# eraserより先にdreamerを消すとWAになりました
# dreameraserのパターンは消去済みなのに、なんでだろ
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()
s = s[::-1]
counter = 0

while counter <= len(s):
    if s[counter:counter+5] == "maerd":
        counter += 5
    elif s[counter:counter+5] == "esare":
        counter += 5
    elif s[counter:counter+7] == "remaerd":
        counter += 7
    elif s[counter:counter+6] == "resare":
        counter += 6
    else:
        break
if len(s) == counter:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = input()[::-1]
len_s = len(s)
start, end = 0,5
ans = "YES"
while end <= len_s:
  if s[start:end] == "maerd" or s[start:end] == "esare":
    start += 5
    end += 5
  elif s[start:end+1] == "resare":
    start += 6
    end += 6
  elif s[start:end+2] == "remaerd":
    start += 7
    end += 7
  else:
    ans = "NO"
    break
print(ans)

Submission status: Accepted

Solution code:
s=input()[::-1]
for i in range(10**5):
  if s[:5]=="maerd":
    s=s[5:]
  elif s[:7]=="remaerd":
    s=s[7:]
  elif s[:5]=="esare":
    s=s[5:]
  elif s[:6]=="resare":
    s=s[6:]
  elif s=="":
    print("YES")
    break
  else:
    print("NO")
    break

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 = list(input())[::-1]

c = 0

r = "YES"

while c < len(s):
    try:
        if s[c:c + 6] == list('eraser')[::-1]:
            c += 6
        elif s[c:c + 7] == list('dreamer')[::-1]:
            c += 7
        elif s[c:c + 5] == list('dream')[::-1] or s[c:c + 5] == list('erase')[::-1]:
            c += 5
        else:
            r = "NO"
            break
    except IndexError:
        r = "NO"
        break

print(r)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S = input()
ans = 'YES'
while len(S) > 0:
  if S[-7:] == 'dreamer':
    S = S[:-7]
  elif S[-6:] == 'eraser':
    S = S[:-6]
  elif S[-5:] == 'dream':
    S = S[:-5]
  elif S[-5:] == 'erase':
    S = S[:-5]
  else:
    ans = 'NO'
    break
print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python

S = input()
S_copy = S
T = []
words = ['dream', 'dreamer', 'erase', 'eraser']

while True:
    match = False
    word_matched = ''
    # check if S_copy ends with word in words
    for word in words:
        if S_copy.endswith(word):
            match = True
            # print('S_copy is', f'{S_copy}')
            # print('ends with', f'{word}')
            if len(word) > len(word_matched):
                # print('this word is longer than previous word_matched')
                # print('word:', f'{word}')
                # print('previous word_matched:', f'{word_matched}')
                word_matched = word

    if match:
        T.insert(0, word_matched)
        # ends with dreamer
        # erasedreamer => erase
        S_copy = S_copy[:-len(word_matched)]
    else:
        break

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

Submission status: Accepted

Solution code:
s = list(input())
t = ''
cnt = len(s) - 1
while cnt >= 0:
    if s[cnt] == 'm':
        t = 'dream' + t
        cnt -= 5
        continue
    if s[cnt] == 'e':
        t = 'erase' + t
        cnt -= 5
        continue
    if s[cnt] == 'r':
        if cnt - 2 >= 0 and s[cnt - 2] == 'm':
            t = 'dreamer' + t
            cnt -= 7
            continue
        elif cnt - 2 >= 0 and s[cnt - 2] == 's':
            t = 'eraser' + t
            cnt -= 6
            continue
    break
s = ''.join(s)
if s == t:
    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:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

s=input()
s=s[::-1]
n=len(s)
i=0
while i<n:
    if s[i:i+5]=="esare":i+=5
    elif s[i:i+6]=="resare":i+=6
    elif s[i:i+5]=="maerd":i+=5
    elif s[i:i+7]=="remaerd":i+=7
    else:
        print("NO")
        exit()
else:
    print("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:
s = input()
s = s[::-1]
t_list = ['dream','dreamer','erase','eraser']
t_list = [t[::-1] for t in t_list]
 
ans = 'NO'
i = 0
while i < len(s):  
  p = i
  for t in t_list:        
    if s[i:i+len(t)] == t:      
      i += len(t)
      if i == len(s):
        ans ='YES'
      break
  if p==i or ans=='YES':
    break
 
print(ans)

Submission status: Accepted

Solution code:
s = input()
i = 0
while True:
	if i == len(s):
		print('YES')
		break
	if len(s) - i < 5:
		print('NO')
		break
	if s[i] == 'd':
		if s[i:i+5] != 'dream':
			print('NO')
			break
		if len(s) - i < 7:
			i += 5
			continue
		if s[i:i+7] != 'dreamer':
			i += 5
			continue
		if len(s) - i == 7 or s[i+7] != 'a':
			i += 7
			continue
		i += 5
		continue
	if s[i] == 'e':
		if s[i:i+5] != 'erase':
			print('NO')
			break
		if len(s) - i < 6:
			i += 5
			continue
		if s[i:i+6] != 'eraser':
			i += 5
			continue
		if len(s) - i == 6 or s[i+6] != 'a':
			i += 6
			continue
		i += 5
		continue
	print('NO')
	break

Submission status: Accepted

Solution code:
s = input()
s = s[-1::-1]
pattern_list = ["dream"[-1::-1],"dreamer"[-1::-1],"erase"[-1::-1],"eraser"[-1::-1]]
flg = True
ret = "YES"
while flg:
    bad_loop = True
    for pattern in pattern_list:
        if s==pattern:
            flg=False
            bad_loop = False
        elif s.startswith(pattern):
            s = s[len(pattern)::]
            bad_loop = False
    if bad_loop:
        ret="NO"
        flg=False
print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

f = 0
while f == 0:  
  f = 1
  for w in words:
    if sr[0:len(w)] == w:
      sr = sr[len(w):]
      f = 0
  
if sr =='':
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:

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

ans = 'NO'
i = 0
while i < len(s):  
  p = i
  for w in words_r:        
    if s[i:i+len(w)] == w:      
      i += len(w)
      if i == len(s):
        ans ='YES'
      break
  if p==i or ans=='YES':
    break

print(ans)

Submission status: Accepted

Solution code:


S = input()
s = ""
for i in range(1, len(S) + 1):
    s += S[-i]


words = ["resare", "esare", "remaerd", "maerd"]

l = 0
while l < len(S):
    result = False
    for word in words:
        
        if s[l:l+len(word)] == word:
            result = True
            break
    if result:
        l += len(word)
    else:print("NO");exit()
print("YES")

Submission status: Accepted

Solution code:
S = input()
sr = ''
for i in S:
    sr = i + sr
lista = ['remaerd','resare','esare','maerd']
c = 0
while c == 0:
    c = 1
    for i in lista:
        
        if sr[0:len(i)] == i:
            sr = sr[len(i):]
            c = 0

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

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]
i = 0
while i < len(s):
  if s[i:i+5] in ['maerd','esare']:
    i += 5
  elif s[i:i+6] == 'resare':
    i += 6
  elif s[i:i+7] == 'remaerd':
    i += 7
  else:
    print('NO')
    exit()
print('YES')

Submission status: Accepted

Solution code:
import sys

s = sys.stdin.readline().rstrip()

def main():
    t = s
    cands = 'eraser, erase, dreamer, dream'.split(', ')
    for c in cands:
        t = t.replace(c, '')
    
    return 'YES' if not t else 'NO'

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

Submission status: Accepted

Solution code:
s = input()

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

for i in range(len(s) + 1):
    # check s[:i]
    if i >= 5 and s[i-5:i] == 'dream' and dp[i-5]:
        dp[i] = 1
    if i >= 7 and s[i-7:i] == 'dreamer' and dp[i-7]:
        dp[i] = 1
    if i >= 5 and s[i-5:i] == 'erase' and dp[i-5]:
        dp[i] = 1
    if i >= 6 and s[i-6:i] == 'eraser' and dp[i-6]:
        dp[i] = 1
if dp[-1]:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = list(input())
S.reverse()
S = "".join(S)
ans = "YES"
while len(S) > 0:
        if S[:5] == "maerd" or S[:5] == "esare":
                S = S[5:]
        elif S[:6] == "resare":
                S = S[6:]
        elif S[:7] == "remaerd":
                S = S[7:]
        else:
                ans = "NO"
                break
print(ans)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

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

S = input().rstrip()
S = S[::-1]
#print(S)

cur = 0
while cur < len(S):
	#print(cur, S[cur:])
	for t in T:
		#print(S[cur:cur+len(t)], t[::-1])
		if S[cur:cur+len(t)] == t[::-1]:
			cur += len(t)
			break
	else:
		print('NO')
		break
else:
	print('YES')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

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

# dream dreamer erase eraser
def solve(S: str):
    hoge = S.replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')
    print(NO if hoge else YES)
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
s = input()

#for i in range(len(s)):
# print(s[len(s)-7:len(s)])

while len(s) > 0:
    sevenLast = s[len(s)-7:len(s)]
    sixLast = s[len(s)-6:len(s)]
    fiveLast = s[len(s)-5:len(s)]

    if sevenLast == 'dreamer':
        s = s[:len(s)-7]
    elif sixLast == 'eraser':
        s = s[:len(s)-6]
    elif fiveLast == 'dream':
        s = s[:len(s)-5]
    elif fiveLast == 'erase':
        s = s[:len(s)-5]
    else:
        print('NO')
        sys.exit()

print('YES')

Submission status: Accepted

Solution code:
import re
pat = r'(dream|dreamer|erase|eraser)+$'

s = input()
if re.match(pat, s):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import sys


def judge(s):
    if s[:6] == t4:
        s2 = s[6:]
    elif s[:5] == t1 or s[:5] == t3:
        s2 = s[5:]
    elif s[:7] == t2:
        s2 = s[7:]
    else:
        s2 = "AAAAA"
    return s2


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

t1 = "maerd"
t2 = "remaerd"
t3 = "esare"
t4 = "resare"

for i in range(100000):
    length = len(s)
    if length == 5 or length == 6 or length == 7:
        if s == t1 or s == t2 or s == t3 or s == t4:
            print("YES")
            sys.exit()
        else:
            print("NO")
            sys.exit()

    ss = judge(s)
    if 0 == len(ss):
        print("YES")
        sys.exit()
    s = ss

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

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

flag = True
while(len(s) > 0):
  if s[-7:] == word[1]:
    s = s[:-7]
  elif s[-6:] == word[3]:
    s = s[:-6]
  elif s[-5:] == word[0] or s[-5:] == word[2]:
    s = s[:-5]
  else:
    flag = False
    break
  
if flag:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

S = one_str()

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

flg=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" or S[-5:] =="erase":
        S = S[:-5]
        continue
    
    flg = False
    break


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

Submission status: Accepted

Solution code:
S = input()[::-1]
A = ["maerd","remaerd","esare","resare"]
def HIT(ST,A):
  for i in A:
    if ST[:len(i)]==i:
      return ST[len(i):]
    else:
      continue
  return ST
for j in range(len(S)//5+1):
  S = HIT(S,A)
  if S == "":
    break
if S == "":
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
import sys
li = ["dream","dreamer","erase","eraser"]
li = [s[::-1] for s in li]
sen = input()[::-1]
while 1:
  ju = 0
  for i in range(4):
    le = len(li[i])
    if sen[:le] == li[i]:
      if len(sen) == le:
        print("YES")
        sys.exit()
      else:
        sen = sen[le:]
        ju = 1
  if not ju:
    print("NO")
    sys.exit()

Submission status: Accepted

Solution code:
S = input()[::-1]
T = ['maerd' ,'remaerd' ,'esare' ,'resare']
i, j = 0, 0
while True:
    if i == 4:
        break
    if T[i] == S[j:j+len(T[i])]:
        j += len(T[i])
        i = 0
    else:
        i += 1
print("YES" if len(S)==j 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()
last = len(s)
ans = 'YES'
while last > 0:
    if s[last - 5 : last] == 'dream' or s[last - 5 : last] == 'erase':
        last -= 5
    elif s[last-6:last] == 'eraser':
        last -= 6
    elif s[last-7:last] == 'dreamer':
        last -= 7
    else:
        ans = 'NO'
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

word = ['dream', 'erase']

while len(S) > 0:
    if S[-2:] == 'er':
        if S[-6:] == 'eraser':
            S = S[:len(S)-len(S[-6:])]
        elif S[-7:] == 'dreamer':
            S = S[:len(S)-len(S[-7:])]
        else:
            break
    else:
        if S[-5:] in word:
            S = S[:len(S)-len(S[-5:])]
        else:
            break

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

Submission status: Accepted

Solution code:
S = list(input())
#S = list("dream" * 20000)
string = [list("dream") ,  list("dreamer") , list("erase") ,list("eraser")]
for i in range(4):
    string[i] = string[i][::-1]
#print(string)
S = S[::-1]
#print(S[0:5])
idx = 0
#print(S[idx:5])
while idx != len(S):
    if S[idx:idx + 5] == string[0]:
        idx += 5
    elif S[idx:idx + 7] == string[1]:
        idx += 7
    elif S[idx:idx + 5] == string[2]:
        idx += 5
    elif S[idx:idx + 6] == string[3]:
        idx += 6
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
str = input()
str = str.replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')

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

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

Submission status: Accepted

Solution code:
S = list(input())

while len(S) != 0:
    if S[-1] == "m":
        if "".join(S[-5:]) == "dream":
            del S[-5:]
        else:
            print("NO")
            exit()
    elif "".join(S[-3:]) == "mer":
        if "".join(S[-7:]) == "dreamer":
            del S[-7:]
        else:
            print("NO")
            exit()
    elif S[-1] == "e":
        if "".join(S[-5:]) == "erase":
            del S[-5:]
        else:
            print("NO")
            exit()
    elif "".join(S[-3:]) == "ser":
        if "".join(S[-6:]) == "eraser":
            del S[-6:]
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()

print("YES")

Submission status: Accepted

Solution code:
S = input()
S = list(S)
s = ''.join(list(reversed(S)))
def main(s):
  l = ["resare", "esare","remaerd", "maerd"]
  for i in l:
    s = s.replace(i, '')
  return s
if main(s) == '':
  print('YES')
elif main(s) != '':
  print('NO')