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:

def str_read(s):

    if len(s) == 0:
        return True
    else:
        flag = False
        if len(s) > 4 and s[0:5] in ['dream', 'erase']:
            flag = flag or str_read(s[5:])
        if len(s) > 5 and s[0:6] in ['eraser']:
            flag = flag or str_read(s[6:])
        if len(s) > 6 and s[0:7] in ['dreamer']:
            flag = flag or str_read(s[7:])
        return flag


s = input()

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

Submission status: Runtime Error

Solution code:

def str_read(s):

    if len(s) == 0:
        return True
    else:
        flag = False
        if len(s) > 4 and s[0:5] in ['dream', 'erase']:
            flag = flag or str_read(s[5:])
        if len(s) > 5 and s[0:6] in['eraser']:
            flag = flag or str_read(s[6:])
        if len(s) > 6 and s[0:7] in['dreamer']:
            flag = flag or str_read(s[7:])
        return flag


s = input()

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

Submission status: Runtime Error

Solution code:

def str_read(s):

    if len(s) == 0:
        return True
    else:
        flag = False
        if len(s) > 4 and s[0:5] in ['dream', 'erase']:
            flag = flag or str_read(s[5:])
        if len(s) > 5 and s[0:6] in['eraser']:
            flag = flag or str_read(s[6:])
        if len(s) > 6 and s[0:7] in['dreamer']:
            flag = flag or str_read(s[7:])
        return flag


s = input()

if str_read(s):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
S=list(input())
i=0
while i!=len(S):
    if i+6<=len(S) and S[i:i + 6] == ['e', 'r', 'a', 's', 'e', 'r']:
        i += 6
    elif i+5<=len(S) and S[i:i+5]==['e','r','a','s','e']:
        i+=5
    elif i+7<=len(S) and S[i:i+7]==['d','r','e','a','m','e','r'] and (len(S[i+7:])==7 or S[i+7]!='a'):
        i+=7
    elif i+5<=len(S) and S[i:i+5]==['d','r','e','a','m']:
        i+=5
    else:
        print('NO')
        exit()
print('YES')

Submission status: Runtime Error

Solution code:
S=list(input())
i=0
while i!=len(S):
    if S[i:i + 6] == ['e', 'r', 'a', 's', 'e', 'r']:
        i += 6
    elif S[i:i+5]==['e','r','a','s','e']:
        i+=5
    elif S[i:i+7]==['d','r','e','a','m','e','r'] and (len(S[i+7:])==7 or S[i+7]!='a'):
        i+=7
    elif S[i:i+5]==['d','r','e','a','m']:
        i+=5
    else:
        print('NO')
        exit()
print('YES')

Submission status: Runtime Error

Solution code:
s = input()[::-1]
words = [w[::-1] for w in ['dream', 'dreamer', 'erase', 'eraser']]

can = 'YES'
while s:
    print(s)
    match_any = False
    for w in words:
        if s.startswith(w):
            s = s.replace(w, '', 1)
            match_any = True
            break
    if not match_any:
        can = 'NO'
        break
print(can)

Submission status: Runtime Error

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

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

s = ''

def dfs(t):
    if t == s:
        return True
    for ss in a:
        tmpt = t + ss
        if len(tmpt)<= len(s) and tmpt == s[:len(tmpt)]:
            if(dfs(tmpt)):
                return True
    
    return False



def solve():
    global s
    s = input()
    init= ''

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




solve()

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
input = sys.stdin.readline

S = list(input().strip())
P = [list(v) for v in ["dream", "dreamer", "erase", "eraser"]]

n = 0
i = 0
his = deque()
while True:
    v = P[i]
    
    p = S[n:n+len(v)]
    if p == v:
        xx = S[n+len(v):]
        if xx == []:
            print("YES")
            exit()
        else:
            his.append([n, i + 1])
            n += len(v)
            i = 0
    else:
        i += 1
        if i == 4:
            if len(his) == 0:
                break
            else:
                n, i = his.pop()
                
print("NO")

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

S = list(input().strip())
P = [list(v) for v in ["dream", "dreamer", "erase", "eraser"]]

def dfs(n):
    if len(S[n:]) == 0:
        return True
    
    for v in P:
        if S[n:n+len(v)] == v:
            if dfs(n + len(v)):
                return True
    
    return False

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

Submission status: Runtime Error

Solution code:
def dfs(n):
        divide=["dream","dreamer","erase","eraser"]
        if n==len(s):
                return True
        for i in divide:
                if n+len(i)<=len(s):
                        if s[n:n+len(i)]==i:
                                if dfs(n+len(i)):
                                        return True

        return False
s=input()
print("YES") if dfs(0) else print("NO")

Submission status: Runtime Error

Solution code:
def dfs(n):
        divide=["dream","erase","eraser","dreamer"]
        if n==len(s):
                return True
        for i in divide:
                if n+len(i)<=len(s):
                        if s[n:n+len(i)]==i:
                                if dfs(n+len(i)):
                                        return True

        return False
s=input()
print("YES") if dfs(0) else print("NO")

Submission status: Runtime Error

Solution code:
def dfs(n):
        divide=["dream","erase","eraser","dreamer"]
        if n==len(s):
                return True
        for i in divide:
                if n+len(i)<=len(s):
                        if "".join(s[n:n+len(i)])==i:
                                if dfs(n+len(i)):
                                        return True

        return False
s=list(input())
print("YES") if dfs(0) else print("NO")

Submission status: Runtime Error

Solution code:
s=list(input())
divide=["dream","erase","eraser","dreamer"]
def dfs(n):
        if n==len(s):
                return True
        for i in divide:
                if n+len(i)<=len(s):
                        if "".join(s[n:n+len(i)])==i:
                                if dfs(n+len(i)):
                                        return True

        return False
print("YES") if dfs(0) else print("NO")

Submission status: Runtime Error

Solution code:
s=list(input())
divide=["dream","erase","eraser","dreamer"]
def dfs(n):
        if n==len(s):return True
        for i in divide:
                if n+len(i)<=len(s):
                        if "".join(s[n:n+len(i)]):
                                if dfs(n+len(i)):return True
        return False
print("YES") if dfs(0) else print("NO")

Submission status: Runtime Error

Solution code:
s=list(input())
divide=["dream","erase","eraser","dreamer"]
def dfs(n):
        if n==len(s):
                return True
        for i in divide:
                if n+len(i)<=len(s):
                        if "".join(s[n:n+len(i)]):
                                if dfs(n+len(i)):
                                        return True
        return False
print("YES") if dfs(0) else print("NO")

Submission status: Runtime Error

Solution code:
import re

def hoge(str):
	if str == "":
		return True
	for word in ["dreamer", "eraser", "dream", "erase"]:
		keyword = word[::-1]
		pattern = re.compile(r"^%s" % keyword)
		if(pattern.match(str)):
			return hoge(re.sub(pattern, "", str))
	return False

S= input()

if(hoge(S[::-1])):
	print("YES")
else:
	print("NO")

Submission status: Runtime Error

Solution code:
import re
S=input()

def hoge(str):
	if str == "":
		return True
	for word in ["dreamer", "eraser", "dream", "erase"]:
		keyword = word[::-1]
		pattern = re.compile(r"^%s" % keyword)
		if(str.startswith(keyword)):
			return hoge(re.sub(pattern, "", str))
	return False

if(hoge(S[::-1])):
	print("YES")
else:
	print("NO")

Submission status: Runtime Error

Solution code:
S=input()

def hoge(str):
	if str == "":
		return True
	for word in ["dreamer", "eraser", "dream", "erase"]
		keyword = word.sort(reverse=True)
		pattern = re.compile(r"^%s" % keyword)
		if(str.startswith(keyword)):
			return hoge(str.relpace(pattern, ""))
	return False

if hoge(S.sort(reverse=True)):
	print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
S=input()

def hoge(str)
	if str == "":
		return True
	for word in ["dreamer", "eraser", "dream", "erase"]
		keyword = word.sort(reverse=True)
		pattern = re.compile(r"^%s" % keyword)
		if(str.startswith(keyword)):
			return hoge(str.relpace(pattern, ""))
	return False

if hoge(S.sort(reverse=True)):
	print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s=list(input())
divide=["dream","erase","eraser","dreamer"]
def dfs(n):
        if n==len(s):
                return True
        for i in divide:
                if n+len(i)<=len(s):
                        if "".join(s[n:n+len(i)])==i:
                                if dfs(n+len(i)):
                                        return True
        return False
print("YES") if dfs(0) else print("NO")

Submission status: Runtime Error

Solution code:
import re
s=input()

def hoge(str):
	if(str == ""):
		return "YES"
	if(str.startswith("remaerd")):
		return hoge(re.sub('^remaerd', '', str))
	if(str.startswith("resare")):
		return hoge(re.sub('^resare', '', str))
	if(str.startswith("maerd")):
		return hoge(re.sub('^maerd', '', str))
	if(str.startswith("esare")):
		return hoge(re.sub('^esare', '', str))
	return "NO"

if(s == ""):
  print("NO")
else:
	print(hoge(s[::-1]))

Submission status: Runtime Error

Solution code:
import re
s=input()

def hoge(str):
	if(str == ""):
		return "YES"
	if(str.startswith("maerd")):
		return hoge(re.sub('^maerd', '', str))
	if(str.startswith("remaerd")):
		return hoge(re.sub('^remaerd', '', str))
	if(str.startswith("esare")):
		return hoge(re.sub('^esare', '', str))
	if(str.startswith("resare")):
		return hoge(re.sub('^resare', '', str))
	return "NO"

if(s == ""):
  print("NO")
else:
	print(hoge(s[::-1]))

Submission status: Runtime Error

Solution code:
import re
s=input()

def hoge(str):
	if(str == ""):
		return "YES"
	if(str.startswith("maerd")):
		return hoge(re.sub('^maerd', '', str))
	if(str.startswith("remaerd")):
		return hoge(re.sub('^remaerd', '', str))
	if(str.startswith("esare")):
		return hoge(re.sub('^esare', '', str))
	if(str.startswith("resare")):
		return hoge(re.sub('^resare', '', str))
	return "NO"

print(hoge(s[::-1]))

Submission status: Runtime Error

Solution code:
import re
s=input()

def hoge(str):
	if(str == ""):
		return "YES"
	if(str.startWith("dream".sort(reverse=True))):
		return hoge(re.sub('^maerd', '', str))
	if(str.startWith("dreamer".sort(reverse=True))):
		return hoge(re.sub('^remerd' '', str))
	if(str.startWith("erase".sort(reverse=True))):
		return hoge(re.sub('^esare', '', str))
	if(str.startWith("eraser".sort(reverse=True))):
		return hoge(re.sub('^resare', '', str))
	return "NO"

print(s.sort(reverse=True))

Submission status: Runtime Error

Solution code:
import re
s=input()

def hoge(str):
    if(str == ""):
    	return "YES"
	if(str.startWith("dream".sort(reverse=True))):
		return hoge(re.sub('^maerd', '', str))
	if(str.startWith("dreamer".sort(reverse=True))):
		return hoge(re.sub('^remerd' '', str))
	if(str.startWith("erase".sort(reverse=True))):
		return hoge(re.sub('^esare', '', str))
	if(str.startWith("eraser".sort(reverse=True))):
		return hoge(re.sub('^resare', '', str))
	return "NO"

print(s.sort(reverse=True))

Submission status: Runtime Error

Solution code:
import re
s=input()

def hoge(str)
    if(str == ""):
    	return "YES"
	if(str.startWith("dream".sort(reverse=True))):
		return hoge(re.sub('^maerd', '', str))
	if(str.startWith("dreamer".sort(reverse=True))):
		return hoge(re.sub('^remerd' '', str))
	if(str.startWith("erase".sort(reverse=True))):
		return hoge(re.sub('^esare', '', str))
	if(str.startWith("eraser".sort(reverse=True))):
		return hoge(re.sub('^resare', '', str))
	return "NO"

print(s.sort(reverse=True))

Submission status: Runtime Error

Solution code:
import re
s=input()

def hoge(str)
    res = []
	if(str.startWith("dream")):
		res.append(re.sub('^dream', '', str))
	if(str.startWith("dreamer")):
		res.append(re.sub('^dreamer', '', str))
	if(str.startWith("erase")):
		res.append(re.sub('^erase', '', str))
	if(str.startWith("eraser")):
		res.append(re.sub('^eraser', '', str))
	return res

def fuga(res):
	if(len(res) == 0):
  		return "NO"
	if("" in res):
  		return "YES"
	for str in res:
        return fuga(hoge(str))
print(fuga([s])

Submission status: Runtime Error

Solution code:
import re
s=input()

def hoge(str)
	if(str == ""):
  		return "YES"
	if(str.startWith("dream")):
		return hoge(re.sub('^dream', '', str))
	if(str.startWith("dreamer")):
		return hoge(re.sub('^dreamer', '', str))
	if(str.startWith("erase")):
		return hoge(re.sub('^erase', '', str))
	if(str.startWith("eraser")):
		return hoge(re.sub('^eraser', '', str))
	return "NO"

print(hoge(s))

Submission status: Runtime Error

Solution code:
s=list(input())
divide=["dream","erase","eraser","dreamer"]
def dfs(n):
        if n==len(s):
                return True
        for i in divide:
                tmp="".join(s[n:n+len(i)])
                if n+len(i)<=len(s) and tmp==i:
                        if dfs(n+len(i)):
                                return True
        return False
print("YES") if dfs(0) else print("NO")

Submission status: Runtime Error

Solution code:
s=list(input())
divide=["dream","erase","eraser","dreamer"]
def dfs(n):
        if n==len(s):#最後まで行ったらtrue
                return True
        for i in divide:
                tmp="".join(s[n:n+len(i)])
                if n+len(i)<=len(s) and tmp==i:
                        if dfs(n+len(i)):
                                return True
        return False
if dfs(0):
        print("YES")
else:
        print("NO")
#print("YES") if dfs(0) else print("NO")

Submission status: Runtime Error

Solution code:
s=input()

def hoge(str)
	if(str == ""):
  		return "YES"
	if(str.startWith("dream")):
		return hoge(str.rstrip("dream"))
	if(str.startWith("dreamer")):
		return hoge(str.rstrip("dreamer"))
	if(str.startWith("erase")):
		return hoge(str.rstrip("erase"))
	if(str.startWith("eraser")):
		return hoge(str.rstrip("eraser"))
	return "NO"

print(hoge(s))

Submission status: Runtime Error

Solution code:
s=list(input())
divide=["dream","erase","eraser","dreamer"]
#全探索する
def dfs(n):
        if n==len(s):#最後まで行ったらtrue
                return True
        for i in divide:
                tmp="".join(s[n:n+len(i)])
                if n+len(i)<=len(s) and tmp==i:
                        if dfs(n+len(i)):
                                return True
        return False
print("YES") if dfs(0) else print("NO")

Submission status: Runtime Error

Solution code:
s=input()
divide=["dream","erase","eraser","dreamer"]
#全探索する
def dfs(n):
        if n==len(s):#最後まで行ったらtrue
                return True
        for i in divide:
                if n+len(i)<=len(s) and "".join(s[n:n+len(i)])==i:
                        if dfs(n+len(i)):
                                return True
        return False
print("YES") if dfs(0) else print("NO")

Submission status: Runtime Error

Solution code:
s=list(input())
divide=["dream","erase","eraser","dreamer"]
#全探索する
def dfs(n):
        if n==len(s):#最後まで行ったらtrue
                return True
        for i in divide:
                if n+len(i)<=len(s) and "".join(s[n:n+len(i)])==i:
                        if dfs(n+len(i)):
                                return True
        return False
print("YES") if dfs(0) else print("NO")

Submission status: Runtime Error

Solution code:
s=list(input())
divide=["dream","erase","eraser","dreamer"]
#全探索する
def dfs(n):
        if n==len(s):#最後まで行ったらtrue
                return True
        for i in divide:
                if n+len(i)<=len(s) and "".join(s[n:n+len(i)])==i:
                        if dfs(n+len(i)):
                                print(n)
                                return True
        return False
print("YES") if dfs(0) else print("NO")

Submission status: Runtime Error

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

for i in range(len(moji)):
  moji[i] = moji[i][::-1]

s = input()[::-1]

for i in range(0, 3):
  tmp = s.replace(moji[i], "")
  if tmp != s:
    for j in range(1, 3):
      ans = tmp.replace(moji[j], "")
      if ans != tmp:
        flg = "YES"

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

Submission status: Runtime Error

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

def isDaydream(s):
    if s == "":
        return True
    for string in strings:
        if s.endswith(string):
            if(isDaydream(s[:len(string)*-1])):
                return True
    return False
if(isDaydream(input())):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
S=input()
n=0
#print(S)
while S[:]!=S[:n]:
    if S[n:n+5]=="dream" or S[n:n+8]=="dreamera":
        n+=5 #dream
    elif S[n:n+7]=="dreamer" and S[n+7]!="a":
        n+=7 #dreamer
    elif S[n:n+5]=="erase" and S[n+6]!="eraser":
        n+=5 #erase
    elif S[n:n+6]=="eraser" and S[n+6]!="a":
        n+=6 #eraser
    #elif S[:]==S[:n-1]:
        #print("YES")
        #exit()
    else:
        print("NO")
        exit()
else:
    print("YES")

Submission status: Runtime Error

Solution code:
S=input()
n=0
While S[:]!=S[:n-1]:
    if S[n:n+5]==dream and S[n:n+7]!=dreamer:
        n+=5
    elif S[n:n+7]==dreamer:
        n+=7
    elif S[n:n+5]==erase and S[n+6]!=eraser:
        n+=5
    elif S[n:n+6]==eraser:
        n+=6
    #elif S[:]==S[:n-1]:
        #print("YES")
        #exit()
    else:
        print("NO")
        exit()
else:
    print("YES")

Submission status: Runtime Error

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

def isDaydream(startindex):
    if S[startindex:] == "":
        return True
    for string in strings:
        if S[startindex:].startswith(string):
            if(isDaydream(len(string)+startindex)):
                return True
    return False
S = input()
if(isDaydream(0)):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

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

def isDaydream(startindex):
    global S
    if S[startindex:] == "":
        return True
    for string in strings:
        if S[startindex:].startswith(string):
            if(isDaydream(len(string)+startindex)):
                return True
    return False
S = input()
if(isDaydream(0)):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

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

def isDaydream(s):
    if s == "":
        return True
    for string in strings:
        if s.startswith(string):
            if(isDaydream(s[len(string):])):
                return True
    return False
if(isDaydream(input())):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

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

def isDaydream(s):
    if s == "":
        return True
    for string in strings:
        if s.startswith(string):
            if(isDaydream(s[len(string):])):
                return True
    return False

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

Submission status: Runtime Error

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

while len(s) > 0:
    flag = 0
    for w in words:
        if s[-1 * len(w):] == w:
            s = s.replace(w, "").rstrip()
            flag = 1
            break
    if flag == 0:
        print("NO")
        exit()

print("YES"

Submission status: Runtime Error

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

def makeS(T, flg):
    if len(T) > len(S):
        return 0
    
    for p in P:
        T += p
        if T == S:
            return 1
        else:
            flg += makeS(T, flg)
            T = T[:len(T)-len(p)]
    return flg

if makeS('', 0):
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
words = {"dream": "A", "dreamer": "A", "erase": "A", "eraser": "A"}
 
ans = []
 
inputs = list(input())
 
inputs = inputs.replace("eraser", "").replace("dreamer", "")
inputs = .replace("dream", "").replace("erase", "")

if len(list(inputs)) > 0:
  print("No")
else:
  print("Yes")

Submission status: Runtime Error

Solution code:
words = {"dream": "A", "dreamer": "A", "erase": "A", "eraser": "A"}

ans = []

inputs = list(input())

tmp1 = []

for c in reversed(inputs):
  
  tmp1.append(c)
  
  tmp2 = "".join([x for x in reversed(tmp1)])
  
  if tmp2 in words:
    ans.append("".join(tmp2))
    tmp1.clear()
    tmp2.clear()

ans = [x for x in reversed(ans)]

if "".join(ans) == "".join(inputs):
  print("YES")
else:
  print("No")

Submission status: Runtime Error

Solution code:
def check(string):
    if len(string) == 0:
        return True
    else:
        if(string.startswith("dreamer")):
            tmp = string[7:]
            if check(tmp):
                return True
        if(string.startswith("dream")):
            tmp = string[5:]
            if check(tmp):
                return True
        if(string.startswith("eraser")):
            tmp = string[6:]
            if check(tmp):
                return True
        if(string.startswith("erase")):
            tmp = string[5:]
            if check(tmp):
                return True

        return False

S = raw_input()

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

Submission status: Runtime Error

Solution code:
s=list(input())
booler=True
while s!=[] and booler==True:
  if s[-5]=="d" and s[-4]=="r" and s[-3]=="e" and s[-2]=="a" and s[-1]=="m":
    for i in range(5):
      del s[-1]
  elif s[-6]=="e" and s[-5]=="r" and s[-4]=="a" and s[-3]=="s" and s[-2]=="e" and s[-1]=="r":
    for i in range(6):
      del s[-1]
  elif s[-5]=="e" and s[-4]=="r" and s[-3]=="a" and s[-2]=="s" and s[-1]=="e":
    for i in range(5):
      del s[-1]
  elif s[-7]=="d" and s[-6]=="r" and s[-5]=="e" and s[-4]=="a" and s[-3]=="m" and s[-2]=="e" and s[-1]=="r":
    for i in range(7):
      del s[-1]
  else:
    booler=False
if booler:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
s=list(input())
booler=True
while s!=[]:
  if s[-5]=="d" and s[-4]=="r" and s[-3]=="e" and s[-2]=="a" and s[-1]=="m":
    for i in range(5):
      del s[-1]
  elif s[-6]=="e" and s[-5]=="r" and s[-4]=="a" and s[-3]=="s" and s[-2]=="e" and s[-1]=="r":
    for i in range(6):
      del s[-1]
  elif s[-5]=="e" and s[-4]=="r" and s[-3]=="a" and s[-2]=="s" and s[-1]=="e":
    for i in range(5):
      del s[-1]
  elif s[-7]=="d" and s[-6]=="r" and s[-5]=="e" and s[-4]=="a" and s[-3]=="m" and s[-2]=="e" and s[-1]=="r":
    for i in range(7):
      del s[-1]
  else:
    booler=False
if b:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
#coding:utf-8
import re

if __name__ == "__main__":
    patterns = ["dream", "dreamer", "erase" ,"eraser"]
    S = input()

    # while True:
    #     flag = False
    #     if S[-5:] == "dream":
    #         S = S[:-5]
    #         flag = True
    #     if S[-7:] == "dreamer":
    #         S = S[:-7]
    #         flag = True
    #     if S[-5:] == "erase":
    #         S = S[:-5]
    #         flag = True
    #     if S[-6:] == "eraser":
    #         S = S[:-6]
    #         flag = True
    #
    #     if flag == False:
    #         print("NO")
    #         break
    #
    #     if S == "":
    #         print("YES")
    #         break

    while True:
        flag = False
        if re.search("dream$",S):
            S = re.sub("dream$","",S)
            flag = True
        if re.search("dreamer$",S):
            S = re.sub("dreamer$","",S)
            flag = True
        if re.search("erase$",S):
            S = re.sub("erase$","",S)
            flag = True
        if re.search("eraser$",S):
            S = r

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
import re
str_array = ['dream', 'dreamer', 'erase', 'eraser']
rev_str_array = [i[::-1] for i in str_array]
S = sys.stdin.readline().strip()
revS = S[::-1]


def strip_string(revS, rev_str_array):
    for s in rev_str_array:
        if revS.startswith(s):
            revS = re.sub("^%s" % s, "", revS)
            revS = strip_string(revS, rev_str_array)
        else:
            continue
    else:
        return revS


print("YES" if strip_string(revS, rev_str_array) == "" else "NO")

Submission status: Runtime Error

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

while bool:
  if len(S) == 0:
    break
 
  bool = False
  for n in N:
    
    if S.endswith(n):
      L = S.rsplit(n,1)
      S = L[0]
      print(S)
      bool = True
      break
  

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

Submission status: Runtime Error

Solution code:
#049 C

S = input()
A = 'dream'
B = 'dreamer'
C = 'erase'
D = 'eraser'

S=S[::-1]
A=A[::-1]
B=B[::-1]
C=C[::-1]
D=D[::-1]

tmp =""
for i in S:
    tmp +=i
    print(tmp)
    for j in [A,B,C,D]:
        if tmp == j:
            S=S.replace(tmp,"",1)
            print(S)
            tmp=""
if len(S)==0:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
S = str(input())S = str(input())
while "eraser" in S:     
    S=S.replace("eraser","")
while "erase" in S: 
    S=S.replace("erase","")
while "dreamer" in S: 
    S=S.replace("dreamer","")
while "dream" in S: 
    S=S.replace("dream","")
if len(S) == 0:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
a = ["dream", "dreamer", "erase", "eraser"]
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

t = input().strip()


def dfs(somes):
    if somes == t:
        return True
    
    if len(somes) >= len(t):
        return False

    for i in a:
        if len(somes) + len(i) <= len(t)  and i == t[len(somes):len(somes) + len(i)]:
            if dfs(somes+i):
                return True
    
    return False

def solve():
    s = ""
    if dfs(s):
        print("YES")
    else:
        print("NO")

solve()

Submission status: Runtime Error

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
a = ["dream", "dreamer", "erase", "eraser"]
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

t = input().strip()


def dfs(somes):
    if somes == t:
        return True
    
    if len(somes) >= len(t):
        return False

    for i in a:
        if i == t[len(somes):len(somes) + len(i)]:
            if dfs(somes+i):
                return True
    
    return False

def solve():
    s = ""
    if dfs(s):
        print("YES")
    else:
        print("NO")

solve()

Submission status: Runtime Error

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
a = ["dream", "dreamer", "erase", "eraser"]
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

t = input().strip()


def dfs(somes):
    if somes == t:
        return True
    
    if len(somes)>= len(t):
        return False
    
    temp = somes

    for i in a:
        if dfs(somes+i):
            return True
    
    return False

def solve():
    s = ""
    if dfs(s):
        print("YES")
    else:
        print("NO")

solve()

Submission status: Runtime Error

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
a = ["dream", "dreamer", "erase", "eraser"]
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

t = input()



def dfs(somes):
    if somes == t:
        return True
    
    if len(somes)>= len(t):
        return False
    
    temp = somes

    for i in a:
        if dfs(somes+i):
            return True
    
    return False

def solve():
    s = ""
    if dfs(s):
        print("YES")
    else:
        print("NO")


solve()

Submission status: Runtime Error

Solution code:
#C問題
S=str(input())
Slist=list(S)
Slen=len(Slist)
Srev=Slist[::-1]
kari=""
for i in range(Slen):
    if len(kari) == 5:
        if kari == "maerd":
            kari=Srev[i]
        elif kari == "esare":
            kari=Slev[i]
        else:
            kari+=Srev[i]
    elif len(kari) == 6:
        if kari == "resare":
            kari=Srev[i]
        else:
            kari+=Srev[i]
    elif len(kari) == 7:
        if kari == "remaerd":
            kari=Srev[i]
        else:
            break
    else:
        kari+=Srev[i]
if kari == "esare" or kari == "maerd" or kari == "resare" or kari == "remaerd":
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

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

def isValid(T, str):
    tmp = T+str
    if len(tmp) > len(S):
        return
    if tmp == S:
        print("YES")
        sys.exit()
    T = tmp
    isValid(T, "dream")
    isValid(T, "dreamer")
    isValid(T, "erase")
    isValid(T, "eraser")

isValid(T, "")
print("NO")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
//words = ['dream', 'dreamer', 'erase', 'eraser']
words = ['dream', 'erase', 'aser*', 'er', 'as']
s = input()
for word in words:
  s = s.replace(word, '*')
s = s.replace('*', '')
if len(s) == 0:
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

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

while True:
  if s[:5] == "maerd":
    s = s[5:]
  elif s[:7] == "remaerd":
    s - s[7:]
  elif s[:5] == "esare":
    s = s[5:]
  elif s[:6] == "resare":
    s - s[6:]
  else:
    break

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

Submission status: Runtime Error

Solution code:
def dream(s):
  ss=s
  s=s.replace("maerd","")
  s=s.replace("resare","")
  s=s.replace("esare","")
  s=s.replace("remserd","")
 
   if s=="":
    return "YES"
  else:
    return "NO"
s=input()
s=s[::-1]
print(dream(s))

Submission status: Runtime Error

Solution code:
s = list(input())
s.reverse()
s = "".join(s)
before_s = s
for _ in range(10**5):
    if s[:5]=="maerd" or s[:5] =="esare":
        s = s[5:]
    elif s[:7]=="remaerd" :
        s = s[7:]
    elif s[:6] == "resare":
        s = s[6:]
    if s == "":
        ans = "YES"
        break
    if s == before_s:
        ans ="NO"
        break
print(ans)