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


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

Submission status: Accepted

Solution code:
import sys
S = input()
while S:
    if (S[-5:] == 'dream') or (S[-5:] == 'erase'):
        S = S[:-5]
    elif S[-6:] == 'eraser':
        S = S[:-6]
    elif S[-7:] == 'dreamer':
        S = S[:-7]
    else:
        print('NO')
        sys.exit()
print('YES')

Submission status: Accepted

Solution code:
s = input()

ichi = 0
l = len(s)
cnt = l

while True:
    s_dreamer = s.rfind ("dreamer",ichi,l)
    s_eraser = s.rfind ("eraser",ichi,l)
    s_dream = s.rfind ("dream",ichi,l)
    s_erase = s.rfind ("erase",ichi,l)

    if s_dreamer == l - 7 and 0 <= l - 7:
        l = s_dreamer
        cnt -= 7 

    elif s_eraser == l - 6 and 0 <= l - 6:
        l = s_eraser
        cnt -= 6  

    elif s_dream == l - 5 and 0 <= l - 5:
        l = s_dream
        cnt -= 5  

    elif s_erase == l - 5 and 0 <= l - 5:
        l = s_erase
        cnt -= 5

    elif cnt == 0:
        print("YES")
        break

    else:
        print("NO")
        break

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
sys.setrecursionlimit(10 ** 6)
S = input()
def func(i):
    if i >= len(S):
        return True
    if (S[i:i+5] == 'dream' or S[i:i+5] == 'erase') and func(i + 5):
        return True
    if (S[i:i+7] == 'dreamer') and func(i + 7):
        return True
    if (S[i:i+6] == 'eraser') and func(i + 6):
        return True
    return False

print('YES' if func(0) else 'NO')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)

S = input()

def func(i):
    if i >= len(S):
        return True
    if S[i:i+5] == 'dream':
        if func(i + 5): return True
        if S[i+5:i+7] == 'er':
            if func(i + 7): return True
        return False
    if S[i:i+5] == 'erase':
        if func(i + 5): return True
        if S[i+5] == 'r':
            if func(i + 6): return True
        return False

print('YES' if func(0) else 'NO')

Submission status: Accepted

Solution code:
s=input()
ind =0
len_s=len(s)
s = s+ "AAAAAAAAA"

A = "dreamer"
B= "dream"
C= "erase"
D="eraser"

flag =True
while(1):
    if(s[ind] =="d"):
        if(s[ind + 5] =="d"):
            if(s[ind:ind+5]!=B):
                flag = False
                break
            else:
                ind+=5
        else:
            if(s[ind+5]!='e' and s[ind+5]!='A'):
                flag=False
                break
            if(s[ind+7] == "a" or ind + 7 >len_s):
                if(s[ind:ind+5]!=B):
                    flag = False
                    break
                else:
                    ind+=5

            else:
                if(s[ind:ind+7] !=A):
                    flag = False
                    break
                else:
                    ind+=7
    elif(s[ind]=="e"):
        if(s[ind+5]=="r"):
            if(s[ind:ind+6]!=D):
                flag = False
                break
            else:
                ind+=6

        else:
            if(s[ind:ind +5] !=C):
                flag =False
                break
            else:
                ind+=5
    else:
        flag=False
        break
    if(ind == len_s):
        break
    if(ind > len_s):
        flag=False
        break
if(flag):
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = input()
s += "0000000000"
i = 0
while i < len(s):
    # print("s:[{}:] : {}".format(i, s[i:]))
    if s[i:i + 5] == "dream":
        if s[i + 5:i + 7] == "er":
            if s[i + 7] == "a":  # dream+eraだと確定
                i += 5
                continue
            else:  # dreamerと確定
                i += 7
                continue
        else:  # dreamと確定
            i += 5
            continue
    elif s[i:i+5] == "erase":  # eraseで始まる場合
        if s[i + 5] != "r":  # eraseで確定
            i += 5
            continue
        else:  # eraserで確定
            i += 6
            continue
    elif s[i:] == "0000000000":
        print("YES")
        exit()
    else:
        print("NO")
        exit()

Submission status: Accepted

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

def check(string):
    if string[-5:] == "dream":
        new = string[:-5]
        return new

    if string[-7:] == "dreamer":
        new = string[:-7]
        return new

    if string[-5:] == "erase":
        new = string[:-5]
        return new

    if string[-6:] == "eraser":
        new = string[:-6]
        return new

    print("NO")


if __name__ == '__main__':
    s = str(input())

    while s:
        s = check(s)

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

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
check = ['maerd', 'remaerd', 'esare', 'resare']
T = []
now = 0

while now < len(S):
    if S[now:now+5] == 'maerd':
        now += 5
        T.append('maerd')
    elif S[now:now+5] == 'esare':
        now += 5
        T.append('esare')
    elif S[now:now+7] == 'remaerd':
        now += 7
        T.append('remaerd')
    elif S[now:now+6] == 'resare':
        now += 6
        T.append('resare')
    else:
        print('NO')
        break
if ''.join(T) == S:
    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 = input()
words = ['dream', 'dreamer', 'erase', 'eraser']
r = len(s)
t = ''

for l in range(len(s), -1, -1):
  if r - l >= 5:
    if s[l:r] in words:
      t = s[l:r] + t
      r = l

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

Submission status: Accepted

Solution code:
import copy

S = input()
strs = list(S)
strs.reverse()
targets = [list("maerd"), list("remaerd"), list("esare"), list("resare")]

cnt = -1
_targets = copy.copy(targets)
for i in range(len(strs)):
    s = strs[i]
    cnt += 1
    is_match = False
    __targets = copy.copy(_targets)
    for target in __targets:
        if len(target) <= cnt:
            continue
        if target[cnt] == s:
            is_match = True
            if len(target) - 1 == cnt:
                _targets = copy.copy(targets)
                cnt = -1
            break
        else:
            _targets.remove(target)
    if not(is_match):
        print("NO")
        exit()

print("YES")

Submission status: Accepted

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

for i in range(len(A)):
    A[i] = A[i][::-1]

s = input()[::-1]
i = 0
while True:
    f = True
    for a in A:
        if len(a) > len(s) - i:
            continue
        if s[i:i+len(a)] == a:
            i += len(a)
            f = False
            break
    else:
        if i == len(s):
            print('YES')
            exit()
        if f == True:
            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:
T = ["dream", "dreamer","erase", "eraser", ""]
S = input()
L = len(S)
ans = "YES"
while L >= 7:
    if S[-7:] == "dreamer":
        L -= 7
        S = S[:-7]
    elif S[-6:] == "eraser":
        L -= 6
        S = S[:-6]
    elif S[-5:] == "erase" or S[-5:] == "dream":
        L -= 5
        S = S[:-5]
    else:
        ans = "NO"
        break
if S in T:
    print(ans)
else:
    print("NO")

Submission status: Accepted

Solution code:
S=str(input())
for i in range(20000):
    if S[-7:]=="dreamer":
        S=S[:-7]
    if S[-6:]=="eraser":
        S=S[:-6]
    if S[-5:]=="dream" or S[-5:]=="erase":
        S=S[:-5]
    if S[-7:]!="dreamer" and S[-6:]!="eraser" and S[-5:]!="dream" and S[-5:]!="erase":
        break
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(["NO","YES"][len(s)==0])

Submission status: Accepted

Solution code:
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()
S = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
print("YES" if len(S)==0 else "NO")

Submission status: Accepted

Solution code:
import sys
S = input()
S = S[::-1]
while S:
    if S[:3]=="res":
        if S[:6]=="resare":
            S = S[6:]
#             print(S)
        else:
            break

    elif S[:3]=="esa":
        if S[:5]=="esare":
            S = S[5:]
#             print(S)
        else:
            break
    
    elif S[:3]=="rem":
        if S[:7]=="remaerd":
            S = S[7:]
#             print(S)
        else:
            break
            
    elif S[:3]=="mae":
        if S[:5]=="maerd":
            S = S[5:]
#             print(S)
        else:
            break
            
    else:
        break

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

Submission status: Accepted

Solution code:
import sys
S = input()
S = S[::-1]
while S:
    if S[:3]=="res":
        if S[:6]=="resare":
            S = S[6:]
#             print(S)
        else:
            print("NO")
            sys.exit()

    elif S[:3]=="esa":
        if S[:5]=="esare":
            S = S[5:]
#             print(S)
        else:
            print("NO")
            sys.exit()
    
    elif S[:3]=="rem":
        if S[:7]=="remaerd":
            S = S[7:]
#             print(S)
        else:
            print("NO")
            sys.exit()
        
    elif S[:3]=="mae":
        if S[:5]=="maerd":
            S = S[5:]
#             print(S)
        else:
            print("NO")
            sys.exit()
            
    else:
        print("NO")
        sys.exit()
else:
    print("YES")

Submission status: Accepted

Solution code:
s = input()

while len(s) > 4:
    if s[-5:] == 'dream' or s[-5:] == 'erase':
        s = s[:-5]
        continue
    elif s[-6:] == 'eraser':
        s = s[:-6]
        continue
    elif s[-7:] == 'dreamer':
        s = s[:-7]
        continue
    else:
        break
        
if len(s) == 0:
    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:
#!/usr/bin/python3
# coding: utf-8

import sys


def main():
    line = sys.stdin.readline().strip()
    line1 = line.replace('eraser', '').replace(
        'erase', '').replace('dreamer', '').replace('dream', '')
    if line1 == '':
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

s = input()
t = ["eraser", "erase", "dreamer", "dream"]
for n in range(4):
    s = s.replace(t[n], "")
if not s:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = "".join(list(reversed(list(input()))))

flag = 0
while flag == 0 :
    if (S[0:7] == "remaerd") and (len(S) >= 7) :
        S = S[7:]
    elif (S[0:6] == "resare" and len(S) >= 6) :
        S = S[6:]
    elif ((S[0:5] == "maerd") or (S[0:5] == "esare")) and (len(S) >= 5) :
        S = S[5:]
    elif len(S) == 0 :
        ans = 1
        flag = 1
    else :
        ans = -1
        flag = 1
D = {1:"YES",-1:"NO"}
print(D[ans])

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().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")

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

Submission status: Accepted

Solution code:
S = input()
Scopy = S[::-1]
check = ['maerd', 'remaerd', 'esare', 'resare']
now = 0
while now < len(S):
    if Scopy[now] == 'm':
        if Scopy[now:now+5] != check[0]:
            print('NO')
            break
        else:
            now += 5
    
    elif Scopy[now] == 'e':
        if Scopy[now:now+5] != check[2]:
            print('NO')
            break
        else:
             now += 5
    
    elif Scopy[now] == 'r':
        if Scopy[now:now+7] == check[1]:
            now += 7
        elif Scopy[now:now+6] == check[3]:
            now += 6
        else:
            print('NO')
            break
    else:
        print('NO')
        break

if now == len(S):
    print('YES')

Submission status: Accepted

Solution code:
S = str(input())

S = S[::-1]

words = ('dreamer', 'dream', 'eraser', 'erase')
sdrow = [word[::-1] for word in words]

while S:
    flag = False
    for drow in sdrow:
        if S.startswith(drow):
            flag = True
            S = S.replace(drow, '', 1)
    if not flag: break

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

Submission status: Accepted

Solution code:
s=input()
S=s[::-1]
i=0
j=0
k=len(S)
while(1):
    if(i==k):
        print("YES")
        break
    if(S[i:i+5]=="maerd" or S[i:i+5]=="esare"):
        i+=5
    if(S[i:i+6]=="resare"):
        i+=6
    if(S[i:i+7]=="remaerd"):
        i+=7
    if(i==j):
        print("NO")
        break
    j=i

Submission status: Accepted

Solution code:
import sys
s = input()
i = 0
while s[i:i+5] != '':
    if s[i:i+5] == 'dream':
        if s[i+5:i+10] == 'dream':
            i += 5
        elif s[i+5:i+10] == 'erase':
            i += 5
        elif s[i+5:i+7] == 'er':
            i += 7
        else:
            i += 5
    elif s[i:i+5] == 'erase':
        if s[i+5:i+10] == 'dream':
            i += 5
        elif s[i+5:i+10] == 'erase':
            i += 5
        elif s[i+5:i+6] == 'r':
            i += 6
        else:
            i += 5
    else:
        print('NO')
        sys.exit(0)
print('YES')

Submission status: Accepted

Solution code:
s = input()
q = [0]
flag = False
while len(s) > 0:
    if s[0:5] in ['dream','erase'] and flag == False:
        q.append(s[0:5])
        s = s[5:]
        flag = False
    elif s[0:6] == 'eraser':
        q.append(s[0:6])
        s = s[6:]
        flag = False
    elif s[0:7] == 'dreamer':
        q.append(s[0:7])
        s = s[7:]
        flag = False
    elif q[-1] in ['dream','erase']:
        s = q[-1] + s
        q.pop()
        flag = True
    else:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S = list(input())
a1 = list('dreamer')
a2 = list('dream')
b1 = list('eraser')
b2 = list('erase')

#a1
loop_list = [b1, b2, a1, a2]
for word in loop_list:
    for i in range(len(S)-len(word)+1):
        all_match = True
        for j in range(len(word)):
            if S[i+j] == word[j]:
                pass
            else:
                all_match = False

        if all_match == False:
            continue

        for j in range(len(word)):
            S[i+j] = ''

# print(S)
if  sum( list(map(len,S))   ) == 0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input()

div = ['dream', 'dreamer', 'erase', 'eraser']
end = 0
ans = "YES"

while end < len(S):
    
    isExist = False
    
    for d in div:
        if d == S[len(S) - len(d) - end: len(S) - end]:
            end += len(d)
            isExist = True

    if isExist != True:
        ans = "NO"
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
Cr = input()
while Cr:
    if Cr[-7:] == 'dreamer':
        Cr = Cr[0:-7]
    elif Cr[-6:] == 'eraser':
        Cr = Cr[0:-6]
    elif Cr[-5:] in ['dream', 'erase']:
        Cr = Cr[0:-5]
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
import re
pattern = r"(?:dream(?:er)?|eraser?)+$"
text = input()
if re.match(pattern , text):
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import re

S = input()
result = re.match(r'\A(dream(er)?|erase(r)?)+\Z', S)
if result:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
def solve(s, ws):
    while True:
        find_w = False
        for w in ws:
            if s.startswith(w):
                s = s[len(w):]
                find_w = True
                break
        if not s:
            return "YES"
        elif not find_w:
            return "NO"
    return None


S = input()[::-1]
WS = [w[::-1] for w in['dream', 'dreamer', 'erase', 'eraser']]
print(solve(S, WS))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys, copy
s = input();

# def daydream(name,s):
#     print(name)
#     if ( name == s ):
#         return True
#     if ( len( name ) > len(s) ):
#         return False
#     for x in ["dream", "dreamer", "erase", "eraser"]:
#         if ( daydream(name + x, s) ):
#             return True
#     return False
#

#def daydream(s):
#    if (s == ""):
#        return True
#    for x in ["dream", "dreamer", "erase", "eraser"]:
#        if ( s.startswith(x) ):
#            if ( daydream(s[len(x):]) ):
#                return True
#    return False

ss = [s]
while( len(ss) > 0 ):
    tt = copy.deepcopy(ss)
    ss = list()
    for t in tt:
        for x in ["dream", "dreamer", "erase", "eraser"]:
            if ( t.startswith(x) ):
                t_cut = t[len(x):]
                ss.append(t_cut)
                if ( t_cut == "" ):
                    print("YES")
                    sys.exit(0)


print("NO")

Submission status: Accepted

Solution code:
## ABC 049C
## C - Daydream
import sys

s = input()
letter = ['dream','dreamer','erase','eraser']

ll = len(s)
while ll > 0:
    for le in range(len(letter)):
        if(ll-len(letter[le]) < 0):
            continue
        ss = s[ll-len(letter[le]):ll]
        # print("out:"+ss,letter[le])
        if(letter[le] == ss):
            ll -= len(letter[le])
            break
        else:
            if(le == len(letter)-1):
                print('NO')
                sys.exit()
            else:
                continue
        
print('YES')

Submission status: Accepted

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

import math

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

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

divide = [i[::-1] for i in divide]

can = True
i = 0
while i < len(s):
    # print("here")
    can2 = False
    for j in divide:
        # print("here2")
        # print("i: ", i, "len(j): ", len(j), "s[i:len(j)]", s[i:len(j)+i])
        if s[i:len(j)+i] == j:
            # print("here3")
            # print(s[i:len(j)])
            can2 = True
            i += len(j)
    if not can2:
        # print("here4")
        can = False
        break

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

Submission status: Accepted

Solution code:
S = list(input())

while len(S) != 0:
    if "".join(S[-5:]) == "dream" or "".join(S[-5:]) == "erase":
        del S[-5:]
    elif "".join(S[-6:]) == "eraser":
    #elif "".join(a[-6:]) == "eraser":
        del S[-6:]
    elif "".join(S[-7:]) == "dreamer":
        del S[-7:]
    else:
        break
    
if len(S) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#! /usr/bin/python3
# 白昼夢 / Daydream

S = input()

def main(s):
    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(S)

Submission status: Accepted

Solution code:
S = input()

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

for s in String:
    S = S.replace(s,'')

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

Submission status: Accepted

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

S = input()[::-1]
idx = 0
while idx < len(S):
    flag = False
    for i in range(4):
        if len(S) - idx < len(A[i]):
            continue
        else:
            if S[idx:idx+len(A[i])] == A[i]:
                flag = True
                idx += len(A[i])
                break
            else:
                continue
    if idx >= len(S) or flag == False:
        break

print(["NO","YES"][idx == len(S)])

Submission status: Accepted

Solution code:
W=["dream", "dreamer", "erase", "eraser"]
word=input()
while True:
    if word=="":
        print("YES")
        exit()

    ok = False
    for w in W:
        if word[-len(w):] == w:
            word = word[:-len(w)]
            ok = True
            break

    if not ok:
        print("NO")
        exit()

Submission status: Accepted

Solution code:
s = input()
i = 0

while i < len(s):
    if s[i:min(len(s),i+11)] == 'dreameraser':
        i += 11
    elif s[i:min(len(s),i+10)] == 'dreamerase':
        i += 10
    elif s[i:min(len(s),i+7)] == 'dreamer':
        i += 7
    elif s[i:min(len(s),i+6)] == 'eraser':
        i += 6
    elif s[i:min(len(s),i+5)] == 'erase':
        i += 5
    elif s[i:min(len(s),i+5)] == 'dream':
        i += 5
    else:
        print('NO')
        break
        
    if i == len(s):
        print('YES')
        break

Submission status: Accepted

Solution code:
s = str(input())
list_s = list(s)
while len(list_s) > 0:
    if list_s[-5:] == list("dream") or list_s[-5:] == list("erase"):
        for i in range(5):
            list_s.pop()
    elif list_s[-6:] == list("eraser"):
        for i in range(6):
            list_s.pop()
    elif list_s[-7:] == list("dreamer"):
        for i in range(7):
            list_s.pop()
    else:
        ans = "NO"
        break
else:
    ans = "YES"
print(ans)

Submission status: Accepted

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

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

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

#a : 開始インデックス
#b : 終了インデックス

a = 0
while a < len(S):
    can = False
    for i in range(4):
        d = divide[i]
        b = a + len(d)
        if S[a:b] == d:
            can = True
            a = b
            break
    if can == False:
        break

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

Submission status: Accepted

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

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

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

#a : 開始インデックス
#b : 終了インデックス

a = 0
while a < len(S):
    can = False
    for i in range(4):
        d = divide[i]
        d_size = len(d)
        b = a + d_size
        if S[a:b] == d:
            can = True
            a = b
    if can == False:
        break

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

Submission status: Accepted

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

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

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


i = 0
while i < len(S):
    can2 = False
    for j in range(4):
        d = divide[j]
        d_size = len(d)
        if S[i:d_size + i] == d:
            can2 = True
            i += d_size
    if can2 == False:
        break

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

Submission status: Accepted

Solution code:
s = input()

flg = 0
try:
	while flg == 0:
		if s[0] == "d":
			if s[:5] == "dream":
				if s[5] == "d":
					s = s[5:]
				elif s[5:7] == "er":
					if s[7] == "a": # erase(r)
						s = s[5:]
					elif len(s) == 7 or s[7] == "d" or s[7] == "e": #dreamer
						s = s[7:]
					else:
						flg = 1
				else:
					flg = 2
			else:
				flg = 3
		elif s[0] == "e":
			if s[:5] == "erase" and (len(s) == 5 or s[5] == "d" or s[5] == "e"):
				s = s[5:]
			elif s[:6] == "eraser" and (len(s) == 6 or s[6] == "d" or s[6] == "e"):
				s = s[6:]
			else:
				flg = 4
		else:
			flg = 7
	if flg != 0:
		#print(flg)
		print("NO")
except IndexError:
	if len(s) == 0:
		print("YES")
	elif s == "dream" or s == "dreamer" or s == "erase" or s == "eraser":
		print("YES")
	else:
		print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

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


def scan(n):
    for w in words:
        if revs[n:].startswith(w):
            return len(w)
    print('NO')
    exit()


n = 0
while revs[n:] != '':
    n += scan(n)

print('YES')

Submission status: Accepted

Solution code:
#AtCorder Begginer Contest 049 C Daydream

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

dream = "dream"[::-1]
dreamer = "dreamer"[::-1]
erase = "erase"[::-1]
eraser = "eraser"[::-1]

for i in range(len(s)):
    if s.startswith(dreamer):
        s = s.replace(dreamer,"",1)
    elif s.startswith(dream):
        s = s.replace(dream,"",1)

    if s.startswith(eraser):
        s = s.replace(eraser,"",1)
    elif s.startswith(erase):
        s = s.replace(erase,"",1)

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

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    S = input()
    i = len(S)
    while i > 0:
        ok = False
        for x in ["dreamer", "eraser", "dream", "erase"]:
            if S.startswith(x, i - len(x)):
                i -= len(x)
                ok = True
                break
        if not ok:
            print(NO)
            return
    print(YES)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

def match(pattern, strings):
	return re.match('^{0}'.format(pattern), strings)

def any_match(strings):
	return re.match('^dream|^erase', strings)

S = input()

i = 0
while i < len(S):
	if match('dreamer', S[i:]):
		i += len('dreamer')
		if any_match(S[i:]):
			continue
		else:
			if i == len(S):
				break
			else:
				i -= len('dreamer')
				i += len('dream')
				continue
	elif match('eraser', S[i:]):
		i += len('eraser')
		if any_match(S[i:]):
			continue
		else:
			if i == len(S):
				break
			else:
				i -= len('eraser')
				i += len('erase')
				continue
	elif match('dream', S[i:]):
		i += len('dream')
		continue
	elif match('erase', S[i:]):
		i += len('erase')
		continue
	else:
		print('NO')
		exit()

print('YES')