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:
# coding: utf-8
# Your code here!
S = input()
while True:
    if len(S)!=0:
        if S[len(S)-7:len(S)]=="dreamer":
            S = S[0:len(S)-7]
        elif S[len(S)-6:len(S)]=="eraser":
            S = S[0:len(S)-6]
        elif S[len(S)-5:len(S)]=="dream":
            S = S[0:len(S)-5]
        elif S[len(S)-5:len(S)]=="erase":
            S = S[0:len(S)-5]
        else:
            print("NO")
            break

    else:
        print("YES")
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
while True:
  if S.endswith("dream"):
    S = S[0: len(S)-len("dream")]
  elif S.endswith("dreamer"):
    S = S[0: len(S)-len("dreamer")]
  elif S.endswith("erase"):
    S = S[0: len(S)-len("erase")]
  elif S.endswith("eraser"):
    S = S[0: len(S)-len("eraser")]
  else:
    break
if (len(S) == 0):
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
# 解説を参考にした（この問題はアイデア勝負だと思うが…）
sentence = input()
ans = 0
sentence = sentence.replace("eraser", "")
sentence = sentence.replace("erase", "")
sentence = sentence.replace("dreamer", "")
sentence = sentence.replace("dream", "")

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

Submission status: Accepted

Solution code:
s = str(input())

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

new_s =s[::-1]
new_t = []
for item in T:
  new_t.append(item[::-1])

ans_t =''
collector = ''

for c in new_s:
  collector += c
  if collector in new_t:
    ans_t += collector
    collector = ''
    
if new_s == ans_t:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
S = input()

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

for i in range(len(strs)):
    S = S.replace(strs[i], '')

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

Submission status: Accepted

Solution code:
S = input()

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

flag = True
while flag:
    for fstr in fstrs:
        result = S.rfind(fstr)
        if result >= 0 and result == len(S) - len(fstr):
            # print('found: {} in {} ({})'.format(fstr, S, result))
            S = S[0:result]
            flag = True
            break
        else:
            # print('not found: {} in {}'.format(fstr, S))
            flag = False
    if len(S) == 0:
        break

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

Submission status: Accepted

Solution code:
S = input()
ls = len(S)
if ls<5:
    print('NO')
else:
    i = 0
    while True:
        if (ls-1>=i+4):
            if S[i:i+5]=='dream':
                if S[i:] == 'dream' or S[i:] == 'dreamer':
                    print('YES')
                    break
                elif ls-1>=i+7:
                    if (S[i+5:i+8]=='dre') or (S[i+5:i+8]=='era'):
                        i+=5
                        continue
                    elif (S[i+5:i+8]=='erd') or (S[i+5:i+8]=='ere'):
                        i+=7
                        continue

            elif S[i:i+5]=='erase':
                if S[i:] == 'erase' or S[i:] == 'eraser':
                    print('YES')
                    break
                elif ls-1>=i+5:
                    if S[i+5]=='r':
                        i += 6
                        continue
                    elif S[i+5]=='d' or S[i+5]=='e':
                        i += 5
                        continue
        print('NO')
        break

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc049/tasks/arc065_a

s = input()[::-1]
collector = ''
t = ''
words = ['remaerd', 'maerd', 'resare', 'esare']

for c in s:
    collector += c
    if collector in words:
        t += collector
        collector = ''

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(s):
  while True:
    if s == '':
      return True
    else:
      if s[0:7] == 'dreamer'[::-1]:
        s = s[7:]
      elif s[0:5] == 'dream'[::-1]:
        s = s[5:]
      elif s[0:5] == 'erase'[::-1]:
        s = s[5:]
      elif s[0:6] == 'eraser'[::-1]:
        s = s[6:]
      else:
        return False
  
print('YES' if solve(input()[::-1]) 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:
import re

S=input()[::-1]

if re.match(r'^(maerd|remaerd|esare|resare)+$',S):
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
rvrsd_S = input()[::-1]
words = ['dream', 'dreamer', 'erase', 'eraser']
rvrsd_words = [i[::-1] for i in words]
a = 0
sw = True
while sw == True:
    sw = False
    for i in rvrsd_words:
        if rvrsd_S[a:a+len(i)] == i:
            a += len(i)
            sw = True
    if a >= len(rvrsd_S):
        print('YES')
        exit()
print('NO')

Submission status: Accepted

Solution code:
S = input()

S = S.replace('eraser', '!').replace('erase', '!').replace('dreamer', '!').replace('dream', '!')
S = S.replace('!', '')

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

Submission status: Accepted

Solution code:
S = input()

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

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

Submission status: Accepted

Solution code:
S = input()


A = list(S)
A =  list(reversed(A))


while len(A)!=0:
    if len(A)>= 5 and A[0]+A[1]+A[2]+A[3]+A[4] == "esare":
        del A[:5]
    elif len(A)>= 5 and A[0]+A[1]+A[2]+A[3]+A[4] == "maerd":
        del A[:5]
    elif len(A)>= 6 and A[0]+A[1]+A[2]+A[3]+A[4]+A[5] =="resare":
        del A[:6]
    elif len(A)>= 7 and A[0]+A[1]+A[2]+A[3]+A[4]+A[5]+A[6] =="remaerd":
        del A[:7]
    else:
        print('NO')
        break;
if len(A) ==0:
    print('YES')

Submission status: Accepted

Solution code:
import re
s = input()
print('YES' if re.match('^(eraser?|dream(er)?)*$', s) else 'NO')

Submission status: Accepted

Solution code:
l=['dream','dreamer','erase','eraser']
s=input().rstrip()
x=list(s)
if len(x)<5:
    print("NO")
elif len(x)==5:
    if ''.join(x)=='dream' or ''.join(x)=='erase':
        print("YES")
    else:
        print("NO")
elif len(x)==6:
    if ''.join(x)==l[3]:
        print("YES")
    else:
        print("NO")
elif len(x)==7:
    if ''.join(x)==l[1]:
        print("YES")
    else:
        print("NO")
else:
    i=0;
    G=0;
    while(i<len(x)):
        #print(i)
        if x[i]=='d':
            t=x[i:i+5]
            p=x[i:i+7]
            if ''.join(p)=='dreamer':
                if (i+7)<len(x) and x[i+7]!='a':
                    i+=7;
                elif (i+7+1)>len(x):
                    break;
                elif (i+7)<len(x) and x[i+7]=='a':
                    i+=5;
            elif ''.join(t)=='dream':
                i+=5;
            else:
                G=1;
                break;
        elif x[i]=='e':
            t=x[i:i+5]
            p=x[i:i+6]
            if ''.join(p)==l[3]:
                i+=6;
            elif ''.join(t)==l[2]:
                i+=5;
            else:
                G=1;
                break;
        else:
            G=1;
            break;
    if G==0:
        print("YES")
    else:
        print("NO")

Submission status: Accepted

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10 **9)


S = str(input())
dp = [0] * (2 * len(S))

#再帰関数
def check(i): #i最初の文字
    flag0 = False
    flag1 = False
    flag2 = False
    flag3 = False
    flag4 = False
    flag5 = False
    if dp[i+5] != 0 or dp[i+6] != 0 or dp[i+7] != 0:
        return dp[i+5] or dp[i+6] or dp[i+7]
    #S[i:]=残りが条件を満たす
    if S[i:] == 'dream' or S[i:] == 'dreamer' or S[i:] == 'erase' or S[i:] == 'eraser':
        return True
    if S[i:i+7] == 'dreamer': #dreamerを使った時に、条件を満たすかを再帰で計算
        dp[i+7] = check(i+7)
        flag2 = dp[i+7]
    if S[i:i+5] == 'dream':
        dp[i+5] =  check(i+5)
        flag3 =  dp[i+5]
    if S[i:i+6] == 'eraser':
        dp[i+6] =  check(i+6)
        flag4 =  dp[i+6]
    if S[i:i+5] == 'erase':
        dp[i+5] =  check(i+5)
        flag5 = dp[i+5]
    return flag0 or flag1 or flag2 or flag3 or flag4 or flag5 #どれかがTrueならOK

if check(0):
    print ('YES')
else:
    print ('NO')

Submission status: Accepted

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10 **9)
S = str(input())
A = ['dream', 'dreamer', 'erase', 'eraseer']

N = len(S)
i = 0

def check(i): #i最初の文字
    flag0 = False
    flag1 = False
    flag2 = False
    flag3 = False
    flag4 = False
    flag5 = False
    if S[i:] == 'dream' or S[i:] == 'dreamer' or S[i:] == 'erase' or S[i:] == 'eraser':
        flag1 = True
    if S[i:i+7] == 'dreamer':
        flag2 = check(i+7)
    if S[i:i+5] == 'dream':
        flag3 =  check(i+5)
    if S[i:i+6] == 'eraser':
        flag4 =  check(i+6)
    if S[i:i+5] == 'erase':
        flag5 = check(i+5)
    return flag0 or flag1 or flag2 or flag3 or flag4 or flag5

if check(0):
    print ('YES')
else:
    print ('NO')

Submission status: Accepted

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

flag = True
while flag and s != "":
    flag = False
    for i in range(len(w)):       
        if s[-1*len(w[i]):] == w[i]:
            s = s[:-1*len(w[i])]
            flag = True

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def Hantei(S):
    res = False
    dream = list("dream")
    dreamer = list("dreamer")
    erase = list("erase")
    eraser = list("eraser")

    flg = 0
    if S[-1] == dream[-1]:
        flg = 1
    elif S[-1] == dreamer[-1] and S[-2] == dreamer[-2] and S[-3] == dreamer[-3]:
        flg = 2
    elif S[-1] == erase[-1]:
        flg = 3
    elif S[-1] == eraser[-1] and S[-2] == eraser[-2] and S[-3] == eraser[-3]:
        flg = 4

    if flg == 1:
        S.pop()
        if S.pop()==dream[-2] and S.pop()==dream[-3] and S.pop()==dream[-4] and S.pop()==dream[-5]:
            res = True
    if flg == 2:
        S.pop()
        S.pop()
        S.pop()
        if S.pop()==dreamer[-4] and S.pop()==dreamer[-5] and S.pop()==dreamer[-6] and S.pop()==dreamer[-7]:
            res = True
    if flg == 3:
        S.pop()
        if S.pop()==erase[-2] and S.pop()==erase[-3] and S.pop()==erase[-4] and S.pop()==erase[-5]:
            res = True
    if flg == 4:
        S.pop()
        S.pop()
        S.pop()
        if S.pop()==eraser[-4] and S.pop()==eraser[-5] and S.pop()==eraser[-6]:
            res = True
            
    return res

S = list(input())
while True:
    if Hantei(S) == False:
        print("NO")
        break
    if len(S) == 0:
        print("YES")
        break

Submission status: Accepted

Solution code:
s = input()
while True:
    # print(s[-6:], s[-7:], s[-5:])
    # print(s[:-6], s[:-7], s[:-5])
    # print(s)
    if len(s) >= 6 and s[-6:] == 'eraser':
        s = s[:-6]
    elif len(s) >= 5 and s[-5:] == 'erase':
        s = s[:-5]
    elif len(s) >= 7 and s[-7:] == 'dreamer':
        s = s[:-7]
    elif len(s) >= 5 and s[-5:] == 'dream':
        s = s[:-5]
    elif len(s) > 0:
        # print('s=', s, ';',s=='erase',s[-5:]=='erase',s[:-5])
        print('NO')
        import sys
        sys.exit()
    else:break
    # except:
    #     print('NO')
    #     import sys
    #     sys.exit()
print('YES')

Submission status: Accepted

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

for str in replace_str :
    s = s.replace(str,"")

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

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
t = ['maerd','remaerd','esare','resare']
i = 0
frag = 0
while i <= len(S)-1 and frag == 0:
  k = 0
  for j in range(4):
    d = t[j]
    if S[i:len(d)+i] == d:
      i = i + len(d)
    else:
      k = k + 1
      if k == 4:
        frag = 1
        print('NO')
if i == len(S):
  print('YES')

Submission status: Accepted

Solution code:
S = input()

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

answer = 'YES' if not S else 'NO'
print(answer)

Submission status: Accepted

Solution code:
S=list(input())
S.reverse()
i=0
l=len(S)
while True:
    if i==l:
        print("YES")
        break
    elif ''.join(S[i:i+5])=="esare":
        i=i+5
    elif ''.join(S[i:i+5])=="maerd":
        i=i+5
    elif ''.join(S[i:i+6])=="resare":
        i=i+6
    elif  ''.join(S[i:i+7])=="remaerd":
        i=i+7
    else:
        print("NO")
        break

Submission status: Accepted

Solution code:
S = input()

word_lst = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(word_lst)):
  word_lst[i] = word_lst[i][::-1]
  
S = S[::-1]
ans = ''
while len(ans) < len(S) - 4:
  if S[len(ans)] == 'm':
    ans = ans + word_lst[0]
  elif S[len(ans):len(ans)+3] == 'rem':
    ans = ans + word_lst[1]
  elif S[len(ans)] == 'e':
    ans = ans + word_lst[2]
  elif S[len(ans):len(ans)+3] == 'res':
    ans = ans + word_lst[3]
  else:
    break

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

Submission status: Accepted

Solution code:
s=input()[::-1]
de=['maerd','esare']
dr='remaerd'
er='resare'
def check(a,x):
	if a > x:
		print("NO")
		exit(0)
i=0
n=len(s)
while i<n:
	check(i,n-5)
	if s[i:i+5] in de:
		i+=5
		continue
	check(i,n-6)
	if s[i:i+6] == er:
		i+=6
		continue
	check(i,n-7)
	if s[i:i+7]  == dr:
		i+=7
		continue
	print('NO')
	break
else:
	print("YES")

Submission status: Accepted

Solution code:
s = input().rstrip('\n');
can = 0;
n = len(s);
tsugi = n;
while tsugi >= 1 :
	if s[tsugi - 5 : tsugi] == 'dream' :
		can = 1;
		tsugi = tsugi -5;
	elif s[tsugi - 5 : tsugi] == 'erase' :
		can = 1;
		tsugi = tsugi -5;
	elif s[tsugi - 6 : tsugi] == 'eraser' :
		can = 1;
		tsugi = tsugi -6;
	elif s[tsugi - 7 : tsugi] == 'dreamer' :
		can = 1;
		tsugi = tsugi -7;
	else :
		can = 0;
		tsugi = -1;
if bool(can) :
	print('YES');
else :
	print('NO');

Submission status: Accepted

Solution code:
#ABC49-C
S=input()
divide=["dream","dreamer","erase","eraser"]
for i in range(4): #４つの文字群を反転
    divide[i]=divide[i][::-1]
len_s=len(S)
S=S[::-1]

check=0
i=0
a=[]
while check==0:
    if i==len_s: #ぴったり終わりの時
        a.append(1)
        break
    if len_s-i <5: #残りが５文字未満のとき、これ以上見つけられない。
        check=1
        a.append(2)
        break
    if S[i:i+5] == divide[0]:
        i=i+5
        a.append(3)
        continue
    if S[i:i+5] == divide[2]:
        i=i+5
        a.append(4)
        continue
    if len_s-i <6: #残りが6文字未満のとき、これ以上見つけられない。
        check=1
        a.append(5)
        break
    if S[i:i+6] == divide[3]:
        i=i+6
        a.append(6)
        continue
    if len_s-i <7: #残りが７文字未満のとき、これ以上見つけられない。
        check=1
        a.append(7)
        break
    if S[i:i+7] == divide[1]:
        i=i+7
        a.append(8)
        continue
    check=1 #上のif文どれにも引っかからなかったとき。

if check==0:
    print("YES")
else:
    print("NO")
#print(a)

Submission status: Accepted

Solution code:
def resolve():
    s = input()

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

    s = s[::-1]
    i = 0

    while i < len(s):

        flag = False

        for devider in deviders:

            if s[i:i + len(devider)] == devider:

                i += len(devider)
                flag = True
                break

        if not flag:
            print('NO')
            return

    print('YES')

    return
  
resolve()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=list(S())

  l=[['d', 'r', 'e', 'a', 'm'],
  ['d', 'r', 'e', 'a', 'm', 'e', 'r'],
  ['e', 'r', 'a', 's', 'e'],
  ['e', 'r', 'a', 's', 'e', 'r']]

  while True:
    if len(s)<=4:
      break
    else:
      if l[0]==s[-5:]:
        [s.pop() for _ in ' '*5]
      elif l[1]==s[-7:]:
        [s.pop() for _ in ' '*7]
      elif l[2]==s[-5:]:
        [s.pop() for _ in ' '*5]
      elif l[3]==s[-6:]:
        [s.pop() for _ in ' '*6]
      else:
        return 'NO'

  if len(s)==0:
    return 'YES'
  return 'NO'

print(main())

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:
# -*- coding:utf-8 -*-

def solve():
    S = input()
    T = ""
    while True:
        if S == "":
            break
        
        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")

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
# デジャヴュ。ゼロから始めるのではなく消していってゼロにする
# なぜか1WA

s = input()
while True:
    if len(s) == 0:
        print("YES")
        exit()
    elif len(s) <= 4:
        print("NO")
        exit()
    else:
        # 長さの処理しなくてもエラーにはならんっぽい
        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:
            print("NO")
            break

Submission status: Accepted

Solution code:
S = input()

flag = True
while len(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:
        flag = False
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
i=0
while i<=len(S):
    if i==len(S):
        print("YES")
        exit()
    if S[i:i+11] == "dreameraser":
        i+=11
    elif S[i:i+10] == "dreamerase":
        i+=10
    elif S[i:i+7] == "dreamer":
        i+=7
    elif S[i:i+6] == "eraser":
        i+=6
    elif S[i:i+5] in ["dream","erase"]:
        i+=5
    else:
        print("NO")
        exit()

Submission status: Accepted

Solution code:
S=input()
i=0
while i<=len(S):
    if i==len(S):
        print("YES")
        exit()

    if S[i:i+11] == "dreameraser":
        i+=11
        continue
    elif S[i:i+10] == "dreamerase":
        i+=10
        continue
    elif S[i:i+7] == "dreamer":
        i+=7
        continue
    elif S[i:i+6] == "eraser":
        i+=6
        continue
    elif S[i:i+5] in ["dream","erase"]:
        i+=5
        continue
    else:
        print("NO")
        exit()

Submission status: Accepted

Solution code:
S=input()
i=0
while i<=len(S):
    if i==len(S):
        print("YES")
        exit()
    if S[i:i+11] == "dreameraser":
        i+=11
        continue
    elif S[i:i+10] == "dreamerase":
        i+=10
        continue
    elif S[i:i+7] == "dreamer":
        i+=7
        continue
    elif S[i:i+6] == "eraser":
        i+=6
        continue
    elif S[i:i+5] in ["dream","erase"]:
        i+=5
        continue
    else:
        print("NO")
        exit()
print("NO")

Submission status: Accepted

Solution code:
import sys
S = str(input())
while S != '':
    if (S[:5] == 'dream' and S[5:11] == 'eraser') or (S[:5] == 'dream' and S[5: 10] == 'erase') or (S[:5] == 'dream' and S[5:] == '') or (S[:5] == 'dream' and S[5:10] == 'dream'):
        S = S[5:]
    elif (S[:5] == 'erase' and S[5:] != '' and S[5] != 'r') or (S[:5] == 'erase' and S[5:] == ''):
        S = S[5:]
    elif S[:6] == 'eraser':
        S = S[6:]
    elif S[:7] == 'dreamer':
        S = S[7:]
    else:
        print('NO')
        sys.exit()
        break
        
print('YES')

Submission status: Accepted

Solution code:
import re  # 正規表現, findall('正規表現', 文字列), search('正規表現', 文字列)
import sys # プログラム終了：sys.exit()
# sys.setrecursionlimit(10**6) # 再帰呼び出しの上限を上げる

def i_input(): return int(input())
def s_input(): return map(int,input().split())
def l_input(): return list(map(int, input().split()))
# 文字列のまま受け取りたいときはinput()

def main():
    S = input()

    while 1:
        if S == '':
            print('YES')
            sys.exit()
        elif end_match('dreamer', S):
            S = S[:-7]
            # print('a', S)
        elif end_match('eraser', S):
            S = S[:-6]
            # print('b', S)
        elif end_match('dream', S):
            S = S[:-5]
            # print('c', S)
        elif end_match('erase', S):
            S = S[:-5]
            # print('d', S)
        else:
            print('NO')
            sys.exit()

def end_match(query, S):
    length = len(query)
    end = S[-length:]
    # print(query, end)
    if end == query:
        return True
    else:
        return False

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()[::-1]
a,b,c,d = "dream"[::-1],"dreamer"[::-1],"erase"[::-1],"eraser"[::-1]

while s:
  if s[0:7] == b:
    s = s.replace(b,"",1)
  elif s[0:6] == d:
    s = s.replace(d,"",1)
  elif s[0:5] == a or s[0:5] == c:
    s = s.replace(s[0:5],"",1)
  else:
    print("NO")
    break

if s == "":
  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 S == "":
    print('YES')
else:
    print("NO")

Submission status: Accepted

Solution code:
def word_break(s, words):
    ok = [True]
    word_length = max(len(word) for word in words)
    for i in range(1, len(s) + 1):
        ok += any(ok[j] and s[j:i] in words for j in range(max(0, i - word_length), i)),
    return ok[-1]


s = input()
words = {"eraser", "erase", "dreamer", "dream"}
print("YES" if word_break(s, words) else "NO")

Submission status: Accepted

Solution code:
def word_break(s, words):
    ok = [True]
    word_length = max(len(word) for word in words)
    for i in range(1, len(s)+1):
        ok += any(ok[j] and s[j:i] in words for j in range(max(0, i - word_length), i)),
    return ok[-1]
 
 
s = input()
words = ["eraser", "erase", "dreamer", "dream"]
print("YES" if word_break(s, words) else "NO")

Submission status: Accepted

Solution code:
s = input()
s = s.replace('eraser','z')
s = s.replace('erase','z')
s = s.replace('dreamer','z')
s = s.replace('dream','z')
for  S in s:
    if S != 'z':
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    S = input()
    A = ['eraser', 'erase', 'dreamer', 'dream']
    for x in A:
        S = S.replace(x, '')
    if S == '':
        print('YES')
    else:
        print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()[::-1]
l = ["resare","esare","remaerd","maerd"]
i = 0

while not i == len(s):
    for a in l:
        if s[i:i+len(a)] == a:
            i += len(a)
            break
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()

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

  while True:
    a=s[-5:]
    b=s[-7:]
    c=s[-6:]

    if a==l[0]:
      s=s[:-5]
    elif b==l[1]:
      s=s[:-7]
    elif a==l[2]:
      s=s[:-5]
    elif c==l[3]:
      s=s[:-6]
    else:
      if s=='':
        return 'YES'
      else:
        return 'NO'

print(main())

Submission status: Accepted

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



def solve(s):
  s = s.replace("dream","D")
  s = s.replace("erase","E")
  s = s.replace("Der","")
  s = s.replace("Er","")
  s = s.replace("D","")
  s = s.replace("E","")
  if len(s) == 0:
    return "YES"
  else:
    return "NO"

if __name__ == "__main__":
  S = str(input())
  print(solve(S))

Submission status: Accepted

Solution code:
S = input()
flag = True
while flag:
    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]
    elif len(S)==0:
        break
    else:
        flag = False

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - 白昼夢 / Daydream
https://atcoder.jp/contests/abc049/tasks/arc065_a

"""
import sys


def solve(S):
    while S:
        if S.endswith('dreamer'):
            S = S[:-7]
        elif S.endswith('eraser'):
            S = S[:-6]
        elif S.endswith('dream'):
            S = S[:-5]
        elif S.endswith('erase'):
            S = S[:-5]
        else:
            return 'NO'
    return 'YES'


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
s = input()
tt = ['dream', 'dreamer', 'erase', 'eraser']
t = ''
i = len(s) - 1
while (i > 0):
    if s[i] == 'm':
        t = tt[0] + t
        i -= 5
    elif s[i] == 'e':
        t = tt[2] + t
        i -= 5
    elif s[i] == 'r':
        if s[i - 2] == 'm':
            t = tt[1] + t
            i -= 7
        elif s[i - 2] == 's':
            t = tt[3] + t
            i -= 6
        else:
            break
    else:
        break
if s == t:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

S = str(input())
S = list(S)
S.reverse()
S = "".join(S)

def check(T):
    if len(S) == 0:
        return 1
    adds = ["maerd","remaerd","esare","resare"]
    q = copy.deepcopy(adds)
    while len(q) > 0:
        t = q.pop()
        if t == S:
            return 1
        for add in adds:
            if S[len(t):len(t+add)] == add:
                q.append(t+add)
    return 0

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

Submission status: Accepted

Solution code:
# 9
# 英小文字からなる文字列が与えられ、空文字にdream dreamer erase eraser のいずれかを追加することでその文字列が生成できるかを判定する。
a = str(input())
tmp = ''
for i in range(len(a)):
    tmp = a[len(a)-1] + tmp
    a = a[:-1]
    if tmp == 'dream' or tmp == 'dreamer' or tmp == 'erase' or tmp == 'eraser':
        tmp = ''

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

Submission status: Accepted

Solution code:
S = input()
T_list = ['dream', 'eraser', 'dreamer', 'erase']
S = S[::-1]
while len(S) > 0:
    if S[:5] == 'maerd' or S[:5] == 'esare':
        S = S[5:]
    elif S[:6] == 'resare':
        S = S[6:]
    elif S[:7] == 'remaerd':
        S = S[7:]
    else:
        break
if len(S) > 0:
    print('NO')
else:
    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()

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

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

S = S[::-1]

word_list1 = "dream"
word_list2 = "dreamer"
word_list3 = "erase"
word_list4 = "eraser"

s = ""
ans = ""

word_list = [word_list1[::-1],word_list2[::-1],word_list3[::-1],word_list4[::-1]]

for i in S:
    s += i
    if s in word_list:
        ans += s
        s = ""

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    S = str(input())
    word_list = ['dream', 'dreamer', 'erase', 'eraser']
    rev_S = S[::-1]
    word_list = list(map(lambda x : x[::-1], word_list))

    answer = 'YES'
    while len(rev_S) >= 1:
        for i in range(len(word_list)):
            word = word_list[i]
            if rev_S.startswith(word):
                rev_S = rev_S[len(word)::]
                break
            elif i == len(word_list)-1:
                answer = 'NO'
                break
        if answer == 'NO':
            break

    print(answer)

Submission status: Accepted

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