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 = input()

flag = 1
while len(S):
    if S[:7] == 'dreamer':
        if S[5:11] == 'eraser':
            S = S[11:]
        elif S[5:10] == 'erase':
            S = S[10:]
        else:
            S = S[7:]
    elif S[:6] == 'eraser':
        S = S[6:]
    elif S[:5] == 'dream' or S[:5] == 'erase':
        S = S[5:]
    else:
        flag = 0
        break

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

Submission status: Accepted

Solution code:
S = input()
patterns = ['dreamer', 'dream', 'eraser', 'erase']


while len(S) != 0:
    isShaved = False
    for p in patterns:
        if S.endswith(p):
            S = S[:len(S)-len(p)]
            isShaved = True
            break
    if not isShaved:
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
str_list = ['dream', 'dreamer','erase','eraser']
def reverse_str(str_):
    return str_[::-1]

s = str(input())
s = s[::-1]
find_list = list(map(reverse_str, str_list))
index = 0

while index < len(s):
    loop_flag = False
    for i in range(len(find_list)):
        str_value = find_list[i]
        if str(s[index:index+len(str_value)]) == str_value:

            loop_flag = True
            index += len(str_value)
    if not loop_flag:
        break
if index >= len(s):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
from os.path import commonprefix as cp
import math
INF, MOD = float("inf"), 1e9 + 7
MAX, MIN = -INF, INF
dx1, dy1, dx2, dy2 = [-1, 0, 1, 0], [0, -1, 0, 1], [-1, 0, 1, -1, 1, -1, 0, 1], [-1, -1, -1, 0, 0, 1, 1, 1]

def get_int():
    return int(input())

def get_int_list():
    return list(map(int, input().split()))

while(True):
    try:
        prefixs = ["remaerd", "maerd", "resare", "esare"]
        s = input()[::-1]
        while(len(s)):
            flag = True
            for p in prefixs:
                if cp([s, p]) == p:
                    flag = False
                    s = s[len(p):]
                    break
            if flag:
                print("NO");
                exit()
        print("YES")
    except EOFError:
        exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
S = input()

while(len(S) > 0):
    if S[0:6] == "eraser":
        S = S[6:]
    elif S[0:5] == "erase":
        S = S[5:]
    elif S[0:5] == "dream":
        tmp = S[5:8]
        if len(tmp) == 0:
            S = S[5:]
        elif tmp == "era":
            S = S[5:]
        elif tmp == "er":
            S = S[7:]
        elif tmp == "ere":
            S = S[7:]
        elif tmp == "erd":
            S = S[7:]
        else:
            S = S[5:]
    else:
        print("NO")
        sys.exit()
print("YES")

Submission status: Accepted

Solution code:
input_str = input()
new_str = ''.join(list(reversed(input_str)))
candidates = ["dream", "dreamer", "erase", "eraser"]
candidates = [''.join(list(reversed(s))) for s in candidates]

def match_candidates(s, i, candidates):
    for candidate in candidates:
        length = len(candidate)
        if s[i:i+length] == candidate: return length
    return -1

def judge_str(s, candidates):
    i = 0
    while i < len(new_str):
        jump = match_candidates(s, i, candidates)
        if jump == -1:
            return "NO"
        i += jump
    return "YES"
    
print(judge_str(new_str, candidates))

Submission status: Accepted

Solution code:
def solve(S):
    S = S[::-1]
    for _ in range(len(S) // 5 + 1):
        if S[:5] == "dream"[::-1]:
            S = S[5:]
        if S[:5] == "erase"[::-1]:
            S = S[5:]
        if S[:6] == "eraser"[::-1]:
            S = S[6:]
        if S[:7] == "dreamer"[::-1]:
            S = S[7:]
    if len(S):
        return "NO"
    else:
        return "YES"
#
# assert(solve("erasedream") == "YES")
# assert(solve("dreameraser") == "YES")
# assert(solve("dreamerer") == "NO")
# assert(solve("dreamdreamerer") == "NO")
# assert(solve("erasdreamerer") == "NO")
# assert(solve("dreameraserer") == "NO")

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

Submission status: Accepted

Solution code:
s = input()

while 1:
    if len(s)<=7:
        if s=='dream' or s=='dreamer' or s=='erase' or s=='eraser':
            print('YES')
            break
    
    elif s[-5:]=='dream':
        s = s[:-5]
        continue
    
    elif s[-7:]=='dreamer':
        s = s[:-7]
        continue
    
    elif s[-5:]=='erase':
        s = s[:-5]
        continue
    
    elif s[-6:]=='eraser':
        s = s[:-6]
        continue
    
    else:
        print('NO')
        break

Submission status: Accepted

Solution code:
S=input()
i=len(S)
flag=True
while i>0:
    if S[i-7:i]=='dreamer':
        i=i-7
    elif S[i-6:i]=='eraser':
        i=i-6
    elif S[i-5:i]=='dream' or S[i-5:i]=='erase':
        i=i-5
    else:
        flag=False
        break
if flag==True:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s = list(input())

while len(s) > 0:
    if ''.join(s[-7:]) == 'dreamer':
        del s[-7:]
    elif ''.join(s[-6:]) == 'eraser':
        del s[-6:]
    elif ''.join(s[-5:]) == 'dream' or ''.join(s[-5:]) == 'erase':
        del s[-5:]
    else:
        break
print('YES' if len(s) == 0 else 'NO')

Submission status: Accepted

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

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

length1 = 0
length2 = 0
can = 0
flag = True

while flag:
    length1 = length2
    for i in range(4):
        if S[length1:length1+len(divide[i])] == divide[i]:
            length2 = length1 + len(divide[i])
    if length1 == length2:
        flag = False

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

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
while S:
    if S.startswith('maerd'):
        S = S[5:]
    elif S.startswith('remaerd'):
        S = S[7:]
    elif S.startswith('esare'):
        S = S[5:]
    elif S.startswith('resare'):
        S = S[6:]
    else:
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

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

s = ""
for i in range(len(S)):
    s += S[-(i+1)]
    if s[::-1] in a:
        s = ""
    if len(s) > 6:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
s = list(input())
while len(s) > 0:
    if ''.join(s[-7:]) == 'dreamer':
        del s[-7:]    
    elif ''.join(s[-6:]) == 'eraser':
        del s[-6:]
    elif ''.join(s[-5:]) == 'dream' or ''.join(s[-5:]) == 'erase':
        del s[-5:]
    else:
        break
print('NO' if len(s) != 0 else 'YES')

Submission status: Accepted

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Beginning_Contest049-C
#  TODO https://atcoder.jp/contests/abc049/tasks/arc065_a
#  TODO 参考サイトからの文字列逆転を活用＋replace関数を利用
def solveProblem(givenStr):

	strT1 = "dream"
	strT2 = "dreamer"
	strT3 = "erase"
	strT4 = "eraser"
	givenStr = givenStr[::-1]
	strList = [strT2[::-1],strT4[::-1],strT1[::-1],strT3[::-1]]
	while len(givenStr) > 0:
		stripFlag = False
		for word in strList:
			givenSubStr=givenStr[0:len(word)]
			if givenSubStr == word:
				givenStr=givenStr.replace(word,"",1)
				stripFlag = True
		if stripFlag == False:
			break
	if len(givenStr) == 0:
		answer="YES"
	else:
		answer="NO"
	return answer

if __name__ == '__main__':
	S = str(input().strip())
	solution = solveProblem(S)
	print("{}".format(solution))

Submission status: Accepted

Solution code:
s = input()

s = s[::-1]
s = list(s)
#print(s)
count = 0
can = True
jm = []
j = 0
maxcount = 0
for i in s:
    jm.append(i)
    j += 1
    count += 1
    if count > 7:
        can = False
#        print(0)
        break
    elif "".join(jm) == "maerd":
        maxcount += count
        count,j = 0,0
        jm = []
#        print(1)
    elif "".join(jm) == "remaerd":
        maxcount += count
        count,j = 0,0
        jm = []
#        print(2)
    elif "".join(jm) == "esare":
        maxcount += count
        count,j = 0,0
        jm = []
#        print(3)
    elif "".join(jm) == "resare":
        maxcount += count
        count,j = 0,0
        jm = []
#        print(4)
    else:
#        print(5,end = "")
        pass


#print("forward bool is" + str(can))

if maxcount == 0:
    can = False

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

Submission status: Accepted

Solution code:
S = input()

S = S[::-1]

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

if len(S) > 0:
    while len(S) > 0:
        if S.startswith(dream):
            S = S[len(dream):]
        elif S.startswith(dreamer):
            S = S[len(dreamer):]
        elif S.startswith(erase):
            S = S[len(erase):]
        elif S.startswith(eraser):
            S = S[len(eraser):]
        else:
            break
    if len(S) > 0:
        print("NO")
    else:
        print("YES")

else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
def check(s):
    if s[-5:]=='dream':
        return 'dream'
    elif s[-7:]=='dreamer':
        return 'dreamer'
    elif s[-5:]=='erase':
        return 'erase'
    elif s[-6:]=='eraser':
        return 'eraser'
    else: return 'False'

count=0
while len(s)>0 and count==0:
    if check(s)=='False':
        count+=1
        print('NO')
    elif check(s)=='dream' or check(s)=='erase':
        s=s[:-5]
    elif check(s)=='eraser':
        s=s[:-6]
    elif check(s)=='dreamer':
        s=s[:-7]

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

Submission status: Accepted

Solution code:
from collections import deque
s = input()
li = ['dream', 'dreamer', 'erase', 'eraser']

ans = 'NO'
Q = deque()
Q.append(0)
while True:
    try:
        k = Q.popleft()
    except:
        break
    if k == len(s):
        ans = 'YES'
        break
    for a in li:
        if a == s[k: k + len(a)]:
            Q.append(k + len(a))

print(ans)

Submission status: Accepted

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

while s != '':
    for a in li:
        if s[-len(a):] == a:
            s = s[:-len(a)]
            break
    else:
        break
if s == '':
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s = input()
judge = "YES"

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

if not s.isdigit():
  judge = "NO"
print(judge)

Submission status: Accepted

Solution code:
s = input()
judge = "YES"

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

if s:
  judge = "NO"

print(judge)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
a='YES'
while len(s)!=0:
  if s[len(s)-5:len(s)]=='dream':
    s=s[0:len(s)-5]
  elif s[len(s)-7:len(s)]=='dreamer':
    s=s[0:len(s)-7]
  elif s[len(s)-5:len(s)]=='erase':
    s=s[0:len(s)-5]
  elif s[len(s)-6:len(s)]=='eraser':
    s=s[0:len(s)-6]
  else:
    a='NO'
    break
print(a)

Submission status: Accepted

Solution code:
s = input()
tmp = s
flag=0
while tmp != '':
  if tmp[-7::] =='dreamer':
    tmp = tmp[0:-7]
  elif tmp[-6::] == 'eraser':
    tmp = tmp[0:-6]
  elif tmp[-5::] == 'dream' or tmp[-5::] == 'erase':
    tmp = tmp[0:-5]
  else:
    flag=1
    break
    
if flag ==0:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
a = input()
a = a[::-1]
k = ["dreamer","dream","erase","eraser"]
for i in range(4):
    k[i] = k[i][::-1]
f = 1
i= 0
while f:
    if a[i:i+5] == k[2] or a[i:i+5] == k[1]:
        i +=5
    elif a[i:i+6] == k[3]:
        i +=6
    elif a[i:i+7] == k[0]:
        i+=7
    else:break
if len(a)==i:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
def solve(s):
    stack = [s]
    while stack:
        word = stack.pop()
        if len(word) == 0:
            return True
        for prefix in ('dreamer', 'dream', 'eraser', 'erase'):
            if word.startswith(prefix):
                stack.append(word[len(prefix):])

print('YES' if solve(input()) else 'NO')

Submission status: Accepted

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

words = ["dream", "dreamer", "erase", "eraser"]
words = [w[::-1] for w in words]
lens = [len(w) for w in words]

while True:
    for l, w in zip(lens, words):
        if s[:l] == w:
            s = s[l:]
            break
    else:
        print("NO")
        break
    if len(s) == 0:
        print("YES")
        break

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()
S1 = S.replace('erase', 'YYY').replace('YYYr', '').replace('YYY', '').replace('dreamer', '').replace('dream', '')
if S1 == '':
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
def DFS(S):
    word_list = [ "dreamer","dream", "eraser", "erase"]
    stack = ["dream", "dreamer", "erase", "eraser"]
    while stack:
        word = stack.pop()
        if word == S[0]:
            return "YES"
        for i in word_list:
            next_word = word + i
            check = S[0][:len(word + i)]
            if next_word != check:
                continue
            if next_word == check:
                stack.append(next_word)
    return "NO"






if __name__ == "__main__":
    S = [input()]
    print(DFS(S))

Submission status: Accepted

Solution code:
def DFS(S):
    word_list = ["dreamer", "dream", "eraser", "erase"]
    stack = ["dream", "dreamer", "erase", "eraser"]
    while stack:
        word = stack.pop()
        if word == S[0]:
            return "YES"
        for i in word_list:
            next_word = word + i
            check = S[0][:len(word + i)]
            if next_word != check:
                continue
            if next_word == check:
                stack.append(next_word)
    return "NO"
 
 
 
 
 
 
if __name__ == "__main__":
    S = [input()]
    print(DFS(S))

Submission status: Accepted

Solution code:
S = input()

dp = [False] * (len(S) + 1)
dp[0] = True
T = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(1, len(S) + 1):
    tmp = []
    for t in T:
        if i < len(t):
            continue
        tmp.append(dp[i-len(t)] and t == S[i-len(t): i])
    if any(tmp):
        dp[i] = True
print('YES' if dp[len(S)] else 'NO')

Submission status: Accepted

Solution code:
S = str(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:
import queue


def check_dream(s):
    return s.startswith('dream')


def check_dreamer(s):
    return s.startswith('dreamer')


def check_erase(s):
    return s.startswith('erase')


def check_eraser(s):
    return s.startswith('eraser')


def check_sentence(s, q):
    if check_dream(s):
        q.put(s[5:])

    if check_dreamer(s):
        q.put(s[7:])

    if check_erase(s):
        q.put(s[5:])

    if check_eraser(s):
        q.put(s[6:])

    return q


def search():
    sentence_q = queue.Queue()
    initial_s = input()

    s = initial_s
    while(1):
        if s == '':
            return True

        sentence_q = check_sentence(s, sentence_q)
        if sentence_q.empty():
            return False

        s = sentence_q.get()


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

Submission status: Accepted

Solution code:
s = input()

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

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

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


print(
    "NO"
    if ii(str)
    .replace("eraser", "")
    .replace("erase", "")
    .replace("dreamer", "")
    .replace("dream", "")
    else "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:
a=input()
a=a.replace("eraser","")
a=a.replace("erase","")
a=a.replace("dreamer","")

a=a.replace("dream","")
if a=="":
  print("YES")
else:
  print("NO")

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 sys
S = input()
S = S[::-1]

AR = []
A = ["dream","dreamer","erase","eraser"]
for a in A:
    AR.append(a[::-1])

i = 0
while i < len(S):
    for ar in AR:
        l = len(ar)
        if ar == S[i:i+l]:
            i += l
            break
    else:
        print("NO")
        sys.exit()

print("YES")

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]
part = ['dream'[::-1],'dreamer'[::-1],'erase'[::-1],'eraser'[::-1]]
i = 0
while(1):
    ok = False
    for p in part:
        if s[i:i+len(p)] == p:
            i += len(p)
            ok = True
            break
    if ok == False or i == len(s):
        break
print('YES' if ok else 'NO')

Submission status: Accepted

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

words = list(map(lambda s: s[::-1], ['dreamer', 'eraser', 'erase', 'dream']))

while True:
    for w in words:
        if S[:len(w)] == w:
            S = S[len(w):]
            break
    else:
        break

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

Submission status: Accepted

Solution code:
d = ["dream", "dreamer", "erase", "eraser"]

def getDevidedString(s):
    i = 0
    while i < 4:
        position = len(d[i]) * -1
        str = s[position:]
        if str == d[i]:
           return s[0:position]
        i += 1
    return s

S = input()

while len(S) != 0:
    tmp = getDevidedString(S)
    if len(S) != len(tmp):
        S = tmp
    else:
        break

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

Submission status: Accepted

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

print('YES')

Submission status: Accepted

Solution code:
#入力した文字列から順に文字を取り除いていく
#dreamerやdreamから削ると、削った文字列が本当にdreamerやdreamなのか判断できないため、eraserやeraseから削る
S=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")

#文字列Sが空にの場合OK
if S:
    print("NO")
else:
    print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    s = input()
    word_list = ['dream', 'dreamer', 'erase', 'eraser']

    i = len(s)
    while 0 < i:
        f = False
        for w in word_list:
            if s[i - len(w):i] == w:
                i -= len(w)
                f = True
                break
        if not f:
            break

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

bool = [False]

def hantei(s):
    # print(s)
    if s=='':
        bool[0]=True
        return

    if s.count('dream')>=1:
        r=s.replace('dream','')
        hantei(r)

    if s.count('dreamer')>=1:
        r=s.replace('dreamer','')
        hantei(r)

    if s.count('erase')>=1:
        r=s.replace('erase','')
        hantei(r)

    if s.count('eraser')>=1:
        r=s.replace('eraser','')
        hantei(r)
    return

hantei(s)
        

if bool[0]==True:
    print('YES')

if bool[0]==False:
    print('NO')

Submission status: Accepted

Solution code:
strings = ['eraser','erase', 'dreamer','dream' ]
# strings = [s[::-1] for s in strings]

S = str(input())
# S = S[::-1]
# print(S,strings)
for s in strings:
    S = S.replace(s, "")

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

Submission status: Accepted

Solution code:
S = input()

cnt = 0
j = len(S) - 1

for i in range(len(S) - 1, -1, -1):
    if j - i > len("dreamer"):
        break
    for dd in ("dream", "dreamer", "erase", "eraser"):
        if S[i:j + 1] == dd:
            j = i - 1
            cnt += len(dd)

print(("NO", "YES")[len(S) == cnt])

Submission status: Accepted

Solution code:
S = input()

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    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:
            break

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
i = 0
n = len(s)
p = 0
while i < n:
    if i == 0:
        if s[i] == "d":
            if i + 5 <= n:
                if s[i:i+5] == "dream":
                    i = i + 5
                    if i + 5 < n:
                        if s[i] != "e" and s[i] != "d":
                            print("NO")
                            exit()
                else:
                    print("NO")
                    exit()
            else:
                print("NO")
                exit()
        elif s[i] == "e":
            if i + 2 <= n:
                if s[i:i+2] == "er":
                    i = i + 1
                else:
                    print("NO")
                    exit()
            else:
                print("NO")
                exit()
        else:
            print("NO")
            exit()
    else:
        if s[i] == "d":
            if i + 5 <= n:
                if s[i:i+5] == "dream":
                    i = i + 5
                    if i + 5 < n:
                        if s[i] != "e" and s[i] != "d":
                            print("NO")
                            exit()
                else:
                    print("NO")
                    exit()
            else:
                print("NO")
                exit()
        elif s[i] == "e":
            if i + 2 <= n:
                if s[i:i+2] == "er":
                    i = i + 1
                else:
                    print("NO")
                    exit()
            else:
                print("NO")
                exit()
        elif s[i] == "r":
            if s[i - 5: i + 1] == "eraser" and i - 5 >= 0:
                if s[i - 2] != "r":
                    if i + 1 < n:
                        if s[i + 1] == "d":
                            i = i + 1
                        elif s[i + 1] == "e":
                            i = i + 1
                        else:
                            print("NO")
                            exit()
                        #p = 1
                    else:
                        print("YES")
                        exit()
            elif i + 4 <= n:
                if s[i - 2] != "r":
                    if i + 1 < n:
                        if s[i + 1] == "d":
                            i = i + 1
                            p = 1
                        elif s[i + 1] == "e":
                            i = i + 1
                            p = 1
                    else:
                        print("YES")
                        exit()
                if s[i:i+4] == "rase":
                    i = i + 4
                    p = 1
                if p == 0:
                    print("NO")
                    exit()
            elif s[i - 2] != "r":
                if i + 1 < n:
                    if s[i + 1] == "d":
                        i = i + 1
                    elif s[i + 1] == "e":
                        i = i + 1
                    else:
                        print("NO")
                        exit()
                else:
                    print("YES")
                    exit()
            else:
                print("NO")
                exit()
        else:
            print("NO")
            exit()
    p = 0
print("YES")

Submission status: Accepted

Solution code:
s = input()
str_list = ["eraser","erase","dreamer","dream"]
for e in str_list:
    s = s.replace(e,"#")
s = s.replace("#","")
ans = "YES" if s == "" else "NO"
print(ans)

Submission status: Accepted

Solution code:
s = input()
str_list = ["eraser","erase","dreamer","dream"]
for e in str_list:
    s = s.replace(e,"")
ans = "YES" if s == "" else "NO"
print(ans)

Submission status: Accepted

Solution code:
s = input()
for i in range(len(s) // 5):
    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]
ans = "YES" if s == "" else "NO"
print(ans)

Submission status: Accepted

Solution code:
s = input()
for i in range(len(s) // 5):
    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]
ans = "YES" if s == "" else "NO"
print(ans)

Submission status: Accepted

Solution code:
s = input()
str_list = ["dream","dreamer","erase","eraser"]
for i in range(len(s) // 5):
    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]
ans = "YES" if s == "" else "NO"
print(ans)

Submission status: Accepted

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

word = ['maerd', 'remaerd', 'esare', 'resare']

T = []

now = 0
for i in range(10**5):
    if s[now:now+5] == 'maerd':
        now += 5
    elif s[now:now+5] == 'esare':
        now += 5
    elif s[now:now+7] == 'remaerd':
        now += 7
    elif s[now:now+6] == 'resare':
        now += 6
    else:
        break

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

Submission status: Accepted

Solution code:
rules = ['dream', 'dreamer', 'erase', 'eraser']

s = input()
stack = [0]
mem = [0 for _ in range(len(s)+1)]
ok = False
while len(stack) > 0:
    start_id = stack.pop()
    string = s[start_id:]
    if start_id == len(s):
        print('YES')
        ok = True
        break

    for rule in rules:
        if string.startswith(rule):
            next_start_id = start_id + len(rule)
            if next_start_id <= len(s):
                part = string[next_start_id:]
                if mem[next_start_id] == 0:
                    stack.append(next_start_id)
                    mem[next_start_id] = 1
if not ok:
    print('NO')

Submission status: Accepted

Solution code:
S = input().strip()

while True:
  if S.endswith('dream'):
    S = S[:-5]
  elif S.endswith('dreamer'):
    S = S[:-7]
  elif S.endswith('erase'):
    S = S[:-5]
  elif S.endswith('eraser'):
    S = S[:-6]
  else:
    break

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

Submission status: Accepted

Solution code:
S = input()
L = ['dream', 'dreamer', 'erase', 'eraser']
#L = ['eraser', 'erase', 'dreamer', 'dream']
cnt=0 
while len(S):
  for item in L:
    if S[-1*len(item):] == item:
      S = S[:-1*len(item)]
  cnt+=1
  if len(S) == 0:
    print("YES")
  if cnt > 100001:
    print("NO")
    exit(0)

Submission status: Accepted

Solution code:
# encoding: utf-8
S = input()

words = S.replace("d", " d").lstrip().split()

ans = "NO"
for word in words:
    word_tmp = word
    while len(word_tmp) > 0:
        if word_tmp[-6:] == "eraser":
            word_tmp = word_tmp[:-6]
        elif word_tmp[-5:] == "erase":
            word_tmp = word_tmp[:-5]
        elif word_tmp[-7:] == "dreamer":
            word_tmp = word_tmp[:-7]
        elif word_tmp[-5:] == "dream":
            word_tmp = word_tmp[:-5]
        else: break
    else:
        continue
    break
else: ans = "YES"

print(ans)

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()[::-1]
List = ["maerd", "remaerd", "esare", "resare"]
while True:
    if len(S) == 0:
          print("YES")
          break
    if S[0:7] in List:
        S = S[7:]
    elif S[0:6] in List:
        S = S[6:]
    elif S[0:5] in List:
        S = S[5:]
    else:
        print("NO")
        break

Submission status: Accepted

Solution code:
s = input()
size = len(s)

dp = [False] * (size + 1)
dp[0] = True

for i in range(5, size + 1):
    if dp[i - 5] and (s[i-5:i] == 'dream' or s[i-5:i] == 'erase'):
        dp[i] = True
    elif dp[i - 6] and s[i-6:i] == 'eraser':
        dp[i] = True
    elif dp[i - 7] and s[i-7:i] == 'dreamer':
        dp[i] = True
    else:
        dp[i] = False
if dp[size]:
    print('YES')
else:
    print('NO')