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()
pat_list = ["dream","dreamer","erase","eraser"]

while 1:
    flag=0
    for p in pat_list:
        if s.endswith(p):
            flag=1
            s = s[:-len(p)]
    if not s:
        print("YES")
        break
    if not flag:
        print("NO")
        break

Solution (Python):
s = input()

while len(s) > 7:
  if s[-5:] in ["dream", "erase"]:
    s = s[:-5]
  elif s[-6:] in ["eraser"]:
    s = s[:-6]
  elif s[-7:] in ["dreamer"]:
    s = s[:-7]
  else:
    break

if (len(s)==5 and s in ["dream", "erase"]) or (len(s)==6 and s in ["eraser"]) or (len(s)==7 and s in ["dreamer"]):
  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):
S = list(input())
S.reverse()

D = [['m','a','e','r','d'],['r','e','m','a','e','r','d'],['e','s','a','r','e'],['r','e','s','a','r','e']]
can = True

while len(S) != 0:
    can2 = False
    for i in range(4):
        d = D[i]
        if S[:len(d)] == d:
            can2 = True
            for j in range(len(d)):
                S.pop(0)
            break
    if can2 == False:
        can = False
        break

if can == True:
    print('YES')
elif can == False:
    print('NO')

Solution (Python):
s = ''.join(list(reversed(input())))
t = ''

while True:
    n = len(t)
    if len(s) <= n:
        if s == t:
            print('YES')
        else:
            print('NO')
        break
    if s[n] == 'm':
        t += ''.join(list(reversed('dream')))
    elif s[n] == 'e':
        t += ''.join(list(reversed('erase')))
    elif s[n:n+3] == 'rem':
        t += ''.join(list(reversed('dreamer')))
    elif s[n:n+3] == 'res':
        t += ''.join(list(reversed('eraser')))
    else:
        print('NO')
        break

Solution (Python):
s = input()
s_reverse = ''.join(list(reversed(s)))
t = ''

while True:
    n = len(t)
    if len(s) <= n:
        if s_reverse == t:
            print('YES')
        else:
            print('NO')
        break
    if s_reverse[n] == 'm':
        t += ''.join(list(reversed('dream')))
    elif s_reverse[n] == 'e':
        t += ''.join(list(reversed('erase')))
    elif s_reverse[n:n+3] == 'rem':
        t += ''.join(list(reversed('dreamer')))
    elif s_reverse[n:n+3] == 'res':
        t += ''.join(list(reversed('eraser')))
    else:
        print('NO')
        break

Solution (Python):
s = input()
s_reverse = ''.join(list(reversed(s)))
t = ''

while True:
    n = len(t)
    if s_reverse == t:
        print('YES')
        break
    if len(s) <= n:
        print('NO')
        break
    if s_reverse[n] == 'm':
        t += ''.join(list(reversed('dream')))
    elif s_reverse[n] == 'e':
        t += ''.join(list(reversed('erase')))
    elif s_reverse[n:n+3] == 'rem':
        t += ''.join(list(reversed('dreamer')))
    elif s_reverse[n:n+3] == 'res':
        t += ''.join(list(reversed('eraser')))
    else:
        print('NO')
        break

Solution (Python):
lt = ["dream", "dreamer", "erase", "eraser"]
s = input()

lt = [w[::-1] for w in lt]
s = s[::-1]
cond = True
i = 0
while i < len(s):
    for t in lt:
        if s[i:].startswith(t):
            i += len(t)
            break
    else:
        cond = False
        break

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

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

index=0
words=["dream","dreamer","erase","eraser"]
for i in range(4):
    words[i]=words[i][::-1]

while index<N:
    word1=S[index:index+5]
    word2=S[index:index+6]
    word3=S[index:index+7]
    if word1 in words:
        index+=5
    elif word2 in words:
        index+=6
    elif word3 in words:
        index+=7
    else:
        print("NO")
        exit()
print("YES")

Solution (Python):
S = input()
li = ['dream','dreamer','erase','eraser']
li_len=[5,7,5,6]

while S:
    for i,moji in enumerate(li):
        if S[-li_len[i]:] == moji:
            S = S[:-li_len[i]]
            break
    else:
        print('NO')
        break
if not S:print('YES')

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

Solution (Python):
s=input()
while 1:
    n = len(s)
    if n==0:
        print("YES")
        exit()
    elif 1<=n<=4:
        print("NO")
        exit()
    else:
        if s[n-5:n]=="dream" or s[n-5:n]=="erase":
            s=s[:n-5]
        elif s[n-6:n]=="eraser":
            s=s[:n-6]
        elif s[n-7:n]=="dreamer":
            s=s[:n-7]
        else:
            print("NO")
            exit()

Solution (Python):
import re
print('NYOE S'[bool(re.match('^(dream|dreamer|erase|eraser)+$',input()))::2])

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

Solution (Python):
words = {"resare" , "esare" , "remaerd" , "maerd",""}
s = input()
n = len(s)
now=""
f=0
s=s[::-1]
for i in range(0 ,n):
	now = now+s[i]
	if now in words:
		now = ""
if now in words:
	print("YES")
else:
	print("NO")

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:
        print("NO")
        exit()

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

Solution (Python):
from sys import stdin
import sys

s = stdin.readline().rstrip()

A = 'dream'
B = 'dreamer'
C = 'erase'
D = 'eraser'

s = s[::-1]
A = A[::-1]
B = B[::-1]
C = C[::-1]
D = D[::-1]

while True:
    if len(s) >= 5 and s[:5] == A:
        s = s[5:]
    elif len(s) >= 7 and s[:7] == B:
        s = s[7:]
    elif len(s) >= 5 and s[:5] == C:
        s = s[5:]
    elif len(s) >= 6 and s[:6] == D:
        s = s[6:]
    else:
        print("NO")
        sys.exit()

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

Solution (Python):
S = input()

words = ["dream", "dreamer", "erase", "eraser"]
S_rv = S[::-1]
words_rv = [word[::-1] for word in words]

for i in range(len(S_rv)):
    for word_rv in words_rv:
        if S_rv[: len(word_rv)] == word_rv:
            S_rv = S_rv[len(word_rv) :]

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

Solution (Python):
WORDS = ['dream', 'dreamer', 'erase', 'eraser']
REVERSED_WORDS = [word[::-1] for word in WORDS]


def main(s):
    i = 0
    while i < len(s):
        for word in REVERSED_WORDS:
            if s[i:].startswith(word):
                i += len(word)
                break
        else:
            print('NO')
            break
    else:
        print('YES')


if __name__ == "__main__":
    main(input()[::-1])

Solution (Python):
S = input()
s = S[::-1]
a = "dream"[::-1]
b = "dreamer"[::-1]
c = "erase"[::-1]
d = "eraser"[::-1]

idx = 0
ans = "YES"
while idx < len(s):
    if s[idx] == "m":
        if s[idx : idx + 5] == a:
            idx = idx + 5
        else:
            ans = "NO"
            break

    elif s[idx] == "e":
        if s[idx : idx + 5] == c:
            idx = idx + 5
        else:
            ans = "NO"
            break

    elif s[idx] == "r":
        if s[idx : idx + 7] == b:
            idx = idx + 7
        elif s[idx : idx + 6] == d:
            idx = idx + 6
        else:
            ans = "NO"
            break

    else:
        ans = "NO"
        break

print(ans)

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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

    S = S[::-1]
    word = ['dream', 'dreamer', 'erase', 'eraser']
    word = [w[::-1] for w in word]

    ok = True
    i = 0
    while i < len(S):
        j = i
        for w in word:
            if all(w[j] == S[i + j] for j in range(len(w))):
                j += len(w)
                break
        if i == j:
            ok = False
            break
        i = j

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

    return


if __name__ == '__main__':
    main()

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

s = ['dream','dreamer','erase','eraser'] 
s = [_[::-1] for _ in s]

idx = 0
ans='YES'
while idx < len(S):
    if S[idx] == 'm':
        if S[idx:idx+5] == s[0]:
            idx=idx+5
        else:
            ans='NO'
            break
        
    elif S[idx] == 'e':
        if S[idx:idx+5] == s[2]:
            idx=idx+5
        else:
            ans='NO'
            break
        
    elif S[idx] == 'r':
        if S[idx:idx+7] == s[1]:
            idx=idx+7
        elif S[idx:idx+6] == s[3]:
            idx=idx+6
        else:
            ans='NO'
            break
        
    else:
        ans='NO'
        break
        
print(ans)

Solution (Python):
s=input()
n=len(s)
dp=[False]*(n+1)
c=["dream","dreamer","erase","eraser"]
if s[:5] in c:
    dp[5]=True
if s[:6] in c:
    dp[6]=True
if s[:7] in c:
    dp[7]=True
for i in range(n+1):
    if dp[i]:
        l=""
        if i+5<=n:
            for idx in range(5):
                l+=s[i+idx]
            if l in c:
                dp[i+5]=True
        if i+6<=n:
            l+=s[i+5]
            if l in c:
                dp[i+6]=True
        if i+7<=n:
            l+=s[i+6]
            if l in c:
                dp[i+7]=True

if dp[n]:
    print("YES")
else:
    print("NO")

Solution (Python):
S = input()
C = ["maerd","remaerd","esare","resare"]
ans = ""
a = "YES"
x = len(S)
for i in range(x):
    ans = ans + S[x - 1 -i]
    if ans == C[0]:
        ans = ""
    elif ans == C[1]:
        ans = ""
    elif ans == C[2]:
        ans = ""
    elif ans == C[3]:
        ans = ""
if len(ans) != 0:
    a = "NO"
print(a)

Solution (Python):
import re
S = input()
'''
メタ文字：
^ = 文字列の先頭、
| = OR
+ = 直前のパターンを1回以上繰り返し、
$ = 文字列の末尾
'''
if re.match("^(dream|dreamer|erase|eraser)+$", S):
    print('YES')
else:
    print('NO')

Solution (Python):
I = input()

import re
if re.match("^(dream|dreamer|erase|eraser)+$", I):
    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
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = input()
    words = ["dream","erase"]
    wordsr = ["dreamer", "eraser"]
    while s:
        if s[-7:] == "dreamer":
            s = s[:-7]
        elif s[-6:] == "eraser":
            s = s[:-6]
        elif s[-5:] in words:
            s = s[:-5]
        else:
            print('NO')
            sys.exit()
    print('YES')


if __name__ == '__main__':
    main()

Solution (Python):
st = input()
S = st[::-1]
words ={"remaerd","resare","maerd","esare"}

lenT = 0
flag = 0
ans = "NO"

while flag < 5:
  for i in range(5, 8):
    if S[0:i] in words:
      S = S[i:]
      flag = 0
      
    elif S == "":
      flag = 5
      ans = "YES"
      break
    else:
      flag += 1
    
print(ans)

Solution (Python):
s = input()

s = s[::-1]
lis = ['dreamer', 'dream', 'eraser', 'erase']
nlis = []
for i in lis:
    nlis.append(i[::-1])


for i in range(10**5 + 1):
    for j in nlis:
        if s.startswith(j):
            s = s[len(j):]


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

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

f = True
while f:
    os = s
    for i in a:
        if s.endswith(i):
            s = s[:-len(i)]
            if len(s) == 0:
                print("YES")
                f = False
    if len(os) == len(s):
        print("NO")
        f = False

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

Solution (Python):
s = input()

tmp = ""
cnt = 0
for c in reversed(s):
  tmp = c + tmp
  if tmp in ["dream", "dreamer", "erase", "eraser"]:
    cnt += len(tmp)
    tmp = ""
    
if cnt == len(s):
  print("YES")
else:
  print("NO")

Solution (Python):
S=input()
N=len(S)

idx=N-1
ans="YES"
while idx>=0:
    now=S[idx]
    if now=="m":
        if S[idx-4:idx+1]!="dream":
            ans="NO"
            break
        else:idx-=5
    elif now=="e":
        if S[idx-4:idx+1]!="erase":
            ans="NO"
            break
        else:idx-=5
    elif now=="r":
        if S[idx-5:idx+1]=="eraser":
            idx-=6
        elif S[idx-6:idx+1]=="dreamer":
            idx-=7
        else:
            ans="NO"
            break
print(ans)

Solution (Python):

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

Solution (Python):
input_str = input()

while(True):
  if input_str[0:11] == "dreameraser":
    input_str = input_str[11:]
  elif input_str[0:10] == "dreamerase":
    input_str = input_str[10:]
  elif input_str[0:7] == "dreamer":
    input_str = input_str[7:]
  elif input_str[0:6] == "eraser":
    input_str = input_str[6:]
  elif input_str[0:5] == "dream" or input_str[0:5] == "erase":
    input_str = input_str[5:]
  else:
    print("NO")
    break
  
  if len(input_str) == 0:
    print("YES")
    break

Solution (Python):








S = input()
def calculate(s):

    index = 0
    isOK = True
    while index < len(s):

        
        p1 = s[index:index + 11]
        if p1 == 'dreameraser':
            index += 11
            continue
        

        p2 = s[index:index + 10]
        if p2 == 'dreamerase':
            index += 10
            continue

        s1 = s[index:index+7]

        if s1 == 'dreamer':
            index += 7
            continue

        s2 = s[index:index+6]

        if s2 == 'eraser':
            index += 6
            continue

        s3 = s[index:index+5]

        if s3 == 'erase':
            index += 5
            continue

        if s3 == 'dream':
            index += 5
            continue

        isOK = False
        break

    if isOK:
        print("YES")
    else:
        print("NO")
calculate(S)

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

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

Solution (Python):
s = input()[::-1]
a = "maerd"
b = "remaerd"
c = "esare"
d = "resare"
while len(s)!=0:
  if s[:5]==a:
    s = s[5:]
  elif s[:7]==b:
    s = s[7:]
  elif s[:5]==c:
    s = s[5:]
  elif s[:6]==d:
    s = s[6:]
  else:
    print("NO")
    exit()
print("YES")

Solution (Python):
s=input()
a=["dreamer", "dream", "eraser", "erase"]
while s:
  for i in a:
    k=len(i)
    if s[-k:]==i:
      s=s[:-k]
      break
  else:
  	break

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')







def solve():
    S = input()[::-1]

    flag = True
    while S:
        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:]
        else:
            flag = False
            break

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

if __name__ == '__main__':
    solve()

Solution (Python):
import re
S = input()

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

Solution (Python):
import re
S = input()

if re.match("^(dream|dreamer|erase|eraser)+$", S):
    print('YES')
else:
    print('NO')

Solution (Python):
import re
S = input()
'''
メタ文字：
^ = 文字列の先頭、
| = OR
+ = 直前のパターンを1回以上繰り返し、
$ = 文字列の末尾
'''
if re.match("^(dream|dreamer|erase|eraser)+$", S):
    print('YES')
else:
    print('NO')

Solution (Python):
from collections import deque
import sys

def fnw(n,s):
    sm=deque([])
    if n<=len(s):
        for _ in range(n):
            sm.append(s.popleft())
    return ''.join(sm)

def jfws(s):
    fws=fnw(5,s)
    if fws=='dream':
        fws=fnw(2,s)
        if fws=='er':
            if s:
                if s[0]=='a':
                    s.extendleft(deque(reversed(list(fws))))
        else:
            s.extendleft(deque(reversed(list(fws))))
        return False
    elif fws=='erase':
        fws=fnw(1,s)
        if fws!='r' and fws!='':
            s.appendleft(fws)
        return False
    else:
        return True 

def main(s):
    while s:
        if jfws(s):
            return 'NO'
    return 'YES'

s=deque(sys.stdin.readline().strip())
print(main(s))

Solution (Python):
from collections import deque
import sys

def fnw(n,s):
    sm=deque([])
    if n<=len(s):
        for _ in range(n):
            sm.append(s.popleft())
    return sm

def jfws(s):
    
    sm=fnw(5,s)
    
    if ''.join(sm)=='dream':
        sm=fnw(2,s)
        if ''.join(sm)=='er':
            if bool(s):
                if s[0]=='a':
                    s.extendleft(deque(reversed(list(sm))))
        else:
            s.extendleft(deque(reversed(list(sm))))
        return False
    elif ''.join(sm)=='erase':
        sm=fnw(1,s)
        if ''.join(sm)!='r':
            s.extendleft(sm)
        return False
    else:
        return True 

def main(s):
    while len(s)>0:
        if jfws(s):
            return 'NO'
    return 'YES'

s=deque(sys.stdin.readline().strip())
print(main(s))

Solution (Python):
S = input()
n = len(S)
T = ['dreamer', 'eraser', 'dream', 'erase']
idx = n
res = 'YES'
while idx > 0:
    for t in T:
        if S[idx-len(t):idx] == t:
            idx -= len(t)
            break
    else:
        res = 'NO'
        idx = -1
print(res)

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

cand = {'maerd', 'remaerd', 'esare', 'resare'}

res = 'YES'

while len(S):
    orig = S
    for w in cand:
        if S.startswith(w):
            S = S[len(w):]
    if orig == S:
        res = 'NO'
        break

print(res)

Solution (Python):
s=input()
t=""
w=["dreameraser","dreamerase","dreamer","dream","eraser","erase"]
for i in range(10**5):
    for j in range(6):
        temp=t
        temp+=w[j]
        if temp[len(t):len(temp)]==s[len(t):len(temp)]:
                t+=w[j]
                break
    if s==t:
        print("YES")
        exit()
print("NO")
exit()

Solution (Python):
S = list(input())
S.reverse()
S = ''.join(S)
idx = 0
len_S = len(S)
flag = True
while idx != len_S:
    if (len_S - idx > 6) and (S[idx:idx+7] == 'remaerd'):
        idx += 7
    elif (len_S - idx > 5) and (S[idx:idx+6] == 'resare'): 
        idx += 6
    elif (len_S - idx > 4) and (S[idx:idx+5] == 'maerd'): 
        idx += 5
    elif (len_S - idx > 4) and (S[idx:idx+5] == 'esare'): 
        idx += 5
    else:
        flag = False
        break

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

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()

    S = S[::-1]
    idx = 0
    ans = "YES"
    while idx <= len(S) - 1:
        is_ok = False
        if S[idx:idx + 5] in ("maerd", "esare"):
            is_ok = True
            idx += 5
        if S[idx:idx + 6] == "resare":
            is_ok = True
            idx += 6
        if S[idx:idx + 7] == "remaerd":
            is_ok = True
            idx += 7

        if not is_ok:
            ans = "NO"
            break

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
S = input()

check = ('dream','dreamer','erase','eraser')

index = len(S) + 1
flag = True

while True:
    if len(S) == 0:
        break
    for c in check:
        if S[-len(c):] in check:
            S = S[:-len(c)]
            break
    else:
        flag = False
        break

print('YES' if flag else 'NO')

Solution (Python):

import re

s = input()
s = "".join(s.split("eraser"))
s = "".join(s.split("erase"))
s = "".join(s.split("dreamer"))
s = "".join(s.split("dream"))

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

Solution (Python):
s = input()[::-1]
ls = ['dream', 'dreamer', 'erase', 'eraser']
ls = [ls[i][::-1] for i in range(4)]
ans = 'YES'
i = 0
while i < len(s):
    ng = 1
    for j in range(4):
        if s[i:i+len(ls[j])] == ls[j]:
            i += len(ls[j])
            ng = 0
    if ng:
        ans = 'NO'
        break
print(ans)

Solution (Python):
import re
s = input()
s = s[::-1]

match = re.match('((remaerd)|(maerd)|(resare)|(esare))*',s)


if match.group() == s:
    print('YES')
else:
    print('NO')

Solution (Python):
S = input()
words = ["dream", "dreamer", "erase", "eraser"]
while len(S) > 0:
    flag = True
    for word in words:
        if S.endswith(word):
            flag = False
            S = S[:-len(word)]
    if flag:
        print("NO")
        exit(0)
print("YES")

Solution (Python):
def solve():
    S = input()
    idx = len(S)
    while idx-5 >= 0:
        if S[idx-5:idx] in ["dream","erase"]:
            idx -= 5
        elif idx-6 >= 0 and S[idx-6:idx] == "eraser":
            idx -= 6
        elif idx-7 >=0 and S[idx-7:idx] == "dreamer":
            idx -= 7
        else:
            print('NO')
            return
    else:
        if idx == 0:
            print('YES')
        else:
            print('NO')

if __name__ == '__main__':
    solve()

Solution (Python):
s=input()[::-1]
a=["dreamer"[::-1],"eraser"[::-1],"dream"[::-1],"erase"[::-1]]
st=1
en=0
while st>en:
  st=len(s)
  for m in a:
    
    if s.find(m)==0:
      s=s[len(m):]
    
  en=len(s)
  
print("YES" if s=="" else "NO")

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=SI()
s=s[::-1]
i=0
while i<len(s):
    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:
        print("NO")
        sys.exit()
print("YES")

Solution (Python):
import sys
from collections import defaultdict, deque, Counter
import math
 

from bisect import bisect_left, bisect_right

 

 

input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
 
def main():
    S = list(getS())
    tgt5 = [list(s) for s in ["dream", "erase"]]
    tgt6 = [list(s) for s in ["eraser"]]
    tgt7 = [list(s) for s in ["dreamer"]]
    dp = [0 for i in range(len(S)+1)]
    dp[0] = 1
    for i, c in enumerate(S):
        if dp[i] == 1:
            for tg in tgt5:
                if S[i: i+5] == tg and i+5 <= len(S):
                    dp[i+5] = 1
            for tg in tgt6:
                if S[i: i+6] == tg and i+6 <= len(S):
                    dp[i+6] = 1
            for tg in tgt7:
                if S[i: i+7] == tg and i+7 <= len(S):
                    dp[i+7] = 1

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

    return


 
if __name__ == "__main__":
    main()

Solution (Python):
s = list(input())
tes = ''
tes2 = ''
tes3 = []
res = 1
tr = -1
for i in range(len(s)) :
    tes += s[i]
    if tes == 'dream' or tes == 'erase' or tes == 'dreamer' or tes == 'eraser' :
        for j in range(i+1,len(s)):
            tes2 += s[j]
            if tes2 == 'dream' or tes2 == 'erase' :
                tr = 1
                
                
                tes2 = ''
                break
            elif len(tes2) >= 7 or j == len(s)-1 :
                tr = 0
                
                
                tes2 = ''
                break
        if tr == 1:
            
            tes3.append(tes)
            tes = ''

            

    elif len(tes) > 7:
        res = 0
        break
        



if tes == 'dream' or tes == 'erase' or tes == 'dreamer' or tes == 'eraser':
    tes3.append(tes)
    tes = ''

if  len(tes3) > 0 and len(tes) == 0 :
    print('YES')
else :
    print('NO')

Solution (Python):
import re

s = input()

if re.fullmatch(r"(dream|dreamer|erase|eraser)+", s):
    print("YES")
else:
    print("NO")

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

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

print("YES")

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

ans = ""
i = 0
for _ in range(n):
    if i > n or ans == s: break
    if s[i:i+5] == "erase":
        i += 5
        ans += "erase"
        if s[i:i+1] == "r":
            i += 1
            ans += "r"
    elif s[i:i+5] == "dream":
        i += 5
        ans += "dream"
        if s[i:i+3] == "era": continue
        elif s[i:i+2] == "er":
            i += 2
            ans += "er"
print("YES" if ans == s else "NO")

Solution (Python):
S = input().strip()
N = len(S)
if N<5:
    print("NO")
else:
    flag = 0
    cur = N
    while cur>0:
        if cur>=7 and S[cur-7:cur]=="dreamer":
            cur -= 7
        elif cur>=6 and S[cur-6:cur]=="eraser":
            cur -= 6
        elif cur>=5 and S[cur-5:cur] in ["dream","erase"]:
            cur -= 5
        else:
            flag = 1
            break
    if flag==0:
        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):
S = input()[::-1]
W = ['dream','dreamer','erase','eraser']
i = 0
while i < len(S):
    for w in W:
        if S[i:i+len(w)] == w[::-1]:
            i += len(w)
            break
    else:
        print('NO')
        exit()
print('YES')

Solution (Python):
def check():
  S = input()
  n = len(S)
  dp = [False]*(n+10)
  dp[0] = True
  for i in range(n+1):
    if S[i:i+5]=='dream':
      dp[i+5] |= dp[i]
    if S[i:i+7]=='dreamer':
      dp[i+7] |= dp[i]
    if S[i:i+5]=='erase':
      dp[i+5] |= dp[i]
    if S[i:i+6]=='eraser':
      dp[i+6] |= dp[i]
  if dp[n]==True:
    return 'YES'
  return 'NO'
print(check())

Solution (Python):
s = str(input())
t = s.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if 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):
import re
s=input()
if re.match(r"(dream|dreamer|erase|eraser)+$",s):
    print("YES")
else:
    print("NO")

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    S = in_s()
    S = S.replace('eraser', '')
    S = S.replace('erase', '')
    S = S.replace('dreamer', '')
    S = S.replace('dream', '')

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


if __name__ == '__main__':
    main()

Solution (Python):
S = input ()
Z = ''.join(list(reversed(S)))
Z = Z.replace('resare', '')
Z = Z.replace('esare', '')
Z = Z.replace('remaerd', '')
Z = Z.replace('maerd', '')
z = len (Z)
if z == 0:
    print ('YES')
else:
    print ('NO')

Solution (Python):
s=input()

ans=0
while s!="":
    
    if s[-6:] =="eraser":
        s=s[:-6]
        
    elif s[-5:]=="dream":
        s=s[:-5]
        
    elif s[-7:]=="dreamer":
        s=s[:-7]
        
    elif s[-5:]=="erase":
        s=s[:-5]
        
    else:
        ans=1
        print("NO")
        break

if ans==0:
    print("YES")

Solution (Python):


import re

s = input()

print(
  "YES" if re.match("(dream|dreamer|erase|eraser)+$", s)
  else "NO"
)

Solution (Python):


s = input()[::-1]

cnt = 0
while cnt < len(s):
  if not s[cnt:cnt+7] == "remaerd":
    if not s[cnt:cnt+6] == "resare":
      if not s[cnt:cnt+5] in ["maerd", "esare"]:
        print("NO")
        exit()
      else:
        cnt += 5
    else:
      cnt += 6
  else:
    cnt += 7
print("YES")

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):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



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

a = "dream"
b = "dreamer"
c = "erase"
d = "eraser"

while len(S) > 0:
    if S[:5] == a[::-1] or S[:5] == c[::-1]:
        S = S[5:]
    elif S[:6] == d[::-1]:
        S = S[6:]
    elif S[:7] == b[::-1]:
        S = S[7:]
    else:
        print("NO")
        exit()
print("YES")

Solution (Python):

S=input()

N=len(S)
dp=[0]*(N+1)
dp[0]=1
L=["dream", "dreamer", "erase", "eraser"]
for i in range(1,N+1):
    for l in L:
        n=len(l)
        if 0<=i-n<N:
            if S[i-n:i]==l and dp[i-n]:
                dp[i]=1

if dp[-1]:
    print("YES")
else:
    print("NO")

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