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

tmp = len(S)

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

Submission status: Accepted

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

S = input()[::-1]

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

while len(S)!=0:

    if S[:5] == Moji[0] or S[:5] == Moji[3]:
        S = S[5:]
    elif S[:6] == Moji[2]:
        S = S[6:]
    elif S[:7] == Moji[1]:
        S = S[7:]
    else:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

Solution code:
import numpy as np
import math
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

s = list(input())
s.reverse()
v = []
v.append(list("dream"))
v.append(list("erase"))
v.append(list("eraser"))
v.append(list("dreamer"))
for i in range(4):
    v[i].reverse()

now = 0
while(1):
    check = False
    for i in range(4):
        if now+len(v[i]) > len(s): continue
        tmp = ''.join(s[now:now+len(v[i])])
        x = ''.join(v[i])
        if tmp == x:
            check = True
            now += len(v[i])
        if check: break
    if not check: break
    if now == len(s): break

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

Submission status: Accepted

Solution code:
n = input()
t = ["dream", "dreamer", "erase", "eraser"]

while True:
  if not n:
    status = "YES"
    break

  elif n[-5:] in t:
    n = n[:-5]
    
  elif n[-6:] in t:
    n = n[:-6]
  
  elif n[-7:] in t:
    n = n[:-7]
    
  else:
    status = "NO"
    break
    
print(status)

Submission status: Accepted

Solution code:
s = input()

while True:
    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]
    elif len(s) == 0:
        print('YES')
        break
    else:
        print("NO")
        break

Submission status: Accepted

Solution code:
S = input()[::-1]
f = False
while True:
  if S[:5]=="maerd":
    S = S[5:]
    continue
  elif S[:5]=="esare":
    S = S[5:]
    continue
  elif S[:7]=="remaerd":
    S = S[7:]
    continue
  elif S[:6]=="resare":
    S = S[6:]
    continue
  elif S == "":
    f = True
    break
  else:
    break
print("YES" if f else "NO")

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    S = rl().rstrip()
    
    i = 0
    while i < len(S):
        sub_str = S[i:i + 5]
        if sub_str == 'dream':
            i += 5
            if i < len(S) - 2 and S[i:i + 2] == 'er' and S[i + 2] != 'a' or \
               i == len(S) - 2 and S[i:i + 2] == 'er':
                i += 2
        elif sub_str == 'erase':
            i += 5
            if i < len(S) and S[i] == 'r':
                i += 1
        else:
            print('NO')
            return
    print('YES')


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

while len(newstring)>0:
    if newstring[:5]=="maerd":
        newstring=newstring[5:]

    elif newstring[:7]=="remaerd":
        newstring=newstring[7:]

    elif newstring[:5]=="esare":
        newstring=newstring[5:]

    elif newstring[:6]=="resare":
        newstring=newstring[6:]

    else:
        print("NO")
        exit()

print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    D = ['dream', 'dreamer', 'erase', 'eraser']
    D = [d[::-1] for d in D]
    tmp = ''
    for s in S[::-1]:
        tmp = ''.join([tmp, s])
        if tmp in D:
            tmp = ''
        if len(tmp) > 7:
            print('NO')
            exit()
    if tmp == '':
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

can = True
i = 0
while i < len(S):
  can2 = False
  for d in divide:
    if S[i:i+len(d)] == d:
      can2 = True
      break
  i += len(d)*(can2)
  if not can2:
    can = False
    break
print("YNEOS"[~can%2::2])

Submission status: Accepted

Solution code:
import sys
import re

input = sys.stdin.readline

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)


def read():
    S = input().strip()
    return S,


def solve(S):
    N = len(S)
    
    def dfs(i):
        enable = False
        if i == N:
            return True
        elif i > N:
            return False
        if S[i:i+7] == "dreamer":
            enable |= dfs(i+7)
        if S[i:i+6] == "eraser":
            enable |= dfs(i+6)
        if S[i:i+5] in ["dream", "erase"]:
            enable |= dfs(i+5)
        return enable
    
    return "YES" if dfs(0) else "NO"


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    S = SI()
    l = len(S)
    S = S[::-1] + "ppppppp"
    W = ["maerd", "remaerd", "esare", "resare"]
    idx = 0
    while idx < l:
        no_flag = True
        for w in W:
            if S[idx: idx+len(w)] == w:
                idx += len(w)
                no_flag = False

        if no_flag:
            print("NO")
            exit()

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



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
T = ''
U = ['dreamer', 'dream', 'eraser', 'erase']
answer = 'NO'
list = [T]
done = 0

while done == 0:
    for l in list:
        list.remove(l)
        for u in U:
            if S.startswith(l + u):
                if S == l + u:
                    answer = 'YES'
                    done = 1
                list.append(l + u)
    if list == []:
        done = 1
print(answer)

Submission status: Accepted

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

    while len(S) >= 5:
        if len(S) >= 7 and S[-7:] == "dreamer":
            S = S[:-7]
            continue

        if len(S) >= 6 and S[-6:] == "eraser":
            S = S[:-6]
            continue

        elif S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue

        else:
            break

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

main()

Submission status: Accepted

Solution code:
# C - 白昼夢

S = str(input())
S = S[::-1]
l = len(S)
i = 0
ans = 'YES'
while True:
    if S[i:i+5] == 'maerd' or S[i:i+5] == 'esare':
        i += 5
        if i == l:
            break
    elif S[i:i+6] == 'resare':
        i += 6
        if i == l:
            break
    elif S[i:i+7] == 'remaerd':
        i += 7
        if i == l:
            break
    else:
        ans = 'NO'
        break
print(ans)

Submission status: Accepted

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


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

    t = ["dream", "dreamer", "erase", "eraser"]
    table = [ti[::-1] for ti in t]

    while len(s) > 0:
        flg = True
        for ti in table:
            if s[:len(ti)] == ti:
                s = s[len(ti):]
                flg = False
                break
        if flg:
            break

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
s = input()
while True:
  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')
    sys.exit()
  if s == '':
    print('YES')
    sys.exit()

Submission status: Accepted

Solution code:
s = input()
s_rev = s[::-1]
T_list = ['maerd', 'remaerd', 'esare', 'resare']
 
def mojicut(s, r):
    n = s.replace(r, "", 1)
    return n
 
 
while len(s_rev) > 0:
    s_len = len(s_rev)
    for i in T_list:
        if s_rev.startswith(i):
            s_rev = mojicut(s_rev, i)
            break
    if len(s_rev) == s_len:
        break
 
if len(s_rev) > 0:
    print("NO")
else:
    print("YES")

Submission status: Accepted

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

word_list = ["eraser","erase","dreamer","dream"]
for i in word_list:
    s = s.replace(i,".")

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

Submission status: Accepted

Solution code:
s = str(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:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun  3 18:19:05 2020

@author: NEC-PCuser
"""

S = input()

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

print(ans)

Submission status: Accepted

Solution code:
init = input()

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

def reverseWord(str):
  return str[::-1]

def elimTheWord(str):
  for word in reversed_words:
    if str.find(word) == 0:
      str = str[len(word):]
  return str

reversed_words = list(map(reverseWord, words))

# main
target = reverseWord(init)

while True:
  pivot = elimTheWord(target)
  if pivot == '':
    print('YES')
    break
  if pivot == target:
    print('NO')
    break
  target = pivot

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
S = input()

ret = set()
for i in range(len("dreamer")):
    ret.add("dreamer"[i:])
for i in range(len("eraser")):
    ret.add("eraser"[i:])
for i in range(len("dream")):
    ret.add("dream"[i:])
for i in range(len("erase")):
    ret.add("erase"[i:])

word = ""

for i in reversed(range(len(S))):
    word = S[i] + word
    if word not in ret:
        print("NO")
        exit()
    elif word == "dreamer" or word == "eraser":
        word = ""
    elif word == "dream" or word == "erase":
        word = ""
    else:
        continue

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

Submission status: Accepted

Solution code:
s = input()
for word in ["eraser","erase","dreamer","dream"]:
    s = s.replace(word,".")
if len(set(s)) == 1:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
def main():
    S = input()
    for word in ["eraser", "erase", "dreamer", "dream"]:
        S = S.replace(word, ".")
    # print(S)
    if len(set(S)) == 1:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import re
s = input()
if re.search('^(dreamer|eraser|dream|erase)*$', s):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input()
A = ['dream', 'dreamer', 'erase' ,'eraser' ]
A_re = []

S_re = list(reversed(S))
for i in range(0, 4):
    A_re.append(''.join(list(reversed(A[i]))))

can = True
i = 0

while i < len(S):
    can2 = False
    for j in range(0, 4):
        d = A_re[j]
        S_word = ''.join(S_re[i:(i + len(d))])
        if S_word == d:
            can2 = True
            i += len(d)
            break

    if can2 == False:
        can = False
        break

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

Submission status: Accepted

Solution code:
S = input()
i = len(S)
w1 = 'dream'
w2 = 'dreamer'
w3 = 'erase'
w4 = 'eraser'
a,b,c,d = 0,5,2,1
answer = ''
flag = True

while flag:
    if S[a:b] == w1:
        if i == b :
            answer = 'YES'
            break
        elif S[a:b + c] == w2:
            if i == b + c:
                answer = 'YES'
                break
            
            if S[b :b + 5] == w3:
                if i == b + 5 :
                    answer = 'YES'
                    break
                if S[b :b + 6] == w4:
                    if i == b + 6:
                        answer = 'YES'
                        break
                    a += len(w4)+len(w1)
                    b += len(w4)+len(w1)
                    
                else:
                    a += len(w3)+len(w1)
                    b += len(w3)+len(w1)
            
            else:
                a += len(w2)
                b += len(w2)
        else:
            a += len(w1)
            b += len(w1)
    elif S[a:b] == w3:
        if i == b :
            answer = 'YES'
            break

        if S[a:b + d] == w4:
            if i == b + d :
                answer = 'YES'
                break
            a += len(w4)
            b += len(w4)
        else:
            a += len(w3)
            b += len(w3)
    else:
        answer = 'NO'
        break

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
def S(): return stdin.readline().rstrip()

a = S()
strl = ['dream','dreamer','erase','eraser']
t = ''
for i in range(len(a)-1,-1,-1):
    if 7<len(t):
        print('NO')
        exit()
    else:
        t = a[i]+t
        if t in strl:
            t = ''

print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
dp = [0]*(len(S) + 1)
dp[0] = 1

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

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

Submission status: Accepted

Solution code:
import re

s = input()

m = re.match(r"^(dream|dreamer|erase|eraser)+$", s)

print("NO" if m is None else "YES")

Submission status: Accepted

Solution code:
def solve():

    S = input()

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

    while(True):
        if(len(S) == 0):
            break
        flag = False
        for w in words:
            if(S.endswith(w)):
                S = S[0:len(S) - len(w)]
                flag = True
        
        if(not flag):
            print('NO')
            return
            
        
    print('YES')
    
solve()

Submission status: Accepted

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

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

S = input()

## Logic

S = S[::-1]

i = 0 
while i < len(S):
    if S[i:i+7]=="remaerd":
        i = i + 7
    elif S[i:i+6]=="resare":
        i = i + 6
    elif S[i:i+5]=="maerd":
        i = i + 5
    elif S[i:i+5]=="esare":
        i = i + 5
    else:
        print("NO")
        sys.exit()
print("YES")

Submission status: Accepted

Solution code:
s = input()[::-1]
word = ["dream", "dreamer", "erase", "eraser"]
dream = "dream"[::-1]
dreamer = "dreamer"[::-1]
erase = "erase"[::-1]
eraser = "eraser"[::-1]
while True:
    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
    break
if len(s) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

for str in array:
    S = S.replace(str," ")
ans = S.replace(" ","")
if len(ans) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:

s = input()

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

while len(s) > 0:
    for word in words:
        flg = False

        if s.endswith(word):
            s = s[:(len(s) - len(word))]
            flg = True
            break

    if not flg:
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = str(input())

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

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

fin = True
com1 = False
cont = 0

for i in range(len(S)):
    if cont > 0:
        cont -= 1
        continue
    for j in range(len(words)):
        if words[j] == S[i:i+len(words[j])]:
            com1 = True
            cont = len(words[j]) - 1
            break
    if com1 == False:
        fin = False
        break
    com1 = False

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

Submission status: Accepted

Solution code:
S = str(input())

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

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

fin = True
com1 = False
cont = 0

for i in range(len(S)):
    if cont > 0:
        cont -= 1
        continue
    for j in range(len(words)):
        if words[j] == S[i:i+len(words[j])]:
            com1 = True
            cont = len(words[j]) - 1
            break
    if com1 == False:
        fin = False
        break
    com1 = False

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

Submission status: Accepted

Solution code:
S=input()
str_list=["dreamer","eraser","dream","erase"]
     
while True:
  S_tmp=S
  for str in str_list:
    if S[-len(str):]==str:
      S=S[0:len(S)-len(str)]
        
  if S_tmp==S:
    break    
        
if S=="":
  print("YES")
if S!="":
  print("NO")

Submission status: Accepted

Solution code:
s = input()

import re
output ="NO"
s = re.sub('dreameraser', 'A', s)
s = re.sub('dreamerase', 'A', s)
s = re.sub('dreamer', 'A', s)
s = re.sub('eraser', 'A', s)
s = re.sub('erase', 'A', s)
s = re.sub('dream', 'A', s)
if s.isupper() :
    output = "YES"
print(output)

Submission status: Accepted

Solution code:
s = input()

import re
output ="NO"
s = re.sub('eraser', '', s)
s = re.sub('erase', '', s)
s = re.sub('dreamer', '', s)
s = re.sub('dream', '', s)
if s == "":
    output = "YES"
print(output)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = list(input())

def check(s):
	#print(s)
	if s == []:
		print("YES")
	elif s[-7:] == list("dreamer"):
		del s[-7:]
		check(S)
	elif s[-6:] == list("eraser"):
		del s[-6:]
		check(s)
	elif any(s[-5:] == list(x) for x in ["dream", "erase"]):
		del s[-5:]
		check(s)
	else:
		print("NO")

check(S)

Submission status: Accepted

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

now = 0
while now < len(s):
    if s[now:now + 7] == 'dreamer'[::-1]:
        now += 7
    elif s[now:now + 6] == 'eraser'[::-1]:
        now += 6
    elif s[now:now + 5] == 'dream'[::-1]:
        now += 5
    elif s[now:now + 5] == 'erase'[::-1]:
        now += 5
    else:
        print('NO')
        exit()

print('YES')

Submission status: Accepted

Solution code:
import re

def main():
    s = list(input())
    sr = ''.join(list(reversed(s)))
    t = ['dream', 'dreamer', 'erase', 'eraser']
    tr = list()
    for i in t:
        tr.append(''.join(list(reversed(i))))
    while sr:
        flag = False
        for i in tr:
            if sr.startswith(i):
                sr = sr.replace(i ,'', 1)
                flag = True
        if not flag:
            print('NO')
            break
        if sr == '':
            print('YES')
            break
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()

s1 = s.replace("eraser", 'xxx')
s2 = s1.replace("erase", 'xxx')
s3 = s2.replace("dreamer", 'xxx')
s4 = s3.replace("dream", 'xxx')

s5 = s4.strip('x')

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

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
a1= 'eraser'
a2= 'erase'
a3= 'dreamer'
a4= 'dream'
a1= a1[::-1]
a2= a2[::-1]
a3= a3[::-1]
a4= a4[::-1]

a = S.replace(a1, '').replace(a2, '').replace(a3, '').replace(a4, '')

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

Submission status: Accepted

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


def reverse(t):
    return t[::-1]


RT = [reverse(t) for t in T]
RS = reverse(S)
can = True
i = 0
while i < len(RS):
    can2 = False
    for j in range(4):
        sizeT = len(RT[j])
        if RT[j] == RS[i:i + sizeT]:
            i += sizeT
            can2 = True
            break

    if not can2:
        can = False
        break

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

Submission status: Accepted

Solution code:
s = input()

s2 = s
word_list = ['dream', 'dreamer', 'erase', 'eraser']
while len(s2) > 0:
  match_flg = False
  for word in word_list:
    if s2[-len(word):] == word:
      s2 = s2[:(len(s2)-len(word))]
      match_flg = True
      break
  if not match_flg:
    break
if len(s2) == 0:
  print('YES')
else:
  print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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:
        break


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

Submission status: Accepted

Solution code:
import sys
import math
import numpy as np
import copy

def main():
    s = input()

    a, b, c, d = "dream", "dreamer", "erase", "eraser"
    ra, rb, rc, rd = a[::-1], b[::-1], c[::-1], d[::-1]
    rs = s[::-1]

    while rs:
        flag = False
        for ele in [ra, rb, rc, rd]:
            if rs.startswith(ele):
                rs = rs.replace(ele, "", 1)
                flag = True
        if not flag:
            print("NO")
            return 0
    
    print("YES")
    return 0

if __name__ == '__main__':
    sys.exit(main())

Submission status: Accepted

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

s = sinput()

a = "dream"
b = "dreamer"
c = "erase"
d = "eraser"

s = "".join(s.split(d))
s = "".join(s.split(c))
s = "".join(s.split(b))
s = "".join(s.split(a))

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

Submission status: Accepted

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

s = sinput()[::-1]

a = "dream"[::-1]
b = "dreamer"[::-1]
c = "erase"[::-1]
d = "eraser"[::-1]

s = "".join(s.split(d))
s = "".join(s.split(c))
s = "".join(s.split(b))
s = "".join(s.split(a))

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

Submission status: Accepted

Solution code:
S=input()

reverse_S=S[::-1]

while True:
    if (reverse_S.find('maerd')==0 or
        reverse_S.find('esare')==0
        ):
        reverse_S=reverse_S[5:]

    elif reverse_S.find('remaerd')==0:
        reverse_S=reverse_S[7:]
        
    elif reverse_S.find('resare')==0:
        reverse_S=reverse_S[6:]

    else:
        break

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

Submission status: Accepted

Solution code:
import re
moji = str(input())
moji = re.sub("eraser", "", moji)
moji = re.sub("erase", "", moji)
moji = re.sub("dreamer", "", moji)
moji = re.sub("dream", "", moji)
 
if len(moji) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
#白昼夢
s = input()
words = ['dream','dreamer','erase','eraser']
#evaluate
while True:
  for i in range(4):
    if s.endswith(words[i]):
      s = s[:-len(words[i])]
      break #inner loop
  else:
    print('NO')
    break #outerloop
  if not s: 
    print('YES')
    break #outerloop

Submission status: Accepted

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