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: Time Limit Exceeded

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
                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
                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":
                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
                        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("YES")
                    exit()
            else:
                print("NO")
                exit()
        else:
            print("NO")
            exit()
    p = 0
print("YES")

Submission status: Time Limit Exceeded

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

s = input()
stack = [0]
mem = [0]
ok = False
loop = 0
while len(stack) > 0:
    loop += 1
    #print(stack, mem)
    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 part.startswith('d') or part.startswith('e') or part == '':
                if next_start_id not in mem:
                    stack.append(next_start_id)
                    mem.append(next_start_id)
if not ok:
    print('NO')

Submission status: Time Limit Exceeded

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

s = input()
stack = [0]
mem = [0]
ok = False
while len(stack) > 0:
    start_id = stack.pop()
    string = s[start_id:]
    if string == '':
        print('YES')
        ok = True
        break
    for rule in rules:
        if string.startswith(rule):
            next_start_id = start_id + len(rule)
            part = string[next_start_id:]
            if part not in mem:
                stack.append(next_start_id)
                mem.append(next_start_id)
if not ok:
    print('NO')

Submission status: Time Limit Exceeded

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

stack = [input()]
mem = [stack[0]]
ok = False
while len(stack) > 0:
    string = stack.pop()
    if string == '':
        print('YES')
        ok = True
        break
    for rule in rules:
        if string.startswith(rule):
            part = string[len(rule):]
            if part not in mem:
                stack.append(part)
                mem.append(part)
if not ok:
    print('NO')

Submission status: Time Limit Exceeded

Solution code:
#AtCorder Begginer Contest 049 C Daydream

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

dream = "dream"[::-1]
dreamer = "dreamer"[::-1]
erase = "erase"[::-1]
eraser = "eraser"[::-1]

while len(s) > 0:
    if s.startswith(dreamer):
        s = s.replace(dreamer,"",1)
    elif s.startswith(dream):
        s = s.replace(dream,"",1)

    if s.startswith(eraser):
        s = s.replace(eraser,"",1)
    elif s.startswith(erase):
        s = s.replace(erase,"",1)

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

Submission status: Time Limit Exceeded

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

while len(S) > 0:
    if S[:5] == 'maerd':
        S = S[:5]
    elif S[:5] == 'esare':
        S = S[5:]
    elif S[:6] == 'resare':
        S = S[6:]
    elif S[:7] == 'remaerd':
        S = S[7:]
    else:
        print('NO')
        break

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

Submission status: Time Limit Exceeded

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

while len(S) > 0:
    if S[:5] == 'maerd':
        S = S[:5]
    elif S[:5] == 'esare':
        S = S[5:]
    elif S[:6] == 'resare':
        S = S[6:]
    elif S[:7] == 'remaerd':
        S = S[7:]
    else:
        print('NO')

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_list = list(s)
while True:
    l5 = s_list[-5:]
    l6 = s_list[-6:]
    l7 = s_list[-7:]
    s5 = s6 = s7 = ''

    for ch in l5:
        s5 += ch
#    print("s5 :", s5)
    for ch in l6:
        s6 += ch
#    print("s6 :", s6)
    for ch in l7:
        s7 += ch
#    print("s7 :", s7)

    if (s5 == 'erase') | (s5 == 'dream'): 
        s_list = s_list[:-5]
#       print("s_list:", s_list)
    elif s6 == 'eraser':
        s_list = s_list[:-6]
#       print("s_list:", s_list)
    elif s7 == 'dreamer':
        s_list = s_list[:-7]
#       print("s_list:", s_list)
    else:
        print('NO')
#       print("s_list:", s_list)
        exit()

    if  s_list == []:
        print('YES')
        exit()

Submission status: Time Limit Exceeded

Solution code:
S = input()
S = S[::-1]
C = ['maerd', 'remaerd', 'esare', 'resare']
ans = False
for j in range(len(S)):
    for i in range(len(S)):
        if S[0:i] in C:
            S = S[i:len(S)]
            ans = True
            break
if ans:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
S = input()
C = ["dream", "dreamer", "erase", "eraser"]
c = 0
flag = False
while len(S) > c:
    T = ([S.split(i) for i in C])
    for i in range(len(T)):
        if T[i][0] in C:
            S = S[len(T[i][0]):len(S)]
            flag = True
            break
        else:
            flag = False
    c+=1
if flag:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
s = 'dreamdreamer'
s = input()
tmps = [ 'dream', 'dreamer', 'erase', 'eraser' ]
lists = []
for tmp in tmps:
    lists.append(tmp[::-1])
s = s[::-1]

stack = ['']
rtn = 'NO'
while len(stack)>0:
    txt = stack.pop(0)
    for item in lists:
        tmp_txt = txt + item
        if tmp_txt == s:
            stack = []
            rtn = 'YES'
            break
        if(s.find(tmp_txt) == 0):
            stack.append(tmp_txt)

print(rtn)

Submission status: Time Limit Exceeded

Solution code:
# s = 'dreamdareamer'
s = input()
lists = [ 'dream', 'dreamer', 'erase', 'eraser' ]
stack = ['']
rtn = 'NO'
while len(stack)>0:
    txt = stack.pop(0)
    for item in lists:
        tmp_txt = txt + item
        if tmp_txt == s:
            stack = []
            rtn = 'YES'
            break
        if( len(tmp_txt) < len(s) ):
            stack.append(tmp_txt)

print(rtn)

Submission status: Time Limit Exceeded

Solution code:
S = input()

S = S.replace("dream",'/*/').replace('erase','/+/')
S = S.split('/')
while '' in S:
    S.remove('')
for i in range(len(S)):
    if S[i] == '*' or S[i] == '+':
        continue
    if S[i] == 'r':
        if i != 0 and S[i-1] == '+':
            continue
    elif S[i] == 'er':
        if i != 0 and S[i-1] == '*':
            continue
    print('NO')
    exit()
print('YES')

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)
s = input()
ans = False
def dfs(now, length):
  global ans
  if len(now) >= length:
    if now == s:
      ans = True
    return
  
  dfs(now + 'dream', length)
  dfs(now + 'dreamer', length)
  dfs(now + 'erase', length)
  dfs(now + 'eraser', length)

dfs('', len(s))

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

Submission status: Time Limit Exceeded

Solution code:
import re
s = input()

while s != "":
  if len(s) < 5:
    print('NO')
    exit()
  if s.endswith('dream'):
    s = re.sub("dream$", "", s)
  elif s.endswith('dreamer'):
    s = re.sub("dreamer$", "", s)
  elif s.endswith('erase'):
    s = re.sub("erase$", "", s)
  elif s.endswith('eraser'):
    s = re.sub("eraser$", "", s)
  else:
    print('NO')
    exit()
  
print('YES')

Submission status: Time Limit Exceeded

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

while True:
    flag = False
    for data in datas:
        if s[::-1].startswith(data[::-1]):
            s = s[:-len(data)]
            flag = True
            break
    if not flag:
        break
if len(s):
    print('NO')
else:
    print('YES')

Submission status: Time Limit Exceeded

Solution code:
s = list(str(input()))

for i in range(len(s)- 5):
    if s[i] == 'e' and s[i+1] == 'r' and s[i + 2] == 'a' and s[i + 3] == 's' and s[i + 4] == 'e' and s[i+5] == 'r':
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''
        s[i + 5] = ''
        
while '' in s:
    s.remove('')
    
for i in range(len(s)- 4):
    if s[i] == 'e' and s[i+1] == 'r' and s[i + 2] == 'a' and s[i + 3] == 's' and s[i + 4] == 'e' :
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''
        
while '' in s:
    s.remove('')
    
    
    
for i in range(len(s)- 6):
    if s[i] == 'd' and s[i+1] == 'r' and s[i + 2] == 'e' and s[i + 3] == 'a' and s[i + 4] == 'm' and s[i + 5] == 'e' and s[i + 6] == 'r':
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''
        s[i + 5] = ''
        s[i+6] = ''
        
while '' in s:
    s.remove('')
    
for i in range(len(s)- 4):
    if s[i] == 'd' and s[i+1] == 'r' and s[i + 2] == 'e' and s[i + 3] == 'a' and s[i + 4] == 'm' :
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''

        
while '' in s:
    s.remove('')
    
if s == []:
    print('YES')
else:
    print('NO')

Submission status: Time Limit Exceeded

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


S = input() + '_'
T_s = ["dream", "dreamer", "erase", "eraser"]

while True:
    S_ = S
    for T in T_s:
        S = S.replace(T + "_", "_")
    if S_ == S:
        break

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

Submission status: Time Limit Exceeded

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

N = input()
T = ''
char_one = 'dream'
char_two = 'dreamer'
char_three = 'erase' 
char_four = 'eraser'
char_list = [char_one[::-1], char_two[::-1], char_three[::-1], char_four[::-1]]
reverse_string = N[::-1]

start = time.time()
concat_str = ''
i = 0

while i < len(N):
    for string in char_list:
        if reverse_string.find(string) == 0:
            i += len(string)
            reverse_string = re.sub(string, '', reverse_string)
            break
    if i == 0:
       break

if i == len(N):
   print('YES')
else:
   print('NO')

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()

while s:
    r = re.search(r"(dream|dreamer|erase|eraser)$", s)
    if r:
        s = s[:r.start()]
    else:
        print("NO")
        break
else:
    print("YES")

Submission status: Time Limit Exceeded

Solution code:
string = list(input())
erase = 'erase'
eraser = 'eraser'
dream = 'dream'
dreamer = 'dreamer'
er = 'er'
a = 'a'
r = 'r'
while True:
    if "".join(string[:5]) == dream:
        if "".join(string[5:7]) == er:
            if "".join(string[7:8]) == a:
                string = string[5:]
            else:
                string = string[7:]
        else:
            string = string[5:]
    elif "".join(string[:5]) == erase:
        if "".join(string[5:6]) == r:
            if "".join(string[6:7]) == a:
                string = string[5:]
            else:
                string = string[6:]
        else:
                string = string[5:]
    elif string == []:
        print('YES')
        break
    else:
        print('NO')
        break

Submission status: Time Limit Exceeded

Solution code:
def c_daydream(S):
    import re
    # Sを逆にしたものから該当する文字を除いていき、空文字列にできるか？
    s = S[::-1]
    dict = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
    n = len(s)
    while n > 0:
        for d in dict:
            if s.startswith(d):
                s = re.sub('^' + d, '', s)
                break
        else:
            return 'NO'
        n = len(s)
    return 'YES'

S = input().strip()
print(c_daydream(S))

Submission status: Time Limit Exceeded

Solution code:
s=input()
w=["dream","dreamer","erase","eraser"]
while True:
    if len(s)==0:
        print("YES")
        exit()
    if len(s)<=4:
        print("NO")
        exit()
    
    if s[0:5]==w[0]:
        if len(s)>=7:
            if s[5:7]=="er": #dremaerかeraserかerase
                if s[7]=="a": #erはeraseかeraserのer
                    s=s[5:]
                else:
                    s=s[7:]
        else:
            s=s[5:]

    elif s[0:5]==w[2]:
        if s[5]=="r": 
            s=s[6:]
        else:
            s=s[5:]
    else:
        print("NO")
        exit()

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

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()
flg = True
while flg:
    flg = False
    for rp in ['dream', 'dreamer', 'erase', 'eraser']:
        aft = re.sub(rp+'$', '', s)
        ##print(s,rp,aft, flg)
        if s != aft:
            s = aft
            flg = True
if s == '':
    print('YES')
else:
    print('NO')

Submission status: Time Limit Exceeded

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

import sys

s = input()

a1 = "dream"
a2 = "dreamer"
a3 = "erase"
a4 = "eraser"

while True:
    if len(s) < 5:
        print("NO")
        sys.exit(0)
    elif len(s) == 5:
        if s in ["dream", "erase"]:
            print("YES")
        else:
            print("NO")
        sys.exit(0)
    elif len(s) == 6:
        if s == "eraser":
            print("YES")
        else:
            print("NO")
        sys.exit(0)
    elif len(s) == 7:
        if s == "dreamer":
            print("YES")
        else:
            print("NO")
        sys.exit(0)
    else:
        if s[:7] in ["dreamerd", "dreamere"]:
            s = s[7:]
        elif s[:6] in ["dreamd", "dreame", "erasee", "erased"]:
            s = s[5:]
        elif s[:7] in ["eraserd", "erasere"]:
            s = s[6:]
        continue

Submission status: Time Limit Exceeded

Solution code:
import sys
S=raw_input()
judge=["dream","dreamer","erase","eraser"]

S_pointer=0

V=set()
V.add(0)

cnt=0
while cnt<len(S)/5+1:
	tmp=set()
	for i in V:
		for j in judge:
			if S[i:i+7].find(j)==0:
				if i+len(j)==len(S):
					tmp.add(i+len(j))
					print "YES"
					sys.exit()
				else:
					tmp.add(i+len(j))

	V=V|tmp
	cnt+=1

#print V

print "YES" if max(V)==len(S) else "NO"

Submission status: Time Limit Exceeded

Solution code:
S=raw_input()
judge=["dream","dreamer","erase","eraser"]

S_pointer=0

V=set()
V.add(0)

cnt=0
while cnt<len(S):
	tmp=set()
	for i in V:
		for j in judge:
			if S[i:i+7].find(j)==0:	
				tmp.add(i+len(j))

	V=V|tmp
	cnt+=1

#print V

print "YES" if max(V)==len(S) else "NO"

Submission status: Time Limit Exceeded

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")

def addString(src, add_strings):
    return [src + add_string for add_string in add_strings]

Ts = []
if input_string[0] == "e":
    Ts = ["eraser", "erase"]
elif input_string[0] == "d":
    Ts = ["dreamer", "dream"]
else:
    print("No")
    exit(1)

while(1):
    for T in Ts:
        if T == input_string:
            print("YES")
            exit(0)

    next_Ts = []

    for T in Ts:
        next_Ts += addString(T, add_strings)

    Ts = [] + next_Ts

    # for T in Ts:
    #     if len(T) > len(input_string):
    #         del T

    Ts = [T for T in Ts if len(T) < len(input_string)]
    if len(Ts) == 0:
        print("No")
        exit(1)

Submission status: Time Limit Exceeded

Solution code:
import sys
def DFS(list,s,t):
    if s==t:
        print("YES")
        sys.exit()
    if not t in s:
        return

    for i in list:
        DFS(list,s,t+i)
    return

list=["dream","dreamer","erase","eraser"]
s=input()
t=""
DFS(list,s,t)
print("NO")

Submission status: Time Limit Exceeded

Solution code:
def DFS(list,s,t):
    if s==t:
        return True
    if not t in s:
        return False

    for i in list:
        if(DFS(list,s,t+i)): return True
    return False

list=["dream","dreamer","erase","eraser"]
s=input()
t=""
if DFS(list,s,t):
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
words = ("dreamer", "eraser", "dream", "erase")

s = input()

pos = 0
while pos < len(s):
    for w in words:
        if s.startswith(w, pos):
            pos += len(w)
            break
if pos == len(s):
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
import re
words = (re.compile("^dreamer"), re.compile("^eraser"), re.compile("^dream"), re.compile("^erase"))

s = input()

while s != "":
    for w in words:
        if w.match(s) is not None:
            s = w.sub("", s)
            break
    if s == "":
        print("YES")
        exit()
print("NO")

Submission status: Time Limit Exceeded

Solution code:
def DFS(list,s,t):
    if s==t:
        return True
    if not t in s:
        return False

    for i in list:
        if(DFS(list,s,t+i)): return True

list=["dream","dreamer","erase","eraser"]
s=input()
t=""
if DFS(list,s,t):
    print("YES")
else: print("NO")

Submission status: Memory Limit Exceeded

Solution code:
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 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


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

    solver(S)
    print("NO")
    return


if __name__ == "__main__":
    main()

Submission status: Memory 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()
    # 再帰的に解いて解く

    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: Memory Limit Exceeded

Solution code:
words = ("dream","dreamer","erase","eraser")
import sys
readline = sys.stdin.readline

S = readline().rstrip()

stack = [("",0)]
while stack:
  s,ind = stack.pop()
  if s == S:
    print("YES")
    break
  for w in words:
    if S[ind:ind + len(w)] == w:
      stack.append([s + w, ind + len(w)])
else:
  print("NO")

Submission status: Memory Limit Exceeded

Solution code:
words = ("dream","dreamer","erase","eraser")
import sys
readline = sys.stdin.readline

S = readline().rstrip()

stack = list(words)
while stack:
  s = stack.pop()
  if not S.startswith(s):
    continue
  if s == S:
    print("YES")
    break
  for w in words:
    stack.append(s + w)
  
else:
  print("NO")

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(100000)

s = 'HAKUTYUMU' + input()


def check(s):
    next_s = s

    if s[-5:] == 'dream':
        next_s = s[:-5]
    if s[-7:] == 'dreamer':
        next_s = s[:-7]
    if s[-5:] == 'erase':
        next_s = s[:-5]
    if s[-6:] == 'eraser':
        next_s = s[:-6]

    if s == 'HAKUTYUMU':
        return True

    if s == next_s:
        return False

    return check(next_s)


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

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(100000)
S = input()
def trans(s,i):
    if s == "":
        return "YES"
    if i == 0:
        t = s[:5]
        if t == "dream":
            return trans(s[5:],1)
        elif t == "erase":
            return trans(s[5:],2)
        else:
            return "NO"
    elif i == 1:
        if s[:5] == "dream":
            return trans(s[5:],1)
        elif s[:2] == "er":
            return trans(s[2:],3)
        else:
            return "NO"
    elif i == 2:
        if s[:5] == "dream":
            return trans(s[5:],1)
        elif s[:5] == "erase":
            return trans(s[5:],2)
        elif s[:1] == "r":
            return trans(s[1:],0)
        else:
            return "NO"
    elif i == 3:
        if s[:5] == "dream":
            return trans(s[5:],1)
        elif s[:3] == "ase":
            return trans(s[3:],2)
        elif s[:5] == "erase":
            return trans(s[5:],2)
        else:
            return "NO"
    
print(trans(S,0))

Submission status: Memory Limit Exceeded

Solution code:
# dfs
import sys
sys.setrecursionlimit(10**6)


C = ['dream', 'dreamer', 'erase', 'eraser']
S = input()
L = len(S)


def dfs(x):
    l = len(x)
    if l >= L:
        if S == x:
            return True
        else:
            return False

    match = S[l:l+7]
    for c in C:
        if match.find(c) == 0:
            if dfs(x+c):
                return True
    return False


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

Submission status: Memory Limit Exceeded

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

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


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

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


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

    return False


if __name__ == "__main__":
    main()

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10000000)
s=input()
text=['dream','dreamer','erase','eraser']

def bfs(t):
  if t == s:
    return 1
  if len(t) >= len(s):
    return 0
  if t != s[:len(t)]:
    return 0
  ans = 0
  for tx in text:
    ans += bfs(t+tx)
  return ans

if bfs('') > 0:
  print('YES')
else:
  print('NO')

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(20000)
def saiki(T):
  if T==str():
    return "YES"
  if len(T)<5:
    return "NO"
  if T[-5:]=="dream":
    return saiki(str(T[:-5]))
  elif T[-7:]=="dreamer":
    return saiki(str(T[:-7]))
  elif T[-5:]=="erase":
    return saiki(str(T[:-5]))
  elif T[-6:]=="eraser" :
    return saiki(str(T[:-6]))
  else:
    return "NO"
S=input()
print(saiki(S))

Submission status: Memory Limit Exceeded

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50

def dfs(seq):
    if seq in ['dreamer', 'dream', 'erase', 'eraser']:
        return True

    if seq[:7] == 'dreamer':
        if dfs(seq[5:]):
            return True
        elif dfs(seq[7:]):
            return True
        else:
            return False

    elif seq[:5] == 'dream':
        return dfs(seq[5:])

    elif seq[:6] == 'eraser':
        return dfs(seq[6:])

    elif seq[:5] == 'erase':
        return dfs(seq[5:])
    else:
        return False


def run():
    S = input()
    if dfs(S):
        print('YES')
    else:
        print('NO')


if __name__ == "__main__":
    run()

Submission status: Memory Limit Exceeded

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50

def dfs(seq):
    if seq in ['dreamer', 'dream', 'erase', 'eraser']:
        return True

    if seq[:7] == 'dreamer':
        if dfs(seq[5:]) or dfs(seq[7:]):
            return True
        else:
            return False

    elif seq[:5] == 'dream':
        return dfs(seq[5:])

    elif seq[:6] == 'eraser':
        return dfs(seq[6:])

    elif seq[:5] == 'erase':
        return dfs(seq[5:])
    else:
        return False


def run():
    S = input()
    if dfs(S):
        print('YES')
    else:
        print('NO')


if __name__ == "__main__":
    run()

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(3*10**4)
def test(t):
    if len(t)==len(s):
        print('YES')
        exit()
    if s[len(t):len(t)+5]=='dream':
        test(t+'dream')
    if s[len(t):len(t)+7]=='dreamer':
        test(t+'dreamer')
    if s[len(t):len(t)+5]=='erase':
        test(t+'erase')
    if s[len(t):len(t)+6]=='eraser':
        test(t+'eraser')
s=input()
test('')
print('NO')

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
def test(t):
    if len(t)==len(s):
        print('YES')
        exit()
    if s[len(t):len(t)+5]=='dream':
        test(t+'dream')
    if s[len(t):len(t)+7]=='dreamer':
        test(t+'dreamer')
    if s[len(t):len(t)+5]=='erase':
        test(t+'erase')
    if s[len(t):len(t)+6]=='eraser':
        test(t+'eraser')
s=input()
test('')
print('NO')

Submission status: Memory Limit Exceeded

Solution code:
import sys
import resource
sys.setrecursionlimit(100000)

def hantei(S):
  if S == 'dream' or S == 'dreamer' or S == 'erase' or S == 'eraser':
    return 1
  if S[:5] == 'dream':
    if S[:7] == 'dreamer':
      return hantei(S[5:]) | hantei(S[7:])
    else:
      return hantei(S[5:])
  if S[:5] == 'erase':
    if S[:6] == 'eraser':
      return hantei(S[5:]) | hantei(S[6:])
    else:
      return hantei(S[5:])
  else:
    return 0

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

Submission status: Memory Limit Exceeded

Solution code:
S = input()
N = len(S)
op = [""]
while len(op):
    T = op.pop()
    len_T = len(T)
    if S == T:
        print("YES")
        exit(0)
    if len_T + 5 <= N:
        if S[len_T:len_T+5] == "dream":
            op.append(T + "dream")
            if len_T + 5 < N:
                if not (S[len_T + 5] == "e" or S[len_T + 5] == "d"):
                    op.pop()
            if len_T + 7 <= N:
                if S[len_T:len_T+7] == "dreamer":
                    op.append(T + "dreamer")
                    if len_T + 7 < N:
                        if not (S[len_T + 7] == "e" or S[len_T + 7] == "d"):
                            op.pop()
        elif S[len_T:len_T+5] == "erase":
            op.append(T + "erase")
            if len_T + 5 < N:
                if not (S[len_T + 5] == "e" or S[len_T + 5] == "d"):
                    op.pop()
            if len_T + 6 <= N:
                if S[len_T:len_T+6] == "eraser":
                    op.append(T + "eraser")
                    if len_T + 6 < N:
                        if not (S[len_T + 6] == "e" or S[len_T + 6] == "d"):
                            op.pop()
print("NO")

"""if len_T + 5 < N:
    if not (S[len_T + 5] == "e" or S[len_T + 5] == "d"):
        op.pop()

if len_T + 6 < N:
    if not (S[len_T + 6] == "e" or S[len_T + 6] == "d"):
        op.pop()

if len_T + 7 < N:
    if not (S[len_T + 7] == "e" or S[len_T + 7] == "d"):
        op.pop()
"""

Submission status: Memory Limit Exceeded

Solution code:
S = input()
N = len(S)
op = [""]
while len(op):
    T = op.pop()
    len_T = len(T)
    if S == T:
        print("YES")
        exit(0)
    if len_T + 5 <= N:
        if S[len_T:len_T+5] == "dream":
            op.append(T + "dream")
            if len_T + 7 <= N:
                if S[len_T:len_T+7] == "dreamer":
                    op.append(T + "dreamer")
        elif S[len_T:len_T+5] == "erase":
            op.append(T + "erase")
            if len_T + 6 <= N:
                if S[len_T:len_T+6] == "eraser":
                    op.append(T + "eraser")
print("NO")

"""if len_T + 5 <= N:
    if not (S[len_T] == "e" or S[len_T] == "d"):
        op.pop()
"""