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:
import sys
from collections import deque
s = input()

queue = deque()
queue.append(0)
candidates = ['dream', 'dreamer', 'erase', 'eraser']

index = 0
while queue:
    index = queue.popleft()
    match = False
    for candidate in candidates:
        if s[index:index + len(candidate)] == candidate:
            match = True
            if index + len(candidate) == len(s):
                print('YES')
                sys.exit(0)
            queue.append(index + len(candidate))
print('NO')

Submission status: Accepted

Solution code:
import re

s = input()
flag = re.match('^(dream|dreamer|erase|eraser)+$',s)

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

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


s = S()
# 後ろから見る
s = s[::-1]
t = ''
ans = 'YES'
i = 0
while True:
    # print(f'{i=}')
    # print(f'{s[i:]=}')
    if s[i: i + 7] == 'dreamer'[::-1]:
        i += 7
    elif s[i: i + 6] == 'eraser'[::-1]:
        i += 6
    elif s[i: i + 5] == 'dream'[::-1]:
        i += 5
    elif s[i: i + 5] == 'erase'[::-1]:
        i += 5
    elif i >= len(s):
        break
    else:
        ans = 'NO'
        break
print(ans)

Submission status: Accepted

Solution code:
S = str(input())

T = len(S)
K = T//5+1

for i in range (0, K+1):
	T = len(S)
	if S[-5::] == 'dream':
		S = S[0:T-5]
	elif S[-5::] == 'erase':
		S = S[0:T-5]
	elif S[-7::] == 'dreamer':
		S = S[0:T-7]
	elif S[-6::] == 'eraser':
		S = S[0:T-6]

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

Submission status: Accepted

Solution code:
S = input()

flag = 0

words = ("dream","erase","dreamer","eraser")
count = 0

while len(S) >= 5:

    for i in words:
        N = len(i)
        if S[-N:] in words:
            n = len(S) - N
            S = S[:n]
            flag = 1
            break
        else:
            flag = 0
            continue


    if flag == 0:
        break



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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

S = list(s())
S.reverse()
for i in range(10**5):
    if not S:
        break

    if ''.join(S[:7][::-1]) == 'dreamer' :
        S = S[7:]
    elif ''.join(S[:6][::-1]) == 'eraser':
        S = S[6:]
    elif ''.join(S[:5][::-1]) == 'dream':
        S = S[5:]
    elif ''.join(S[:5][::-1]) == 'erase':
        S = S[5:]
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    words = ["dream", "dreamer", "erase", "eraser"]

    while s:
        for word in words:
            if len(s) >= len(word):
                if s[-len(word):] == word:
                    s = s[:-len(word)]
                    break
        else:
            print("NO")
            sys.exit()

    print("YES")

if __name__ == '__main__':
    main()

Submission status: Accepted

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

s = s[::-1]
ans = ""
for i in range(4): div[i] = div[i][::-1]

for i in range(sl):
    ans += s[i]
    if ans in div:
        ans = ""

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

Submission status: Accepted

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

dreams = ['dream', 'dreamer', 'erase', 'eraser']
dreams = [dream[::-1] for dream in dreams]

i = 0
while i < len(S):
    flag = False
    for j in dreams:
        if S[i:i+len(j)] == j:
            i = i + len(j)
            flag = True
    if not flag:
        break

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    s = input()
    s = s[::-1]
    flag = True

    i = 0
    while i < len(s):
        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:
            flag = False
            break
    print('YES' if flag else 'NO')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()[::-1]
l = [ 'dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
	s1 = l[i][::-1]
	l[i] = s1

n = len(s)
i = 0
t = tuple(l)

while i < n:
	judge = 0
	s_l = []
	for j in (5,6,7):
		if n-i >= j:
			s1 = s[i:i+j]
			if s1 in t:
				i += j
				judge = 1
	
	if judge == 0:
		break

if i == n:
	print('YES')
else:
	print('NO')

Submission status: Accepted

Solution code:
print('YNEOS'[input().replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')>''::2])

Submission status: Accepted

Solution code:
print('YNEOS'[input().replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')!=''::2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

# 単転したら分解は一意
S = S[::-1]

while 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:
        print("NO")
        exit()

print("YES")

Submission status: Accepted

Solution code:
import sys
S = input()
S = S[::-1]
while 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:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
a = input()

b = a[::-1]

i = 0
while i  < len(b):
    if b[i:i+5] == "esare":
        i += 5
    elif b[i:i+5] == "maerd":
        i += 5
    elif b[i:i+6] == "resare":
        i += 6
    elif b[i:i+7] == "remaerd":
        i += 7
    else:
        ans = "NO"
        break

if i  == len(b):
    ans = "YES"
else:
    ans = "NO"

print(ans)

Submission status: Accepted

Solution code:
S = input()

import re

if re.fullmatch(r'(dream|dreamer|erase|eraser)*', S):
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s=input()

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

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

Submission status: Accepted

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

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()
tmp = ''.join(list(reversed(S)))
s = 0
ans = 'YES'

for i in range(len(S)):
    if tmp[s:i] == 'maerd' or tmp[s:i] == 'remaerd'or tmp[s:i] == 'esare' or tmp[s:i] == 'resare':
        s = i
        ans = 'YES'
        continue
    
    if len(tmp[s:i]) > 7:
        ans = 'NO'
        break
        
print(ans)

Submission status: Accepted

Solution code:
str = input()
words = ["dream", "dreamer", "erase", "eraser"]

def replace(S, s):
    reversedS = S[::-1]
    reverseds = s[::-1]
    replaced = reversedS.replace(reverseds, "", 1)
    return replaced[::-1]

while True:
    tmp = str
    for word in words:
        if str.endswith(word):
            str = replace(str, word)
            break
    if tmp == str:
        print("NO")
        break
    if str == "":
        print("YES")
        break
    tmp = str

Submission status: Accepted

Solution code:


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    '''
    dreamer
      dream
     eraser
      erase
    '''
    strings = ['dreamer', 'dream', 'eraser', 'erase']
    for i in range(len(strings)):
        strings[i] = ''.join(reversed(strings[i]))
    S = input().strip()
    S = ''.join(reversed(S))
    i = 0
    while i < len(S):
        found_string = None
        for string in strings:
            if S[i:].startswith(string):
                found_string = string
                break
        if found_string is None:
            return 'NO'
        i += len(found_string)
    return 'YES'


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

Submission status: Accepted

Solution code:
s = input()

flag = 0

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

if (flag == 0):
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
from sys import stdin
data = stdin.readline().rstrip()

def shorten_phrase(x):
    l = len(x)
    if x.startswith("eraser"):
        x = x[6:]
    elif x.startswith("erase"):
        x = x[5:]
    elif x.startswith("dreamera"):
        x = x[5:]
    elif x.startswith("dreamer"):
        x = x[7:]
    elif x.startswith("dream"):
        x = x[5:]
    m = len(x)
    return l != m

while shorten_phrase(data):
    if data.startswith("eraser"):
        data = data[6:]
    elif data.startswith("erase"):
        data = data[5:]
    elif data.startswith("dreamera"):
        data = data[5:]
    elif data.startswith("dreamer"):
        data = data[7:]
    elif data.startswith("dream"):
        data = data[5:]
if len(data) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()[::-1]
n = len(s)
words = ['maerd', 'remaerd', 'esare', 'resare']
while True:
    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
    break
print('NO' if s else 'YES')

Submission status: Accepted

Solution code:
s = str(input())

le = len(s)

while le>=5:
    fiv = s[-5:]
    six = s[-6:]
    sev = s[-7:]

    if fiv=="dream" or fiv=="erase":
        s = s[:-5]
    elif six=="eraser":
        s = s[:-6]
    elif sev=="dreamer":
        s = s[:-7]
    else:
        print("NO")
        exit()
    
    le = len(s)

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

Submission status: Accepted

Solution code:
S = input()[::-1]
word = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
judge = [True, True, True, True]
count = 0
while any(judge):
  for i in range(len(word)):
    if S[:len(word[i])] == word[i]:
      S = S[len(word[i]):]
    else:
      count += 1
    if S == '':
      print('YES')
      exit()
    if count == 4:
      print('NO')
      exit()
  count = 0

Submission status: Accepted

Solution code:
S=input()[::-1]
num=(len(S)//5)+1
while num > 0:
  for i in ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]:
    if S[:len(i)] == i:
      S = S[len(i):]
    if S == '':
      print('YES')
      exit()
  num -= 1
print('NO')

Submission status: Accepted

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

n = len(s)
k = 0

flg = True
while k < n:
    if s[k : min(k + 7, n)] == 'remaerd':
        k += 7
    elif s[k : min(k + 6, n)] == 'resare':
        k += 6
    elif s[k : min(k + 5, n)] == 'maerd' or s[k : min(k + 5, n)] == 'esare':
        k += 5
    else:
        flg = False
        break

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

Submission status: Accepted

Solution code:
import sys

S = input()

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

while len(S) > 0:
    if len(S) < 5:
        print('NO')
        sys.exit(0)
    no_match = True
    for word in words:
        if S[-3] == word[-3]:
            if len(S) < len(word) or S[-len(word):] != word:
                print('NO')
                sys.exit(0)
            S = S[:-len(word)]
            no_match = False
            break
    if no_match:
        print('NO')
        sys.exit(0)

print('YES')

Submission status: Accepted

Solution code:
import sys

S = input()

while len(S) > 0:
    if len(S) < 5:
        print('NO')
        sys.exit(0)
    third = S[-3]
    if third == 'e':
        if len(S) < 5 or S[-5:] != 'dream':
            print('NO')
            sys.exit(0)
        S = S[:-5]
        continue
    if third == 'a':
        if len(S) < 5 or S[-5:] != 'erase':
            print('NO')
            sys.exit(0)
        S = S[:-5]
        continue
    if third == 'm':
        if len(S) < 7 or S[-7:] != 'dreamer':
            print('NO')
            sys.exit(0)
        S = S[:-7]
        continue
    if third == 's':
        if len(S) < 6 or S[-6:] != 'eraser':
            print('NO')
            sys.exit(0)
        S = S[:-6]
        continue
    else:
        print('NO')
        sys.exit(0)

print('YES')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

s=input().rstrip("\n")
e=len(s)
l=["dream","dreamer","erase","eraser"]
for i in range(len(s))[::-1]:
    #print(s[i:e])
    #print(s)
    if s[i:e] in l:
        e=i
        s=s[:i]  
        continue
    if len(s[i:e])>7:
        print("NO")
        sys.exit()
if len(s)>0 and s not in l:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
import re
print("YES" if re.fullmatch("(erase(r)?|dream(er)?)+", input())else "NO")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
can = ["dream", "dreamer", "erase", "eraser"]
ss = input().rstrip('\n')

pos = len(ss)
while True:
    found = False
    for cc in can:
        lenz = len(cc)
        if (pos-lenz >= 0) and (ss[pos-lenz:pos] == cc):
            pos = pos - lenz
            found = True
            break
    if (not found) or (pos <= 0): break

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

Submission status: Accepted

Solution code:
s = list(input())
index = 0
while index < len(s):
    if "".join(s[index:index+7]) == "dreamer":
        index += 7
    elif "".join(s[index:index+6]) == "eraser":
        index += 6
    elif "".join(s[index:index+5]) == "erase" or "".join(s[index:index+5]) == "dream":
        index += 5
    elif "".join(s[index:index+4]) == "aser":
        index += 4
    elif "".join(s[index:index+3]) == "ase":
        index += 3
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

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

s = s.replace("eraser"[::-1], "")
s = s.replace("erase"[::-1], "")
s = s.replace("dreamer"[::-1], "")
s = s.replace("dream"[::-1], "")

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

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
s1 = 'maerd'
s2 = 'esare'
s3 = 'remaerd'
s4 = 'resare'

while(1):
	if S[:5] == s1:
		S = S[5:]
	elif S[:5] == s2:
		S = S[5:]
	elif S[:7] == s3:
		S = S[7:]
	elif S[:6] == s4:
		S = S[6:]
	else:
		break

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

Submission status: Accepted

Solution code:
import re
if re.fullmatch(r'(dream|dreamer|erase|eraser)*', input().strip()):
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a=0
while a<len(s):
    if s[a:a+5]=="esare" or s[a:a+5]=="maerd":
        a+=5
    elif s[a:a+6]=="resare":
        a+=6
    elif s[a:a+7]=="remaerd":
        a+=7
    else:
        print("NO")
        exit()

print("YES")

Submission status: Accepted

Solution code:
from collections import deque

s = input()
q = deque(list(s))

while q:
  if len(q) >= 5:
    subs = q.popleft()+q.popleft()+q.popleft()+q.popleft()+q.popleft()
    if subs != 'erase' and subs != 'dream':
      print('NO')
      exit()
    if subs == 'erase' and len(q) != 0 and q[0] == 'r':
      q.popleft()
    if subs == 'dream' and len(q) == 2 and q[0]+q[1] == 'er':
      q.popleft()
      q.popleft()
    if subs == 'dream' and len(q) >= 3 and q[0]+q[1] == 'er' and q[2] != 'a':
      q.popleft()
      q.popleft()
  else:
   
    print('NO')
    exit()
    
print('YES')

Submission status: Accepted

Solution code:
S=input()
check=["dream","dreamer","erase","eraser"]
S=S[::-1]
for i in range(len(check)):
  check[i]=check[i][::-1]
nagasa=len(S)
cur=0
while cur<nagasa:
  flag=False
  for x in check:
    find_pos=S.find(x,cur)
    if cur==find_pos:
      flag=True
      cur=find_pos+len(x)
      break
  if flag==False:
    print("NO")
    exit()
print("YES")

Submission status: Accepted

Solution code:
import re
s = list(input())
s.reverse()

s = "".join(s)
s = re.split('maerd|remaerd|esare|resare', s)
if len(s) == s.count(""):
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = list(input())
import re
S.reverse()
S = "".join(S)
S = re.split('maerd|remaerd|esare|resare', S)
if len(S) == S.count("") :
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
S = list(input())
import re
S.reverse()
D1 = "maerd"
D2 = "remaerd"
E1 = "esare"
E2 = "resare"
S = "".join(S)
S = re.split('maerd|remaerd|esare|resare', S)
if len(S) == S.count("") :
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
import sys
s = str(input())
ls = ["dream","dreamer","erase","eraser"]
while True:
    k = s[-5:]
    if k not in ls:
        t = s[-6:]
        if t not in ls:
            l = s[-7:]
            if l not in ls:
                print("NO")
                sys.exit()
            else:
                s = s[:-7]
                if s == "":
                    print("YES")
                    break
        else:
            s = s[:-6]
            if s == "":
                print("YES")
                break
    else:
        s = s[:-5]
        if s == "":
            print("YES")
            break

Submission status: Accepted

Solution code:
import sys

S = input()
S = S[::-1]
temp = ''

for a in S:
    temp += a
    # dream,dreamer
    if temp == "maerd" or temp == "remaerd" or temp == "esare" or temp == "resare":
        temp = ""
    if len(temp)>7:
        print("NO")
        sys.exit()
print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
words = ("dream", "dreamer", "erase", "eraser")

for _ in range((len(S) + 4) // 5):
    for word in words:
        if S.endswith(word):
            S = S[: -len(word)]
print("NO") if S else print("YES")

Submission status: Accepted

Solution code:
s = input()[::-1]
x = ["dream", "dreamer", "erase", "eraser"]
can = True
i = 0
for a in range(4):
    x[a] = x[a][::-1]
while(True):
    if(i == len(s)):
        break
    can2 = False
    for j in range (4):
        if(s[i:i+len(x[j])] == x[j]):
            can2 = True
            i += len(x[j])
    if(can2 == False):
        can = False
        break
print("YES" if can == True else "NO")

Submission status: Accepted

Solution code:
s = input()
n = len(s)
i = 0
flag = 0
while(True):
    if(s[i:i+5]) == "dream":
        if(i+5==n):
            break
        elif(s[i+5:i+10] =="dream"):
            i += 5
        elif(s[i+5:i+10] == "erase"):
            i += 5
        elif(s[i+5:i+7] == "er"):
            i += 7
            if(i==n):
                break
        else:
            flag = 1
            break

    elif(s[i:i+5]) == "erase":
        if(i+5==n):
            break
        elif(s[i+5:i+10] =="dream"):
            i += 5
        elif(s[i+5:i+10] == "erase"):
            i += 5
        elif(s[i+4:i+6] == "er"):
            i += 6
            if(i==n):
                break
        else:
            flag = 1
            break
    else:
        flag = 1
        break
print("YES" if flag == 0 else "NO")

Submission status: Accepted

Solution code:
import sys
S = input().rstrip()
S = S[::-1]
S1 = "dream"
S2 = "dreamer"
S3 = "erase"
S4 = "eraser"
S1 = S1[::-1]
S2 = S2[::-1]
S3 = S3[::-1]
S4 = S4[::-1]
while len(S) > 0:
  if S[0:len(S1)] == S1:
    S = S[len(S1):]
  elif S[0:len(S2)] == S2:
    S = S[len(S2):]
  elif S[0:len(S3)] == S3:
    S = S[len(S3):]
  elif S[0:len(S4)] == S4:
    S = S[len(S4):]
  else:
    print("NO")
    sys.exit()
print("YES")

Submission status: Accepted

Solution code:
s = input()

while True:
    if s[-7:] == 'dreamer':
        s = s[:-7]
    elif s[-6:] == 'eraser':
        s = s[:-6]
    elif s[-5:] == 'dream':
        s = s[:-5]
    elif s[-5:] == 'erase':
        s = s[:-5]

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

Submission status: Accepted

Solution code:
S = input()

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

is_updated = True
while is_updated and len(S) > 0:
  is_updated = False
  for text in TEXTS:
    if S[len(S) - len(text):] == text:
      S = S[:len(S) - len(text)]
      is_updated = True

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

Submission status: Accepted

Solution code:
# coding: utf-8
"""this is python work script"""

def solver(word):
    """solve this problem"""
    check_result = word.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')

    answer = 'YES'
    if check_result:
        answer = 'NO'

    return answer

def main():
    """main function"""
    input_word = input().rstrip()
    answer = solver(input_word)
    print(answer)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
"""this is python work script"""

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

def check_word(word, check_word_list):
    find_word = False

    # print(word, check_word_list)
    for i, cw in enumerate(check_word_list):
        find_result = word.find(cw)
        # print(i, cw, find_result)

    # # remove check word if not find it in string
    # if find_result == -1:
    #     check_word_list.remove(cw)

    #  remove word if find it in string head
        if find_result == 0:
            word_length = len(cw)
            word = word[word_length:]
            find_word = True
        # print(word, check_word_list)

    return find_word, word

def solver(word, check_word_list):
    """solve this problem"""
    wip = True
    while wip:
        wip, word = check_word(word, check_word_list)

    answer = 'NO'
    if len(word) == 0:
        answer = 'YES'
    return answer

def reverse_string_list(string_list):
    answer_list = []
    for word in string_list:
        answer_list.append(word[::-1])

    return answer_list

def main():
    """main function"""
    word = input().rstrip()[::-1]
    word_list = reverse_string_list(CHECK_WORDS)
    answer = solver(word=word, check_word_list=word_list)
    print(answer)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#! env python
# -*- coding: utf-8 -*-

import os
import sys

# ac_py.main
# Date: 2020/06/12
# Filename: main 
# Author: acto_mini

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


def find(s):
    while True:
        for term in d:
            if s.endswith(term):
                s = s[:-1 * len(term)]
                break
        else:
            print("NO")
            break
        if len(s) == 0:
            print("YES")
            break
    return


def main():
    find(input())
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

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

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

Submission status: Accepted

Solution code:
s=input()

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

Submission status: Accepted

Solution code:
s = list(input())
s = s[::-1]
ans = 1
while len(s):
    if len(s) <= 4:
        ans = 0
        break
    elif s[0:5] == list("maerd"):
        del s[0:5]
    elif s[0:5] == list("esare"):
        del s[0:5]
    elif len(s) <= 5:
        ans = 0
        break
    elif s[0:6] == list("resare"):
        del s[0:6]
    elif len(s) <= 6:
        ans = 0
        break
    elif s[0:7] == list("remaerd"):
        del s[0:7]
    else:
        ans = 0
        break
print(["NO","YES"][ans])

Submission status: Accepted

Solution code:
S = input()
s = S[::-1]
s1 = s.replace('resare', '').replace('esare', '')
s2 = s1.replace('remaerd', '').replace('maerd', '')

print('YES' if s2 == '' else 'NO')

Submission status: Accepted

Solution code:
s = input()

lst = ['dreameraser', 'dreamerase', 'dreamer', 'dream', 'eraser', 'erase']
while s:
  flag = 0
  for elem in lst:
    if elem in s:
      s = s.replace(elem, '')
      flag = 1
      break
  if flag == 0:
    print('NO')
    quit()
print('YES')

Submission status: Accepted

Solution code:
S = input()
dp = [0] * (len(S) + 1)
dp[0] = 1

words = ["dream", "dreamer", "erase", "eraser"]
done = 'NO'

for i in range(len(S)):
    if dp[i] == 0:
        continue
    for w in words:
        if S[i:i+len(w)] == w:
            dp[i+len(w)] = 1
    
    if dp[len(S)] == 1:
        done = 'YES'
        break

print(done)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


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


def LS(): return list(sys.stdin.readline().rstrip().split())


S = S()

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

Submission status: Accepted

Solution code:
import re

s = input()

s = s[::-1]

while s:
    if re.match("resare",s):
        s = s[6:]
    elif re.match("esare",s):
        s = s[5:]
    elif re.match("remaerd",s):
        s = s[7:]
    elif re.match("maerd",s):
        s = s[5:]
    else:
        break
    
if len(s) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s3=s=input()[::-1]
l=["maerd","remaerd","esare","resare"]
s2=""
for i in range(len(s)):
 s2+=s[i]
 if s2 in l:
  s3=s3[len(s2):]
  s2=""
print("YES"if s2==""else "NO")

Submission status: Accepted

Solution code:
S = input()

num_eraser = S.count('eraser')
num_erase = S.count('erase') - num_eraser
num_dreamer = S.count('dreamer') - S.count('dreamerase')
num_dream = S.count('dream') - num_dreamer
# dream + erase(r) で dreamer が含まれるのに注意

# print(num_eraser, num_erase, num_dreamer, num_dream)
cnt = num_eraser * 6 + num_erase * 5 + num_dreamer * 7 + num_dream * 5
# print('cnt', cnt)
if len(S) == cnt:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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