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()
s = s[::-1]
t = ["dream", "dreamer", "erase", "eraser"]
for i in range(len(t)):
    t[i] = t[i][::-1]
can = True
i = 0
while i < len(s):
    can2 = False
    for j in range(len(t)):
        d = t[j]
        if s[i:i+len(d)] == d:
            can2 = True
            i += len(d)
    if not can2:
        can = False
        break

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

Submission status: Accepted

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


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


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


def main():
    S = input()
    T = []
    i = 0
    while i <= len(S)-1:
        target = S[i:i+5]
        if target == A:
            i += len(A)
            T.append("A")
            continue
        if target == C:
            i += len(C)
            T.append("C")
            continue
        T.append(target[0])
        i += 1

    if T[0] != "A" and T[0] != "C":
        print("NO")
        return

    for i in range(1, len(T)):
        if T[i] == 'r':
            if T[i-1] == "e":
                if i >= 2 and T[i-2] == "A":
                    continue
                print('NO')
                return
            if T[i-1] == "C":
                continue
            print('NO')
            return

    print('YES')


main()

Submission status: Accepted

Solution code:

S = input()

S = S[::-1]

cand = {'maerd', 'remaerd', 'esare', 'resare'}

can = True

while S not in cand:
    ok = False
    for x in cand:
        if S[:len(x)] == x:
            S = S[len(x):]
            ok = True
            break
    if ok == False:
        can = False
        break

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

Submission status: Accepted

Solution code:
s=input()
l=['dreamer','eraser','dream','erase']
t=''
a=0
for c in s[::-1]:
    t=c+t
    if t in l:
        a+=len(t)
        t=''
print('YES'if a==len(s)else'NO')

Submission status: Accepted

Solution code:
def main2():
    S = input()
    idx = 0
    while idx < len(S):
        if S[idx:].startswith("dream"):
            e = S[idx+5:idx+5+3]

            if len(e) == 3:
                if e.startswith("d") or e == "era":
                    idx += 5

                elif e == "erd" or e == "ere":
                    idx += 7
                    
                else:
                    idx += 5

            elif len(e) == 2:
                if e == "er":
                    idx += 7
                else:
                    idx += 5

            elif len(e) == 1:
                idx += 5
            
            else:
                idx += 5

        elif S[idx:].startswith("eraser"):
            idx += 6

        elif S[idx:].startswith("erase"):
            idx += 5

        else:
            print("NO")
            exit()

    print("YES")

if __name__ == "__main__":
    main2()

Submission status: Accepted

Solution code:
S=input()
def solve(query):
    while 1:
        if not query:
            print("YES")
            break

        for frag in ("erase","eraser","dream","dreamer"):
            if query.endswith(frag):
                query=query[:-len(frag)]
                break
        else:
            print("NO")
            break

solve(S)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
I = ["dream", "dreamer", "erase", "eraser"]
I2 = input()
 
if I2.replace(I[1], "").replace(I[0], "").replace(I[3], "").replace(I[2], "").strip() == "":
  print("YES")
elif I2.replace(I[0], "").replace(I[2], "").replace(I[1], "").replace(I[3], "").strip() == "":
  print("YES")
elif I2.replace(I[2], "").replace(I[0], "").replace(I[3], "").replace(I[1], "").strip() == "":
  print("YES")
elif I2.replace(I[3], "").replace(I[2], "").replace(I[1], "").replace(I[0], "").strip() == "":
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
S = input()
words = ['dreamer','dream','eraser','erase']
i = len(S)
while i>0:
    update = False
    for w in words:
        if S[:i].endswith(w):
            i -= len(w)
            update =True
            break
    if not update:
        break
print('YES' if i == 0 else 'NO')

Submission status: Accepted

Solution code:
S = input()
words = ['dreameraser','dreamerase','dreamer','dream','eraser','erase']
i = 0
while i < len(S):
    update = False
    for w in words:
        if S[i:].startswith(w):
            i += len(w)
            update =True
            break
    if not update:
        break
print('YES' if i == len(S) else 'NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

s = input()
s = re.sub("eraser","",s)
s = re.sub("erase","",s)
s = re.sub("dreamer","",s)
s = re.sub("dream","",s)

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
i = 0
while N-i >4:
    if S[N-i-5:N-i] == "dream":
        i+=5
    elif N-i>6 and S[N-i-7:N-i]=="dreamer":
        i+=7
    elif S[N-i-5:N-i] == "erase":
        i += 5
    elif N-i>5 and S[N-i-6:N-i] =="eraser":
        i+=6
    else:
        break

if N == i:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import math
def main():
    s = input()
    lis = ["maerd", "remaerd", "esare", "resare"]
    s = s[::-1]

    i = 0
    while(i < len(s)-4):
        if(s[i:i+5] in lis):
            i+=5
        elif(i+7 <= len(s) and s[i:i+7]=="remaerd"):
            i += 7
        elif(i+6<=len(s) and s[i:i+6]=="resare"):
            i+=6
        else:
            print("NO")
            exit()
    print("YES")
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
t=n-1
while t>=0:
    if s[t]=='r':
        if t<5:
            print('NO')
            exit()
        elif s[t-1]=='e' and s[t-2]=='s' and s[t-3]=='a' and s[t-4]=='r' and s[t-5]=='e':
            t-=6
        elif t<6:
            print('NO')
            exit()
        elif s[t-1]=='e' and s[t-2]=='m' and s[t-3]=='a' and s[t-4]=='e' and s[t-5]=='r' and s[t-6]=='d':
            t-=7
        else:
            print('NO')
            exit()
    elif s[t]=='e':
        if t<4:
            print('NO')
            exit()
        elif s[t-1]=='s' and s[t-2]=='a' and s[t-3]=='r' and s[t-4]=='e':
            t-=5
        else:
            print('NO')
            exit()
    elif s[t]=='m':
        if t<4:
            print('NO')
            exit()
        elif s[t-1]=='a' and s[t-2]=='e' and s[t-3]=='r' and s[t-4]=='d':
            t-=5
        else:
            print('NO')
            exit()
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re


def main():
    print("YES" if re.match("^(dream|dreamer|erase|eraser)+$", input()) else "NO")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
while len(S)>0:
    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]
    else:
        break
print("YES" if len(S)==0 else "NO")

Submission status: Accepted

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

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

s = s[::-1]

while True:
    if s.startswith(list[0][::-1]):
        n -= 5
        s = s[5:]
    elif s.startswith(list[1][::-1]):
        n -= 7
        s = s[7:]
    elif s.startswith(list[2][::-1]):
        n -= 5
        s = s[5:]
    elif s.startswith(list[3][::-1]):
        n -= 6
        s = s[6:]
    else:
        break

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

Submission status: Accepted

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

Submission status: Accepted

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

s = "".join(reversed(list(s)))
while n:
    if s.startswith("maerd"):
        n -= 5
        s = s[5:]
    elif s.startswith("remaerd"):
        n -= 7
        s = s[7:]
    elif s.startswith("esare"):
        n -= 5
        s = s[5:]
    elif s.startswith("resare"):
        n -= 6
        s = s[6:]
    else:
        break
print("YES" if n == 0 else "NO")

Submission status: Accepted

Solution code:
s=input()
s=s[::-1]
f=0
l=['dream' ,'dreamer', 'erase','eraser']
l=[c[::-1] for c in l]
while(f==0):
    if(s[:7] in l):
        s=s[7:]
    elif(s[:6] in l):
        s=s[6:]
    elif(s[:5] in l):
        s=s[5:]
    else:
        f=1
if(len(s)==0):
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
def main(S):
  while len(S) > 0:
    if S[-1] == "m":
      if S[-5:] == "dream":
        S = S[:-5]
      else:
        print("NO")
        return 0
    elif S[-1] == "e":
      if S[-5:] == "erase":
        S = S[:-5]
      else:
        print("NO")
        return 0
    elif S[-1] == "r":
      if S[-6:] == "eraser":
        S = S[:-6]
      elif S[-7:] == "dreamer":
        S = S[:-7]
      else:
        print("NO")
        return 0
    else:
      print("NO")
      return 0
  else:
    print("YES")
    
main(input())

Submission status: Accepted

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

fi_flg = False
while fi_flg is False:
  if S[:7] in candidacies:
    S = S[7:]
  elif S[:6] in candidacies:
    S = S[6:]
  elif S[:5] in candidacies:
    S = S[5:]
  else:
    fi_flg = True

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

Submission status: Accepted

Solution code:
S = input()
strs = list(reversed(S))
rev_S = ''.join(strs)
while True:
  if rev_S[:6] == 'resare':
    rev_S = rev_S[6:]
    continue
  elif rev_S[:7] == 'remaerd':
    rev_S = rev_S[7:]
    continue
  elif rev_S[:5] == 'esare' or rev_S[:5] == 'maerd':
    rev_S = rev_S[5:]
    continue
  else:
    break

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

Submission status: Accepted

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

PARTS = ["eraser", "erase", "dreamer", "dream"]
# PARTS2 = []


def main():
    global PARTS2
    sys.setrecursionlimit(100000)
    S = input()

    # for i in range(0, 4):
    #     for j in range(0, 4):
    #         PARTS2.append(PARTS[i] + PARTS[j])

    # PARTS2 = PARTS2 + PARTS

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


def judgeStr2(target: str) -> bool:
    currentStr = target
    while currentStr != "":
        isNextOK = False
        for item in PARTS:
            if not currentStr.startswith(item):
                continue

            tempStr = currentStr.replace(item, "", 1)
            if tempStr == "":
                return True

            for item2 in PARTS:
                if tempStr.startswith(item2):
                    isNextOK = True
                    break

            if isNextOK:
                currentStr = tempStr
                break
        if isNextOK:
            continue
        else:
            break
    return currentStr == ""


def judgeStr(target: str) -> bool:
    for item in PARTS:
        if target.startswith(item):
            tempStr = target.replace(item, "", 1)
            if tempStr == "" or judgeStr(tempStr):
                return True

    return False


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()

while len(S) > 0:
    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]
    else :
        break

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

Submission status: Accepted

Solution code:
# coding: utf-8
import math
#n = int(input())
#x, y = map(int,input().split())
#A = list(map(int,input().split()))
ans = 0
s = input()
n = len(s)
s=s[::-1]
i=0
flg=True
while True:
    if i>=n:
        break
    if s[i:i+7]=="remaerd":
        i+=7
    elif s[i:i+6]=="resare":
        i+=6
    elif s[i:i+5]=="maerd" or s[i:i+5]=="esare":
        i+=5
    else:
        flg=False
        break
if flg:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = str(input())

s = "".join(list(reversed(s)))

y = 0

for _ in range(100000):
    if y == len(s):
        print("YES")
        break
    elif s[y:y+7] == "remaerd":
        y += 7
        #print(y)
    elif s[y:y+6] == "resare":
        y += 6
        #print(y)
    elif s[y:y+5] == "esare":
        y += 5
        #print(y)
    elif s[y:y+5] == "maerd":
        y += 5
    else:
        print("NO")
        break

Submission status: Accepted

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

s = "".join(reversed(list(s)))
while n:
    if s.startswith("maerd"):
        n -= 5
        s = s[5:]
    elif s.startswith("remaerd"):
        n -= 7
        s = s[7:]
    elif s.startswith("esare"):
        n -= 5
        s = s[5:]
    elif s.startswith("resare"):
        n -= 6
        s = s[6:]
    else:
        break
print("YES" if n == 0 else "NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C - 白昼夢
def main():
    s = list(input())
    
    while len(s) != 0:
        if ''.join(s[-5:]) == 'dream':
            for _ in range(5):
                s.pop()
        elif ''.join(s[-7:]) == 'dreamer':
            for _ in range(7):
                s.pop()
        elif ''.join(s[-5:]) == 'erase':
            for _ in range(5):
                s.pop()
        elif ''.join(s[-6:]) == 'eraser':
            for _ in range(6):
                s.pop()
        else:
            print('NO')
            exit()
    else:
        print('YES')


if __name__ ==  "__main__":
    main()

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

s = input()

ans = "YES"
while True:
    if len(s) < 5:
        ans = "NO"
        break
    elif len(s) == 5:
        if (s != "dream" and s != "erase"):
            ans = "NO"
        break
    elif len(s) == 6:
        if (s != "eraser"):
            ans ="NO"
        break
    elif len(s) == 7:
        if (s != "dreamer"):
            ans ="NO"
        break
    else:
        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:
            ans = "NO"
            break
print(ans)

Submission status: Accepted

Solution code:
def main():
	S = input()

	border = len(S)

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

	if border == 0:
		print("YES")
	else:
		print("NO")
 
 
if __name__ == "__main__":
  	main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


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



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
s = list(input())
while(len(s) > 0):
    if (''.join(s[-5:]) == 'dream'):
        for i in range(5):
            s.pop()
    elif (''.join(s[-5:]) == 'erase'):
        for i in range(5):
            s.pop()
    elif (''.join(s[-6:]) == 'eraser'):
        for i in range(6):
            s.pop()
    elif (''.join(s[-7:]) == 'dreamer'):
        for i in range(7):
            s.pop()
    else:
        print('NO')
        sys.exit()
print('YES')

Submission status: Accepted

Solution code:
S=input()
W=[0]*(len(S)+1)
W[0]=1
words=['dream','dreamer','erase','eraser' ]
for i in range(len(S)):
  if W[i]==0:
    continue
  for k in words:
    if S[i:i+len(k)]==k:
      W[i+len(k)]=1
if W[len(S)]==1:
  print("YES")
  exit()
else:
  print("NO")

Submission status: Accepted

Solution code:
s = ''.join(list(reversed(input())))
words = {'remaerd', 'resare', 'maerd', 'esare'}
word = ''
j = 0
for i in range(len(s)-4):
    if j == 0:
        a = s[i:i+5]
        b = s[i:i+6]
        c = s[i:i+7]
        if a in words:
            word += a
            j = 4
        elif b in words:
            word += b
            j = 5
        elif c in words:
            word += c
            j = 6
    else:
        j -= 1
if word == s:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
s=''.join(reversed(list(input())))
t=''
text = ['maerd', 'esare', 'resare', 'remaerd']
while len(t) < len(s):
  for tx in text:
    if t + tx == s[:len(t+tx)]:
      t += tx
      break
  else:
    print('NO')
    sys.exit()
print('YES')

Submission status: Accepted

Solution code:
def main():
    text = input()
    words = ['dreamer', 'eraser', 'dream', 'erase']
    length = len(text)
    while text:
        for word in words:
            if text.endswith(word):
                text = text[:-len(word)]
        else:
            if (new := len(text)) != length:
                length = new
            else:
                return 'NO'
    return 'YES'


if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

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

ind = 0
while ind < len(S):
    flg = False
    for s in Ss:
        n = len(s)
        if S_r[ind:ind+n] == s:
            ind += n
            flg = True
    if not flg:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
s = input()
should_continue = True

while should_continue:
    should_continue = False
    if len(s) >= 6:
        s6 = s[0:6]
        if s6 == "dreamd" or s6 == "erased" or s6 == "erasee":
            s = s[5:]
            should_continue = True
    if len(s) >= 7:
        if s6 == "eraser":
            s = s[6:]
            should_continue = True
    if len(s) >= 8:
        s8 = s[:8]
        if s8 == "dreamerd" or s8 == "dreamere":
            s = s[7:]
            should_continue = True
        elif s8 == "dreamera":
            s = s[5:]
            should_continue = True

if s == "dream" or s == "dreamer" or s == "erase" or s == "eraser":
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s=input()
x=["eraser","erase","dreamer","dream",]
t=[]
flag=0
for i in range(4):
    if x[i] in s:
        s=s.replace(x[i],"1")
S=len(s)

for j in range(S) :
    if s[j]!="1":
        print("NO")
        flag+=1
        break

if flag==0:
    print("YES")

Submission status: Accepted

Solution code:
S = input()
s = S.split("a")
H = S.split("a",1)
h=H[0]
B = S.rsplit("a",1)
b=B[1]
X = set(s)
if h in ["dre","er"]:
  if b in ["m","mer","se","ser"]:
    if X <= {"dre","er","m","mer","se","ser","mdre","merdre","mer","merer","sedre","serdre","seer","serer"}:
      print("YES")
    else:
      print("NO")  
  else:
    print("NO")
else:
  print("NO")

Submission status: Accepted

Solution code:
s = input()
now = len(s)
while 1:
    flag = 1
    if 7 <= now:
        if s[now-7:now] == "dreamer":
            now -= 7
            flag = 0
    if 6 <= now:
        if s[now-6:now] == "eraser":
            now -= 6
            flag = 0
    if 5 <= now:    
        if s[now-5:now] == "erase":
            now -= 5
            flag = 0
        if s[now-5:now] == "dream":
            now -= 5
            flag = 0
    if flag:
        print("NO")
        exit()
    if now == 0:
        print("YES")
        exit()
    elif now < 5:
        print("NO")
        exit()

Submission status: Accepted

Solution code:
S=input()

dp=[False]* (len(S)+1)

dp[0] = True

for i in range(1, len(dp)):
  for w in [ 'dream', 'dreamer', 'erase', 'eraser']:
    if dp[i-len(w)] and w == S[i-len(w):i]:
      dp[i] = True

if dp[-1]:
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
import re;print("YNEOS"[re.match("(erase(r)?|dream(er)?)+$",input())is None::2])

Submission status: Accepted

Solution code:
import re
print("YNEOS"[re.fullmatch(r"(erase(r)?|dream(er)?)+", input()) is None::2])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import re
s = input()
s = re.sub(r'erase(r|)',"", s)
s = re.sub(r'dream(er|)',"", s)
print('YNEOS'[s!=""::2])

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('NO')
else:
  print('YES')

Submission status: Accepted

Solution code:
S =input()
ls_S = list(S)
ans = "YES"

while len(ls_S) != 0:
  if "".join(ls_S[len(ls_S)-5:]) == "dream":
    ls_S = ls_S[:len(ls_S)-5]
  elif "".join(ls_S[len(ls_S)-5:]) == "erase":
    ls_S = ls_S[:len(ls_S)-5]
  elif "".join(ls_S[len(ls_S)-7:]) == "dreamer":
    ls_S = ls_S[:len(ls_S)-7] 
  elif "".join(ls_S[len(ls_S)-6:]) == "eraser":
    ls_S = ls_S[:len(ls_S)-6]
  else:
    ans = "NO"
    break
print(ans)

Submission status: Accepted

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

B=""
while B!=S:
    B=S
    for X in F:
        a=len(X)
        if S[-a:]==X:
            S=S[:-a]

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

Submission status: Accepted

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

Submission status: Accepted

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

pointer=0
while 1:
  if pointer == len(S):
    print('YES')
    exit()
  if pointer >= len(S)-4:
    print('NO')
    exit()
  if S[pointer:pointer+5] in {'dream'[::-1],'erase'[::-1]}:
    pointer += 5
    continue
  elif S[pointer:pointer+6] == 'eraser'[::-1]:
    pointer += 6
    continue
  elif S[pointer:pointer+7] == 'dreamer'[::-1]:
    pointer += 7
    continue
  else:
    print('NO')
    exit()

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
dp = [0] * (n+1)
dp[0] = 1
for i in range(1,n+1):
    if i >= 5:
        if s[i-5:i] == "dream" or s[i-5:i] == "erase":
            dp[i] = dp[i-5]
    if i >= 6:
        if s[i-6:i] == "eraser":
            dp[i] = dp[i-6]
    if i >= 5:
        if s[i-7:i] == "dreamer":
            dp[i] = dp[i-7]
if dp[n]:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

while len(s) >= 5:
    if len(s) >= 5 and s[-5:] == 'dream':
        s = s[:-5]

    elif len(s) >= 7 and s[-7:] == 'dreamer':
        s = s[:-7]

    elif len(s) >= 5 and s[-5:] == 'erase':
        s = s[:-5]

    elif len(s) >= 6 and s[-6:] == 'eraser':
        s = s[:-6]

    else:
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

def checklast(s):
    # print(s)
    for word in str_list:
        if s[-len(word):] == word:
            return s[:-len(word)]
    else:
            return None
    
for i in range(100000):
    if s is None:
        print("NO")
        break
    if len(s) == 0:
        print("YES")
        break
    s = checklast(s)

Submission status: Accepted

Solution code:
S = input()
T = ''

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

for word in add_word:
    S = S.replace(word, '')

if S == T:
    ans = 'YES'
else:
    ans = 'NO'

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50

def dfs(n,seq):
    if seq[n:] in ['dreamer', 'dream', 'erase', 'eraser']:
        return True

    if seq[n:n+7] == 'dreamer':
        if dfs(n+5, seq):
            return True
        elif dfs(n+7, seq):
            return True
        else:
            return False

    elif seq[n:n+5] == 'dream':
        return dfs(n+5, seq)

    elif seq[n:n+6] == 'eraser':
        return dfs(n+6, seq)

    elif seq[n:n+5] == 'erase':
        return dfs(n+5, seq)
    else:
        return False


def run():
    S = input()
    if dfs(0,S):
        print('YES')
    else:
        print('NO')


if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
def resolve():
    S = input()
    pats = ('dream', 'dreamer', 'erase', 'eraser')

    dp = [False for _ in range(len(S) + 1)]
    dp[0] = True
    for i in range(len(S)):
        if not dp[i]:
            continue
        for pat in pats:
            if S[i:i + len(pat)] == pat:
                dp[i + len(pat)] = True
    if dp[-1]:
        print("YES")
    else:
        print("NO")


resolve()

Submission status: Accepted

Solution code:
s=input()
t=''
while s!='':
  if len(s)<=4:
    break
  elif s[:5]=='dream':
    if len(s)>=10 and s[5:10]=='erase':
      s=s[5:]
      continue
    elif len(s)>=7 and s[5:7]=='er':
      s=s[7:]
      continue
    else:
      s=s[5:]
      continue
  elif s[:5]=='erase':
    if len(s)>=6 and s[5]=='r':
      s=s[6:]
      continue
    else:
      s=s[5:]
      continue
  
  elif s[:5]!='dream' and s[:5]!='erase':
    break
      
    
if s=='':
  print('YES')
  
else:
  print('NO')

Submission status: Accepted

Solution code:
S = input()

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

    if idx == 0:
        print('YES')
        break

Submission status: Accepted

Solution code:
S=input()[::-1]
N=len(S)
T=['maerd','esare','resare','remaerd']
ans='YES'
i=0
while i<N:
    if S[i:i+5]==T[0]:
        i+=5
    elif S[i:i+5]==T[1]:
        i+=5
    elif S[i:i+6]==T[2]:
        i+=6
    elif S[i:i+7]==T[3]:
        i+=7
    else:
        ans='NO'
        break
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[1]:


S = input()


# In[4]:


f = True
s_reversed = S[::-1]
words = ['maerd', 'remaerd', 'esare', 'resare']
while s_reversed:
    length = len(s_reversed)
    for i in [7,6,5]:
        while s_reversed[:i] in words:
            s_reversed = s_reversed[i:]
    if length == len(s_reversed):
        print("NO")
        f = False
        break
if f:
    print("YES")


# In[ ]:

Submission status: Accepted

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

Submission status: Accepted

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

while s:
    l = len(s)
    for i in[7,6,5]:
        while s[:i:] in t:
            s = s[i::]
    if l == len(s):
        print('NO')
        exit()
print('YES')