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):
s = input()[::-1]
while len(s) > 0 :
    if s[:7] == 'remaerd':
        s = s[7:]
    elif s[:6] == 'resare':
        s = s[6:]
    elif s[:5] == 'maerd':
        s = s[5:]
    elif s[:5] == 'esare':
        s = s[5:]
    else:
        break
print(('NO','YES')[len(s)==0])

Solution (Python):

S = list(input())
a1 = list('dreamer')
a2 = list('dream')
b1 = list('eraser')
b2 = list('erase')


loop_list = [b1, b2, a1, a2]
for word in loop_list:
    for i in range(len(S)-len(word)+1):
        all_match = True
        for j in range(len(word)):
            if S[i+j] == word[j]:
                pass
            else:
                all_match = False

        if all_match == False:
            continue

        for j in range(len(word)):
            S[i+j] = ''


if  sum( list(map(len,S))   ) == 0:
    print('YES')
else:
    print('NO')

Solution (Python):
S = input()

div = ['dream', 'dreamer', 'erase', 'eraser']
end = 0
ans = "YES"

while end < len(S):
    
    isExist = False
    
    for d in div:
        if d == S[len(S) - len(d) - end: len(S) - end]:
            end += len(d)
            isExist = True

    if isExist != True:
        ans = "NO"
        break

print(ans)

Solution (Python):
s = input()
while True:
  n = len(s)
  if n==0:
    print("YES")
    exit()
  if n>=5:
    if s[n-5:n] == "dream":
      s = s[:n-5]
      continue
    if s[n-5:n] == "erase":
      s = s[:n-5]
      continue
  if n>=6:
    if s[n-6:n] == "eraser":
      s = s[:n-6]
      continue
  if n>=7:
    if s[n-7:n] == "dreamer":
      s = s[:n-7]
      continue
  break
print("NO")

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

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

Solution (Python):
import re
pattern = r"(?:dream(?:er)?|eraser?)+$"
text = input()
if re.match(pattern , text):
    print('YES')
else:
    print('NO')

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

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

Solution (Python):
import re

S = input()
result = re.match(r'\A(dream(er)?|erase(r)?)+\Z', S)
if result:
    print('YES')
else:
    print('NO')

Solution (Python):
def solve(s, ws):
    while True:
        find_w = False
        for w in ws:
            if s.startswith(w):
                s = s[len(w):]
                find_w = True
                break
        if not s:
            return "YES"
        elif not find_w:
            return "NO"
    return None


S = input()[::-1]
WS = [w[::-1] for w in['dream', 'dreamer', 'erase', 'eraser']]
print(solve(S, WS))

Solution (Python):

import sys, copy
s = input();






















ss = [s]
while( len(ss) > 0 ):
    tt = copy.deepcopy(ss)
    ss = list()
    for t in tt:
        for x in ["dream", "dreamer", "erase", "eraser"]:
            if ( t.startswith(x) ):
                t_cut = t[len(x):]
                ss.append(t_cut)
                if ( t_cut == "" ):
                    print("YES")
                    sys.exit(0)


print("NO")

Solution (Python):


import sys

s = input()
letter = ['dream','dreamer','erase','eraser']

ll = len(s)
while ll > 0:
    for le in range(len(letter)):
        if(ll-len(letter[le]) < 0):
            continue
        ss = s[ll-len(letter[le]):ll]
        
        if(letter[le] == ss):
            ll -= len(letter[le])
            break
        else:
            if(le == len(letter)-1):
                print('NO')
                sys.exit()
            else:
                continue
        
print('YES')

Solution (Python):


import math

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

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

divide = [i[::-1] for i in divide]

can = True
i = 0
while i < len(s):
    
    can2 = False
    for j in divide:
        
        
        if s[i:len(j)+i] == j:
            
            
            can2 = True
            i += len(j)
    if not can2:
        
        can = False
        break

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

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

while len(S) != 0:
    if "".join(S[-5:]) == "dream" or "".join(S[-5:]) == "erase":
        del S[-5:]
    elif "".join(S[-6:]) == "eraser":
    
        del S[-6:]
    elif "".join(S[-7:]) == "dreamer":
        del S[-7:]
    else:
        break
    
if len(S) == 0:
    print("YES")
else:
    print("NO")

Solution (Python):
a = list(input())
while len(a) != 0:
    if "".join(a[-5:]) == "dream" or "".join(a[-5:]) == "erase":
        del a[-5:]
    elif "".join(a[-6:]) == "eraser":
        del a[-6:]
    elif "".join(a[-7:]) == "dreamer":
        del a[-7:]
    else:
        print("NO")
        break
if len(a) == 0:
    print("YES")

Solution (Python):
if input().rstrip().replace("dream","D").replace("erase","E").replace("Der","").replace("Er","").replace("D","").replace("E","") == "":
    print( "YES" )
else:
    print( "NO" )

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

Solution (Python):



S = input()

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


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

Solution (Python):
S = input()

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

for s in String:
    S = S.replace(s,'')

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

Solution (Python):
A = ["dream", "dreamer", "erase", "eraser"]
for i in range(4):
    A[i] = A[i][::-1]

S = input()[::-1]
idx = 0
while idx < len(S):
    flag = False
    for i in range(4):
        if len(S) - idx < len(A[i]):
            continue
        else:
            if S[idx:idx+len(A[i])] == A[i]:
                flag = True
                idx += len(A[i])
                break
            else:
                continue
    if idx >= len(S) or flag == False:
        break

print(["NO","YES"][idx == len(S)])

Solution (Python):
W=["dream", "dreamer", "erase", "eraser"]
word=input()
while True:
    if word=="":
        print("YES")
        exit()

    ok = False
    for w in W:
        if word[-len(w):] == w:
            word = word[:-len(w)]
            ok = True
            break

    if not ok:
        print("NO")
        exit()

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

Solution (Python):
s = input()
i = 0

while i < len(s):
    if s[i:min(len(s),i+11)] == 'dreameraser':
        i += 11
    elif s[i:min(len(s),i+10)] == 'dreamerase':
        i += 10
    elif s[i:min(len(s),i+7)] == 'dreamer':
        i += 7
    elif s[i:min(len(s),i+6)] == 'eraser':
        i += 6
    elif s[i:min(len(s),i+5)] == 'erase':
        i += 5
    elif s[i:min(len(s),i+5)] == 'dream':
        i += 5
    else:
        print('NO')
        break
        
    if i == len(s):
        print('YES')
        break

Solution (Python):
s = str(input())
list_s = list(s)
while len(list_s) > 0:
    if list_s[-5:] == list("dream") or list_s[-5:] == list("erase"):
        for i in range(5):
            list_s.pop()
    elif list_s[-6:] == list("eraser"):
        for i in range(6):
            list_s.pop()
    elif list_s[-7:] == list("dreamer"):
        for i in range(7):
            list_s.pop()
    else:
        ans = "NO"
        break
else:
    ans = "YES"
print(ans)

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

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

for i, r in enumerate(divide):
    divide[i] = r[::-1]




a = 0
while a < len(S):
    can = False
    for i in range(4):
        d = divide[i]
        b = a + len(d)
        if S[a:b] == d:
            can = True
            a = b
            break
    if can == False:
        break

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

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

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

for i, r in enumerate(divide):
    divide[i] = r[::-1]




a = 0
while a < len(S):
    can = False
    for i in range(4):
        d = divide[i]
        d_size = len(d)
        b = a + d_size
        if S[a:b] == d:
            can = True
            a = b
    if can == False:
        break

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

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

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

for i, r in enumerate(divide):
    divide[i] = r[::-1]


i = 0
while i < len(S):
    can2 = False
    for j in range(4):
        d = divide[j]
        d_size = len(d)
        if S[i:d_size + i] == d:
            can2 = True
            i += d_size
    if can2 == False:
        break

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

Solution (Python):
s = input()

flg = 0
try:
	while flg == 0:
		if s[0] == "d":
			if s[:5] == "dream":
				if s[5] == "d":
					s = s[5:]
				elif s[5:7] == "er":
					if s[7] == "a": 
						s = s[5:]
					elif len(s) == 7 or s[7] == "d" or s[7] == "e": 
						s = s[7:]
					else:
						flg = 1
				else:
					flg = 2
			else:
				flg = 3
		elif s[0] == "e":
			if s[:5] == "erase" and (len(s) == 5 or s[5] == "d" or s[5] == "e"):
				s = s[5:]
			elif s[:6] == "eraser" and (len(s) == 6 or s[6] == "d" or s[6] == "e"):
				s = s[6:]
			else:
				flg = 4
		else:
			flg = 7
	if flg != 0:
		
		print("NO")
except IndexError:
	if len(s) == 0:
		print("YES")
	elif s == "dream" or s == "dreamer" or s == "erase" or s == "eraser":
		print("YES")
	else:
		print("NO")

Solution (Python):
s = list(input())
answer=""
i =0
while i < len(s):
    if i+4<=len(s)-1 and s[i]=="d":
        if (s[i+1], s[i+2], s[i+3], s[i+4]) == ("r", "e", "a", "m"):
            if i+4 ==len(s)-1:
                answer="YES"
            i+=5
        else:
            answer="NO"
            break
    elif s[i]=="e":
        if i+5<=len(s)-1 and (s[i+1], s[i+2], s[i+3], s[i+4],s[i+5])==("r","a","s","e","r"):
            if i+5 ==len(s)-1:
                answer="YES"
            i+=6
        elif i+4<=len(s)-1 and (s[i+1], s[i+2], s[i+3], s[i+4])==("r","a","s","e"):
            if i+4 ==len(s)-1:
                answer="YES"
            i+=5
        elif i+1<=len(s)-1 and i>=5 and (s[i-5],s[i-4],s[i-3],s[i-2],s[i-1],s[i+1])==("d","r","e","a","m","r"):
            if i+1 ==len(s)-1:
                answer="YES"
            i+=2
        else:
            answer="NO"
            break
    else:
        answer="NO"
        break
print(answer)

Solution (Python):



s = input()
revs = s[::-1]
words = ['maerd', 'remaerd', 'esare', 'resare']


def scan(n):
    for w in words:
        if revs[n:].startswith(w):
            return len(w)
    print('NO')
    exit()


n = 0
while revs[n:] != '':
    n += scan(n)

print('YES')

Solution (Python):


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

dream = "dream"[::-1]
dreamer = "dreamer"[::-1]
erase = "erase"[::-1]
eraser = "eraser"[::-1]

for i in range(len(s)):
    if s.startswith(dreamer):
        s = s.replace(dreamer,"",1)
    elif s.startswith(dream):
        s = s.replace(dream,"",1)

    if s.startswith(eraser):
        s = s.replace(eraser,"",1)
    elif s.startswith(erase):
        s = s.replace(erase,"",1)

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

Solution (Python):


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

dream = "dream"[::-1]
dreamer = "dreamer"[::-1]
erase = "erase"[::-1]
eraser = "eraser"[::-1]

for i in range(len(s)):
    if s.startswith(dreamer):
        s = s.replace(dreamer,"",1)
    elif s.startswith(dream):
        s = s.replace(dream,"",1)

    if s.startswith(eraser):
        s = s.replace(eraser,"",1)
    elif s.startswith(erase):
        s = s.replace(erase,"",1)

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

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    S = input()
    i = len(S)
    while i > 0:
        ok = False
        for x in ["dreamer", "eraser", "dream", "erase"]:
            if S.startswith(x, i - len(x)):
                i -= len(x)
                ok = True
                break
        if not ok:
            print(NO)
            return
    print(YES)


if __name__ == '__main__':
    main()

Solution (Python):
s = input()

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

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

Solution (Python):
s=input()
while len(s)>0:
    if s[-5:]=='dream' or s[-5:]=='erase':
        s=s[:len(s)-5]
        continue
    if s[-7:]=='dreamer':
        s=s[:len(s)-7]
        continue
    if s[-6:]=='eraser':
        s=s[:len(s)-6]
        continue
    print('NO')
    break
else:
    print('YES')

Solution (Python):
import re

def match(pattern, strings):
	return re.match('^{0}'.format(pattern), strings)

def any_match(strings):
	return re.match('^dream|^erase', strings)

S = input()

i = 0
while i < len(S):
	if match('dreamer', S[i:]):
		i += len('dreamer')
		if any_match(S[i:]):
			continue
		else:
			if i == len(S):
				break
			else:
				i -= len('dreamer')
				i += len('dream')
				continue
	elif match('eraser', S[i:]):
		i += len('eraser')
		if any_match(S[i:]):
			continue
		else:
			if i == len(S):
				break
			else:
				i -= len('eraser')
				i += len('erase')
				continue
	elif match('dream', S[i:]):
		i += len('dream')
		continue
	elif match('erase', S[i:]):
		i += len('erase')
		continue
	else:
		print('NO')
		exit()

print('YES')

Solution (Python):
def is_fit(str_list,chr_):
    while len(chr_) > 0:
        if   chr_[-7:] in t_list:
            chr_ = chr_[:-7]
        elif chr_[-6:] in t_list:
            chr_ = chr_[:-6]
        elif chr_[-5:] in t_list:
            chr_ = chr_[:-5]
        else:
            return "NO"
    return "YES"

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

print(is_fit(t_list,s))

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

Solution (Python):
s = input()
t_list = ['dream','dreamer','erase','eraser']

flg = True
while len(s) > 0:
    if   s[-7:] in t_list:
        s = s[:-7]
    elif s[-6:] in t_list:
        s = s[:-6]
    elif s[-5:] in t_list:
        s = s[:-5]
    else:
        flg = False
        break

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

Solution (Python):
S = input()

S = S[::-1]

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

print("YES")

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

print('YES')

Solution (Python):
from sys import stdin

S = stdin.readline().rstrip()

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

ans = True
while len(S) > 0:

    

    if S[len(S) - 7:] == lst[1]:
        S = S[:len(S) - 7]
    elif S[len(S) - 6:] == lst[3]:
        S = S[:len(S) - 6]
    elif S[len(S) - 5:] == lst[0] or S[len(S) - 5:] == lst[2]:
        S = S[:len(S) - 5]
    else:
        ans = False
        break

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

Solution (Python):

import os, sys
import math

def read_items_in_line(cast=int):
    return [cast(x) for x in sys.stdin.readline().strip(' \n').split(' ')]

items = ["dream", "dreamer", "erase", "eraser"]
rev_items = [x[::-1] for x in items]

S = read_items_in_line(cast=str)[0]
rev_S = S[::-1]

while(True):
    found = False
    for x in rev_items:
        
        if rev_S.startswith(x):
            rev_S = rev_S[len(x):]
            found = True
            break
    if not found:
        break

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

Solution (Python):
S = input()
T = ["dream", "dreamer", "erase", "eraser"]
def main():
    i = len(S)
    if i == 0:
        print("NO")
        return 0
    while True:
        if i == 0:
            break
        elif i < 5:
            print("NO")
            return 0
        elif S[i - 5:i] == T[0] or S[i - 5:i] == T[2]:
            i -= 5
        elif i < 6:
            print("NO")
            return 0
        elif S[i - 6:i] == T[3]:
            i -= 6
        elif i < 7:
            print("NO")
            return 0
        elif S[i - 7:i] == T[1]:
            i -= 7
        else:
            print("NO")
            return 0
    print("YES")
    return 0
main()

Solution (Python):
globals().update({"s": input()}) or ((lambda it: set(it.takewhile(lambda _: len([globals().update({"s": s[:-len(w)]}) for w in ["dreamer", "eraser", "dream", "erase"] if s.endswith(w)]), it.repeat(0))))(__import__("itertools")) or True) and print(s and "NO" or "YES")

Solution (Python):
print([list(it.takewhile(lambda x: any([globals()['s'].endswith(w) and (globals().__setitem__('s', globals()['s'][:-len(w)]) or True) or False for w in ["dreamer", "eraser", "dream", "erase"]]), it.repeat([]))) for it in [__import__("itertools")] for _ in [globals().__setitem__('s', input())]] and len(globals()['s']) == 0 and "YES" or "NO")

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

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

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

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

Solution (Python):
S = input()
ls = len(S)
memo = [False] * (ls+1)

memo[0] = True
for i in range(ls):
    if memo[i] == False:
        continue
    else:
        if S[i: i+5] == "dream" or S[i: i+5] == "erase":
            memo[i+5] = True
        if S[i: i+6] == "eraser":
            memo[i+6] = True
        if S[i: i+7] == "dreamer":
            memo[i+7] = True

if memo[ls]:
    print("YES")
else:
    print("NO")

Solution (Python):
S = input()

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

Solution (Python):
S = input()[::-1]
i = 0
ls = len(S)
accept = True

while ls > i:
    if S[i: i+5] == "maerd" or S[i: i+5] == "esare":
        i += 5
    elif S[i: i+6] == "resare":
        i += 6
    elif S[i: i+7] == "remaerd":
        i += 7
    else:
        accept = False
        break

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

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

Solution (Python):
S = str(input())
S = S[::-1]
moji = ["maerd", "esare", "remaerd", "resare"]
i = 0
while i < len(S):
    answer = False
    for j in range(4):
        if S[i:i+len(moji[j])] == moji[j]:
            i += len(moji[j])
            answer = True
    if not answer:
        print("NO")
        break
if answer:
    print("YES")

Solution (Python):
import sys
s = input()
i = 1 
s1 = ''
while i <= len(s):
  s1 += s[-i]
  i += 1
s2 = s1
while s2 != '':
  if s2[0:5] == 'maerd':
    s2 = s2[5:]
  elif s2[0:7] == 'remaerd':
    s2 = s2[7:]
  elif s2[0:5] == 'esare':
    s2 = s2[5:]
  elif s2[0:6] == 'resare':
    s2 = s2[6:]
  else:
    print('NO')
    sys.exit()
print('YES')

Solution (Python):
s = input()

curs = [0]
while True:
  next_curs = []
  break_ = False
  for c in curs:
    
    if s[c:c+5] == 'dream':
      next_curs.append( c+5 )
      if len(s) == c+5:
        break_ = True
    if s[c:c+7] == 'dreamer':
      next_curs.append( c+7 )
      if len(s) == c+7:
        break_ = True
    if s[c:c+5] == 'erase':
      next_curs.append( c+5 )
      if len(s) == c+5:
        break_ = True
    if s[c:c+6] == 'eraser':
      next_curs.append( c+6 )
      if len(s) == c+6:
        break_ = True
  if next_curs == []:
    print('NO')
    break
  if break_: 
    print('YES')
    break
  curs = next_curs

Solution (Python):
a=list(input())
n=0
while n<len(a):
    oldn=n
    if a[n] == "e":
        if n+4<len(a) and a[n+1]=="r" and a[n+2]=="a" and a[n+3]=="s" and a[n+4]=="e":
            if n+5<len(a) and a[n+5]=="r":
                n=n+6
            else:
                n=n+5
    else:
        if a[n] == "d":
            if n+4<len(a) and a[n+1]=="r" and a[n+2]=="e" and a[n+3]=="a" and a[n+4]=="m":
                if n+6<len(a) and a[n+5]=="e" and a[n+6] == "r":
                    if n+7<len(a) and a[n+7]=="a":
                        n=n+5
                    else:
                        n=n+7
                else:
                    n=n+5
    if oldn == n:
        print("NO")
        break
else:
    print("YES")

Solution (Python):
S = input()
S = S[::-1]
words = ['dream','dreamer','erase','eraser']

i = 0
while i < len(S):
    for word in words:
        if S[i:].startswith(word[::-1]):
            i += len(word)
            break
    else:
        print('NO')
        exit()
print('YES')

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

Solution (Python):
s = input()
if s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","") == "":
    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):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD




dp = None


def main():
    S = input()

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

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

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

        else:
            break

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


main()

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

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

Solution (Python):
given = ["dreamer", "dream", "eraser", "erase"]
S = input()
while len(S) > 0:
    judge = [S.endswith(i) for i in given]
    if any(judge):
        target = given[judge.index(True)]
        S = S[:-len(target)]
        if len(S) == 0:
            print("YES")
            break
    else:
        print("NO")
        break

Solution (Python):
import re
print("YES" if re.match('^(dream|dreamer|erase|eraser)*$', input()) else "NO")

Solution (Python):

def main():
    s = input()
    s = s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")

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

if __name__ == "__main__":
        main()

Solution (Python):

def main():
    s = input()
    s = s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")

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

if __name__ == "__main__":
        main()

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

Solution (Python):
S = input()

N = len(S)
T = ''
i = 0
while i < N:
    j = N - 1 - i
    if S[j] == 'm':
        T = 'dream' + T
        i += 5
    elif S[j] == 'e':
        T = 'erase' + T
        i += 5
    elif S[j - 2:j + 1] == 'mer':
        T = 'dreamer' + T
        i += 7
    elif S[j - 2:j + 1] == 'ser':
        T = 'eraser' + T
        i += 6
    else:
        break

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

Solution (Python):
s = input()
while True:
    temp = s
    s5 = temp[-5:]
    s6 = temp[-6:]
    s7 = temp[-7:]

    if (s5 == 'erase') | (s5 == 'dream'): 
        s = temp[:-5]
    elif s6 == 'eraser':
        s = temp[:-6]
    elif s7 == 'dreamer':
        s = temp[:-7]
    else:
        print('NO')
        exit()

    if s == '':
        print('YES')
        exit()

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

Solution (Python):
S=str(input())
S=S.replace('eraser','1')
S=S.replace('erase','2')
S=S.replace('dreamer','3')
S=S.replace('dream','4')
S=S.replace('1','')
S=S.replace('2','')
S=S.replace('3','')
S=S.replace('4','')
if len(S)==0:
    print('YES')
else:
    print('NO')

Solution (Python):
S = input()
Sb = S[::-1]
daydreamers = ["maerd", "remaerd", "esare", "resare"]
judge = True

i = 0
while i < len(S) and judge:
    temp = ""
    isThere = False
    for j in range(7):
        temp += Sb[i+j]
        if temp in daydreamers:
            isThere = True
            i = i+j+1
            break
    if not isThere:
        judge = False

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

Solution (Python):

"""
Created on Wed Aug 15 12:43:21 2018
ABC049C
@author: maezawa
"""

s = input()
a = ('dream', 'dreamer', 'erase', 'eraser')

i = len(s)
ans = 'YES'
while True:
    if s[-5:] == a[0] or s[-5:] == a[2]:
        i -= 5
    elif i>=6 and s[-6:] == a[3]:
        i -= 6
    elif i>=7 and s[-7:] == a[1]:
        i -= 7
    else:
        ans = 'NO'
        break
    if i == 0:
        ans = 'YES'
        break
    elif i<5:
        ans = 'NO'
        break
    s = s[:i]

    
print(ans)

Solution (Python):

"""
Created on Wed Aug 15 12:43:21 2018
ABC049C
@author: maezawa
"""

s = input()
a = ('dream', 'dreamer', 'erase', 'eraser')

i = len(s)
ans = 'YES'
while True:
    if s[-5:] == a[0] or s[-5:] == a[2]:
        i -= 5
        if i == 0:
            ans = 'YES'
            break
        elif i<5:
            ans = 'NO'
            break
        s = s[:i]
    elif i>=6 and s[-6:] == a[3]:
        i -= 6
        if i == 0:
            ans = 'YES'
            break
        elif i<5:
            ans = 'NO'
            break
        s = s[:i]
    elif i>=7 and s[-7:] == a[1]:
        i -= 7
        if i == 0:
            ans = 'YES'
            break
        elif i<5:
            ans = 'NO'
            break
        s = s[:i]
    else:
        ans = 'NO'
        break
    
print(ans)