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: Accepted

Solution code:
s = input()[::-1]
ls = [word[::-1] for word in ["dream", "dreamer", "erase", "eraser"]]
i = 0
while s:
    word = ls[i]
    if s.find(word) == 0:
        s = s[len(word):]
        i = 0
    else:
        i += 1
        if i > 3:
            print("NO")
            break
else:
    print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
string = input()
erase = 'erase'
eraser = 'eraser'
dream = 'dream'
dreamer = 'dreamer'
er = 'er'
a = 'a'
r = 'r'
while True:
    if string[:5] == dream:
        if string[5:7] == er:
            if string[7:8] == a:
                string = string[5:]
            else:
                string = string[7:]
        else:
            string = string[5:]
    elif string[:5] == erase:
        if string[5:6] == r:
            if string[6:7] == a:
                string = string[5:]
            else:
                string = string[6:]
        else:
            string = string[5:]
    elif string == '':
        print('YES')
        break
    else:
        print('NO')
        break

Submission status: Accepted

Solution code:
def solve():
    S = input()
    ['dream', 'dreamer', 'erase', 'eraser']
    r_S = S[::-1]
    while(len(r_S) > 0):
        if r_S[:7] == 'dreamer'[::-1]:
            r_S = r_S[7:]
        elif r_S[:6] == 'eraser'[::-1]:
            r_S = r_S[6:]
        elif r_S[:5] == 'dream'[::-1] or r_S[:5] == 'erase'[::-1]:
            r_S = r_S[5:]
        else:
            break
    if len(r_S) == 0:
        print('YES')
    else:
        print('NO')

solve()

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
while True:
  if S[0:5] == "maerd":
    S = S[5::]
  elif S[0:7] == "remaerd":
    S = S[7::]
  elif S[0:5] == "esare":
    S = S[5::]
  elif S[0:6] == "resare":
    S = S[6::]
  else:
    break
if len(S) == 0:
  print("YES")
else:
  print("NO")

Submission status: Accepted

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

words = [w[::-1] for w in ["dream", "dreamer", "erase", "eraser"]]
while True:
    removed = False
    for w in words:
        if S.startswith(w):
            S = S[len(w):]
            removed = True
            break
    if S == "":
        print("YES")
        break
    if not removed:
        print("NO")
        break

Submission status: Accepted

Solution code:
dp = [0] * 100005

S = raw_input()

dp[0] = 1

for i in range(len(S)):
    if dp[i] == 0:
        continue
    if i + 5 <= len(S) and S[i:i+5] == "dream":
        dp[i + 5] = 1
    if i + 7 <= len(S) and S[i:i+7] == "dreamer":
        dp[i + 7] = 1
    if i + 5 <= len(S) and S[i:i+5] == "erase":
        dp[i + 5] = 1
    if i + 6 <= len(S) and S[i:i+6] == "eraser":
        dp[i + 6] = 1

print "YES" if (dp[len(S)] == 1) else "NO"

Submission status: Accepted

Solution code:
def c_daydream(S):
    # Sを逆にしたものから文字列を除いていき、空文字にできるか？
    s = S[::-1]
    n = len(s)
    while True:
        if n == 0:
            return 'YES'
        elif n >= 5 and s[:5] == 'maerd':
            s = s[5:]
        elif n >= 7 and s[:7] == 'remaerd':
            s = s[7:]
        elif n >= 5 and s[:5] == 'esare':
            s = s[5:]
        elif n >= 6 and s[:6] == 'resare':
            s = s[6:]
        else:
            return 'NO'
        n = len(s)
    return None

S = input().strip()
print(c_daydream(S))

Submission status: Accepted

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

s = input()
s = s[::-1]
flag = 0
while(flag >= 0):
    flag = 0
    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:]
    elif(s == ''):
        print('YES')
        break
    else:
        flag = -1
        print('NO')

Submission status: Accepted

Solution code:
inline = list(input())
inline.reverse()

a1 = list("dream")
a2 = list("erase")
a3 = list("dreamer")
a4 = list("eraser")
a1.reverse()
a2.reverse()
a3.reverse()
a4.reverse()
i = 0
key = 0
while i < len(inline):
    if inline[i] == "m":
        if inline[i+1] == a1[1] and inline[i+2] == a1[2] and inline[i+3] == a1[3] and inline[i+4] == a1[4]:
            i+=5
        else:
            key += 1
            break
    elif inline[i] == "r" and inline[i+1] == "e":
        if inline[i+2] == a3[2] and inline[i+3] == a3[3] and inline[i+4] == a3[4] and inline[i+5] == a3[5] and inline[i+6] == a3[6]:
            i+=7
        elif inline[i+2] == a4[2] and inline[i+3] == a4[3] and inline[i+4] == a4[4] and inline[i+5] == a4[5]:
            i+= 6
        else :
            key += 1
            break

    elif inline[i] == "e":
        if inline[i+1] == a2[1] and inline[i+2] == a2[2] and inline[i+3] == a2[3] and inline[i+4] == a2[4]:
            i+=5
        else:
            key += 1
    else:
        key += 1
        break


if key >= 1:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
s=input()
w=["dream","dreamer","erase","eraser",""]
while True:
    

    if s[0:5]==w[0]:
        if s[5:7]=="er": #dremaerかeraserかerase
            if s[7]=="a": #erはeraseかeraserのer
                s=s[5:]
            else:
                s=s[7:]
        else:
            s=s[5:]

    elif s[0:5]==w[2]:
        if s[5]=="r": 
            s=s[6:]
        else:
            s=s[5:]
    else:
        print("NO")
        exit()

    if len(s)<=7:
        if s in w:
            print("YES")
            exit()
        else:
            print("NO")
            exit()
    
    #print(s)

Submission status: Accepted

Solution code:
s = input()
l = ['dream', 'dreamer', 'erase', 'eraser']
pos = 0
flg = True
can = False
while flg:
    flg = False
    for i in range(len(l)):
        st = len(l[i])+pos
        if st<=len(s):
            if s[st*(-1):len(s)-pos] == l[i]:
                pos += len(l[i])
                if pos == len(s):
                    can = True
                    break
                flg = True
if can == True:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s = input()

p = len(s)

while p > 0:
    if p >= 7 and s[(p - 7):p] == "dreamer":
        p -= 7
    elif p >= 6 and s[(p - 6):p] == "eraser":
        p -= 6
    elif p >= 5 and s[(p - 5):p] == "dream":
        p -= 5
    elif p >= 5 and s[(p - 5):p] == "erase":
        p -= 5
    else:
        p = -1
        break

if p == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]
while len(s)>4:
	if s[:5]=="maerd" or s[:5]=="esare": s=s[5:]
	elif s[:6]=="resare": s=s[6:]
	elif s[:7]=="remaerd": s=s[7:]
	else: break
if s=="": print("YES")
else: print("NO")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys

s = input()

a1 = "dream"
a2 = "dreamer"
a3 = "erase"
a4 = "eraser"

while True:
    if len(s) < 5:
        print("NO")
        sys.exit(0)
    elif len(s) == 5:
        if s in ["dream", "erase"]:
            print("YES")
        else:
            print("NO")
        sys.exit(0)
    elif len(s) == 6:
        if s == "eraser":
            print("YES")
        else:
            print("NO")
        sys.exit(0)
    elif len(s) == 7:
        if s == "dreamer":
            print("YES")
        else:
            print("NO")
        sys.exit(0)
    else:
        if s[:8] in ["dreamerd", "dreamere"]:
            s = s[7:]
        elif s[:6] in ["dreamd", "dreame", "erasee", "erased"]:
            s = s[5:]
        elif s[:7] in ["eraserd", "erasere"]:
            s = s[6:]
        else:
            print("NO")
            sys.exit(0)

Submission status: Accepted

Solution code:
s = input()
key = 1
i = 0

while i < len(s):
    if s[i:i+5] == "dream":
        if s[i+5:i+10] != "erase" and s[i+5:i+7] == "er":
            i += 7
        elif s[i+5:i+11] == "eraser":
            i += 11
        elif s[i+5:i+10] == "erase":
            i += 10
        else:
            i += 5
    elif s[i:i+6] == "eraser":
        i += 6
    elif s[i:i+5] == "erase":
        i += 5
    else:
        key = 0
        break

if key == 0:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
given = ["dreamer", "dream", "eraser", "erase"]
S = input()
while len(S) > 0:
    tmp = S
    for i in given:
        if S.endswith(i):
            S = S[::-1].replace(i[::-1], "", 1)[::-1]
            if len(S) == 0:
                print("YES")
                break
    if tmp == S:
        print("NO")
        break

Submission status: Accepted

Solution code:
given = [i[::-1] for i in ["dreamer", "eraser", "dream", "erase"]]
S = input()[::-1]
while S != "":
    tmp = S
    for i in given:
        if S.startswith(i):
            S = S.replace(i, "", 1)
            if len(S) == 0:
                print("YES")
                break
    if tmp == S:
        print("NO")
        break

Submission status: Accepted

Solution code:
s = input()
index = 0
result = 'YES'
while index < len(s):
    if s.startswith('dreameraser', index):
        index += 11
    elif s.startswith('dreamerase', index):
        index += 10
    elif s.startswith('dreamer', index):
        index += 7
    elif s.startswith('eraser', index):
        index += 6
    elif s.startswith('dream', index) or s.startswith('erase', index):
        index += 5
    else:
        result = 'NO'
        break
print(result)

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C


def initialize():
    count = 1
    extracted_s = ''
    return count, extracted_s


if __name__ == '__main__':
    s = input()
    words = ['dream', 'dreamer', 'erase', 'eraser']
    count, extracted_s = initialize()

    while len(s) != len(extracted_s):
        extracted_s = s[len(s) - count:]
        count += 1

        if extracted_s in words:
            s = s[:-len(extracted_s)]
            count, extracted_s = initialize()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
i = 0
while True:
	if i == len(s):
		print('YES')
		break
	if len(s) - i < 5:
		print('NO')
		break
	if s[i] == 'd':
		if s[i:i+5] != 'dream':
			print('NO')
			break
		if len(s) - i < 7:
			i += 5
			continue
		if s[i:i+7] != 'dreamer':
			i += 5
			continue
		if len(s) - i == 7 or s[i+7] != 'a':
			i += 7
			continue
		i += 5
		continue
	if s[i] == 'e':
		if s[i:i+5] != 'erase':
			print('NO')
			break
		if len(s) - i < 6:
			i += 5
			continue
		if s[i:i+6] != 'eraser':
			i += 5
			continue
		if len(s) - i == 6 or s[i+6] != 'a':
			i += 6
			continue
		i += 5
		continue
	print('NO')
	break

Submission status: Accepted

Solution code:
import re

wordlist = ['maerd', 'remaerd', 'esare', 'resare']

S = input()
Sr = ''
for i in range(len(S)):
    Sr += S[-(i+1)]

temp = ''
while Sr != '':
    if temp == Sr:
        print('NO')
        break
    temp = Sr
    
    for word in wordlist:
        if re.match(word, Sr):
            Sr = Sr[len(word):]
        
else:
    print('YES')

Submission status: Accepted

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

    s = len(S)
    while s > 4:
        e = s
        for i in (5, 6, 7):
            s = e - i
            if S[s:e] in ('dream', 'dreamer', 'erase', 'eraser'):
                break
        else:
            print('NO')
            return
    print('YES')

main()

Submission status: Accepted

Solution code:
s = input()
revs = s[::-1] + "Z"
i = 0

while(True):
 if revs[i:i+5]=="maerd": i+=5
 elif revs[i:i+7]=="remaerd": i+=7
 elif revs[i:i+5]=="esare": i+=5
 elif revs[i:i+6]=="resare": i+=6
 elif revs[i]=="Z":
  print("YES")
  break
 else:
  print("NO")
  break

Submission status: Accepted

Solution code:
s = input() + "ZZZZZZZZZZZZZ"

i = 0
ans = "NO"

while(True):

 if s[i:i+5]=="dream":
  if s[i+5]=="d" or s[i+5]=="Z" or s[i+5:i+8]=="era":
   i += 5
  elif s[i+5:i+8]=="erd" or s[i+5:i+8]=="ere" or s[i+5:i+8]=="erZ":
   i += 7
  else:
   break
 
 elif s[i:i+5]=="erase":
  if s[i+5]=="d" or s[i+5]=="e" or s[i+5]=="Z":
   i += 5
  elif s[i+5]=="r":
   i += 6
  else:
   break

 elif s[i]=="Z":
  ans = "YES"
  break

 else:
  break

print(ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

s = ns()
s = list(s)
flag = 1
while len(s) != 0:
    if s[-5:] == list("dream") or s[-5:] == list("erase"):
        del s[-5:]
        continue
    elif s[-6:] == list("eraser"):
        del s[-6:]
        continue
    elif s[-7:] == list("dreamer"):
        del s[-7:]
        continue
    else:
        flag = 0
        break

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

Submission status: Accepted

Solution code:
s = input()[::-1]
l = ["dream", "dreamer", "erase", "eraser"]
start = 0

for i in range(len(l)):
  l[i] = l[i][::-1]
  
def f():
  i = 0
  j = 0
  while j <= len(s):
    can = False
    for d in l:
      if s[i:i+len(d)] == d:
        i += len(d)
        can = True

    if i == len(s) and can == True:
      return 'YES'

    if can == False:
      return 'NO'
    j += 1

  return 'YES'

print(f())

Submission status: Accepted

Solution code:
S = input()
word5 = ['dream','erase']
word6 = ['dreamer',]

i = len(S)

while True:
	if i - 5 < 0:
		break

	if S[i-5:i] in word5:
		i -= 5

	elif i - 6 >= 0 and S[i-6:i] == 'eraser':
		i -= 6

	elif i - 7 >= 0 and S[i-7:i] == 'dreamer':
		i -= 7

	else:
		break

if i == 0:
	print("YES")
else:
	print("NO")

Submission status: Accepted

Solution code:
import sys
s=input()
while(s):
  if(s[-7:]=="dreamer"):
    s=s[:-7]
  elif(s[-5:]=="dream"):
    s=s[:-5]
  elif(s[-6:]=="eraser"):
    s=s[:-6]
  elif(s[-5:]=="erase"):
    s=s[:-5]
  else:
    print("NO")
    sys.exit()
print("YES")

Submission status: Accepted

Solution code:
import itertools
S = input()
L = ["dreamer", "eraser", "erase", "dream"]
R = list(itertools.permutations(L))
flag=0
for sg in R:
    T=S
    for i in range(4):
        T=T.replace(sg[i], "")
    if T=="":
        flag=1
        break
if flag==1:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()[::-1]
gogun = ["maerd","remaerd","esare","resare"]
while (len(s)>0):
    if len(s) >= 5 and (s[:5] == gogun[0] or s[:5] == gogun[2]):
        s = s[5:]
    elif len(s) >= 6 and s[:6] == gogun[3]:
        s = s[6:]
    elif len(s) >= 7 and s[:7] == gogun[1]:
        s = s[7:]
    else:
        print("NO")
        break
else:
    print("YES")

Submission status: Accepted

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

    i = 0
    f = True
    while i < len(s):
        if s[i:i+5] == "maerd":
            i += 5
        elif s[i:i+5] == "esare":
            i += 5
        elif s[i:i+6] == "resare":
            i += 6
        elif s[i:i+7] == "remaerd":
            i += 7
        else:
            f = False
            break

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


    

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

t=len(S)
for i in range(len(S)//4+1):
    if S[t-7:t]=="dreamer":
        t-=7
    elif S[t-6:t]=="eraser":
        t-=6
    elif S[t-5:t]=="dream" or S[t-5:t]=="erase":
        t-=5
    else:
        break

if t==0: print("YES")
else: print("NO")

Submission status: Accepted

Solution code:
def c_Daydream(S):
    # Sを逆にしたものから一覧にある文字列を逆にしたものを除いていき、空文字にできるか？
    s = S[::-1]
    while True:
        if len(s) >= 5 and s[0:5] == 'maerd':
            s = s[5:]
        elif len(s) >= 7 and s[0:7] == 'remaerd':
            s = s[7:]
        elif len(s) >= 5 and s[0:5] == 'esare':
            s = s[5:]
        elif len(s) >= 6 and s[0:6] == 'resare':
            s = s[6:]
        elif len(s) == 0:
            return 'YES'
        else:
            return 'NO'
S = input().strip()
print(c_Daydream(S))

Submission status: Accepted

Solution code:
S = input()

while True:
    if "dreameraser" in S:
        S = S.replace("dreameraser", "")
    elif "dreamerase" in S:
        S = S.replace("dreamerase", "")
    elif "dreamer" in S:
        S = S.replace("dreamer", "")
    elif "eraser" in S:
        S = S.replace("eraser", "")
    elif "dream" in S:
        S = S.replace("dream", "")
    elif "erase" in S:
        S = S.replace("erase", "")
    else:
        if S == "":
            print("YES")
        else:
            print("NO")
        break

Submission status: Accepted

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

    editorial(S)


def editorial(S):
    """
    それぞれがそれ以外のprefixにならなければ良い
    """
    l = len(S)
    idx = 0
    ok = True
    rs = S[::-1]
    r7 = "dreamer"[::-1]
    r6 = "eraser"[::-1]
    r5_1 = "dream"[::-1]
    r5_2 = "erase"[::-1]

    while idx < l:
        if rs[idx:idx + 7] == r7:
            idx += 7
        elif rs[idx:idx + 6] == r6:
            idx += 6
        elif rs[idx:idx + 5] == r5_1 or \
                rs[idx:idx + 5] == r5_2:
            idx += 5
        else:
            ok = False
            break

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


def RE(S):
    l = len(S)
    if _dfs(S, l, 0):
        print("YES")
    else:
        print("NO")


def _dfs(S, l, idx, pattern=0):
    # print(l, idx, pattern)
    if idx == l:
        return True

    if S[idx:idx + 7] == "dreamer":
        ok = _dfs(S, l, idx + 7, 1)
        if ok:
            return True
    if S[idx:idx + 6] == "eraser":
        ok = _dfs(S, l, idx + 6, 2)
        if ok:
            return True
    if S[idx:idx + 5] == "dream" or \
            S[idx:idx + 5] == "erase":
        ok = _dfs(S, l, idx + 5, 3)
        if ok:
            return True

    return False


def WA(S):
    l = len(S)
    idx = 0
    ok = True
    while idx < l:
        if S[idx:idx + 7] == "dreamer":
            idx += 7
        elif S[idx:idx + 6] == "eraser":
            idx += 6
        elif S[idx:idx + 5] == "dream" or \
                S[idx:idx + 5] == "erase":
            # 評価順番注意
            idx += 5
        else:
            ok = False
            break

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
val = input()
q = "dream"
w = "dreamer"
e = "erase"
r = "eraser"

while True:
    if val.count(q+r) != 0:
        val = val.replace(q+r, "")
    elif val.count(q+e) != 0:
        val = val.replace(q+e, "")
    elif val.count(w) != 0:
        val = val.replace(w, "")
    elif val.count(q) != 0:
        val = val.replace(q, "")
    elif val.count(r) != 0:
        val = val.replace(r, "")
    elif val.count(e) != 0:
        val = val.replace(e, "")
    else:
        break
print("YES" if len(val) == 0 else "NO")

Submission status: Accepted

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

Submission status: Accepted

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

V=set()
V.add(0)

cnt=0
while cnt<len(S):
	tmp=set()
	for i in V:
		for j in judge:
			if S[i:i+7].find(j)==0:
				tmp.add(i+len(j))
				if i+len(j)==len(S):
					print "YES"
					sys.exit()
	V=tmp
	cnt+=1
else:
	print "NO"

Submission status: Accepted

Solution code:
def solve():
    while 1:
        try:
            s = list(input())
            s.reverse()
            s = "".join(s)
            if len(s) < 5:
                raise EndLoop

            l = 0
            r = 5
            while r <= len(s):
                if s[l:r] == "maerd" or s[l:r] == "esare":
                    l += 5
                    r += 5
                elif s[l:r] == "remae":
                    if s[l:r + 2] == "remaerd":
                        l += 7
                        r += 7
                    else:
                        raise EndLoop
                elif s[l:r] == "resar":
                    if s[l:r + 1] == "resare":
                        l += 6
                        r += 6
                    else:
                        raise EndLoop
                else:
                    raise EndLoop

            print("YES")
            break
        except:
            print("NO")
            break


solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
W = ['dream', 'dreamer', 'erase', 'eraser']
for n in range(4):
    W[n] = W[n][::-1]
check = 0
i = 0
while i < len(S):
    check = 0
    for w in W:
        if w in S[i:i+len(w)]:
            i += len(w)
            check = 1
    if check is 0:
        break
if check is 1:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

# sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def solve(s):
    words = ['dream', 'dreamer', 'erase', 'eraser']
    n = len(s)
    m = n
    while m > 0:
        found = False
        for w in words:
            stop = m
            start = m - len(w)
            if start >= 0:
                if s[start:stop] == w:
                    m = start
                    found = True
                    break
        if not found:
            return False
    return True


def main():
    s = read_str()
    res = solve(s)
    if res:
        print('YES')
    else:
        print('NO')


main()

Submission status: Accepted

Solution code:
s=['eraser','erase','dreamer','dream']

main=input()

prevl=len(main)

while True:
    for ele in s:
        main=main.replace(ele,'')
    if len(main)==prevl:
        break
    prevl=len(main)
if main=='':
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input().replace("dream","&").replace("erase","%").replace("&er","").replace("%r","").replace("&","").replace("%","")
if S:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
S = input().replace("dream","&").replace("erase","%").replace("&er","").replace("%r","").replace("&","").replace("%","")
if S:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
import sys

S = input()

while S:
    prefix = S[0:5]
    if prefix == 'dream':
        if S[5:7] == 'er':
            if len(S) >= 8 and S[7] == 'a':
                S = S[5:]
            else:
                S = S[7:]
        else:
            S = S[5:]
    elif prefix == 'erase':
        if len(S) >= 6 and S[5] == 'r':
            S = S[6:]
        else:
            S = S[5:]
    else:
        print('NO')
        sys.exit(0)
    # print(S)
print('YES')

Submission status: Accepted

Solution code:
s = input();

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

while(len(s) > 4):
    if s[-5:] == words[0]:
        s = s[:-5]
    elif s[-7:] == words[1]:
        s = s[:-7]
    elif s[-5:] == words[2]:
        s = s[:-5]
    elif s[-6:] == words[3]:
        s = s[:-6]
    else:
        break

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

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    S = input()
    while len(S) != 0:
        change = False
        for s in ["dream", "dreamer", "erase", "eraser"]:
            if S.endswith(s):
                S = S[:-len(s)]
                change = True
                break
        if not change:
            break

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
s=0
S=str(input())
while len(S)>=0:
  if s==len(S):
    print("YES")
    sys.exit()
  if S[s:s+5]=="dream":
    if len(S)==s+5:
      print("YES")
      sys.exit()
    elif S[s+5]=="d" or S[s+5:s+8]=="era":
      s+=5
    elif S[s+5:s+8]=="erd" or S[s+5:s+8]=="ere":
      s+=7
    elif S[s+5:s+7]=="er" and len(S)==s+7:
      print("YES")
      sys.exit()
    else: 
      print("NO")
      sys.exit()
  elif S[s:s+5]=="erase":
    if len(S)==s+5:
      print("YES")
      sys.exit()
    elif S[s+5]=="d" or S[s+5]=="e":
      s+=5
    elif S[s+5]=="r":
      s+=6
    else: 
      print("NO")
      sys.exit()
  else: 
    print("NO")
    sys.exit()

Submission status: Accepted

Solution code:
ch = input()
ch = ch[::-1]
flag = 1

while flag>0 and len(ch)>0:
    if ch.find('maerd')==0 or ch.find('esare')==0:#chの0番目にあった
        ch = ch[5:]
    elif ch.find('remaerd')==0:
        ch = ch[7:]
    elif ch.find('resare')==0:
        ch = ch[6:]
    else:
        flag = -1
if flag<0:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
s = raw_input()

while len(s) > 0:
  if s.startswith('eraser'):
    s = s[6:]
  elif s.startswith('erase'):
    s = s[5:]
  elif s.startswith('dreamere') or s.startswith('dreamerd') or s == 'dreamer':
    s = s[7:]
  elif s.startswith('dream'):
    s = s[5:]
  else:
    print 'NO'
    break
else:
  print 'YES'

Submission status: Accepted

Solution code:
import sys
S = input()
S = S[::-1]
f = 1

while f > 0 and len(S)>0:
    if S.find('maerd') ==0 or S.find('esare') == 0:
        S = S[5:]
    elif S.find('remaerd') == 0:
        S = S[7:]
    elif S.find('resare') == 0:
        S = S[6:]
    else:
        f = -1

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

Submission status: Accepted

Solution code:
S = raw_input()
i = len(S)
while i >= 0:
    hit = False
    for w in ["dreamer", "eraser", "dream", "erase"]:
        if S[i-len(w):i] == w:
            i -= len(w)
            hit = True
            break
    if not hit:
        break
print "YES" if (i == 0) else "NO"

Submission status: Accepted

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

s = raw_input()
t = ''

front = 0
rear = 7
while (s != t):
    if('dreamer' in s[front:rear]):
        if('eraser' in s[front:rear+4]):
            t += s[front:rear+4]
            front = rear + 4
            rear = front + 7
        elif('erase' in s[front:rear+3]):
            t += s[front:rear+3]
            front = rear + 3
            rear = front + 7
        else:
            t += s[front:rear]
            front = rear
            rear = front + 7
    elif('eraser' in s[front:rear]):
        t += s[front:rear-1]
        front = rear - 1
        rear = front + 7
    elif('dream' in s[front:rear]):
        t += s[front:rear-2]
        front = rear - 2
        rear = front + 7
    elif('erase' in s[front:rear]):
        t += s[front:rear-2]
        front = rear - 2
        rear = front + 7
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
s = input()

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

while len(s)>4:
    if s[-5:] == words[0]:
        s = s[:-5]
        continue
    elif s[-7:] == words[1]:
        s = s[:-7]
        continue
    elif s[-5:] == words[2]:
        s = s[:-5]
        continue
    elif s[-6:] == words[3]:
        s = s[:-6]
        continue
    else:
        break

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

Submission status: Accepted

Solution code:
s = input()

# t = ['dream', 'dreamer', 'erase', 'eraser']

s = s[::-1]
# for i in range(4):
#     t[i] = t[i][::-1]

# print(s,t)

tmp = s

while tmp != '':
    d = tmp[:5] == 'maerd'
    dr = tmp[:7] == 'remaerd'
    e = tmp[:5] == 'esare'
    er = tmp[:6] == 'resare'
    # print(tmp[:5])
    # print(d,dr,e,er)

    if d:
        tmp = tmp[5:]
    elif e:
        tmp = tmp[5:]
    elif dr:
        tmp = tmp[7:]
    elif er:
        tmp = tmp[6:]
    else:
        print('NO')
        break

if tmp == '':
    print('YES')

Submission status: Accepted

Solution code:
a = ["eraser", "erase", "dreamer", "dream"]
s = input()
for i in range(4):
    s = s.replace(a[i], "")
if s == "":
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = str(input())

DREAM   = "dream"
DREAMER = "dreamer"
ERASE   = "erase"
ERASER  = "eraser"

pre = ""
while len(s) > 0 and pre != s:
    pre = s[:]
    if s[0] == "d":
        if len(s) <= 5:
            s = s.replace(DREAM, "", 1)
        elif s[5] != "e":
            s = s.replace(DREAM, "", 1)
        else:
            if s.find(ERASE) == len(DREAM):
                s = s.replace(DREAM, "", 1)
            else:
                s = s.replace(DREAMER, "", 1)
    else:
        if s.find(ERASE) == s.find(ERASER):
            s = s.replace(ERASER, "", 1)
        else:
            s = s.replace(ERASE, "", 1)
#    print(s)
if len(s) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    S = input()
    while True:
        change = False
        for x in "dreamer", "eraser", "dream", "erase":
            if x == S[-len(x):]:
                S = S[:-len(x)]
                change = True
                break
        if not change:
            break

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


if __name__ == '__main__':
    main()