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:
s=input()
s=s.replace('dreamer','#')
s=s.replace('dream','#')
s=s.replace('eraser','#')
s=s.replace('erase','#')
f=0
for i in s:
    if(i!='#'):
        f=1
        break
if(f==0):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s=input()
l=['dream','dreamer','erase','eraser']
s=s.replace('dream','#')
s=s.replace('dreamer','#')
s=s.replace('erase','#')
s=s.replace('eraser','#')
f=0
for i in s:
    if(i!='#'):
        f=1
        break
if(f==0):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s=input()
l=['dream','dreamer','erase','eraser']
f=0
for i in range(4):
    for j in range(4):
        if(i!=j):
            x=l[i]+l[j]
            y=l[j]+l[i]
            if(x==s or y==s):
                print("YES")
                f=1
                break
    if(f==1):
        break
if(f==0):
    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','*')
f=1
for i in s:
    if i!='*':
        f=0
        break
if f:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s=input(str())
lst=["eraser","erase","dreamer","dream"]
for t in lst:
    s=s.replace(t,"")
if s=="":
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

Solution code:
s=input()[::-1]
t=['dream','dreamer','erase','eraser']
t=[t[0][::-1],t[1][::-1],t[2][::-1],t[3][::-1]]
flag=1
i=0
ans=['NO','YES']
while i<len(s) and flag:
  if s[i]=='r':
    if s[i+2]=='m':
      for j in range(6):
        if i+j>=len(s)-1:flag=0
        elif s[i+j]!=t[1][j]:flag=0
      i+=6
    else:
      for j in range(6):
        if i+j>=len(s)-1:flag=0
        elif s[i+j]!=t[3][j]:flag=0
      i+=6
  elif s[i]=='e':
    for j in range(5):
      if i+j>=len(s)-1:flag=0
      elif s[i+j]!=t[2][j]:flag=0
    i+=5
  else:
    for j in range(5):
      if i+j>=len(s)-1:flag=0
      elif s[i+j]!=t[0][j]:flag=0
    i+=5
print(ans[flag])

Submission status: Wrong Answer

Solution code:
s=input()[::-1]
t=['dream','dreamer','erase','eraser']
t=[t[0][::-1],t[1][::-1],t[2][::-1],t[3][::-1]]
flag=1
i=0
ans=['NO','YES']
while i<len(s) and flag:
  if s[i]=='r':
    if s[i+2]=='m':
      for j in range(6):
        if s[i+j]!=t[1][j]:flag=0
      i+=6
    else:
      for j in range(6):
        if s[i+j]!=t[3][j]:flag=0
      i+=6
  elif s[i]=='e':
    for j in range(5):
      if s[i+j]!=t[2][j]:flag=0
    i+=5
  else:
    for j in range(5):
      if s[i+j]!=t[0][j]:flag=0
    i+=5
print(ans[flag])

Submission status: Wrong Answer

Solution code:
from itertools import product, takewhile


def main():
    words = ["dreameraser", "dreamerase",
             "eraser", "erase",  "dreamer", "dream"]
    S = input()
    for word in words:
        S = S.replace(word, '')
    # print(S)
    if len(S) > 0:
        print("NO")
    else:
        print("YES")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

#n,*a = map(int,readline().split())

"""
a = "dream"[::-1]
b = "dreamer"[::-1]
c = "erase"[::-1]
d = "eraser"[::-1]
"""
s = [*input()]
a = [*"dream"]
b = [*"dreamer"]
c = [*"erase"]
d = [*"eraser"]


while True:
    if not s:
        print("YES")
        break
    elif s[-5:] == a:
        for _ in range(5): s.pop()
    elif s[-5:] == c:
        for _ in range(5): s.pop()
    elif s[-6:] == b:
        for _ in range(6): s.pop()
    elif s[-6:] == d:
        for _ in range(6): s.pop()
    else:
        print("NO")
        break

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

#n,*a = map(int,readline().split())

"""
a = "dream"[::-1]
b = "dreamer"[::-1]
c = "erase"[::-1]
d = "eraser"[::-1]
"""
s = [*input()]
a = [*"dream"]
b = [*"dreamer"]
c = [*"erase"]
d = [*"eraser"]


while True:
    if not s:
        print("Yes")
        break
    elif s[-5:] == a:
        for _ in range(5): s.pop()
    elif s[-5:] == c:
        for _ in range(5): s.pop()
    elif s[-6:] == b:
        for _ in range(6): s.pop()
    elif s[-6:] == d:
        for _ in range(6): s.pop()
    else:
        print("No")
        break

Submission status: Wrong Answer

Solution code:
s = input()
x = 0
a = s.count("dream")
b = s.count("dreamer")
c = s.count("erase")
d = s.count("eraser")
a2 = a-b
c2 = c-d
if a2*5+b*7+c2*5+d*6 == len(s):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
if not input().replace('eraser', '').replace('erase', '').replace('dream', '').replace('dreamer', ''):
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
ar = list(input())
while True:
    l = len(ar)
    if l == 0:
        print("YES")
        exit()
    if "".join(ar[l-5:l]) == 'dream' or "".join(ar[l-5:l]) == 'erase':
        del ar[l-5:l]
    elif "".join(ar[l-6:l]) == 'eraser':
        del ar[l-6:l]
    elif "".join(ar[l-5:l]) == 'dreamer':
        del ar[l-7:l]
    else:
        print("NO")
        exit()

Submission status: Wrong Answer

Solution code:
ar = list(input())
l = len(ar)
if l < 5:
    print('NO')
else:
    while True:
        if l == 0:
            print("YES")
            exit()
        if "".join(ar[l-5:l]) == 'dream' or "".join(ar[l-5:l]) == 'erase':
            l -= 5
        elif "".join(ar[l-6:l]) == 'eraser':
            l -= 6
        elif "".join(ar[l-5:l]) == 'dreamer':
            l -= 7
        else:
            print("NO")
            exit()

Submission status: Wrong Answer

Solution code:
s = input()
s = s[::-1]
hoge = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
j = 0
while i < len(s):
    ans = ''
    while j < len(s):
        ans += s[j]
        if len(ans) > 7:
            print('NO')
            #quit()
        if ans in hoge:
            break
        else:
            j += 1
    j += 1
    i = j
print('YES')

Submission status: Wrong Answer

Solution code:
s = input()
s = s[::-1]
hoge = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
j = 0
while i < len(s):
    ans = ''
    while j < len(s):
        ans += s[j]
        if len(ans) > 7:
            print('NO')
            quit()
        if ans in hoge:
            break
        else:
            j += 1
        j += 1
        i = j
print('YES')

Submission status: Wrong Answer

Solution code:
s = input()
s = s[::-1]
hoge = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
j = 0
while i < len(s):
    j += 1
    i = j
    ans = ''
    while j < len(s):
        ans += s[j]
        if len(ans) > 7:
            print('NO')
            quit()
        if ans in hoge:
            break
        else:
            j += 1
print('YES')

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
idx = 0
while idx < n:
    if idx+5 <= n and s[idx:idx+5] == 'dream':
        idx += 5
    elif s[idx:idx+4] == 'eras':
        idx += 4
    else:
        break
    if idx+2 <= n and s[idx:idx+2] == 'er' and (idx+2 == n or s[idx+2:idx+3] != 'a'):
        idx += 2
if idx == n:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

s=list(ss())
lens=len(s)
flag=True

s.reverse()

word = ("maerd","remaerd","esare","resare")

cnt=0

while cnt <lens:
    cnt_chk=cnt
    if "".join(s[cnt:cnt+5])==word[0]:
        cnt_chk+=5
    elif "".join(s[cnt:cnt+7])==word[1]:
        cnt_chk+=7
    elif "".join(s[cnt:cnt+5])==word[2]:
        cnt_chk+=5
    elif "".join(s[cnt:cnt+6])==word[3]:
        cnt_chk+=5
    if cnt==cnt_chk:
        print("NO")
        exit()
    else:
        cnt=cnt_chk
print("YES")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
S = input()[: -1]
dp = [0] * (len(S) + 1)
for i in range(len(S)):
  if i + 5 <= len(S):
    if S[i: i + 5] == "dream": dp[i + 5] = 1
    if S[i: i + 5] == "erase": dp[i + 5] = 1
  if i + 7 <= len(S):
    if S[i: i + 7] == "dreamer": dp[i + 7] = 1
  if i + 6 <= len(S):
    if S[i: i + 6] == "eraser": dp[i + 6] = 1
if dp[-1]: print("YES")
else: print("NO")

Submission status: Wrong Answer

Solution code:
S = input()
t = len(S)
L = [("dream", 5), ("dreamer", 7), ("erase", 5), ("eraser", 6)]
while t > 0:
    for w, l in L:
        if S.rfind(w) == t - l:
            S.rstrip(w)
            t -= l
            break
    else:
        print("NO")
        break
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
s = list(input())
s.reverse()
s = ''.join(map(str, s))
count = 0
word = ['maerd', 'remaerd', 'resare', 'esare']

while count <= len(s)-8:
  counttemp = count
  for i in range(4):
    w = word[i]
    if s[count:count+len(w)] == w:
      count += len(w)
  if counttemp == count:
    break
if s[count:] in word:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
def solve(S):
    N = len(S)
    i = 0
    while i < N:
        if N - i < 5:
            return False
        if S[i: i + 5] == "dream":
            if i + 5 < N and S[i + 5] == "r":
                i += 6
            else:
                i += 5
        elif S[i: i + 5] == "erase":
            if i + 5 < N and S[i + 5] == "r":
                i += 6
            else:
                i += 5
        else:
            return False
    return True

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

Submission status: Wrong Answer

Solution code:
#dream dreamer erase eraser
import sys

S = input()
index = len(S)
while index >= 7:
    five = S[index-5:index]
    six = S[index-6:index]
    seven = S[index-7:index]
    if five == "dream" or five == "erase":
        index -= 5
    elif six == "eraser":
        index -= 6
    elif seven == "dreamer":
        index -= 7
    else:
        print("NO")
        sys.exit()

last = S[:index]
#if last == "dream" or last == "erase" or last == "eraser" or last == "dreamer":
#    print("YES")
#else:
#    print("NO")

Submission status: Wrong Answer

Solution code:
#dream dreamer erase eraser
import sys

S = input()
index = len(S)
while index >= 7:
    five = S[index-5:index]
    six = S[index-6:index]
    seven = S[index-7:index]
    if five == "dream" or five == "erase":
        index -= 5
    elif six == "eraser":
        index -= 6
    elif seven == "dreamer":
        index -= 7
    else:
        print("NO")
        sys.exit()

last = S[:index]
if last == "dream" or last == "erase" or last == "eraser" or last == "dreamer":
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s=input()
import sys
while len(s)>0:
    if s[0]=='d':
        s=s[5:]
        if s[0:2]=='er' and s[0:5]!='erase':
            s=s[2:]
    elif s[0:6]=='eraser':
        s=s[6:]
    elif s[0:5]=='erase':
        s=s[5:]
    else:
        print('NO')
        sys.exit()
print('YES')

Submission status: Wrong Answer

Solution code:
S = input()
P=S.replace("dreamer","").replace("eraser","").replace("dream","").replace("erase","")
M=S.replace("dream","").replace("erase","").replace("dreamer","").replace("eraser","")
Q=S.replace("eraser","").replace("dreamer","").replace("dream","").replace("erase","")
R=S.replace("erase","").replace("dream","").replace("dreamer","").replace("eraser","")
if len(P)==0 or len(M)==0 or len(Q)==0 or len(R)==0:
      print("YES")
else:
      print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
while s != '':
    if s[:5] == 'dream' or s[:5] == 'erase':
        if len(s) > 5 and s[5] == 'r':
            s = s[6:]
        else:
            s = s[5:]
    else:
        print('NO')
        quit(0)

print('YES')

Submission status: Wrong Answer

Solution code:
def inpl():
    return list(map(int, input().split()))


S = input()

a = 0
length = len(S)
while (a < length):
    if a + 5 > length:
        print("NO")
        exit()
    elif a + 5 == length:
        if S[a:] == "dream" or S[a:] == "erase":
            break
        else:
            print("NO")
            exit()
    elif a + 6 == length:
        if S[a:] == "eraser":
            break
        else:
            print("NO")
            exit()
    elif a + 7 == length:
        if S[a:] == "dreamer":
            break
        else:
            print("NO")
            exit()

    if S[a + 5] == "d":
        if S[a:a + 5] in ["dream", "erase"]:
            a += 5
            continue
        else:
            print("NO")
            exit()
    elif S[a + 5] == "r":
        if S[a:a + 6] == "eraser":
            a += 6
            continue
        else:
            print("NO")
            exit()
    elif S[a + 5] == "e":
        if S[a + 7] == "a":
            if S[a:a + 5] == "dream":
                a += 5
                continue
            else:
                print("NO")
                exit()
        elif S[a + 7] in ["d", "e"]:
            if S[a:a + 7] == "dreamer":
                a += 7
                continue
            else:
                print("NO")
                exit()
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()

print("YES")

Submission status: Wrong Answer

Solution code:
s = input()
copys = s
s += 'r'
i = 0
t = ''
while i <= len(s)-5:
  if s[i:i+5] == 'dream':
    if s[i+5] == 'r':
      i += 6
      t += 'dreamer'
    else:
      i += 5
      t += 'dream'
  elif s[i:i+5] == 'erase':
    if s[i+5] == 'r':
      i += 6
      t += 'eraser'
    else:
      i += 5
      t += 'erase'
  else:
    break

if t == copys:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
S=input()
i=len(S)
ans="NO"
while(True):
    if(i==0):
        ans="YES"
        break
    if(i>=5 and S[i-5:i]=="dream"):
        i-=5
    elif(i >=5 and S[i-5:i]=="erase"):
        i-=5
    elif(i>=6 and S[i-6:i]=="eraser"):
        i-=6
    elif(i>=6 and S[i-6:i]=="dreamer"):
        i-=6
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
s = input()

l = len(s)


def dfs(i):
    #    print("->", s[i:])
    if i == l:
        print("YES")
        exit()
    if s[i:i+5] == "dream":
        if i+7 < l and s[i+5:i+7] == "er":
            dfs(i+7)
        dfs(i+5)
    elif s[i:i+5] == "erase":
        if i+5 < l and s[i+5] == "r":
            dfs(i+6)
        dfs(i+5)


dfs(0)
print("NO")

Submission status: Wrong Answer

Solution code:
s = input()

l = len(s)
i = 0
while True:
    if i == l:
        print("YES")
        exit()
    if l-i < 5:
        print("NO")
        exit()
    str = s[i:i+5]
    if str == "dream" or str == "erase":
        i += 5
    elif s[i:i+2] == "er":

        i += 2
    else:
        print("NO")
        exit()

Submission status: Wrong Answer

Solution code:
s = input()

l = len(s)
i = 0
while True:
    if i == l:
        print("YES")
        exit()
    str = s[i:i+5]
    if str == "dream" or str == "erase":
        i += 5
    elif s[i:i+2] == "er":
        i += 2
    else:
        print("NO")
        exit()

Submission status: Wrong Answer

Solution code:
s = input()

i = 0
while s:
    str = s[i:i+5]
    if str == "dream" or str == "erase":
        i += 5
    elif str[i:i+2] == "er":
        i += 2
    else:
        print("NO")
        exit()

ans = "YES"
print(ans)

Submission status: Wrong Answer

Solution code:
ans = "YES"
s = input()
while s:
    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:
        ans = "NO"
        break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = str(input())
words = ["dreamer","eraser","dream","erase"]
t = ""
i = 0
while i<len(s):
    if i<=len(s)-7 and s[i:i+7] == words[0]:
        t = t+words[0]
        i += 7
    elif i<=len(s)-6 and s[i:i+6] == words[1]:
        t = t+words[1]
        i += 6
    elif i<=len(s)-5 and s[i:i+5] in words:
        t = t+words[2] if s[i:i+5] == words[2] else t+words[3]
        i += 5
    elif i>1 and s[i-2:i+4]==words[1]:
        t = t+"aser"
        i += 4
    else:
        break
if s==t:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
s = str(input())
words = ["dreamer","eraser","dream","erase"]
t = ""
i = 0
while i<len(s):
    if i<=len(s)-7 and s[i:i+7] == words[0]:
        t = t+words[0]
        i += 7
    elif i<=len(s)-6 and s[i:i+6] == words[1]:
        t = t+words[1]
        i += 6
    elif i<=len(s)-5 and s[i:i+5] in words:
        t = t+words[2] if s[i:i+5] == words[2] else t+words[3]
        i += 5
    else:
        break
if i==len(s):
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
S = input()
rS = S[::-1]
keys = ['dream', 'dreamer', 'erase', 'eraser']
reversed_keys = [keys[i][::-1] for i in range(len(keys))]
i = 0
print(reversed_keys)
while i < len(rS):
    if rS[i:i+5] in reversed_keys:
        i += 5
    elif rS[i:i+6] in reversed_keys:
        i += 6
    elif rS[i:i+7] in reversed_keys:
        i += 7
    else:
        break
if i == len(rS):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
S = input()
rS = S[::-1]
keys = ['dream', 'dreamer', 'erase', 'eraser']
reversed_keys = [keys[i][::-1] for i in range(len(keys))]
i = 0
while i < len(rS):
    if rS[i:i+5] in reversed_keys:
        i += 5
    elif rS[i:i+7] in reversed_keys:
        i += 7
    else:
        break
if i == len(rS):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
S = input()
rS = S[::-1]
keys = ['dream', 'dreamer', 'erase', 'eraser']
reversed_keys = [keys[i][::-1] for i in range(len(keys))]
i = 0
while i <= len(rS):
    if rS[i:i+5] in reversed_keys:
        i += 5
    elif rS[i:i+7] in reversed_keys:
        i += 7
    else:
        break
if i == len(rS):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
S = input().replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')
if S == '':
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

s = input()[::-1]
w = [
    "dream"[::-1]
    ,"dramer"[::-1]
    ,"erase"[::-1]
    ,"eraser"[::-1]
]

while len(s)>0:
    if s.startswith(w[0]):
        s = s[len(w[0]):]
    elif s.startswith(w[1]):
        s = s[len(w[1]):]
    elif s.startswith(w[2]):
        s = s[len(w[2]):]
    elif s.startswith(w[3]):
        s = s[len(w[3]):]
    else:
        break

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()

keys = ('dreameraser', 'dreamererase', 'eraser', 'erase', 'dream', 'dreamer')

for key in keys:
    S = S.replace(key, '')

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

Submission status: Wrong Answer

Solution code:
S = input()

keys = ('dreameraser', 'dreamererase', 'erase', 'dream', 'dreamer', 'eraser')

for key in keys:
    S = S.replace(key, '')

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

Submission status: Wrong Answer

Solution code:
S = input()

keys = ('dreameraser', 'dreamererase', 'dreamer', 'eraser', 'erase', 'dream')

for key in keys:
    S = S.replace(key, '')

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

Submission status: Wrong Answer

Solution code:
S = input()

keys = ('dreamerase', 'dreamer', 'eraser', 'erase', 'dream')

for key in keys:
    S = S.replace(key, '')

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

Submission status: Wrong Answer

Solution code:
S = input()

keys = ('dreamer', 'eraser', 'dream', 'erase')

for key in keys:
    S = S.replace(key, '')

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

Submission status: Wrong Answer

Solution code:
s=input()
d=['dream','dreamer','erase','eraser']
while s:
    for m in d:
        if s.endswith(m):
            s=s.rstrip(m)
            break
    else:
        print('NO')
        exit()
print('YES')

Submission status: Wrong Answer

Solution code:
s=input()
d=['dream','dreamer','erase','eraser']
while s:
    for m in d:
        if s.endswith(m):
            s=s.strip(m)
            break
    else:
        print('NO')
        exit()
print('YES')

Submission status: Wrong Answer

Solution code:
import re

s = raw_input()
print ('Yes' if re.match('^((dream)|(dreamer)|(erase)|(eraser))*$',s) else 'No')

Submission status: Wrong Answer

Solution code:
import sys
DAYDREAM = ["dream", "dreamer", "erase", "eraser" ]
S = input()
#print("len(S):", len(S), file=sys.stderr)

ind = 0
res = True

while ind < len(S):
	ok = False
	for i in DAYDREAM:
		for j in DAYDREAM:
			curr = i + j
			
			if S[ind:ind+len(i+j)] == curr:
				ok = True
				ind += len(i)
				break
		if ok == True:
			break

	if ok == False:
		for i in DAYDREAM:
#			print("subS: ", S[-len(i):], file=sys.stderr)
			if S[-len(i):] == i:
				ok = True
				ind += len(i)
				break


	if ok == False:
#		print("ok is False, index: ", ind, file=sys.stderr)
		res = False
		break

print("YES" if res == True else "NO")

Submission status: Wrong Answer

Solution code:
import sys
DAYDREAM = ["dream", "dreamer", "erase", "eraser" ]
S = input()
#print("len(S):", len(S), file=sys.stderr)

ind = 0
res = True

while ind < len(S):
	ok = False
	for i in DAYDREAM:
		for j in DAYDREAM:
			curr = i + j
			
			if S[ind:ind+len(i+j)] == curr:
				ok = True
				ind += len(i)
				break
		if ok == True:
			break

	if ok == False:
		for i in DAYDREAM:
			if S[ind:ind+len(i)] == i:
				ok = True
				ind += len(i)
				break


	if ok == False:
#		print("ok is False, index: ", ind, file=sys.stderr)
		res = False
		break

print("YES" if res == True else "NO")

Submission status: Wrong Answer

Solution code:
S = raw_input().split()[0]
t = ['dreameraser','dreamerase','dreamer','dream','eraser','erase']
while len(S) > 0:
    for i in t:
        print S[-len(i):],i
        if S[-len(i):]==i:
            S = S[:-len(i)]
            break
        elif i == t[-1]:
            print "NO"
            exit()
print "YES"

Submission status: Wrong Answer

Solution code:
S = raw_input().split()[0]
t = ['dreamer','dream','eraser','erase']
while len(S) > 0:
    for i in t:
        print S[-len(i):],i
        if S[-len(i):]==i:
            S = S[:-len(i)]
            break
        elif i == t[-1]:
            print "NO"
            exit()
print "YES"

Submission status: Wrong Answer

Solution code:
S = raw_input()
t = ['dreamer','dream','eraser','erase']
while len(S) > 0:
    for i in t:
        if S[len(i):]==i:
            S = S[:len(i)]
            break
        elif i == t[-1]:
            print "NO"
            exit()
print "YES"

Submission status: Wrong Answer

Solution code:
s = input()
l = ['dreamer', 'eraser', 'erase', 'dream']
l = [a + b for a in l for b in l]
index = 0
ans = True
while index < len(s) and ans:
    flg = True
    print(s[index:])
    for a in l:
        if index + len(a) > len(s) or a != s[index:index+len(a)]:
            flg = False
        else:
            index += len(a)
            flg = True
            break
    ans = flg

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

Submission status: Wrong Answer

Solution code:
s = input()

five = ["dream", "erase"]
six = ["eraser"]
seven = ["dreamer"]

i = len(s) - 1

ans = False
while True:
  if i < 4:
    break
  elif i == 4:
    ans = s[:5] in five
    break
  elif i == 5:
    ans = s[:6] in six
    break
  elif i == 6:
    ans = s[:6] in seven
    break
  else:
    if s[i+1-5:i+1] in five:
      i -= 5
    elif s[i+1-6:i+1] in six:
      i -= 6
    elif s[i+1-7:i+1] in seven:
      i -= 7
    else:
      break

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

Submission status: Wrong Answer

Solution code:
s = input()

five = ["dream", "erase"]
six = ["dreamer", "eraser"]

i = len(s) - 1

ans = False
while True:
  if i < 4:
    break
  elif i == 4:
    ans = s[:5] in five
    break
  elif i == 5:
    ans = s[:6] in six
    break
  else:
    if s[i+1-5:i+1] in five:
      i -= 5
    elif s[i+1-6:i+1] in six:
      i -= 6
    else:
      break

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

Submission status: Wrong Answer

Solution code:
pattern = ["dream", "dreamer", "erase", "eraser"]
split_pattern = ["dream", "er", "ase", "r"]
grammer = {
        "ase": ["er"],
        "r": ["ase", "er"],
        "er": ["dream"],
        "dream": [],
        }
s = input()

splited = []
while s:
    for spl in split_pattern:
        if s.startswith(spl):
            splited.insert(0, spl)
            s = s[len(spl):]
            break
    else:
        print("NO")
        break

pred = []
for word in splited:
    if not pred:
        pred = grammer[word][:]
    else:
        if word != pred[0]:
            print("NO")
            break
        else:
            del pred[0]
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
import sys

def solve(s):
    sys.stderr.write(s)
    sys.stderr.write("\n")

    while(len(s) >= 1):
        if s == "":
            return True
        elif s.startswith("maerd"):
            s = s[5:]
        elif s.startswith("remaerd"):
            s = s[7:]
        elif s.startswith("esare"):
            s = s[5:]
        elif s.startswith("resare"):
            s = s[6:]
        else:
            return False



def main():
    line = sys.stdin.readline().rstrip()
    line_rev = line[::-1]

    if solve(line):
        print("YES")
    else:
        print("NO")

    return 0

if __name__ == '__main__':
    sys.exit(main())

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000)

def solve(s):
    if s == "":
        return True
    elif s.endswith("dream"):
        return solve(s[:-5])
    elif s.endswith("dreamer"):
        return solve(s[:-7])
    elif s.endswith("erase"):
        return solve(s[:-5])
    elif s.endswith("eraser"):
        return solve(s[:-6])
    else:
        return False
    return False


def main():
    line = sys.stdin.readline()

    if solve(line):
        print("YES")
    else:
        print("NO")

    return 0

if __name__ == '__main__':
    sys.exit(main())

Submission status: Wrong Answer

Solution code:
import sys

def solve(s):
    if s == "":
        return True
    elif s.endswith("dream"):
        return solve(s[:-5])
    elif s.endswith("dreamer"):
        return solve(s[:-7])
    elif s.endswith("erase"):
        return solve(s[:-5])
    elif s.endswith("eraser"):
        return solve(s[:-6])
    else:
        return False
    return False


def main():
    line = sys.stdin.readline()

    if solve(line):
        print("YES")
    else:
        print("NO")

    return 0

if __name__ == '__main__':
    sys.exit(main())

Submission status: Wrong Answer

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

while S:
    for w in W:
	if S.endswith(w):
             S = S[:-len(w)]
             break
    else:
        print "No"
        break
else:
    print "Yes"

Submission status: Wrong Answer

Solution code:
import sys

S = raw_input()
T = ''
words = ['dreamer', 'dream', 'eraser', 'erase']

while len(S):
    N = len(S)
    for word in words:
        if S[:len(word)] == word:
            S = S[len(word):]
            break
    if N == len(S):
        sys.stdout.write('NO')
        break
    if len(S) == 0:
        sys.stdout.write('YES')

Submission status: Wrong Answer

Solution code:
import sys
S = raw_input()
T = ''
words = ['dreamer', 'dream', 'eraser', 'erase']

while len(S):
    N = len(S)
    for word in words:
        if S[:len(word)] == word:
            S = S[len(word):]
            break
    if N == len(S):
        sys.stdout.write('NO')
        break
    if len(S) == 0:
        sys.stdout.write('NO')

Submission status: Wrong Answer

Solution code:
S = raw_input()
T = ''
words = ['dreamer', 'dream', 'eraser', 'erase']

while len(S):
    N = len(S)
    for word in words:
        if S[:len(word)] == word:
            S = S[len(word):]
            break
    if N == len(S):
        print 'NO'
        break
    if len(S) == 0:
        print 'YES'

Submission status: Wrong Answer

Solution code:
s = input().strip()
strings = "eraser erase dreamer dream ".split()
while 1:
  for string in strings:
    if s.startswith(string):
      s = s[len(string):]
      break
  else:
    break
print("NO" if s else "YES")

Submission status: Wrong Answer

Solution code:
s = input().strip()
strings = "eraser erase dreamer dream".split()
while 1:
  for string in strings:
    if s.startswith(string):
      s = s[len(string):]
  else:
    break
print("NO" if s else "YES")

Submission status: Wrong Answer

Solution code:
d = {'dream':5,'dreamer':7,'erase':5,'eraser':6}
st = input().strip()
cnt = 0
if st.find('dream')!=-1:
    cnt+=st.count('dream')*d['dream']
if st.find('dreamer')!=-1:
    cnt+=st.count('dreamer')*d['dreamer']
if st.find('erase')!=-1:
    cnt+=st.count('erase')*d['erase']
if st.find('eraser')!=-1:
    cnt+=st.count('eraser')*d['eraser']
print('YES' if cnt==len(st) else 'NO')