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):
dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


def main():
    S = input()

    while len(S):
        lens = len(S)
        if S[-len(dreamer) :] == dreamer:
            S = S[: -len(dreamer)]
        if S[-len(eraser) :] == eraser:
            S = S[: -len(eraser)]
        if S[-len(dream) :] == dream:
            S = S[: -len(dream)]
        if S[-len(erase) :] == erase:
            S = S[: -len(erase)]
        if lens == len(S):
            print("NO")
            return
    print("YES")
    return


main()

Solution (Python):
dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


def main():
    S = input()
    i = len(S)
    while 0 < i:
        pre = i
        if S[i - len(dreamer):i] == dreamer:
            i -= len(dreamer)
        if S[i - len(eraser):i] == eraser:
            i -= len(eraser)
        if S[i - len(dream):i] == dream:
            i -= len(dream)
        if S[i - len(erase):i] == erase:
            i -= len(erase)
        if pre == i:
            print("NO")
            return
    print("YES")
    return


main()

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

Solution (Python):
dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


def main():
    S = input()

    while len(S):
        lens = len(S)
        if S[-len(dreamer) :] == dreamer:
            S = S[: -len(dreamer)]
        if S[-len(eraser) :] == eraser:
            S = S[: -len(eraser)]
        if S[-len(dream) :] == dream:
            S = S[: -len(dream)]
        if S[-len(erase) :] == erase:
            S = S[: -len(erase)]
        if lens == len(S):
            print("NO")
            return
    print("YES")
    return


main()

Solution (Python):
S=input()
f=1
while S!='':
    if S[-7:]=='dreamer':
        S=S[:-7]
    elif S[-6:]=='eraser':
        S=S[:-6]
    elif S[-5:]=='dream' or S[-5:]=='erase':
        S=S[:-5]
    else:
        f=0
        break
print(['NO','YES'][f])

Solution (Python):
dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


def main():
    S = input()

    while len(S):
        lens = len(S)
        if S[ - len(dreamer):] == dreamer:
            S = S[:- len(dreamer)]
        elif S[-len(eraser):] == eraser:
            S = S[:- len(eraser)]
        elif S[-len(dream):] == dream:
            S = S[:-len(dream)]
        elif S[-len(erase):] == erase:
            S = S[:-len(erase)]
        if lens == len(S):
            print("NO")
            return
    print("YES")
    return


main()

Solution (Python):
dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


def main():
    S = input()

    while len(S):
        lens = len(S)
        if S[lens - len(dreamer):] == dreamer:
            S = S[: lens - len(dreamer)]
        elif S[lens - len(eraser):] == eraser:
            S = S[:lens - len(eraser)]
        elif S[lens - len(dream):] == dream:
            S = S[:lens - len(dream)]
        elif S[lens - len(erase):] == erase:
            S = S[:lens - len(erase)]
        if lens == len(S):
            print("NO")
            return
    print("YES")
    return


main()

Solution (Python):
S = input()

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

Solution (Python):
s = list(input())
n = len(s)
s.reverse()
for i in range(6):
    s.append("x")
s = "".join(s)
i = 0
word = ["maerd", "esare", "resare","remaerd"]
while i<n:
    if s[i:i+5]==word[0]:
        i+=5
    elif s[i:i+5]==word[1]:
        i+=5
    elif s[i:i+6]==word[2]:
        i+=6
    elif s[i:i+7]==word[3]:
        i+=7
    else:
        print("NO")
        exit()
print("YES")

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('NO')
else:
  print('YES')

Solution (Python):





mod=10**9+7
def swap(a,b):
    c=a
    a=b
    b=c
    return a,b
def factorial(x): 
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): 
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): 
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    
    
    
    
    
    
    
    
    
    
    s=list(input())
    s.reverse()
    i=0
    while i < len(s):
        if i<=len(s)-5 and ''.join(s[i:i+5]) == "maerd":
            i+=5
        elif i<=len(s)-7 and ''.join(s[i:i+7]) == "remaerd":
            i+=7
        elif i<=len(s)-5 and ''.join(s[i:i+5]) == "esare":
            i+=5
        elif i<=len(s)-6 and ''.join(s[i:i+6]) == "resare":
            i+=6
        else:
            print("NO")
            return
    print("YES")
main()

Solution (Python):
S = input().strip()
cur = 0
flag = 0
while cur<len(S):
    if S[cur:cur+11]=="dreameraser":
        cur += 11
    elif S[cur:cur+10]=="dreamerase":
        cur += 10
    elif S[cur:cur+7]=="dreamer":
        cur += 7
    elif S[cur:cur+6]=="eraser":
        cur += 6
    elif S[cur:cur+5]=="dream" or S[cur:cur+5]=="erase":
        cur += 5
    else:
        flag = 1
        break
if flag==0:
    print("YES")
else:
    print("NO")

Solution (Python):
def main():
    s=input()
    rs=s[::-1]
    c1="maerd"
    c2="remaerd"
    c3="esare"
    c4="resare"
    t = ""
    cc=0
    while cc < len(rs):
        if rs[cc]=="m":
            t = t+c1
            cc += 5
        elif rs[cc]=="e":
            t = t+c3
            cc += 5
        elif rs[cc] =="r":
            if len(rs[cc:]) < 3:
                return "NO"
            elif rs[cc:cc+3] == "rem":
                t = t+c2
                cc += 7
            elif rs[cc:cc+3] == "res":
                t = t+c4
                cc += 6
            else:
                return "NO"
        else:
            return "NO"
    if rs == t:
        return "YES"
    else:
        return "NO"

print(main())

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

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 




 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    S = input()
    
    aa = "dream"
    aa = aa[::-1]
    bb = "dreamer"
    bb = bb[::-1]
    cc = "erase"
    cc = cc[::-1]
    dd = "eraser"
    dd = dd[::-1]
    
    S = S[::-1]
    
    while True:
        if len(S) == 0:
            break
            
        if len(S) < 5:
            print("NO")
            sys.exit()
        
        if S[:5] == aa or S[:5] == cc:
            S = S[5:]
        elif S[:6] == dd:
            S = S[6:]
        elif S[:7] == bb:
            S = S[7:]
        else:
            print("NO")
            sys.exit()
            
    print("YES")
    
    
if __name__ == "__main__":
	main()

Solution (Python):
n = input()
v=n.replace('dream', 'A').replace('erase', 'B')
ans=v.replace('Aer','').replace('Br','').replace('A','').replace('B','')
if len(ans) == 0:
  print('YES')
else:
  print('NO')

Solution (Python):

import sys

YES = "YES"  
NO = "NO"  

def solve(S: str):
    S = S[::-1]
    while len(S)>4:
        if S[:6]=="resare":
            S= S[6:]
        elif S[:5] == "esare" or S[:5]== "maerd":
            S=S[5:]
        elif S[:7] == "remaerd":
            S=S[7:]
        else:
            print(NO)
            return 
        
    
    if len(S) == 0:
        print(YES)
    else:
        print(NO)
    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):
s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']
words = sorted(words, reverse=True)
print()
for word in words:
    if word in s:
        s = s.replace(word, "")

if not s:
    ans = "YES"
else:
    ans = "NO"

print(ans)

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

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

while True:
  if x[:5] == "maerd":
    x = x[5:]
  elif x[:7] == "remaerd":
    x = x[7:]
  elif x[:5] == "esare":
    x = x[5:]
  elif x[:6] == "resare":
    x = x[6:]
  else:
    break
    
if len(x) == 0:
  print("YES")
else:
  print("NO")

Solution (Python):
S = input()
reversed_S = ''.join(list(reversed(S)))  

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


for i in range(len(divide)):
    divide[i] = ''.join(list(reversed(divide[i])))


can = 1

i = 0

while i < len(S):
    can2 = 0
    for j in range(len(divide)):
        if reversed_S[i:i + len(divide[j])] == divide[j]:
            can2 = 1
            i += len(divide[j])

    if can2 == 0:
        can = 0
        break

if can == 1:
    print('YES')
else:
    print('NO')

Solution (Python):
S = input()
dp = [0] * (len(S) + 1)
dp[0] = 1

words = ["dream", "dreamer", "erase", "eraser"]
done = 'NO'

for i in range(len(S)):
    if dp[i] == 0:
        continue
    for w in words:
        if S[i:i+len(w)] == w:
            dp[i+len(w)] = 1
    
    if dp[len(S)] == 1:
        done = 'YES'
        break

print(done)

Solution (Python):
import sys

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

d ='maerd'
dr = 'remaerd'
e = 'esare'
er = 'resare'

i = 0
while True:
    try:
        if s[i:i+5] == d or s[i:i+5] == e:
            i += 5
            if i == len(s):
                print('YES')
                sys.exit(0)
        
        elif s[i:i+6] == er:
            i += 6
            if i == len(s):
                print('YES')
                sys.exit(0)
        
        elif s[i:i+7] == dr:
            i += 7
            if i == len(s):
                print('YES')
                sys.exit(0)
            
        else:
            print('NO')
            sys.exit(0)
            
    except Exception as err:
        print('NO')
        sys.exit(0)

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

Solution (Python):
s = str(input())

if "erase" in s:
  s = s.replace("erase", "E")
if "dream" in s:
  s = s.replace("dream", "D")

if "Er" in s:
  s = s.replace("Er", "")
if "Der" in s:
  s = s.replace("Der", "")

if "E" in s:
  s = s.replace("E", "")
if "D" in s:
  s = s.replace("D", "")

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

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

kws = [list(kw) for kw in ["dream", "dreamer", "erase", "eraser"]]

memo = [0 for _ in range(len(s_list)+1)]
memo[0] = 1
for i in range(len(s_list)):
    if memo[i] == 1:
        for kw in kws:
            l = len(kw)
            if s_list[i:i+l] == kw:
                memo[i+l] = 1

if memo[-1] == 1:
    print("YES")
else:
    print('NO')

Solution (Python):
S = input()

def check(t):
  if len(t) >= 5 and (t[-5:] == 'dream' or t[-5:] == 'erase'):
    return True,t[:-5]
  elif len(t) >=6 and t[-6:] == 'eraser':
    return True,t[:-6]
  elif len(t) >= 7 and t[-7:] == 'dreamer':
    return True,t[:-7]
  else:
    return False,t

while(len(S) > 0):
  flag,S = check(S)
  if not flag:
    print('NO')
    exit()
print('YES')

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

Solution (Python):

s = list(input())
s.reverse()
words = ["dream","dreamer","erase","eraser"]
stack = []
for t in s :
	stack.append(t)
	for word in words :
		if list(reversed(word)) == stack :
			stack = []
if stack :
	print("NO")
else:
	print("YES")

Solution (Python):
s = input()

def remove_word_from_string(string, word):
  return ''.join(string.split(word))




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

for word in ls:
  s = remove_word_from_string(s, word)
  
ans = "YES" if s == '' else "NO"

print(ans)

Solution (Python):
s = input()

def remove_word_from_string(string, word):
  return ''.join(string.split(word))

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

for word in ls:
  s = remove_word_from_string(s, word)
  
ans = "YES" if s == '' else "NO"

print(ans)

Solution (Python):
s = input()

def reverse(string):
  return ''.join(reversed(string))

def split_and_join(string, word):
  return ''.join(string.split(word))

s_r = reverse(s)
ls = ["eraser", "erase", "dreamer", "dream"]
ls_r = []
for item in ls:
  ls_r.append(reverse(item))

for word_r in ls_r:
  s_r = split_and_join(s_r, word_r)
  
ans = "YES" if s_r == '' else "NO"

print(ans)

Solution (Python):
s=input()
length=len(s)

s=s[::-1]

s=s+"WWWWWWW"

index=0
flag=True
while index<length:
    if s[index]=="m" and s[index+1]=="a" and s[index+2]=="e" and s[index+3]=="r" and s[index+4]=="d":
        index+=5
    elif s[index]=="e" and s[index+1]=="s" and s[index+2]=="a" and s[index+3]=="r" and s[index+4]=="e":
        index+=5   
    elif s[index]=="r" and s[index+1]=="e" and s[index+2]=="m" and s[index+3]=="a" and s[index+4]=="e" and s[index+5]=="r" and s[index+6]=="d":
        index+=7   
    elif s[index]=="r" and s[index+1]=="e" and s[index+2]=="s" and s[index+3]=="a" and s[index+4]=="r" and s[index+5]=="e":
        index+=6
    else:
        flag=False
        break
if flag:
    print("YES")
else:
    print("NO")

Solution (Python):
String  = input()
index = 0
flag = False
while index < len(String) - 1:
    flag = True
    if String[index:index + 7] == "dreamer":
        index += 7
        if String[index:index + 4] == "aser":
            index += 4
        elif String[index:index + 3] == "ase":
            index += 3
    elif String[index:index + 5] == "dream":
            index += 5
    elif String[index:index + 6] == "eraser":
            index += 6
            if String[index:index + 4] == "aser":
                index += 4
            elif String[index:index + 3] == "ase":
                index += 3
    elif String[index:index + 5] == "erase":
                index += 5
    else:
        flag = False
        break
if flag:
    print("YES")
else:
    print("NO")

Solution (Python):
import re

S = ''.join(list(reversed(input())))
t = re.findall("maerd|remaerd|resare|esare",S)
T = ''.join(t)
if S == T:
    print("YES")
else:
    print("NO")

Solution (Python):
import re

S = ''.join(list(reversed(input())))
t = re.findall("remaerd|maerd|resare|esare",S)
T = ''.join(t)
if S == T:
    print("YES")
else:
    print("NO")

Solution (Python):
s = input()
i = len(s)
while i > 0:
    if s[i-5:i] == 'dream':
        i -= 5
    elif s[i-7:i] == 'dreamer':
        i -= 7
    elif s[i-5:i] == 'erase':
        i -= 5
    elif s[i-6:i] == 'eraser':
        i -= 6
    else:
        break
if i == 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):
import re
S = input().strip()
while True:
  
  if len(S) == 0:
    print('YES')
    break
  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')
    break

Solution (Python):
S = str(input())
a= [0,1,2,3]

judge = False

class E():
	def ex(self,S):
		m = S.replace('eraser' , '2')
		return m
		
class e():
	def ex(self,S):
		m = S.replace('erase' , '2')
		return m
		
class D():
	def ex(self,S):
		m = S.replace('dreamer','3')
		return m
		
class d():
	def ex(self,S):
		m = S.replace('dream','3')
		return m
		
		

a[0] = E()
a[1] = e()
a[2] = D()
a[3] = d()

for i in range(4):
	for j in range(4):
		for k in range(4):
			for l in range(4):
				m = a[i].ex(S)
				m = a[j].ex(m)
				m = a[k].ex(m)
				m = a[l].ex(m)
				
				try:
					int(m)
					print('YES')
					judge = True
				except:
					pass
				if judge == True:break
			if judge==True:break
		if judge==True:break
	if judge==True:break
	
if judge == False:
	print('NO')

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

Solution (Python):

S = input()
S = S.replace('dream','A').replace('erase','B')
S = S.replace('Aer','C').replace('Br','D')

E = set()

for s in S:
    E.add(s)

ans = 'YES'
for e in E:
    if not e in ('A','B','C','D'):
        ans = 'NO'
        break
print(ans)

Solution (Python):
st = input()
start = 0
ok = True
while start < len(st):
    if st[start] == 'd':
        if st[start: start + 5] == 'dream':
            if st[start: start + 7] == 'dreamer':
                if st[start: start + 11] == 'dreameraser':
                    start += 11
                elif st[start: start + 10] == 'dreamerase':
                    start += 10
                else:
                    start += 7
            else:
                start += 5
        else:
            ok = False
            break
    elif st[start] == 'e':
        if st[start: start + 5] == 'erase':
            if st[start: start + 6] == 'eraser':
                start += 6
            else:
                start += 5
        else:
            ok = False
            break
    else:
        ok = False
        break
if ok:
    print("YES")
else:
    print("NO")

Solution (Python):
S = input()

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

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

Solution (Python):
S=list(input())
l=0
while l!=len(S):
  l=len(S)
  if S[-1]=='m' and S[-2]=='a' and S[-3]=='e' and S[-4]=='r' and S[-5]=='d':
    del S[-5:]
  if len(S)==0:
    break
  if S[-1]=='e' and S[-2]=='s' and S[-3]=='a' and S[-4]=='r' and S[-5]=='e':
    del S[-5:]
  if len(S)==0:
    break
  if S[-1]=='r' and S[-2]=='e' and S[-3]=='s' and S[-4]=='a' and S[-5]=='r' and S[-6]=='e':
    del S[-6:]
  if len(S)==0:
    break
  if S[-1]=='r' and S[-2]=='e' and S[-3]=='m' and S[-4]=='a' and S[-5]=='e' and S[-6]=='r' and S[-7]=='d':
    del S[-7:]
  if len(S)==0:
    break

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

Solution (Python):
S = input().replace("eraser", "4").replace("erase", "3").replace("dreamer", "2").replace("dream", "1")
try:
    int(S)
    print("YES")
except:
    print("NO")

Solution (Python):
S = input().replace("eraser", "4").replace("erase", "3").replace("dreamer", "2").replace("dream", "1")
try:
    int(S)
    print("YES")
except:
    print("NO")

Solution (Python):
def f1():
    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')
            return
    print('YES')

if __name__ == "__main__":
    f1()

Solution (Python):
s = input()

s1 = " ".join(s.split('dreameraser'))

s2 = " ".join(s1.split('dreamerase'))

s3 = " ".join(s2.split('dreamer'))

s4 = " ".join(s3.split('dream'))

s5 = " ".join(s4.split('eraser'))

s6 = " ".join(s5.split('erase'))


if s6.strip() == '':
    print('YES')
else:
    print('NO')

Solution (Python):
if __name__ == "__main__":
    s = input()
    words = ["dream", "dreamer", "erase", "eraser"]
    while len(s) > 0:
        if s[-5:] in ["dream", "erase"]:
            s = s[:-5]
        elif s[-7:] == "dreamer":
            s = s[:-7]
        elif s[-6:] == "eraser":
            s = s[:-6]
        else:
            print("NO")
            break
    if not len(s):
        print("YES")

Solution (Python):


def main():
    s = input()

    i = 0
    is_ok = True
    while i < len(s):
        if i <= len(s) < i + 7:
            if i <= len(s) < i + 4:
                is_ok = False
                break

        next_word = s[i:i+5]
        if next_word == 'dream':
            if s[i+5:i+7] == 'er':
                if s[i+7:i+8] == 'a':
                    
                    i += 5
                else:
                    
                    i += 7
            else:
                
                i += 5
        elif next_word == 'erase':
            if s[i+5:i+6] == 'r':
                
                i += 6
            else:
                
                i += 5
        else:
            is_ok = False
            break

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

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


if __name__ == '__main__':
    
    main2()

Solution (Python):


def main():
    s = input()

    i = 0
    is_ok = True
    while i < len(s):
        if i <= len(s) < i + 7:
            if i <= len(s) < i + 4:
                is_ok = False
                break

        next_word = s[i:i+5]
        if next_word == 'dream':
            if s[i+5:i+7] == 'er':
                if s[i+7:i+8] == 'a':
                    
                    i += 5
                else:
                    
                    i += 7
            else:
                
                i += 5
        elif next_word == 'erase':
            if s[i+5:i+6] == 'r':
                
                i += 6
            else:
                
                i += 5
        else:
            is_ok = False
            break

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

if __name__ == '__main__':
    main()

Solution (Python):
s=str(input())
def solve(s):
  while (s!=""):
    if s[-5:] in ["dream","erase"]:
      s=s[:-5]
    elif s[-7:]=="dreamer":
      s=s[:-7]
    elif s[-6:]=="eraser":
      s=s[:-6]
    else:
      return "NO"
  return "YES"
print(solve(s))

Solution (Python):
S = input()
U = S
T = ""
while True:
    flag = False
    for s in ["dream", "dreamer","erase","eraser"]:
        if S.endswith(s):
            S = S[:-len(s)]
            T = s + T
            flag = True
    if T == U:
        print("YES")
        break 
    elif not flag:
        print("NO")
        break

Solution (Python):
S = input()
c = ["dream","dreamer","erase","eraser"]

S = S[::-1]
c = [cc[::-1] for cc in c]

i=0
while i < len(c):
    if S.startswith(c[i]):
        S = S[len(c[i]):]
        i = 0
        continue
    i = -~i

print("NYOE S"[S==""::2])

Solution (Python):
S = input()
c = ["dream","dreamer","erase","eraser"]

S = S[::-1]
c = [cc[::-1] for cc in c]

i=0
while i < len(c):
    if S[:len(c[i])] == c[i]:
        S = S[len(c[i]):]
        i = 0
        continue
    i += 1

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

Solution (Python):
s = input()
s = s[::-1]
li = ['maerd','remaerd','esare','resare']
check=''
for i in range(len(s)):
    check += s[i]
    if check in li:
        check=''
print('YES' if len(check)==0 else 'NO')

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

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

s = s[::-1]
words = [word[::-1] for word in words]

start=0
for i in range(1, len(s)+1):
  if s[start:i] in words:
    t+=s[start:i]
    start=i
    
if s==t:
  print('YES')
else:
  print('NO')

Solution (Python):
S = [input()]
ans = 'NO'
while S:
    S_new = []
    for s in S:
        if s[:5]=='dream'  : S_new.append(s[5:])
        if s[:7]=='dreamer': S_new.append(s[7:])
        if s[:5]=='erase'  : S_new.append(s[5:])
        if s[:6]=='eraser' : S_new.append(s[6:])
    S = S_new
    if '' in S:
        ans = 'YES'
        break

print(ans)

Solution (Python):
S = input()
reverse_S = S[::-1]
T = ""
dreamlist = ["erase","eraser","dream","dreamer"]
newlist = [dreamlist[i][::-1] for i in range(len(dreamlist))]

flg = 1
while flg >= 1:
    flg = 0
    for i in range(len(newlist)):
        if reverse_S.startswith(T + newlist[i]):
            T += newlist[i]
            flg += 1
            break
        else:
            continue
if reverse_S == T:
    print("YES")
else:
    print("NO")

Solution (Python):
l=list(input())
a=[list('dream'),list('erase')]
b=[list('eraser')]
c=[list('dreamer')]
n=len(l)
r=0
while n>=5:
    f=0
    if n>=7:
        if l[len(l)-5:] in a:
            l[len(l)-5:]=[]
            n-=5
            f+=1
        if l[len(l)-6:] in b:
            l[len(l)-6:]=[]
            n-=6
            f+=1
        if l[len(l)-7:] in c:
            l[len(l)-7:]=[]
            n-=7
            f+=1
    elif n>=6:
        if l[len(l)-5:] in a:
            l[len(l)-5:]=[]
            n-=5
            f+=1
        if l[len(l)-6:] in b:
            l[len(l)-6:]=[]
            n-=6
            f+=1
    elif n>=5:
        if l[len(l)-5:] in a:
            l[len(l)-5:]=[]
            n-=5
            f+=1
    if f==0:
        r=1
        break
if r==1 or n>0:
    print('NO')
else:
    print('YES')

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    s = s.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
    print("YES" if s == "" else "NO")


if __name__ == '__main__':
    slove()

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

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

Solution (Python):
def main():
    S = input()[::-1]
    tar = {'maerd', 'remaerd', 'esare', 'resare'}
    i = 0
    while i < len(S):
        if S[i] == 'm':
            if S[i:i+5] == 'maerd':
                i += 5
            else:
                return print("NO")
        elif S[i] == 'e':
            if S[i:i+5] == 'esare':
                i += 5
            else:
                return print("NO")
        elif S[i] == 'r':
            if S[i:i+6] == 'resare':
                i += 6
            elif S[i:i+7] == 'remaerd':
                i += 7
            else:
                return print("NO")
        else:
            return print("NO")
    print("YES")
if __name__ == '__main__':
    main()

Solution (Python):
import sys

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

if len(s) == 0:
    print('YES')
    sys.exit()

words = ['maerd', 'remaerd', 'esare', 'resare']
can = True

while can:
    can = False
    for word in words:
        if s.startswith(word):
            s = s[len(word):]
            can = True

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

Solution (Python):
S = list(input())
tmp = ''
L = len(S)
S = S[-1:-L-1:-1]
Kouho = ['maerd','remaerd','esare','resare']
ans = 0
for i in range(L):
    
    tmp += str(S[i])
    if tmp in Kouho:
        ans += len(tmp)
        tmp = ''
if ans == L:
    print('YES')
else:
    print('NO')

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

Solution (Python):

import sys

YES = "YES"  
NO = "NO"  


def solve(S: str):
    S = S.replace('eraser', '')
    S = S.replace('erase', '')
    S = S.replace('dreamer', '')
    S = S.replace('dream', '')
    print(YES if S == '' else NO)
    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):
T = str(input())
cdd =["dream","dreamer","erase","eraser"]

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

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

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

Solution (Python):
s=input()
i=len(s)
ans=True
while 3<=i:
    if s[i-7:i]=='dreamer':
        i-=7
    elif s[i-5:i]=='dream':
        i-=5
    elif s[i-6:i]=='eraser':
        i-=6
    elif s[i-5:i]=='erase':
        i-=5
    else:
        ans=False
        break
if ans:
    print('YES')
else:
    print('NO')

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