Problem:


Score : 300 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Another string T is initially empty.
Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:

Append one of the following at the end of T: dream, dreamer, erase and eraser.

Constraints

1≦|S|≦10^5

S consists of lowercase English letters.

Input

The input is given from Standard Input in the following format:

S

Output

If it is possible to obtain S = T, print YES. Otherwise, print NO.

Sample Input 1

erasedream

Sample Output 1

YES

Append erase and dream at the end of T in this order, to obtain S = T.

Sample Input 2

dreameraser

Sample Output 2

YES

Append dream and eraser at the end of T in this order, to obtain S = T.

Sample Input 3

dreamerer

Sample Output 3

NO



Sample input:
erasedream


Sample output:
YES

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
S = input()
n=0
flg=0
#print(s[0:K-1]+s[K-1].lower()+s[K:N])
while(not S==""):

#    if  S[n:].startswith("dreameraser"):
#        n=n+11
        #print(S[n:])
        #flg==1
#        continue
    if S.endswith("dreamer"):
        #n=n+6
        S=S.replace("dreamer","")
        #print(S[n:])
        continue
    elif S.endswith("dream"):
        #n=n+5
        S=S.replace("dream","")
        #print(S)
        #flg==1
        continue
    elif S.endswith("eraser"):
        #n=n+6
        S=S.replace("eraser","")
        #print(S[n:])
        continue
    elif S.endswith("erase"):
        #n=n+5
        S=S.replace("erase","")
        #print(S)
        #flg==1
        continue
    print("NO")
    exit()

print("YES")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
S = input()
n=0
flg=0
#print(s[0:K-1]+s[K-1].lower()+s[K:N])
while(n<len(S)):

    if  S[n:].startswith("dreameraser"):
        n=n+11
        #print(S[n:])
        #flg==1
        continue
    elif S[n:].startswith("dreamer"):
        n=n+6
        #print(S[n:])
        continue
    elif S[n:].startswith("dream"):
        n=n+5
        #print(S[n:])
        #flg==1
        continue
    elif S[n:].startswith("eraser"):
        n=n+6
        #print(S[n:])
        continue
    elif S[n:].startswith("erase"):
        n=n+5
        #print(S[n:])
        #flg==1
        continue
    print("NO")
    exit()

print("YES")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
S = input()
#print(s[0:K-1]+s[K-1].lower()+s[K:N])
while(not S==""):
    if S.startswith("dreameraser"):
        S=S[11:]
        #print(S)
        continue
    elif S.startswith("dreamer"):
        S=S[7:]
        #print(S)
        continue
    elif S.startswith("dream"):
        S=S[5:]
        continue
    elif S.startswith("eraser"):
        S=S[6:]
        continue
    elif S.startswith("erase"):
        S=S[5:]
        continue
    else:
        print("NO")
        exit()

print("YES")

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


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


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'NO', True: 'YES'}
yn = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


def main():
    s = S()
    skip = [0] * len(s)

    for i in range(len(s)):
        if s[i:i+5] == 'dream':
            for idx in range(i, i+5):
                skip[idx] = 1

    for i in range(len(s)):
        if s[i:i+5] == 'erase':
            for idx in range(i, i+5):
                skip[idx] = 2

    for i in range(len(s)-1):
        if skip[i] == 0 and skip[i+1] == 0 and skip[i-1] == 1:
            skip[i] = 3
            skip[i+1] = 3

    for i in range(len(s)):
        if skip[i] == 0 and skip[i-1] == 2:
            skip[i] = 4

    print(YN[all(skip)])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=input()
s=s[::-1]
divide=["dream", "dreamer", "erase", "eraser"]
c1=1
c2=0
for i in range(4):
    divide[i]==divide[i][::-1]
for i in range(len(s)):
    c2=0
    for j in range(4):
        d=divide[j]
        if s[i:i+len(d)]==d:
            c2=1
            i+=len(d)

    if c2==0:
        c1=0
        break

if c1==1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s=input()
s=s[::-1]
divide=["dream", "dreamer", "erase", "eraser"]
c1=1
c2=0
for i in range(4):
    divide[i]=divide[i][::-1]
for i in range(len(s)):
    for j in range(4):
        d=divide[j]
        if s[i:i+len(d)]==d:
            c2=1
            i+=len(d)

    if c2==0:
        c1=0
        break

if c1==1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s=input()
s=s[::-1]
divide=["dream", "dreamer", "erase", "eraser"]
c1=1
c2=0
for i in range(4):
    divide[i]=divide[i][::-1]
for i in range(len(s)):
    for j in range(4):
        d=divide[j]
        if s[i:i+len(d)]==d:
            c2=1
            i+=len(d)

    if c2==0:
        c1=0
        break

Submission status: Wrong Answer

Solution code:
s = "".join(list(reversed(input())))
t_t = ["maerd", "remared", "esare", "resare"]

for _ in range(len(s)):
    for q in t_t:
        if q == s[:len(q)]:
            s = s[len(q):]

print("NO" if len(s) else "YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def main():
    # 入力
    st = input()

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

    d_count = st.count("d")
    era_count = st.count("era")

    d_idx_ls = []
    era_idx_ls = []

    tmp_idx = 0
    for i in range(d_count):
        idx = st.index("d", tmp_idx)
        tmp_idx = idx
        d_idx_ls.append(idx)

    tmp_idx = 0
    for i in range(era_count):
        idx = st.index("era", tmp_idx)
        tmp_idx = idx
        era_idx_ls.append(idx)

    if d_count == 0 and era_count == 0:
        print("NO")
        return
    elif era_count == 0:
        pre_tmp_st_list = [""]
        for i in range(d_count):
            tmp_st_list = []
            for x in pre_tmp_st_list:
                tmp_st_list.append(x + "dream")
                tmp_st_list.append(x + "dreamer")
            pre_tmp_st_list = tmp_st_list

        for x in pre_tmp_st_list:
            if x == st:
                print("YES")
                return
        print("NO")
        return
    elif d_count == 0:
        pre_tmp_st_list = [""]
        for i in range(era_count):
            tmp_st_list = []
            for x in pre_tmp_st_list:
                tmp_st_list.append(x + "erase")
                tmp_st_list.append(x + "eraser")
            pre_tmp_st_list = tmp_st_list

        for x in pre_tmp_st_list:
            if x == st:
                print("YES")
                return
        print("NO")
        return
    else:
        # 2^(d_count + era_count)の候補を作成して確認
        tmp_ls_idx_d = 0
        tmp_ls_idx_era = 0
        pre_tmp_st_list = [""]
        while tmp_ls_idx_d < d_count or tmp_ls_idx_era < era_count:
            tmp_st_list = []
            # 次に追加するのがd
            if tmp_ls_idx_era == era_count:
                for x in pre_tmp_st_list:
                    a = x + "dream"
                    if st.startswith(a):
                        tmp_st_list.append(a)

                    b = x + "dreamer"
                    if st.startswith(b):
                        tmp_st_list.append(b)
                if len(tmp_st_list) == 0:
                    print("NO")
                    return
                else:
                    pre_tmp_st_list = tmp_st_list
                tmp_ls_idx_d += 1
            # 次に追加するのがera
            elif tmp_ls_idx_d == d_count:
                for x in pre_tmp_st_list:
                    a = x + "erase"
                    if st.startswith(a):
                        tmp_st_list.append(a)

                    b = x + "eraser"
                    if st.startswith(b):
                        tmp_st_list.append(b)
                if len(tmp_st_list) == 0:
                    print("NO")
                    return
                else:
                    pre_tmp_st_list = tmp_st_list
                tmp_ls_idx_era += 1
            # 次に追加するのがd
            elif d_idx_ls[tmp_ls_idx_d] < era_idx_ls[tmp_ls_idx_era]:
                for x in pre_tmp_st_list:
                    a = x + "dream"
                    if st.startswith(a):
                        tmp_st_list.append(a)

                    b = x + "dreamer"
                    if st.startswith(b):
                        tmp_st_list.append(b)
                if len(tmp_st_list) == 0:
                    print("NO")
                    return
                else:
                    pre_tmp_st_list = tmp_st_list
                tmp_ls_idx_d += 1
            # 次に追加するのがera
            else:
                for x in pre_tmp_st_list:
                    a = x + "erase"
                    if st.startswith(a):
                        tmp_st_list.append(a)

                    b = x + "eraser"
                    if st.startswith(b):
                        tmp_st_list.append(b)
                if len(tmp_st_list) == 0:
                    print("NO")
                    return
                else:
                    pre_tmp_st_list = tmp_st_list
                tmp_ls_idx_era += 1

        for x in pre_tmp_st_list:
            if x == st:
                print("YES")
                return
        print("NO")


main()

Submission status: Wrong Answer

Solution code:
SET=["dreamer", "dream",  "eraser", "erase"]
S=input()
dp=[0]*100010
dp[0]=1
for i in range(len(S)):
  if not dp[i]:continue
  for j in SET:
    if S[i:i+len(j)]==j:
      dp[i+len(j)]=1
if dp[len(S)]==1:print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
s = input()

while s!="":
    if s[-5:]=="dream" or s[-5:]=="erase":
        s = s[:-5]
    elif s[-6:]=="dreamer" or s[-6:]=="eraser":
        s = s[:-6]
    else:
        print("NO")
        exit()
print("YES")

Submission status: Wrong Answer

Solution code:
s = input()
erase = s.count("erase")
eraser = s.count("eraser")
dreameraser = s.count("dreameraser")
dream = s.count("dream")
dreamer = s.count("dreamer")
erase -= eraser
dream -= dreamer
dreamer -= dreameraser
eraser -= dreameraser
if (eraser * 6 + erase * 5 + dream * 5 + dreamer * 6 + dreameraser*11) == len(s):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s = input()
erase = s.count("erase")
eraser = s.count("eraser")
erase -= eraser
dream = s.count("dream")
dreamer = s.count("dreamer")
dream -= dreamer
if (eraser * 6 + erase * 5 + dream * 5 + dreamer * 6) >= len(s):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s = input()
i = len(s) - 1
flag = False
while i > 0:
    flag = False
    if s[i] == "m" and s[i - 4:i + 1] == "dream":
        flag = True
        i -= 5
    elif s[i] == "e" and s[i - 4: i + 1] == "erase":
        i -= 5
        flag = True
    elif s[i] == "r":
        if s[i - 5: i + 1] == "eraser":
            flag = True
            i -= 6
        elif s[i - 6: i + 1] == "dreamer":
            flag = True
            i -= 7
    if flag == False:
        break
print("Yes" if flag else "No")

Submission status: Wrong Answer

Solution code:
t=input()
trigger=1
key=''
d=-1
app=['dreamer','eraser','dream','erase']
while len(t)>0 and trigger:
    for i in range(4):
        key=app[i]
        if key==t[:len(key)]:
            t=t[len(key):]
            trigger+=1
            d=i
            break
    trigger-=1
    if trigger==0 and d==0 and t[:3]=='ase':
        t='er'+t
        trigger+=1
if t=='':
    print('YES')
else:
    print('NO')
    print(t)

Submission status: Wrong Answer

Solution code:
t=input()
trigger=1
app=['dream','dreamer','erase','eraser']
while len(t)>0 and trigger:
    for i in range(4):
        key=app[i]
        if key==t[:len(key)]:
            t=t[len(key):]
            trigger+=1
            break
    trigger-=1
if t=='':
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
t=input()
trigger=1
app=['dream','dreamer','erase','eraser']
while len(t)>0 and trigger:
    for i in range(4):
        key=app[i]
        if key==t[:len(key)]:
            t=t[len(key):]
            print(t)
            trigger+=1
            break
    trigger-=1
if t=='':
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
S=input()
i=0
ans="YES"
while i<len(S):
    if len(S)-i<5:
        ans="NO"
        break
    elif S[i:i+7]=="dreamer":
        i+=7
    elif S[i:i+6]=="eraser":
        i+=6
    elif S[i:i+5] == "dream" or S[i:i+5] == "erase":
        i+=5
    else:
        ans="NO"
        break
if i<len(S)-1:
    ans="NO"
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())

s = s.replace('dreamer','')
s = s.replace('eraser','')
s = s.replace('dream','')
s = s.replace('erase','')

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

Submission status: Wrong Answer

Solution code:
s = str(input())

s.replace('dreamer','')
s.replace('eraser','')
s.replace('dream','')
s.replace('erase','')

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

Submission status: Wrong Answer

Solution code:
S = input()
ch = ["dream", "dreamer", "erase", "eraser"]
while S:
  N = len(S)
  if S[N-5:N] == ch[0] or S[N-5:N] == ch[2]:
    S = S[:N-5]
  elif S[N-6:N] == ch[1] or S[N-6:N] == ch[3]:
    S = S[:N-6]
  else:
    print("NO")
    exit()
print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
l = input()
l = l.replace('eraser','')
l = l.replace('erase','')
l = l.replace('dreamer','')
l = l.replace('dream','')

if l == '':
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
l = input()
l = l.replace('eraser','')
l = l.replace('erase','')
l = l.replace('dream','')
l = l.replace('dreamer','')

if l == '':
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
words=["eraser","erase","dreamer","dream"]
S=input()
for i in range(0,4):
    S=S.replace(words[i],"",)
if S=="":
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
words=["eraser","erase","dreamer","dream"]
S=input()
for i in range(4):
    S=S.strip(words[i])
if S=="":
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
words=["eraser","erase","dreanmer","dream"]
S=input()
for i in range(4):
    S=S.strip(words[i])
if S=="":
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()

tmp_index = 0

while(len(s) - tmp_index > 4) :

	if( s[tmp_index] == 'd' ) :
		if s[tmp_index:tmp_index+7] == 'dreamer' :
			if ( s[tmp_index + 5:tmp_index + 10] == 'erase' ):
				tmp_index += 5
			else :
				tmp_index += 7
		elif s[tmp_index:tmp_index+5] == 'dream' :
			tmp_index += 5
		else :
			print('NO')
			tmp_index = len(s) - 1
			
	elif( s[tmp_index] == 'e' ) :
		if  s[tmp_index:tmp_index + 6] == 'eraser' :
			tmp_index += 6
		elif s[tmp_index:tmp_index+5] == 'erase' :
			tmp_index += 5
		else :
			print('NO')
			tmp_index = len(s) - 1
	else :
		print('NO')
		tmp_index = len(s) - 1
	if len(s) == tmp_index :
		print('YES')
	elif len(s) - tmp_index < 5 :
		print('NO')

Submission status: Wrong Answer

Solution code:
s = input()

checkedList = []
noCheckedList = []
tmp_index = 0

while(True) :

	if( s[tmp_index] == 'd' ) :
		if ( not (tmp_index in checkedList) ) and ( s[tmp_index:tmp_index+7] == 'dreamer' ) :
			if ( len(s) - tmp_index > 9 ) and ( s[tmp_index + 7:tmp_index + 10] == 'ase' ):
				noCheckedList.append(tmp_index)
			checkedList.append(tmp_index)
			tmp_index += 7
		elif s[tmp_index:tmp_index+5] == 'dream' :
			tmp_index += 5
	elif( s[tmp_index] == 'e' ) :
		if ( not (tmp_index in checkedList) )  and  ( s[tmp_index:tmp_index + 6] == 'eraser' ) :
			tmp_index += 6
		elif s[tmp_index:tmp_index+5] == 'erase' :
			tmp_index += 5
	else :
		if len(noCheckedList) != 0 :
			tmp_index = noCheckedList.pop() + 5
			continue
		else :
			print('NO')
			tmp_index = len(s) - 1
	if tmp_index == len(s):
		print('YES')
		break
	elif len(s) - tmp_index < 5 :
		if len(noCheckedList) != 0 :
			tmp_index = noCheckedList.pop() + 5
		else :
			print('NO')
			break

Submission status: Wrong Answer

Solution code:
s = input()

checkedList = []
noCheckedList = []
tmp_index = 0

while(True) :

	if( s[tmp_index] == 'd' ) :
		if ( not (tmp_index in checkedList) ) and ( s[tmp_index:tmp_index+7] == 'dreamer' ) :
			if ( len(s) - tmp_index > 10 ) and ( s[tmp_index + 7:tmp_index + 11] == 'aser' ):
				noCheckedList.append(tmp_index)
			checkedList.append(tmp_index)
			tmp_index += 7
		elif s[tmp_index:tmp_index+5] == 'dream' :
			tmp_index += 5
	elif( s[tmp_index] == 'e' ) :
		if ( not (tmp_index in checkedList) )  and ( s[tmp_index:tmp_index+5] == 'erase' ) and ( s[tmp_index:tmp_index+6] == 'eraser' ) :
			if ( len(s) - tmp_index > 9 ) and ( s[tmp_index + 6:tmp_index + 10] == 'aser' ) :
				noCheckedList.append(tmp_index)
			checkedList.append(tmp_index)
			tmp_index += 6
		elif s[tmp_index:tmp_index+5] == 'erase' :
			tmp_index += 5
	else :
		if len(noCheckedList) != 0 :
			tmp_index = noCheckedList.pop() + 5
			continue
		else :
			print('NO')
			tmp_index = len(s) - 1
	if tmp_index == len(s):
		print('YES')
		break
	elif len(s) - tmp_index < 5 :
		if len(noCheckedList) != 0 :
			tmp_index = noCheckedList.pop() + 5
		else :
			print('NO')
			break

Submission status: Wrong Answer

Solution code:
s = input()

checkedList = []
noCheckedList = []
tmp_index = 0

while(True) :

	if( s[tmp_index] == 'd' ) :
		if ( not (tmp_index in checkedList) ) and ( s[tmp_index:tmp_index+7] == 'dreamer' ) :
			if ( len(s) - tmp_index > 10 ) and ( s[tmp_index + 7:tmp_index + 11] == 'aser' ):
				noCheckedList.append(tmp_index)
			checkedList.append(tmp_index)
			tmp_index += 7
		elif s[tmp_index:tmp_index+5] == 'dream' :
			tmp_index += 5
	elif( s[tmp_index] == 'e' ) :
		if ( not (tmp_index in checkedList) )  and ( s[tmp_index:tmp_index+5] == 'erase' ) and ( s[tmp_index:tmp_index+6] == 'eraser' ) :
			if ( len(s) - tmp_index > 9 ) and ( s[tmp_index + 6:tmp_index + 10] == 'aser' ) :
				noCheckedList.append(tmp_index)
			checkedList.append(tmp_index)
			tmp_index += 6
		elif s[tmp_index:tmp_index+5] == 'erase' :
			tmp_index += 5
	else :
		if len(noCheckedList) != 0 :
			tmp_index = noCheckedList.pop() + 5
			continue
		else :
			print('NO')
			tmp_index = len(s)
	if tmp_index == len(s):
		print('YES')
		break
	elif len(s) - tmp_index < 5 :
		if len(noCheckedList) != 0 :
			tmp_index = noCheckedList.pop() + 5
		else :
			print('NO')
			break

Submission status: Wrong Answer

Solution code:
s = input()

checkedList = []
noCheckedList = []
tmp_index = 0

while(True) :

	if( s[tmp_index] == 'd' ) :
		if ( not (tmp_index in checkedList) ) and ( s[tmp_index:tmp_index+7] == 'dreamer' ) :
			if ( len(s) - tmp_index > 10 ) and ( s[tmp_index + 7:tmp_index + 11] == 'aser' ):
				noCheckedList.append(tmp_index)
			checkedList.append(tmp_index)
			tmp_index += 7
		elif s[tmp_index:tmp_index+5] == 'dream' :
			tmp_index += 5
	elif( s[tmp_index] == 'e' ) :
		if ( not (tmp_index in checkedList) )  and ( s[tmp_index:tmp_index+5] == 'erase' ) and ( s[tmp_index:tmp_index+6] == 'eraser' ) :
			if ( len(s) - tmp_index > 9 ) and ( s[tmp_index + 6:tmp_index + 10] == 'aser' ) :
				noCheckedList.append(tmp_index)
			checkedList.append(tmp_index)
			tmp_index += 6
		elif s[tmp_index:tmp_index+5] == 'erase' :
			tmp_index += 5
	else :
		if len(noCheckedList) != 0 :
			tmp_index = noCheckedList.pop() + 5
			continue
		else :
			print('NO')
			break
	if tmp_index == len(s):
		print('YES')
		break
	elif len(s) - tmp_index < 5 :
		if len(noCheckedList) != 0 :
			tmp_index = noCheckedList.pop() + 5
		else :
			print('NO')

Submission status: Wrong Answer

Solution code:
s = input()

CheckedList = []
noCheckedList = []
tmp_index = 0

while(True) :

	if( s[tmp_index] == 'd' ) :
		if ( not (tmp_index in CheckedList) ) and ( s[tmp_index:tmp_index+5] == 'dream' ) and ( s[tmp_index:tmp_index+7] == 'dreamer' ) :
			noCheckedList.append(tmp_index)
			CheckedList.append(tmp_index)
			tmp_index += 7
		elif s[tmp_index:tmp_index+5] == 'dream' :
			tmp_index += 5
		elif s[tmp_index:tmp_index+7] == 'dreamer' :
			tmp_index += 7
	elif( s[tmp_index] == 'e' ) :
		if ( not (tmp_index in CheckedList) )  and ( s[tmp_index:tmp_index+5] == 'erase' ) and ( s[tmp_index:tmp_index+6] == 'eraser' ) :
			noCheckedList.append(tmp_index)
			CheckedList.append(tmp_index)
			tmp_index += 6
		elif s[tmp_index:tmp_index+5] == 'erase' :
			tmp_index += 5
		elif s[tmp_index:tmp_index+6] == 'eraser' :
			tmp_index += 6
	else :
		if len(noCheckedList) != 0 :
			tmp_index = noCheckedList.pop() + 5
		else :
			print('No')
			break
	if tmp_index == len(s):
		print('YES')
		break
	elif len(s) - tmp_index < 5 :
		if len(noCheckedList) != 0 :
			tmp_index = noCheckedList.pop() + 5
		else :
			print('No')
			break

Submission status: Wrong Answer

Solution code:
#9
S = input()
for i in range(0, len(S)//5+1):
    if S[-5:-1] == 'dream' or S[-5:-1] == 'erase':
        S = S[:-6]
    elif S[-6:-1] == 'eraser':
        S = S[:-7]
    elif S[-7:-1] == 'dreamer':
        S = S[:-8]
    else:
        break
print('YES' if len(S)==0 else 'NO')

Submission status: Wrong Answer

Solution code:
def checks(s) :
	ret = 'NO'
	if len(s) < 5 :
		return 'NO'
	elif( s[0] == 'd' ) :
		#dream
		if s[:5] == 'dream' :
			if len(s) != 5 :
				ret = checks(s[5:])
			else :
				return 'YES'
		#dreamer
		if ( len(s) > 6 ) and ( ret != 'YES' ) and s[:7] == 'dreamer' :
			if len(s) != 7 :
				ret = checks(s[7:])
			else :
				return 'YES'
	elif( s[0] == 'e' ) :
		#erase
		if s[:5] == 'erase' :
			if len(s) != 5 :
				ret = checks(s[5:])
			else :
				return 'YES'
		#eraser
		if ( len(s) > 5 ) and ( ret != 'YES' ) and s[:6] == 'eraser' :
			if len(s) != 6 :
				ret = checks(s[7:])
			else :
				return 'YES'
	return ret

S = input()

print(checks(S))

Submission status: Wrong Answer

Solution code:
#9
S = input()
for i in range(0, len(S)//5+1):
    if S[0:5] == 'dream' or S[0:5] == 'erase':
        S = S[5:]
    elif S[0:6] == 'eraser':
        S = S[6:]
    elif S[0:7] == 'dreamer':
        S = S[7:]
print('YES' if len(S)==0 else 'NO')

Submission status: Wrong Answer

Solution code:
#9
S = input()
for i in range(0, len(S)//5+1):
    if S[0:5] == 'dream' or S[0:5] == 'erase':
        S = S[5:]
    elif S[0:6] == 'eraser':
        S = S[6:]
    elif S[0:7] == 'dreamer':
        S = S[7:]
print('Yes' if len(S)==0 else 'No')

Submission status: Wrong Answer

Solution code:
#9
S = input()
while len(S)!=0:
    if S[0:5] == 'dream' or S[0:5] == 'erase':
        S = S[5:]
    elif S[0:6] == 'eraser':
        S = S[6:]
    elif S[0:7] == 'dreamer':
        S = S[7:]

print('Yes' if len(S)==0 else 'No')

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys

S = stdin.readline().rstrip()
T = ''

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

if len(S) < len('dream'):
    print('NO')
    sys.exit()

pos = 0
flag_dream = False
flag_erase = False

while pos < len(S):
    if S[pos:pos+len(data[0])] == data[0]:
        pos = pos + len(data[0])
        flag_dream = True
    elif S[pos:pos+len(data[1])] == data[1]:
        pos = pos + len(data[1])
        flag_erase = True
    elif S[pos:pos+len(data[2])] == data[2]:
        pos = pos + len(data[2])
    elif S[pos:pos+len(data[3])] == data[3]:
        pos = pos + len(data[3])
    elif flag_dream and S[pos:pos+len('er')] == 'er':
        pos = pos + len('er')
        flag_dream = False
        flag_erase = False
    elif flag_erase and S[pos:pos+len('r')] == 'r':
        pos = pos + len('er')
        flag_dream = False
        flag_erase = False
    else:
        print('NO')
        sys.exit()


print('YES')

Submission status: Wrong Answer

Solution code:
s = input()
dp = [0] * (len(s) + 1)
dp[0] = 1
words = ["dream","dreamer","erase","eraser"]
done = "No"
for i in range(len(s)):
    if dp[i] == 0:
        continue
    for w in words:
        if s[i:i+len(w)] == w:
            dp[i+len(w)] = 1
        
    if dp[len(s)] == 1:
        done = "Yes"


print(done)

Submission status: Wrong Answer

Solution code:
S=input()
while len(S) >=5:
	if S[-7:]=='dreamer':
		S=S[:-7]
	elif S[-6:] == 'eraser':
		S=S[:-6]
	elif S[-5:] == 'dream':
		S=S[:-5]
	elif S[-5:] == 'erase':
		S=S[:-5]
	else:
		print('No')
		break
if len(S)==0:
	print('YES')
if 1<=len(S)<=4:
	print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
S = input()
while len(S)>5:
  if S[-7:] == "dreamer":
    S = S[:-7]
  elif S[-6:] == "eraser":
    S = S[:-6]
  elif S[-5:] == "dream" or S[-5:] == "erase":
    S = S[:-5]
  else:
    print("No")
    sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
import re

s = input()
ptn = re.compile(r'maerd|remaerd|sare|resare')
tmp = s[::-1]

while(True):
  res = re.match(ptn , tmp)
  if res is None:
    break
  tmp = tmp.replace(res.group(),'',1)

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

Submission status: Wrong Answer

Solution code:
import re

s = input()
ptn = re.compile(r'maerd|remaerd|sare|resare')
tmp = s[::-1]

while(True):
  res = re.match(ptn , tmp)
  if res is None:
    print(tmp)
    break
  tmp = tmp.replace(res.group(),'',1)
  print(tmp)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

S = input()

S = S.replace("eraser", "")
S = S.replace("erase", "")
S = S.replace("dreamer", "")
S = S.replace("dream", "").strip()




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

Submission status: Wrong Answer

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

S = input()

S = S.replace("dreamer", "")
S = S.replace("dream", "")
S = S.replace("eraser", "")
S = S.replace("erase", "").strip()


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

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
def f(x,i):
  if x == 'm':
    if s[i:i+5] == 'maerd':
      return 5
    else:
      print('NO')
      exit()
  elif x == 'e':
    if s[i:i+5] == 'esare':
      return 5
    else:
      print('NO')
      exit()
  elif x == 'r': 
    if s[i:i+6] == 'resare':
      return 6
    elif s[i:i+7] == 'remaerd':
      return 7
    else:
      print('NO')
      exit()
  else:
    print('NO')
    exit()
cnt = 0
i = 0
while cnt != len(s):
  cnt += f(s[i],i)
  i += cnt
else:
  print('YES')

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
def f(x,i):
  if x == 'm':
    if s[i:i+5] == 'maerd':
      return 5
    else:
      print('NO')
      exit()
  elif x == 'e':
    if s[i:i+5] == 'esare':
      return 5
    else:
      print('NO')
      exit()
  elif x == 'r': 
    if s[i:i+6] == 'resare':
      return 6
    elif s[i:i+7] == 'remaerd':
      return 7
    else:
      print('NO')
      exit()
  else:
    print('NO')
    exit()
cnt = 0
i = 0
while cnt < len(s):
  cnt += f(s[i],i)
  i += cnt
else:
  print('YES')

Submission status: Wrong Answer

Solution code:
s = input()
s_r_l = list(reversed(s))
s_r = ''.join(list(s_r_l))
# print(s_r)
t = str()
d = ['dream','dreamer','erase','eraser']
d_r = []
for i in d:
    i_s_l = list(reversed(i))
    i_s = ''.join(list(i_s_l))
    d_r.append(i_s)
# print(d_r)
while len(s_r)>0:
    judge = [s_r.endswith(i) for i in d_r]
    if any(judge):
        target = d_r[judge.index(True)]
        # print(target)
        s_r = s_r[len(target):]
        if len(s_r) == 0:
            print("YES")
    else:
        print("NO")
        break

Submission status: Wrong Answer

Solution code:
s = input()

while 1:
    for x in ('dream', 'dreamer', 'erase', 'eraser'):
        if s.endswith(x):
            s = s[:-len(x)]
            break
    else:
        print('NO')
        break
    if not s:
        print('YES')