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:
import math
import bisect
from queue import Queue
from collections import deque

s = input()

dp = [0 for _ in range(len(s)+1)]

dp[0] = 1

for i in range(len(s)+1):
    if(dp[i] == 1):
        if(i+4 < len(s)):
            if("".join(s[i:i+5]) == "dream"):
                dp[i+5] = 1
            if ("".join(s[i:i + 5]) == "erase"):
                dp[i+5] = 1
        if (i + 6 < len(s)):
            if ("".join(s[i:i + 7]) == "dreamer"):
                dp[i + 7] = 1
        if (i + 5 < len(s)):
            if ("".join(s[i:i + 6]) == "eraser"):
                dp[i + 6] = 1

if(dp[len(s)] == 1):
    print("YES")
else:
    print("NO")

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()
s = s[::-1]
# print(s)
key = 0
#print(s[:5])
while len(s) > 0:
    if s[:5] in ['maerd', 'esare']:
        s = s[5:]
        #print(s)
    elif s[:6] == 'resare':
        s = s[6:]
        #print(s)
    elif s[:7] == 'remaerd':
        s = s[7:]
        #print(s)
    else:
        key = 1
        break
if key == 0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

X = ['dream', 'dreamer', 'erase', 'eraser']
X = [s[::-1] for s in X]
i = 0
while i < len(S):
  if i+5 <= len(S) and S[i+2] == 'e':
    if S[i:i+5] == X[0]:
      i += 5
    else:
      print('NO')
      break
  elif i+7 <= len(S) and S[i+2] == 'm':
    if S[i:i+7] == X[1]:
      i += 7
    else:
      print('NO')
      break
  elif i+5 <= len(S) and S[i+2] == 'a':
    if S[i:i+5] == X[2]:
      i += 5
    else:
      print('NO')
      break
  elif i+6 <= len(S) and S[i+2] == 's':
    if S[i:i+6] == X[3]:
      i += 6
    else:
      print('NO')
      break
  else:
    print('NO')
    break
else:
  print('YES')

Submission status: Accepted

Solution code:
s = input()
words = ['maerd', 'remaerd', 'esare', 'resare']
reverse_s = list(reversed(s))
current = 0

while current < len(s):
    diff = 0
    for word in words:
        if "".join(reverse_s[current:current+len(word)]) == word:
            diff = len(word)
            break
    if diff == 0:
        break
    current += diff
if current == len(s):
    print('YES')
else:
    print("NO")

Submission status: Accepted

Solution code:
import re
s = input()
str = ["dream","dreamer","erase","eraser"]
str = ["maerd","remaerd","esare","resare"]
s=s[::-1]
while len(s)>0:
  if len(s) < 5:
    print("NO")
    break
  if s[0:7] == str[1] :
    s=s[7:]
  elif s[0:6] == str[3]:
    s=s[6:]
  elif s[0:5] == str[0] or s[0:5] == str[2]:
    s=s[5:]
  else:
    print("NO")
    break
  if len(s)==0:
    print("YES")
    break

Submission status: Accepted

Solution code:
s = input()
def solve(query):
    while 1:
        for frag in ("erase", "eraser", "dream", "dreamer"):
            if query.endswith(frag):
                query = query[:-len(frag)]
                break
        else:
            print("NO")
            break
        if not query:
            print("YES")
            break

solve(s)

Submission status: Accepted

Solution code:
S = input()

divide = True
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:
        divide = False
        break
        
if divide:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input()
while len(S) >= 5:
    if S[:7] == 'dreamer':
        S = S[11:] if S[7:11] == 'aser' else S[10:] if S[7:10] == 'ase' else S[7:]
    elif S[:6] == 'eraser':
        S = S[6:]
    elif S[:5] in ['dream','erase']:
        S = S[5:]
    else:
        break
print('YES') if S == '' else print('NO')

Submission status: Accepted

Solution code:
S = input().strip()[::-1]
div = [i[::-1] for i in ["dream", "dreamer", "erase", "eraser"]]

idx = 0
ok = False
while True:
    sub_ok = False
    for d in div:
        if S[idx:idx+len(d)] == d:
            idx += len(d)
            sub_ok = True
            break
    if sub_ok != True:
        break
    if idx == len(S):
        ok = True
        break

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

Submission status: Accepted

Solution code:
# C - 白昼夢
S = input()
S2 = S
W_L = ["dream","dreamer","erase","eraser"]
while True:
    cnt = 0
    for w in W_L:
        if S2.endswith(w):
            S2 = S2[:-(len(w))]
            cnt+=1
    if cnt ==0:
        print('NO')
        exit()
            
    if len(S2)<=7:
        break
    
if S2 ==''or S2 in W_L:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import re
s = input()


while True:
    # s = re.sub('dream$|dreamer$|erase$|eraser$','',s)

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

Submission status: Accepted

Solution code:
def reverse_str(s):
    return ''.join(list(s)[::-1])


words = list(map(reverse_str, 'dream dreamer erase eraser'.split()))
S = reverse_str(input())
ok = True
while S:
    for r in range(5, 8):
        tmp = S[:r]
        if tmp in words:
            # print(S, end=' => ')
            S = S[r:]
            # print(S)
            break
    else:
        ok = False
        break
print('YES' if ok else 'NO')

Submission status: Accepted

Solution code:
from math import *

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def main():
    a = cino(True)
    check = True
    # print(a[5:10])
    # print(a[11-6:11][::-1])
    i = len(a)-1
    # print(a[10])
    while i>=0:
        # print(i)
        if a[i-5:i+1][::-1]=="resare":
            # "remaerd"}:
            # print(a[i-5:i+1][::-1])
            i-=6
        elif a[i-6:i+1][::-1]=="remaerd":
            # print(a[i-6:i+1][::-1])
            i-=7
        elif a[i-4:i+1][::-1] in {"esare","maerd"}:
            # print(a[i-4:i+1][::-1])
            i-=5
        else:
            check = False
            break
    if check:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

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

for i in m:
    S = S.replace(i,"")


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

Submission status: Accepted

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

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

for i in m:
    S = S.replace(i[::-1],"")


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

Submission status: Accepted

Solution code:
S=input()
T=[]

l=-1
while l-2>=-len(S):
    k=S[l:l-3:-1]
    if k=="mae":
        T+="dream"[::-1]
        l-=5
    elif k=="rem":
        T+="dreamer"[::-1]
        l-=7
    elif k=="esa":
        T+="erase"[::-1]
        l-=5
    elif k=="res":
        T+="eraser"[::-1]
        l-=6
    else:
        break
if S=="".join(T[::-1]):
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

dct = ['dream', 'dreamer', 'erase', 'eraser']
rdct = [''.join(reversed(x)) for x in dct]

def main():
    S = input()[:-1]
    rS = ''.join(reversed(S))

    fr = 0
    for _ in range(20005):
        flag = False
        for d in rdct:
            to = fr + len(d)
            if d == rS[fr:to]:
                fr = to
                flag = False
                break
            flag = True
        if flag:
            break
    
    if fr == len(S):
        print('YES')
    else:
        print('NO')
    
if __name__ == "__main__":
    main()

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()
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 = str(input())
s1 = s[::-1]
u = ['dream','dreamer','erase','eraser']

while True:
    restart = False
    for i in range(4):
        if u[i][::-1] == s1[:len(u[i])]:
            s1 = s1[len(u[i]):]
            restart = True
            break
    if restart == False:
        break
if len(s1) > 0:
    print('NO')
else:
    print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

while True:
    if len(S) == 0:
        print('YES')
        exit()
    if len(S) < 5:
        print('NO')
        exit()
    if S[:5] == 'dream':
        if len(S) > 6 and S[5:7] == 'er':
            if len(S) > 7 and S[7] == 'a':
                S = S[5:]
            else :
                S = S[7:]
        else :
            S = S[5:]
    elif S[:5] == 'erase':
        if len(S) > 5 and S[5] == 'r':
            S = S[6:]
        else :
            S = S[5:]
    else :
        print('NO')
        exit()

Submission status: Accepted

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

DEBUG = False

if DEBUG:
    print("S: {}".format(S))
while True:
    if DEBUG:
        print("S[:7]: {}".format(S[:7]))
    if len(S) >= 5:
        if S[:7] == "remaerd":
            S = S[7:]
        elif S[:6] == "resare":
            S = S[6:]
        elif S[:5] == "maerd" or S[:5] == "esare":
            S = S[5:]
        else:
            print("NO")
            exit()
    else:
        break
if DEBUG:
    print("S: {}".format(S))
if len(S) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
temp = ['maerd', 'remaerd', 'esare', 'resare']
s.reverse()

i = 0
while i < n:
    flag = False
    for t in temp:
        if s[i:i+len(t)] == list(t):
            i += len(t)
            flag = True
            break

    if not flag:
        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 = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())


    def rev_strip(s):
        dream_rev = ''.join(reversed(list('dream')))
        dreamer_rev = ''.join(reversed(list('dreamer')))
        erase_rev = ''.join(reversed(list('erase')))
        eraser_rev = ''.join(reversed(list('eraser')))
        if s[:5] == dream_rev:
            return True, s[5:]
        elif s[:7] == dreamer_rev:
            return True, s[7:]
        elif s[:5] == erase_rev:
            return True, s[5:]
        elif s[:6] == eraser_rev:
            return True, s[6:]
        else:
            return False, ''
    
    def solve(s):
        while s:
            result, s = rev_strip(s)
            if not result:
                return False
        return True
    
    
    s = input()
    s_rev = ''.join(reversed(list(s)))
    print('YES') if solve(s_rev) else print('NO')



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = input()
words = ('dream', 'dreamer', 'erase', 'eraser')

while True:
    if S == '':
        print("YES")
        break

    for word in words:
        if S.endswith(word):
            S = S[:-len(word)]
            break
    else:
        print("NO")
        break

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

S = inputS()

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

while S:
  flag = 0
  for i in range(4):
    word = l[i]
    if S[-len(word):] == word:
      S = S[:-len(word)]
      flag = 1
  if flag == 0:
    print("NO")
    exit()

print("YES")

Submission status: Accepted

Solution code:
s = input()

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

cnt = 0
t = ""
while cnt <= len(s) - 8:
    if s[cnt] == "d":
        if s[cnt+5] == "d":
            cnt += 5
            t += vocabs[0]
        elif s[cnt+5] == "e":
            if s[cnt+7] == "a":
                cnt += 5
                t += vocabs[0]
            else:
                cnt += 7
                t += vocabs[1]
        else:
            break
    elif s[cnt] == "e":
        if s[cnt+5] == "r":
            cnt += 6
            t += vocabs[3]
        else:
            cnt += 5
            t += vocabs[2]
    else:
        break

if s[cnt:] == vocabs[0]:
    t+= vocabs[0]
elif s[cnt:] == vocabs[1]:
    t+= vocabs[1]
elif s[cnt:] == vocabs[2]:
    t+= vocabs[2]
elif s[cnt:] == vocabs[3]:
    t+= vocabs[3]


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

Submission status: Accepted

Solution code:
import sys
S=list(input())
S.reverse()
S="".join(S)
#print(S)

while S:
  if len(S)<5:
    print("NO")
    sys.exit(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")
    sys.exit(0)
    
print("YES")

Submission status: Accepted

Solution code:
s = input()


def solve(x):
    while 1:
        for frag in ("erase", "eraser", "dream", "dreamer"):
            if x.endswith(frag):
                x = x[:-len(frag)]
                break
        else:
            print("NO")
            break
        if not x:
            print("YES")
            break



solve(s)

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:
def main():
  S = input()
  while len(S)>=5:
    if len(S)>=7 and S[-7:]=="dreamer":
      S = S[:-7]
      continue
    
    elif 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:
S = input()
k = ["dream", "dreamer" ,"erase", "eraser"]
ans = "NO"

while len(S) > 0:
  a = len(S)
  for i in k:
    if S[-1*len(i):] == i:
      S = S[0:-1*len(i)]
      break
  if a == len(S):
    break
  elif len(S) == 0:
    ans="YES"
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(4):
    char = divide[i][::-1]
    line[i] = char
s_str = S[::-1]
char = ''
for i in range(len(s_str)):
    char += s_str[i]
    if char in line:
        char = ''
if char == '':
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input()
str_list = ['dream', 'erase', 'dreamer', 'eraser']
start = 0
success_flag = False
continue_flag = False


def reverse_str(var: str):
    return ''.join(list(reversed(var)))


reverse_S = reverse_str(S)
while True:
    for str_name in str_list:
        if reverse_S[start:start + len(str_name)] == reverse_str(str_name):
            if len(S) == start + len(str_name):
                success_flag = True
                break
            start += len(str_name)
            continue_flag = True
    if success_flag:
        print('YES')
        break
    if not continue_flag:
        print('NO')
        break
    else:
        continue_flag = False

Submission status: Accepted

Solution code:
s = input()

length = len(s)
t = ''
word = ''

for a in range(length-1, -1, -1):
    t += s[a]
    if t == 'maerd' or t == 'remaerd' or t == 'esare' or t == 'resare':
        word += t
        t = ''

if s == word[::-1]:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = str(input())
S = S[::-1]
D = ["dream", "dreamer", "erase", "eraser"]
for i, d in enumerate(D):
    D[i] = d[::-1]

can = True
i = 0
while i<len(S):
    can2 = False
    for d in D:
        if S[i:i+len(d)]==d:
            can2 = True
            i += len(d)
    if can2!=True:
        can = False
        break

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import re
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    YESNO(re.match(r'^(dream(er)?|eraser?)+$',input()))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

S = sys.stdin.readline().strip()

S = S[::-1]
i = 0
while i < len(S):
    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:
        break

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

Submission status: Accepted

Solution code:
S = input()
lS = len(S)
i=0
S=S[::-1]
while i<lS:
    if S[i:i+5] == 'esare' or S[i:i+5] == 'maerd':
        i = i+5
    elif S[i:i+6]=='resare':
        i = i+6
    elif S[i:i+7]=='remaerd':
        i = i+7
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
from collections import deque

def bfs(string):
    can = ["dream", "dreamer", "erase", "eraser"]
    queue = deque([])
    queue.append("dream")
    queue.append("dreamer")
    queue.append("erase")
    queue.append("eraser")
    while queue:
        judge = queue.popleft()
        if judge == string:break
        for temp in can:
            ans = judge + temp
            if ans == string[:len(ans)]:
                queue.append(ans)
    return "YES" if judge == string else "NO"

if __name__ == '__main__':
    s = input()
    print(bfs(s))

Submission status: Accepted

Solution code:
def judge(s):
    flag = True
    s = s[::-1]
    ans = ""
    pivot = 0
    while pivot < len(s):
        if s[pivot] == "m":
            ans += "maerd"
            pivot += 5
        elif s[pivot] == "e":
            ans += "esare"
            pivot += 5
        elif s[pivot:pivot+3] == "rem":
            ans += "remaerd"
            pivot += 7
        elif s[pivot:pivot+3] == "res":
            ans += "resare"
            pivot += 6
        else:
            flag = False
            break
    if flag == False:
        return "NO"
    elif s == ans:
        return "YES"
    else:
        return "NO"

if __name__ == '__main__':
    s = input()
    print(judge(s))

Submission status: Accepted

Solution code:
target = input()

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

Submission status: Accepted

Solution code:
S = input()
dream = "dream"
dreamer = "dreamer"
erase = "erase"
eraser = "eraser"


while True:
    if S.find(dream, len(S) - len(dream), len(S)) == len(S) - len(dream):
        S = S[:len(S) - len(dream)]
        continue
    elif S.find(dreamer, len(S) - len(dreamer), len(S)) == len(S) - len(dreamer):
        S = S[:len(S) - len(dreamer)]
        continue
    elif S.find(erase, len(S) - len(erase), len(S)) == len(S) - len(erase):
        S = S[:len(S) - len(erase)]
        continue
    elif S.find(eraser, len(S) - len(eraser), len(S)) == len(S) - len(eraser):
        S = S[:len(S) - len(eraser)]
        continue
    elif len(S) == 0:
        print("YES")
        break
    else:
        print("NO")
        break

Submission status: Accepted

Solution code:
s = list(input())
s.append(0)
s.append(0)
s.append(0)
l =len(s)
while l>3:
    if s[0]=="d" and s[1]=="r" and s[2]=="e" and s[3]=="a" and s[4]=="m" and s[5]=="e" and s[6]=="r":
        if s[7]=="a":
            del s[0]
            del s[0]
            del s[0]
            del s[0]
            del s[0]
            l =len(s)
        else:
            del s[0]
            del s[0]
            del s[0]
            del s[0]
            del s[0]
            del s[0]
            del s[0]
            l =len(s)          
    elif s[0]=="d" and s[1]=="r" and s[2]=="e" and s[3]=="a" and s[4]=="m":
      del s[0]
      del s[0]
      del s[0]
      del s[0]
      del s[0]
      l =len(s)                    
    elif s[0]=="e" and s[1]=="r" and s[2]=="a" and s[3]=="s" and s[4]=="e" and s[5]=="r":
      del s[0]
      del s[0]
      del s[0]
      del s[0]
      del s[0]
      del s[0]
      l =len(s)
    elif s[0]=="e" and s[1]=="r" and s[2]=="a" and s[3]=="s" and s[4]=="e":
      del s[0]
      del s[0]
      del s[0]
      del s[0]
      del s[0]
      l =len(s)
    else:
        print("NO")
        break
if s[0]==0:
    print("YES")

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    print('YES' if re.match('^(dream|dreamer|erase|eraser)+$', S) else 'NO')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=list(input())
s=s[::-1]
start=0
def find(s,start):
    if len(s)-start>=5 and (s[start:start+5]==list("maerd") or s[start:start+5]==list("esare")):
        start=start+5
        return(start,0)#左がstart,右がまだ処理続行
    elif len(s)-start>=6 and s[start:start+6]==list("resare"):
        start=start+6
        return(start,0)
    elif len(s)-start>=7 and s[start:start+7]==list("remaerd"):
        start=start+7
        return(start,0)
    elif len(s)-start==0:
        return(start,1)#1はぴったり終了
    else:
        return(start,2)#2は満たさないで終了
shori=0
while shori==0:
    (start,shori)=find(s,start)
if shori==1:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
import sys
S = input()[::-1]
t = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
while len(S) > 0:
    if S[:5] == t[0]:
        S = S[5:]
    elif S[:7] == t[1]:
        S = S[7:]
    elif S[:5] == t[2]:
        S = S[5:]
    elif S[:6] == t[3]:
        S = S[6:]
    else:
        print('NO')
        sys.exit()
print('YES')