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

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

DP = [0] * 100000

DP[0] = 1

for s in range(len(S)):
    if DP[s] != 1:
        continue

    for i in range(4):
        tmp = S[s: s+len(dire[i])]
        if tmp == dire[i]:
            DP[s + len(dire[i])] = 1

if DP[len(S)] == 1:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import sys 
sys.setrecursionlimit(10**6)
s = input()
def dfs(s):
    while True:
        f = True
        for i in ['dream', 'dreamer', 'erase', 'eraser']:
            if s[-len(i):]==i:
                s = s[:-len(i)]
                if s=='':
                    return True
                f = False
        if f: return False
    
if dfs(s):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import sys 
sys.setrecursionlimit(10**6)
s = input()
def dfs(s):
    while True:
        f = True
        for i in ['erase', 'eraser', 'dream', 'dreamer']:
            if s[-len(i):]==i:
                s = s[:-len(i)]
                if s=='':
                    return True
                f = False
        if f: return False
    
if dfs(s):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import sys

S = input()

while S:
    if S[-1] == 'r':
        if S[-7:] == 'dreamer':
            S = S[:-7]
        elif S[-6:] == 'eraser':
            S = S[:-6]
        else:
            print('NO')
            sys.exit()
    elif S[-5:] == 'dream' or S[-5:] == 'erase':
        S = S[:-5]
    else:
        print('NO')
        sys.exit()

print('YES')

Submission status: Accepted

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

i = 0
while i < len(S):
    for w in W:
        if S[i:].startswith(w):
            i += len(w)
            break
    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','*')
s = s.replace('*','')
if len(s) == 0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import copy
def deleteStr(S, text):
    if len(S) < len(text):
        return S
    for i, letter in enumerate(text):
        if letter == S[i]:
            continue
        else:
            return S
    return S[len(text):]

def checkStr(S, text):
    if len(S) < len(text):
        return False
    for i, letter in enumerate(text):
        if letter == S[i]:
            continue
        else:
            return False
    return True

def main():
    S = input()

    for i in range(len(S)):
        S_len = len(S)
        if checkStr(S, 'dreamer'):
            if checkStr(S, 'dreamerase'):
                S = deleteStr(S, 'dream')
            else:
                S = deleteStr(S, 'dreamer')
        else:
            S = deleteStr(S, 'dream')

        if checkStr(S, 'eraser'):
            S = deleteStr(S, 'eraser')
        else:
            S = deleteStr(S, 'erase')

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

while len(S) != 0:
    if S[-5:] == a or S[-5:] == c:
        S = S[:-5]
    elif S[-7:] == b:
        S = S[:-7]
    elif S[-6:] == d:
        S = S[:-6]
    else:
        break
    
if len(S) == 0:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = list(input())
T = S[::-1]
l = len(S)
P = ["j"]*20
T.extend(P)
start = 0
j = 0

while(True):
    five = "".join(T[start:start+5])
    six = "".join(T[start:start+6])
    seven = "".join(T[start:start+7])
    if five == "esare" or five == "maerd":
        start += 5
    elif six == "resare":
        start += 6
    elif seven == "remaerd":
        start += 7
    else:
        j = 1
    if j == 1 or start == l:
        break

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
words = ['maerd', 'remaerd', 'esare', 'resare']
S = input()
T = ''
for a in S[::-1]:
  T += a
  for s in words:
    if T == s:
      T = ''
print('YES' if T == '' else 'NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
result = True

while 0 < len(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:
      result = False
      break

print("YES" if result else "NO")

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7

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

Submission status: Accepted

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

while True :
    if len(s) == 0:
        print('YES')
        break
    elif s[0:5] == 'esare':
        s = s[5:]
    elif s[0:6] == 'resare':
        s = s[6:]
    elif s[0:5] == 'maerd':
        s = s[5:]
    elif s[0:7] == 'remaerd' :
        s = s[7:]
    else :
        print('NO')
        break

Submission status: Accepted

Solution code:
def extract_6(x):
	strtemp=' '
	if(len(x)>=6):
		temp=[0]*6
		for i in range(6):
			temp[i]=x[len(x)-6+i]
	else:
		temp='false'
	strtemp=''.join(temp)
	return(strtemp)

def extract_5(x):
	strtemp=' '
	if(len(x)>=5):
		temp=[0]*5
		for i in range(5):
			temp[i]=x[len(x)-5+i]
	else:
		temp='false'
	strtemp=''.join(temp)
	return(strtemp)
	
def extract_7(x):
	strtemp=' '
	if(len(x)>=7):
		temp=[0]*7
		for i in range(7):
			temp[i]=x[len(x)-7+i]
	else:
		temp='false'
	strtemp=''.join(temp)
	return(strtemp)

S=input()
flag=1
while(flag==1):
	if(extract_7(S)=='dreamer'):
		S=S[:-7]
	elif(extract_6(S)=='eraser'):
		S=S[:-6]
	elif(extract_5(S)=='dream'):
		S=S[:-5]
	elif(extract_5(S)=='erase'):
		S=S[:-5]
	else:
		flag=0
if len(S)!=0:
	print('NO')
else:
	print('YES')

Submission status: Accepted

Solution code:
s = input()

flag = 0
while s != []:
  ss=s
  if s=='erase':
    s = []
  elif len(s)>5 and s[0:6]=='erasee':
    s = s[5:]
  elif len(s)>5 and s[0:6]=='erased':
    s = s[5:]
  elif s=='eraser':
    s = []
  elif len(s)>6 and s[0:7]=='erasere':
    s = s[6:]
  elif len(s)>6 and s[0:7]=='eraserd':
    s = s[6:]
  elif s=='dreamer':
    s = []
  elif len(s)>7 and s[0:8]=='dreamere':
    s = s[7:]
  elif len(s)>7 and s[0:8]=='dreamerd':
    s = s[7:]
  elif s=='dream':
    s = []
  elif len(s)>5 and s[0:6]=='dreamd':
    s = s[5:]
  elif len(s)>5 and s[0:6]=='dreame':
    s = s[5:]

  if ss==s:
    flag=1
    break

if flag==0:
  print("YES")
else:
  print("NO")
    
# dream dreamer erase eraser

Submission status: Accepted

Solution code:
# ABC049 C

def main():
    s = input()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################



s = input()
n = len(s)
s += "zzzzzzzzzzzzzzzzzzz"
t = ""
while(True):
    if(n - len(t) <= 4):
        break
    if(s[len(t)+2]=='a' and s[len(t)+5]=='r'):
        t+="eraser"
        continue
    elif(s[len(t)+2]=='a'):
        t+="erase"
    elif(s[len(t)+7]=='a' or s[len(t)+5]=='z' or s[len(t)+5]=='d'):
        t+="dream"
    else:
        t+="dreamer"
        
if(s[0:n]==t):
    print("YES")
else:
    print("NO")
#print(s[0:n],t)

Submission status: Accepted

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

def main():
    S = readline().rstrip()
    T = S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
    if not T:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
S_r = S[::-1]
dire = ['dream','dreamer','erase','eraser']
dire_r = [0]*4
for i in range(4):
    tmp = dire[i]
    dire_r[i] = tmp[::-1]
ind = 0

excep = 0

while ind  <len(S_r):
    if excep == 1:
        break
    flag2= 0
    for j in range(4):
        if flag2 ==0:
            case = 0
            for k in range(len(dire_r[j])):
                tmp = dire_r[j]

                if ind + k < len(S_r) and case == 0:
                #    print(j)
            #        print('S:'+S_r[ind+k])
            #        print('dire:'+tmp[k])
                    if S_r[ind+k] != tmp[k]:
                        flag = 0
                        case = 1
                        if j == 3:
                            excep = 1

                    elif k== len(dire_r[j])  -1:
                        ind = ind + len(dire_r[j])
                        flag = 1
                        case = 1
                        flag2 = 1


if flag == 1:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

while S:
    for c in C:
        if S.endswith(c):
            S = S[:-len(c)]
            break
    else:
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

Solution code:
import re
N = str(input())

words = re.findall("^(dream|dreamer|erase|eraser)+$", N)
print('NO') if words == [] else print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abs/tasks/arc065_a


def main():
    s = input()
    t = s[:]
    no = False
    while len(t) > 0:
        if t[-1] == "m" and t[-5:] == "dream":
            t = t[:-5]
        elif t[-1] == "e" and t[-5:] == "erase":
            t = t[:-5]
        elif t[-1] == "r":
            if t[-6:] == "eraser":
                t = t[:-6]
            elif t[-7:] == "dreamer":
                t = t[:-7]
            else:
                no = True
                break
        else:
            no = True
            break
    if no:
        print("NO")
    else:
        print("YES")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# python 3.4.3
import sys
input = sys.stdin.readline
import numpy as np

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()
S = S[::-1]


words = ["dream","dreamer","erase","eraser"]
for i in range(4):
    words[i] = words[i][::-1]
 
i = 0
while i < len(S):
    for w in words:
        l = len(w)
        if w == S[i:i+l]:
            i += l
            break
    else:
        print("NO")
        sys.exit()
 
print("YES")

Submission status: Accepted

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    S = _in[0]
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    S_unit = S.replace('dream','A').replace('erase','B').replace('Aer','C').replace('Br','D')
    _ = S_unit.replace('A','').replace('B','').replace('C','').replace('D','')
    flag = 'YES' if _=='' else 'NO'
    ### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(flag)

Submission status: Accepted

Solution code:
def solve(S):
    str_list = ["dream", "dreamer", "erase", "eraser"]
    n = 0
    while n < len(S):
        for s in str_list:
            if n:
                if S[:-n].endswith(s):
                    n += len(s)
                    break
            else:
                if S.endswith(s):
                    n += len(s)
                    break
        else:
            return False
    return True


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

Submission status: Accepted

Solution code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    s = input()
    s = s[::-1]
    hoge = ["maerd","remaerd","esare","resare"]
    i, bit = 0, 0
    while True:
        if i == len(s):
            break
        if s[i:i+5] == hoge[0]:
            i += 5
        elif s[i:i+7] == hoge[1]:
            i += 7
        elif s[i:i+5] == hoge[2]:
            i += 5
        elif s[i:i+6] == hoge[3]:
            i += 6
        else:
            print("NO")
            bit = 1
            break
    if bit == 0:
        print("YES")
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import re
N = input()

N_list = re.findall("^(dream|dreamer|erase|eraser)+$", N) 

if N_list==[]:
  print('NO')
else:
  print('YES')

Submission status: Accepted

Solution code:
s = input()[::-1]
lst = [l[::-1] for l in ['dream', 'dreamer', 'erase', 'eraser']]
while len(s):
    flg = False
    if s[:5] == lst[0]:
        s = s[5:]
        flg = True
    elif s[:7] == lst[1]:
        s = s[7:]
        flg = True
    elif s[:5] == lst[2]:
        s = s[5:]
        flg = True
    elif s[:6] == lst[3]:
        s = s[6:]
        flg = True
    if flg is False:
        break
print('YES' if len(s)==0 else 'NO')

Submission status: Accepted

Solution code:
def readinput():
    s = input()
    return s

def compare(s):
    # dreameraser
    # dreamerase
    # dreamer
    # dream
    # eraser
    # erase
    if (s[0:11] == 'dreameraser'):
        return 11
    elif (s[0:10] == 'dreamerase'):
        return 10
    elif (s[0:7] == 'dreamer'):
        return 7
    elif (s[0:5] == 'dream'):
        return 5
    elif (s[0:6] == 'eraser'):
        return 6
    elif (s[0:5]=='erase'):
        return 5
    else:
        return 0

def main(s):
    p=0 # 比較する部分列の先頭
    while(p<=len(s)):
        if(p==len(s)):
            return True
        q = compare(s[p:])
        if(q==0):
            return False
        p += q
    return False

if __name__=='__main__':
    s = readinput()
    ans = main(s)
    if(ans == True):
        print('YES')
    else:
        print('NO')

Submission status: Accepted

Solution code:
s = input()

for _ in range(10**5//5):
  if s.endswith('dream') or s.endswith('erase'):
    s = s[:-5]
  if s.endswith('eraser'):
    s = s[:-6]
  if s.endswith('dreamer'):
    s = s[:-7]
    
print('YES') if s == '' else print('NO')

Submission status: Accepted

Solution code:
s = input()
n = len(s)
yn = "YES"

while(len(s) > 0):
    if(s.endswith("dream") or s.endswith("erase")):
        s = s[:(len(s)-5)]
    elif(s.endswith("eraser")):
        s = s[:(len(s)-6)]
    elif(s.endswith("dreamer")):
        s = s[:(len(s)-7)]
    else:
        yn = "NO"
        break

print(yn)

Submission status: Accepted

Solution code:
s=input()
while True:
    for flag in ["erase","eraser","dream","dreamer"]:
        if s.endswith(flag):
            s=s[:-len(flag)]
            break
    else:
        print("NO")
        break
    if len(s)==0:
        print("YES")
        break

Submission status: Accepted

Solution code:
s=input()
l=["dreamer","dream","erase","eraser"]
i=0
f=False
while True:
    s5=s[i:i+5]
    s6=s[i:i+6]
    s7=s[i:i+7]
    if i==len(s):f=True
    if s7=="dreamer" and s[i+7:i+8]!="a":
        i+=7
        continue
    if  s7=="dreamer" and s[i+7:i+8]=="a":
        i+=5
        continue
    if s6=="eraser":
        i+=6
        continue
    if s5=="dream":i+=5;continue
    if s5=="erase":i+=5;continue
    break
print("YES" if f else "NO")

Submission status: Accepted

Solution code:
t = ["dream","dreamer","erase","eraser"]

# 反転

t_r = []
for i in range(len(t)):
    t_r.append(t[i][::-1])
    
s = input()
s_r = s[::-1]
#print(s_r)

flag = True
#for i in range(len(s_r)):
i=0
while(i<len(s_r)):
    flag2 = False
   
    for j in range(len(t_r)):
        t = t_r[j] 
        tmp_s = s_r[i:i+len(t)]
        #print(t)
        
        if(tmp_s == t):
            flag2 = True
            i += len(t)
    if flag2 == False:
        flag = False
        break

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

Submission status: Accepted

Solution code:
import sys
import re
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    S = input()
    words = ["eraser","erase","dreamer","dream"]
    for w in words:
        S = re.sub(w,"",S)
    if S=="":
        print("YES")
    else:
        print("NO")

main()

Submission status: Accepted

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

while len(S) != 0:
    i = 0
    for s in lst:
        i = S.find(s, n)
        if i == 0:
            if s == lst[0] and S.find(lst[3], n) == 5:
                pass
            else:
                S = S[len(s) :]
                break
    if i != 0:
        print("NO")
        exit()

print("YES")

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

s = ns()
n = len(s)

ans = True
while len(s) > 0:
    if s.endswith("dreamer"):
        s = s[:-7]
    elif s.endswith("dream"):
        s = s[:-5]
    elif s.endswith("eraser"):
        s = s[:-6]
    elif s.endswith("erase"):
        s = s[:-5]
    else:
        ans = False
        break

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

s = ns()
n = len(s)

sel = ["dreameraser", "dreamerase", "dreamer", "dream", "eraser", "erase"]
i = 0
ans = True
while i < n:
    flag = False
    for p in sel:
        if i + len(p) <= n:
            if s[i:i + len(p)] == p:
                flag = True
                i += len(p)
                break
    if not flag:
        ans = False
        break

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

Submission status: Accepted

Solution code:
S = input()[::-1]
import sys
sys.setrecursionlimit(1000)
c = ['maerd', 'remaerd', 'esare', 'resare']

def dfs(s):
    L = len(s)
    while 1:
        if L==0:
            return True
        if L<5:
            return False
        if s[:5] in c:
            s = s[5:]
            L -= 5
        elif L>=6 and s[:6]=='resare':
            s = s[6:]
            L -= 6
        elif L>=7 and s[:7]=='remaerd':
            s = s[7:]
            L -= 7
        else:
            return False

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

Submission status: Accepted

Solution code:
import sys #追加
sys.setrecursionlimit(500*500)

s = input()
check_flag = True
def check_and_cut(string):
    tmp = '123'
    flag = True
    if len(string) <= 4:
        pass
    else:
        if len(string) >4:
            if string[-5:] == 'dream':
                tmp = string[:-5]
                flag = False
            elif string[-5:] == 'erase':
                tmp = string[:-5]
                flag = False
        if len(string) >5 and flag:
            if string[-6:] == 'eraser':
                tmp = string[:-6]
                flag = False
        if len(string) >6 and flag:
            if string[-7:] == 'dreamer':
                tmp = string[:-7]
                flag = False
    #print(string,len(string),string[-6:],tmp,string[-6:] == 'eraser')
    return tmp
while check_flag:
    t = check_and_cut(s)
    if t == '123':
        print('NO')
        exit()
    if len(t) == 0:
        print('YES')
        exit()
    s = t

Submission status: Accepted

Solution code:
s = input()

while s:
    if s[:6] == "eraser":
        s = s[6:]
    elif s[:5] == "erase":
        s = s[5:]
    elif s[:5] == "dream":
        if s[5:8] == "era":
            s = s[5:]
        elif s[5:7] == "er":
            s = s[7:]
        else:
            s = s[5:]
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    s = input()

    invs = ''.join(list(reversed(s)))

    while 1:
        for f in map(lambda x: ''.join(list(reversed(x))), ["erase", "eraser", "dream", "dreamer"]):
            if invs.startswith(f):
                invs = invs[len(f):]
                break
            if invs == "":
                print("YES")
                return
        else:
            print("NO")
            return


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def solve(n):

    while len(n) > 4:
        if n[-5:] == "dream":
            n = n[:-5]
        elif n[-7:] == "dreamer":
            n = n[:-7]
        elif n[-5:] == "erase":
            n = n[:-5]
        elif n[-6:] == "eraser":
            n = n[:-6]
        else:
            break

    return "YES" if len(n) == 0 else "NO"

if __name__ == "__main__":
    n = input()
    print(solve(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
import random
def resolve():
    
    S=input()
    A="dream dreamer erase eraser".split()
    #print(A)
    que=[S]
    while(que!=[]):
        t=len(que)
        #print(t)
        vS=que.pop(random.randint(0,t-1))
        if vS=="":
            print("YES")
            return
        for w in A:
            r=len(w)
            if vS[:r]==w:
                que.append(vS[r:])
        #print(que,"k")    

    print("NO")
#%%submit!
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

T_rev = []

for i in range(len(T)):
	T_rev.append(T[i][::-1])

flag = True
i = 0
while i < len(S):
	for j in range(len(T)):
		ed = i + len(T_rev[j])
		# print(S[i:ed])
		if (S[i:(i + len(T_rev[j]))] == T_rev[j]):
			i += len(T[j])
			flag = True
			break
		else:
			flag = False

	if(flag == False):
		break

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

Submission status: Accepted

Solution code:
s=input()

while True:
    
    if len(s)<5:
        break
        
    else:
      
        if s[:5]=='dream':
            
            if len(s)<7:                
                  s=s[5:]
            elif 7<=len(s) and len(s)<10:
                if s[5:7]=='er':
                  s=s[7:]
            else:
                
                if s[5:7]=='er':
                    if s[7:10]=='ase':
                        s=s[5:]
                    else:
                        s=s[7:]
                else:
                    s=s[5:]
                
        elif s[:5]=='erase':
          
            if len(s)>5:
                if s[5]=='r':
                    s=s[6:]
                else:
                    s=s[5:]
                    
            else:
                s=s[5:]
                
        else:
            break
            
if s=='':
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
buff = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
    buff[i] = buff[i][::-1]
S = S[::-1]
while len(S) > 0:
    if S[:7] == buff[1]:
        S = S[7:]
    elif S[:6] == buff[3]:
        S = S[6:]
    elif S[:5] == buff[0] or S[:5] == buff[2]:
        S = S[5:]
    else:
        break
if S: print('NO')
else: print('YES')

Submission status: Accepted

Solution code:
import re
S = input()
if re.fullmatch(r'(dream|dreamer|erase|eraser)+',S):
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
s=input()

li=list(itertools.permutations(["dream","erase","dreamer","eraser"]))

for i in li:
    t=s
    for j in range(4):
        t=t.replace(i[j],"")
    else:
        if t=="":
            print("YES")
            exit()

print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())

dream = 'dream'
dreamer = 'dreamer'
erase = 'erase'
eraser = 'eraser'

while s !='':
  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]
  else:
    print('NO')
    exit()
 
print('YES')