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:
s = input()
ans = "YES"
while s != "":
    if len(s) < 5:
        ans = "NO"
        break
    elif 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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
data = input()

tmp = data.replace('eraser', '')
tmp = tmp.replace('erase', '')
tmp = tmp.replace('dreamer', '')
tmp = tmp.replace('dream', '')
if tmp == '':
  print('YES')
  exit()
print('NO')

Submission status: Accepted

Solution code:
S = str(input())

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

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

Submission status: Accepted

Solution code:
import re# regular expression
s = input()
m = re.fullmatch(r'(dream(er)?|erase(r)?)+', s)
#print(m)
#print(type(m))
if m == None:#マッチ無し
    print("NO")
else:#フルマッチあり
    print("YES")

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    s = input()

    while s != '':
        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')
            exit()

    print('YES')

Submission status: Accepted

Solution code:
S=input()

l=len(S)

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

    if l==len(S):
        break
    else:
        l=len(S)


if l==0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

def main():
    mod=10**9+7
    L=["dream","dreamer","erase","eraser"]
    S=input()
    N=len(S)
    f=1
    pos=N-1
    while f:
        for i in range(len(L)):
            t=L[i]
            temp=1
            for i in range(len(t)):
                if pos-i<0:
                    temp=0
                    break
                if t[-1-i]==S[pos-i]:
                    continue
                else:
                    temp=0
                    break
                
            if temp:
                pos-=len(t)
                break
        if pos==-1:
            break
        if temp==0:
            f=0
            
    if f==1:
        print("YES")
    else:
        print("NO")
                

main()

Submission status: Accepted

Solution code:
import re

s = input()
era = 'eraser'
er = 'erase'
dr = 'dream'
drm = 'dreamer'

s1 = re.sub(era,'',s)
s2 = re.sub(er,'',s1)
s3 = re.sub(drm,'',s2)
s4 = re.sub(dr,'',s3)

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

Submission status: Accepted

Solution code:
S=input()
div=["maerd","remaerd","esare","resare"]
S=S[::-1]
judge=True
cnt=0
while cnt<len(S):
    can=False
    for j in range(4):
        d=div[j]
        if S[cnt:len(d)+cnt]==d:
            can=True
            cnt+=len(d)
    if not can:
        judge=False
        break
if judge:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
def main():
  s = input()
  dream = False
  erase = False

  while s:
    if s.startswith('dream'):
      s = s[5:]
      dream = True
      erase = False
    elif s.startswith('erase'):
      s = s[5:]
      dream = False
      erase = True
    elif s.startswith('er') and dream:
      s = s[2:]
      dream = False
    elif s.startswith('r') and erase:
      s = s[1:]
      erase = False
    else:
      return False
  
  return True

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

Submission status: Accepted

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


def main():
    s = input()

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

    flg = True
    while len(s) > 0:
        for koho in koho_list:
            if len(s) >= len(koho) and s[-len(koho):] == koho:
                s = s[:-len(koho)]
                break
        else:
            flg = False
            break

    if flg:
        print("YES")
    else:
        print("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().replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
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")

Submission status: Accepted

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

print(answer)

Submission status: Accepted

Solution code:
text = "".join(reversed(input()))
words = ["".join(reversed(x)) for x in ["dreamer", "eraser", "dream", "erase"]]

while text != "":
  has_striped = False
  for word in words:
    if text.find(word) != 0: continue
    text = text[len(word):]
    has_striped = True
  if not has_striped: break

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    S = input()
    S = S[::-1]
    ans = ["maerd", "remaerd", "esare", "resare"]
    while S:
        for a in ans:
            if S[:5] in ans:
                S = S.replace(S[:5], "", 1)
                break
            elif S[:6] in ans:
                S = S.replace(S[:6], "", 1)
                break
            elif S[:7] in ans:
                S = S.replace(S[:7], "", 1)
                break
        else:
            return print("NO")
    else:
        return print("YES")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
c = 0
dream = list("dream")
dreamer = list("dreamer")
erase = list("erase")
eraser = list("eraser")
while True:
    if S[c:c + 5] == dream:
        c += 5
        if S[c:c + 5] != erase and S[c:c + 2] == list("er"):
            c += 2
        if c == N:
            print("YES")
            break
    elif S[c:c + 5] == erase:
        c += 5
        if S[c:c + 1] == ["r"]:
            c += 1
        if c == N:
            print("YES")
            break
    else:
        print("NO")
        break

Submission status: Accepted

Solution code:
S=input()
T=["dream","dreamer","erase","eraser"]
S=S.replace(T[3],"0000000").replace(T[2],"00000").replace(T[1],"0000000").replace(T[0],"00000")
U=""
for k in range(len(S)):
    U+="0"
if S==U:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
# coding:utf-8
import sys 
def main():
    s = input()
    s = s.replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')
    if s == '':
        print('YES')
    else:
        print('NO')

if __name__ == '__main__' :
    main()

Submission status: Accepted

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

Submission status: Accepted

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

cur_pos = 0
tmp_str = ''
str_list = ['maerd', 'remaerd', 'esare', 'resare']

while (cur_pos < N):
    tmp_str += S[cur_pos]

    if (tmp_str in str_list):
        tmp_str = ''
    
    cur_pos += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
ans = "YES"

while (len(s) - 5) > 2:
    c = s[-5:]
    if (c == "dream"):
        s = s[ : -5]
    else:
        if (c == "erase"):
            s = s[: -5]
        else:
            c = s[-6:]
            if (c == "eraser"):
                s = s[: -6]
            else:
                c = s[-7:]
                if (c == "dreamer"):
                    s = s[: -7]
                else:
                    ans = "NO"
                    break

                    
if s != "dream":
    if s != "erase":
        if s != "dreamer":
            if s != "eraser":
                ans = "NO"

print(ans)

Submission status: Accepted

Solution code:
s = input()
search = ['dream', 'dreamer', 'erase', 'eraser']
index = len(s)
while index > 0:
  found = False
  for i in search:
    if index < len(i):
      continue
    if s[index-len(i):index] == i:
      found = True
      index -= len(i)
      break
  if not found:
    print('NO')
    exit()
print('YES')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#input
S = input()
S = S.replace('eraser','') # 文字列の置き換えeraser を空文字に
S = S.replace('erase','')
S = S.replace('dreamer','')
S = S.replace('dream','')

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    while len(S):
        if S[:7] == 'dreamer':
            if S[5:11] == 'eraser':
                S = S[5:]
            elif S[5:10] == 'erase':
                S = S[5:]
            else:
                S = S[7:]
        elif S[:5] == 'dream':
            S = S[5:]
        elif S[:6] == 'eraser':
            S = S[6:]
        elif S[:5] == 'erase':
            S = S[5:]
        else:
            print('NO')
            exit()
    print('YES')


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 True:
    if len(s) == 0:
        print ("YES")
        exit ()

    if s[0:5] == "maerd" or s[0:5] == "esare":
        s = s[5:]
    else:
        if s[0:6] == "resare":
            s = s[6:]
        else:
            if s[0:7] == "remaerd":
                s = s[7:]
            else:
                print ("NO")
                exit ()

Submission status: Accepted

Solution code:
#ABC049

s = input()

while len(s) != 0:
    
    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
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','')
if S=='':
    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=list(str(input()))
b=0
while len(s)>=7:
  if s[-1]=='r':
    sd=[s[-7],s[-6],s[-5],s[-4],s[-3],s[-2],s[-1]]
    se=[s[-6],s[-5],s[-4],s[-3],s[-2],s[-1]]
    if ''.join(sd)=='dreamer':
      del s[-7:]
    elif ''.join(se)=='eraser':
      del s[-6:]
    else:
      print('NO')
      b+=1
      break
  elif s[-1]=='m':
    sd=[s[-5],s[-4],s[-3],s[-2],s[-1]]
    if ''.join(sd)=='dream':
      del s[-5:]
    else:
      print('NO')
      b+=1
      break
  elif s[-1]=='e':
    sd=[s[-5],s[-4],s[-3],s[-2],s[-1]]
    if ''.join(sd)=='erase':
      del s[-5:]
    else:
      print('NO')
      b+=1
      break  
  else:
    print('NO')
    b+=1
    break
if len(s)==0 or (len(s)==6 and ''.join(s)=='eraser') or (len(s)==5 and ''.join(s)=='dream') or (len(s)==5 and ''.join(s)=='erase'):
  print('YES') 
elif b!=1:
  print('NO')

Submission status: Accepted

Solution code:
a = str(input())
l = len(a)
let5 = ['dream','erase']


while l >= 5:
  lb = len(a)
  if a[-5:] in let5:
    a = a[:-5]
    l -= 5
  if a[-6:] == 'eraser':
    a = a[:-6]
    l -= 6
  if a[-7:] == 'dreamer':
    a = a[:-7]
    l -= 7
  if l == 0:
    print('YES')
    break
  if l == lb:
    print('NO')
    break
else:
  print('NO')

Submission status: Accepted

Solution code:
S = input()

# dream + eraser で dreamer ができるのに注意
c1 = S.count('dream')  # dream + dreamer
c2 = S.count('dreamer')  # dreamer + (dream + erase) + (dream + eraser)
c3 = S.count('erase')  # erase + eraser
c4 = S.count('eraser')  # eraser
# c5 = S.count('dreameraser')  # dream + eraser
c6 = S.count('dreamerase')  # (dream + erase) + (dream + eraser)

num_eraser = c4
num_erase = c3 - num_eraser
num_dreamer = c2 - c6
num_dream = c1 - num_dreamer

l = num_eraser * 6 + num_erase * 5 + num_dreamer * 7 + num_dream * 5
if l == len(S):
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
pattern = ["dream","dreamer","erase","eraser"]
for i in range(len(pattern)):
  pattern[i] = pattern[i][::-1]
while True:
  flag = False
  for v in pattern:
    if S[:len(v)] == v:
      S = S[len(v):]
      flag = True
  if S == "":
    print("YES")
    break
  elif not flag:
    print("NO")
    break

Submission status: Accepted

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


def main():
    S = input()
    S = S[::-1]
    a = ['maerd', 'remaerd', 'esare', 'resare']
    if S.replace(a[3], '').replace(a[2], '').replace(a[1], '').replace(a[0], '') == "":
        print('YES')
    else:
        print('NO')

main()

Submission status: Accepted

Solution code:
S = input()

# S = 'dreameraser'

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

while True:
    flag = False

    for word in words:
        # word=words[3]
        length = len(word)
        if S[-length:] == word:
            S = S[:len(S) - length]
            flag = True
            break

    if flag:
        if S == '':
            print('YES')
            break
        else:
            continue
    else:
        print('NO')
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
flag = True
while(flag):
    if(len(S)==0):
        flag = False
    if(S[-5:]=='dream' or S[-5:]=='erase'):
        S=S[:-5]
    elif(S[-6:]=='eraser'):
        S=S[:-6]
    elif(S[-7:]=='dreamer'):
        S=S[:-7]
    else:
        break
if(flag):
    print('NO')
else:
    print('YES')
#反省点

Submission status: Accepted

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

while s:
    if s.rfind('dream') == l-len('dream'): #文字列の背後から'dream'をさがす
        s = s[:l-len('dream')] #末尾の'dream'を削除する（スライス）
    
    elif s.rfind('dreamer') == l-len('dreamer'):
        s = s[:l-len('dreamer')]

    elif s.rfind('erase') == l-len('erase'):
        s = s[:l-len('erase')]
    
    elif s.rfind('eraser') == l-len('eraser'):
        s = s[:l-len('eraser')]

    else:
        break #文字列がなくなるか、指定の文字が探せなくなったらbreak

    l = len(s)

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

Submission status: Accepted

Solution code:
import sys
#input = sys.stdin.buffer.readline
sys.setrecursionlimit(20000+1)

def main():
    s = "".join(list(reversed(str(input()))))
    b = True
    
    while len(s) != 0:
        if len(s) >= 5:
            use = ["maerd","esare"]
            if s[:5] in use:
                s = s[5:]
            elif (len(s) >= 6 and s[:6] == "resare"):
                s = s[6:]
            elif (len(s) >= 7 and s[:7] == "remaerd"):
                s = s[7:]
            else:
                b = False
                break
        else:
            b = False
            break
            
    if b:
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()

words = ["dream", "dreamer", "erase", "eraser"]
ans = "YES"
r = len(S)

while r > 0:
    ok = False
    for w in words:
        l = r - len(w)
        if l < 0:
            continue
        if S[l:r] == w:
            r = l
            ok = True
            break
    if not ok:
        ans = "NO"
        break

print(ans)

Submission status: Accepted

Solution code:
s = input()
while s:
    if s.startswith("eraser"):
        s = s[6:]
    elif s.startswith("erase"):
        s = s[5:]
    elif s.startswith("dreamera"):
        s = s[5:]
    elif s.startswith("dreamer"):
        s = s[7:]
    elif s.startswith("dream"):
        s = s[5:]
    else:
        print("NO")
        break
else:
    print("YES")

Submission status: Accepted

Solution code:
s = input()
temp = s
while len(temp) > 4:
    if temp[len(temp) - 3:] == 'eam' and temp[len(temp) - 5:] == 'dream': temp = temp[: len(temp) - 5]
    elif temp[len(temp) - 3:] == 'mer' and temp[len(temp) - 7:] == 'dreamer': temp = temp[: len(temp) - 7]
    elif temp[len(temp) - 3:] == 'ase' and temp[len(temp) - 5:] == 'erase': temp = temp[: len(temp) - 5]
    elif temp[len(temp) - 3:] == 'ser' and temp[len(temp) - 6:] == 'eraser': temp = temp[: len(temp) - 6]
    else: break
if len(temp) > 4: print('NO')
else: print('YES')

Submission status: Accepted

Solution code:
s = str(input())
s = s[::-1]  #sを逆にする

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

f = 0

if len(s) == 0:
    f = 1

while len(s) != 0:
    if s[:7] == 'remaerd':
        s = s[7::]
    elif s[:6] == 'resare':
        s = s[6::]
    elif s[:5] == 'esare':
        s = s[5:]
    elif s[:5] == 'maerd':
        s = s[5:]
    else:
        f = 1
        break

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

Submission status: Accepted

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

s = readline().rstrip().decode('utf-8')
s = s[::-1]
n = len(s)
l = ["dreamer","dream","eraser", "erase"]
for i in range(4):
    l[i] = l[i][::-1]

i=0
while i < n:
    flag = 0
    for j in range(4):
        if i+len(l[j]) <= n and s[i:i+len(l[j])] == l[j]:
            i += len(l[j])
            flag = 1
            break
    if not flag:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
# ABC 049 C
S = str(input())

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

Submission status: Accepted

Solution code:
# 動的計画法(DP)
s=input()
words = {"dream", "dreamer", "erase", "eraser"}

dp = dict()
dp[0] = 1
for i in range(0, len(s)):
    if not dp.get(i):
        continue
    for word in words:
        if s[i:i+len(word)] == word:
            dp[i+len(word)] = 1

print("YES" if dp.get(len(s)) else "NO")

Submission status: Accepted

Solution code:
s = input()

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

import re
def setudan(s):
  if s[-5:] == 'dream' or s[-5:] == 'erase':
    return s[:-5]
  elif s[-6:] == 'eraser':
    return s[:-6]
  elif s[-7:] == 'dreamer':
    return s[:-7]
  else:
    return 0

while True:
  s = setudan(s)
  if s == 0:
    print('NO')
    break
  if s =='':
    print('YES')
    break

Submission status: Accepted

Solution code:
S0 = input()
S = S0[::-1]
cands = ["dream"[::-1],"dreamer"[::-1],"erase"[::-1],"eraser"[::-1]]
i = 0
while i < len(S):
  f = False
  for word in cands:
    #print(S[i:],word)
    if S[i:].startswith(word):
        f = True
        i += len(word)
        break
  if f == False:
    print("NO")
    exit(0)
#print(i)
if i == len(S):
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
S = input()

ind = len(S)
flg = True
while ind > 0:
    if S[ind-7:ind] in ["dreamer"]:
        ind -= 7
    elif S[ind-6:ind] in ["eraser"]:
        ind -= 6
    elif S[ind-5:ind] in ["dream", "erase"]:
        ind -= 5
    else:
        flg = False
        break

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

Submission status: Accepted

Solution code:
hantei = ["dream", "dreamer", "erase", "eraser"]
s = input()
len_s = len(s)
s = s+"0000000000000"

checker = 1
i = 0
while i < len_s:
    if s[i:i+5] == "dream":
        if s[i+5:i+7] == "er":
            if s[i+7] =="a":
                i += 5
            else:
                i += 7
        else:
            i += 5
    elif s[i:i+5] == "erase":
        if s[i+5] == "r":
            i += 6
        else:
            i += 5
    else:
        checker = 0
        break
if checker:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc049/tasks/arc065_a
# なんかこの問題知ってる気がする
# 前方向から貪欲にマッチしようとすると,dreamer なのか dream eraser なのかわかりにくい
# しかし後ろ三文字を見ると、eam,mer,ase,serと一意に決定できる。よって逆方向から貪欲にマッチングさせると即座に構成可能か判別できる

S = input()

i = len(S)
while i - 3 > 0:
    tri = S[i - 3:i]
    if tri == 'eam':
        is_ok = S[i - 5:i] == 'dream'
        i -= 5
    elif tri == 'ase':
        is_ok = S[i - 5:i] == 'erase'
        i -= 5
    elif tri == 'mer':
        is_ok = S[i - 7:i] == 'dreamer'
        i -= 7
    elif tri == 'ser':
        is_ok = S[i - 6:i] == 'eraser'
        i -= 6
    else:
        print('NO')
        exit()

    if not is_ok:
        print('NO')
        exit()


print('YES')

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc049/tasks/arc065_a
# なんかこの問題知ってる気がする
# 前方向から貪欲にマッチしようとすると,dreamer なのか dream eraser なのかわかりにくい
# しかし後ろ三文字を見ると、eam,mer,ase,serと一意に決定できる。よって逆方向から貪欲にマッチングさせると即座に構成可能か判別できる

S = input()

i = len(S)
T = ''
while i - 3 > 0:
    tri = S[i - 3:i]
    if tri == 'eam':
        T += 'maerd'
        i -= 5
    elif tri == 'ase':
        T += 'esare'
        i -= 5
    elif tri == 'mer':
        T += 'remaerd'
        i -= 7
    elif tri == 'ser':
        T += 'resare'
        i -= 6
    else:
        print('NO')
        exit()

if S == T[::-1]:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input().strip()

a = ("dream", "dreamer", "erase", "eraser")

while True:
    if S == "":
        break
    flg = False
    for aa in a:
        if S.endswith(aa):
            S = S[:-len(aa)]
            flg = True
    if flg:
        continue
    break

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

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
s=input()
l=len(s)
while s!=0:
    l=len(s)
    if s.rfind("dream")==l-5:
        s=s[:l-5]
    elif s.rfind("dreamer")==l-7:
        s=s[:l-7]
    elif s.rfind("erase")==l-5:
        s=s[:l-5]
    elif s.rfind("eraser")==l-6:
        s=s[:l-6]
    else:
        break
if len(s)==0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

S = S[::-1]
#print(S)
L = ['maerd', 'remaerd', 'esare', 'resare']

while len(S) > 0:
    if 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')
        break
if len(S) == 0:
    print('YES')

Submission status: Accepted

Solution code:
S = input()

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

current = S
canEqual = False
while len(current) > 0:
  matchExists = False
  for w in words:
    last_index = -len(w)
    if(current[last_index:] == w):
      current = current[:last_index]
      matchExists = True
      break
  
  if(len(current) == 0):
    canEqual = True
    break
  
  if(matchExists == False):
    break

result = "YES" if canEqual == True else "NO"
print(result)

Submission status: Accepted

Solution code:
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))
MOD = 10 ** 9 + 7


S = input()
S = ''.join(list(reversed(S)))
while len(S) > 0:
    if S[:7] == 'remaerd':
        S = S[7:]
    elif S[:6] == 'resare':
        S = S[6:]
    elif S[:5] in ['esare', 'maerd']:
        S = S[5:]
    else:
        print('NO')
        exit(0)
print('YES')

Submission status: Accepted

Solution code:
S = str(input())
S_iterator = reversed(S)
S_list = list(S_iterator)
s1 = ['m','a','e','r','d']
s2 = ['r','e','m','a','e','r','d']
s3 = ['e','s','a','r','e']
s4 = ['r','e','s','a','r','e']

i=0
while(i < len(S_list)):
    if(S_list[i:i+5]==s1):
        err = 0
        i = i+5
    elif(S_list[i:i+7]==s2):
        err = 0
        i = i+7
    elif(S_list[i:i+5]==s3):
        err = 0
        i = i+5
    elif(S_list[i:i+6]==s4):
        err = 0
        i = i+6
    else:
        err = 1
        break
    
if(err == 0):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import sys
s = str(input())
i = 0
while i < len(s):
    if i + 5 <= len(s) and s[i:i+5] == 'dream': #now dream or dreamer
        if i + 6 < len(s) and s[i+5] == 'e' and s[i+6] == 'r': #now dreamer or now dream and next is erase or eraser
            if i + 7 < len(s) and s[i+7] == 'a': #next erase or eraser, now dream
                i += 5
            else: #now dreamer
                i += 7
        else: #now dream
            i += 5
    elif i + 5 <= len(s) and s[i:i+5] == 'erase':
        if i + 5 < len(s) and s[i+5] == 'r': #now eraser
            i += 6
        else: #now erase
            i += 5
    else:
        print('NO')
        sys.exit()
print('YES')

Submission status: Accepted

Solution code:
s = input()
now = 0
n = len(s)
prev = ""
x = {"eraser", "dreamer", "dream", "erase"}
y = {"ase", "aser"}
ds = [7, 6, 5, 4, 3]
ans = "YES"
while now < n:
    q = 1
    for i in ds:
        index = now + i
        if index > n:
            continue
        w = s[now:index]
        if w in x:
            now += i
            prev = w
            q = 0
            break
        elif prev == "dreamer" and w in y:
            now += i
            prev = w
            q = 0
            break
    if q:
        ans = "NO"
        break
print(ans)

Submission status: Accepted

Solution code:
s=input()[::-1]
words = {"dream", "dreamer", "erase", "eraser"}

while len(s)!=0:
    for i in words:
        l = len(i)
        if s[0:l] == i[::-1]:
            s = s[l::]
            break
    else:
        break

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