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: Runtime Error

Solution code:
ins = input()


def foo(s):
    last = s[-1]
    # is empty
    if not s:
        return "YES"
    else:
        n = 0
        if last == 'r' and s[-6:] == 'eraser':
            n = -6
        elif last == 'r' and s[-7:] == 'dreamer':
            n = -7
        elif (last == 'e' and s[-5:] == 'erase') or (last == 'm' and s[-5:] == 'dream'):
            n = -5

        if n == 0:
            return "NO"
        else:
            return foo(s[:n])


print(foo(ins))

Submission status: Runtime Error

Solution code:
s = input()

ichi = 0
cnt = 0
l = len(s)

while True:
    s_dreamer = s.find ("dreamer",ichi,l)
    s_eraser = s.find ("eraser",ichi,l)
    s_dream = s.find ("dream",ichi,l)
    s_erase = s.find ("erase",ichi,l)


    if s_dream == ichi:
        ichi = s_dreamer + 7
        cnt += 7 

    elif s_eras == ichi:
        ichi = s_eraser + 6
        cnt += 6  

    elif s_dreamer == ichi:
        ichi = s_dream + 5
        cnt += 5  

    elif s_eraser == ichi:
        ichi = s_erase + 5
        cnt += 5

    elif cnt == l:
        print("YES")
        break

    else:
        print("NO")
        break

Submission status: Runtime Error

Solution code:
s=input()
ind =0
len_s=len(s)
s = s+ "zzzzzzzzzz"

A = "dreamer"
B= "dream"
C= "erase"
D="eraser"

flag =True
while(1):
    if(s[ind] =="d"):
        if(s[ind + 5] =="d"):
            if(s[ind:ind+5]!=B):
                flag = False
                break
            else:
                ind+=5
        else:
            if(s[ind+5]!='e'):
                flag=False
                break
            if(s[ind+7] == "a"):
                if(s[ind:ind+5]!=B):
                    flag = False
                    break
                else:
                    ind+=5

            else:
                if(s[ind:ind+7] !=A):
                    flag = false
                    break
                else:
                    ind+=7
    elif(s[ind]=="e"):
        if(s[ind+5]=="r"):
            if(s[ind:ind+6]!=D):
                flag = False
                break
            else:
                ind+=6

        else:
            if(s[ind:ind +5] !=C):
                flag =False
                break
            else:
                ind+=5
    else:
        flag=False
        break
    if(ind == len_s):
        break
    if(ind > len_s):
        flag=False
        break
if(flag):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s=input()
ind =0
len_s=len(s)
s = s+ "zzzzzzzzzz"

A = "dreamer"
B= "dream"
C= "erase"
D="eraser"

flag =True
while(1):
    if(s[ind] =="d"):
        if(s[ind + 5] =="d"):
            if(s[ind:ind+5]!=B):
                flag = False
                break
            else:
                ind+=5
        else:
            if(s[ind+5]!='e'):
                flag=False
                break
            if(s[ind+7] == "a"):
                if(s[ind:ind+5]!=B):
                    flag = False
                    break
                else:
                    ind+=5

            else:
                if(s[ind:ind+7] !=A):
                    flag = false
                    break
                else:
                    ind+=7
    elif(s[ind]=="e"):
        if(s[ind+5]=="r"):
            if(s[ind:ind+6]!=D):
                flag = False
                break
            else:
                ind+=6

        else:
            if(s[ind:ind +5] !=C):
                flag =False
                break
            else:
                ind+=5
    else:
        flag=False
        break
    if(ind == len_s):
        break
    if(ind > len(s)):
        flag=False
        break
if(flag):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s=input()
ind =0
len_s=len(s)
s = s+ "zzzzzzzzzz"

A = "dreamer"
B= "dream"
C= "erase"
D="eraser"

flag =True
while(1):
    if(s[ind] =="d"):
        if(s[ind + 5] =="d"):
            if(s[ind:ind+5]!=B):
                flag = False
                break
            else:
                ind+=5
        else:
            if(s[ind+5]!='e'):
                flag=False
                break
            if(s[ind+7] == "a"):
                if(s[ind:ind+5]!=B):
                    flag = False
                    break
                else:
                    ind+=5

            else(s[ind:ind+7] !=A):
                flag = false
                break
            else:
                ind+=7
    elif(s[ind]=="e"):
        if(s[ind+5]=="r"):
            if(s[ind:ind+6]!=D):
                flag = False
                break
            else:
                ind+=6

        else:
            if(s[ind:ind +5] !=C):
                flag =False
                break
            else:
                ind+=5
    else:
        flag=False
        break
    if(ind == len_s):
        break
    if(ind > len(s)):
        flag=False
        break
if(flag):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
S = input()

def func(S):
    if S == '':
        return True
    a, b, c, d = False, False, False, False
    if S[0:5] == 'dream':
        a = func(S[5:])
        if S[5:7] == 'er':
            b =  func(S[7:])
    elif S[0:5] == 'erase':
        c = func(S[5:])
        if S[5] == 'r':
            d = func(S[6:])
    else:
        return False
    return a or b or c or d

print('YES' if func(S) else 'NO')

Submission status: Runtime Error

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

def check(string):
    if string[-5:] == "dream":
        new = string[:-5]
        return new

    if string[-7:] == "dreamer":
        new = string[:-7]
        return new

    if string[-5:] == "erase":
        new = string[:-5]
        return new

    if string[-6:] == "eraser":
        new = string[:-6]
        return new

    print("NO")


if __name__ == '__main__':
    s = str(input())

    while s:
        print(s)
        s = check(s)

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

Submission status: Runtime Error

Solution code:
import sys
S = input()
S = S[::-1]
while S:
    if S[:3]=="res":
        if S[:6]=="resare":
            S = S[6:]
            print(S)
        else:
            print("NO")
            sys.exit()

    elif S[:3]=="esa":
        if S[:5]=="esare":
            S = S[5:]
            print(S)
        else:
            print("NO")
            sys.exit()
    
    elif S[:3]=="rem":
        if S[:7]=="remaerd":
            S = S[7:]
            print(S)
        else:
            print("NO")
            sys.exit()
        
    elif S[:3]=="mae":
        if S[:5]=="maerd":
            S = S[5:]
            print(S)
        else:
            print("NO")
            sys.exit()
            
    else:
        print("NO")
        sys.exit()
else:
    print("YES")

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
s = input()

while len(s) > 4:
    if s[-5:] == 'deram' or 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 len(s) == 0:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
s = input()

while len(s):
    if s[-5:] == 'deram' or 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 len(s) == 0:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
s = input()
while len(s) > 0 :
    if s[:7] == 'dreamer':
        del s[:7]
    elif s[:7] == 'eraser':
        del s[:7]
    elif s[:5] == 'dream':
        del s[:5]
    elif s[:5] == 'erase':
        del s[:5]
    else:
        break
print(('NO','Yes')[len(s)==0])

Submission status: Runtime Error

Solution code:
W=["dream", "dreamer", "erase", "eraser" ]
def srch(word):
    if word=="":
        print("YES")
        exit()

    for w in W:
        if word[:len(w)] == w:
            srch(word[len(w):])

srch(input())
print("NO")

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

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


def dfs(n):
    if n == len(s):
        return True
    for w in words:
        if s[n:].startswith(w):
            if dfs(n + len(w)):
                return True
    return False


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

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']
L = len(max(words, key=len))


def dfs(n):
    if n == len(s):
        return True
    for w in words:
        if w in s[n:n + L]:
            if dfs(n + len(w)):
                return True
    return False


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

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

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


def dfs(n):
    if n == len(s):
        return True
    for w in words:
        if w in s[n:]:
            if dfs(n + len(w)):
                return True
    return False


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

Submission status: Runtime Error

Solution code:
s = input()

while len(s)>4:
    if s[-5:] == 'dream':
        s = s[:-5]
        continue
    elif s[-7:] == 'dreamer':
        s = s[:-7]
        continue
    elif s[-5:] == 'erase':
        s = s[:-5]
        continue
    elif s[-6:] == 'eraser':
        s = s[:-6]
        continue
    else:
        beak
if s =='' :
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
s = input()

while len(s)>4:
    if s[-5:] == 'dream':
        s = s[:-5]
    elif s[-7:] == 'dreamer':
        s = s[:-7]
    elif s[-5:] == 'erase':
        s = s[:-5]
    elif s[-6:] == 'eraser':
        s = s[:-6]
    else:
        beak
if s =='' :
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
def check(i):
    flag = False
    for each_word in word_list:
        if not flag and each_word == S[0+i:len(each_word)+i]: 
            if len(each_word)+i < len(S):
                flag = check(len(each_word)+i)
            else:
                flag = True
               
    return flag


S = input()
word_list = ['dream', 'dreamer', 'erase', 'eraser']
flag = False
flag = check(0)
if flag:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
def check(i):
    flag = False
    for each_word in word_list:
        if not flag and each_word == S[0+i:len(each_word)+i]: 
            if len(each_word)+i < len(S):
                flag = check(len(each_word)+i)
            else:
                flag = True
               
    return flag


S = input()
word_list = ['dream', 'dreamer', 'erase', 'eraser']
flag = False
for each_word in word_list:
    flag = check(0)
if flag:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int n;
string s,d="dreamer",e="eraser";
bool memo[123456],done[123456];

bool dp(int i){
	int j,p=0;
	if(done[i]){
		return memo[i];
	}
	done[i] = true;
	memo[i] = false;
	if(i==n){
		memo[i] = true;
		return memo[i];
	}
	if(s[i]!='d' && s[i]!='e'){
		return memo[i];
	}
	if(s[i]=='d'){
		for(j=i; j<min(n,j+7); ++j){
			if(s[j]!=d[j-i]){
				break;
			}
			++p;
		}
		if(p==7){
			memo[i] = dp(i+5)|dp(i+7);
		}else if(p==5){
			memo[i] = dp(i+5);
		}
	}else{
		for(j=i; j<min(n,j+6); ++j){
			if(s[j]!=e[j-i]){
				break;
			}
			++p;
		}
		if(p==5 || p==6){
			memo[i] = dp(i+p);
		}else{
			memo[i] = false;
		}
	}
	return memo[i];
}

int main(void){
	fill(done,done+123456,false);
	cin >> s;
	n = s.l_ength();
	cout << ((dp(0)?"YES":"NO")) << endl;
	return 0;
}

Submission status: Runtime Error

Solution code:
S = input()
ls = len(S)

def dfs(i):
    if i == ls:
        return True
    elif S[i: i+5] == "dream" or S[i: i+5] == "erase" or S[i: i+6] == "eraser" or S[i: i+7] == "dreamer":
        return dfs(i+5) or dfs(i+6) or dfs(i+7)

    return False

if dfs(0):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
a=list(S)
n=0
while n<len(a):
    oldn=n
    if a[n] == "e":
        if n+4<len(a) and a[n+1]=="r" and a[n+2]=="a" and a[n+3]=="s" and a[n+4]=="e":
            if n+5<len(a) and a[n+5]=="r":
                n=n+6
            else:
                n=n+5
    else:
        if a[n] == "d":
            if n+4<len(a) and a[n+1]=="r" and a[n+2]=="e" and a[n+3]=="a" and a[n+4]=="m":
                if n+6<len(a) and a[n+5]=="e" and a[n+6] == "r":
                    if n+7<len(a) and a[n+7]=="a":
                        n=n+5
                    else:
                        n=n+7
                else:
                    n=n+5
    if oldn == n:
        print("NO")
        break
else:
    print("OK")

Submission status: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

Solution code:
i = len(s)
ans = 'YES'
while True:
    if s[-5:] == a[0] or s[-5:] == a[2]:
        i -= 5
        if i == 0:
            ans = 'YES'
            break
        elif i<5:
            ans = 'NO'
            break
        s = s[:i]
    elif i>=6 and s[-6:] == a[3]:
        i -= 6
        if i == 0:
            ans = 'YES'
            break
        elif i<5:
            ans = 'NO'
            break
        s = s[:i]
    elif i>=7 and s[-7:] == a[1]:
        i -= 7
        if i == 0:
            ans = 'YES'
            break
        elif i<5:
            ans = 'NO'
            break
        s = s[:i]
    else:
        ans = 'NO'
        break
    #print(s)
print(ans)

Submission status: Runtime Error

Solution code:
def test():
    s = input()
    divide = ["dream", "dreamer", "erase", "eraser"]
    dp = [0 for i in range(10010)]

    dp[0] = 1
    for i in range(len(dp)):
        if dp[len(s)] == 1:
            print('YES')
            return 0
        if dp[i] == 0:
            continue
        for d in divide:
            if s[i:i+len(d)] == d:
                dp[i+len(d)] = 1
    print('NO')

test()

Submission status: Runtime Error

Solution code:
def test():
    s = input()
    divide = ["dream", "dreamer", "erase", "eraser"]
    dp = [0 for i in range(10010)]

    dp[0] = 1
    for i in range(len(dp)):
        if dp[len(s)] == 1:
            print('YES')
            return 0
        if dp[i] == 0:
            continue
        for d in divide:
            if s[i:i+len(d)] == d:
                dp[i+len(d)] = 1
                print(i+len(d))
    print('NO')

test()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2000)

def text_match_words(text, words):
	match_words = []
	for word in words:
		if word == text[:len(word)]:
			match_words.append(word)
	return match_words

def is_match_for(text, words):
	if "" == text: 
		return True
	else:
		match_words = text_match_words(text, words)
		if [] == match_words:
			return False
		else:
			return any([is_match_for(text[len(match_word):], words) for match_word in match_words])

words = ("dream", "dreamer", "erase", "eraser")

s = input()

if is_match_for(s, words):
	print("YES")
else:
	print("NO")

Submission status: Runtime Error

Solution code:

sys.setrecursionlimit(2000)

def text_match_words(text, words):
	match_words = []
	for word in words:
		if word == text[:len(word)]:
			match_words.append(word)
	return match_words

def is_match_for(text, words):
	if "" == text: 
		return True
	else:
		match_words = text_match_words(text, words)
		if [] == match_words:
			return False
		else:
			return any([is_match_for(text[len(match_word):], words) for match_word in match_words])

words = ("dream", "dreamer", "erase", "eraser")

s = input()

if is_match_for(s, words):
	print("YES")
else:
	print("NO")

Submission status: Runtime Error

Solution code:

def text_match_words(text, words):
	match_words = []
	for word in words:
		if word == text[:len(word)]:
			match_words.append(word)
	return match_words

def is_match_for(text, words):
	if "" == text: 
		return True
	else:
		match_words = text_match_words(text, words)
		if [] == match_words:
			return False
		else:
			return any([is_match_for(text[len(match_word):], words) for match_word in match_words])

if is_match_for(input(), ("dream", "dreamer", "erase", "eraser")):
	print("YES")
else:
	print("NO")

Submission status: Runtime Error

Solution code:
def text_match_words(text, words):
	match_words = []
	for word in words:
		if word == text[:len(word)]:
			match_words.append(word)
	return match_words

def is_match_for(text, words):
	if "" == text: 
		return True
	else:
		match_words = text_match_words(text, words)
		if [] == match_words:
			return False
		else:
			return any([is_match_for(text[len(match_word):], words) for match_word in match_words])

words = ("dream", "dreamer", "erase", "eraser")

s = input()

if is_match_for(s, words):
	print("YES")
else:
	print("NO")

Submission status: Runtime Error

Solution code:
def text_match_words(text, words):
	match_words = []
	for word in words:
		if word == text[:len(word)]:
			match_words.append(word)
	return match_words

def is_match_for(text, words):
	if "" == text: 
		return True
	else:
		match_words = text_match_words(text, words)
		if [] == match_words:
			return False
		else:
			return any([is_match_for(text[len(match_word):], words) for match_word in match_words])

if __name__ == "__main__":
	words = ("dream", "dreamer", "erase", "eraser")

	s = input()

	if is_match_for(s, words):
		print("YES")
	else:
		print("NO")

Submission status: Runtime Error

Solution code:
def text_match_words(text, words):
	match_words = []
	for word in words:
		if word == text[:len(word)]:
			match_words.append(word)
	return match_words

def is_match_for(text, words):
	if "" == text: 
		return True
	else:
		match_words = text_match_words(text, words)
		if [] == match_words:
			return False
		else:
			return any([is_match_for(text[len(match_word):], words) for match_word in match_words])
		
s = input()

words = ("dream", "dreamer", "erase", "eraser")

if is_match_for(s, words):
	print("YES")
else:
	print("NO")

Submission status: Runtime Error

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: Runtime Error

Solution code:
import sys
S = input()
S = S.split("er")



for s in S:
    if s not in {'asedream', 'dream', 'as'}:
        if s != '':
            print("NO")
            sys.exit()
    else:
        flag = False
    if s == "":
        if flag:
            print("NO")
            sys.exit()
        flag = True

print("YES")

Submission status: Runtime Error

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

Solution code:
s = input().rstrip()
d = ['dream', 'dreamer']
e = ['erase', 'eraser']
ch = d + e

def search_(s, ch):
    if len(s) == 0:
        return True
    if len(s) < len(ch):
        return False
    else:
        if s[:len(ch)] == ch:
            return search(s[len(ch):])
    return False

def search(s):
    if len(s) == 0:
        return True
    if s[0] == 'd' or s[0] == 'e':
        for ci in ch:
            if search_(s, ci):
                return True
    return False

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

Submission status: Runtime Error

Solution code:
s = input().rstrip()
d = ['dream', 'dreamer']
e = ['erase', 'eraser']
ch = d + e

def search_(s, ch):
    if len(s) == 0:
        return True
    if len(s) < len(ch):
        return False
    else:
        if s[:len(ch)] == ch:
            return search(s[len(ch):])

def search(s):
    if len(s) == 0:
        return True
    if s[0] == 'd' or s[0] == 'e':
        for ci in ch:
            if search_(s, ci):
                return True
    return False

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

Submission status: Runtime Error

Solution code:
def tree(str):
    if(str == ""):
        return True
    if(str.startswith("d")):
        if(str.startswith("dream")):
            tree(str.replace("dream","",1))
        if (str.startswith("dreamer")):
            tree(str.replace("dreamer","",1))
    elif(str.startswith("e")):
        if (str.startswith("erase")):
            tree(str.replace("erase","",1))
        if (str.startswith("eraser")):
            tree(str.replace("eraser","",1))
st = input()
if(tree(st)) : print("YES")
else: print("NO")

Submission status: Runtime Error

Solution code:
st = input()

def tree(str):
    if(str == ""):
        return True
    if(str.startswith("d")):
        if(str.startswith("dream")):
            tree(str.replace("dream","",1))
        if (str.startswith("dreamer")):
            tree(str.replace("dreamer","",1))
    elif(str.startswith("e")):
        if (str.startswith("erase")):
            tree(str.replace("erase","",1))
        if (str.startswith("eraser")):
            tree(str.replace("eraser","",1))

if(tree(st)) : print("YES")
else: print("NO")

Submission status: Runtime Error

Solution code:
import sys

st = input()

def tree(str):
    if(str == ""):
        print("YES")
        sys.exit()
    if(str.startswith("d")):
        if(str.startswith("dream")):
            tree(str.replace("dream","",1))
        if (str.startswith("dreamer")):
            tree(str.replace("dreamer","",1))
    elif(str.startswith("e")):
        if (str.startswith("erase")):
            tree(str.replace("erase","",1))
        if (str.startswith("eraser")):
            tree(str.replace("eraser","",1))

tree(st)
print("NO")

Submission status: Runtime Error

Solution code:
s = input()
n_s = len(s)
S = ''
for i in range(n_s):
    S += s[-i-1]
words = ["maerd", "remaerd", "esare", "resare"]
cnt = 0
result = 'Yes'
while True:
    if S[cnt:cnt+5] == 'maerd':
        cnt += 5
    elif S[cnt:cnt+5] == 'esare':
        cnt += 5
    elif S[cnt:cnt+6] == 'resare':
        cnt += 6
    elif S[cnt:cnt+7] == 'remaerd':
        cnt += 7
    else:
        result = 'No'
        break
    if cnt == n_S:
        break
print(result)

Submission status: Runtime Error

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 + "_", "_")
        print(S)
    if S_ == S:
        break

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

Submission status: Runtime Error

Solution code:
s = input()
cs = s
judge = True
while 0<len(cs): 
    if cs[:5]=='dream':
        cs = cs[5:]
        if cs[:2]=='er' and not cs[:5]=='erase':
            cs = cs[2:]
    elif cs[:5]=='erase':
        cs = cs[5:]
        if cs[0]=='r':
            cs = cs[1:]
    else:
        judge = False
        break
print('YES' if judge else 'NO')

Submission status: Runtime Error

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: Runtime Error

Solution code:
s=input()
w=["dream","dreamer","erase","eraser",""]
while True:
    

    if s[0:5]==w[0]:
        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)<=6:
        if s in w:
            print("YES")
            exit()
        else:
            print("NO")
            exit()

    #print(s)

Submission status: Runtime Error

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 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: Runtime Error

Solution code:
s=input()
w=["dream","dreamer","erase","eraser"]
while True:
    if s[0:5]==w[0]:
        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: Runtime Error

Solution code:
def main():
	s = input()
	flag = greedy(s,len(s))
	if flag:
		print("YES")
	else:
		print("NO")

def greedy(s2,end):
	if end > 7:
		if s2[end-7:end] == "dreamer":
			return greedy(s2,end-7)
		elif s2[end-6:end] == "eraser":
			return greedy(s2,end-6)
		elif (s2[end-5:end] == "dream") or (s2[end-5:end] =="erase"):
			return greedy(s2,end-5)
		else:
			return False
	else:
		if (s2[:end] == "dreamer") or (s2[:end] == "dream") or \
		(s2[:end] == "eraser") or (s2[:end] == "erase"):
			return True
		else:
			return False

if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
def main():
	s = input()
	flag = greedy(s,len(s))
	if flag:
		print("YES")
	else:
		print("NO")

def greedy(s2,end):
	if end > 7:
		if s2[end-7:end] == "dreamer":
			return greedy(s2,end-7)
		elif s2[end-6:end] == "eraser":
			return greedy(s2,end-6)
		elif s2[end-5:end] == "dream" or "erase":
			return greedy(s2,end-5)
		else:
			return False
	else:
		if s2[:end] == "dreamer" or "dream" or "eraser" or "erase":
			return True
		else:
			return False

if __name__ == "__main__":
	main()

Submission status: Runtime Error

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

def is_contains_word(s, words):
    for word in words:
        if s == '':
            return True
        if s.endswith(word):
            return is_contains_word(s[:-len(word)], words)
    return False

def main():
    s = input()
    words = ('dream', 'dreamer', 'erase', 'eraser')

    print('YES') if is_contains_word(s, words) else print('NO')

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import deque

S = input()

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

Q = deque([''])

found = False
while Q:
    w = Q.popleft()
    if S == w:
        found = True
        break
    for nw in words:
        if len(w + nw) <= len(S):
            Q.appendleft(w + nw)
    print(Q)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

    dfs(S)


def dfs(S):
    l = len(S)
    if _dfs(S, l, 0):
        print("YES")
    else:
        print("NO")


def _dfs(S, l, idx, pattern=0):
    # print(l, idx, pattern)
    if idx == l:
        return True

    if S[idx:idx + 7] == "dreamer":
        ok = _dfs(S, l, idx + 7, 1)
        if ok:
            return True
    if S[idx:idx + 6] == "eraser":
        ok = _dfs(S, l, idx + 6, 2)
        if ok:
            return True
    if S[idx:idx + 5] == "dream" or \
            S[idx:idx + 5] == "erase":
        ok = _dfs(S, l, idx + 5, 3)
        if ok:
            return True

    return False


def WA(S):
    l = len(S)
    idx = 0
    ok = True
    while idx < l:
        if S[idx:idx + 7] == "dreamer":
            idx += 7
        elif S[idx:idx + 6] == "eraser":
            idx += 6
        elif S[idx:idx + 5] == "dream" or \
                S[idx:idx + 5] == "erase":
            # 評価順番注意
            idx += 5
        else:
            ok = False
            break

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

S = input()

while S:
    prefix = S[0:5]
    if prefix == 'dream':
        if S[5:7] == 'er':
            if len(S) >= 8 and S[7] == 'a':
                S = S[5:]
            else:
                S = S[7:]
        else:
            S = S[5:]
    elif prefix == 'erase':
        if len(S) >= 6 and S[5] == 'r':
            S = S[6:]
        else:
            S = S[5:]
    else:
        print('NO')
        sys.exit(0)
    print(S)
print('YES')