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:
# Input
s = str(input())
N = len(s)

while s != "":
    if s[N-5:N] == "dream" or s[N-5:N] == "erase":
        s = s[:N-5]
        N = len(s)
    elif s[N-6:N] == "eraser":
        s = s[:N-6]
        N = len(s)
    elif s[N-7:N] == "dreamer":
        s = s[:N-7]
        N = len(s)
    else:
        break

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

Submission status: Accepted

Solution code:
def main():
    target = input()
    string = ["eraser", "dreamer", "erase", "dream"]
    for i in range(len(target)):
        for s in string:
            if target[-len(s):] == s:
                target = target[:-len(s)]
        if target == "":
            break
    print("YES" if target == "" else "NO")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

p = 0
while p < len(s):
    if s[p:p+5] == 'dream' and s[p+5:p+6] != 'e':
        p += 5
        t += 'dream'
    elif s[p:p+5] == 'erase' and s[p+5:p+6] != 'r':
        p += 5
        t += 'erase'
    elif s[p:p+6] == 'eraser':
        p += 6
        t += 'eraser'
    elif s[p:p+7] == 'dreamer' and s[p+7:p+8] != 'a':
        p += 7
        t += 'dreamer'
    elif s[p:p+7] == 'dreamer' and s[p+7:p+8] == 'a':
        p += 5
        t += 'dream'
    else:
        break

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

Submission status: Accepted

Solution code:
def main():
    s=input()[::-1]
    string=('maerd','remaerd','esare','resare')
    
    n=len(s)
    i=0
    while i<n:
        st=s[i:i+5]
        if st in string:
            i+=5
            continue
        st=s[i:i+6]
        if st==string[3]:
            i+=6
            continue
        st=s[i:i+7]
        if st==string[1]:
            i+=7
            continue
        else:
            print('NO')
            exit()
    print('YES')   

if  __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    s=input()
    string=('dream','erase')

    i=0
    n=len(s)
    while i<n:
        st=s[i:i+5]
        if st==string[0]:
            i+=5
            st=s[i:i+2]
            if st=='er':
                if i+2==n:
                    break
                if s[i+2]!='a':
                    i+=2
        
        elif st==string[1]:
            i+=5
            if i==n:
                break
            if s[i]=='r':
                i+=1
        
        else:
            print('NO')
            exit()
    print('YES')
if  __name__=='__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

d = np.array([[0, 0, 0, 0, 0, 0],
            [2, 0, 9, 0, 0, 0],
            [0, 3, 0, 0, 0, 0],
            [0, 0, 4, 0, 0, 0],
            [0, 0, 0, 5, 0, 0],
            [0, 0, 0, 0, 6, 0],
            [2, 0, 7, 0, 0, 0],
            [0, 8, 0, 0, 0, 0],
            [2, 0, 9, 11, 0, 0],
            [0, 10, 0, 0, 0, 0],
            [0, 0, 0, 11, 0, 0],
            [0, 0, 0, 0, 0, 12],
            [0, 0, 13, 0, 0, 0],
            [2, 1, 9, 0, 0, 0]], dtype = 'int32')
s = 1
S = input()
N = len(S)
id = {'d': 0, 'r': 1, 'e': 2, 'a': 3, 'm': 4, 's': 5}
for c in S:
    s = d[s][id[c]] if c in id else 0
    if s == 0:
        break

print("YES" if s in {1, 6, 8, 13} else "NO")

Submission status: Accepted

Solution code:
s=input()
n=len(s)
s=s+"0000000"
c=0
check=0
while c<n:
    if s[c:c+5]=="dream":
        if s[c+5:c+7]=="er":
            if s[c+7]=="a":
                c+=5
            else:
                c+=7
        else:
            c+=5
    elif s[c:c+5]=="erase":
        if s[c+5]=="r":
            c+=6
        else:
            c+=5
    else:
        check+=1
        break
if check==0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = input()
while len(s) > 4:
    if s[:5] == "dream":
        if s[5:7] == "er":
            if s[7:10] == "ase":
                s = s[5:]
            else:
                s = s[7:]
        else:
            s = s[5:]
    elif s[:5] == "erase":
        if s[5:6] == "r":
            s = s[6:]
        else:
            s = s[5:]
    else:
        break
if s == "":
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
t = ["dream","dreamer","erase","eraser"]
s = s[::-1]
t1=[]
for i in t:
    t1.append(i[::-1])

count = 0
while True:
    check = False
    for i in t1:
        
        if s[count:min(count+len(i),len(s))] == list(i):
            count += len(i)
            check = True
            if count == len(s):
                print("YES")
                exit()
            break
    if count == len(s):
        print("Yes")
        exit()
    if check == False:
        print("NO")
        exit()

Submission status: Accepted

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

for w in words:
    s = s.replace(w, '')

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

Submission status: Accepted

Solution code:
import re

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

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import re;print("YNEOS"[re.match(r"^(dream(er)?|eraser?)+$",input())==None::2])

Submission status: Accepted

Solution code:
def ans2():
    s = input()
    flag = True
    while flag:
        if (s[-7:])=='dreamer':
            s = s[:-7]
        elif (s[-5:])=='dream':
            s = s[:-5]
        elif (s[-6:])=='eraser':
            s = s[:-6]
        elif (s[-5:])=='erase':
            s = s[:-5]
        else:
            flag = False
    
    if not s:
        print("YES")
    else:
        print("NO")
ans2()

Submission status: Accepted

Solution code:
def main():
    s = input()
    ref = ['eraser','erase','dreamer','dream']
    for i in range(4):
        s = s.replace(ref[i], '')
    if not s:
        print("YES")
    else:
        print("NO")
main()

Submission status: Accepted

Solution code:
import re

s = input()
s = re.sub("eraser","",s)
s = re.sub("erase","",s)
s = re.sub("dreamer","",s)
s = re.sub("dream","",s)

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

Submission status: Accepted

Solution code:
#python3
def main():
    s = input()
    flag = True 
    while flag:
        flag = False
        if s[-7:] == "dreamer":
            s = s[:-7]
            flag = True
        if s[-6:] == "eraser":
            s = s[:-6]
            flag = True
        if s[-5:] == "erase":
            s = s[:-5]
            flag = True
        if s[-5:] == "dream":
            s = s[:-5]
            flag = True
    if not s:
        print("YES")
    else:
        print("NO")

main()

Submission status: Accepted

Solution code:
s = input()

flg = 0

for i in range(20001):
    len(s)
    if s[-5:] == "dream":
        s = s[:len(s) - 5]
    elif s[-7:] == "dreamer":
        s = s[:len(s) - 7]
    elif s[-5:] == "erase":
        s = s[:len(s) - 5]
    elif s[-6:] == "eraser":
        s = s[:len(s) - 6]
    elif s == "":
        flg = 1
    else:
        flg = 0
        break

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

Submission status: Accepted

Solution code:
#python3
def main():
    s = input()
    p = ['eraser', 'erase', 'dreamer', 'dream']
    for i in range(4):
        s = s.replace(p[i], '')
    if not s:
        print('YES')
    else:
        print('NO')
main()

Submission status: Accepted

Solution code:
import re
s = input()

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

Submission status: Accepted

Solution code:
s = input()

num = len(s)

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

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

Submission status: Accepted

Solution code:
S = input()

elements = ["maerd", "remaerd", "esare", "resare"]
reverseS = S[::-1]

ans = "NO"
i = 0
while True:
    flg = 0
    for element in elements:
        l = len(element)
        if element == reverseS[i:i+l]:
            i += l
            flg = 1
            break
    if flg == 0:
        break
    elif i == len(reverseS):
        ans = "YES"
        break

print(ans)

Submission status: Accepted

Solution code:
s = input()
while len(s) > 0:
    for a in ('dreamer', 'dream', 'eraser', 'erase'):
        if s[-len(a):] == a:
            s = s[:-len(a)]
            break
    else:
        break
if len(s) == 0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input()
case =True
while(case == True):
    if len(S) <5:
        case = False
    
    elif S[0:5] == 'dream': #check 'dreamer' and 'dream'
        if S[0:10] == 'dreamerase':
            S = S[5:]
        elif S[0:7] == 'dreamer':
            S = S[7:]
        else:
            S = S[5:]

    elif S[0:5] == 'erase': #check 'erase' and 'eraser'
        if len(S) > 5 and S[5] == 'r':
            S = S[6:]
        else:
            S = S[5:]
    
    else:
        case =False

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

S = S[::-1]

index = 0
#possible = False

while index < len(S):
    if S[index] == 'm':
        if S[index:index+5] == 'maerd':
            index += 5
            continue
        else:
            break
    elif S[index] == 'e':
        if S[index:index+5] == 'esare':
            index += 5
            continue
        else:
            break
    elif S[index] == 'r':
        if S[index:index+6] == 'resare':
            index += 6
            continue
        elif S[index:index+7] == 'remaerd':
            index += 7
            continue
        else:
            break

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

Submission status: Accepted

Solution code:
def main():
    S = input()[::-1]
    s1 = "dream"[::-1]
    s2 = "dreamer"[::-1]
    s3 = "erase"[::-1]
    s4 = "eraser"[::-1]
    ans = "NO"
    while True:
        match_flag = False
        for c in [s1, s2, s3, s4]:
            if S[0:len(c)] == c:
                match_flag = True
                S = S.replace(c, "", 1)
                break
        if match_flag is False:
            break
        if S == "":
            ans = "YES"
            break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S=input()
flag=True
while len(S)>7:
    if S[-7:]=="dreamer":
        S=S[:-7]
    elif S[-5:]=="dream" or S[-5:]=="erase":
        S=S[:-5]
    elif S[-6:]=="eraser":
        S=S[:-6]
    else:
        flag=False
        break
if S=="dreamer" or S=="dream" or S=="erase" or S=="eraser" or S=="":
    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:
s = input()
flag = True
while 1:
    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:
        flag = False
        break
    if s == "":
        break
if flag:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

while(True):
	if i==len(s):
		print("YES")
		exit()
	if s[-7-i:len(s)-i]==b:
		i+=7
	elif s[-5-i:len(s)-i]==a:
		i+=5
	elif s[-6-i:len(s)-i]==d:
		i+=6
	elif s[-5-i:len(s)-i]==c:
		i+=5
	else :
		print("NO")
		exit()

Submission status: Accepted

Solution code:
s = input()
flag = True
while 1:
    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:
        flag = False
        break
    if s == "":
        break
if flag:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S=input()

while(1):
    length = len(S)
    if length==0:
        break
    if S[length-5:length]=="dream":
        S = S[:length-5]
    elif S[length-5:length]=="erase":
        S = S[:length-5]
    elif S[length-6:length]=="eraser":
        S = S[:length-6]
    elif S[length-7:length]=="dreamer":
        S = S[:length-7]
    else:
        print("NO")
        exit(0)
print("YES")

Submission status: Accepted

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

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

    for word in words:
        s = s.replace(word, "")

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

i=len(S)
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:
        print("NO")
        break

    if i == 0:
        print("YES")
        break

Submission status: Accepted

Solution code:
def main(S):
    listdreamereraser = ['dreamer','eraser','dream','erase']
    while True:
        for i in listdreamereraser:
            if i == S[-len(i):]:
                S = S[:-len(i)]
                break
        else:
            return False
        if len(S) == 0:
            return True

S = input()
print('YES' if main(S) else 'NO')

Submission status: Accepted

Solution code:
def main(S):
    listdreamereraser = ['dreamer','eraser','dream','erase']
    while True:
        for i in listdreamereraser:
            if i in S[-len(i):]:
                S = S[:-len(i)]
                break
        else:
            return False
        if len(S) == 0:
            return True

S = input()
print('YES' if main(S) else 'NO')

Submission status: Accepted

Solution code:
S = input()

# Greedyアルゴリズム
S = S[::-1]

S = S.replace("resare","")
S = S.replace("esare","")
S = S.replace("remaerd","")
S = S.replace("maerd","")

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

Submission status: Accepted

Solution code:
S=input()[::-1]
T=""
L=["dream","dreamer","erase","eraser"] 
for s in S:
    T=s+T
    if T in L:
        T=""
    elif len(T)>6:
        break
print("YES" if T=="" else "NO")

Submission status: Accepted

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

print(solve())

Submission status: Accepted

Solution code:
S=input()

l = len(S)
ans = True

while(l>0):
    if l<=4:
        ans=False
        break
    if l>=5:
        if S[-5:] == "erase" or S[-5:]=="dream":
            S = S[:-5]
            l = l-5
            continue
    if l>=6:
        if S[-6:] == "eraser":
            S = S[:-6]
            l = l-6
            continue
    if l>=7:
        if S[-7:] == "dreamer":
            S = S[:-7]
            l = l-7
            continue
    ans = False
    break

if not ans:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
s = input()
flag = 1
while len(s)>4:
    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:
        flag = 0
        break
if len(s):
    flag = 0
if flag:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s=input()
# dream dreamer erase eraser 
while len(s)>0:
	if (s[-1]=="r") & (s[-7:]=="dreamer"):
		s=s[:-7]
	elif (s[-1]=="r") & (s[-6:]=="eraser"):
		s=s[:-6]
	elif (s[-1]=="e") & (s[-5:]=="erase"):
		s=s[:-5]
	elif (s[-1]=="m") & (s[-5:]=="dream"):
		s=s[:-5]
	else:
		break

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

Submission status: Accepted

Solution code:
S = input()

T = ["dream","dreamer","erase","eraser"]
flag = True
for i in range(len(S)):
    if (flag == False) or (len(S) == 0):
        break
    if S[-5:] in T:
        S = S[:-5]
    elif S[-6:] in T:
        S = S[:-6]
    elif S[-7:] in T:
        S = S[:-7]
    else:
        print("NO")
        flag = False
if flag == True:
    print("YES")

Submission status: Accepted

Solution code:
import sys
s = input()
s = s[::-1]
A = ['dreamer','dream','eraser', 'erase']
for i in range(len(A)):
    A[i] = A[i][::-1]
while(len(s)!=0):
    cs = s
    for i in range(len(A)):
        if (s.startswith(str(A[i]))):
            #print(A[len(A[i])+1:])
            s = s[len(A[i]):]
            #print(s)
            break
    if (cs == s):
        print('NO')
        sys.exit()
print('YES')

Submission status: Accepted

Solution code:
s = input()

while True:
  if s == "":
    print('YES')
    break
  elif 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:
    print('NO')
    break

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

"""対象文字列
dream
erase
eraser
dreamer
"""

flg = True
while flg:
  if S[-7:] == 'dreamer':
    S = S[:-7]
  elif S[-6:] == 'eraser':
    S = S[:-6]
  elif S[-5:] == 'erase':
    S = S[:-5]
  elif S[-5:] == 'dream':
    S = S[:-5]
  else:
    flg = False


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


print(ans)

Submission status: Accepted

Solution code:
s = input()
i=len(s)-1
while i > 0:
    if i<4:
        print("NO")
        exit()
    check=s[i-2:i+1]

    if check == "eam": # dream
        if s[i-4:i+1] == "dream":
            i-=5
            continue
    elif check == "mer": # dreamer
        if i > 5 and s[i-6:i+1] == "dreamer":
            i-=7
            continue
    elif check == "ase": # erase
        if s[i-4:i+1] == "erase":
            i-=5
            continue
    elif check == "ser": # eraser
        if i > 4 and s[i-5:i+1] == "eraser":
            i-=6
            continue

    print("NO")
    exit()

print("YES")

Submission status: Accepted

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

def test(S,l):
    while len(S) > 0:
        if S[::-1] in l:
            print('YES')
            return
        elif S[-1:-6:-1] in l:
            S = S[:-5]
        elif S[-1:-7:-1] in l:
            S = S[:-6]
        elif S[-1:-8:-1] in l:
            S = S[:-7]
        else:
      	    print('NO')
      	    return
  
test(S,l)

Submission status: Accepted

Solution code:
s = input()

pos = len(s)
while pos > 0:
    # print(s[pos-6:pos])
    if s[pos-1] == 'e':
        if s[pos-5:pos] == 'erase':
            # print(s[pos-5:pos])
            pos -= 5
        else:
            break
    elif s[pos-1] == 'm':
        if s[pos-5:pos] == 'dream':
            # print(s[pos-5:pos])
            pos -= 5
        else:
            break
    elif s[pos-6:pos] == 'eraser':
        # print(s[pos-6:pos])
        pos -= 6
    elif s[pos-7:pos] == 'dreamer':
        # print(s[pos-7:pos])
        pos -= 7
    else:
        break
print('YES' if pos <= 0 else 'NO')

Submission status: Accepted

Solution code:
s = input()
devide = ["maerd", "remaerd", "esare", "resare"]

reverse_input = "".join(list(reversed(s)))
can = False
point = 0

for i in range(len(s)+1) :
    slice = reverse_input[point:i]
    if slice in devide :
        point += len(slice)
        can = True
    else :
        can = False

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

Submission status: Accepted

Solution code:
S = input()
reverse = S[::-1]
devide = ["dream", "erase", "dreamer", "eraser"]
r_devide = [devide[i][::-1] for i in range(len(devide))]
i=0
while i < len(S):
  can = False
  for j in r_devide:
    if j in reverse[i:i+len(j)] :
      can = True
      i += len(j)
  
  if can == False:
    break
    
if can == True:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
def main(s):
    e = ["dreamer","eraser","dream","erase"]
    #キューの初期化
    t = [""]
    #キューが空でない間繰り返し
    while len(t) > 0:
        val = t.pop(0)
        for i in e:
            tar = val + i
            #一致したら終了判定→キューに追加
            if s[:len(tar)] == tar:
                if s == tar:
                    return True
                else:
                    t.append(tar)
    return False

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

Submission status: Accepted

Solution code:
S=input()
flag=False
while True:
    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:
s1 = input()
s = s1 + '111111111111'
index = 0
while index < len(s):
    word = s[index:index + 5]
    # print(word)
    if word == '11111':
        break
    if '1' in word:
        print("NO")
        exit()

    if word == 'dream':
        index += 5

        if s[index:index + 2] == 'er':
            if s[index:index + 5] == 'erase':
                pass
            else:
                index += 2

    elif word == 'erase':
        index += 5
        if s[index] == 'r':
            index += 1

    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', '')

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

Submission status: Accepted

Solution code:
def main():
  s=input()
  q=[0]
  m=len(s)
  l=["dream","dreamer","erase","eraser"]
  while q:
    i=q.pop()
    if i==m:
      print("YES")
      return
    for j in l:
      nj=len(j)
      if i+nj<=m and s[i:i+nj]==j:
        q.append(i+nj)
  print("NO")

main()

Submission status: Accepted

Solution code:
S = input()[::-1]
N = len(S)
T = ""
n = 0
C = ["maerd","remaerd","esare","resare"]
while n<N:
    if S[n]=="m":
        T+=C[0]
        n+=5
    elif S[n]=="e":
        T+=C[2]
        n+=5
    elif S[n]=="r":
        if N-n<6:break
        if S[n+2]=="m":
            T+=C[1]
            n+=7
        elif S[n+2]=="s":
            T+=C[3]
            n+=6
        else:break
    else:break
print("YES" if S==T else "NO")

Submission status: Accepted

Solution code:
import re
s = input()
m = re.fullmatch(r"(dreamer|dream|erase|eraser)+", s)

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

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]
ans = ["maerd","remaerd","esare","resare"]
flag = 1
while len(s) != 0 and flag == 1:
    flag = 0
    if s[:5] in ans:
        s = s[5:]
        flag = 1
    elif s[:7] in ans:
        s = s[7:]
        flag = 1
    elif s[:6] in ans:
        s = s[6:]
        flag = 1
        
if flag == 0:
    print("NO")
else:
    print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import permutations

S = input()

def is_passed(s, ws):
    for w in ws:
        s = ''.join(s.split(w))
        if len(s) == 0:
            return True
    return False

def main():
    l = ['dreamer', 'eraser', 'dream', 'erase']
    pm = permutations(l, len(l))
    passed = False
    for ws in pm:
        passed = is_passed(S, ws)
        if passed:
            break
    print('YNEOS'[not passed::2])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    S = input()
    T = set("dream dreamer erase eraser".split())
    
    p = ""
    for i in range(len(S)):
        p = S[~i] + p
        if p in T:
            p = ""
        elif len(p) > 7:
            print("NO")
            return

    print("YES")

main()

Submission status: Accepted

Solution code:
S = input()
str_list = ['dream','dreamer','erase','eraser']
fl = True
while fl:
    if S[-5:] in str_list:
        S = S[0:-5]
    elif S[-6:] in str_list:
        S = S[0:-6]
    elif S[-7:] in str_list:
        S = S[0:-7]
    elif S=="":
        fl = False
    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", "")


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

Submission status: Accepted

Solution code:
s = input()
y = 0
while y < len(s):
    if s[y:y+11] == "dreameraser":
        y += 11
    elif s[y:y+10] == "dreamerase":
        y += 10
    elif s[y:y+7] == "dreamer":
        y += 7
    elif s[y:y+6] == "eraser":
        y += 6
    elif s[y:y+5] == "dream" or s[y:y+5] == "erase":
        y += 5
    else: 
        print("NO")
        break
else: print("YES")

Submission status: Accepted

Solution code:
S = input()

def check(t):
  if len(t) >= 5 and (t[-5:] == 'dream' or t[-5:] == 'erase'):
    return True,t[:-5]
  elif len(t) >=6 and t[-6:] == 'eraser':
    return True,t[:-6]
  elif len(t) >= 7 and t[-7:] == 'dreamer':
    return True,t[:-7]
  else:
    return False,t

while(len(S) > 0):
  flag,S = check(S)
  if not flag:
    print('NO')
    exit()
print('YES')

Submission status: Accepted

Solution code:
s = input()
dp = [0 for i in range(len(s)+1)]
dp[0] = 1
words = ['eraser', 'erase', 'dreamer', 'dream']

for i in range(len(s)):
  i += 1
  for sent in words:
    before = i - len(sent)
    if before < 0:
      continue
    if dp[before] == 1 and s[before:i] == sent:
      dp[i] = 1
print('YES' if dp[-1] else 'NO')

Submission status: Accepted

Solution code:
S = input()

while len(S) > 4:
    if S[-5:] == 'dream':
        S = S[:-5]
        continue
    elif S[-5:] == 'erase':
        S = S[:-5]
        continue
    elif S[-6:] == 'eraser':
        S = S[:-6]
        continue
    elif S[-7:] == 'dreamer':
        S = S[:-7]
        continue
    else:
        break

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

Submission status: Accepted

Solution code:
S = input()[::-1]
D = ["dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1]]
while True:
    for d in D:
        if S.startswith(d):
            S = S.replace(d, "", 1)
            break
    else:
        break
print("YNEOS"[S!=""::2])

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()[::-1]
T=["dream","dreamer","erase","eraser"]
l,n=0,len(s)

while l!=n:
    flag=0
    for i in T:
        word=i[::-1]
        if s[l:l+len(word)]==word:
            l +=len(word)
            flag=1
    if flag==0:print("NO");exit()
print("YES")

Submission status: Accepted

Solution code:
s=input()[::-1]
T=["dream","dreamer","erase","eraser"]
l,n=0,len(s)

while l!=n:
    flag=0
    for i in T:
        word=i[::-1]
        if s[l:l+len(word)]==word:
            l +=len(word)
            flag=1
            break
    if flag==0:print("NO");exit()
print("YES")

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=list(S())

  a1=list('dream')
  a2=list('dreamer')
  a3=list('erase')
  a4=list('eraser')

  while len(s)>4:
    if s[-5:]==a1:
      for _ in range(5):
        s.pop()
    elif s[-7:]==a2:
      for _ in range(7):
        s.pop()
    elif s[-5:]==a3:
      for _ in range(5):
        s.pop()
    elif s[-6:]==a4:
      for _ in range(6):
        s.pop()
    else:
      break

  if s==[]:
    return 'YES'
  return 'NO'

# main()
print(main())

Submission status: Accepted

Solution code:
s=input()
while len(s)>0:
  #初めがdreamの場合
  if s[:5]=="dream" and (len(s)==5 or s[5]=="d" or s[5:8]=="era"):
    s=s[5:]
  elif s[:7]=="dreamer" and (len(s)==7 or s[7]=="d" or s[7]=="e"):
    #初めがdreamerの場合
    s=s[7:]
  elif s[:5]=="erase" and (len(s)==5 or s[5]=="d" or s[5]=="e"):
    #初めがeraseの場合
    s=s[5:]
  elif s[:6]=="eraser" and (len(s)==6 or s[6]=="d" or s[6]=="e"):
    s=s[6:]
  else:
    print("NO")
    exit()
print("YES")

Submission status: Accepted

Solution code:
string = input()
 
flg = True
while len(string) > 0:
  if string.endswith('dream'):
    string = string[:-5]
  elif string.endswith('dreamer'):
    string = string[:-7]
  elif string.endswith('erase'):
    string = string[:-5]
  elif string.endswith('eraser'):
    string = string[:-6]
  else:
    print('NO')
    flg = False
    break
if flg:
  print('YES')

Submission status: Accepted

Solution code:

S = input()
T = ""

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

tmp = ""
for s in S[::-1]:
  tmp = s + tmp
  if tmp in U:
    T = tmp + T
    tmp = ""

if T == S:
  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('YES')
else:
    print('NO')

Submission status: Accepted

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

    st = [s]
    while st:
        x = st.pop()
        if x == '':
            print('YES')
            return

        for w in ('dream', 'dreamer', 'erase', 'eraser'):
            if x.endswith(w):
                st.append(x[:-len(w)])

    print('NO')


if __name__ == '__main__':
    main()