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:
s=list(input())
s.reverse()
s=''.join(s)

i=0
while i<len(s):
    if s[i:i+5]=='esare' or  s[i:i+5]=='maerd':
        i+=5
    elif s[i:i+6]=='resare':
        i+=6
    elif s[i:i+7]=='remaerd':
        i+=7
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
S = input().replace('dream', 'A').replace('erase', 'B').replace('er', 'C').replace('r', 'D')
N = len(S)

for i in range(N):
    if S[i] in 'AB':
        continue
    elif S[i] == 'C':
        if i == 0 or S[i-1] != 'A':
            print('NO')
            exit()
    elif S[i] == 'D':
        if i == 0 or S[i-1] != 'B':
            print('NO')
            exit()
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
import queue

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

S = input()

BFS = queue.Queue()

can = False

BFS.put(0)

while not BFS.empty():
    t = BFS.get()
    if (t == len(S)):
        can = True
        break
    for s in divide:
        if s == S[t: t + len(s)]:
            BFS.put(t + len(s))

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

Submission status: Accepted

Solution code:
import re

def solve(s):
    return 'YES' if re.match('^((dream(er)?)|(erase(r)?))*$', s) else 'NO'

_s = input()
print(solve(_s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

new_S = "".join(list(reversed(S)))
string_list = ["dream", "dreamer", "erase", "eraser"]
reverse_string_list = []
for i in range(len(string_list)):
    reverse_string_list.append("".join(list(reversed(string_list[i]))))

can = True
index = 0
for i in range(len(new_S)):
    if index >= len(new_S):
        break
    can2 = False
    for each_string in reverse_string_list:
        if new_S[index:index + len(each_string)] == each_string:
            index += len(each_string) - 1
            can2 = True
    if can2 is False:
        can = False
        break
    index += 1

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

Submission status: Accepted

Solution code:
S = input()

a = 'dreamer'
b = 'eraser'
c = 'dream'
d = 'erase'
key = [a,b,c,d]

st = S[::]

while len(st):
    for i in range(4):
        tmp = st[-len(key[i]):]
        if tmp == key[i]:
            st = st[:-len(key[i])]
            if not len(st):
                print('YES')
                exit(0)
            break
        if i == 3:
            print('NO')
            exit(0)

Submission status: Accepted

Solution code:
S = input()
hikari = ['maerd','remaerd','esare','resare']

a = True

while a:
    length = len(S)
    go = ''
    roku = ''
    nana = ''

    if length >= 5:
        for i in range(length-1,length-6,-1):
            go += S[i]
    if length >= 6:
        for i in range(length-1,length-7,-1):
            roku += S[i]
    if length >= 7:
        for i in range(length-1,length-8,-1):
            nana += S[i]

    if go in hikari:
        #cut
        S = S[:-5]
        a = True
    elif roku in hikari:
        #cut
        S = S[:-6]
        a = True
    elif nana in hikari:
        #cut
        S = S[:-7]
        a = True
    else:
        a = False

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

S0 = S.replace("dream", "A")
S1 = S0.replace("erase", "B")
S2 = S1.replace("Aer", "A")
S3 = S2.replace("Br", "B")

#print(S3)
check = True
for i in range(len(S3)):
    if S3[i] != "A" and S3[i] != "B":
        check = False

print("YES" if check == True else "NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
Mozi = ["resare","esare","remaerd","maerd"]

S = S[::-1]
for i in Mozi:
    S = S.replace(i,"")
if not S:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input()

stack = []

for s in S[::-1]:
    stack.append(s)
    n = len(stack)
    if n == 5 and (stack == ['e', 's', 'a', 'r', 'e'] or stack == ['m', 'a', 'e', 'r', 'd']):
        stack = []
    elif n == 6 and stack == ['r', 'e', 's', 'a', 'r', 'e']:
        stack = []
    elif n == 7 and stack == ['r', 'e', 'm', 'a', 'e', 'r', 'd']:
        stack = []
    elif n == 8:
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

Solution code:
S = input()
sc = ["eraser", "erase", "dreamer", "dream"]
for i in sc:
    S = S.replace(i, "")
if S:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
S = input()

sc = ["eraser", "erase", "dreamer", "dream"]
for i in sc:
    S = S.replace(i, "")
if len(S) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
from collections import deque

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

s = input()
que = deque()

can = "NO"

que.append(0)

while(len(que) > 0):
  t = que.pop()
  if (t == len(s)):
    can = "YES"
    break
  for e in divide:
    if s[t:t+len(e)] == e:
      que.append(t+len(e))
print(can)

Submission status: Accepted

Solution code:
S = input()

sc = ["dreameraser", "dreamerase", "eraser", "dreamer", "dream", "erase"]
for i in sc:
    S = S.replace(i, "p")

S = S.replace("p", "")

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


S = input()
import sys
while True:
    if(len(S)==0):
        print("YES")
        sys.exit()
    if S.endswith("dreamer"):
        S = S[:-7]
    elif S.endswith("eraser"):
                S = S[:-6]
    elif S.endswith("dream"):
        S = S[:-5]
    elif S.endswith("erase"):
        S = S[:-5]
    else:
        print("NO")
        sys.exit()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

    n = len(S)

    while n > 0:
        if S[n - 5:n] == "dream":
            n -= 5
        elif S[n - 5:n] == "erase":
            n -= 5
        elif S[n - 7:n] == "dreamer":
            n -= 7
        elif S[n - 6:n] == "eraser":
            n -= 6
        else:
            print("NO")
            return
    else:
        print("YES")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

    s = list(S)
    n = len(s)

    while n > 0:
        if "".join(s[n - 5:n]) == "dream":
            n -= 5
        elif "".join(s[n - 5:n]) == "erase":
            n -= 5
        elif "".join(s[n - 7:n]) == "dreamer":
            n -= 7
        elif "".join(s[n - 6:n]) == "eraser":
            n -= 6
        else:
            print("NO")
            return
    else:
        print("YES")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
lst = ["dream", "dreamer", "erase", "eraser"]
S = str(input())

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

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

Submission status: Accepted

Solution code:
s = input()
res = -1

while len(s) > 0 :

    if len(s) - 5 >= 0 and s[len(s)-5:len(s)] == "erase" :
      #print(s[0:len(s)-5])
      if len(s) - 5 > 0 :
        s = s[0:len(s)-5]
      else :
          res = 1
          s = s[0:len(s)-5]

    elif len(s) - 5 >= 0 and s[len(s)-5:len(s)] == "dream" :
      #print(s[0:len(s)-5])
      if len(s) - 5 > 0 :
        s = s[0:len(s)-5]
      else :
          res = 1
          s = s[0:len(s)-5]

    elif len(s) - 6 >= 0 and s[len(s)-6:len(s)] == "eraser" :
      #print(s[0:len(s)-6])
      if len(s) - 6 > 0 :
        s = s[0:len(s)-6]
      else :
          res = 1
          s = s[0:len(s)-6]

    elif len(s) - 7 >= 0 and s[len(s)-7:len(s)] == "dreamer" :
      #print(s[0:len(s)-7])
      if len(s) - 7 > 0 :
        s = s[0:len(s)-7]
      else :
          res = 1
          s = s[0:len(s)-7]

    else :
        res = 0
        s = ""


if res==1 :
    print("YES")
else :
    #print(res)
    print("NO")

Submission status: Accepted

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

arr = ['dream', 'dreamer', 'erase', 'eraser']
arr_reversed = list(map(lambda item: item[::-1], arr))
able = True
t = ""
while s_reverse != t and able:
    for i in range(len(arr_reversed)):
        item = arr_reversed[i]
        if s_reverse[len(t): len(t) + len(item)] == item:
            t += item
            break
        elif i == len(arr_reversed) - 1:
            able = False

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

Submission status: Accepted

Solution code:
S=input()[::-1]
W=("dream"[::-1],"dreamer"[::-1],"erase"[::-1],"eraser"[::-1])
ind=0
while ind<len(S):
  for w in W:
    if S[ind:ind+len(w)]==w:
      ind+=len(w)
      break
  else:
    print("NO")
    break
else:
  print("YES")

Submission status: Accepted

Solution code:
S = input()

num_5 = ["dream", "erase"]
num_6 = ["eraser"]
num_7 = ["dreamer"]
while len(S) != 0:
    if S[0:7] in num_7:
        if S[5:11] in num_6:
            S = S[5:]
        elif S[5:10] in num_5:
            S = S[5:]
        else:
            S = S[7:]
    elif S[0:6] in num_6:
        if S[5:10] in num_5:
            S = S[5:]
        else:
            S = S[6:]
    elif S[0:5] in num_5:
        S = S[5:]
    else:
        print("NO")
        exit()

print("YES")

Submission status: Accepted

Solution code:
s = t = input()
a = 'dream'
b = 'dreamer'
c = 'erase'
d = 'eraser'

while t:
    if t[-7:] == b:
        t = t[:-7]
    elif t[-6:] == d:
        t = t[:-6]
    elif t[-5:] in (a, c):
        t = t[:-5]
    else:
        break

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

Submission status: Accepted

Solution code:
s = input()
a = 0
t = ("")

while a < len(s):
    if s[a+0:a+5] == ("dream") and s[a+5+0:a+5+2] != ("er"):
        a += 5

    elif s[a+0:a+5] == ("dream") and s[a+5+0:a+5+2] == ("er"):
        if s[a+7+0:a+7+3] != ("ase"):
            a += 7

        elif s[a+7+0:a+7+3] == ("ase") and s[a+10+0:a+10+1] != ("r"):
            a += 10

        elif s[a+7+0:a+7+3] == ("ase") and s[a+10+0:a+10+1] == ("r"):
            a += 11

    elif s[a+0:a+5] == ("erase") and s[a+5+0:a+5+1] != ("r"):
        a += 5

    elif s[a+0:a+5] == ("erase") and s[a+5+0:a+5+1] == ("r"):
        a += 6

    else:
        break

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

Submission status: Accepted

Solution code:
s = input().strip()
words = ["dream", "dreamer", "erase", "eraser"]
i = len(s)
while i > 0:
    b = False
    for w in words:
        if w == s[i-len(w):i]:
            b = True
            i -= len(w)
            break
    if not b:
        break

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

Submission status: Accepted

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

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

Submission status: Accepted

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

word_list = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
while i != len(s):
    a = s[i:i+5]
    a = ''.join(a)
    b = s[i:i+6]
    b = ''.join(b)
    c = s[i:i+7]
    c = ''.join(c)
    if a in word_list:
        i += 5
    elif b in word_list:
        i += 6
    elif c in word_list:
        i += 7
    else:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re
s=input()
s=s[::-1]
#print(s)

#dream|dreamer|erase|eraser

#maerd|remaerd|esare|resare
t=re.split('maerd|remaerd|esare|resare', s)
#print(len(t))
#print(t.count(''))
if len(t)==t.count(''):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
S = input().rstrip()

while S:
    if S[-5:] == "dream":
        S = S[:-5]
    elif S[-5:] == "erase":
        S = S[:-5]
    elif S[-6:] == "eraser":
        S = S[:-6]
    elif S[-7:] == "dreamer":
        S = S[:-7]
    else:
        print("NO")
        sys.exit()
print("YES")

Submission status: Accepted

Solution code:
s = input()

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

#print(s[-5:],s[-6:],s[-7:])

while True:
    if s[-5:] in li:
        s = s[0:-5]
    elif s[-6:] in li:
        s = s[0:-6]
    elif s[-7:] in li:
        s = s[0:-7]
    else:
        print('NO')
        exit()
    if s=='':
        break
print('YES')

Submission status: Accepted

Solution code:
s = input()

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

for i in words:
    s = s.replace(i,"")
if s == "":
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
import collections
def solve(S):
    r_ix = len(S)
    while len(S):
        is_hit = False

        for word in ['dream', 'dreamer', 'erase', 'eraser']:
            l_ix = r_ix - len(word)
            if S[l_ix:r_ix] == word:
                S = S[:l_ix]
                r_ix = l_ix
                is_hit = True

        if not is_hit:
            return "NO"
                
    return "YES"


def solve2(S):
    word = ['dream', 'dreamer', 'erase', 'eraser']
    buf = []
    for ch in S:
        buf.append(ch)
    curchar = ''
    while len(buf) > 0:
        c = buf.pop()
        curchar = c + curchar
        if curchar in word:
            curchar = ''

    if curchar == '':
        return "YES"

    return "NO"

if __name__ == "__main__":
    S = input()
    print(solve(S))

Submission status: Accepted

Solution code:
import collections
def solve(S):
    r_ix = len(S)
    while len(S):
        is_hit = False

        for word in ['dream', 'dreamer', 'erase', 'eraser']:
            l_ix = r_ix - len(word)
            if S[l_ix:r_ix] == word:
                S = S[:l_ix]
                r_ix = l_ix
                is_hit = True

        if not is_hit:
            return "NO"
                
    return "YES"


def solve2(S):
    word = ['dream', 'dreamer', 'erase', 'eraser']
    buf = []
    for ch in S:
        buf.append(ch)
    curchar = ''
    while len(buf) > 0:
        c = buf.pop()
        curchar = c + curchar
        if curchar in word:
            curchar = ''

    if curchar == '':
        return "YES"

    return "NO"

if __name__ == "__main__":
    S = input()
    print(solve2(S))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
s2 = s.split('eraser')
s3 = ''.join(s2).split('erase')
s4 = ''.join(s3).split('dreamer')
s5 = ''.join(s4).split('dream')
s5 = list(set(s5))
if len(s5) == 1 and s5[0] == '':
  print("YES")
else:
  print("NO")

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = input()
flag = True
while flag:
    if s=='':
        flag==False
    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:
        break


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

Submission status: Accepted

Solution code:
S = list(input())
S.reverse()
N = len(S)
i = 0
ans = "YES"

# maerd remaerd esare resare
while i != N:
    if "".join(map(str,S[i:i+5])) == "maerd":
        i += 5
    elif "".join(map(str,S[i:i+5])) == "esare":
        i += 5
    elif "".join(map(str,S[i:i+6])) == "resare":
        i += 6
    elif "".join(map(str,S[i:i+7])) == "remaerd":
        i += 7
    else:
        ans = "NO"
        break

print(ans)

Submission status: Accepted

Solution code:
S=input()
W=("dream","dreamer","erase","eraser")
s=[0]
while s:
  i=s.pop()
  if i==len(S):
    print("YES")
    break
  for w in W:
    if S[i:i+len(w)]==w:
      s.append(i+len(w))
else:
  print("NO")

Submission status: Accepted

Solution code:
s_1 = "dream"
s_2 = "dreamer"
s_3 = "erase"
s_4 = "eraser"

S = input()

while True:
  if S[-5:] == s_1:
    S = S[:-5]
  elif S[-7:] == s_2:
    S = S[:-7]
  elif S[-5:] == s_3:
    S = S[:-5]
  elif S[-6:] == s_4:
    S = S[:-6]
  else :
    break

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
"""AtCoder Beginner Contest 049: C - 白昼夢 / Daydream
https://atcoder.jp/contests/abc049/tasks/arc065_a
"""

__author__ = 'bugttle <bugttle@gmail.com>'

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


def match_word(S):
    for word in WORDS:
        if S.endswith(word):
            return word
    return None


def check(S):
    while True:
        word = match_word(S)
        if word is None:
            return 'NO'
        S = S[:S.rfind(word)]
        if S == '':
            return 'YES'


def main():
    S = input()
    print(check(S))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

while s:
    if s.endswith('dream'):
        s = s[:-5]
        continue
    if s.endswith('erase'):
        s = s[:-5]
        continue
    if s.endswith('dreamer'):
        s = s[:-7]
        continue
    if s.endswith('eraser'):
        s = s[:-6]
        continue
    print('NO')
    exit()
print('YES')

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

s=input().strip()
n=len(s)
s+="###################################"
i=0
while n-i>=1:
    """print(n-i)
    print(s[i:i+5])"""

    if s[i:i+5]=="dream":
        if s[i+5:i+7]=="er":
            #print(s[i+7:i+11])
            if s[i+7:i+10]=="ase":
                if s[i+10]=="r":
                    i+=11
                else:
                    i+=10    
            else:
                i+=7
        else:
            i+=5

    elif s[i:i+5]=="erase":
        #print(8)
        if s[i+5]=="r":
            i+=6
        else:
            i+=5
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

S = input()

# 文頭から行末まで
# +は直前のものが連続するの意
# https://userweb.mnet.ne.jp/nakama/
if re.match('^(dream|dreamer|erase|eraser)+$', S):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import re

S = input()

# 文頭から行末まで
# +は直前のものが連続するの意
if re.match('^(dream|dreamer|erase|eraser)+$', S):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import re

S = input()

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

Submission status: Accepted

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

a = 'dream'[::-1]
b = 'dreamer'[::-1]
c = 'erase'[::-1]
d = 'eraser'[::-1]

idx = 1
for _ in range(len_s):
    if s[:idx] in [a, b, c, d]:
        s = s[idx:]
        idx = 0
    idx += 1
if s[:idx] in [a, b, c, d]:
    s = []

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

Submission status: Accepted

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

s = S[::]
a = 'dream'[::-1]
b = 'dreamer'[::-1]
c = 'erase'[::-1]
d = 'eraser'[::-1]

# print(S)
idx = 1
for i in range(1, len(S)):
    if s[:idx] in [a, b, c, d]:
        # print('sだよ')
        # print('カット')
        # print(s[:idx])
        # print(i)
        # print('s[idx:]だよ', s[idx:])
        s = s[idx:]
        # print('カット後のsだよ', s)
        # print()
        idx = 0
    idx += 1
    # print('ほげ', s[:idx])
if s[:idx] in [a, b, c, d]:
    s = []

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

def main():
    s = input()
    s = re.sub('eraser', '', s)
    s = re.sub('erase', '', s)
    s = re.sub('dreamer', '', s)
    s = re.sub('dream', '', s)
    print('YES' if len(s) == 0 else 'NO')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input().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', '')
if s:
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
s = input()

while s != "":
    if 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
else:
    print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a="dream"
b="dreamer"
c="erase"
d="eraser"

ar=a[::-1]
br=b[::-1]
cr=c[::-1]
dr=d[::-1]

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


Sr=Sr.replace(dr,'')
Sr=Sr.replace(cr,'')
Sr=Sr.replace(br,'')
Sr=Sr.replace(ar,'')

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

Submission status: Accepted

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

divide = ["dream", "dreamer", "erase", "eraser"]
for i in range(len(divide)):
    divide[i] = divide[i][::-1]

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
L = ['eraser','erase','dreamer','dream']
for e in L:
    S = S.replace(e,"")
if len(S) == 0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s = input()
lst = ['eraser', 'erase', 'dreamer', 'dream']

for i in lst:
  s = s.replace(i, '')
 

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

Submission status: Accepted

Solution code:
S = input()

list = ["eraser","erase","dreamer","dream"]
for x in list:
    S = S.replace(x,"")

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

Submission status: Accepted

Solution code:
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', '')
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()
while len(S) > 0:
    if 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:
        break
if len(S) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input()
dp = [False for _ in range(len(S)+1)]
char_list = ['dream', 'dreamer', 'erase', 'eraser']
dp[0] = True

for i in range(len(S)):
  if dp[i] == False:
    continue
  for char in char_list:
    if S[i:i+len(char)] == char:
      dp[i+len(char)] = True

if dp[len(S)]:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
s = input()

flag = True

while s != "":
    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:
        flag = False
        break

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

Submission status: Accepted

Solution code:
#49c
S = str(input()) #1≦|S|≦10**5
#Tが空文字列である状態から始め、以下の操作を好きな回数繰り返すことで S=Tとすることができるか判定してください。
#    Tの末尾に dream dreamer erase eraser のいずれかを追加する。

#末尾から見ていく
i = len(S) - 5
if i < 0:
    print("NO")
else:
    while i >= 0:
        end_5_char = S[i:i+5]

        #print(i,end_5_char)

        if end_5_char == "eamer":
            #print(i,S[i-2:i])
            if i < 2 or S[i-2:i] != "dr":
                print("NO")
                break
            else:
                i -= 2
        elif end_5_char == "raser":
            #print(i,S[i-1:i])
            if i < 1 or S[i-1:i] != "e":
                print("NO")
                break
            else:
                i -= 1
        elif end_5_char != "dream" and end_5_char != "erase":
            print("NO")
            break

        i -= 5
    else:
        print("YES")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import re

S = input()

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

Submission status: Accepted

Solution code:
s = list(input())
s= s[::-1]
s += list("qqqqqqqq")
li = [list("maerd"),list("remaerd"),list("esare"),list("resare")]
#print(li)
memo = 0
while(1):
    a = s[memo:memo+5]
    b = s[memo:memo+6]
    c = s[memo:memo+7]
    #print(a,b,c,memo)
    if a==li[0] or a==li[2]:
        memo += 5
        continue
    elif b==li[3]:
        memo += 6
        continue
    elif c==li[1]:
        memo += 7
        continue
    elif memo >= len(s)-8:
        print("YES")
        break
    else:
        print("NO")
        break
    



    pass

Submission status: Accepted

Solution code:
S = input()

import re

pattern = r"^(dream|dreamer|erase|eraser)+$"
target = S

if re.match(pattern, target):
	print("YES")
else:
	print("NO")

Submission status: Accepted

Solution code:
s = list(input());tmp = ""
t = ["maerd", "remaerd", "esare", "resare"]
while s:
    tmp += s.pop()
    if tmp in t: tmp = ""
if len(tmp)>=7: print("NO")
else: print("YES")

Submission status: Accepted

Solution code:
import sys


def solve(inp):
    S = inp.readline().rstrip()

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

    S = ''.join(reversed(S))

    while len(S) > 0:
        f = 0
        for p in P:
            p_str = ''.join(reversed(p))
            if S.startswith(p_str):
                f = 1
                S = S[len(p):]
                break
        if f == 0:
            return "NO"

    return "YES"


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()
N = len(S)

# dp[i] := i文字目までをS=Tとすることができるか
dp = [0] * (N + 9)
dp[0] = 1
for i in range(N):
    if dp[i]:
        if S[i:i+5] == 'dream':
            dp[i+5] = 1
        if S[i:i+7] == 'dreamer':
            dp[i+7] = 1
        if S[i:i+5] == 'erase':
            dp[i+5] = 1
        if S[i:i+6] == 'eraser':
            dp[i+6] = 1
if dp[N]:
    YES()
else:
    NO()

Submission status: Accepted

Solution code:
s = str(input())

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

Submission status: Accepted

Solution code:
s = input()
lst = ["eraser","erase","dreamer","dream"]
for w in lst:
    s = s.replace(w,"")

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

print(ans)

Submission status: Accepted

Solution code:
s = "".join(input().split("eraser"))
s = "".join(s.split("erase"))
s = "".join(s.split("dreamer"))
s = "".join(s.split("dream"))
if len(s) == 0:
    ans = "YES"
else:
    ans = "NO"

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys

S = input()

i = 0
while i < len(S):
	if i + 4 < len(S) and S[i : i + 5] == "dream":
		if i + 6 < len(S) and S[i + 5 : i + 7] == "er":
			if i + 9 < len(S) and S[i + 7 : i + 10] == "ase":
				if i + 10 < len(S) and S[i + 10] == "r":
					i += 11
				else:
					i += 10
			else:
				i += 7
		else:
			i += 5
	else:
		if i + 4 < len(S) and S[i : i + 5] == "erase":
			if i + 5 < len(S) and S[i + 5] == "r":
				i += 6
			else:
				i += 5
		else:
			print("NO")
			sys.exit()

print("YES")