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:
def is_fit(str_list,chr_):
    while len(chr_) > 0:
        if   chr_[-7:] in t_list:
            chr_ = chr_[:-7]
        elif chr_[-6:] in t_list:
            chr_ = chr_[:-6]
        elif chr_[-5:] in t_list:
            chr_ = chr_[:-5]
        else:
            return "NO"
    return "YES"

s = input()
t_list = ["dream","dreamer","erase","eraser"]

print(is_fit(t_list,s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
t_list = ['dream','dreamer','erase','eraser']

flg = True
while len(s) > 0:
    if   s[-7:] in t_list:
        s = s[:-7]
    elif s[-6:] in t_list:
        s = s[:-6]
    elif s[-5:] in t_list:
        s = s[:-5]
    else:
        flg = False
        break

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

Submission status: Accepted

Solution code:
S = input()

S = S[::-1]

while len(S) > 0:
  if S[0:5] == "dream"[::-1]:
    S = S[5:]
    continue
  elif S[0:7] == "dreamer"[::-1]:
    S = S[7:]
    continue
  elif S[0:5] == "erase"[::-1]:
    S = S[5:]
    continue
  elif S[0:6] == "eraser"[::-1]:
    S = S[6:]
    continue
  else:
    print("NO")
    exit(0)

print("YES")

Submission status: Accepted

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

print('YES')

Submission status: Accepted

Solution code:
from sys import stdin

S = stdin.readline().rstrip()

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

ans = True
while len(S) > 0:

    # print(S)

    if S[len(S) - 7:] == lst[1]:
        S = S[:len(S) - 7]
    elif S[len(S) - 6:] == lst[3]:
        S = S[:len(S) - 6]
    elif S[len(S) - 5:] == lst[0] or S[len(S) - 5:] == lst[2]:
        S = S[:len(S) - 5]
    else:
        ans = False
        break

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

Submission status: Accepted

Solution code:
#encoding: utf-8
import os, sys
import math

def read_items_in_line(cast=int):
    return [cast(x) for x in sys.stdin.readline().strip(' \n').split(' ')]

items = ["dream", "dreamer", "erase", "eraser"]
rev_items = [x[::-1] for x in items]

S = read_items_in_line(cast=str)[0]
rev_S = S[::-1]

while(True):
    found = False
    for x in rev_items:
        # print((rev_S, x))
        if rev_S.startswith(x):
            rev_S = rev_S[len(x):]
            found = True
            break
    if not found:
        break

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

Submission status: Accepted

Solution code:
S = input()
T = ["dream", "dreamer", "erase", "eraser"]
def main():
    i = len(S)
    if i == 0:
        print("NO")
        return 0
    while True:
        if i == 0:
            break
        elif i < 5:
            print("NO")
            return 0
        elif S[i - 5:i] == T[0] or S[i - 5:i] == T[2]:
            i -= 5
        elif i < 6:
            print("NO")
            return 0
        elif S[i - 6:i] == T[3]:
            i -= 6
        elif i < 7:
            print("NO")
            return 0
        elif S[i - 7:i] == T[1]:
            i -= 7
        else:
            print("NO")
            return 0
    print("YES")
    return 0
main()

Submission status: Accepted

Solution code:
globals().update({"s": input()}) or ((lambda it: set(it.takewhile(lambda _: len([globals().update({"s": s[:-len(w)]}) for w in ["dreamer", "eraser", "dream", "erase"] if s.endswith(w)]), it.repeat(0))))(__import__("itertools")) or True) and print(s and "NO" or "YES")

Submission status: Accepted

Solution code:
print([list(it.takewhile(lambda x: any([globals()['s'].endswith(w) and (globals().__setitem__('s', globals()['s'][:-len(w)]) or True) or False for w in ["dreamer", "eraser", "dream", "erase"]]), it.repeat([]))) for it in [__import__("itertools")] for _ in [globals().__setitem__('s', input())]] and len(globals()['s']) == 0 and "YES" or "NO")

Submission status: Accepted

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

while len(S) > 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:]
    else:
        print('NO')
        break

if len(S) == 0:
    print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
ls = len(S)
memo = [False] * (ls+1)

memo[0] = True
for i in range(ls):
    if memo[i] == False:
        continue
    else:
        if S[i: i+5] == "dream" or S[i: i+5] == "erase":
            memo[i+5] = True
        if S[i: i+6] == "eraser":
            memo[i+6] = True
        if S[i: i+7] == "dreamer":
            memo[i+7] = True

if memo[ls]:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input()

result = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if len(result) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input()[::-1]
i = 0
ls = len(S)
accept = True

while ls > i:
    if S[i: i+5] == "maerd" or S[i: i+5] == "esare":
        i += 5
    elif S[i: i+6] == "resare":
        i += 6
    elif S[i: i+7] == "remaerd":
        i += 7
    else:
        accept = False
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = str(input())
S = S[::-1]
moji = ["maerd", "esare", "remaerd", "resare"]
i = 0
while i < len(S):
    answer = False
    for j in range(4):
        if S[i:i+len(moji[j])] == moji[j]:
            i += len(moji[j])
            answer = True
    if not answer:
        print("NO")
        break
if answer:
    print("YES")

Submission status: Accepted

Solution code:
import sys
s = input()
i = 1 
s1 = ''
while i <= len(s):
  s1 += s[-i]
  i += 1
s2 = s1
while s2 != '':
  if s2[0:5] == 'maerd':
    s2 = s2[5:]
  elif s2[0:7] == 'remaerd':
    s2 = s2[7:]
  elif s2[0:5] == 'esare':
    s2 = s2[5:]
  elif s2[0:6] == 'resare':
    s2 = s2[6:]
  else:
    print('NO')
    sys.exit()
print('YES')

Submission status: Accepted

Solution code:
s = input()
# curs = [index1, index2] 
curs = [0]
while True:
  next_curs = []
  break_ = False
  for c in curs:
    #print(c)
    if s[c:c+5] == 'dream':
      next_curs.append( c+5 )
      if len(s) == c+5:
        break_ = True
    if s[c:c+7] == 'dreamer':
      next_curs.append( c+7 )
      if len(s) == c+7:
        break_ = True
    if s[c:c+5] == 'erase':
      next_curs.append( c+5 )
      if len(s) == c+5:
        break_ = True
    if s[c:c+6] == 'eraser':
      next_curs.append( c+6 )
      if len(s) == c+6:
        break_ = True
  if next_curs == []:
    print('NO')
    break
  if break_: 
    print('YES')
    break
  curs = next_curs

Submission status: Accepted

Solution code:
a=list(input())
n=0
while n<len(a):
    oldn=n
    if a[n] == "e":
        if n+4<len(a) and a[n+1]=="r" and a[n+2]=="a" and a[n+3]=="s" and a[n+4]=="e":
            if n+5<len(a) and a[n+5]=="r":
                n=n+6
            else:
                n=n+5
    else:
        if a[n] == "d":
            if n+4<len(a) and a[n+1]=="r" and a[n+2]=="e" and a[n+3]=="a" and a[n+4]=="m":
                if n+6<len(a) and a[n+5]=="e" and a[n+6] == "r":
                    if n+7<len(a) and a[n+7]=="a":
                        n=n+5
                    else:
                        n=n+7
                else:
                    n=n+5
    if oldn == n:
        print("NO")
        break
else:
    print("YES")

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
words = ['dream','dreamer','erase','eraser']

i = 0
while i < len(S):
    for word in words:
        if S[i:].startswith(word[::-1]):
            i += len(word)
            break
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


# --------------------------------------------

dp = None


def main():
    S = input()

    while len(S) >= 5:
        if len(S) >= 7 and S[-7:] == "dreamer":
            S = S[:-7]
            continue

        if len(S) >= 6 and S[-6:] == "eraser":
            S = S[:-6]
            continue

        elif S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue

        else:
            break

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


main()

Submission status: Accepted

Solution code:
s = input()

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

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

Submission status: Accepted

Solution code:
given = ["dreamer", "dream", "eraser", "erase"]
S = input()
while len(S) > 0:
    judge = [S.endswith(i) for i in given]
    if any(judge):
        target = given[judge.index(True)]
        S = S[:-len(target)]
        if len(S) == 0:
            print("YES")
            break
    else:
        print("NO")
        break

Submission status: Accepted

Solution code:
import re
print("YES" if re.match('^(dream|dreamer|erase|eraser)*$', input()) else "NO")

Submission status: Accepted

Solution code:

def main():
    s = input()
    s = s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")

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

if __name__ == "__main__":
        main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

N = len(S)
T = ''
i = 0
while i < N:
    j = N - 1 - i
    if S[j] == 'm':
        T = 'dream' + T
        i += 5
    elif S[j] == 'e':
        T = 'erase' + T
        i += 5
    elif S[j - 2:j + 1] == 'mer':
        T = 'dreamer' + T
        i += 7
    elif S[j - 2:j + 1] == 'ser':
        T = 'eraser' + T
        i += 6
    else:
        break

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

Submission status: Accepted

Solution code:
s = input()
while True:
    temp = s
    s5 = temp[-5:]
    s6 = temp[-6:]
    s7 = temp[-7:]

    if (s5 == 'erase') | (s5 == 'dream'): 
        s = temp[:-5]
    elif s6 == 'eraser':
        s = temp[:-6]
    elif s7 == 'dreamer':
        s = temp[:-7]
    else:
        print('NO')
        exit()

    if s == '':
        print('YES')
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=str(input())
S=S.replace('eraser','1')
S=S.replace('erase','2')
S=S.replace('dreamer','3')
S=S.replace('dream','4')
S=S.replace('1','')
S=S.replace('2','')
S=S.replace('3','')
S=S.replace('4','')
if len(S)==0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input()
Sb = S[::-1]
daydreamers = ["maerd", "remaerd", "esare", "resare"]
judge = True

i = 0
while i < len(S) and judge:
    temp = ""
    isThere = False
    for j in range(7):
        temp += Sb[i+j]
        if temp in daydreamers:
            isThere = True
            i = i+j+1
            break
    if not isThere:
        judge = False

print("YES" if judge else "NO")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 15 12:43:21 2018
ABC049C
@author: maezawa
"""

s = input()
a = ('dream', 'dreamer', 'erase', 'eraser')

i = len(s)
ans = 'YES'
while True:
    if s[-5:] == a[0] or s[-5:] == a[2]:
        i -= 5
    elif i>=6 and s[-6:] == a[3]:
        i -= 6
    elif i>=7 and s[-7:] == a[1]:
        i -= 7
    else:
        ans = 'NO'
        break
    if i == 0:
        ans = 'YES'
        break
    elif i<5:
        ans = 'NO'
        break
    s = s[:i]

    #print(s)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 15 12:43:21 2018
ABC049C
@author: maezawa
"""

s = input()
a = ('dream', 'dreamer', 'erase', 'eraser')

i = len(s)
ans = 'YES'
while True:
    if s[-5:] == a[0] or s[-5:] == a[2]:
        i -= 5
        if i == 0:
            ans = 'YES'
            break
        elif i<5:
            ans = 'NO'
            break
        s = s[:i]
    elif i>=6 and s[-6:] == a[3]:
        i -= 6
        if i == 0:
            ans = 'YES'
            break
        elif i<5:
            ans = 'NO'
            break
        s = s[:i]
    elif i>=7 and s[-7:] == a[1]:
        i -= 7
        if i == 0:
            ans = 'YES'
            break
        elif i<5:
            ans = 'NO'
            break
        s = s[:i]
    else:
        ans = 'NO'
        break
    #print(s)
print(ans)

Submission status: Accepted

Solution code:
# ABC049C 白昼夢/Daydream
s = input()[::-1]
flag = True
pivot = 0
while pivot<len(s):
	if s[pivot]=='m':				# dream
		t = s[pivot:pivot+5]
		if t=='maerd':
			pivot += 5
		else:
			flag = False
			break
	elif s[pivot]=='e':			# erase
		t = s[pivot:pivot+5]
		if t=='esare':
			pivot += 5
		else:
			flag = False
			break
	elif s[pivot]=='r':
		if s[pivot+2]=='m':		# dreamer
			t = s[pivot:pivot+7]
			if t=='remaerd':
				pivot += 7
			else:
				flag = False
				break
		elif s[pivot+2]=='s':	# eraser
			t = s[pivot:pivot+6]
			if t=='resare':
				pivot += 6
			else:
				flag = False
				break
		else:
			flag = False
			break
	else:
		flag = False
		break
print('YES' if flag else 'NO')

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

S = input()
S1 = S2 = S

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

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

if S1 == '' or S2 == '':
	print('YES')
else:
	print('NO')

Submission status: Accepted

Solution code:
s  = input().replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    given = ["dreamer", "dream", "eraser", "erase"]
    S = input()
    judge = [S.endswith(i) for i in given]
    while len(S) > 0:
        judge = [S.endswith(i) for i in given]
        if any(judge):
            target = given[judge.index(True)]
            S = S[:-len(target)]
            if len(S) == 0:
                print("YES")
                break
        else:
            print("NO")
            break
            
            




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

while "" != s:
    result = False
    for word in ("dream", "dreamer", "erase", "eraser"):
        if s[-len(word):] == word:
            s = s[:-len(word)]
            result = True
            break
    if result == False:
        break
print("YES" if result else "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:
def test():
    s = input()
    divide = ["dream", "dreamer", "erase", "eraser"]
    dp = [0 for i in range(100010)]

    dp[0] = 1
    for i in range(len(dp)):
        if dp[len(s)] == 1:
            print('YES')
            return 0
        if dp[i] == 0:
            continue
        for d in divide:
            if s[i:i+len(d)] == d:
                dp[i+len(d)] = 1
    print('NO')

test()

Submission status: Accepted

Solution code:
text = input().replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if text == "":  # this is wrong: text == ""
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
text = input().replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if text:  # this is wrong: text == ""
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
s = input()

while s != "":
	is_match = False
	for word in ("dream", "dreamer", "erase", "eraser"):
		if s[-len(word):] == word:
			s = s[:-len(word)]
			is_match = True
	if is_match == False:
		print("NO")
		exit()
print("YES")

Submission status: Accepted

Solution code:
S = input()

five_letters = ["dream", "erase"]

found = False

while True:
    if len(S) == 0:
        found = True
        break

    if S[-5:] in five_letters:
        S = S[:-5]

    elif S[-6:] == "eraser":
        S = S[:-6]

    elif S[-7:] == "dreamer":
        S = S[:-7]

    else:
        break

if found:
    print("YES")

else:
    print("NO")

Submission status: Accepted

Solution code:
s=input()[::-1]
i=0
f=True
while 1:
  p=s[i:i+5]
  if not p:break
  if p=="maerd" or p=="esare":
    i+=5
  elif p=="remae":
    if s[i:i+7]=="remaerd":
      i+=7
    else:
      f=False
      break
  elif p=="resar":
    if s[i:i+6]=="resare":
      i+=6
    else:
      f=False
      break
  else:
    f=False
    break
if f:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
S = input()

marker = len(S)
flag = True

while flag and (marker > 0):

    if S[marker-7:marker] == "dreamer":
        marker -= 7
    elif S[marker-6:marker] == "eraser":
        marker -= 6
    elif S[marker-5:marker] == "dream":
        marker -= 5
    elif S[marker-5:marker] == "erase":
        marker -= 5
    else:
        flag = False
if flag:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

for i in range(100000):
    if S=="":
        print("YES")
        break
    elif S[-5:-1]=='drea':
        S=S[0:len(S)-5]
    elif S[-7:-1]=='dreame':
        S=S[0:len(S)-7]
    elif S[-5:-1]=='eras':
        S=S[0:len(S)-5]
    elif S[-6:-1]=='erase':
        S=S[0:len(S)-6]
        
if S!="":
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
SR = S[::-1]
temp =['dream','dreamer','erase','eraser']
T=""
j=0
count=0
while j<=10**5//5:
    j +=1
    for i in temp:
        if i[::-1] == SR[count:len(i)+count]:
            count+=len(i)
            T+=i[::-1]
            if SR==T:
                print('YES')
                exit()
print('NO')

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
C = ['maerd', 'remaerd', 'esare', 'resare']
ans = False
s = 0
for i in range(len(S)+1):
    if S[s:i] in C:
        s = i
        ans = True
    else:
        ans = False
if ans:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input()[::-1]
T = ['dream'[::-1], 'erase'[::-1],'dreamer'[::-1], 'eraser'[::-1]]

s = ''
for i in range(len(S)):
    s += S[i]
    if s in T:
        s = ''
    
if len(s) == 0:
    re = 'YES'
else:
    re = 'NO'

print(re)

Submission status: Accepted

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

""" 逆順使わないでDPでやる版 """

S = input()

dp = [False] * (len(S)+1)
# 0文字地点は遡る用にTrueにしておく
dp[0] = True

for i in range(1, len(dp)):
    if i-5 >= 0:
        if S[i-5:i] == "dream" or S[i-5:i] == "erase":
            # 条件に当てはまったら、文字数分遡って有効な文字列が続いているか確認
            if dp[i-5]:
                dp[i] = True
    if i-6 >= 0:
        if S[i-6:i] == "eraser":
            if dp[i-6]:
                dp[i] = True
    if i-7 >= 0:
        if S[i-7:i] == "dreamer":
            if dp[i-7]:
                dp[i] = True

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

Submission status: Accepted

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

S = input()
T = ""

words = []
words.append("dream")
words.append("dreamer")
words.append("erase")
words.append("eraser")
# 候補文字列を反転
for i in range(len(words)):
    words[i] = words[i][::-1]
# Sも反転
S = S[::-1]

while len(S) != 0:
    if S[:5] == words[0] or S[:5] == words[2]:
        S = S[5:]
    elif S[:6] == words[3]:
        S = S[6:]
    elif S[:7] == words[1]:
        S = S[7:]
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
S = input()
ans = True
W = ['dream', 'erase', 'eraser', 'dreamer']
while S:
  if S[:5] in W[:2]:
    match = False
    mw = ''
    for w in W:
      if S == w:
        match = True
        mw = w
    for w1 in W:
      for w2 in W:
        if S[:len(w1) + len(w2)] == w1 + w2:
          match = True
          mw = w1
    if match:
      S = S[len(mw):]
    else:
      ans = False
      break
  else:
    ans = False
    break
print('YES' if ans else 'NO')

Submission status: Accepted

Solution code:
S = input()

S = S[::-1]
T = ''
i = 0
while i < len(S):
    if S[i] == 'm':
        T += 'maerd'
        i += 5
    elif S[i] == 'e':
        T += 'esare'
        i += 5
    elif S[i:i + 3] == 'rem':
        T += 'remaerd'
        i += 7
    elif S[i:i + 3] == 'res':
        T += 'resare'
        i += 6
    else:
        break

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

Submission status: Accepted

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

for i, t in enumerate(T):
    T[i] = t[::-1]

cursor = 0
S = S[::-1]

while cursor < len(S):
    for t in T:
        if t == S[cursor:cursor+len(t)]:
            cursor += len(t)
            break
    else:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

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

Submission status: Accepted

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

for i, t in enumerate(T):
    T[i] = t[::-1]

cursor = 0
S = S[::-1]

while cursor < len(S):
    if S[cursor:cursor+7] == T[1]:
        cursor += 7

    elif S[cursor:cursor+6] == T[3]:
        cursor += 6

    elif S[cursor:cursor+5] == T[0]:
        cursor += 5

    elif S[cursor:cursor+5] == T[2]:
        cursor +=5

    else:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

Solution code:
import re

def solve(s):
	s=re.sub('eraser','',s)
	s=re.sub('erase','',s)
	s=re.sub('dreamer','',s)
	s=re.sub('dream','',s)
	if s:
		return 'NO'
	else:
		return 'YES'

s=input()
print(solve(s))

Submission status: Accepted

Solution code:
#coding:utf-8

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

s = input()

for i in range(len(words)):
    words[i] = words[i][::-1]
s = s[::-1]
count = 0
ans = 'YES'
while(count < len(s)):
    for word in words:
        if s[count:count+len(word)] == word:
            count += len(word)
            break
    else:
        ans = 'NO'
        break

print(ans)

Submission status: Accepted

Solution code:
words = ["dream", "dreamer", "erase","eraser"]
reverse_words = []
for word in words:
    reverse_words.append(word[::-1])
S = input()
S = S[::-1]

while len(S) !=0:
    flag = 0
    for word in reverse_words:
        if S.startswith(word):
            S = S[len(word):]
            flag=1
            break
    if (not flag):
        print("NO")
        quit()
print("YES")

Submission status: Accepted

Solution code:
s=list(input())

s.reverse()

f=1
n=len(s)

a1=list("dream")
a2=list("dreamer")
a3=list("erase")
a4=list("eraser")

a1.reverse()
a2.reverse()
a3.reverse()
a4.reverse()

while f>0 and n>0:
    k=-1
    if n>=7:
        if s[0:7]==a2:
            k=7
    if n>=6:
        if s[0:6]==a4:
            k=6
    if n>=5:
        if s[0:5]==a1:
            k=5
        elif s[0:5]==a3:
            k=5
    
    if k>0:
        del s[0:k]
        n=len(s)
    else:
        f=-1

if f>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()

while True:
    if len(s) == 0:
        print('YES')
        break
    elif 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:
        print('NO')
        break

Submission status: Accepted

Solution code:
import re
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()
            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = 0
    finally:


        return array_result

arr_data = getinputdata()

s = arr_data[0][0]

pattern="^(erase|eraser|dream|dreamer){1,}$"

if(re.search(pattern,s)):
    
    print("YES")

else:
    
    print("NO")

Submission status: Accepted

Solution code:
s=input()
d='dream'
e='erase'
i=0
while i<=len(s)-1:
    if len(s)-1-i<4:
        i=float('inf')
        break
    elif s[i]=='d':
        for j in range(5):
            if s[i+j]!=d[j]:
                i=float('inf')
                break
        else:    
            if i+6<=len(s)-1 and s[i+5]=='e' and s[i+6]=='r':
                if i+7<=len(s)-1 and s[i+7]=='a':
                    i+=5
                else:
                    i+=7
            else:
                i+=5
    elif s[i]=='e':
        for j in range(5):
            if s[i+j]!=e[j]:
                i=float('inf')
                break
        else:
            if i+5<=len(s)-1 and s[i+5]=='r':
                i+=6
            else:
                i+=5
    else:
        i=float('inf')
        break
if i==float('inf'):
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
s = input()
stack = []
choices = ['dream', 'dreamer', 'erase', 'eraser']
for c in choices:
    if s[:len(c)] == c:
        stack.append(len(c))

ans = 'NO'
while len(stack) > 0:
    i = stack[-1]
    # print(stack, i)
    stack = stack[:-1]
    if i == len(s):
        ans = 'YES'
        break
    for c in choices:
        if s[i:i+len(c)] == c:
            stack.append(i+len(c))
                
print(ans)

Submission status: Accepted

Solution code:
s = input()

def solve(s):
    while len(s) > 0:
        if s[-5:] == 'dream':
            s = s[:-5]
        elif s[-7:] == 'dreamer':
            s = s[:-7]
        elif s[-5:] == 'erase':
            s = s[:-5]
        elif s[-6:] == 'eraser':
            s = s[:-6]
        else:
            print('NO')
            return 
    print('YES')
    return

solve(s)