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



Sample input:
erasedream


Sample output:
YES

Submission status: Accepted

Solution code:
import subprocess
import gzip, base64, os
import stat

gz = b'H4sIACAjaV0C/+19C3hTVbbwadNHeDXlIVZEiRqgCJSmLQVkdFLaQAIBKi2IKB7SNKXVpMkkJ9A6PpihdYiliv46w3XmzuXOOI7XO/cOM+M4yCCUZ9G5KoIPZnwAjo8TKloRoYqQu9be+6T7nOQUevX+8/3/Z5TurLXXWnvvtdZe+5F99rnX7pqdnpYmKJ904QYBoU8vtRHYxvDTwwkSwE0XBsDfMcJoIQvgTI7OJthUaQ8TraRGRmeAfxkoN53JT7ep0tGMTknTuDRT4D82VSp7BVUqCOYEH9b1sJ9iD/tXqNIOA8VvzlLzpTO+HsbXw+iVVEgXVKnSvgz2r5rhq1m7lLSC0VVw9PipfF+qxe/7l1N4/3KbKn2c0T2u4bsR+LKEi//ksnQRK09PL/ms/kqq2GGKr6GmtGSKr3ayr6Ex0jS5aXrp5NKSgnCgoIjUKZfRzlmwWKXHPFbnEcwHML9grHPfazOCxxbOPJI3qXuKbcDqQ29j3hTGlw3/Wj/Jrc+4akB6mmAh1cA8K/wrhX8Df7BB/GfPc3sf8Mf3r2v1jMxpueKD9TfbPp38qXhbjnlVYb79NVfH8XEdIzYOLv/56OCWZucdz+jp5SMocFgK/DkhNT434Snqzxgd/BsZqeW06uB/r1Puozr0VZmp8SYd/DId/I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BzqKUfD0nZU1CVNjSCX0t2f6qeCm1TQgTTG1Dp1L9KKvEEIknuUhsOiPUwchHlJHo+m6zQPhugXiLSmqRyFvsiwBX3ehb6FJk82WGaXzmvqlj0qfvZDGFVuJFMuOuSvNTJ61nbCuz9fft/TTjM2Tcwtc4XCdcnWwoHlELsLU3umoZV1iL4Hm6AEQDCDJnlQWvrAqBE4Cib5RStBcUaX8fVV8q+hzEBOqDItUErpLd9elLQ0fUkiEFouhdC6B3eZhYvBL/X7/EHU/RN1t+h1ikNN9Xj87pDdsgpEp3QMvgngTxNr/MGtGYilSQWUNeNjEOkr/RjqCDTdo0a6sij+UnOoR6DwM90BNv1OhwYukr0+oNSM0SIIAgJhNwrvVpyLzmQB+NRU5MY9IbCAeidDcCyqjDZmP0MqdBJsbMQbS+EscIfqPWmCPIa1OLG1RhUFsEyxI/k5eWAL6QVKEWH83lTxF3owNNYR0nWR6A4GJHsnhSKAl+YL4Jf3AGRASa02lEPXC3Y3GsZa4l6SgHdM6wdJxsaBSWmLJgBam2MYM+DckQpIDZRxTmrwqCearFydkMlhA4IeFVFYiVoSlzlhsgUxs2flXZ/1VTxTuG/AWZ52IlVnAAA'
bin = gzip.decompress(base64.b64decode(gz))
p = os.path.dirname(__file__)
pymain = os.path.join(p, "a.out")
with open(pymain, "wb") as f:
    f.write(bin)
os.chmod(pymain, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
if p == "":
    pymain = "./" + pymain
subprocess.call(pymain)


# compiled by pythran
'''
#pythran export main2()
import numpy as np

def str2array(s, a):
    for i in range(a.shape[0]):
        a[i] = ord(s[i])

def equal(s, i, a):
    for j in range(a.shape[0]):
        if a[j] != ord(s[i + j]):
            return 0
    return 1

def main2():
    s = open('/dev/stdin').readline()
    dream = np.empty(5, dtype=np.int32)
    str2array('dream', dream)
    dreamer = np.empty(7, dtype=np.int32)
    str2array('dreamer', dreamer)
    erase = np.empty(5, dtype=np.int32)
    str2array('erase', erase)
    eraser = np.empty(6, dtype=np.int32)
    str2array('eraser', eraser)
    r = ord('r')
    i = len(s) - 1
    while True:
        if i < 10:
            if (i == 5 and (equal(s, 0, dream) or equal(s, 0, erase))) or \
                    (i == 6 and equal(s, 0, eraser)) or \
                    (i == 7 and equal(s, 0, dreamer)):
                print('YES')
            else:
                print('NO')
            return
        else:
            if ord(s[i - 1]) == r:
                if equal(s, i - 7, dreamer):
                    i -= 7
                elif equal(s, i - 6, eraser):
                    i -= 6
                else:
                    print('NO')
                    return
            else:
                if equal(s, i - 5, dream) or equal(s, i - 5, erase):
                    i -= 5
                else:
                    print('NO')
                    return
'''

Submission status: Accepted

Solution code:
s=input()[::-1]
rs=s.replace('resare','').replace('esare','').replace('remaerd','').replace('maerd','')
if rs in '':
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC 49 C

def resolve():
    s = input()
    while (len(s) != 0):
        if s.rfind('eraser') == len(s) - len('eraser') and len(s) - len('eraser') >= 0:
            s = s[:len(s) - len('eraser')]
        elif s.rfind('erase') == len(s) - len('erase') and len(s) - len('erase') >= 0:
            s = s[:len(s) - len('erase')]
        elif s.rfind('dreamer') == len(s) - len('dreamer') and len(s) - len('dreamer') >= 0:
            s = s[:len(s) - len('dreamer')]
        elif s.rfind('dream') == len(s) - len('dream') and len(s) - len('dream') >= 0:
            s = s[:len(s) - len('dream')]
        else:
            print('NO')
            return

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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

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

Submission status: Accepted

Solution code:
s=input()
while len(s)>=5:
  if len(s)<=9:
    if s=='dream' or s=='dreamer' or s=='erase' or s=='eraser':
      print('YES')
      exit()
    else:
      print('NO')
      exit()
  else:
    if s[0:5]=='dream':
      s=s[5:]
      if s[0:2]=='er' and s[2]!='a':
        s=s[2:]
    elif s[0:5]=='erase':
      if s[5]=='r':
        s=s[6:]
      else:
        s=s[5:]
    else:
      print('NO')
      exit()

Submission status: Accepted

Solution code:
S = input()[::-1]
n = len(S)
count = 0
flag = True

while count<n:
    if S[count:count+5] == "dream"[::-1]:
        count += 5
    elif S[count:count+7] == "dreamer"[::-1]:
        count += 7
    elif S[count:count+5] == "erase"[::-1]:
        count += 5
    elif S[count:count+6] == "eraser"[::-1]:
        count += 6
    else:
        flag = False
        break

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

Submission status: Accepted

Solution code:
s = input()
d = ['dream', 'dreamer', 'erase', 'eraser']
s = s[::-1]
for i in range(len(d)):
    d[i]= d[i][::-1]
while s != '':
    for j in range(len(d)):
        if s[0:len(d[j])] == d[j]:
            s = s[len(d[j]):]
            break
    else:
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = input()

dp = [0] * 100007 # sの最大値+t_element_listの要素の最大値以上

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

dp[0] = 1
for i in range(len(s)):
    if dp[i] == 1:
        for j in range(len(t_element_list)):
            if s[i:i+len(t_element_list[j])] == t_element_list[j]:
                dp[i + len(t_element_list[j])] = 1

if dp[len(s)] == 1:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s = input()

ok = True
index = len(s)
while True:
    if index == 0:
        break

    if s[index - 1] == 'r':
        if index - 6 >= 0 and s[index - 6:index] == 'eraser':
            index -= 6
        elif index - 7 >= 0 and s[index - 7:index] == 'dreamer':
            index -= 7
        else:
            ok = False
            break
    elif s[index - 1] == 'e':
        if index - 5 < 0 or s[index - 5:index] != 'erase':
            ok = False
            break
        else:
            index -= 5
    elif s[index - 1] == 'm':
        if index - 5 < 0 or s[index - 5:index] != 'dream':
            ok = False
            break
        else:
            index -= 5
    else:
        ok = False
        break
if ok:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s = input()
while s != '':
    tmp = s
    s = s.replace('eraser', '')
    s = s.replace('erase', '')
    s = s.replace('dreamer', '')
    s = s.replace('dream', '')
    if s == '':
        print('YES')
    if tmp == s:
        print('NO')
        break

Submission status: Accepted

Solution code:
def main():
    S = input()

    i = 0
    while i < len(S):
        if S[i:i+7] == "dreamer" and (i+7 == len(S) or (i+7 < len(S) and S[i+7] != "a")):
            i += 7
        elif S[i:i+6] == "eraser":
            i += 6
        elif S[i:i+5] == "dream" or S[i:i+5] == "erase":
            i += 5
        else:
            return "NO"

    return "YES"



if __name__ == '__main__':

    print(main())

Submission status: Accepted

Solution code:
import math
import numpy as np


#a, b, c, x = map(int, [input() for i in range(4)])
#z = list(map(int, input().split()))
#n, a, b = map(int, input().split())

#print(len(z))
#for i in z:
#    print(i)

#a = sorted(a,reverse = True)
#print(sum(a[::2]) - sum(a[1::2]))
#z = map(int, [input() for i in range(int(n))])

s = input()

s = s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")


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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
 
while len(S) > 0:
  if "dreameraser" in S:
    S = S.replace("dreameraser","")
  elif "dreamerase" in S:
    S = S.replace("dreamerase","")
  elif "dreamer" in S:
    S = S.replace("dreamer","")
  elif "dream" in S:
    S = S.replace("dream","")
  elif "eraser" in S:
    S = S.replace("eraser","")
  elif "erase" in S:
    S = S.replace("erase","")
  else:
    break
    
if len(S) == 0:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
s = input()
d = ["dream", "dreamer", "erase", "eraser"]
s = s[::-1]
can = False
for i in range(len(d)):
    d[i] = d[i][::-1]
while(s != ""):
    for i in range(4):
        if s[0:len(d[i])] == d[i]:
            s = s[len(d[i]):]
            break
    else:
        break
else:
    can = True
if can == True:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    s = input()
    possible = [False] * (len(s) + 1)
    possible[0] = True

    candidates = ['dream', 'dreamer', 'erase', 'eraser']
    for i in range(len(s)):
        if not possible[i]:
            continue
        for c in candidates:
            if s[i:i+len(c)] == c:
                possible[i + len(c)] = True

    print('YES' if possible[-1] else 'NO')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import re

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')


S=input()
s=S.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")

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

Submission status: Accepted

Solution code:
S = input()
if len(S)<5:
    print('NO')
else:
    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

Submission status: Accepted

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

isOk=False
while len(s)>=5:
    if s[:5]=="maerd" or s[:5]=="esare":
        s=s[5:]
    elif len(s)>=6 and s[:6]=="resare":
        s=s[6:]
    elif len(s)>=7 and s[:7]=="remaerd":
        s=s[7:]
    else:
        break
    
    if len(s)==0:
        isOk=True

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

Submission status: Accepted

Solution code:
def main():
    s = input()
    while s:
        if s[:7] == 'dreamer':
            if s[:10] != 'dreamerase':
                s = s[7:]
            else:
                s = s[5:]
        elif s[:5] == 'dream':
            s = s[5:]
        elif s[:6] == 'eraser':
            if s[:10] != 'eraseerase':
                s = s[6:]
            else:
                s = s[5:]
        elif s[:5] == 'erase':
            s = s[5:]
        else:
            return 'NO'
    else:
        return 'YES'





print(main())

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

"""
逆にSを殻にする
"""
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")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
st = input()

sample = ['dream', 'dreamer', 'erase', 'eraser']
sample_edit = ['dream', 'eraser','erase', 'er']
sample_er = ['er']
sample_dr = ['dream']
sample_ase = ['ase', 'aser']

ret = 'NO'
reg_len = 0
fd_word = ''
dream_flg = False
end_flg = False

word = ''
length = len(sample_edit)

#while( len(st) != 0 ):
while( True ):
  if reg_len == len(st):
    break
  
  reg_len = len(st)
  for i in range(length):
    word = sample_edit[i]
    fd = st.startswith(word)
    
    if fd > 0:
      
      #print(st,i,dream_flg)
      #st = ''.join(st[len(word):len(st)])
      st = st[len(word):len(st)]
        
      if word == 'dream':
        dream_flg = True
      elif word == 'er':
        if dream_flg == False:
          end_flg = True
        else:
          dream_flg = False
      
      break
    
        
  if end_flg == True:
    break
    
  if len(st) == 0:
    ret = 'YES'
    break
    
  #print(st)
  #print(len(st))

print( ret )

Submission status: Accepted

Solution code:
import sys
str = input()
str = str[::-1]
ary = ['dream','dreamer','erase','eraser']
x = 0
good = True

for i in range(4):
    ary[i] = ary[i][::-1]

while good:
    for i in range(4):
        if str.find(ary[i],x,x + len(ary[i])) > -1:
            x += len(ary[i])
            break
    else:
        good = False
if x == len(str):
    print("YES")
else:
    print("NO")