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 resolve():
    S = input()
    strings = ["dream", "dreamer", "erase", "eraser"]
    while True:
        if S == "":
            print("YES")
            return

        if S.startswith("eraser"):
            S = S[len("eraser"):]
            continue
        elif S.startswith("erase"):
            S = S[len("erase"):]
            continue
        elif S.startswith("dreamer"):
            if S.startswith("dreamerase"):
                S = S[len("dream"):]
                continue
            else:
                S = S[len("dreamer"):]
                continue
        elif S.startswith("dream"):
            S = S[len("erase"):]
            continue
        else:
            print("NO")
            return




if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(1000000)
S = input()


def start_with(i):
    if i == len(S):
        print('YES')
        sys.exit(0)

    try:
        if S[i:i+5] == 'dream':
            start_with(i+5)
        if S[i:i+7] == 'dreamer':
            start_with(i+7)
        if S[i:i+5] == 'erase':
            start_with(i+5)
        if S[i:i+6] == 'eraser':
            start_with(i+6)
        return
    except IndexError:
        return


start_with(0)
print('NO')

Submission status: Accepted

Solution code:
s = input()
m = ["dream", "dreamer", "erase", "eraser"]
t = ""
i = 0
find = False
fin = False
while fin == False:
    if s[i:i+6] == m[3]:
        t += m[3]
        i += 6
    elif s[i:i+5] == m[2]:
        t += m[2]
        i += 5
    elif s[i:i+5] == m[0]:
      
        if s[i+5:i+7] == "er":
            if s[i+5:i+10] == "erase":
                t += m[0]
                i += 5
            else:
                t += m[1]
                i += 7
        else:
            t += m[0]
            i += 5
       
    else:
        fin = True

    if i >= len(s):
        find = True


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

Submission status: Accepted

Solution code:
listn = list(input())
while listn != []:
    last_letter = listn[-1]
    if last_letter == "r":
        if "".join(listn[-6:]) == "eraser":
            del listn[-6:]
            continue
        elif "".join(listn[-7:]) == "dreamer":
            del listn[-7:]
            continue
        else:
            print("NO")
            exit()            
    elif last_letter == "m":
        if "".join(listn[-5:]) == "dream":
            del listn[-5:]
            continue
        else:
            print("NO")
            exit()   
    elif last_letter == "e":
        if "".join(listn[-5:]) == "erase":
            del listn[-5:]
            continue
        else:
            print("NO")
            exit()   
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
s = str(input())
l = len(s)
s = s[::-1]
i = 0
while i < l:
    if (s[i:min(l,i+7)] == "remaerd"):
        i += 7
    elif (s[i:min(l,i+6)] == "resare"):
        i += 6
    elif (s[i:min(l,i+5)] == "maerd" ):
        i += 5
    elif (s[i:min(l,i+5)] == "esare"):
        i += 5
    else:
        print('NO')
        break

else:
    print('YES')

Submission status: Accepted

Solution code:
s = str(input())
l = len(s)
s = s[::-1]
i = 0
while i < l:
    if s[i] == "r":
        if (s[i:min(l,i+7)] == "remaerd"):
            i += 7
        elif (s[i:min(l,i+6)] == "resare"):
            i += 6
        else:
            print('NO')
            break
    
    elif s[i] == "m":
        if (s[i:min(l,i+5)] == "maerd"):
            i += 5
        else:
            print('NO')
            break
            
    elif s[i] == "e":
        if (s[i:min(l,i+5)] == "esare"):
            i += 5
        else:
            print('NO')
            break
            
    else:
        print('NO')
        break
        
    
else:
    print('YES')

Submission status: Accepted

Solution code:
S = input()[::-1]
dividor = ['dream','dreamer','erase','eraser']
j=0
while True:
    flag = 0
    for d in dividor:
        if S[j:j+len(d)]==d[::-1]:
            flag = 1
            j+=len(d)
            if j==len(S):
                print("YES")
                quit() 
    if flag==0:
        print("NO")
        quit()

Submission status: Accepted

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

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()
p = len(S)
while 0<p:
  if 0<=p-5 and S[p-5:p]=='dream':
    p -= 5
    continue
  elif 0<=p-7 and S[p-7:p]=='dreamer':
    p -= 7
    continue
  elif 0<=p-6 and S[p-6:p]=='eraser':
    p -= 6
    continue
  elif 0<=p-5 and S[p-5:p]=='erase':
    p -= 5
    continue
  else:
    print('NO')
    break
else:
  print('YES')

Submission status: Accepted

Solution code:
S = input()
if len(S) < 5:
  print('NO')
  exit()
else:
  i = 0
  while True:
    if (i+5 == len(S) and S[i:i+5]=='dream') or (i+5 == len(S) and S[i:i+5]=='erase') or (i+6 == len(S) and S[i:i+6]=='eraser') or (i+7 == len(S) and S[i:i+7]=='dreamer'):
      print('YES')
      exit()
    elif S[i:i+5]=='dream' and i+8 <= len(S):
      if S[i+5:i+8]=='erd' or S[i+5:i+8]=='ere': i+=7
      elif S[i+5:i+8]=='era' or S[i+5:i+6]=='d': i+=5
      else:
        print('NO')
        exit()
    elif S[i:i+5]=='erase'  and i+7 <= len(S):
      if S[i+5:i+6]=='e' or S[i+5:i+6]=='d': i+=5
      elif S[i+5:i+6]=='r': i+=6
      else:
        print('NO')
        exit()
    else:
        print('NO')
        exit()

Submission status: Accepted

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

output = 'NO'

while(True):
    if (s_reverse[:5] == 'erase'[::-1] or s_reverse[0:5] == 'dream'[::-1]):
        s_reverse = s_reverse[5:]
    elif (s_reverse[:6] == 'eraser'[::-1]):
        s_reverse = s_reverse[6:]
    elif (s_reverse[:7] == 'dreamer'[::-1]):
        s_reverse = s_reverse[7:]
    else:
        if (len(s_reverse) == 0):
            output = 'YES'
        break
        
print(output)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
S = input()
n=0
flg=0
#print(s[0:K-1]+s[K-1].lower()+s[K:N])
S=S[::-1]
while(not S==""):

#    if  S[n:].startswith("dreameraser"):
#        n=n+11
        #print(S[n:])
        #flg==1
#        continue
    if S.startswith("remaerd"):
        #n=n+6
        S=S.replace("remaerd","",1)
        #print(S[n:])
        continue
    elif S.startswith("maerd"):
        #n=n+5
        S=S.replace("maerd","",1)
        #print(S)
        #flg==1
        continue
    elif S.startswith("resare"):
        #n=n+6
        S=S.replace("resare","",1)
        #print(S[n:])
        continue
    elif S.startswith("esare"):
        #n=n+5
        S=S.replace("esare","",1)
        #print(S)
        #flg==1
        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','')
print('YES' if s=='' else 'NO')

Submission status: Accepted

Solution code:
s = input()
t = ''
result = 'NO'

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

for i in range(len(scripts)):
    script = scripts[i]
    script = script[::-1]
    scripts[i] = script

s_rev = s[::-1]

while len(s) > 0:
    for script in scripts:
        if s_rev[:len(script)] == script:
            s_rev = s_rev[len(script):]
            break
    else:
        break

if s_rev == '':
    result = 'YES'
print(result)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'NO', True: 'YES'}
yn = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


def main():
    s = S()
    skip = [0] * len(s)

    for i in range(len(s)):
        if s[i:i+5] == 'dream':
            for idx in range(i, i+5):
                skip[idx] = 1

    for i in range(len(s)):
        if s[i:i+5] == 'erase':
            for idx in range(i, i+5):
                skip[idx] = 2

    for i in range(len(s)-1):
        if skip[i] == 0 and skip[i+1] == 0 and skip[i-1] == 1 and s[i] == 'e' and s[i+1] == 'r':
            skip[i] = 3
            skip[i+1] = 3

    for i in range(len(s)):
        if skip[i] == 0 and skip[i-1] == 2 and s[i] == 'r':
            skip[i] = 4

    print(YN[all(skip)])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
t = ''
result = 'YES'

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

while len(s) > len(t) and result == 'YES':
    restmp = False
    for script in scripts:
        tmp = t + script
        if tmp == s[:len(tmp)]:
            if tmp == s:
                t = tmp
                restmp = True
                break
            for script2 in scripts:
                tmp2 = tmp + script2
                if tmp2 == s[:len(tmp2)]:
                    t = tmp
                    restmp = True
                    break
            else:
                continue
            break

    if restmp is False:
        result = 'NO'

print(result)

Submission status: Accepted

Solution code:
import re

S = input()


if re.match("^(dream|dreamer|erase|eraser)+$", S):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input()

ans = "YES"
while len(S) > 0:
    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:
        ans = "NO"
        break

print(ans)

Submission status: Accepted

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

ns = ''
len_ns = 0
for i in s:
    ns = i + ns
    len_ns += 1
    if len_ns < 5:continue
    if 5 <= len_ns <= 7:
        if ns in check:
            ns = ''
            len_ns = 0
    else:
        print('NO')
        exit()
else:
    if ns not in check:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
def resolve():
	s = input()
	K = ['dream', 'dreamer', 'erase', 'eraser']
	for i in range(len(K)):
		K[i] = K[i][::-1]
	r = ''
	for i in s[::-1]:
		r += i
		if r in K:
			r = ''
	if len(r):
		print("NO")
	else:
		print("YES")
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    # 入力
    st = input()

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

    d_count = st.count("d")
    era_count = st.count("era")

    d_idx_ls = []
    era_idx_ls = []

    tmp_idx = 0
    for i in range(d_count):
        idx = st.index("d", tmp_idx)
        tmp_idx = idx + 1
        d_idx_ls.append(idx)

    tmp_idx = 0
    for i in range(era_count):
        idx = st.index("era", tmp_idx)
        tmp_idx = idx + 1
        era_idx_ls.append(idx)

    if d_count == 0 and era_count == 0:
        print("NO")
        return
    elif era_count == 0:
        pre_tmp_st_list = [""]
        for i in range(d_count):
            tmp_st_list = []
            for x in pre_tmp_st_list:
                tmp_st_list.append(x + "dream")
                tmp_st_list.append(x + "dreamer")
            pre_tmp_st_list = tmp_st_list

        for x in pre_tmp_st_list:
            if x == st:
                print("YES")
                return
        print("NO")
        return
    elif d_count == 0:
        pre_tmp_st_list = [""]
        for i in range(era_count):
            tmp_st_list = []
            for x in pre_tmp_st_list:
                tmp_st_list.append(x + "erase")
                tmp_st_list.append(x + "eraser")
            pre_tmp_st_list = tmp_st_list

        for x in pre_tmp_st_list:
            if x == st:
                print("YES")
                return
        print("NO")
        return
    else:
        # 2^(d_count + era_count)の候補を作成して確認
        tmp_ls_idx_d = 0
        tmp_ls_idx_era = 0
        pre_tmp_st_list = [""]
        while tmp_ls_idx_d < d_count or tmp_ls_idx_era < era_count:
            tmp_st_list = []
            # 次に追加するのがd
            if tmp_ls_idx_era == era_count:
                for x in pre_tmp_st_list:
                    a = x + "dream"
                    if st.startswith(a):
                        tmp_st_list.append(a)

                    b = x + "dreamer"
                    if st.startswith(b):
                        tmp_st_list.append(b)
                if len(tmp_st_list) == 0:
                    print("NO")
                    return
                else:
                    pre_tmp_st_list = tmp_st_list
                tmp_ls_idx_d += 1
            # 次に追加するのがera
            elif tmp_ls_idx_d == d_count:
                for x in pre_tmp_st_list:
                    a = x + "erase"
                    if st.startswith(a):
                        tmp_st_list.append(a)

                    b = x + "eraser"
                    if st.startswith(b):
                        tmp_st_list.append(b)
                if len(tmp_st_list) == 0:
                    print("NO")
                    return
                else:
                    pre_tmp_st_list = tmp_st_list
                tmp_ls_idx_era += 1
            # 次に追加するのがd
            elif d_idx_ls[tmp_ls_idx_d] < era_idx_ls[tmp_ls_idx_era]:
                for x in pre_tmp_st_list:
                    a = x + "dream"
                    if st.startswith(a):
                        tmp_st_list.append(a)

                    b = x + "dreamer"
                    if st.startswith(b):
                        tmp_st_list.append(b)
                if len(tmp_st_list) == 0:
                    print("NO")
                    return
                else:
                    pre_tmp_st_list = tmp_st_list
                tmp_ls_idx_d += 1
            # 次に追加するのがera
            else:
                for x in pre_tmp_st_list:
                    a = x + "erase"
                    if st.startswith(a):
                        tmp_st_list.append(a)

                    b = x + "eraser"
                    if st.startswith(b):
                        tmp_st_list.append(b)
                if len(tmp_st_list) == 0:
                    print("NO")
                    return
                else:
                    pre_tmp_st_list = tmp_st_list
                tmp_ls_idx_era += 1

        for x in pre_tmp_st_list:
            if x == st:
                print("YES")
                return
        print("NO")


main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc049/tasks/arc065_a

s = input()

strings = ['dream', 'dreamer', 'erase', 'eraser']
i = len(s)
while s:
    for i in range(4):
        t = strings[i]
        if s[-len(t):] == t:
            s = s[:-len(t)]
            break
    else:
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

Solution code:
SET=["dreamer", "dream",  "eraser", "erase"]
S=input()
dp=[0]*100010
dp[0]=1
for i in range(len(S)):
  if not dp[i]:continue
  for j in SET:
    if S[i:i+len(j)]==j:
      dp[i+len(j)]=1
if dp[len(S)]==1:print("YES")
else:print("NO")

Submission status: Accepted

Solution code:
s = input()

while s!="":
    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")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

t1 = "dream"
t2 = "dreamer"
t3 = "erase"
t4 = "eraser"

while True:
    if S[-5:] == t1 or S[-5:] == t3:
        S = S[0:-5]
    elif S[-6:] == t4:
        S = S[0:-6]
    elif S[-7:] == t2:
        S = S[0:-7]
    elif len(S) == 0:
        print("YES")
        break
    else:
        print("NO")
        break

Submission status: Accepted

Solution code:
s = input()
i = len(s) - 1
while i > 0:
    exist = False
    if (s[i] == "m" and s[i - 4:i + 1] == "dream") or (s[i] == "e" and s[i - 4:i + 1] == "erase"):
        exist = True
        i -= 5
    elif s[i] == "r":
        if s[i - 6:i + 1] == "dreamer":
            i -= 7
            exist = True
        elif s[i - 5:i + 1] == "eraser":
            i -= 6
            exist = True
    if exist == False:
        break
if exist:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = input()
i = len(s) - 1
flag = False
while i > 0:
    flag = False
    if s[i] == "m" and s[i - 4:i + 1] == "dream":
        flag = True
        i -= 5
    elif s[i] == "e" and s[i - 4: i + 1] == "erase":
        i -= 5
        flag = True
    elif s[i] == "r":
        if s[i - 5: i + 1] == "eraser":
            flag = True
            i -= 6
        elif s[i - 6: i + 1] == "dreamer":
            flag = True
            i -= 7
    if flag == False:
        break
print("YES" if flag else "NO")

Submission status: Accepted

Solution code:
s = input()

i = len(s)

while i > 0:
    if s[i-5:i] == 'dream':
        i -= 5
        continue
    elif s[i - 7:i] == 'dreamer':
        i -= 7
        continue
    elif s[i-5: i] == 'erase':
        i -= 5
        continue
    elif s[i-6: i] == 'eraser':
        i -= 6
        continue
    else:
        print('NO')
        exit(0)

print('YES')

Submission status: Accepted

Solution code:
s = input()[::-1]
N = len(s)
idx = 0
ls = ['maerd', 'remaerd', 'esare', 'resare']
while 1:
    tmp = idx
    if s[idx:idx+5] in ls:
        idx += 5
    elif s[idx:idx+6] in ls:
        idx += 6
    elif s[idx:idx+7] in ls:
        idx += 7
    
    if idx == N:
        print('YES')
        break
    if tmp == idx:
        print('NO')
        break

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
s=str(input())
can=True
while len(s)>4:
    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:
        can=False
        break
if len(s)==0:
    can=True
elif len(s)<=4:
    can=false
if(can):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S=input()
word=["dream", "dreamer", "erase", "eraser"]
dp=[0]*(len(S)+1)
dp[0]=1
done="NO"

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

print(done)

Submission status: Accepted

Solution code:
## coding: UTF-8
S = input()  # type(S) => <class 'str'>



#print(S[-3:]) daydaydreamdream
answer = 'YES'

while True:
    tester = S[-3:] #末尾3文字で判断
    if(tester == 'eam'): #末尾3文字がeamならdream
        if(S[-5:] == 'dream'): #dreamだったらdreamをカット、それ以外だったらこの地点でNO
            S = S[:-5] #末尾5文字(dream)をカット
            #print('1')
            #print(S)
        else:
            answer = 'NO'
            break
    elif(tester == 'mer'): #末尾3文字がmerならdreamer
        if(S[-7:] == 'dreamer'): #dreamerだったらdreamerをカット、それ以外だったらこの地点でNO
            S = S[:-7] #末尾7文字(dreamer)をカット
            #print('2')
            #print(S)
        else:
            answer = 'NO'
            break
    elif(tester == 'ase'): #末尾3文字がaseならerase
        if(S[-5:] == 'erase'): #eraseだったらeraseをカット、それ以外だったらこの地点でNO
            S = S[:-5] #末尾5文字(erase)をカット
            #print('3')
            #print(S)
        else:
            answer = 'NO'
            break
    elif(tester == 'ser'): #末尾3文字がserならeraser
        if(S[-6:] == 'eraser'): #eraserだったらeraserをカット、それ以外だったらこの地点でNO
            S = S[:-6] #末尾6文字(eraser)をカット
            #print('4')
            #print(S)
        else:
            answer = 'NO'
            break
    elif(len(S) == 0):
        break
    else:
        answer = 'NO'
        break

print(answer)

Submission status: Accepted

Solution code:
t=input()
trigger=1
key=''
d=-1
app=['dreamer','eraser','dream','erase']
while len(t)>0 and trigger:
    for i in range(4):
        key=app[i]
        if key==t[:len(key)]:
            t=t[len(key):]
            trigger+=1
            d=i
            break
    trigger-=1
    if trigger==0 and d==0 and t[:3]=='ase':
        t='er'+t
        trigger+=1
if t=='':
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S=input()
i=0
ans="YES"
while i<len(S) or ans=="Yes":
    if S[i:i+7]=="dreamer" and S[i+5:i+10]!="erase":
        i+=7
    elif S[i:i+6]=="eraser":
        i+=6
    elif S[i:i+5] == "dream" or S[i:i+5] == "erase":
        i+=5
    else:
        ans="NO"
        break
if i<len(S)-1:
    ans="NO"
print(ans)

Submission status: Accepted

Solution code:
s = input()
dp = [0]*(len(s) + 1)
dp[0] = 1
judge = 'NO'
words = ['dream', 'dreamer', 'erase', 'eraser']
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:
      judge = 'YES'
      break
print(judge)

Submission status: Accepted

Solution code:
s = str(input())

while len(s) >= 0:
  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]
  else:
    break

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

Submission status: Accepted

Solution code:
S = input()
Srev = S[::-1]
while True: 
  if Srev.startswith('maerd'):
    Srev = Srev[5::]
    continue
  elif Srev.startswith('remaerd'):
    Srev = Srev[7::]
    continue
  elif Srev.startswith('esare'):
    Srev = Srev[5::]
    continue
  elif Srev.startswith('resare'):
    Srev = Srev[6::]
    continue
  elif Srev == '':
    print('YES')
    break
  else:
    print('NO')
    break

Submission status: Accepted

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

while True:
    if reverse_S.startswith('esare'):
        reverse_S = reverse_S[5:]
        continue
    elif reverse_S.startswith('resare'):
        reverse_S = reverse_S[6:]
        continue
    elif reverse_S.startswith('maerd'):
        reverse_S = reverse_S[5:]
        continue
    elif reverse_S.startswith('remaerd'):
        reverse_S = reverse_S[7:]
        continue
    elif reverse_S =='':
        print('YES')
        break
    else:
        print('NO')
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
ch = ["dream", "dreamer", "erase", "eraser"]
while S:
  N = len(S)
  if S[N-5:] == ch[0] or S[N-5:] == ch[2]:
    S = S[:N-5]
  elif S[N-6:] == ch[3]:
    S = S[:N-6]
  elif S[N-7:] == ch[1]:
    S = S[:N-7]
  else:
    print("NO")
    exit()
print("YES")

Submission status: Accepted

Solution code:
S = input()
ch = ["dream", "dreamer", "erase", "eraser"]
while S:
  N = len(S)
  if S[N-5:N] == ch[0] or S[N-5:N] == ch[2]:
    S = S[:N-5]
  elif S[N-6:N] == ch[3]:
    S = S[:N-6]
  elif S[N-7:N] == ch[1]:
    S = S[:N-7]
  else:
    print("NO")
    exit()
print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
S = input()
S = S[::-1]
N = len(S)
words = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
while i != N:
    flag = 1
    for word in words:
        if S[i:i+len(word)] == word:
            flag = 0
            i += len(word)
    if flag:
        print('NO')
        sys.exit()
print('YES')

Submission status: Accepted

Solution code:
l = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  S = input()[::-1]
  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:
      print('NO')
      break
  else:
    print('YES')
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
ss=len(s)

while ss>0:
    if s[ss-5:ss]=="dream":
        ss=max(ss-5,0)
    elif s[ss-7:ss]=="dreamer":
        ss=max(ss-7,0)
    elif s[ss-5:ss]=="erase":
        ss=max(ss-5,0)
    elif s[ss-6:ss]=="eraser":
        ss=max(ss-6,0)
    else:
        print("NO")
        break
if ss<=0:
    print("YES")

Submission status: Accepted

Solution code:
words=["eraser","erase","dreamer","dream"]
S=input()
for i in range(0,4):
    S=S.replace(words[i],"",len(S)//4)
if S=="":
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input()
S_rvs = S[::-1]
texts = ["maerd", "remaerd", "esare", "resare"]

match = True
while len(S_rvs) > 0:
    if (S_rvs[0:5] == "maerd") or (S_rvs[0:5] == "esare"):
        S_rvs = S_rvs[5:]
    elif S_rvs[0:6] == "resare":
        S_rvs = S_rvs[6:]
    elif S_rvs[0:7] == "remaerd":
        S_rvs = S_rvs[7:]
    else:
        match = False
        break

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

Submission status: Accepted

Solution code:
s = input()

tmp_index = 0

while(len(s) - tmp_index > 4) :

	if( s[tmp_index] == 'd' ) :
		if s[tmp_index:tmp_index+7] == 'dreamer' :
			if ( s[tmp_index + 5:tmp_index + 10] == 'erase' ):
				tmp_index += 5
			else :
				tmp_index += 7
		elif s[tmp_index:tmp_index+5] == 'dream' :
			tmp_index += 5
		else :
			tmp_index = len(s) - 1
			
	elif( s[tmp_index] == 'e' ) :
		if  s[tmp_index:tmp_index + 6] == 'eraser' :
			tmp_index += 6
		elif s[tmp_index:tmp_index+5] == 'erase' :
			tmp_index += 5
		else :
			tmp_index = len(s) - 1
	else :
		tmp_index = len(s) - 1
	if len(s) == tmp_index :
		print('YES')
	elif len(s) - tmp_index < 5 :
		print('NO')

Submission status: Accepted

Solution code:
#9
S = input()[::-1]
for i in range(0, len(S)//5+1):
    if S[0:5] == 'maerd' or S[0:5] == 'esare':
        S = S[5:]
    elif S[0:6] == 'resare':
        S = S[6:]
    elif S[0:7] == 'remaerd':
        S = S[7:]
    else:
        break
print('YES' if len(S)==0 else 'NO')