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 sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()
S = S[::-1]
word = ["dream", "dreamer", "erase", "eraser"]
flag = 0
tmp = ""
while 1:
	if tmp == S:
		print("NO")
		break
	tmp = S
	for w in word:
			# print(S)
			# print(w)
			if len(S) <= 4:
				print("NO")
				flag = 1
			elif S[:5] == w[::-1]:
				if len(S) == 5:
					print("YES")
					flag = 1
					break
				else:
					S = S[5:]
			elif S[:6] == w[::-1]:
				if len(S) == 6:
					print("YES")
					flag = 1
					break
				else:
					S = S[6:]
			elif S[:7] == w[::-1]:
				if len(S) == 7:
					print("YES")
					flag = 1
					break
				else:
					S = S[7:]
	if flag == 1:
		break

Submission status: Accepted

Solution code:
S = input().rstrip()
S = S[::-1]
daydream = ['maerd', 'remaerd', 'esare', 'resare']
nextIndex = 0
flg = True
for i in range(10**5//5):
    if nextIndex == len(S):
        break
    for j in daydream:
        if j == S[nextIndex: nextIndex+len(j)]:
            nextIndex += len(j)
            flg = True
            break
        flg = False
    if flg == False:
        break
print("YES" if flg else "NO")

Submission status: Accepted

Solution code:
S = input()
s_list = ["dream", "dreamer", "erase", "eraser"]
S_r = S[::-1]
i_n=0
for i, j in enumerate(s_list):
    s_list[i] = j[::-1]
while i_n < len(S):
    f_can = False
    for j in s_list:
        if S_r[i_n:i_n+len(j)] == j:
            f_can = True
            i_n+=len(j)
        else:
            False
    if f_can == False:
        break
        
if f_can == False:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:
#C問題
S=str(input())
Slist=list(S)
Slen=len(Slist)
Srev=Slist[::-1]
kari=""
for i in range(Slen):
    if len(kari) == 5:
        if kari == "maerd":
            kari=Srev[i]
        elif kari == "esare":
            kari=Srev[i]
        else:
            kari+=Srev[i]
    elif len(kari) == 6:
        if kari == "resare":
            kari=Srev[i]
        else:
            kari+=Srev[i]
    elif len(kari) == 7:
        if kari == "remaerd":
            kari=Srev[i]
        else:
            break
    else:
        kari+=Srev[i]
if kari == "esare" or kari == "maerd" or kari == "resare" or kari == "remaerd":
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input()
flg = True
while flg:
    if S == "":
        flg = False
        print("YES")
    elif 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:
        flg = False
        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()
words_r = ['eraser', 'erase', 'dreamer', 'dream']
for word_r in words_r:
    s = s.replace(word_r, '')
    #コードの意味:
    #s.replace(p,q) :文字列sにpという文字があればそれを先頭から順にqに置換していく
    #sはwords_rに含まれる文字列を''に置換した文字列になる
    #->条件に合うならｓは最終的に''に,そうでないならそれ以外になる
if (len(s) > 0):
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)

for i in range(10):
  S.append('')

judge = 1
s1,s2,prev_s1 = '','',''
i = 0
while(1):
 s1 = S[i]+S[i+1]+S[i+2]+S[i+3]+S[i+4]
 s2 = S[i]+S[i+1]
 s2_ = list(s2)
 if(s1 == ''):
  break
 if((s1 == 'erase')or(s1 == 'dream')): 
  i += 5
 elif(s2 == 'er'):
  if(prev_s1 == 'dream'):
    i += 2
  else: 
    judge = 0
    break
 elif(s2_[0] == 'r'):
  if(prev_s1 == 'erase'):
    i += 1
  else: 
    judge = 0
    break
 else:
    judge = 0
    break
 prev_s1 = s1

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

Submission status: Accepted

Solution code:
s = input()[::-1]
words_r = ['eraser'[::-1], 'erase'[::-1], 'dreamer'[::-1], 'dream'[::-1]]
for word_r in words_r:
    s = s.replace(word_r, '')

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    divs = ["dream", "dreamer", "erase","eraser"]

    S = input()

    rev_S = S[::-1]
    
    rev_divs = [div[::-1] for div in divs]
    
    i = 0
    while(1):
        can = False
        for rev_div in rev_divs:
            if rev_S[i:(i+len(rev_div))] == rev_div:
                can = True
                i += len(rev_div)

                if i == len(rev_S):
                    print("YES")
                    return 
        
        if not can:
            print("NO")
            return

main()

Submission status: Accepted

Solution code:
from collections import deque

def main():
    divide = ["dream", "dreamer", "erase", "eraser"]

    S = input()

    q = deque([0])

    while(q):
        beg_i = q.popleft()

        if beg_i == len(S):
            print("YES")
            return
        
        for div_i in divide:
            end_i = beg_i + len(div_i)
            if S[beg_i:end_i] == div_i:
                q.append(end_i)
    
    print("NO")
    return

main()

Submission status: Accepted

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

dream_r = 'dream'[::-1] # maerd
dreamer_r = 'dreamer'[::-1] # remaerd
erase_r = 'erase'[::-1] # esare
eraser_r = 'eraser'[::-1] # resare

flag = True
i = 0

while flag:
    if S[i:i+len(dream_r)] == dream_r:
        i += len(dream_r)
    elif S[i:i+len(dreamer_r)] == dreamer_r:
        i += len(dreamer_r)
    elif S[i:i+len(erase_r)] == erase_r:
        i += len(erase_r)
    elif S[i:i+len(eraser_r)] == eraser_r:
        i += len(eraser_r)
    else:
        flag = False

    if i == len(S):
        flag = True
        break

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

Submission status: Accepted

Solution code:
S = input()

i = len(S)
while 0 < i:
	#print(i)
	if S[i - 6:i] == "eraser":
		#print(S[i - 6:i])
		i -= 6
	elif S[i - 7:i] == "dreamer":
		#print(S[i - 7:i])
		i -= 7
	elif S[i - 5:i] == "erase" or S[i - 5:i] == "dream":
		#print(S[i - 5:i])
		i -= 5
	else:
		break
print(["YES", "NO"][not(i == 0)])

Submission status: Accepted

Solution code:
s = input()
# s = s[::-1]
W = ['eraser', 'erase', 'dreamer', 'dream']
# W = [w[::-1] for w in W]

for w in W:
  s = s.replace(w, '')

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

Submission status: Accepted

Solution code:
s = input()
li = ["maerd", "remaerd", "esare", "resare"]
p = list(reversed((s)))
j = ""
for i in p:
  j += i
  for h in li:
    if j == h:
      j = ""
      break
if j == "":
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
S = input()[::-1]
W = [w[::-1] for w in ['dream', 'dreamer', 'erase', 'eraser']]
L = len(S)
ans = 'YES'
i = 0
while i < L:
    f = 1
    for w in W:
        if w == S[i : i + len(w)]:
            i += len(w)
            f = 0
            break
    if f:
        ans = 'NO'
        break
print(ans)

Submission status: Accepted

Solution code:
def daydream(S: str) -> bool:
    while True:
        if S.endswith('dream'):
            S = S[:-5]
        elif S.endswith('dreamer'):
            S = S[:-7]
        elif S.endswith('erase'):
            if S[:-5].endswith('eras'):
                S = S[:-4]
            else:
                S = S[:-5]
        elif S.endswith('eraser'):
            if S[:-6].endswith('eras'):
                S = S[:-5]
            else:
                S = S[:-6]
        else:
            break

    return S == ''


if __name__ == "__main__":
    S = input()
    ans = daydream(S)
    print('YES' if ans else 'NO')

Submission status: Accepted

Solution code:
import re
s = input()[::-1]
ss = re.split("maerd|remaerd|esare|resare", s)
if any(ss):
  print("NO")
else:
  print("YES")

Submission status: Accepted

Solution code:
S = list(input())
S.reverse()
gyaku = "".join(S)
ans = gyaku.replace("resare","")
ans = ans.replace("esare","")
ans = ans.replace("remaerd","")
ans = ans.replace("maerd","")

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

Submission status: Accepted

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

S = S.replace('resare', '')
S = S.replace('esare', '')
S = S.replace('remaerd', '')
S = S.replace('maerd', '')

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

Submission status: Accepted

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

output = "NO"

S = S.replace('eraser', '')
S = S.replace('erase', '')
S = S.replace('dreamer', '')
S = S.replace('dream', '')
if S == "":
    output = "YES"

print(output)

Submission status: Accepted

Solution code:
from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]
    T = [
        ['d','r','e','a','m'],
        ['d','r','e','a','m','e','r'],
        ['e','r','a','s','e'],
        ['e','r','a','s','e','r']
    ]
    # S = list(_ for _ in input())
    S = input()
    S = S[::-1]
    # S.reverse()
    # S.sort(reversed=True)

    for i in range(4):
        T[i].reverse()
    while len(S)>0:
        if(''.join(S[0:len(T[0])]) == ''.join(T[0])):
            S = S[len(T[0]):]
            # for i in range(len(T[0])):
            #     S.pop(0)
        elif(''.join(S[0:len(T[1])]) == ''.join(T[1])):
            S = S[len(T[1]):]
            # for i in range(len(T[1])):
            #     S.pop(0)
        elif(''.join(S[0:len(T[2])]) == ''.join(T[2])):
            S = S[len(T[2]):]
            # for i in range(len(T[2])):
            #     S.pop(0)
        elif(''.join(S[0:len(T[3])]) == ''.join(T[3])):
            S = S[len(T[3]):]
            # for i in range(len(T[3])):
            #     S.pop(0)
        else:
            print('NO')
            break
        
    if(len(S) ==0):
        print('YES')

    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]
    T = [
        ['d','r','e','a','m'],
        ['d','r','e','a','m','e','r'],
        ['e','r','a','s','e'],
        ['e','r','a','s','e','r']
    ]
    S = list(_ for _ in input())
    S.reverse()

    for i in range(4):
        T[i].reverse()
    while len(S)>0:
        if(''.join(S[0:len(T[0])]) == ''.join(T[0])):
            for i in range(len(T[0])):
                S.pop(0)
        elif(''.join(S[0:len(T[1])]) == ''.join(T[1])):
            for i in range(len(T[1])):
                S.pop(0)
        elif(''.join(S[0:len(T[2])]) == ''.join(T[2])):
            for i in range(len(T[2])):
                S.pop(0)
        elif(''.join(S[0:len(T[3])]) == ''.join(T[3])):
            for i in range(len(T[3])):
                S.pop(0)
        else:
            print('NO')
            break
        
    if(len(S) ==0):
        print('YES')

    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]
    T = [
        ['d','r','e','a','m'],
        ['d','r','e','a','m','e','r'],
        ['e','r','a','s','e'],
        ['e','r','a','s','e','r']
    ]
    S = list(_ for _ in input())
    S.reverse()

    for i in range(4):
        T[i].reverse()
    while len(S)>0:
        if(S[0:len(T[0])] == T[0]):
            for i in range(len(T[0])):
                S.pop(0)
        elif(S[0:len(T[1])] == T[1]):
            for i in range(len(T[1])):
                S.pop(0)
        elif(S[0:len(T[2])] == T[2]):
            for i in range(len(T[2])):
                S.pop(0)
        elif(S[0:len(T[3])] == T[3]):
            for i in range(len(T[3])):
                S.pop(0)
        else:
            print('NO')
            break
        
    if(len(S) ==0):
        print('YES')

    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]
_ = ["dream", "dreamer", "erase", "eraser"]
_ = [_[i][::-1] for i in range(4)]
i = 0
while i < len(S):
    can = False
    for k in _:
        if S[i:i + len(k)] == k:
            can = True
            i += len(k)
    if not can:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:
S = input()
ans = 'NO'

while True:
    if S[-7:] == 'dreamer':
        S = S[:-7]
        if S == '':
            ans = 'YES'
            break
    elif S[-6:] == 'eraser':
        S = S[:-6]
        if S == '':
            ans = 'YES'
            break
    elif S[-5:] == 'dream' or S[-5:] == 'erase':
        S = S[:-5]
        if S == '':
            ans = 'YES'
            break
    else:
        break

print(ans)

Submission status: Accepted

Solution code:
er = ["dreamer", "eraser"]
noter = ["dream", "erase"]
words = er + noter
s = input()
while len(s) > 0:
  flag = True
  for word in words:
    if s.endswith(word):
      s = s[:-len(word)]
      flag = False
  if flag:
    print("NO")
    exit()
print("YES")

Submission status: Accepted

Solution code:
a=("dream","erase");ans="YES"
s=input()
while s!="":
  if s[-7:]=="dreamer":s=s[:-7]
  elif s[-6:]=="eraser":s=s[:-6]
  elif s[-5:]in a:s=s[:-5]
  else:ans="NO";break
print(ans)

Submission status: Accepted

Solution code:
S = input()

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

ans = 'YES'

while(len(S) > 4):
    a = S[-5:]
    if a == 'dream' or a == 'erase':
        S = S[:-5]
        continue
    a = S[-6:]
    if a == 'eraser':
        S = S[:-6]
        continue
    a = S[-7:]
    if a == 'dreamer':
        S = S[:-7]
        continue
    ans = 'NO'
    break

print(ans)

Submission status: Accepted

Solution code:
#C - 白昼夢 / Daydream

s = input()[::-1]

while True:
  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:
    break

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

Submission status: Accepted

Solution code:
S = input()
index = 0
while True:
    if S.find("eraser", index) == index:
        index += len("eraser")

    elif S.find("erase", index) == index:
        index += len("erase")

    elif S.find("dreamer", index) == index and S.find("ase", index + len("dreamer")) != index + len("dreamer"):
        index += len("dreamer")

    elif S.find("dream", index) == index:
        index += len("dream")

    elif index == len(S):
        print("YES")
        break
    else:
        print("NO")
        break

Submission status: Accepted

Solution code:
S = input()

d = ["dream", "dreamer", "erase", "eraser"]
rs = S[::-1]
ls = len(S)
rd = [(s[::-1], len(s)) for s in d]
i = 0
while True:
    if i == ls:
        print("YES")
        break
    for s, l in rd:
        if rs[i:i+l] == s:
            i += l
            break
    else:
        print("NO")
        break

Submission status: Accepted

Solution code:
s = input()
li = {"dream": 5, "dreamer": 7, "erase": 5, "eraser": 6}
flag = 0
while len(s) > 0:
    ct = 0
    if flag == 1:
        break
    for key in li.keys():
        ct += 1
        if s.endswith(key):
            s = s[:-(li[key])]
            break
        if ct == 4:
            flag = 1
            print("NO")
            break
if flag == 0:
    print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
for i in range(10**5):
    s = s.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
print("YES") if s == '' else print("NO")

Submission status: Accepted

Solution code:
s = input()
moji = ["dream", "dreamer", 'erase', 'eraser']
while s != "":
    if s[-5:] == moji[0]:
        s = s[:-5]
    elif s[-7:] == moji[1]:
        s = s[:-7]
    elif s[-5:] == moji[2]:
        s = s[:-5]
    elif s[-6:] == moji[3]:
        s = s[:-6]
    else:
        break
if s == "":
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = list(input())
s.reverse()
s = "".join(s)

for _ in range(10**5):
    before_s = s
    if s[:5]=="maerd" or s[:5] =="esare":
        s = s[5:]
    elif s[:7]=="remaerd" :
        s = s[7:]
    elif s[:6] == "resare":
        s = s[6:]
    if s == "":
        ans = "YES"
        break
    if s == before_s:
        ans ="NO"
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(50000)

S = input()
S_len = len(S)

def dd(i):
  if i >= S_len: return True
  for ex in ("dream","dreamer","erase","eraser"):
    length = i + len(ex)
    if ex == S[i:length]:
      if dd(length): return True
  return False

print("YES" if dd(0) else "NO")

Submission status: Accepted

Solution code:
s=input()

s=s[::-1]

X=['maerd','remaerd','esare','resare']
ans='YES'
i=0
while i<=len(s)-5:
    if s[i:i+5] in X:
        i+=5
    else:
        if s[i:i+6] in X:
            i+=6
        else:
            if s[i:i+7]  in X:
                i+=7
            else:
                ans='NO'
                break

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8
S = input()
s =len(S)
t=0

def endcheck(t,s):
  if t==s:
    print("YES")
    
while t < s:
  if S[-t-5:s-t] =="dream":
    t += 5
    endcheck(t,s)
  elif S[-t-7:s-t] =="dreamer":
    t += 7
    endcheck(t,s)
  elif S[-t-5:s-t] =="erase":
    t += 5
    endcheck(t,s)
  elif S[-t-6:s-t] =="eraser":
    t += 6
    endcheck(t,s)
  else:
    print("NO")
    break

Submission status: Accepted

Solution code:
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")

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

def solv(s):
  while len(s)>0:
    x=s
    for y in l:
      i=-1*len(y)
      if y==s[i:]: s=s[:i]
    p(x,s)
    if x==s:
      print("NO")
      exit()
  print("YES")

Q=1
for i in range(Q):
  s=input()
  p(i,s,s[-5:],s[:-5])
  solv(s)

Submission status: Accepted

Solution code:
#! /usr/bin/python 
# -*- coding: utf-8 -*- 
#===============================================================================
# Date created  : 2019-03-30T11:32:28+09:00
# Date modified : 2019-03-30T11:56:45+09:00
# Author        : awk
# Description   : unanswered
#===============================================================================


S = input()
S = S[::-1] 
n = len(S)
while len(S) != 0:
    if S[:6] == "resare":
        S = S[6:]
    elif S[:7] == "remaerd":
        S = S[7:]
    elif S[:5] == "esare":
        S = S[5:]
    elif S[:5] == "maerd":
        S = S[5:]
    else:
        print("NO")
        quit()
print("YES")

Submission status: Accepted

Solution code:
data = [str(input()), True]

def check(string):
    if string[len(string)-6:] == 'eraser':
        string = string[:len(string)-6]
        return [string,True]
    elif string[len(string)-5:] == 'erase':
        string = string[:len(string)-5]
        return [string,True]
    elif string[len(string)-7:] == 'dreamer':
        string = string[:len(string)-7]
        return [string,True]
    elif string[len(string)-5:] == 'dream':
        string = string[:len(string)-5]
        return [string,True]
    else:
        return [string,False]
        
while (data[1] == True):
    data = check(data[0])
    if data[0] == '':
        print('YES')
        break
    elif data[1] == False:
        print('NO')
        break

Submission status: Accepted

Solution code:
s = input()
# s = "dreamerase"
L = ["eraser", "dreamer", "erase", "dream"]
i = 0
f = 0
while i < len(s):
    if s[i:i+6] == "eraser" and (len(s) == i+6 or s[i+6:i+8] != "as"):
        i += 6
    elif s[i:i+7] == "dreamer" and (len(s) == i+7 or s[i+7:i+9] != "as"):
        i += 7
    elif s[i:i+5] == "erase" or s[i:i+5] == "dream":
        i += 5
    else:
        f = 1
        break

if f == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = input()
a = s

for i in range(10**4):
    a = a.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    a,b = LI()
    if not (a*b)%2:
        print("Even")
    else:
        print("Odd")
    return

#B
def B():
    s = S()
    print(s.count("1"))
    return

#C
def C():
    n = I()
    a = LI()
    f = 0
    for j in range(100000):
        for i in range(n):
            if a[i]%2:
                f = 1
                break
            a[i] //= 2
        if f:break
    print(j)
    return

#D
def D():
    a,b,c,x = IR(4)
    su = 0
    for i in range(a+1):
        for j in range(b+1):
            for k in range(c+1):
                if 500*i+100*j+50*k == x:su += 1
    print(su)
    return

#E
def E():
    n,y = LI()
    for i in range(n+1):
        for j in range(n+1-i):
            k = n-i-j
            if 10000*i+5000*j+1000*k == y:
                print(i,j,k)
                quit()
    print(-1,-1,-1)
    return

#F
def F():
    s = input()
    while s:
        if s[:11] == "dreameraser":
            s = s[11:]
        elif s[:10] == "dreamerase":
            s = s[10:]
        elif s[:7] == "dreamer":
            s = s[7:]
        elif s[:6] == "eraser":
            s = s[6:]
        elif s[:5] == "dream":
            s = s[5:]
        elif s[:5] == "erase":
            s = s[5:]
        else:
            print("NO")
            quit()
    print("YES")
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    F()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S = input()
revS = S[::-1]
addStrings = ['dream', 'dreamer', 'erase', 'eraser']

T = ""
counter = 0
while True:
    existFlg = False
    for i in range(4):
        if revS[counter:counter + len(addStrings[i])] == addStrings[i][::-1]:
            existFlg = True
            T = T + addStrings[i][::-1]
            counter += len(addStrings[i])
            
    if not existFlg:
        break

if revS == T:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s = input()
s=s[::-1] #文字列の反転
words = ["maerd", "remaerd", "esare", "resare"]
while len(s) > 4:
    if s[:5] == 'maerd':
        s = s[5:]
        continue
    elif s[:7] == 'remaerd':
        s = s[7:]
        continue
    elif s[:5] == 'esare':
        s = s[5:]
        continue
    elif s[:6] == 'resare':
        s = s[6:]
        continue
    else:
        break
if len(s) > 0:
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
s = input()
s=s[::-1]
words = ['maerd','remaerd','esare','resare']
s_long=len(s)
i=0
flag = 1
while i<s_long:
    flag2 = 0
    for j in range(4):
        words_long=len(words[j])
        if s[i:i+words_long]==words[j]:
            i += words_long
            break
        else:
            flag2 += 1
    if flag2 == 4:
        flag = 0
    if not flag:
        break
if flag:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s = input()

# dream dreamer erase eraser
def f():
    global s
    while True:
        if len(s) <= 9:
            if s in ["dream","dreamer","erase","eraser"]:
                return "YES"
            else:
                return "NO"

        if s[:5] == "dream":
            if s[5:7] == "er" and s[7] != "a":
                s = s[7:]
            else:
                s = s[5:]
        elif s[:5] == "erase":
            if s[5] == "r":
                s = s[6:]
            else:
                s = s[5:]
        else:
            return "NO"
            

print(f())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()[::-1]
words = ['maerd', 'remaerd', 'esare', 'resare']
flag = 0
for _ in range(25000):
    if flag==4 or len(s)==0:
        break
    else:
        flag=0
    for word in words:
        l = len(word)
        if s[0:l] == word:
            s = s[l:]
        else:
            flag+=1
if flag==4:
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
def main():
    S = input()
    words = ["dream", "dreamer", "erase", "eraser"]
    while len(S):
        ok = False
        for w in words:
            if S.endswith(w):
                S = S[:-len(w)]
                ok = True
                break
        if not ok:
            print("NO")
            return
    print("YES")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
words = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(words)) :
    words[i] = words[i][::-1]

S = input()[::-1]

ans = True

i = 0

while True :
    flag = False
    for w in words :
        if S[i:i + len(w)] == w :
            i += len(w)
            flag = True
            break
    if flag == False:
        ans = False
        break
    if i == len(S) :
        break

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

Submission status: Accepted

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

i=0
while True:
    for d in sample:
        if s[:len(d)] == d:
            s = s[len(d):]
            break
    
    if d =='':
        print ("NO")
        break

    if len(s) ==0:
        print("YES")
        break

Submission status: Accepted

Solution code:
S = input()
# S.reverse()
S = S[::-1]
#dream, dreamer, erase, eraser
headers = ["resare","esare","remaerd","maerd"]

result = True
while True:
    if S=="":
        result = True
        break
    result = False
    for header in headers:
        if S.startswith(header):
            S = S[len(header):]
            result = True
    if not result:
        break

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

Submission status: Accepted

Solution code:
S = input()

import re
pattern = r'^((dream)|(dreamer)|(erase)|(eraser))*$'

repatter = re.compile(pattern)

if repatter.match(S):
  print('YES')
else:
  print('NO')

Submission status: Accepted

Solution code:
S = input()

idx_end = len(S)
while True:
    if idx_end >= 5 and S[idx_end-5:idx_end] == "dream":
        idx_end -= 5
    elif idx_end >= 7 and S[idx_end-7:idx_end] == "dreamer":
        idx_end -= 7
    elif idx_end >= 5 and S[idx_end-5:idx_end] == "erase":
        idx_end -= 5
    elif idx_end >= 6 and S[idx_end-6:idx_end] == "eraser":
        idx_end -= 6
    else:
        break

    if idx_end == 0:
        break

if idx_end == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
print(('NO', 'YES')[S == ''])