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:
L=["dream","dreamer","erase","eraser"]
S=input()
t=""
a,b=0,0

while len(t)<len(S):
  if S[a:a+7]=="dreamer" and S[a+5:a+8]!="era":
    t=t+"dreamer"
    a=a+7
  elif S[a:a+6]=="eraser":
    t=t+"eraser"
    a=a+6
  elif S[a:a+5]=="dream":
    t=t+"dream"
    a=a+5
  elif S[a:a+5]=="erase":
    t=t+"erase"
    a=a+5
  else:
    print("NO")
    break

if len(t)==len(S):
  print("YES")

Submission status: Accepted

Solution code:
s=input()
s=s.replace("dream","D")
s=s.replace("erase","E")
s=s.replace("Der","M")
s=s.replace("Er","M")
s=s.replace("D","M")
s=s.replace("E","M")
s=s.replace("M","")
if s:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
import sys

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

d ='maerd'
dr = 'remaerd'
e = 'esare'
er = 'resare'

i = 0
while True:
    try:
        if s[i:i+5] == d or s[i:i+5] == e:
            i += 5
            if i == len(s):
                print('YES')
                sys.exit(0)
        
        elif s[i:i+6] == er:
            i += 6
            if i == len(s):
                print('YES')
                sys.exit(0)
        
        elif s[i:i+7] == dr:
            i += 7
            if i == len(s):
                print('YES')
                sys.exit(0)
            
        else:
            print('NO')
            sys.exit(0)
            
    except Exception as err:
        print('NO')
        sys.exit(0)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    S = read().decode('utf-8')
    S = list(S.replace('\n', ''))[::-1]
    T = [
            list('dream')[::-1],
            list('dreamer')[::-1],
            list('erase')[::-1],
            list('eraser')[::-1]
        ]

    while len(S) != 0:
        if S[0:5] == T[0] or S[0:5] == T[2]:
            del S[0:5]
        elif S[0:7] == T[1]:
            del S[0:7]
        elif S[0:6] == T[3]:
            del S[0:6]
        else:
            print('NO')
            sys.exit()

    print('YES')


main()

Submission status: Accepted

Solution code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
S = input().rstrip()
S = S[::-1]

words = ["dream","dreamer","erase","eraser"]
for i in range(4):
    words[i] = words[i][::-1]

i = 0
while i < len(S):
    for w in words:
        l = len(w)
        if w == S[i:i+l]:
            i += l
            break
    else:
        print("NO")
        sys.exit()

print("YES")

Submission status: Accepted

Solution code:
def rev (s):
    _re=''.join(list(reversed(s)))
    return _re

name = ['dream','dreamer','eraser','erase']
S = input()
S_re = rev(S)
i=0
can = True
while i < len(S_re):
    for div in name:
        can2 = False
        if len(S_re[i:]) >= len(div):
           if S_re[i:i+len(div)]==rev(div) :
                i+=len(div)
                can2 = True
                break
    if not can2 :
        can = False
        break


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

Submission status: Accepted

Solution code:
s=input()[::-1]
words=["dreamer","eraser","dream","erase"]
add=0
while add!=len(s):
    cnt=0
    for i in words:
        length=len(i)
        word=s[add:add+length][::-1]
        if word==i:
            add +=length
            break
        else:cnt +=1
    if cnt==4:print("NO");exit()
print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def examC():
    St = S()
    t = ["dream", "dreamer", "erase", "eraser"]
    i = len(St)-1
    cur = ""
    while i>=0:
#        print(cur)
        cur = St[i] + cur
        i -=1
        if cur in t:
            cur = ""
    if len(cur)==0:
        ans = "YES"
    else:
        ans = "NO"
    print(ans)


import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Accepted

Solution code:

T = ["dream", "dreamer", "erase", "eraser"]
S = input()

while len(S) >= 5:
    S_len = len(S)
    key1 = S[S_len-5:]
    key2 = S[S_len-6:]
    key3 = S[S_len-7:]

    if key1 == T[0] or key1 == T[2]:
        S = S[:S_len-5]
    elif key2 == T[3]:
        S = S[:S_len-6]
    elif key3 == T[1]:
        S = S[:S_len-7]
    else:
        break

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

Submission status: Accepted

Solution code:
import sys

def main():
    S = list(input())
    S.reverse()
    words = ['resare', 'esare', 'remaerd', 'maerd']
    while len(S) > 0:
        deleted = False
        for word in words:
            if len(S) >= len(word) and ''.join(S[0:len(word)]) == word:
                del S[0:len(word)]
                deleted = True
        if deleted is False:
            print('NO')
            sys.exit()

    print('YES')

main()

Submission status: Accepted

Solution code:
s= input()
u= s[::-1]
 
k=["resare","esare","remaerd","maerd"]
 
l=u.replace("resare","")
d=l.replace("esare","")
h=d.replace("remaerd","")
w=h.replace("maerd","")
  
    
if w:
  print("NO")
  
else:
  print("YES")

Submission status: Accepted

Solution code:
# coding: utf-8

s = input().rstrip()
s = s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")

if not s:
    print("YES")
elif s:
    print("NO")

Submission status: Accepted

Solution code:
s = list(input())
x = []
i = 0
while(len(x)<len(s)):
    if s[i] == 'd':
        x += ['d','r','e','a','m']
        i = min(i+5,len(s)-1)
        if s[i] == 'e':
            x += ['e','r']
            i += 2
    elif s[i] == 'e':
        x += ['e','r','a','s','e']
        i = min(i+5,len(s)-1)
        if s[i] == 'r':
            x += 'r'
            i += 1
    elif s[i] == 'a':
        x += ['a','s','e']
        i = min(i+3,len(s)-1)
        if s[i] == 'r':
            x += 'r'
            i += 1
    else:
        break
print('YES' if s == x else 'NO')

Submission status: Accepted

Solution code:
S=input()
f=True
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:
        f=False
        break
print('YES' if f else 'NO')

Submission status: Accepted

Solution code:
S = input()[::-1]
i = 0
flag = True
while i < len(S):
    if S[i:i+5] == "maerd":
        i += 5
    elif S[i:i+7] == "remaerd":
        i += 7
    elif S[i:i+5] == "esare":
        i += 5
    elif S[i:i+6] == "resare":
        i += 6
    else:
        flag = False
        break

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
rev_S = list(reversed(S))


while len(rev_S) >= 5:
    if rev_S[0] == "m" and rev_S[0:5] == ['m', 'a', 'e', 'r', 'd']:
        del rev_S[:5]
    elif rev_S[0] == "e" and rev_S[0:5] == ['e', 's', 'a', 'r', 'e']:
        del rev_S[:5]
    elif rev_S[0] == "r" and rev_S[0:7] == ['r', 'e', 'm', 'a', 'e','r', 'd']:    
        del rev_S[:7]
    elif rev_S[0] == "r" and rev_S[0:6] == ['r', 'e', 's', 'a','r', 'e']:    
        del rev_S[:6]
    else:
        break
if len(rev_S) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = input()

i = 0
while i < len(s):
    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] == 'dream' or s[i:i+5] == 'erase':
        i += 5
    else:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

Solution code:
S = input()
divide = ["dream", "dreamer", "erase", "eraser"]
S = S[::-1]
divide = [divide[i][::-1] for i in range(4)]
 
while len(S) > 0:
    for i in range(4):
        if S[:len(divide[i])] == divide[i]:
            flag = "YES"
            S = S[len(divide[i]):]
            break
        else:
            flag = "NO"
    if flag == "NO":
        break

print(flag)

Submission status: Accepted

Solution code:
a=input()
l=["dreamer","eraser","dream","erase"]
for i in range(len(a)//5):
    for i in l:
        if a[-7:]==i:
            a=a[:-7]
        elif a[-6:]==i:
            a=a[:-6]
        elif a[-5:]==i:
            a=a[:-5]
        else:
            pass
if len(a)==0: 
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S=list(reversed(input()))
N=len(S)
i=0
while i<N:
  if N-i<=4:
    print("NO")
    exit()
    
  elif N-i<=5:
    if S[i]=="m" and S[i+1]=="a" and S[i+2]=="e" and S[i+3]=="r" and S[i+4]=="d":
      i+=5
    elif S[i]=="e" and S[i+1]=="s" and S[i+2]=="a" and S[i+3]=="r" and S[i+4]=="e":
      i+=5
    else:
      print("NO")
      exit()
  
  elif N-i<=6:
    if S[i]=="m" and S[i+1]=="a" and S[i+2]=="e" and S[i+3]=="r" and S[i+4]=="d":
      i+=5
    elif S[i]=="e" and S[i+1]=="s" and S[i+2]=="a" and S[i+3]=="r" and S[i+4]=="e":
      i+=5
    elif S[i]=="r" and S[i+1]=="e" and S[i+2]=="s" and S[i+3]=="a" and S[i+4]=="r" and S[i+5]=="e":
      i+=6
    else:
      print("NO")
      exit()
      
  else:
    if S[i]=="m" and S[i+1]=="a" and S[i+2]=="e" and S[i+3]=="r" and S[i+4]=="d":
      i+=5
    elif S[i]=="e" and S[i+1]=="s" and S[i+2]=="a" and S[i+3]=="r" and S[i+4]=="e":
      i+=5
    elif S[i]=="r" and S[i+1]=="e" and S[i+2]=="s" and S[i+3]=="a" and S[i+4]=="r" and S[i+5]=="e":
      i+=6
    elif S[i]=="r" and S[i+1]=="e" and S[i+2]=="m" and S[i+3]=="a" and S[i+4]=="e" and S[i+5]=="r" and S[i+6]=="d":
      i+=7
    else:
      print("NO")
      exit()
  
    
print("YES")

Submission status: Accepted

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

for i in l:
  s = s.replace(i,'')

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

Submission status: Accepted

Solution code:
s = input()

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

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

Submission status: Accepted

Solution code:
import sys

#+++++
		
def main():
	s = input()
	ww=['dream','dreamer','erase','eraser']
	
	s=s[::-1]
	wwr=[w[::-1] for w in ww]
	#print(wwrs)
	while len(s)>0:
		#pa(s)
		is_ok=False
		for w in wwr:
			ll=len(w)
			ss=s[:ll]
			#pa((2,ss,w))
			if ss == w:
				is_ok=True
				#pa((1,ss,ll))
				s=s[ll:]
		if not is_ok:
			print('NO')
			return 
		
	print('YES')
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


def main():
    S = input()

    while len(S):
        lens = len(S)
        if S[-len(dreamer) :] == dreamer:
            S = S[: -len(dreamer)]
        if S[-len(eraser) :] == eraser:
            S = S[: -len(eraser)]
        if S[-len(dream) :] == dream:
            S = S[: -len(dream)]
        if S[-len(erase) :] == erase:
            S = S[: -len(erase)]
        if lens == len(S):
            print("NO")
            return
    print("YES")
    return


main()

Submission status: Accepted

Solution code:
dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


def main():
    S = input()
    i = len(S)
    while 0 < i:
        pre = i
        if S[i - len(dreamer):i] == dreamer:
            i -= len(dreamer)
        if S[i - len(eraser):i] == eraser:
            i -= len(eraser)
        if S[i - len(dream):i] == dream:
            i -= len(dream)
        if S[i - len(erase):i] == erase:
            i -= len(erase)
        if pre == i:
            print("NO")
            return
    print("YES")
    return


main()

Submission status: Accepted

Solution code:
dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


def main():
    S = input()

    while len(S):
        lens = len(S)
        if S[-len(dreamer) :] == dreamer:
            S = S[: -len(dreamer)]
        if S[-len(eraser) :] == eraser:
            S = S[: -len(eraser)]
        if S[-len(dream) :] == dream:
            S = S[: -len(dream)]
        if S[-len(erase) :] == erase:
            S = S[: -len(erase)]
        if lens == len(S):
            print("NO")
            return
    print("YES")
    return


main()

Submission status: Accepted

Solution code:
S=input()
f=1
while S!='':
    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:
        f=0
        break
print(['NO','YES'][f])

Submission status: Accepted

Solution code:
dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


def main():
    S = input()

    while len(S):
        lens = len(S)
        if S[ - len(dreamer):] == dreamer:
            S = S[:- len(dreamer)]
        elif S[-len(eraser):] == eraser:
            S = S[:- len(eraser)]
        elif S[-len(dream):] == dream:
            S = S[:-len(dream)]
        elif S[-len(erase):] == erase:
            S = S[:-len(erase)]
        if lens == len(S):
            print("NO")
            return
    print("YES")
    return


main()

Submission status: Accepted

Solution code:
dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


def main():
    S = input()

    while len(S):
        lens = len(S)
        if S[lens - len(dreamer):] == dreamer:
            S = S[: lens - len(dreamer)]
        elif S[lens - len(eraser):] == eraser:
            S = S[:lens - len(eraser)]
        elif S[lens - len(dream):] == dream:
            S = S[:lens - len(dream)]
        elif S[lens - len(erase):] == erase:
            S = S[:lens - len(erase)]
        if lens == len(S):
            print("NO")
            return
    print("YES")
    return


main()

Submission status: Accepted

Solution code:
S = input()

while True:
    if S == '':
        print('YES')
        break
    elif len(S) >= 5 and S[-5:] == 'dream':
        S = S[:-5]
    elif len(S) >= 7 and S[-7:] == 'dreamer':
        S = S[:-7]
    elif len(S) >= 5 and S[-5:] == 'erase':
        S = S[:-5]
    elif len(S) >= 6 and S[-6:] == 'eraser':
        S = S[:-6]
    else:
        print('NO')
        break

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
s.reverse()
for i in range(6):
    s.append("x")
s = "".join(s)
i = 0
word = ["maerd", "esare", "resare","remaerd"]
while i<n:
    if s[i:i+5]==word[0]:
        i+=5
    elif s[i:i+5]==word[1]:
        i+=5
    elif s[i:i+6]==word[2]:
        i+=6
    elif s[i:i+7]==word[3]:
        i+=7
    else:
        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('NO')
else:
  print('YES')

Submission status: Accepted

Solution code:
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
mod=10**9+7
def swap(a,b):
    c=a
    a=b
    b=c
    return a,b
def factorial(x): #階乗計算
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): #約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): #素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト atcoder
    # ord(c) chr(2) alphabet <=> number
    s=list(input())
    s.reverse()
    i=0
    while i < len(s):
        if i<=len(s)-5 and ''.join(s[i:i+5]) == "maerd":
            i+=5
        elif i<=len(s)-7 and ''.join(s[i:i+7]) == "remaerd":
            i+=7
        elif i<=len(s)-5 and ''.join(s[i:i+5]) == "esare":
            i+=5
        elif i<=len(s)-6 and ''.join(s[i:i+6]) == "resare":
            i+=6
        else:
            print("NO")
            return
    print("YES")
main()

Submission status: Accepted

Solution code:
S = input().strip()
cur = 0
flag = 0
while cur<len(S):
    if S[cur:cur+11]=="dreameraser":
        cur += 11
    elif S[cur:cur+10]=="dreamerase":
        cur += 10
    elif S[cur:cur+7]=="dreamer":
        cur += 7
    elif S[cur:cur+6]=="eraser":
        cur += 6
    elif S[cur:cur+5]=="dream" or S[cur:cur+5]=="erase":
        cur += 5
    else:
        flag = 1
        break
if flag==0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
def main():
    s=input()
    rs=s[::-1]
    c1="maerd"
    c2="remaerd"
    c3="esare"
    c4="resare"
    t = ""
    cc=0
    while cc < len(rs):
        if rs[cc]=="m":
            t = t+c1
            cc += 5
        elif rs[cc]=="e":
            t = t+c3
            cc += 5
        elif rs[cc] =="r":
            if len(rs[cc:]) < 3:
                return "NO"
            elif rs[cc:cc+3] == "rem":
                t = t+c2
                cc += 7
            elif rs[cc:cc+3] == "res":
                t = t+c4
                cc += 6
            else:
                return "NO"
        else:
            return "NO"
    if rs == t:
        return "YES"
    else:
        return "NO"

print(main())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    S = input()
    
    aa = "dream"
    aa = aa[::-1]
    bb = "dreamer"
    bb = bb[::-1]
    cc = "erase"
    cc = cc[::-1]
    dd = "eraser"
    dd = dd[::-1]
    
    S = S[::-1]
    
    while True:
        if len(S) == 0:
            break
            
        if len(S) < 5:
            print("NO")
            sys.exit()
        
        if S[:5] == aa or S[:5] == cc:
            S = S[5:]
        elif S[:6] == dd:
            S = S[6:]
        elif S[:7] == bb:
            S = S[7:]
        else:
            print("NO")
            sys.exit()
            
    print("YES")
    
    
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n = input()
v=n.replace('dream', 'A').replace('erase', 'B')
ans=v.replace('Aer','').replace('Br','').replace('A','').replace('B','')
if len(ans) == 0:
  print('YES')
else:
  print('NO')

Submission status: Accepted

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

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(S: str):
    S = S[::-1]
    while len(S)>4:
        if S[:6]=="resare":
            S= S[6:]
        elif S[:5] == "esare" or S[:5]== "maerd":
            S=S[5:]
        elif S[:7] == "remaerd":
            S=S[7:]
        else:
            print(NO)
            return 
        
    
    if len(S) == 0:
        print(YES)
    else:
        print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']
words = sorted(words, reverse=True)
print()
for word in words:
    if word in s:
        s = s.replace(word, "")

if not s:
    ans = "YES"
else:
    ans = "NO"

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

while True:
  if x[:5] == "maerd":
    x = x[5:]
  elif x[:7] == "remaerd":
    x = x[7:]
  elif x[:5] == "esare":
    x = x[5:]
  elif x[:6] == "resare":
    x = x[6:]
  else:
    break
    
if len(x) == 0:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
S = input()
reversed_S = ''.join(list(reversed(S)))  #Sを反転した文字列

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

# divideの各要素も反転
for i in range(len(divide)):
    divide[i] = ''.join(list(reversed(divide[i])))

# 全体が分けきれるか
can = 1

i = 0

while i < len(S):
    can2 = 0
    for j in range(len(divide)):
        if reversed_S[i:i + len(divide[j])] == divide[j]:
            can2 = 1
            i += len(divide[j])

    if can2 == 0:
        can = 0
        break

if can == 1:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import sys

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

d ='maerd'
dr = 'remaerd'
e = 'esare'
er = 'resare'

i = 0
while True:
    try:
        if s[i:i+5] == d or s[i:i+5] == e:
            i += 5
            if i == len(s):
                print('YES')
                sys.exit(0)
        
        elif s[i:i+6] == er:
            i += 6
            if i == len(s):
                print('YES')
                sys.exit(0)
        
        elif s[i:i+7] == dr:
            i += 7
            if i == len(s):
                print('YES')
                sys.exit(0)
            
        else:
            print('NO')
            sys.exit(0)
            
    except Exception as err:
        print('NO')
        sys.exit(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())

if "erase" in s:
  s = s.replace("erase", "E")
if "dream" in s:
  s = s.replace("dream", "D")

if "Er" in s:
  s = s.replace("Er", "")
if "Der" in s:
  s = s.replace("Der", "")

if "E" in s:
  s = s.replace("E", "")
if "D" in s:
  s = s.replace("D", "")

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

Submission status: Accepted

Solution code:
s_list = list(input())

kws = [list(kw) for kw in ["dream", "dreamer", "erase", "eraser"]]

memo = [0 for _ in range(len(s_list)+1)]
memo[0] = 1
for i in range(len(s_list)):
    if memo[i] == 1:
        for kw in kws:
            l = len(kw)
            if s_list[i:i+l] == kw:
                memo[i+l] = 1

if memo[-1] == 1:
    print("YES")
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input()

def check(t):
  if len(t) >= 5 and (t[-5:] == 'dream' or t[-5:] == 'erase'):
    return True,t[:-5]
  elif len(t) >=6 and t[-6:] == 'eraser':
    return True,t[:-6]
  elif len(t) >= 7 and t[-7:] == 'dreamer':
    return True,t[:-7]
  else:
    return False,t

while(len(S) > 0):
  flag,S = check(S)
  if not flag:
    print('NO')
    exit()
print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:

s = list(input())
s.reverse()
words = ["dream","dreamer","erase","eraser"]
stack = []
for t in s :
	stack.append(t)
	for word in words :
		if list(reversed(word)) == stack :
			stack = []
if stack :
	print("NO")
else:
	print("YES")

Submission status: Accepted

Solution code:
s = input()

def remove_word_from_string(string, word):
  return ''.join(string.split(word))

# listの順番は、語尾がrのワードを先にしないと最終的にrが残ってしまう
# これだとワードの種類が多くなったときなどに使えなくなってしまうので
# もっと良い方法はないものだろうか...
ls = ["eraser", "erase", "dreamer", "dream"]

for word in ls:
  s = remove_word_from_string(s, word)
  
ans = "YES" if s == '' else "NO"

print(ans)

Submission status: Accepted

Solution code:
s = input()

def remove_word_from_string(string, word):
  return ''.join(string.split(word))

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

for word in ls:
  s = remove_word_from_string(s, word)
  
ans = "YES" if s == '' else "NO"

print(ans)

Submission status: Accepted

Solution code:
s = input()

def reverse(string):
  return ''.join(reversed(string))

def split_and_join(string, word):
  return ''.join(string.split(word))

s_r = reverse(s)
ls = ["eraser", "erase", "dreamer", "dream"]
ls_r = []
for item in ls:
  ls_r.append(reverse(item))

for word_r in ls_r:
  s_r = split_and_join(s_r, word_r)
  
ans = "YES" if s_r == '' else "NO"

print(ans)

Submission status: Accepted

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

s=s[::-1]

s=s+"WWWWWWW"

index=0
flag=True
while index<length:
    if s[index]=="m" and s[index+1]=="a" and s[index+2]=="e" and s[index+3]=="r" and s[index+4]=="d":
        index+=5
    elif s[index]=="e" and s[index+1]=="s" and s[index+2]=="a" and s[index+3]=="r" and s[index+4]=="e":
        index+=5   
    elif s[index]=="r" and s[index+1]=="e" and s[index+2]=="m" and s[index+3]=="a" and s[index+4]=="e" and s[index+5]=="r" and s[index+6]=="d":
        index+=7   
    elif s[index]=="r" and s[index+1]=="e" and s[index+2]=="s" and s[index+3]=="a" and s[index+4]=="r" and s[index+5]=="e":
        index+=6
    else:
        flag=False
        break
if flag:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
String  = input()
index = 0
flag = False
while index < len(String) - 1:
    flag = True
    if String[index:index + 7] == "dreamer":
        index += 7
        if String[index:index + 4] == "aser":
            index += 4
        elif String[index:index + 3] == "ase":
            index += 3
    elif String[index:index + 5] == "dream":
            index += 5
    elif String[index:index + 6] == "eraser":
            index += 6
            if String[index:index + 4] == "aser":
                index += 4
            elif String[index:index + 3] == "ase":
                index += 3
    elif String[index:index + 5] == "erase":
                index += 5
    else:
        flag = False
        break
if flag:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
import re

S = ''.join(list(reversed(input())))
t = re.findall("maerd|remaerd|resare|esare",S)
T = ''.join(t)
if S == T:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
import re

S = ''.join(list(reversed(input())))
t = re.findall("remaerd|maerd|resare|esare",S)
T = ''.join(t)
if S == T:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re
S = input().strip()
while True:
  #print(S)
  if len(S) == 0:
    print('YES')
    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')
    break

Submission status: Accepted

Solution code:
S = str(input())
a= [0,1,2,3]

judge = False

class E():
	def ex(self,S):
		m = S.replace('eraser' , '2')
		return m
		
class e():
	def ex(self,S):
		m = S.replace('erase' , '2')
		return m
		
class D():
	def ex(self,S):
		m = S.replace('dreamer','3')
		return m
		
class d():
	def ex(self,S):
		m = S.replace('dream','3')
		return m
		
		

a[0] = E()
a[1] = e()
a[2] = D()
a[3] = d()

for i in range(4):
	for j in range(4):
		for k in range(4):
			for l in range(4):
				m = a[i].ex(S)
				m = a[j].ex(m)
				m = a[k].ex(m)
				m = a[l].ex(m)
				
				try:
					int(m)
					print('YES')
					judge = True
				except:
					pass
				if judge == True:break
			if judge==True:break
		if judge==True:break
	if judge==True:break
	
if judge == False:
	print('NO')

Submission status: Accepted

Solution code:
# ABC049 C - 白昼夢 / Daydream
S = input()
S = S.replace('dream','A').replace('erase','B')
S = S.replace('Aer','C').replace('Br','D')

E = set()

for s in S:
    E.add(s)

ans = 'YES'
for e in E:
    if not e in ('A','B','C','D'):
        ans = 'NO'
        break
print(ans)