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 = list(input())
N = len(S)

def f(x):
    print(x)
    exit()

if N < 5:
    f("NO")
elif S[0] == "d":
    w = 1
elif S[0] == "e":
    w = -1
else:
    f("NO")

i = 0
while True:
    if w > 0:
        if S[i]+S[i+1]+S[i+2]+S[i+3]+S[i+4] == "dream":
            i += 5
            if i == N:
                f("YES")
            elif S[i] == "d":
                pass
            elif S[i] == "e":
                if i+1 <= N-1:
                    if S[i+1] == "r":
                        if i+1 == N-1:
                            f("YES")
                        elif S[i+2] == "a":
                            w *= -1
                        elif S[i+2] == "e":
                            i += 2
                            w *= -1
                        elif S[i+2] == "d":
                            pass
                        else:
                            f("NO")
                else:
                    f("NO")
            else:
                f("NO")
        else:
            f("NO")
    elif w < 0:
        if S[i]+S[i+1]+S[i+2]+S[i+3]+S[i+4] == "erase":
            i += 5
            if i == N:
                f("YES")
            if S[i] == "r":
                i += 1
                if i == N:
                    f("YES")
            elif S[i] == "d":
                w *= -1
            elif S[i] == "e":
                pass
            else:
                f("NO")
        else:
            f("NO")
    if i+4 > N-1:
        f("NO")

Submission status: Wrong Answer

Solution code:
s=input()
s=s[::-1]
#print(s[:5],s[:7])

for i in range(100000):
    if s[:5] == 'maerd' or s[:6] == 'esare':
        s = s[5:]
    if s[:6] == 'resare':
        s = s[6:]
    if s[:7] == 'remaerd':
        s = s[7:]

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

Submission status: Wrong Answer

Solution code:
s=input()
s=s[::-1]
#print(s[:5],s[:7])

for i in range(100000):
    if s[:5] == 'maerd' or s[:6] == 'esare':
        s = s[5:]
    if s[:6] == 'resare':
        s = s[6:]
    if s[:7] == 'remaerd':
        s = s[7:]

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

Submission status: Wrong Answer

Solution code:
s=input()
s=s[::-1]
print(s[:5],s[:7])

for i in range(100000):
    if s[:5] == 'maerd' or s[:6] == 'esare':
        s = s[5:]
    if s[:6] == 'resare':
        s = s[6:]
    if s[:7] == 'remaerd':
        s = s[7:]

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

Submission status: Wrong Answer

Solution code:
S = input()
 
# 前から順に消すと詰む
# 後ろから順に消すと一意に定まる
while True:
  if S[-5:] == 'erase': S = S[:-5]
  else:
    if S[-6:] == 'eraser': S = S[:-6]
    else:
      if S[-5:] == 'dream': S = S[:-5]
      else:
        if S[-7:] == 'dreamer': S = S[:-7]
        else: break

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

Submission status: Wrong Answer

Solution code:
S = input()
 
# 前から順に消すと詰む
# 後ろから順に消すと一意に定まる
while len(S) > 0:
  if S[-5:] == 'erase': S = S[:-5]
  else:
    if S[-6:] == 'eraser': S = S[:-6]
    else:
      if S[-5:] == 'dream': S = S[:-5]
      else:
        if S[-7:] == 'dreamer': S = S[:-7]
        else: break

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

Submission status: Wrong Answer

Solution code:
S = input()

# 前から順に消すと詰む
# 後ろから順に消すと一意に定まる
while True:
  if S[-5:] == 'erase': S = S[:-5]
  else:
    if S[-6:] == 'eraser': S = S[:-6]
    else:
      if S[-5:] == 'dream': S = S[:-5]
      else:
        if S[-7:] == 'dreamer': S = S[:-7]
        else: break

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

Submission status: Wrong Answer

Solution code:
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


S = LS2()
N = len(S)

i = 0
while i < N:
    if S[i] == 'd':
        if i+5 > N:
            print('NO')
            exit()
        if ''.join(S[i:i+5]) != 'dream':
            print('NO')
            exit()
        if i+5 == N:
            break
        if S[i+5] == 'd':
            i += 5
            continue
        elif S[i+5] == 'e':
            if i+6 == N or S[i+6] != 'r':
                print('NO')
                exit()
            if i+7 == N:
                break
            if S[i+7] == 'a':
                i += 5
                continue
            if S[i+7] == 'd':
                i += 7
                continue
            print('NO')
            exit()
    elif S[i] == 'e':
        if i+5 > N:
            print('NO')
            exit()
        if ''.join(S[i:i+5]) != 'erase':
            print('NO')
            exit()
        if i+5 == N:
            break
        if S[i+5] == 'd':
            i += 5
            continue
        if S[i+5] == 'r':
            i += 6
            continue
        print('NO')
        exit()
    else:
        print('NO')
        exit()

print('YES')

Submission status: Wrong Answer

Solution code:
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


S = LS2()
N = len(S)

i = 0
while i < N:
    if S[i] == 'd':
        if i+5 > N:
            print('NO')
            exit()
        if ''.join(S[i:i+5]) != 'dream':
            print('NO')
            exit()
        if i+5 == N:
            break
        if S[i+5] == 'd':
            i += 5
            continue
        elif S[i+5] == 'e':
            if i+6 == N or S[i+6] != 'r':
                print('NO')
                exit()
            if i+7 == N:
                break
            if S[i+7] == 'a':
                i += 5
                continue
            if S[i+7] == 'd':
                i += 7
                continue
            else:
                print('NO')
                exit()
    elif S[i] == 'e':
        if i+5 > N:
            print('NO')
            exit()
        if ''.join(S[i:i+5]) != 'erase':
            print('NO')
            exit()
        if i+5 == N:
            break
        if S[i+5] == 'd':
            i += 5
            continue
        if S[i+5] == 'r':
            i += 6
            continue
        else:
            print('NO')
            exit()
    else:
        print('NO')
        exit()

print('YES')

Submission status: Wrong Answer

Solution code:
def solve():
    S = input()
    i = 0
    while i < len(S):
        if S[i:i+5] not in ['dream', 'erase']:
            return 'NO'
        i += 5
        if S[i:i+6] == 'eraser':
            i += 6
        if S[i:i+5] == 'erase':
            i += 5
        if S[i:i+2] == 'er':
            i += 2
    return 'YES'

    
if __name__ == '__main__':
    ans = solve()
    print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
r = ''.join(list(reversed(s)))
flag = [0,0,0,0]
t = ['maerd', 'remaerd', 'esare', 'resare']
while len(r) >= 0:
    if r[0:5] == t[0]:
        r = r[5:]
        flag[0] +=1
    elif r[0:6] == t[1]:
        r = r[6:]
        flag[1] +=1
    elif r[0:5] == t[2]:
        r = r[5:]
        flag[2] +=1
    elif r[0:6] == t[3]:
        r = r[6:]
        flag[3] +=1
    elif len(r) == 0:
        print('YES')
        break
    else:
        print('NO')
        break

Submission status: Wrong Answer

Solution code:
s = str(input())
r = ''.join(list(reversed(s)))
flag = [0,0,0,0]
t = ['maerd', 'remaerd', 'esare', 'resare']
while len(r) >= 0:
    if r[0:5] == t[0]:
        r = r[5:]
        flag[0] +=1
    elif r[0:6] == t[1]:
        r = r[6:]
        flag[1] +=1
    elif r[0:5] == t[2]:
        r = r[5:]
        flag[2] +=1
    elif r[0:6] == t[3]:
        r = r[6:]
        flag[3] +=1
    elif len(r) == 0:
        print('YES')
        break
    else:
        print('NO')
        break
print(flag)

Submission status: Wrong Answer

Solution code:
S = list(input())
S.reverse()
S = ''.join(S)
st = ['maerd','remeard','esare','resare']
ans = 'YES'
while S != '':
    if S[0:5] in st:
        S = S[5:]
    elif S[0:4] in st:
        S = S[4:]
    elif S[0:6] in st:
        S = S[6:]
    else:
        ans = 'NO'
        break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

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

Submission status: Wrong Answer

Solution code:
s = input()

if s.replace("dreamer", "").replace("dream", "").replace("eraser", "").replace("eras", ""):
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
s = input()

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

Submission status: Wrong Answer

Solution code:
s=input()
q=1
p=0
while q == 1:
    q=0
    p=0
    r=0
    t=s[0:8]
    if "dreamera" in t:
        s=s[5:]
        p=1
        q=1
        r=1
    t=s[0:6]
    if "eraser" in t:
        s=s[6:]
        q=1
    t=s[0:5]
    if "erase" in t:
        s=s[5:]
        p=1
        q=1
    t=s[0:7]
    if "dreamer" in t:
        s=s[7:]
        q=1
        r=1
    t=s[0:5]
    if r==0 and "dream" in t:
        s=s[5:]
        q=1
if s == "":
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s=input()
q=1
p=0
while q == 1:
    q=0
    p=0
    r=0
    t=s[0:8]
    if "dreamera" in t:
        s=s[5:]
        p=1
        q=1
        r=1
    if q==0:
        t=s[0:5]
        if "erase" in t:
            s=s[5:]
            p=1
            q=1
    t=s[0:7]
    if "dreamer" in t:
        s=s[7:]
        q=1
        r=1
    t=s[0:6]
    if "eraser" in t:
        s=s[6:]
        q=1
    t=s[0:5]
    if r==0 and "dream" in t:
        s=s[5:]
        q=1
if s == "":
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
words = ['dream','dreamer', 'erase', 'eraser']
s = raw_input()
dp = [False for _ in range(len(s))]
i = 0
for j in range(len(s)):
	dp[j] = any([(dp[j - len(w) - 1] if j - len(w) -1 >= 0 else True) and s[j- len(w):j+1] == w  for w in words])

print 'YES' if dp[-1] else 'NO'

Submission status: Wrong Answer

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

dp = [False for _ in range(len(s))]
i = 0
for j in range(len(s)):
	dp[j] = any([s[j- len(w):j+1] == w for w in words])

print 'YES' if dp[-1] else 'NO'

Submission status: Wrong Answer

Solution code:
words = [w[::-1] for w in ['dream','dreamer', 'erase', 'eraser']]
s = raw_input()[::-1]
i = 0
while(i < len(s)):
	for w in words:
		if w == s[:len(w)]:
			i += len(w)
			break



print 'YES' if i == len(s) else 'NO'

Submission status: Wrong Answer

Solution code:
S=input()
def solve(query):
    while 1:
        for frag in ("erase","eraser","dream","dreamer"):
            if query.endswith(frag):
                query=query[:-len(frag)]
                break
        else:
            print("No")
            break

        if not query:
            print("Yes")
            break

solve(S)

Submission status: Wrong Answer

Solution code:
S=input()
def solve(query):
    while 1:
        if not query:
            print("Yes")
            break

        for frag in ("erase","eraser","dream","dreamer"):
            if query.endswith(frag):
                query=query[:-len(frag)]
                break
        else:
            print("No")
            break

solve(S)

Submission status: Wrong Answer

Solution code:
import re
S = input()
print("YES" if re.match("(dream|dreamer|erase|eraser)", S) else "NO")

Submission status: Wrong Answer

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

I = "dream dreamer erase eraser".split()
I2 = input()

if I2.replace(I[1], "").replace(I[0], "").replace(I[3], "").replace(I[2], "").strip() == "":
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
S = input()
words = ['dreamer','dream','eraser','erase']
i = 0
while i < len(S):
    update = False
    for w in words:
        if S[i:].startswith(w):
            i += len(w)
            update =True
            break
    if not update:
        break
print('YES' if i == len(S) else 'NO')

Submission status: Wrong Answer

Solution code:
S = input()
words = ['dream', 'dreamer', 'erase', 'eraser']
i = 0
while i < len(S):
    update = False
    for w in words:
        if S[i:].startswith(w):
            i += len(w)
            update =True
            break
    if not update:
        break
print('YES' if i == len(S) else 'NO')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import math
def main():
    s = input()
    lis = ["maerd", "remaerd", "esare", "resare"]
    s = s[::-1]

    i = 0
    while(i < len(s)-4):
        if(s[i:i+5] in lis):
            i+=5
        elif(i+7 < len(s) and s[i:i+7]=="remaerd"):
            i += 7
        elif(i+6<len(s) and s[i:i+6]=="resare"):
            i+=6
        else:
            print("NO")
            exit()
    print("YES")
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s,f=input()[::-1],-1
while f<0:
    if s:
        if s[:5]=='maerd':
            s=s[5:]
        elif s[:5]=='esare':
            s=s[5:]
        elif s[:6]=='resare':
            s=s[6:]
        elif s[:7]=='remaerd':
            s=s[7:]
        else:
            f=0
    else:
        f=1
print(['No','Yes'][f])

Submission status: Wrong Answer

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = input()
while len(S)>0:
    if S[-7:] == "deamer":
        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:
        break
print("NO" if len(S)>0 else "YES")

Submission status: Wrong Answer

Solution code:
S = input()
while len(S)>0:
    if S[-7:] == "deamer":
        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:
        break
print("YES" if len(S)==0 else "NO")

Submission status: Wrong Answer

Solution code:
s = input()

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

for i in list:
    s = s.replace(i, "")

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

Submission status: Wrong Answer

Solution code:
s=input()
k=["eraser","dreamer","erase","dream"]
c=0
for i in k:
  if i in s:
    s=s.replace(i,".")
s=list(set(s))
if len(s)==1:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
s=input()
f=0
l=['dream' ,'dreamer', 'erase','eraser']
while(f==0):
    if(s[:7] in l):
        s=s[7:]
    elif(s[:6] in l):
        s=s[6:]
    elif(s[:5] in l):
        s=s[5:]
    else:
        f=1
    
if(len(s)==0):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s=input()
f=0
l=['dream' ,'dreamer', 'erase','eraser']
while(f==0):
    if(s[:7] in l):
        s=s[7:]
    elif(s[:6] in l):
        s=s[6:]
    elif(s[:5] in l):
        s=s[5:]
    else:
        f=1
        break
if(len(s)==0):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
S = input()
S = S[::-1]
candidacies = ["dream", "dreamer", "erase", "eraser"]
candidacies = [c[::-1] for c in candidacies]

fi_flg = False
while fi_flg is False:
  if S[:7] in candidacies:
    S = S[7:]
  elif S[:6] in candidacies:
    S = S[6:]
  elif S[:5] in candidacies:
    S = S[:5]
  else:
    fi_flg = True

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

Submission status: Wrong Answer

Solution code:
S = input()
S = S[::-1]
candidacies = ["dream", "dreamer", "erase", "eraser"]
candidacies = [c[::-1] for c in candidacies]

fi_flg = False
while fi_flg is False:
  if S[:6] in candidacies:
    S = S[6:]
  elif S[:5] in candidacies:
    S = S[5:]
  else:
    fi_flg = True

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

Submission status: Wrong Answer

Solution code:
S = input()
strs = list(reversed(S))
rev_S = ''.join(strs)
while True:
  if len(rev_S)< 5:
    break
  elif rev_S[:6] == 'resare'or rev_S[:6] == 'remaerd':
    rev_S = rev_S[6:]
    continue
  elif rev_S[:5] == 'esare' or rev_S[:5] == 'maerd':
    rev_S = rev_S[5:]
    continue
  else:
    break

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

Submission status: Wrong Answer

Solution code:
S = input()
strs = list(reversed(S))
rev_S = ''.join(strs)
rev_S.replace('resare', '')
rev_S.replace('esare', '')
rev_S.replace('remaerd', '')
rev_S.replace('maerd', '')


if rev_S.replace == '':
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
S = input()
strs = list(reversed(S))
rev_S = ''.join(strs)
rev_S.replace('maerd', '')
rev_S.replace('remaerd', '')
rev_S.replace('esare', '')
rev_S.replace('resare', '')
if rev_S.replace == '':
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

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

	border = len(S)

	while True:
		if S[border - 5: border] == "dream":
			border -= 5
		elif S[border - 7: border] == "dreamer":
			border -= 7
		elif S[border - 5: border] == "erase":
			border -= 5
		elif S[border - 6: border] == "eraser":
			border -= 6
		else:
			break

	if border == 0:
		print("Yes")
	else:
		print("No")
 
 
if __name__ == "__main__":
  	main()

Submission status: Wrong Answer

Solution code:
S=input()
W=[0]*(len(S)+1)
W[0]=1
words=['dream','dreamer','erase','eraser' ]
for i in range(len(S)):
  if W[i]==0:
    continue
  for k in words:
    if S[i:i+len(k)]==k:
      W[i+len(k)]=1
if W[len(S)]==1:
  print("Yes")
  exit()
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s = ''.join(list(reversed(input())))

s = s.replace('resaremaerd', '')
s = s.replace('remaerd', '').replace('resare', '')
s = s.replace('maerd', '').replace('esare', '')
if len(s) == 0:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
t=''
tx = ['dream', 'erase', 'eraser', 'dreamer']
pos=0
while 1:
  if pos + 8 <= len(s):
    if t + 'dreamdre' == s[:pos+8] or t + 'dreamera' == s[:pos+8]:
      t += 'dream'
      pos += 5
    elif t + 'dreamerd' == s[:pos+8] or t + 'dreamere' == s[:pos+8]:
      t += 'dreamer'
      pos += 7
    elif t + 'erasedre' == s[:pos+8] or t + 'eraseera' == s[:pos+8]:
      t += 'erase'
      pos += 5
    elif t + 'eraserdr' == s[:pos+8] or t + 'eraserer' == s[:pos+8]:
      t += 'erase'
      pos += 5
    else:
      print('NO')
      break
  else:
    for x in tx:
      if t+x == s:
        print('YES')
        break
    else:
      print('NO')
    break

Submission status: Wrong Answer

Solution code:
S = input()
S_r = S[::-1]

Ss = ["maerd","remaerd","esare","resare"]
for s in Ss:
    S_r = S_r.replace(s,"") 

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

Submission status: Wrong Answer

Solution code:
import math
import sys
S=input()
S= S[::-1]
d=['dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
    s=d[i]
    s=s[::-1]
    d[i]=s
    k=0
for i in range(len(S)):
    if i<k:
        break
    #print(i)
    for j in range(4):
        if d[j]==S[i:i+len(d[j])]:
            #print(j,S[i:i+len(d[j])])
            k=k+len(d[j])
            break
        if j==3:
            print('NO')
            sys.exit()
print('YES')

Submission status: Wrong Answer

Solution code:
S =input()
ls_S = list(S)
ans = "Yes"

while len(ls_S) != 0:
  if "".join(ls_S[len(ls_S)-5:]) == "dream":
    ls_S = ls_S[:len(ls_S)-5]
  elif "".join(ls_S[len(ls_S)-5:]) == "erase":
    ls_S = ls_S[:len(ls_S)-5]
  elif "".join(ls_S[len(ls_S)-7:]) == "dreamer":
    ls_S = ls_S[:len(ls_S)-7] 
  elif "".join(ls_S[len(ls_S)-6:]) == "eraser":
    ls_S = ls_S[:len(ls_S)-6]
  else:
    ans = "No"
    break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
s = input()
t = s[::-1]
while len(t) != 0:
    if t[:5] == "maerd" or t[:5] == "esare":
        t = t[5:]
    elif t[:6] == "resare":
        t = t[6:]
    elif t[:7] == "remaerd":
        t = t[6:]
    else:
        print("NO")
        sys.exit()
print("YES")

Submission status: Wrong Answer

Solution code:
s = str(input())
dream = ['dream','dreamer']
erase = ['erase','eraser']
isOK = True
t = ''
while len(s)>0:
    #print(s,t)
    if s[:7] in dream:
        if s[7:]!='':
            if s[7:7+5] in erase or s[7:7+5] in dream:
                t += s[:7]
                s = s[7:]
            else:
                t += s[:5]
                s = s[5:]
        else:
            t += s[:7]
            s = s[7:]
    elif s[:6] in erase:
        if s[6:]!='':
            if s[6:6+5] in erase or s[6:6+5] in dream:
                t += s[:6]
                s = s[6:]
            else:
                t += s[:5]
                s = s[5:]
        else:
            t += s[:6]
            s = s[6:]
    elif s[:5] in dream or s[:5] in erase:
        t += s[:5]
        s = s[5:]
    else:
        isOK = False
        break
if isOK:
    print('YES')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = str(input())
dream = ['dream','dreamer']
erase = ['erase','eraser']
isOK = True
t = ''
nokori_s = s
while len(s)>0:
    #print(s,t)
    if s[:7] in dream:
        if s[7:]!='':
            if s[7:7+5] in erase or s[7:7+5] in dream:
                t += s[:7]
                s = s[7:]
            else:
                t += s[:5]
                s = s[5:]
        else:
            break
    elif s[:6] in erase:
        if s[6:]!='':
            if s[6:6+5] in erase or s[6:6+5] in dream:
                t += s[:6]
                s = s[6:]
            else:
                t += s[:5]
                s = s[5:]
        else:
            break
    elif s[:5] in dream or s[:5] in erase:
        t += s[:5]
        s = s[5:]
    else:
        isOK = False
        break
if isOK:
    print('YES')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = input()

while len(s) >= 5:
    if len(s) >= 5 and s[-5:] == 'dream':
        s = s[:-5]

    elif len(s) >= 7 and s[-7:] == 'dreamer':
        s = s[:-7]

    elif len(s) >= 5 and s[-5:] == 'erase':
        s = s[:-5]

    elif len(s) >= 6 and s[-6:] == 'eraser':
        s = s[:-6]

    else:
        break

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50

def dfs(seq):
    if seq in ['dreamer', 'dream', 'erase', 'eraser']:
        return True

    if seq[:7] == 'dreamer':
        for i in [5, 7]:
            if dfs(seq[i:]):
                return True
            else:
                return False
    elif seq[:5] == 'dream':
        if dfs(seq[5:]):
            return True
        else:
            return False
    elif seq[:6] == 'eraser':
        for i in [5,6]:
            if dfs(seq[i:]):
                return True
            else:
                return False
    elif seq[:5] == 'erase':
        if dfs(seq[5:]):
            return True
        else:
            return False
    else:
        return False


def run():
    S = input()
    if dfs(S):
        print('YES')
    else:
        print('NO')


if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
s=input()

s=s.replace('dreamerase','')
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:
S = input()

idx = 0
while True:
    if S[idx:idx+5] == 'dream':
        idx += 5
    elif S[idx:idx+6] == 'eraser':
        idx += 6
    elif S[idx:idx+5] == 'erase':
        idx += 5
    elif S[idx:idx+7] == 'dreamer':
        idx += 7
    else:
        print('NO')
        break

    if idx == len(S):
        print('YES')
        break

Submission status: Wrong Answer

Solution code:
s=input()
num=0
ans=0
num2=len(s)
d=list("dreamer")
e=list("eraser")
for i in range(num2):
    if num==num2:
        ans=1
        break
    if num+3>=num2:
        break
    if s[num]=="d":
        for j in range(5):
            if s[num]!=d[j]:
                ans=2
                break
            else:
                num+=1
        if ans==2:
            ans=0
            break
        if num==num2:
            ans=1
            break
        if num2-num>=6:
            if s[num+2]=="e":
                for j in range(5,7):
                    if s[num]!=d[j]:
                        ans=2
                        break
                    else:
                        num+=1
            elif s[num+2]=="d":
                for j in range(5,7):
                    if s[num]!=d[j]:
                        ans=2
                        break
                    else:
                        num+=1
        else:
            for j in range(5,7):
                if s[num]!=d[j]:
                    ans=2
                    break
                else:
                    num+=1
        if ans==2:
            ans=0
            break
    elif s[num]=="e":
        for j in range(5):
            if s[num]!=e[j]:
                ans=2
                break
            else:
                num+=1
        if ans==2:
            ans=0
            break
        if num==num2:
            ans=1
            break
        if num+1==num2:
            if s[-1]=="r":
                ans=1
            break
        if num2-num>=5:
            if s[num+1]=="d" or s[num+1]=="e":
                for j in range(5,6):
                    if s[num]!=e[j]:
                        ans=2
                        break
                    else:
                        num+=1
        else:
            for j in range(5,6):
                if s[num]!=e[j]:
                    ans=2
                    break
                else:
                    num+=1
        if ans==2:
            ans=0
            break
    else:
        break
if ans==0:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
s=input()
num=0
ans=0
num2=len(s)
d=list("dreamer")
e=list("eraser")
for i in range(num2):
    if num==num2:
        ans=1
        break
    if num+4>=num2:
        break
    if s[num]=="d":
        for j in range(5):
            if s[num]!=d[j]:
                ans=2
                break
            else:
                num+=1
        if ans==2:
            ans=0
            break
        if num==num2:
            ans=1
            break
        if num2-num>=6:
            if s[num+2]=="e":
                for j in range(5,7):
                    if s[num]!=d[j]:
                        ans=2
                        break
                    else:
                        num+=1
            elif s[num+2]=="d":
                for j in range(5,7):
                    if s[num]!=d[j]:
                        ans=2
                        break
                    else:
                        num+=1
        else:
            for j in range(5,7):
                if s[num]!=d[j]:
                    ans=2
                    break
                else:
                    num+=1
        if ans==2:
            ans=0
            break
    elif s[num]=="e":
        for j in range(5):
            if s[num]!=e[j]:
                ans=2
                break
            else:
                num+=1
        if ans==2:
            ans=0
            break
        if num==num2:
            ans=1
            break
        if num+1==num2:
            if s[-1]=="r":
                ans=1
            break
        if num2-num>=5:
            if s[num+1]=="d" or s[num+1]=="e":
                for j in range(5,6):
                    if s[num]!=e[j]:
                        ans=2
                        break
                    else:
                        num+=1
        else:
            for j in range(5,6):
                if s[num]!=e[j]:
                    ans=2
                    break
                else:
                    num+=1
        if ans==2:
            ans=0
            break
    else:
        break
if ans==0:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
s=input()
num=0
ans=0
num2=len(s)
d=list("dreamer")
e=list("eraser")
for i in range(num2):
    if num==num2:
        ans=1
        break
    if num+4>=num2:
        break
    if s[num]=="d":
        for j in range(5):
            if s[num]!=d[j]:
                ans=2
                break
            else:
                num+=1
        if ans==2:
            ans=0
            break
        if num==num2:
            ans=1
            break
        if num+1==num2:
            break
        if num2-num>=6:
            if s[num+2]=="e":
                for j in range(5,7):
                    if s[num]!=d[j]:
                        ans=2
                        break
                    else:
                        num+=1
        else:
            for j in range(5,7):
                if s[num]!=d[j]:
                    ans=2
                    break
                else:
                    num+=1
        if ans==2:
            ans=0
            break
    elif s[num]=="e":
        for j in range(5):
            if s[num]!=e[j]:
                ans=2
                break
            else:
                num+=1
        if ans==2:
            ans=0
            break
        if num==num2:
            ans=1
            break
        if num+1==num2:
            if s[-1]=="r":
                ans=1
            break
        if num2-num>=5:
            if s[num+1]=="d":
                for j in range(5,6):
                    if s[num]!=e[j]:
                        ans=2
                        break
                    else:
                        num+=1
        else:
            for j in range(5,6):
                if s[num]!=e[j]:
                    ans=2
                    break
                else:
                    num+=1
        if ans==2:
            ans=0
            break
    else:
        break
if ans==0:
    print("NO")
else:
    print("YES")