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:
import sys
sys.setrecursionlimit(1000000)
a=['dream','dreamer','erase','eraser']
def check(c):
    rt=False
    size=len(c)
    if c=='':
        return True
    for i in a:
        if size>=len(i) and c[:len(i)]==i:
            rt=check(c[len(i):]) or rt
    return rt

print(cnt,'YES' if check(s) else 'NO', s)

Submission status: Runtime Error

Solution code:
S = input()
# S.reverse()
S = S[::-1]
#dream, dreamer, erase, eraser
headers = ["resare","esare","remaerd","maerd"]

def solve(str):
    if str == "":
        return(True)
    else:
        for header in headers:
            if str.startswith(header):
                return(solve(str[len(header):]))
        return(False)

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

Submission status: Runtime Error

Solution code:
S = input()

def string_cut(string):
    if string[0] == 'd' and len(string)>5:
        sliced = string[7:]
        if sliced[0] == 'a':
            sliced = string[5:]
            string_cut(sliced)
        else:
            string_cut(sliced)
    
    if string[0] == 'e' and len(string)>5:
        sliced = string[5:]
        if sliced[0] == 'r':
            sliced = string[6:]
            string_cut(sliced)
        else:
            string_cut(sliced)
    
    if string[0] != 'd' or string[0] != 'e' or len(string) < 5:
        print('NO')
    
    if len(string) == 0:
        print('YES')

string_cut(S)

Submission status: Runtime Error

Solution code:
def erase_end(string):
    if string.endswith("dream"):
        string = string.rstrip("dream")
    elif string.endswith("dreamer"):
        string = string.rstrip("dreamer")
    elif string.endswith("erase"):
        string = string.rstrip("erase")
    elif string.endswith("eraser"):
        string = string.rstrip("eraser")
    elif string == "":
        string = "YES"
    else:
        string = "NO"
    return string
    
string = input()

while True:
    if string == "YES" or string == "NO":
    string = erase_end(string)
        break

print(string)

Submission status: Runtime Error

Solution code:
T = input()
lenT = len(T)
a = T.replace("eraser","xxxxxx")
b = a.replace("dreamer","xxxxxxx")
c = b.replace("erase","xxxxx")
d = c.replace("dream","xxxxx")
D = d.count("x")
if D == lenT:
  print("YES")
else D < lenT:
  print("NO")

Submission status: Runtime Error

Solution code:
T = input()
 
w0 = "dream"
w1 = "dreamer"
w2 = "erase"
w3 = "eraser"
 
dict_sen = {0:w0,1:w1,2:w2,3:w3}
 
dp = ""
cnt = 0
cnt1= 0
F = 0
while(cnt < time2):
  cnt += 1
  for i in range(4):
    if T[F:F+len(dict_sen[i])] == dict_sen[i]:
      dp.extend(dict_sen[i])
      F = len(dp)
      cnt1 += 1
      break
 
if dp != T:
  print("NO")
else :
  print("YES")

Submission status: Runtime Error

Solution code:
T = input()
 
w0 = "dream"
w1 = "dreamer"
w2 = "erase"
w3 = "eraser"
 
dict_sen = {0:w0,1:w1,2:w2,3:w3}
 
dp = ""
cnt = 0
cnt1= 0
time = ceil(len(T)/5)
time2 = floor(len(T)/7)

while(cnt < time):
  cnt += 1
  for i in range(4):
    if T[:len(dict_sen[i])] == dict_sen[i]:
      T = T[len(dict_sen[i]):]
      cnt1 += 1
      break

if cnt1 < time2:
  print("NO")
else :
  print("YES")

Submission status: Runtime Error

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

def solve(s):
    if s in ["maerd","remaerd","esare","resare"]:
        return True
    elif len(s) <= 7:
        return False
    if s[0:5] in ["maerd","esare"]:
        return solve(s[5:])
    if s[0:6] == "resare":
        return solve(s[6:])
    if s[0:7] == "remaerd":
        return solve(s[7:])
    return False
print("YES" if solve(s) else "NO")

Submission status: Runtime Error

Solution code:
def solve(S):
    if S in ["dream","dreamer","erase","eraser"]:
        return True
    elif len(S) <= 7:
        return False

    if S[0:7] == "dreamer":
        return solve(S[7:]) or solve(S[5:])
    elif S[0:5] == "dream":
        return solve(S[5:])
    if S[0:6] == "eraser":
        return solve(S[6:])
    elif S[0:5] == "erase":
        return solve(S[5:])

    return False

print("YES" if solve(input()) else "NO")

Submission status: Runtime Error

Solution code:
def solve(S):
    if S in ["dream","dreamer","erase","eraser"]:
        return True
    elif len(S) <= 7:
        return False

    if S[0:7] == "dreamer":
        return solve(S[7:]) or solve(S[5:])
    elif S[0:5] == "dream":
        return solve(S[5:])
    if S[0:6] == "eraser":
        return solve(S[6:]) or solve(S[5:])
    elif S[0:5] == "erase":
        return solve(S[5:])

    return False

print("YES" if solve(input()) else "NO")

Submission status: Runtime Error

Solution code:
def solve(S):
    if S == "":
        return True
    
    if S in ["dream","dreamer","erase","eraser"]:
        return True
    elif len(S) <= 6:
        return False

    if S[0:7] == "dreamer":
        return solve(S[7:]) or solve(S[5:])
    elif S[0:5] == "dream":
        return solve(S[5:])
    if S[0:6] == "eraser":
        return solve(S[6:]) or solve(S[5:])
    elif S[0:5] == "erase":
        return solve(S[5:])

    return False

print("YES" if solve(input()) else "NO")

Submission status: Runtime Error

Solution code:
def solve(S):
    if S in ["dream","dreamer","erase","eraser"]:
        return True
    elif len(S) <= 7:
        return False
    if S[0:7] == "dreamer":
        return solve(S[7:]) or solve(S[5:])
    elif S[0:5] == "dream":
        return solve(S[5:])
    if S[0:6] == "eraser":
        return solve(S[6:]) or solve(S[5:])
    elif S[0:5] == "erase":
        return solve(S[5:])

    return False

print("YES" if solve(input()) else "NO")

Submission status: Runtime Error

Solution code:
st=input()
j="0"
u="0"
for i in st:
    if i=="d" and u=="0":
        u="d"
        j="1"
    elif i=="r" and u=="d":
        u="r1"
    elif i=="e" and u=="r1":
        u="e1"
    elif i=="a" and u=="e1":
        u="a1"
    elif i=="m" and u=="a1":
        u="0"
    elif i=="e" and u=="0":
        u="e2"
        j="2"
    elif i=="r" and u=="e2":
        u="0"
    """"""    
    elif i=="e" and u=="0":
        u="e3"
        j="0"
    elif i=="r" and u=="e3":
        u="r2"
    """"""
    elif i=="a" and u=="0" and j=="2":
        u="a2"
    elif i=="s" and u=="a2":
        u="s"
    elif i=="e" and u=="s":
        u="0"
        j="3"
    elif i=="r" and j=="3":
        j="0"
    else:
        print("NO")
        exit(0)
if u=="0":
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
s = S()
while s:
    if s[:7] == list("dreamer"):
        i = 5
        while s[i:i+5] == list("erase"):
            i += 5
        if s[i] == "r":i+=1
        s = s[i:]
    elif s[:6] == list("eraser"):
        while s[i:i+5] == list("erase"):
            i += 5
        if s[i] == "r":i+=1
        s = s[i:]
    elif s[:5] == list("dream"):
        s = s[5:]
    elif s[:5] == list("erase"):
        s = s[5:]
    else:
        print("NO")
        quit()
print("YES")
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Runtime Error

Solution code:
import sys
s = list(input())
check =['dream','dreamer','erase','eraser']
while len(s) >= 8:
    if ''.join(s[-5:]) == check[0]:
        print(s)
        for _ in range(5): s.pop()
        continue
    if ''.join(s[-7:]) == check[1]:
        print(s)
        for _ in range(7): s.pop()
        continue
    if ''.join(s[-5:]) == check[2]:
        print(s)
        for _ in range(5): s.pop()
        continue
    if ''.join(s[-6:]) == check[3]:
        print(s)
        for _ in range(6): s.pop()
        continue
    print('No')
    sys.exit()
if ''.join(s) == check[0] or ''.join(s) == check[1] or ''.join(s) == check[2] or ''.join(s) == check[3]:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s1=input().replace("eraser","")
s2=s1.replace("erase","")
s3=s2.replace("dreamer","")
s4=s3.replace("dream","")
if s:
	print("No")
else:
	print("Yes")
"""
#failed
import itertools

s=str(input())
add=["dream","dreamer","erase","eraser"]
t=[]

for i,_ in enumerate(add,1):
	for j in itertools.permutations(add,r=i):
		t.append("".join(j))

print(t)

temp=False
for i in range(len(t)):
	if(s==t[i]):
		temp=True
		break

if temp==True:
	print("Yes")
else:
	print("No")
	

"""

Submission status: Runtime Error

Solution code:
l_o = ['dream','dreamer', 'ereaser', 'erase']
l_r = [x[::-1] for x in l_o]

mi = min([len(word) for word in l_o])

print(helper(input()[::-1]))

def helper(s):
    print(s)
    if s == '':
        return True
    elif len(s) < mi:
        return False

    else:
        for word in l_r:
            if s.startswith(word):
                return helper(s[len(word):])
        return False

Submission status: Runtime Error

Solution code:
int_s = input()
str_sr = int_s[::-1]


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

str_r = list(map(lambda x: x[::-1], str_a))

result = True

while len(str_sr):
    currnt_flg = False
    for r in str_r:
        print('r:' + r)
        if len(str_sr) >= len(r) and str_sr[:len(r)] == r:
            print('ok')
            str_sr = str_sr[len(r):]
            print(str_sr)
            current_flg = True
            break
    else:
        result = False
        break

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

Submission status: Runtime Error

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

YES = "YES"  # type: str
NO = "NO"  # type: str

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

def solve(S: str):
    print(YES if is_valid(S) else NO)
    return

def is_valid(S):
    if S == '':
        return True
    for token in tokens:
        sub = S[-len(token):]
        if sub == token:
            return is_valid(S[:-len(token)])
    return False

def is_valid2(S):
    import re
    x = r"^(dream|dreamer|erase|eraser)*$"
    return True if re.match(x, S) else False

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

YES = "YES"  # type: str
NO = "NO"  # type: str

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

def solve(S: str):
    print(YES if is_valid(S) else NO)
    return

def is_valid(S):
    if S in tokens:
        return True
    for token in tokens:
        sub = S[-len(token):]
        if sub == token:
            return is_valid(S[:-len(token)])
    return False


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

pattern = ["maerd", "remaerd", "esare", "resare"]

def rec(s):
    if (len(s) == 0):
        return True

    for candidate in pattern:
        if s[:len(candidate)] == candidate:
            rec(s[len(candidate):])
            return True

    return False

def main():
    S = input()
    S = S[::-1]

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

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
S = input()
S = S[::-1]
l = ['dream','dreamer','erase','eraser']
L = []
for i in l:
    L.append(i[::-1])
def rec(s):
    flag=False
    for ii in L:
        leng = len(ii)
        if len(s)<leng:
            continue
        else:
            if s[num:leng]==ii:
                if len(s)==leng:
                    flag=True
                    break
                else:
                    return rec(s[leng:])
            else:
                continue
    return flag
f = rec(S)
if f:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
S = input()

S = S[::-1]

l = ['dream','dreamer','erase','eraser']
L = []
for i in l:
    L.append(i[::-1])
num=0
def rec(s):
    flag=False
    for ii in L:
        leng = len(ii)
        if len(s)<leng:
            continue
        else:
            if s[num:leng]==ii:
                if len(s)==leng:
                    flag=True
                    break
                else:
                    return rec(s[leng:])
            else:
                continue
    return flag
f = rec(S)
if f:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
S = input()

S = S[::-1]

l = ['dream','dreamer','erase','eraser']
L = []
for i in l:
    L.append(i[::-1])
print(L)
num=0
def rec(s):
    flag=False
    for ii in L:
        leng = len(ii)
        if len(s)<leng:
            continue
        else:
            if s[num:leng]==ii:
                if len(s)==leng:
                    flag=True
                    break
                else:
                    return rec(s[leng:])
            else:
                continue
    return flag
f = rec(S)
if f:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
S = input()

def rec(s):
    leng = len(s)
    if leng==0:
        print('YES')
    else:
        if leng>4:
            if s[0:5]=="dream":
                if leng==5:
                    rec(s[5:])
                else:
                    if s[5:7]=="er":
                        if s[5:10]=="erase":
                            if leng==10:
                                rec(s[10:])
                            elif s[10]=="r":
                                rec(s[11:])
                            else:
                                rec(s[10:])
                        else:
                            rec(s[7:])
                    else:
                        rec(s[5:])
            elif s[0:5]=="erase":
                if leng==5:
                    rec(s[5:])
                else:
                    if s[5]=="r":
                        rec(s[6:])
                    else:
                        rec(s[5:])
            else:
                print('NO')
        else:
            print('NO')
rec(S)

Submission status: Runtime Error

Solution code:
S = input()

def rec(s):
    leng = len(s)
    if leng==0:
        print('YES')
    else:
        if s[0:5]=="dream":
            if leng==5:
                rec(s[5:])
            else:
                if s[5:7]=="er":
                    if s[5:10]=="erase":
                        if leng==10:
                            rec(s[10:])
                        elif s[10]=="r":
                            rec(s[11:])
                        else:
                            rec(s[10:])
                    else:
                        rec(s[7:])
                else:
                    rec(s[5:])
        elif s[0:5]=="erase":
            if leng==5:
                rec(s[5:])
            else:
                if s[5]=="r":
                    rec(s[6:])
                else:
                    rec(s[5:])
        else:
            print('NO')
rec(S)

Submission status: Runtime Error

Solution code:
S = input()

def rec(s):
    leng = len(s)
    if leng==0:
        print('YES')
    else:
        if s[0:5]=="dream":
            if leng==5:
                rec(s[5:])
            else:
                if s[5:7]=="er":
                    if s[5:10]=="erase":
                        if s[10]=="r":
                            rec(s[11:])
                        else:
                            rec(s[10:])
                    else:
                        rec(s[7:])
                else:
                    rec(s[5:])
        elif s[0:5]=="erase":
            if leng==5:
                rec(s[5:])
            else:
                if s[5]=="r":
                    rec(s[6:])
                else:
                    rec(s[5:])
        else:
            print('NO')
rec(S)

Submission status: Runtime Error

Solution code:
S = input()

def rec(s):
    print(s)
    leng = len(s)
    if leng==0:
        print('YES')
    else:
        if s[0:5]=="dream":
            if leng==5:
                rec(s[5:])
            else:
                if s[5:7]=="er":
                    if s[5:10]=="erase":
                        if s[10]=="r":
                            rec(s[11:])
                        else:
                            rec(s[10:])
                    else:
                        rec(s[7:])
                else:
                    print("s:")
                    print(s)
                    rec(s[5:])
        elif s[0:5]=="erase":
            if leng==5:
                rec(s[5:])
            else:
                if s[5]=="r":
                    rec(s[6:])
                else:
                    rec(s[5:])
        else:
            print('NO')
rec(S)

Submission status: Runtime Error

Solution code:
S = input()

sys.setrecursionlimit(10**7) 

def is_ok(s):
    if len(s)==0:
        return 'YES'
    elif len(s)<5:
        return 'NO'
    elif s[-7:]=='dreamer':
        next_s = s[:-7]
    elif s[-6:]=='eraser':
        next_s = s[:-6]
    elif s[-5:]=='dream' or s[-5:]=='erase':
        next_s = s[:-5]
    else:
        return 'NO'
    # import pdb;pdb.set_trace()
    ans = is_ok(next_s)
    return ans

print(is_ok(S))

Submission status: Runtime Error

Solution code:
S = input()

def is_ok(s):
    if len(s)==0:
        return 'YES'
    elif len(s)<5:
        return 'NO'
    elif s[-7:]=='dreamer':
        next_s = s[:-7]
    elif s[-6:]=='eraser':
        next_s = s[:-6]
    elif s[-5:]=='dream' or s[-5:]=='erase':
        next_s = s[:-5]
    else:
        return 'NO'
    # import pdb;pdb.set_trace()
    ans = is_ok(next_s)
    return ans

print(is_ok(S))

Submission status: Runtime Error

Solution code:

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

Submission status: Runtime Error

Solution code:
a

Submission status: Runtime Error

Solution code:
import re

def func(s):
    text = [ 'dream', 'dreamer', 'erase', 'eraser']
    if len(s) == 0:
        print('YES')
        exit()

    for t in text:
        if re.match(t, s):
            func(s.replace(t, '', 1))

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

    func(s)

    print('NO')

Submission status: Runtime Error

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

S = input()
words = ['dream', 'dreamer', 'erase', 'eraser']
result = True

while len(S) != 0 and result == True:
  print(S)
  for i in range(5,8):
    if i == 8:
      result = False
      break
    if S[-i:] == words[0]:
      S = S[:-i]
      break
    elif S[-i:] == words[1]:
      S = S[:-i]
      break
    elif S[-i:] == words[2]:
      S = S[:-i]
      break
    elif S[-i:] == words[3]:
      S = S[:-i]
      break
    else:
      continue

if result == True:
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
inp = input()
m = 0
n = 0
li = ['dream','dreamer','erase','eraser']
while True:
    for i in li:
        if inp.startswith(i):
    	    inpp = inp.replace(i,'',1)
    	    if inpp == '':
    		    m = 1
    		    break
    	    for k in li:
    	    	if inpp.startswith(k):
    		        inp = inpp
    		        n = 1
    		        break
    	    else:
                if k == 'eraser':
                	break
    	    	continue
    	    break
    if m == 1:
    	print('YES')
    	break
    if n != 1:
    	print('NO')
    	break

Submission status: Runtime Error

Solution code:
s = input()

def f(t):
    if len(t) > len(s):
        return False
    if t == s:
        return True
    return f(t + 'dream') or f(t + 'erase') or f(t + 'dreamer') or f(t + 'eraser')

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

Submission status: Runtime Error

Solution code:
s = input()

s = s[::-1]

s = list(s)
#print(s)
count = 0
can = True
jm = []
j = 0
maxcount = 0

for i in s:
    jm.append(s[j])
    j += 1
    count += 1
    if count > 7:
        can = False
#        print(0)
        break
    elif "".join(jm) == "maerd":
        maxcount += count
        count,j = 0,0
#        print(1)
    elif "".join(jm) == "remaerd":
        maxcount += count
        count,j = 0,0
        jm = []
#        print(2)
elif "".join(jm) == "esare":
        maxcount += count
        count,j = 0,0
        jm = []
#        print(jm + 1)
elif "".join(jm) == "rersare":
        maxcount += count
        count,j = 0,0
        jm = []
    else:
        pass


#print("forward bool is" + str(can))

if maxcount == 0:
    can = False

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

Submission status: Runtime Error

Solution code:
S = input()


def is_composable(s):
    if len(s) == 0:
        return True

    if s.startswith("dreamer"):
        dream_s = s[5:]
        dreamer_s = s[7:]
        return is_composable(dream_s) or is_composable(dreamer_s)
    elif s.startswith("dream"):
        dream_s = s[5:]
        return is_composable(dream_s)
    elif s.startswith("eraser"):
        erase_s = s[5:]
        eraser_s = s[6:]
        return is_composable(erase_s) or is_composable(eraser_s)
    elif s.startswith("erase"):
        erase_s = s[5:]
        return is_composable(erase_s)
    else:
        return False


if len(S) > 0 and is_composable(S):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
S = input()


def is_composable(s):
    if len(s) == 0:
        return True

    if s.startswith("dreamer"):
        dream_s = s[5:]
        dreamer_s = s[7:]
        return is_composable(dream_s) or is_composable(dreamer_s)
    elif s.startswith("dream"):
        dream_s = s[5:]
        return is_composable(dream_s)
    elif s.startswith("eraser"):
        erase_s = s[5:]
        eraser_s = s[6:]
        return is_composable(erase_s) or is_composable(eraser_s)
    elif S.startswith("erase"):
        erase_s = s[5:]
        return is_composable(erase_s)
    else:
        return False


if len(S) > 0 and is_composable(S):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
from collections import deque
A = deque(input())
while len(A) >= 2:
    if list(A)[-5:] == list("dream") or list("erase"):
        for _ in range(5):
            A.pop()
    elif list(A)[-6:] == list("eraser"):
        for _ in range(6):
            A.pop()
    elif list(A)[-7:] == list("dreamer"):
        for _ in range(7):
            A.pop()
    else:
        A = deque([0])
if len(A) == 0:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
from collections import deque
A = deque(input())
while A != deque() and A != deque([0]):
    if list(A)[:7] == list("dreamer") and list(A)[5:10] != list("erase"):
        for _ in range(7):
            A.leftpop()
    elif A[:5] == list("dream"):
        for _ in range(5):
            A.leftpop()
    elif A[:6] == list("eraser"):
        for _ in range(6):
            A.leftpop()
    elif A[:5] == list("erase"):
        for _ in range(5):
            A.leftpop()
    else:
        A = [0]
if A == []:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
from collections import deque
A = deque(input())
while A != [] and A != [0]:
    if A[:7] == list("dreamer") and A[5:10] != list("erase"):
        A = A[7:]
    elif A[:5] == list("dream"):
        A = A[5:]
    elif A[:6] == list("eraser"):
        A = A[6:]
    elif A[:5] == list("erase"):
        A = A[5:]
    else:
        A = [0]
if A == []:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
def solve(s):
    if len(s) == 0:
        return True
    return any(solve(s[len(prefix):]) for prefix in ('dreamer', 'dream', 'eraser', 'erase') if s.startswith(prefix))

print('YES' if solve(input()) else 'NO')

Submission status: Runtime Error

Solution code:
from collections import deque
def DFS(S):
    word_list = ["dream", "dreamer", "erase", "eraser"]
    stack = deque(word_list)
    while stack:
        print(stack)
        word = stack.pop()
        if word == S[0]:
            return "Yes"
        for i in word_list:
            next_word = word + i
            check = S[0][:len(word + i)]
            if next_word != check:
                continue
            if next_word == check:
                stack.append(next_word)
    return "NO"






if __name__ == "__main__":
    S = [input()]
    print(DFS(S))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
int_s = input()
str_sr = int_s[::-1]


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

str_r = list(map(lambda x: x[::-1], str_a))

result = True

while len(str_sr):
    currnt_flg = False
    for r in str_r:
        print('r:' + r)
        if len(str_sr) >= len(r) and str_sr[:len(r)] == r:
            print('ok')
            str_sr = str_sr[len(r):]
            print(str_sr)
            current_flg = True
            break
    else:
        result = False
        break

if result:
    print('YES')
else:
    print('No')

Submission status: Runtime Error

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
                    if s[i] != "e" and s[i] != "d":
                        print("NO")
                        exit()
                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
                    if s[i] == "e" or s[i] == "d":
                        print("NO")
                        exit()
                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("NO")
                        exit()
                else:
                    print("YES")
                    exit()
            else:
                print("NO")
                exit()
        else:
            print("NO")
            exit()
    p = 0
print("YES")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

while True:
  if S.endswith('dream'):
    S = S[:-5]
  elif S.endswith('dreamer'):
    S = S[:-7]
  elif S.endswith('erase'):
    S = S[:-5]
  elif S.endswith('eraser'):
    S = S[:-6]
  else break

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

Submission status: Runtime Error

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

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


def foo(s):
    last = s[-1:]
    # is empty
    print(s)
    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))