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

Solution (Python):
import sys
sys.setrecursionlimit(1000000)

S = input()

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

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

Solution (Python):
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)

Solution (Python):
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')

Solution (Python):

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")

Solution (Python):
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")

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

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

Solution (Python):

S = input()
word = ["dream","dreamer","erase","eraser"]

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

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

Solution (Python):
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")

Solution (Python):
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')

Solution (Python):
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")

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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")

Solution (Python):
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)

Solution (Python):

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)

Solution (Python):


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')

Solution (Python):


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

while True:
    match = False
    word_matched = ''
    
    for word in words:
        if S_copy.endswith(word):
            match = True
            
            
            if len(word) > len(word_matched):
                
                
                
                word_matched = word

    if match:
        T.insert(0, word_matched)
        
        
        S_copy = S_copy[:-len(word_matched)]
    else:
        break



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

Solution (Python):
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')

Solution (Python):
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')

Solution (Python):

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")

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

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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)

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

Solution (Python):
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')

Solution (Python):

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)

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

Solution (Python):
S = input()
length_substring_S = len(S)
test_str_list = ['dream', 'dreamer', 'erase', 'eraser']
flag = True

while flag == True:
  flag = False
  for i in range(len(test_str_list)):
    if S[0:length_substring_S].endswith(test_str_list[i]):
      length_substring_S -= len(test_str_list[i])
      flag = True
      break

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

Solution (Python):


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")

Solution (Python):
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')

Solution (Python):
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')

Solution (Python):
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)

Solution (Python):
s = input()

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

for i in range(len(s) + 1):
    
    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')

Solution (Python):
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)

Solution (Python):
s = input()

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

Solution (Python):
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]


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

Solution (Python):

import sys

YES = "YES"  
NO = "NO"  


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



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  
    solve(S)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
s = input()




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')

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

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

Solution (Python):
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

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

Solution (Python):
S = input()

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

Solution (Python):
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")

Solution (Python):
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")

Solution (Python):
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")

Solution (Python):
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")

Solution (Python):
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()

Solution (Python):
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()

Solution (Python):
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")

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

Solution (Python):
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)

Solution (Python):
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")

Solution (Python):
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')

Solution (Python):
S = list(input())

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

S = S[::-1]

idx = 0

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")

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

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

Solution (Python):
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

Solution (Python):
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")

Solution (Python):
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')

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

Solution (Python):

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')

Solution (Python):
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)

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

Solution (Python):
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')

Solution (Python):
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")

Solution (Python):
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:
    
    
    if ind == S_max:
        break

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

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

Solution (Python):
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')

Solution (Python):
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)

Solution (Python):
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')

Solution (Python):
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)

Solution (Python):
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")

Solution (Python):
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')

Solution (Python):
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")

Solution (Python):
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


ismatch = re.match(r'^(dream|dreamer|erase|eraser)*$',S)

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

print(result)

Solution (Python):
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)

Solution (Python):
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]

pos=0
can=True
while (pos < n):
  ifdivide=False
  for substr in putl:
    substr_size=len(substr)
    chk=S[pos:(pos+substr_size)]
    
    if chk==list(substr):
      ifdivide=True
      
      break
  if ifdivide:
    pos+=substr_size
  else:
    can=False
    break
if can:
  print("YES")
else:
  print("NO")

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

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


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()

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


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()

Solution (Python):
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)

Solution (Python):
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")

Solution (Python):
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')

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