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: Wrong Answer

Solution code:
def search(pat, txt, q):
        
    M = len(pat)
    N = len(txt)
    i = 0
    j = 0
    p = 0
    t = 0
    h = 1
    d = 256
    ll = list()
    cnt = 0
    for i in range(M-1):
        h = (h*d)%q
    for i in range(M):
        p = (d*p + ord(pat[i]))%q
        t = (d*t + ord(txt[i]))%q
    for i in range(N-M+1):
        if p==t:
            for j in range(M):
                if txt[i+j] != pat[j]:
                    break
            j+=1
            if j==M:
            	cnt += 1
        if i < N-M:
            t = (d*(t-ord(txt[i])*h) + ord(txt[i+M]))%q
            if t < 0:
                t = t+q
    
    return cnt

s = input()

if len(s) < 5:
    print('NO')
else:
    a = search('dream',s,101)
    b = search('dreamer',s,101)
    c = search('erase',s,101)
    d = search('eraser',s,101)
    if b:
        a = a - b
    if d:
        c = c - d
    l = a * 5 + b * 6 + c * 5 + d * 6
    
    if l == len(s):
        print('YES')
    else:
        print('NO')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

import sys

def match(s):
    if s[:5] == 'dream' or s[:5] == 'erase':
        return 5
    if s[:6] == 'eraser':
        return 6
    if s[:7] == 'dreamer':
        return 7
    return -1

def main():
    s = raw_input()
    offset = 0
    while offset < len(s):
        n = match(s[offset:])
        if n == -1:
            print 'NO'
            sys.exit()
        offset += n
    print 'YES'

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=raw_input()

d=s.find('eraser')
while(d>=0):
    if(d!=0):
       s=s[0:d]
    else:
       s=s[d+6:]
    d=s.find('eraser')

c=s.find('erase')
while(c>=0):
    if(c!=0):
        s=s[0:c]
    else:
        s=s[c+5:]
    c=s.find('erase')

b=s.find('dreamer')
while(b>=0):
    if(b!=0):
     s=s[0:b]
    else:
     s=s[b+7:]
    b=s.find('dreamer')

a=s.find('dream')
while(a>=0):
    if(a!=0):
     s=s[0:a]
    else:
     s=s[a+5:]
    a=s.find('dream')


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

Submission status: Wrong Answer

Solution code:
s=raw_input()
a=s.find('dream')
while(a>=0):
    if(a!=0):
     s=s[0:a]
    else:
     s=s[a+5:]
    a=s.find('dream')
b=s.find('dreamer')
while(b>=0):
    if(b!=0):
     s=s[0:b]
    else:
     s=s[b+7:]
    b=s.find('dreamer')
c=s.find('erase')
while(c>=0):
    if(c!=0):
        s=s[0:c]
    else:
        s=s[c+5:]
    c=s.find('erase')
d=s.find('eraser')
while(d>=0):
    if(d!=0):
       s=s[0:d]
    else:
       s=s[d+6:]
    d=s.find('eraser')
if(len(s)==0):
    print 'YES'
else:
    print 'NO'

Submission status: Wrong Answer

Solution code:
import re
a = raw_input()
a = re.sub(r'dreamer','',a)
a = re.sub(r'eraser','',a)
a = re.sub(r'dream','',a)
a = re.sub(r'erase','',a)
if a == '':
    print 'YES'
else:
    print 'NO'

Submission status: Wrong Answer

Solution code:
s=input()
t=['dreamer','dream', 'eraser', 'erase']
re=1
for i in t :
    if (i in s) :
        re=re+0
    else :
        re=re-1
if re==1 :
    print('YES')
else :
    print('NO')

Submission status: Wrong Answer

Solution code:
s=raw_input()
a=s.find('dream')
while(a>=0):
    s=s[0:a]+s[a+5:]
    a=s.find('dream')
b=s.find('dreamer')
while(b>=0):
    s=s[0:b]+s[b+7:]
    b=s.find('dreamer')
c=s.find('erase')
while(c>=0):
    s=s[0:c]+s[c+5:]
    c=s.find('erase')
d=s.find('eraser')
while(d>=0):
    s=s[0:d]+s[d+6:]
    d=s.find('eraser')
if(len(s)==0):
    print 'YES'
else:
    print 'NO'

Submission status: Wrong Answer

Solution code:
input_string = input()

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

for add_string in add_strings:
    input_string = input_string.replace(add_string, "x")

input_string = input_string.replace("x", "")

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

Submission status: Wrong Answer

Solution code:
input_string = input()

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

for add_string in add_strings:
    input_string = input_string.replace(add_string, "")

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

Submission status: Wrong Answer

Solution code:
s=raw_input()
a=s.find('dream')



if(a>=0):
    s=s[0:a]+s[a+5:]
b=s.find('dreamer')
if(b>=0):
    s=s[0:b]+s[b+7:]
c=s.find('erase')
if(c>=0):
    s=s[0:c]+s[c+5:]
d=s.find('eraser')
if(d>=0):
    s=s[0:d]+s[d+6:]
if(len(s)==0):
    print 'YES'
else:
    print 'NO'

Submission status: Wrong Answer

Solution code:
s=raw_input()
a=s.find('dream')



if(a>=0):
    s=s[0:a]+s[a+5:]
b=s.find('dreamer')
if(b>=0):
    s=s[0:b]+s[b+5:]
c=s.find('erase')
if(c>=0):
    s=s[0:c]+s[c+5:]
d=s.find('eraser')
if(d>=0):
    s=s[0:d]+s[d+5:]
if(len(s)==0):
    print 'YES'
else:
    print 'NO'

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
string = input()
keys = ["dreamer","eraser","dream","erase"]
keys_to_find = ["dreamer","eraser","dream","erase"]

for key in keys_to_find:
    index = string.find(key)
    if index != -1:
        string = string.replace(key,"")
    # print("index:",index)
    # print("string:",string)
if string == "":
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
string = input()
keys = ["dreamer","eraser","dream","erase"]
keys_to_find = ["dreamer","eraser","dream","erase"]

for key in keys_to_find:
    index = string.find(key)
    if index != -1:
        string = string.replace(key,"")
    print("index:",index)
    print("string:",string)
if string == "":
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s = raw_input()
flag = 0
while len(s) > 0:
    if s[-5:] == "dreamer":
        flag = 0
        s = s.replace(s[-5:], "")
        flag = 1
    if s[-6:] == "eraser":
        s = s.replace(s[-6:], "")
        flag = 1
    if s[-5:] == "dream" or  s[-5:] == "erase":
        s = s.replace(s[-5:], "")
        flag = 1
    if flag != 1:
        print "NO"
        break

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

Submission status: Wrong Answer

Solution code:
list=["dream","dreamer","erase","eraser"]
s=input()
t=""
i=0
while(i<len(s)):
    t+=s[i]
    if t in list:
        t=""
    if len(t)>=7:
        break
    i+=1
if i==len(s) and ((t in list)or t==""):
    print("YES")
else: print("NO")

Submission status: Wrong Answer

Solution code:
list=["dream","dreamer","erase","eraser"]
s=input()
t=""
i=0
while(i<len(s)):
    t+=s[i]
    if t in list:
        t=""
    if len(t)>=7:
        break
    i+=1
if i==len(s) and t in list:
    print("YES")
else: print("NO")

Submission status: Wrong Answer

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

S = raw_input()
T = ""

for i in range(4):
    S = S.replace(TS[i],"")

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

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
s = raw_input()
s_sub_a = s[-5:]
s_sub_b = s[-6:]
s_sub_c = s[-7:]

if s_sub_c == "dreamer":
    s = s.replace(s_sub_c, "")
    s_sub_a = s[-5:]
    s_sub_b = s[-6:]
    s_sub_c = s[-7:]
if s_sub_b == "eraser":
    s = s.replace(s_sub_b, "")
    s_sub_a = s[-5:]
    s_sub_b = s[-6:]
    s_sub_c = s[-7:]

if s_sub_a == "dream":
    s = s.replace(s_sub_a, "")
    s_sub_a = s[-5:]
    s_sub_b = s[-6:]
    s_sub_c = s[-7:]

if s_sub_a == "erase":
    s = s.replace(s_sub_a, "")
    s_sub_a = s[-5:]
    s_sub_b = s[-6:]
    s_sub_c = s[-7:]
if len(s) == 0:
    print "YES"
else:
    print "NO"

Submission status: Wrong Answer

Solution code:
a = raw_input()

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

while len(a) > 0:
	if len(a) == 7 or a[:7] in t and a[:7][-1] in ['d', 'e']:
		a = a[7:]
	elif a[:6] in t:
		a = a[6:]
	elif a[:5] in t:
		a = a[5:]
	else:
		print "NO"
		break

if len(a) == 0:
	print "YES"

Submission status: Wrong Answer

Solution code:
s = input()

ans = 'YES'

while len(s) > 0:
    if s.startswith('dreamerd'):
        s = s[7:]
    elif s.startswith('dreamera'):
        s = s[5:]
    elif s.startswith('dreamd'):
        s = s[5:]
    elif s == 'dream':
        break
    elif s.startswith('eraser'):
        s = s[6:]
    elif s.startswith('erase'):
        s = s[5:]
    else:
        ans = 'NO'
        break

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a = raw_input()

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

while len(a) > 0:
	if a[:6] in t:
		a = a[6:]
	elif a[:5] in t:
		a = a[5:]
	else:
		print "NO"
		break

if len(a) == 0:
	print "YES"

Submission status: Wrong Answer

Solution code:
s = raw_input()
s_sub_a = s[-5:]
s_sub_b = s[-6:]
s_sub_c = s[-7:]
if s_sub_a == 'dream' or s_sub_a == 'erase' or s_sub_b == 'eraser' or s_sub_c == 'dreamer':
    print "YES"
else:
    print "NO"

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache
import sys
sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    # 再帰的に解いて解く

    @lru_cache(None)
    def solver(T):
        if T == "":
            print("YES")
            quit()
        if len(T) >= 5:
            if T[:5] == "dream" or T[:5] == "erase":
                solver(T[5:])
        if len(T) >= 6:
            if T[:6] == "eraser":
                solver(T[6:])
        if len(T) >= 7:
            if T[:7] == "dreamer":
                solver(T[7:])
        return

    solver(S)
    print("NO")
    return


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

words = ['dreamer', 'eraser', 'dream', 'erase']
for i in range(4):
    K = words[i]
    words[i] = K[::-1]

T = ''
T_next = ''

while len(T) < len(S):
    if len(T) + 5 > len(S):
        break
    for i in range(4):
        S_next = S[len(T):len(T + words[i])]
        T_next = words[i]
        #print(S_next)
        #print(T_next)
        #print()
        if S_next == T_next:
            T += T_next
            if T == S:
                print('YES')
                exit()
            break

print('NO')

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

T = ''
T_next = ''

while len(T) < len(S):
    if len(T) + 5 > len(S):
        break
    for i in range(4):
        S_next = S[len(T):len(T + words[i])]
        T_next = words[i]
        #print(S_next)
        #print(T_next)
        #print()
        if (words[i] in words[0:1]) and (len(T + T_next) < len(S) and S[len(T + T_next)] == 'a'):
            pass
        elif S_next == T_next:
            T += T_next
            if T == S:
                print('YES')
                exit()
            break

print('NO')

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

T = ''
T_next = ''

while len(T) < len(S):
    if len(T) + 5 > len(S):
        break
    for i in range(4):
        S_head = S[:len(T + words[i])]
        T_next = T + words[i]
        #print(S_head)
        #print(T_next)
        #print()
        if T_next == S:
            print('YES')
            exit()
        elif (words[i] in words[0:1]) and (len(T_next) < len(S) and S[len(T_next)] == 'a'):
            pass
        elif S_head == T_next:
            T = T_next
            break

print('NO')

Submission status: Time Limit Exceeded

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    s = input()
    len_s = len(s)

    a = []

    def rec(n,m):
        if n == len_s:
            a.append(m)
            return
        elif n > len_s:
            return
        if s[n] == "e":
            rec(n+5, m+"erase")
            rec(n+6, m+"eraser")

        elif s[n] == "d":
            rec(n+5, m+"dream")
            rec(n+7, m+"dreamer")

    ans = rec(0,"")
    if len(a) != 0:
        print("YES")
    else:
        print("NO")







if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

words = ['dream', 'dreamer', 'erase', 'eraser']
candidate = ['']
ans = 'NO'

while len(candidate)>0:
    p = candidate.pop()
    if list(p) == s:
        ans = 'YES'
        break
    if len(p) >= len(s):
        continue
    if p == ''.join(s[0:len(p)]):
        for w in words:
            candidate.append(p+w)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

words = ['dream', 'dreamer', 'erase', 'eraser']
candidate = ['']
ans = 'NO'

while len(candidate)>0:
    p = candidate.pop()
    if list(p) == s:
        ans = 'YES'
        break
    if len(p) >= len(s):
        continue
    for w in words:
        candidate.append(p+w)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()
i = 0
while i < len(s):
    if s[i] == 'd':
        S = s[i:i + 5]
        if i + 6 < len(s):
            if S + s[i + 5] + s[i + 6] == "dreamer":
                i += 7
                if i + 3 < len(s):
                    if s[i:i + 4] == "aser":
                        i += 4
                        continue
                if i + 2 < len(s):
                    if s[i:i + 3] == "ase":
                        i += 3
                        continue
                continue
        if S == "dream":
            i += 5
            continue
        break
    elif s[i] == 'e':
        S = s[i:i + 5]
        if i + 5 < len(s):
            if S + s[i + 5] == "eraser":
                i += 6
                continue
        if S == "erase":
            i += 5
            continue
        break
    if i + 4 >= len(s):
        break
else:
    print("YES")
    exit()
print("NO")

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()
i = 0
while i < len(s):
    if s[i] == 'd':
        S = s[i:i + 5]
        if i + 6 < len(s):
            if S + s[i + 5] + s[i + 6] == "dreamer":
                i += 7
                if i + 3 < len(s):
                    if s[i:i + 4] == "aser":
                        i += 4
                        continue
                if i + 2 < len(s):
                    if s[i:i + 3] == "ase":
                        i += 3
                        continue
                continue
        if S == "dream":
            i += 5
            continue
    elif s[i] == 'e':
        S = s[i:i + 5]
        if i + 5 < len(s):
            if S + s[i + 5] == "eraser":
                i += 6
                continue
        if S == "erase":
            i += 5
            continue
    else:
        break
    if i + 4 >= len(s):
        break
else:
    print("YES")
    exit()
print("NO")

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()
i = 0
while i < len(s):
    if s[i] == 'd':
        S = s[i:i + 5]
        if i + 6 < len(s):
            if S + s[i + 5] + s[i + 6] == "dreamer":
                i += 7
                if i + 3 < len(s):
                    if s[i:i + 4] == "aser":
                        i += 4
                        continue
                if i + 2 < len(s):
                    if s[i:i + 3] == "ase":
                        i += 3
                        continue
                continue
        if S == "dream":
            i += 5
            continue
    elif s[i] == 'e':
        S = s[i:i + 5]
        if i + 5 < len(s):
            if S + s[i + 5] == "eraser":
                i += 6
                continue
        if S == "erase":
            i += 5
            continue
    if i + 4 >= len(s):
        break
else:
    print("YES")
    exit()
print("NO")

Submission status: Time Limit Exceeded

Solution code:
# 049 C
S = input()

SS = list(reversed(S))
while len(SS)>0:
    if (SS[0]=='r')and(SS[1]=='e')and(SS[2]=='s')and(SS[3]=='a')and(SS[4]=='r')and(SS[5]=='e'):
        del SS[:6]
    elif (SS[0]=='r')and(SS[1]=='e')and(SS[2]=='m')and(SS[3]=='a')and(SS[4]=='e')and(SS[5]=='r')and(SS[6]=='d'):
        del SS[:7]
    elif (SS[0]=='e')and(SS[1]=='s')and(SS[2]=='a')and(SS[3]=='r')and(SS[4]=='e'):
        del SS[:5]
    elif (SS[0]=='m')and(SS[1]=='a')and(SS[2]=='e')and(SS[3]=='r')and(SS[4]=='d'):
        del SS[:5]
    else:
        print('NO')
        break
if len(SS)==0:
    print('YES')

Submission status: Time Limit Exceeded

Solution code:
import re
                                         
S = input()
T = S
while True:
    if re.search("dreamer$", T):
        T = T[:-7]
    elif re.search("eraser$", T):
        T = T[:-6]
    elif re.search("(dream|erase)$", T):
        T = T[:-5]
    else:
        print("NO")
        break
    if T == "":
        print("YES")
        break

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
t=0
while t<len(s):
    if s[t]=='d':
        if t>len(s)-5:
            print('NO')
            exit()
        if s[t+1]=='r' and s[t+2]=='e' and s[t+3]=='a' and s[t+4]=='m':
            t+=5
            if t==len(s):
                print('YES')
                exit()
            elif t>len(s)-2:
                print('NO')
                exit()
            if s[t]=='e' and s[t+1]=='r':
                if t==len(s)-2:
                    print('YES')
                    exit()
                elif s[t+2]!='a':
                    t+=2
    elif s[t]=='e':
        if t>len(s)-5:
            print('NO')
            exit()
        if s[t+1]=='r' and s[t+2]=='a' and s[t+3]=='s' and s[t+4]=='e':
            t+=5
            if t==len(s):
                print('YES')
                exit()
            elif t>len(s)-1:
                print('NO')
                exit()
            if s[t]=='r':
                if t==len(s)-1:
                    print('YES')
                    exit()
                elif s[t+1]!='a':
                    t+=1
    else:
        print('NO')
        exit()
print('NO')

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
t=0
while t<len(s):
    if s[t]=='d':
        if t>len(s)-5:
            print('NO')
            exit()
        if s[t+1]=='r' and s[t+2]=='e' and s[t+3]=='a' and s[t+4]=='m':
            t+=5
            if t==len(s):
                print('YES')
                exit()
            elif t>len(s)-2:
                print('NO')
                exit()
            if s[t]=='e' and s[t+1]=='r':
                if t==len(s)-2:
                    print('YES')
                    exit()
                elif s[t+2]!='a':
                    t+=2
    elif s[t]=='e':
        if t>len(s)-5:
            print('NO')
            exit()
        if s[t+1]=='r' and s[t+2]=='a' and s[t+3]=='s' and s[t+4]=='e':
            t+=5
            if t==len(s):
                print('YES')
                exit()
            elif t>len(s)-1:
                print('NO')
                exit()
            if s[t]=='r':
                if t==len(s)-1:
                    print('YES')
                    exit()
                elif s[t+1]!='a':
                    t+=1
    else:
        print('NO')
        exit()

Submission status: Time Limit Exceeded

Solution code:
S = input()
S = S[::-1]
candidacies = ["dream", "dreamer", "erase", "eraser"]
candidacies = [c[::-1] for c in candidacies]

fi_flg = False
while fi_flg is False:
  if S[:6] in candidacies:
    S = S[6:]
  elif S[:5] in candidacies:
    S = S[5:]
  elif S[:7] in candidacies:
    S = S[:7]
  else:
    fi_flg = True

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

Submission status: Time Limit Exceeded

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

PARTS = ["eraser", "erase", "dreamer", "dream"]
PARTS2 = []


def main():
    global PARTS2
    sys.setrecursionlimit(100000)
    S = input()

    for i in range(0, 4):
        for j in range(0, 4):
            PARTS2.append(PARTS[i] + PARTS[j])

    PARTS2 = PARTS2 + PARTS

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


def judgeStr(target: str) -> bool:
    for item in PARTS2:
        if target.startswith(item):
            tempStr = target.replace(item, "", 1)
            if tempStr == "" or judgeStr(tempStr):
                return True

    return False


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
t=''
while s!='':
  if len(s)<=4:
    break
  elif s[:5]=='dream':
    if len(s)>=10 and s[5:10]=='erase':
      s=s[5:]
      continue
    elif len(s)>=7 and s[5:7]=='er':
      s=s[7:]
      continue
    else:
      s=s[5:]
      continue
  elif s[:5]=='erase':
    if len(s)>=6 and s[5]=='r':
      s=s[6:]
      continue
    else:
      s=s[5:]
      continue
      
    
if s=='':
  print('YES')
  
else:
  print('NO')

Submission status: Time Limit Exceeded

Solution code:
s=input()
t=''
while s!='':
  if s[:5]=='dream':
    if s[5:10]=='erase':
      s=s[5:]
      continue
    elif s[5:7]=='er':
      s=s[7:]
      continue
  elif s[:5]=='erase':
    if s[5]=='r':
      s=s[6:]
    else:
      s=s[5:]
      
  else:
    break
    
if s=='':
  print('YES')
  
else:
  print('NO')

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input().strip()
N = len(S)
cur = 0
flag = 0
while cur<N:
    if S[cur:cur+5]=="dream":
        if cur+5==N:
            cur += 5
        elif cur+5<N and S[cur+5]=="d":
            cur += 5
        elif S[cur:cur+7]=="dreamer":
            if cur+7==N:
                cur += 7
            elif S[cur+7] in ["d","e"]:
                cur += 7
            elif S[cur+7]=="a":
                cur += 5
            else:
                flag = 1
                break
    elif S[cur:cur+5]=="erase":
        if cur+5==N:
            cur += 5
        elif cur+5<N and S[cur+5]=="r":
            cur += 6
        elif cur+5<N and S[cur+5] in ["d","e"]:
            cur += 5
        else:
            flag = 1
            break
    else:
        flag=1
        break
if flag==0:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
s = input()
s = s.replace("dream", "D")
s = s.replace("erase", "E")
ok = True
i = 0
while i <= len(s)-1:
    if s[i] in ["D","E"]: 
        i += 1
        continue
    if i == 0:
        ok = False
        break
    if s[i] == "e":
        if i+1>len(s) or  s[i+1]!="r" or s[i-1] != "D":
            ok = False
            break
        i += 2
    elif s[i] == "r":
        if s[i-1] != "E":
            ok = False
            break
        i += 1
print("YES" if ok else "NO")

Submission status: Time Limit Exceeded

Solution code:
words = ['maerd','remaerd', 'resare', 'esare']

s = list(input())
s.reverse()

while True:
  chg_flg = False
  for w in words:
    st = ''.join(s)
    if st.startswith(w):
      s = s[len(w):]
      chg_flg = True
  if not chg_flg:
    break

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

Submission status: Time Limit Exceeded

Solution code:
import re

S = input()

list_string = ['dream', 'dreamer', 'erase', 'eraser']
regex = r'(dream(er)?eraser?)+|(eraser?dream(er)?)+|(((dream(er)?)|(eraser?))+)$'

def check(list_string, regex, S):
    while S:
        if re.search(regex, S):
            S =  re.sub(regex, '', S)

        else:
            return 'NO'
    return 'YES'

print(check(list_string, regex, S))

Submission status: Time Limit Exceeded

Solution code:
import re

S = input()

list_string = ['dream', 'dreamer', 'erase', 'eraser']
regex = r'(dream(er)?eraser?)|(eraser?dream(er)?)|(((dream(er)?)|(eraser?))+)$'

def check(list_string, regex, S):
    while S:
        if re.search(regex, S):
            S =  re.sub(regex, '', S)

        else:
            return 'NO'
    return 'YES'

print(check(list_string, regex, S))

Submission status: Time Limit Exceeded

Solution code:
import re

S = input()

list_string = ['dream', 'dreamer', 'erase', 'eraser']
regex = r'((dream(er)?)+|(eraser?)+)+$'

def check(list_string, regex, S):
    while S:
        if re.search(regex, S):
            S =  re.sub(regex, '', S)

        else:
            return 'NO'
    return 'YES'

print(check(list_string, regex, S))

Submission status: Time Limit Exceeded

Solution code:
import re

S = input()

list_string = ['dream', 'dreamer', 'erase', 'eraser']
regex = r'((dream(er)?)|(eraser?))+$'

def check(list_string, regex, S):
    while S:
        if re.search(regex, S):
            S =  re.sub(regex, '', S)

        else:
            return 'NO'
    return 'YES'

print(check(list_string, regex, S))

Submission status: Time Limit Exceeded

Solution code:
import re

S = input()

list_string = ['dream', 'dreamer', 'erase', 'eraser']
regex = r'((dream(er)?)|(eraser?))$'

def check(list_string, regex, S):
    while S:
        if re.search(regex, S):
            S =  re.sub(regex, '', S)

        else:
            return 'NO'
    return 'YES'

print(check(list_string, regex, S))

Submission status: Time Limit Exceeded

Solution code:
import re

S = input()

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

while True:
    if S and S[-1] != 'm' and S[-1] != 'r' and S[-1] != 'e':
        print('NO')
        break

    if len(S) == 0:
        print('YES')
        break
    flg = False
    for s in list_string:
        if re.search(f'{s}$', S):
            S = re.sub(f'{s}$', '', S)
            flg = True

    if flg:
        continue
    else:
        print('NO')
        break

Submission status: Time Limit Exceeded

Solution code:
import re

S = input()

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

while True:
    if len(S) == 0:
        print('YES')
        break
    flg = False
    for s in list_string:
        if re.search(f'{s}$', S):
            S = re.sub(f'{s}$', '', S)
            flg = True

    if flg:
        continue
    else:
        print('NO')
        break

Submission status: Time Limit Exceeded

Solution code:
S = input()
 
import re
 
li = ['dream','dreamer','erase','eraser']
 
 
while len(list(S)) > 8: 
    if S[0] == 'd':
        if S[0:5] == 'dream':
            if S[5:10] == 'erase':
                S = S[5:]
            elif S[5:10] == 'dream':
                S = S[5:]
            elif S[5:7] == 'er':
                if S[7:12] == 'dream':
                    S = S[7:]
                elif S[7:12] == 'erase':
                    S = S[7:]
            else:break
 
    else:
        if S[0:6] == 'eraser':
            S = S[6:]
        elif S[0:5] == 'erase':
            if S[5:10] == 'erase':
                S = S[5:]
            elif S[5:10] == 'dream':
                S = S[5:]
        else:break
k = 0 
for l in li:
    if S == l:k = 1
if k == 0:print('NO')
else:print('YES')

Submission status: Time Limit Exceeded

Solution code:
import sys
N = list(input())

N_rev = N[::-1]
#print(N_rev[1:5])

while len(N_rev) > 0:
  if N_rev[0] == "m" and N_rev[1] == "a" and N_rev[2] == "e" and N_rev[3] == "r" and N_rev[4] == "d":
      N_rev = N_rev[5:]
      #print("subscript[dream]",N_rev)
  elif N_rev[0] == "r" and N_rev[1] == "e" and N_rev[2] == "m" and N_rev[3] == "a" and N_rev[4] == "e" and N_rev[5] == "r" and N_rev[6] == "d":
      N_rev = N_rev[7:]
      #print("subscript[dreamer]",N_rev)
  elif N_rev[0] == "r" and N_rev[1] == "e" and N_rev[2] == "s" and N_rev[3] == "a" and N_rev[4] == "r" and N_rev[5] == "e":
      N_rev = N_rev[6:]
      #print("subscript[eraser]",N_rev)
      
  elif N_rev[0] == "e" and N_rev[1] == "s" and N_rev[2] == "a" and N_rev[3] == "r" and N_rev[4] == "e":
      N_rev = N_rev[5:]

  else:
    print("NO")
    sys.exit()

if len(N_rev) == 0:
  print("YES")

Submission status: Time Limit Exceeded

Solution code:
import sys
N = list(input())


N_rev = N[::-1]
#print(N_rev)

while len(N_rev) > 0:
  if N_rev[0] == "m":
    if N_rev[1] == "a" and N_rev[2] == "e" and N_rev[3] == "r" and N_rev[4] == "d":
      N_rev = N_rev[5:]
      #print("subscript[dream]",N_rev)
    else:
      print("NO")
      sys.exit()
  elif N_rev[0] == "r":
    if N_rev[1] == "e" and N_rev[2] == "m" and N_rev[3] == "a" and N_rev[4] == "e" and N_rev[5] == "r" and N_rev[6] == "d":
      N_rev = N_rev[7:]
      #print("subscript[dreamer]",N_rev)
    elif N_rev[1] == "e" and N_rev[2] == "s" and N_rev[3] == "a" and N_rev[4] == "r" and N_rev[5] == "e":
      N_rev = N_rev[6:]
      #print("subscript[eraser]",N_rev)
    else:
      print("NO")
      sys.exit()
  elif N_rev[0] == "e":
    if N_rev[1] == "s" and N_rev[2] == "a" and N_rev[3] == "r" and N_rev[4] == "e":
      N_rev = N_rev[5:]
      #print("subscript[erase]",N_rev)
    else:
      print("NO")
      sys.exit()
  else:
    print("NO")
    sys.exit()

if len(N_rev) == 0:
  print("YES")