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:
st = input()
start = 0
ok = True
while start < len(st):
    if st[start] == 'd':
        if st[start: start + 5] == 'dream':
            if st[start: start + 7] == 'dreamer':
                if st[start: start + 11] == 'dreameraser':
                    start += 11
                elif st[start: start + 10] == 'dreamerase':
                    start += 10
                else:
                    start += 7
            else:
                start += 5
        else:
            ok = False
            break
    elif st[start] == 'e':
        if st[start: start + 5] == 'erase':
            if st[start: start + 6] == 'eraser':
                start += 6
            else:
                start += 5
        else:
            ok = False
            break
    else:
        ok = False
        break
if ok:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
s=input()[::-1]
p=["maerd","remaerd","resare","esare"]
while True:
  if s[:5]==p[0]:s=s[5:]
  elif s[:5]==p[3]:s=s[5:]
  elif s[:7]==p[1]:s=s[7:]
  elif s[:6]==p[2]:s=s[6:]
  else:
    if s=="":print("YES");break
    else:print("NO");break

Submission status: Accepted

Solution code:
S=list(input())
l=0
while l!=len(S):
  l=len(S)
  if S[-1]=='m' and S[-2]=='a' and S[-3]=='e' and S[-4]=='r' and S[-5]=='d':
    del S[-5:]
  if len(S)==0:
    break
  if S[-1]=='e' and S[-2]=='s' and S[-3]=='a' and S[-4]=='r' and S[-5]=='e':
    del S[-5:]
  if len(S)==0:
    break
  if S[-1]=='r' and S[-2]=='e' and S[-3]=='s' and S[-4]=='a' and S[-5]=='r' and S[-6]=='e':
    del S[-6:]
  if len(S)==0:
    break
  if S[-1]=='r' and S[-2]=='e' and S[-3]=='m' and S[-4]=='a' and S[-5]=='e' and S[-6]=='r' and S[-7]=='d':
    del S[-7:]
  if len(S)==0:
    break

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

Submission status: Accepted

Solution code:
S = input().replace("eraser", "4").replace("erase", "3").replace("dreamer", "2").replace("dream", "1")
try:
    int(S)
    print("YES")
except:
    print("NO")

Submission status: Accepted

Solution code:
def f1():
    s = input()
    while s:
        if s[-5:] in ['dream', 'erase']:
            s = s[:-5]
        elif s[-6:] == 'eraser':
            s = s[:-6]
        elif s[-7:] == 'dreamer':
            s = s[:-7]
        else:
            print('NO')
            return
    print('YES')

if __name__ == "__main__":
    f1()

Submission status: Accepted

Solution code:
s = input()

s1 = " ".join(s.split('dreameraser'))

s2 = " ".join(s1.split('dreamerase'))

s3 = " ".join(s2.split('dreamer'))

s4 = " ".join(s3.split('dream'))

s5 = " ".join(s4.split('eraser'))

s6 = " ".join(s5.split('erase'))


if s6.strip() == '':
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    s = input()
    words = ["dream", "dreamer", "erase", "eraser"]
    while len(s) > 0:
        if s[-5:] in ["dream", "erase"]:
            s = s[:-5]
        elif s[-7:] == "dreamer":
            s = s[:-7]
        elif s[-6:] == "eraser":
            s = s[:-6]
        else:
            print("NO")
            break
    if not len(s):
        print("YES")

Submission status: Accepted

Solution code:


def main():
    s = input()

    i = 0
    is_ok = True
    while i < len(s):
        if i <= len(s) < i + 7:
            if i <= len(s) < i + 4:
                is_ok = False
                break

        next_word = s[i:i+5]
        if next_word == 'dream':
            if s[i+5:i+7] == 'er':
                if s[i+7:i+8] == 'a':
                    # dream
                    i += 5
                else:
                    # dreamer
                    i += 7
            else:
                # dream
                i += 5
        elif next_word == 'erase':
            if s[i+5:i+6] == 'r':
                # eraser
                i += 6
            else:
                # erase
                i += 5
        else:
            is_ok = False
            break

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

def main2():
    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')


if __name__ == '__main__':
    #main()
    main2()

Submission status: Accepted

Solution code:


def main():
    s = input()

    i = 0
    is_ok = True
    while i < len(s):
        if i <= len(s) < i + 7:
            if i <= len(s) < i + 4:
                is_ok = False
                break

        next_word = s[i:i+5]
        if next_word == 'dream':
            if s[i+5:i+7] == 'er':
                if s[i+7:i+8] == 'a':
                    # dream
                    i += 5
                else:
                    # dreamer
                    i += 7
            else:
                # dream
                i += 5
        elif next_word == 'erase':
            if s[i+5:i+6] == 'r':
                # eraser
                i += 6
            else:
                # erase
                i += 5
        else:
            is_ok = False
            break

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=str(input())
def solve(s):
  while (s!=""):
    if s[-5:] in ["dream","erase"]:
      s=s[:-5]
    elif s[-7:]=="dreamer":
      s=s[:-7]
    elif s[-6:]=="eraser":
      s=s[:-6]
    else:
      return "NO"
  return "YES"
print(solve(s))

Submission status: Accepted

Solution code:
S = input()
U = S
T = ""
while True:
    flag = False
    for s in ["dream", "dreamer","erase","eraser"]:
        if S.endswith(s):
            S = S[:-len(s)]
            T = s + T
            flag = True
    if T == U:
        print("YES")
        break 
    elif not flag:
        print("NO")
        break

Submission status: Accepted

Solution code:
S = input()
c = ["dream","dreamer","erase","eraser"]

S = S[::-1]
c = [cc[::-1] for cc in c]

i=0
while i < len(c):
    if S.startswith(c[i]):
        S = S[len(c[i]):]
        i = 0
        continue
    i = -~i

print("NYOE S"[S==""::2])

Submission status: Accepted

Solution code:
S = input()
c = ["dream","dreamer","erase","eraser"]

S = S[::-1]
c = [cc[::-1] for cc in c]

i=0
while i < len(c):
    if S[:len(c[i])] == c[i]:
        S = S[len(c[i]):]
        i = 0
        continue
    i += 1

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

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]
li = ['maerd','remaerd','esare','resare']
check=''
for i in range(len(s)):
    check += s[i]
    if check in li:
        check=''
print('YES' if len(check)==0 else 'NO')

Submission status: Accepted

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

Submission status: Accepted

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

s = s[::-1]
words = [word[::-1] for word in words]

start=0
for i in range(1, len(s)+1):
  if s[start:i] in words:
    t+=s[start:i]
    start=i
    
if s==t:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
S = [input()]
ans = 'NO'
while S:
    S_new = []
    for s in S:
        if s[:5]=='dream'  : S_new.append(s[5:])
        if s[:7]=='dreamer': S_new.append(s[7:])
        if s[:5]=='erase'  : S_new.append(s[5:])
        if s[:6]=='eraser' : S_new.append(s[6:])
    S = S_new
    if '' in S:
        ans = 'YES'
        break

print(ans)

Submission status: Accepted

Solution code:
S = input()
reverse_S = S[::-1]
T = ""
dreamlist = ["erase","eraser","dream","dreamer"]
newlist = [dreamlist[i][::-1] for i in range(len(dreamlist))]

flg = 1
while flg >= 1:
    flg = 0
    for i in range(len(newlist)):
        if reverse_S.startswith(T + newlist[i]):
            T += newlist[i]
            flg += 1
            break
        else:
            continue
if reverse_S == T:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
l=list(input())
a=[list('dream'),list('erase')]
b=[list('eraser')]
c=[list('dreamer')]
n=len(l)
r=0
while n>=5:
    f=0
    if n>=7:
        if l[len(l)-5:] in a:
            l[len(l)-5:]=[]
            n-=5
            f+=1
        if l[len(l)-6:] in b:
            l[len(l)-6:]=[]
            n-=6
            f+=1
        if l[len(l)-7:] in c:
            l[len(l)-7:]=[]
            n-=7
            f+=1
    elif n>=6:
        if l[len(l)-5:] in a:
            l[len(l)-5:]=[]
            n-=5
            f+=1
        if l[len(l)-6:] in b:
            l[len(l)-6:]=[]
            n-=6
            f+=1
    elif n>=5:
        if l[len(l)-5:] in a:
            l[len(l)-5:]=[]
            n-=5
            f+=1
    if f==0:
        r=1
        break
if r==1 or n>0:
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    s = s.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
    print("YES" if s == "" else "NO")


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

while len(Sr) > 0:
  L = len(Sr)
  if Sr[:5] == "maerd":
      Sr = Sr[5:]
  elif L >= 7 and Sr[:7] == "remaerd":
    Sr = Sr[7:]
  elif Sr[:5] == "esare":
    Sr = Sr[5:]
  elif L >= 6 and Sr[:6] == "resare":
    Sr = Sr[6:]
  else:
    print("NO")
    exit()
print("YES")

Submission status: Accepted

Solution code:
def main():
    S = input()[::-1]
    tar = {'maerd', 'remaerd', 'esare', 'resare'}
    i = 0
    while i < len(S):
        if S[i] == 'm':
            if S[i:i+5] == 'maerd':
                i += 5
            else:
                return print("NO")
        elif S[i] == 'e':
            if S[i:i+5] == 'esare':
                i += 5
            else:
                return print("NO")
        elif S[i] == 'r':
            if S[i:i+6] == 'resare':
                i += 6
            elif S[i:i+7] == 'remaerd':
                i += 7
            else:
                return print("NO")
        else:
            return print("NO")
    print("YES")
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

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

if len(s) == 0:
    print('YES')
    sys.exit()

words = ['maerd', 'remaerd', 'esare', 'resare']
can = True

while can:
    can = False
    for word in words:
        if s.startswith(word):
            s = s[len(word):]
            can = True

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
S=input()

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

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

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 = list(input())
tmp = ''
L = len(S)
S = S[-1:-L-1:-1]
Kouho = ['maerd','remaerd','esare','resare']
ans = 0
for i in range(L):
    
    tmp += str(S[i])
    if tmp in Kouho:
        ans += len(tmp)
        tmp = ''
if ans == L:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import re
if re.match(r"^(dream|dreamer|erase|eraser)+$", input()):
  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.replace('eraser', '')
    S = S.replace('erase', '')
    S = S.replace('dreamer', '')
    S = S.replace('dream', '')
    print(YES if S == '' else NO)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
T = str(input())
cdd =["dream","dreamer","erase","eraser"]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
X=['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
S=S[::-1]
while 1:
    S2=S
    for x in X:
        if x == S[:len(x)]:
            S = S[len(x):]
    if S == '':
        print('YES')
        break
    if S2==S:
        print('NO')
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
t = ''
add_list = ['dream', 'dreamer', 'erase', 'eraser']
cur = len(s)
for i in range(len(s)):
    if s[-1 - i:cur] in add_list:
        cur = -1 - i
if -cur == len(s):
    print('YES')
else:
    print('NO')

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:
import sys
input=sys.stdin.readline

def main():
    S = input().strip()
    S = S.replace("eraser","")
    S = S.replace("erase","")
    S = S.replace("dreamer","")
    S = S.replace("dream","")
    if S == "":
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

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

while S:
    if len(S) < 5:
        print('NO')
        exit()
    elif S[-5:] in l:
        S = S[:-5]
    elif S[-6:] in l:
        S = S[:-6]
    elif S[-7:] in l:
        S = S[:-7]
    else:
        print('NO')
        exit()
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()[::-1]
for i in range(10 ** 5):
    if s[:5] == "dream"[::-1] or s[:5] == "erase"[::-1]:
        s = s[5:]
    elif s[:7] == "dreamer"[::-1]:
        s = s[7:]
    elif s[:6] == "eraser"[::-1]:
        s = s[6:]
    else:
        if len(s) > 0:
            print("NO")
            break
        else:
            print("YES")
            break

Submission status: Accepted

Solution code:
s = input()

# 先にeraser,erase を消さないとdreameraserでaserだけ残る
sub_s = s.replace('eraser', '')
sub_s = sub_s.replace('erase', '')
sub_s = sub_s.replace('dreamer', '')
sub_s = sub_s.replace('dream', '')

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

Submission status: Accepted

Solution code:
S = input()

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

num = 0
b = True
while num < len(r_s) and b == True:
    b = False
    for i_w in w:
        if i_w == r_s[num:num+len(i_w)]:
            b = True
            num += len(i_w)

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

S = S[::-1]

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

i = 0
flag = True
while i<len(S):
    for t in T:
        j = len(t)
        if S[i:i+j] == t:
            i += j
            break
            print(i)
    else:
        flag = False
        break

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

Submission status: Accepted

Solution code:
s = input()

l = list(s)
l.reverse()
str = "".join(l)

words = [
    "maerd",
    "remaerd",
    "esare",
    "resare"
]

r = "YES"
i = 0
while True:
    if i >= len(str):
        break
    found = False
    for w in words:
        if str[i:i+len(w)] == w:
            found = True
            i += len(w)
            break
    if not found:
        r = "NO"
        break
print(r)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2000000)
s=input()
d='dream'
dr='dreamer'
e='erase'
er='eraser'
l=len(s)
def solve(s,end):
    if end==-1:
        print('YES')
        exit(0)
    if s[end-6:end+1]==dr:
        end-=7
    elif s[end-5:end+1]==er:
        end-=6
    elif s[end-4:end+1]==e or s[end-4:end+1]==d:
        end-=5
    else:
        print('NO')
        exit(0)
    solve(s,end)
solve(s,l-1)

Submission status: Accepted

Solution code:
S = input()[::-1]
li = ["dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1]]

while len(S) > 0:
  for i in li:
    if S.find(i) == 0:
      S = S[len(i):]
      break
  else:
    print("NO")
    exit()
print("YES")

Submission status: Accepted

Solution code:
S = input()
temp = S

changed = True
while(changed):
  changed = False
  for suffix in ['dream', 'dreamer', 'erase', 'eraser']:
    if temp.endswith(suffix):
      temp = temp[:-len(suffix)]
      changed = True
      break
print('YES' if not temp else 'NO')

Submission status: Accepted

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

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:
    ans = "YES"
else:
    ans = "NO"

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


S = _s()[::-1]

flag = True
while True:
    if S.startswith('res') and S[:6] == 'eraser'[::-1]:
        S = S[6:]
    elif S.startswith('es') and S[:5] == 'erase'[::-1]:
        S = S[5:]
    elif S.startswith('rem') and S[:7] == 'dreamer'[::-1]:
        S = S[7:]
    elif S.startswith('ma') and S[:5] == 'dream'[::-1]:
        S = S[5:]
    else:
        flag = False
        break

    if len(S) == 0:
        break

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    import re
    pattern="^(dream|dreamer|erase|eraser)+$"
    cmp=re.compile(pattern)
    print("YES" if cmp.match(input()) else "NO")
resolve()

Submission status: Accepted

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

s = S
ans = True
T = ""
while S != T:
    if s[:7] == ws[1]:
        T, s = T + ws[1], s[7:]
    elif s[:6] == ws[3]:
        T, s = T + ws[3], s[6:]
    elif s[:5] == ws[2]:
        T, s = T + ws[2], s[5:]
    elif s[:5] == ws[0]:
        T, s = T + ws[0], s[5:]
    else:
        ans = False
        break

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

Submission status: Accepted

Solution code:
s = input()[::-1]
l = ["maerd", "remaerd", "esare", "resare"]
b = 0
flag = 1
while b!=len(s):
    if s[b:b+5] in ["maerd", "esare"]: b += 5
    elif s[b:b+6] == "resare": b += 6
    elif s[b:b+7] == "remaerd": b += 7
    else: break
else: flag = 0
print("YNEOS"[flag::2])

Submission status: Accepted

Solution code:
S=input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
D = ['dream', 'dreamer', 'erase', 'eraser']

S = input()
dp = [False] * (len(S)+1)
dp[0] = True
for i in range(len(S)):
  if not dp[i]:
    continue
  for d in D:
    if S[i:i+len(d)] == d:
      dp[i+len(d)] = True

if dp[len(S)]:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
S = input()

S = S[::-1]
while len(S):
    if S[0] == "r":
        if S[:7] == "remaerd":
            S = S[7:]
        elif S[:6] == "resare":
            S = S[6:]
        else:
            print("NO")
            break
    elif S[0] == "m":
        if S[:5] == "maerd":
            S = S[5:]
        else:
            print("N0")
            break
    elif S[0] == "e":
        if S[:5] == "esare":
            S = S[5:]
        else:
            print("N0")
            break
    else:
        print("NO")
        break
else:
    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:
s=str(input())
words = ['eraser','erase','dreamer','dream']
for word in words:
  s=s.replace(word,'')
if len(s) == 0 :
  print('YES')
else :
  print('NO')

Submission status: Accepted

Solution code:
S=input()
Word = ['eraser','erase','dreamer','dream']
for i in Word:
  S=S.replace(i,'')
if len(S) == 0 :
  print('YES')
else :
  print('NO')

Submission status: Accepted

Solution code:
S=input()
Word = ['eraser','erase','dreamer','dream']
for i in Word:
  S=S.replace(i,'')
if len(S) == 0 :
  print('YES')
else :
  print('NO')

Submission status: Accepted

Solution code:
s=input()
idx=len(s)
d={'dream':5,'dreamer':7,'erase':5,'eraser':6}

while True:
	f=True
	for i in d:
		if idx-d[i]>=0 and s[idx-d[i]:idx]==i:
			idx-=d[i]
			f=False
			break
	
	if f:
		print('NO')
		break
	if idx==0:
		print('YES')
		break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
l = ['eraser', 'dreamer', 'erase', 'dream', 'ase']
for i in l:
    s = s.replace(i, '')
if len(s) == 0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
while len(S) != 0:
  num = len(S)
  if S.find('maerd') == 0:
    S = S.replace('maerd', '', 1)
  if S.find('remaerd') == 0:
    S = S.replace('remaerd', '', 1)
  if S.find('esare') == 0:
    S = S.replace('esare', '', 1)
  if S.find('resare') == 0:
    S = S.replace('resare', '', 1)
  if num == len(S):
    print('NO')
    exit(0)
print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

tc = ['dreamer', 'dream', 'eraser', 'erase']
start = 0
out = True

while out:
  if start >= len(s):
    break
  laststart = start
  for i in tc:
    if s[start:start+len(i)] == i:
      if i == 'dreamer' and s[start+7:start+8] == 'a':
        start += 5
      else:
        start += len(i)
      break
  #print('{} {}'.format(laststart, start))
  if start == laststart:
    out = False

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

Submission status: Accepted

Solution code:
s = input()[::-1]
a = ['maerd','remaerd','esare','resare']
while s:
    for i in a:
        if i == s[:len(i)]:
            s = s[len(i):]
            break
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
flag = False
while s:
    if "".join(s[-5:]) == "dream":
        del(s[-5:])
    elif "".join(s[-5:]) == "erase":
        del(s[-5:])
    elif "".join(s[-7:]) == "dreamer":
        del(s[-7:])
    elif "".join(s[-6:]) == "eraser":
        del(s[-6:])
    else:
        flag = False
        break
    
    if len(s) == 0:
       flag = True 
if flag:
   print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S=input()
W=["dream","dreamer","erase","eraser"]

ans="YES"
while len(S)>0:
  if S.endswith(W[0]):
    S=S[:-len(W[0])]
  elif S.endswith(W[1]):
    S=S[:-len(W[1])]
  elif S.endswith(W[2]):
    S=S[:-len(W[2])]
  elif S.endswith(W[3]):
    S=S[:-len(W[3])]
  else:
    ans="NO"
    break
    
print(ans)

Submission status: Accepted

Solution code:
s = input()

s_work = s
target_list = ["dream", "dreamer", "erase", "eraser"]

while len(s_work) > 0:
    has_changed = False
    for target in target_list:
        if s_work.endswith(target):
            s_work = s_work[0:-len(target)]
            has_changed = True
            break
    if not has_changed:
        print("NO")
        exit()

print("YES")

Submission status: Accepted

Solution code:
s=input()[::-1]
for c in("resare","esare","remaerd","maerd"):s=s.replace(c,"")
print("YNEOS"[s!=""::2])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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