Problem:


Score : 300 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Another string T is initially empty.
Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:

Append one of the following at the end of T: dream, dreamer, erase and eraser.

Constraints

1≦|S|≦10^5

S consists of lowercase English letters.

Input

The input is given from Standard Input in the following format:

S

Output

If it is possible to obtain S = T, print YES. Otherwise, print NO.

Sample Input 1

erasedream

Sample Output 1

YES

Append erase and dream at the end of T in this order, to obtain S = T.

Sample Input 2

dreameraser

Sample Output 2

YES

Append dream and eraser at the end of T in this order, to obtain S = T.

Sample Input 3

dreamerer

Sample Output 3

NO



Sample input:
erasedream


Sample output:
YES

Submission status: Accepted

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    S = input().rstrip()

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

    res = 'YES'

    pre = S
    now = S

    while True:
        for i in range(4):
            word = words[i]
            N = len(word)
            M = len(now)
            if N <= M:
                r = now[M-N:]
                if r == word:
                    now = now[:M-N]
        if now == '':
            break
        elif now == pre:
            res = 'NO'
            break
        else:
            pre = now

    print(res)



main()

Submission status: Accepted

Solution code:
def hantei(s, h):
    try:
        slen = len(s)
        hlen = len(h)
        res = s.index(h, slen - hlen, slen + 1)
        return res
    except ValueError as e:
        return -1


def resolve():
    s = input()
    a = 'dream'
    b = 'dreamer'
    c = 'erase'
    d = 'eraser'
    while True:
        # 後ろから文字列検索
        # 合ったらその文字を削除
        D = hantei(s, d)
        if D > -1:
            s = s[:-len(d)]
            continue
        B = hantei(s, b)
        if B > -1:
            s = s[:-len(b)]
            continue
        C = hantei(s, c)
        if C > -1:
            s = s[:-len(c)]
            continue
        A = hantei(s, a)
        if A > -1:
            s = s[:-len(a)]
            continue
        if len(s) == 0:
            print('YES')
        else:
            print('NO')
        break
        
resolve()

Submission status: Accepted

Solution code:
X=input()

for i in range(len(X)):
    if X[-7:] == "dreamer":
        X = X[:-7]
    elif X[-6:] == "eraser":
        X = X[:-6]
    elif X[-5:] == "dream":
            X = X[:-5]
    elif X[-5:] == "erase":
        X = X[:-5]

print("YES" if X=="" else "NO")

Submission status: Accepted

Solution code:
import re

s = input()
print('YES' if re.match('^(dream|dreamer|erase|eraser)+$', s) else 'NO')

Submission status: Accepted

Solution code:
S=input().rstrip()
S=S[::-1]
T=["dream","dreamer","erase","eraser"]
for i in range(len(T)):
  T[i]=T[i][::-1]
while len(S):
  flag=False
  for t in T:
    if S.startswith(t):
      S=S[len(t):]
      flag=True
  if not flag: break
if len(S)==0:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
S = input()

R=''.join(list(reversed(S)))
#print(R)
N=len(S)

cursol=0

while True:
    if R[cursol:cursol+5] == 'maerd':
        cursol += 5
    elif R[cursol:cursol+5] == 'esare':
        cursol += 5
    elif R[cursol:cursol+7] == 'remaerd':
        cursol += 7
    elif R[cursol:cursol+6] == 'resare':
        cursol += 6
    else:
        print('NO')
        break
    if cursol == N:
        print('YES')
        break

Submission status: Accepted

Solution code:
s=input()
n=len(s)
i=1
for j in range(n//5):
    if s[-i:-i-5:-1]=="maerd":
        i+=5
 
    if s[-i:-i-5:-1]=="esare":
        i+=5

    if s[-i:-i-6:-1]=="resare":
        i+=6

    if s[-i:-i-7:-1]=="remaerd":
        i+=7

    if i==n+1:
        print("YES")
        break

if i != n+1:
    print("NO")

Submission status: Accepted

Solution code:
s=input()
n=len(s)
i=1
for j in range(n):
    if s[-i:-i-5:-1]=="maerd":
        i+=5
 
    if s[-i:-i-5:-1]=="esare":
        i+=5

    if s[-i:-i-6:-1]=="resare":
        i+=6

    if s[-i:-i-7:-1]=="remaerd":
        i+=7

    if i==n+1:
        print("YES")
        break

if i != n+1:
    print("NO")

Submission status: Accepted

Solution code:
s=input()
n=len(s)
dp=list('false'*n)
dp[0]="true"
if s[0:5]=="dream" or s[0:5]=="erase":
    for i  in range(5):
        dp[i]="true"
if s[0:6]=="eraser":
    for i  in range(6):
        dp[i]="true"
if s[0:7]=="dreamer":
    for i in range(7):
        dp[i]="true"


for i in range(5,n):

    if dp[i-5]=="true" and (s[i-4:i+1]=="dream" or s[i-4:i+1]=="erase"):
        dp[i]="true"
    if dp[i-6]=="true" and s[i-5:i+1]=="eraser":
        dp[i]="true"
    if dp[i-7]=="true" and s[i-6:i+1]=="dreamer":
        dp[i]="true"

if dp[n-1]=="true":
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s=input()
cnt=0
for i in range(len(s)):
    if s[-7:] == 'dreamer':
        s=s[:-7]
    elif s[-6:] == 'eraser':
        s=s[:-6]
    elif s[-5:] =='erase'or s[-5:]=='dream':
        s=s[:-5]
    elif s=='':
        break
    else:
        cnt+=1
        break
if cnt==0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
g=[]

def  jdream(l,i):
    if len(l)>=i+5:

        if l[i:i+5]=="dream":
            i=i+5
            if i==len(l):
                g.append("Y")
                return
     
            else:
                jer(l,i)
                jdream(l,i)
                return
        else:
            
            return
    else:
        
        return

def jerase(l,i):
    if len(l)>=i+5:

        if l[i:i+5]=="erase":
            i=i+5
            if i==len(l):
                g.append("Y")
                return
            else:
                jr(l,i)
                jerase(l,i)
                jdream(l,i)
                return
        else:
            
            return
    else:
        
        return

def jer(l,i):
    if len(l)>=i+2:

        if l[i:i+2]=="er":
            i=i+2
            if i==len(l):
                g.append("Y")
                return
            else:
                jase(l,i)
                jerase(l,i)
                jdream(l,i)
                return
        else:
            
            return
    else:
        
        return

def jase(l,i):
    if len(l)>=i+3:

        if l[i:i+3]=="ase":
            i=i+3
            if i==len(l):
                g.append("Y")
                return
            else:
                jdream(l,i)
                jerase(l,i)
                jr(l,i)
                return
        else:
            
            return
    else:
        
        return

def jr(l,i):
    if len(l)>=i+1:

        if l[i:i+1]=="r":
            i=i+1
            if i==len(l):
                g.append("Y")
                return
            else:
                jdream(l,i)
                jerase(l,i)
                return
        else:
            
            return

    else:
        
        return

s=input()
n=0
jerase(s,n)
n=0
jdream(s,n)


if 'Y' in g:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
#abc049 c
s=input()
divide=["dream","dreamer","erase","eraser"]

s=s[::-1]
for i,x in enumerate(divide):
    divide[i]=x[::-1]

ans=True
i=0
while i<len(s):
    flag=False
    for x in divide:
        lx=len(x)
        if s[i:i+lx] in divide:
             flag=True
             i+=lx
    if flag==False:
        ans=False
        break
if flag:
     print("YES")
else:
     print("NO")

Submission status: Accepted

Solution code:
s = input()

lis = ['dream', 'dreamer', 'erase', 'eraser']
rev_lis = []

for e in lis:
	rev_lis.append(e[::-1])

rev_s = s[::-1]

while True:
	if rev_s == '':
		print('YES')
		exit()
	tmp1 = rev_s[0:5]
	tmp2 = rev_s[0:6]
	tmp3 = rev_s[0:7]
	if tmp1 in rev_lis:
		rev_s = rev_s[5:]
	elif tmp2 in rev_lis:
		rev_s = rev_s[6:]
	elif tmp3 in rev_lis:
		rev_s = rev_s[7:]
	else:
		print('NO')
		exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s=input()
while 0<len(s):
    if s[-5:]=='erase' or s[-5:]=='dream':
        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()
i = len(S)
while i > 0:
    if S[i - 5:i] in {'dream', 'erase'}:
        i -= 5
    elif S[i - 6:i] == 'eraser':
        i -= 6
    elif S[i - 7:i] == 'dreamer':
        i -= 7
    else:
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

Solution code:
s_init = input()
s_list = list(reversed(s_init))
s = ''.join(s_list)
t = ""
words = ["maerd", "remaerd", 'esare', 'resare']
s_list = list(s)
t_list = list(t)
while s != t:
    t_fixed = t
    if len(s_list) < len(t_list):
        break
    elif t == 'gameover':
        break
    else:
        for word in words:
            if s.startswith(t + word):
                t = t + word
                break
        if t == t_fixed:
            t = 'gameover'
if s == t:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
words = ['dream', 'dreamer', 'erase', 'eraser']
dp = [0] * (len(S) + 1)
dp[0] = 1
ans = 'NO'

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C
s = input()

r = ''
for i in range(len(s)-1, -1, -1):
    r = s[i] + r
    if r == 'dream':
        r = ''
    if r == 'dreamer':
        r = ''
    if r == 'erase':
        r = ''
    if r == 'eraser':
        r = ''
        
if r == '':
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input()
strs = ["erase", "eraser", "dreamer","dream"]
rtss = [s[::-1] for s in strs]
S = S[::-1]

ind = 0
while True:
    # print(ind,S[ind])
    if S[ind:ind+5] in rtss:
        ind += 5
    elif S[ind:ind+6] in rtss:
        ind += 6
    elif S[ind:ind+7] in rtss:
        ind +=7
    else:
        print("NO")
        exit()
    if ind == len(S):
        print("YES")
        exit()

Submission status: Accepted

Solution code:
S = input()
Sr = S[::-1]
token = ['dream', 'dreamer', 'erase', 'eraser']
tokenr = list(map(lambda x:x[::-1], token))
t = ''
while(len(Sr)>0):
    notFound = True
    for w in tokenr:
        if w==Sr[:len(w)]:
            Sr = Sr[len(w):]
            t+=w
            notFound = False
    if notFound:
        break
if Sr == '':
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    S = Scanner.string()

    def solve(S):
        while len(S) > 0:
            if len(S) >= 7:
                if S[-7:] == 'dreamer':
                    S = S[:-7]
                    continue
            if len(S) >= 6:
                if S[-6:] == 'eraser':
                    S = S[:-6]
                    continue
            if len(S) >= 5:
                if S[-5:] == 'erase':
                    S = S[:-5]
                    continue
                elif S[-5:] == 'dream':
                    S = S[:-5]
                    continue
            return False
        return True
    print('YNEOS'[not solve(S)::2])


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()[::-1]
Tl = ["dream", 'dreamer', 'erase', 'eraser']
flg = 0

for i in range(len(Tl)):
    Tl[i] = Tl[i][::-1]
while True:
    Sl = len(S)
    for i in range(len(Tl)):
        if S.find(Tl[i]) == 0:
            S = S[len(Tl[i]):]
    if len(S) == 0:
        flg = 1
        break
    elif len(S) == Sl:
        break
    else:
        pass

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

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:
c = input().rstrip('\n')

str1 = "eraser"
str2 = "erase"
str3 = "dreamer"
str4 = "dream"



c = c.replace(str1, "")
c = c.replace(str2, "")
c = c.replace(str3, "")
c = c.replace(str4, "")

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
S = ''.join(list(reversed([c for c in S])))

while S:
    if S[:7] == 'remaerd':
        S = S[7:]
    elif S[:6] == 'resare':
        S = S[6:]
    elif S[:5] == 'maerd':
        S = S[5:]
    elif S[:5] == 'esare':
        S = S[5:]
    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 s == '':
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import sys
s=input()
i=len(s)-1
while True:
    if i<0:
        print('YES')
        sys.exit()
    if i>=4:
        if s[i-4:i+1]=='dream':
            i-=5
            continue
        elif s[i-4:i+1]=='erase':
            i-=5
            continue
    if i>=5 and s[i-5:i+1]=='eraser':
        i-=6
        continue
    if i>=6 and s[i-6:i+1]=='dreamer':
        i-=7
        continue
    print('NO')
    sys.exit()

Submission status: Accepted

Solution code:
s=input()
search=['eraser', 'erase','dreamer', 'dream']
for i in range(4):
    t=s.split(search[i])
    s=''.join(s.split(search[i]))

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

Submission status: Accepted

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

s = s.replace('/', '')
if len(s) == 0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
def we_can(s):
    ptr = 0
    while True:
        if len(s) == abs(ptr):
            return True
        else:
            if ptr == 0:
                if s[ptr-5:] == 'dream' or s[ptr-5:] == 'erase':
                    ptr -= 5
                    continue
                elif s[ptr-6:] == 'eraser':
                    ptr -= 6
                    continue
                elif s[ptr-7:] == 'dreamer':
                    ptr -= 7
                    continue
            if s[ptr-5:ptr] == 'dream' or s[ptr-5:ptr] == 'erase':
                ptr -= 5
                continue
            elif s[ptr-6:ptr] == 'eraser':
                ptr -= 6
                continue
            elif s[ptr-7:ptr] == 'dreamer':
                ptr -= 7
                continue
            return False


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

Submission status: Accepted

Solution code:
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


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


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


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    s = input().rstrip()

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

    pass


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    while True:
        match = False
        for ss in T:
            if s.endswith(ss) :
                s = s[:-1*len(ss)]
                if not s:
                    print('YES')
                    return
                match = True
                break
        if not match:
            print('NO')
            return

solution()

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()
s=s[::-1]
t=""
flag=False

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

Submission status: Accepted

Solution code:
import sys
S="".join(reversed(input()))
i=0
while i<len(S):
    if i+4<len(S) and (S[i:i+5]=="maerd" or S[i:i+5]=="esare"):
        i+=5
    elif i+5<len(S) and (S[i:i+6]=="resare"):
        i+=6
    elif i+6<len(S) and (S[i:i+7]=="remaerd"):
        i+=7
    else:
        print("NO")
        sys.exit()
print("YES")

Submission status: Accepted

Solution code:
S=input()
dp=[False]*(len(S)+1)
dp[0]=True
for i in range(len(S)):
    if i>=4 and S[i-4:i+1]=="dream":
        dp[i+1]|=dp[i-4]
    if i>=4 and S[i-4:i+1]=="erase":
        dp[i+1]|=dp[i-4]
    if i>=6 and S[i-6:i+1]=="dreamer":
        dp[i+1]|=dp[i-6]
    if i>=5 and S[i-5:i+1]=="eraser":
        dp[i+1]|=dp[i-5]
print("YES" if dp[len(S)] else "NO")

Submission status: Accepted

Solution code:
#ABC 049 C
S = input()
T = ''
S = S[::-1]
words = ["dream","dreamer","erase","eraser"]
rev_words = [w[::-1] for w in words]

flag = False
i=0
while(1):
	for w in rev_words:
		s = S[i:i+len(w)]
		if s == w:
			flag = True
			T += w
			i += len(w)
			break
	if T == S:
		ans = "YES"
		break
	if flag == False:
		ans = 'NO'
		break
	flag = False

print(ans)

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()[::-1]
devide = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
    devide[i] = devide[i] [::-1]
    
flag = True
i = 0
while i < len(S):
    flag2 = False
    for j in range(4):
        if devide[j] == S[i : i+len(devide[j])]:
            flag2 = True
            i += len(devide[j])
    
    if not flag2:
        flag = False
        break

print('YES' if flag == True else 'NO')

Submission status: Accepted

Solution code:
S=list(input())
n=len(S)-1
a=0
while n>=0:
  if S[n]=="m":
    if n<4:
      a=1
      break
    if S[n-4:n+1]==["d","r","e","a","m"]:
      n=n-5
    else:
      a=1
      break
  elif S[n]=="e":
    if n<4:
      a=1
      break
    if S[n-4:n+1]==["e","r","a","s","e"]:
      n=n-5
    else:
      a=1
      break
  elif S[n]=="r":
    if n<5:
      a=1
      break
    if n==5:
      if S[0:n+1]==["e","r","a","s","e","r"]:
        n=n-6
    else:
      if S[n-5:n+1]==["e","r","a","s","e","r"]:
        n=n-6
      elif S[n-6:n+1]==["d","r","e","a","m","e","r"]:
        n=n-7
      else:
        a=1
        break
  else:
    a=1
    break
if a==0:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
def main():
    S = input()
    N = len(S)
    ok = set(['dream','erase','dreamer','eraser'])
    if N < 8 and S not in ok:
        print("NO")
        exit()
    i = 0
    while i < N-5:
        tmp = S[i:i+5]
        if tmp == 'dream':
            if i+6 < N and S[i+5:i+7] == 'er':
                if i+7<N and S[i+7] == 'a':
                    i += 5
                else:
                    i += 7
            else:
                i += 5
        elif tmp == 'erase':
            if i+5<N and S[i+5] == 'r':
                i += 6
            else:
                i += 5
        else:
            print('NO')
            exit()
    if i < N and S[i:] not in ok:
        print('NO')
        exit()
    print('YES')

if __name__ == "__main__":
    main()

Submission status: Accepted

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

l5 = ["dream"[::-1], "erase"[::-1]]
l6 = ["eraser"[::-1]]
l7 = ["dreamer"[::-1]]

ans = "YES"

while len(s) > 4:
    if s[:5] in l5:
        s = s[5:]
    elif s[:6] in l6:
        s = s[6:]
    elif s[:7] in l7:
        s = s[7:]
    else:
        ans = "NO"
        break

print(ans)

Submission status: Accepted

Solution code:
S = input()
a = 'dream'
b = 'dreamer'
c = 'erase'
d = 'eraser'
T = S
while len(T) > 4:
    if S[len(T)-5:len(T)] == a:
        T = T[0:len(T)-5]
    elif S[len(T)-7:len(T)] == b:
        T = T[0:len(T)-7]
    elif S[len(T)-5:len(T)] == c:
        T = T[0:len(T)-5]
    elif S[len(T)-6:len(T)] == d:
        T = T[0:len(T)-6]
    else:
        break
if T == '':
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S=input()

for i in range(100000):
  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:
    pass
  if S=="":
    print("YES")
    break
else:
  print("NO")

Submission status: Accepted

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

kari = ['dream', 'dreamer', 'erase', 'eraser']
 
words = [i[::-1] for i in kari]
 
l = len(S)
cnt = ''

for i in range(l):
    cnt += S[i]
    if cnt in words:
        cnt = ''

if cnt!='':
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
S = input()

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

i = len(S)

while True:
    if S[i-5:i]==words[0] or S[i-5:i]==words[2]:
        i -= 5
    elif S[i-6:i]==words[3]:
        i -= 6
    elif S[i-7:i]==words[1]:
        i -= 7
    else:
        print('NO')
        exit()
    if i == 0:
        print('YES')
        exit()

Submission status: Accepted

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

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

words = [i[::-1] for i in kari]

l = len(S)
i = 0

while True:
    if S[i:i+5]==words[0] or S[i:i+5]==words[2]:
        i += 5
    elif S[i:i+6]==words[3]:
        i += 6
    elif S[i:i+7]==words[1]:
        i += 7
    else:
        print('NO')
        exit()
    if i == l:
        print('YES')
        exit()

Submission status: Accepted

Solution code:
#049_C
s = input()[::-1]
k = ['maerd', 'remaerd', 'esare', 'resare']

tmp = 0
flg = True
while tmp < len(s):
    check = False
    for x in k:
        if s[tmp: tmp + len(x)] == x:
            check = True
            tmp += len(x)
    if check == False:
        flg = False
        break
        
print('YES' if flg else 'NO')

Submission status: Accepted

Solution code:
s = str(input())
s = ''.join(list(reversed(s)))

t = 0
while t <= len(s):
    if s[t:t+5] == 'maerd':
        t += 5
        continue
    elif s[t:t+7] == 'remaerd':
        t += 7
        continue
    elif s[t:t+5] == 'esare':
        t += 5
        continue
    elif s[t:t+6] == 'resare':
        t += 6
        continue
    elif t == len(s):
        print('YES')
        quit()
    else:
        break
print('NO')

Submission status: Accepted

Solution code:
s=input()
s1=s.replace("eraser","0").replace("erase","0").replace("dreamer","0").replace("dream","0")
n=len(s1)
flag=False
for  i in range(0,n):
    if s1[i]!='0':
        flag=True
        break
        
if flag==False:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    Si = S[::-1]
    a = ['maerd', 'remaerd', 'esare', 'resare']
    temp = str()
    cnt = 0
    for i in Si:
        temp += i
        if temp in a:
            cnt += len(temp)
            temp = str()
    print('YES' if cnt == len(S) else 'NO')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

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

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

Submission status: Accepted

Solution code:
s = input()[::-1]
while s:
  start = len(s)
  for t in ['maerd', 'remaerd', 'esare', 'resare']:
    if t == s[:len(t)]:
      s = s[len(t):]
  if start == len(s):
    break
print("YNEOS"[len(s)>0::2])

Submission status: Accepted

Solution code:
s = input()
reverse_str = s[::-1]
word_list = ["maerd","remaerd","esare","resare"]
while(True):
    start_len = len(reverse_str)
    for word in word_list:
        if reverse_str.startswith(word):
            reverse_str = reverse_str[len(word):]
    if start_len == len(reverse_str) and start_len != 0:
        print("NO")
        exit()
    elif len(reverse_str) == 0:
        print("YES")
        exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=str(input())
s=s[::-1]
stack=""
for i in s:
  stack=i+stack
  if stack=="dream"or stack=="dreamer"or stack=="erase"or stack=="eraser":
    stack=""
  elif len(stack)>7:
    print("NO")
    exit()
print("YES")

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:
txt = input()
cands = ["dream", "dreamer", "erase", "eraser"]

success = True
while len(txt) > 0:
    flag = False

    for cand in cands:
        subtxt = txt[len(txt) - len(cand):]
        if subtxt == cand:
            txt = txt[:len(txt) - len(cand)]
            flag = True
            break

    if not flag:
        success = False
        break

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

Submission status: Accepted

Solution code:

import sys
from io import StringIO
import unittest

def yn(b):
    print("YES" if b==1 else "NO")
    return

def resolve():
    readline=sys.stdin.readline
    ss=readline().strip()
    #n,m,k=list(map(int, readline().strip().split()))
    #arr=list(map(int, readline().strip().split()))
    #n=int(readline().strip())
    ss=ss.replace("dream","D")
    ss=ss.replace("erase","E")
    ss=ss.replace("Der","DR")
    ss=ss.replace("Er","ER")
    for s in ss:
        if s not in ["D","E","R"]:
            print("NO")
            return
    print("YES")

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまでコピぺえ 
### ----------------

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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 s != "":
    if s[len(s) - 5:] == "dream" or s[len(s) - 5:] == "erase":
        s = s[:len(s) - 5]
    elif s[len(s) - 6:] == "eraser":
        s = s[:len(s) - 6]
    elif s[len(s) - 7:] == "dreamer":
        s = s[:len(s) - 7]
    else:
        ans = "NO"
        break
print(ans)