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 = list(input())
s.append(0)
s.append(0)
s.append(0)
l =len(s)
while l>3:
    if s[0]=="d" and s[1]=="r" and s[2]=="e" and s[3]=="a" and s[4]=="m" and s[5]=="e" and s[6]=="r":
        if s[7]=="a":
            del s[0]
            del s[0]
            del s[0]
            del s[0]
            del s[0]
            l =len(s)
        else:
            del s[0]
            del s[0]
            del s[0]
            del s[0]
            del s[0]
            del s[0]
            del s[0]
            l =len(s)          
    elif s[0]=="d" and s[1]=="r" and s[2]=="e" and s[3]=="a" and s[4]=="m":
      del s[0]
      del s[0]
      del s[0]
      del s[0]
      del s[0]
      l =len(s)                    
    elif s[0]=="e" and s[1]=="r" and s[2]=="a" and s[3]=="s" and s[4]=="e" and s[5]=="r":
      del s[0]
      del s[0]
      del s[0]
      del s[0]
      del s[0]
      del s[0]
      l =len(s)
    elif s[0]=="e" and s[1]=="r" and s[2]=="a" and s[3]=="s" and s[4]=="e":
      del s[0]
      del s[0]
      del s[0]
      del s[0]
      del s[0]
      l =len(s)
    else:
        print("NO")
        break
if s[0]==0:
    print("YES")

Solution (Python):
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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


if __name__ == '__main__':
    main()

Solution (Python):
s=list(input())
s=s[::-1]
start=0
def find(s,start):
    if len(s)-start>=5 and (s[start:start+5]==list("maerd") or s[start:start+5]==list("esare")):
        start=start+5
        return(start,0)
    elif len(s)-start>=6 and s[start:start+6]==list("resare"):
        start=start+6
        return(start,0)
    elif len(s)-start>=7 and s[start:start+7]==list("remaerd"):
        start=start+7
        return(start,0)
    elif len(s)-start==0:
        return(start,1)
    else:
        return(start,2)
shori=0
while shori==0:
    (start,shori)=find(s,start)
if shori==1:
    print("YES")
else:
    print("NO")

Solution (Python):
import sys
S = input()[::-1]
t = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
while len(S) > 0:
    if S[:5] == t[0]:
        S = S[5:]
    elif S[:7] == t[1]:
        S = S[7:]
    elif S[:5] == t[2]:
        S = S[5:]
    elif S[:6] == t[3]:
        S = S[6:]
    else:
        print('NO')
        sys.exit()
print('YES')

Solution (Python):
import re

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

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

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

Solution (Python):
s=input()

s = s[::-1] 

t = 0;

while t ==0:
    a = s.find("maerd")
    b = s.find("remaerd")
    c = s.find("esare")
    d = s.find("resare")

    if a == 0 or c== 0:
        s = s[5:]
        continue
    if b == 0:
        s = s[7:]
        continue
    if d == 0:
        s = s[6:]
        continue
    t=1


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

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

Solution (Python):

s = input()
r_s = ''.join(list(reversed(s)))

dream = "maerd"
dreamer = "remaerd"
erase = "esare"
eraser = "resare"

flag = True

while flag:
    if r_s.startswith(dream):
        r_s = r_s[5:]
    elif r_s.startswith(dreamer):
        r_s = r_s[7:]
    elif r_s.startswith(erase):
        r_s = r_s[5:]
    elif r_s.startswith(eraser):
        r_s = r_s[6:]
    else:
        flag = False

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

Solution (Python):
s = input()
div = ["dream", "dreamer", "erase", "eraser"]
rev = []
t = ""
s_rev = s[::-1]
for d in div:
    rev.append(d[::-1])

result = True
i = 0
while i < len(s):
    can_divide = False
    for d in rev:
        if len(s_rev) - i >= len(d) and s_rev[i:i + len(d)] == d:
            can_divide = True
            i += len(d)
            break
    if not can_divide:
        result = False
        break

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

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


if __name__ == '__main__':
    main()

Solution (Python):
s = input()
t = ""
while len(t) < len(s):
    target_len = len(s) - len(t)

    if s[len(t)] == 'd':
        if target_len == 5:
            t += "dream"
        elif target_len == 7:
            t += "dreamer"
        elif target_len > 7:
            if s[len(t) + 5] != 'd' and s[len(t) + 5:len(t) + 7 + 1] != "era":
                t += "dreamer"
            else:
                t += "dream"
        else:
            break
    else:
        if target_len == 5:
            t += "erase"
        elif target_len == 6:
            t += "eraser"
        elif target_len > 6:
            if s[len(t) + 5] != 'd' and s[len(t) + 5:len(t) + 6 + 2] != "era":
                t += "eraser"
            else:
                t += "erase"
        else:
            break

    if s[0:len(t)] != t:
        break

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

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

Solution (Python):
s = input()

while True:
    for word in ["dream", "dreamer", "erase", "eraser"]:
        if s.endswith(word):
            s = s[:-len(word)]
            break
    else:
        print("NO")
        exit()
    if s == "":
        print("YES")
        break

Solution (Python):
def main():
    from functools import lru_cache
    import sys
    sys.setrecursionlimit(10 ** 7)

    WORDS = 'dream', 'dreamer', 'erase', 'eraser'

    S = input()
    N = len(S)

    @lru_cache(maxsize=None)
    def dfs(cur=N):
        if cur == 0:
            return True

        for word in WORDS:
            if S[cur - len(word):cur] == word:
                if dfs(cur - len(word)):
                    return True

        return False

    cond = dfs()
    print('YES' if cond else 'NO')


if __name__ == '__main__':
    main()

Solution (Python):
def resolve():
    '''
    code here
    '''
    S = input()
    is_flag = True
    while is_flag:
        
        if len(S)>=5:
            temp = S[:5]
            
            if temp == 'dream':
                S = S[5:]
                if len(S) != 0:
                    if S[:5] == 'erase':
                        pass
                    elif S[:2] == 'er':
                        S = S[2:]
                
            elif temp == 'erase':
                S = S[5:]
                if len(S) != 0:
                    if S[0] == 'r':
                        S = S[1:]

            else:
                print('NO')
                is_flag = False
        elif len(S) == 0:
            print('YES')
            is_flag = False
        else:
            print('NO')
            is_flag = False


if __name__ == "__main__":
    resolve()

Solution (Python):
def resolve():
    '''
    code here
    '''
    S = input()
    is_flag = True
    while is_flag:
        
        if len(S)>=5:
            temp = S[:5]
            
            if temp == 'dream':
                S = S[5:]
                if len(S) != 0:
                    if S[:5] == 'erase':
                        pass
                    elif S[:2] == 'er':
                        S = S[2:]
                
            elif temp == 'erase':
                S = S[5:]
                if len(S) != 0:
                    if S[0] == 'r':
                        S = S[1:]

            else:
                print('NO')
                is_flag = False
        elif len(S) == 0:
            print('YES')
            is_flag = False
        else:
            print('NO')
            is_flag = False


if __name__ == "__main__":
    resolve()

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

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  





S = read()[:-1]
S = deque(reversed('xxxxxxxxxx' + S))  


while len(S) > 10:
    end3 = ''.join([S[6], S[5], S[4], S[3], S[2], S[1], S[0]])
    
    if end3[2:] == 'dream':
        num_pop = 5
    elif end3 == 'dreamer':
        num_pop = 7
    elif end3[2:] == 'erase':
        num_pop = 5
    elif end3[1:] == 'eraser':
        num_pop = 6
    else:
        print('NO')
        exit()
    for _ in ra(num_pop):
        S.popleft()


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

Solution (Python):
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']
T = set([s[::-1] for s in T])

A = ''
for s in S[::-1]:
    A += s
    if A in T:
        A = ''
print('YES' if A == '' else 'NO')

Solution (Python):
s=input()
i=0
flag=True
while i<len(s):
  if s[i]=="d":

    if s[i:i+7]=="dreamer":
      if i+7<len(s) and s[i+7]!="a":
        i=i+7
      elif i+7==len(s):
        i=i+7
      elif s[i:i+5]=="dream":
        i=i+5
      else:
        flag=False
        break
    elif s[i:i+5]=="dream":
        i=i+5
    else:
      flag=False
      break
      
      
  elif s[i]=="e":
    if s[i:i+6]=="eraser":
      i=i+6
    elif s[i:i+5]=="erase":
      i=i+5
    else:
      flag=False
      break
      
      
  else:
    flag=False
    break
if flag==True:
  print("YES")
else:
  print("NO")

Solution (Python):
S = input()

s = ['dream', 'dreamer', 'erase', 'eraser']
R = len(S)
while(R > 0):
    for i in range(4):
        if R >= len(s[i]):
            if S[R-len(s[i]):R] == s[i]:
                R -= len(s[i])
                break
        if i == 3:
            print("NO")
            exit(0)
print("YES")

Solution (Python):
def examA():
    S = SI()
    T = SI()
    N = len(S)
    ans = "No"
    for i in range(N):
        cur = S[i:] + S[:i]
        
        if cur==T:
            ans = "Yes"
    print(ans)
    return

def examB():
    H, W = LI()
    S = [SI()for _ in range(H)]
    flag = True
    ans = 0
    print(ans)
    return

def examC():
    L, R = LI()
    ans = inf
    if R-L>=3000:
        R = L+3000

    for l in range(L, R + 1):
        for r in range(l+1, R + 1):
            now = (l*r) %2019
            ans = min(ans,now)
    print(ans)
    return

def examD():
    T = {"dream", "dreamer", "erase", "eraser"}
    S = SI()
    ans = "NO"
    t = ""
    for s in S[::-1]:
        t += s
        if t[::-1] in T:
            t = ""
        if len(t)>10:
            print(ans)
            return
    if t=="":
        ans = "YES"
    print(ans)
    return

def examE():
    N = 50
    K = I()
    base = K//N
    A = [base+i for i in range(N)]
    rest = K%N
    for i in range(rest):
        A[-i-1] += 1
    print(N)
    print(" ".join(map(str,A)))
    return

def examF():
    N = 20
    C = [2**i for i in range(N)]
    L = I()
    cur = 1
    V = [[i+1, i+2, 0]for i in range(N-1)]
    now = 1
    while(now<N):
        if C[now]<=L:
            cur = C[now]
            V.append([now,now+1,C[now-1]])
            now += 1
        else:
            break
    

    for i in range(now)[::-1]:
        if C[i]<=L-cur:
            cost = cur
            V.append([i+1,N,cost])
            cur += C[i]

    print(N,len(V))
    for s,t,c in V:
        print(s,t,c)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

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

S = input()
l = []
def dfs(n):
  if n == len(S):
    l.append("YES")
  if n < len(S):
    if S[n:n+5] == "erase":
      dfs(n+5)    
    if S[n:n+5] == "dream":
      dfs(n+5)  
    if S[n:n+6] == "eraser":
      dfs(n+6)              
    if S[n:n+7] == "dreamer":
      dfs(n+7)
dfs(0)
if len(l) == 0:
  l.append("NO")
print(l[0])

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

a="maerd"
b="remaerd"
c="esare"
d="resare"
s="".join(list(reversed(SI())))
n=len(s)
ind=0
while ind<n:
    
    if s[ind:ind+5]==a or s[ind:ind+5]==c:
        ind+=5
    elif s[ind:ind+6]==d:
        ind+=6
    elif s[ind:ind+7]==b:
        ind+=7
    else:
        print("NO")
        sys.exit()
    
if ind==n:
    print("YES")

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

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

Solution (Python):
S=input()
S=S[::-1]
L=["dream","dreamer","erase","eraser"]
L=[i[::-1] for i in L]
i=0
while i<len(S):
    flg=0
    for j in range(4):
        if S[i]==L[j][0] and S[i:min(i+len(L[j]),len(S))]==L[j]:
            flg=1
            i+=len(L[j])
            break
    if flg==0:
        break

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

Solution (Python):
import re
s = input()
s = re.sub('eraser','0',s)

s = re.sub('erase','0',s)

s = re.sub('dreamer','0',s)

s = re.sub('dream','0',s)



print('YES' if set(s) == set('0') else 'NO')

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()[::-1]
n = len(s)
d = [['maerd',5],['remaerd',7],['esare',5],['resare',6]]
ind = 0
while True:
    if ind == n:
        print('YES')
        break
    ok = False
    for t,a in d:
        if ind + a <= n and s[ind:ind+a] == t:
            
            ind += a
            ok = True
            break
    if not ok:
        print('NO')
        break

Solution (Python):
import sys
S = input()
s = S[::-1]
i = 0
n = len(s)-i
while n>0:
  if s[i:i+5] == "maerd" or s[i:i+5] == "esare" :
    i += 5
    n = len(s)-i
  elif s[i:i+6] == "resare":
    i += 6
    n = len(s)-i
  elif s[i:i+7] == "remaerd":
    i += 7
    n = len(s)-i
    pass
  else:
    print("NO")
    sys.exit()
    
print("YES")

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    S = list(input())
    S_Rev = S[::-1]
    n = len(S)

    pos = 0
    while pos < n:
        if S_Rev[pos] == "m":
            if pos + 5 <= n and "".join(S_Rev[pos:pos + 5]) == "maerd":
                pos += 5
            else:
                print("NO")
                break
        elif S_Rev[pos] == "e":
            if pos + 5 <= n and "".join(S_Rev[pos:pos + 5]) == "esare":
                pos += 5
            else:
                print("NO")
                break
        elif S_Rev[pos] == "r":
            if pos + 6 <= n and "".join(S_Rev[pos:pos + 6]) == "resare":
                pos += 6
            elif pos + 7 <= n and "".join(S_Rev[pos:pos + 7]) == "remaerd":
                pos += 7
            else:
                print("NO")
                break
        else:
            print("NO")
            break
    else:
        print("YES")


if __name__ == '__main__':
    resolve()

Solution (Python):
S = str(input())[::-1]
words = ['maerd', 'esare', 'remaerd', 'resare']

leng = len(S)
while leng>=5:
    if S[:5] in words:
        S = S[5:]
        leng -= 5
    elif leng>=7 and S[:7] in words:
        S = S[7:]
        leng -= 7
    elif leng>=6 and S[:6] in words:
        S = S[6:]
        leng -= 6
    else:
        print('NO')
        break

if leng==0:
    print('YES')

Solution (Python):
def check():
    S = input()
    dp = [False]*len(S)
    dp[-1]=True
    for i in range(1,len(S)):
        dp[i] = (dp[i-5]&(S[max(0,i-4):i+1]in['dream','erase']))|(dp[i-7]&(S[max(0,i-6):i+1]=='dreamer'))|(dp[i-6]&(S[max(0,i-5):i+1]=='eraser'))

    if dp[-1]:
        return 'YES'
    return 'NO'
print(check())

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

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

cur = 0
while cur < n:
  if s[cur:cur+5:] == "maerd" or s[cur:cur+5:] == "esare":
    cur += 5
    continue
  elif s[cur:cur+6:] == "resare":
    cur += 6
    continue
  elif s[cur:cur+7:] == "remaerd":
    cur += 7
    continue
  print("NO")
  exit()
print("YES")

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

S=s[::-1]
T=""
while len(T)<=len(S):
	if T+"maerd"==S[:len(T)+5]:
		T=T+"maerd"
	elif T+"remaerd"==S[:len(T)+7]:
		T=T+"remaerd"
	elif T+"esare"==S[:len(T)+5]:
		T=T+"esare"
	elif T+"resare"==S[:len(T)+6]:
		T=T+"resare"
	else:
		break


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

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

S = list(input())
i = len(S) - 1

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

while i > 0:
    if S[i] == 'm':
        for j in range(5):
            if S[i - j] == T[0][4 - j]:
                continue
            else:
                print ('NO')
                exit()
        i -= 5
    elif S[i] == 'r':
        if S[i - 2] == 'm':
            for j in range(7):
                if S[i - j] == T[1][6 - j]:
                    continue
                else:
                    print ('NO')
                    exit()
            i -= 7
        else:
            for j in range(6):
                if S[i - j] == T[3][5 - j]:
                    continue
                else:
                    print ('NO')
                    exit()
            i -= 6
    else:
        for j in range(5):
            if S[i - j] == T[2][4 - j]:
                continue
            else:
                print ('NO')
                exit()
        i -= 5

if i == -1:
    print ('YES')
else:
    print ('NO')

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

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))

def resolve():
    W="dream dreamer erase eraser".split(" ")
    
    S=input()
    t=[S]
    while(t!=[]):
        temp=t.pop()
        for w in W:
            m=len(w)
            if(temp[-m:])==w:
                f=temp[:-m]
                if f=="":
                    print("YES")
                    return
                t.append(f)
    print("NO")

resolve()

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):
def main():
    S = input()
    if S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", ""):
        return print("NO")
    else:
        return print("YES")


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    s = input()
    w = ["dream", "dreamer", "erase", "eraser"]
    last = len(s)
    for _ in range(len(s)):
        if last < 1:
            break
        for ww in w:
            if s[last - len(ww):] == ww:
                s = s[:last - len(ww)]
                last -= len(ww)
    print("YES" if last < 1 else "NO")


if __name__ == '__main__':
    main()

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
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")

Solution (Python):
s = input()[::-1] + '0'*7
words = ['maerd', 'remaerd', 'esare', 'resare']
i =0
while True:
    if s[i] == 'm':
        if s[i:i+5] == words[0]:
            i += 5
        else:break
    elif s[i] == 'r':
        if s[i:i+7] == words[1]:
            i += 7
        elif s[i:i+6] == words[3]:
            if s[i+6] == 's':
                i += 5
            else:
                i += 6
        else:break
    elif s[i] == 'e':
        if s[i:i+5] == words[2]:
            if s[i+5] == 's':
                i += 4
            else:
                i += 5
        else:
            break
    else:
        break

if s[i:] == '0'*7:
    print('YES')
else:
    print('NO')

Solution (Python):
s=input()
s=s[::-1]
w=['dream','dreamer','erase','eraser']
lenw=[5,7,5,6]
w=[i[::-1] for i in w]
i=0
n=len(s)
while i<n:
    flg=False
    for j in range(4):
        if s[i:min(i+lenw[j],n)]==w[j]:
            i=i+lenw[j]
            flg=True
    if flg==False:
        break

if i==n and flg:
    print('YES')
else:
    print('NO')

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

DREAM = 'dream'[::-1]
DREAMER = 'dreamer'[::-1]
ERASE = 'erase'[::-1]
ERASER = 'eraser'[::-1]

keywords = (DREAM, DREAMER, ERASE, ERASER)

while len(S) > 0:
    for keyword in keywords:
        if S.startswith(keyword):
            S = S[len(keyword):]
            break
    else:
        break

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

Solution (Python):
i = input()[::-1]
T = []
for t in ['dreamer', 'dream', 'eraser', 'erase']:
    T.append(t[::-1])

match = True
while match:
    match = False
    for t in T:
        if i.startswith(t):
            match = True
            i = i.replace(t, '', 1)
            if len(i) < 1:
                print('YES')
                exit()

print('NO')

Solution (Python):
s=input()
x,y,l=0,5,len(s)
for _ in range(10**5):
  if x>=l-7:
    if x==l-7 and s[x:l]=='dreamer':
      print('YES')
    elif x==l-6 and s[x:l]=='eraser':
      print('YES')
    elif x==l-5 and (s[x:l]=='dream' or s[x:l]=='erase'):
      print('YES')
    else:
      print('NO')
    exit()
    
  if s[x:y]=='erase':
    x=y+1 if s[y]=='r' else y
    y=x+5
  elif s[x:y]=='dream':
    x=y if s[y:y+3]=='era' else (y+2 if s[y:y+2]=='er' else y) 
    y=x+5
  else:
    print('NO')
    exit()

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

Solution (Python):
import re

s = input()

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

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


while len(s) > 0:
  
  for i in range(4):
    w = ws[i]
    if s.endswith(w):
      s = s[:-len(w)]
      break
  else:
    break

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

Solution (Python):
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): 
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): 
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} 
def bitArr(n):
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): 
			k = i-a*j
			if k%b==0:
				return i
	return -1

s = readChar()[::-1]

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

jud = ["mae","rem","esa","res"]

while s!="":
	if s[:3] in jud:
		x = jud.index(s[:3])
		if x==0 or x==2:
			if s[:5]==t[x]:
				s = s[5:]
			else:
				print("NO")
				exit()
		elif x==1:
			if s[:7]==t[x]:
				s = s[7:]
			else:
				print("NO")
				exit()
		elif x==3:
			if s[:6]==t[x]:
				s = s[6:]
			else:
				print("NO")
				exit()
		else:
			print(-1)
			exit()
	else:
		print("NO")
		exit()

print("YES")

Solution (Python):
patterns = [[5, "dream"], [7, "dreamer"], [5, "erase"], [6, "eraser"]]

s = input()

idx = len(s)
while idx > 0:
    for sub, pat in patterns:
        n_idx = idx - sub
        if pat == s[n_idx:idx]:
            idx = n_idx
            break
        else:
            continue
    if idx != n_idx:
        break

print("YES" if idx == 0 else "NO")