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 re

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

Submission status: Accepted

Solution code:
s=input()
import re
#re.match は複数を対象にすればマッチする該当のものが返される。一つの時ifの後に持ってくると条件式として利用可能。
if re.match("^(dream|dreamer|erase|eraser)+$",s) :
       print("YES")
else:
       print("NO")

Submission status: Accepted

Solution code:
s=input()

s = s[::-1] #文字の反転

t = 0;

while t ==0:
    a = s.find("maerd")
    b = s.find("remaerd")
    c = s.find("esare")
    d = s.find("resare")

    if a == 0 or c== 0:
        s = s[5:]
        continue
    if b == 0:
        s = s[7:]
        continue
    if d == 0:
        s = s[6:]
        continue
    t=1


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

s = input()
r_s = ''.join(list(reversed(s)))

dream = "maerd"
dreamer = "remaerd"
erase = "esare"
eraser = "resare"

flag = True

while flag:
    if r_s.startswith(dream):
        r_s = r_s[5:]
    elif r_s.startswith(dreamer):
        r_s = r_s[7:]
    elif r_s.startswith(erase):
        r_s = r_s[5:]
    elif r_s.startswith(eraser):
        r_s = r_s[6:]
    else:
        flag = False

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

Submission status: Accepted

Solution code:
s = input()
div = ["dream", "dreamer", "erase", "eraser"]
rev = []
t = ""
s_rev = s[::-1]
for d in div:
    rev.append(d[::-1])

result = True
i = 0
while i < len(s):
    can_divide = False
    for d in rev:
        if len(s_rev) - i >= len(d) and s_rev[i:i + len(d)] == d:
            can_divide = True
            i += len(d)
            break
    if not can_divide:
        result = False
        break

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
t = ""
while len(t) < len(s):
    target_len = len(s) - len(t)

    if s[len(t)] == 'd':
        if target_len == 5:
            t += "dream"
        elif target_len == 7:
            t += "dreamer"
        elif target_len > 7:
            if s[len(t) + 5] != 'd' and s[len(t) + 5:len(t) + 7 + 1] != "era":
                t += "dreamer"
            else:
                t += "dream"
        else:
            break
    else:
        if target_len == 5:
            t += "erase"
        elif target_len == 6:
            t += "eraser"
        elif target_len > 6:
            if s[len(t) + 5] != 'd' and s[len(t) + 5:len(t) + 6 + 2] != "era":
                t += "eraser"
            else:
                t += "erase"
        else:
            break

    if s[0:len(t)] != t:
        break

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

Submission status: Accepted

Solution code:
import re
print("YES" if re.match("^(dream|dreamer|erase|eraser|)+$", input()) else "NO")
#先頭(^)から末尾($)まで文字列の和集合( (|) )の繰り返し(+)で表されているならば”YES＂を出力

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
def main():
    from functools import lru_cache
    import sys
    sys.setrecursionlimit(10 ** 7)

    WORDS = 'dream', 'dreamer', 'erase', 'eraser'

    S = input()
    N = len(S)

    @lru_cache(maxsize=None)
    def dfs(cur=N):
        if cur == 0:
            return True

        for word in WORDS:
            if S[cur - len(word):cur] == word:
                if dfs(cur - len(word)):
                    return True

        return False

    cond = dfs()
    print('YES' if cond else 'NO')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    S = input()
    is_flag = True
    while is_flag:
        # print(S, len(S))
        if len(S)>=5:
            temp = S[:5]
            # print(temp)
            if temp == 'dream':
                S = S[5:]
                if len(S) != 0:
                    if S[:5] == 'erase':
                        pass
                    elif S[:2] == 'er':
                        S = S[2:]
                
            elif temp == 'erase':
                S = S[5:]
                if len(S) != 0:
                    if S[0] == 'r':
                        S = S[1:]

            else:
                print('NO')
                is_flag = False
        elif len(S) == 0:
            print('YES')
            is_flag = False
        else:
            print('NO')
            is_flag = False


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc049/tasks/arc065_a
# まえからっ読んでいくと文字列のオーバーラップが多くいし、末尾のオーバーラップも多くてしんどい
# 逆から読んでくと3文字で即時決定できる

S = read()[:-1]
S = deque(reversed('xxxxxxxxxx' + S))  # よしなにpaddingすることで終端処理を楽に

# print(S)
while len(S) > 10:
    end3 = ''.join([S[6], S[5], S[4], S[3], S[2], S[1], S[0]])
    # print(end3)
    if end3[2:] == 'dream':
        num_pop = 5
    elif end3 == 'dreamer':
        num_pop = 7
    elif end3[2:] == 'erase':
        num_pop = 5
    elif end3[1:] == 'eraser':
        num_pop = 6
    else:
        print('NO')
        exit()
    for _ in ra(num_pop):
        S.popleft()

# print(S)
if len(S) == 10:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

A = ''
for s in S[::-1]:
    A += s
    if A in T:
        A = ''
print('YES' if A == '' else 'NO')

Submission status: Accepted

Solution code:
s=input()
i=0
flag=True
while i<len(s):
  if s[i]=="d":

    if s[i:i+7]=="dreamer":
      if i+7<len(s) and s[i+7]!="a":
        i=i+7
      elif i+7==len(s):
        i=i+7
      elif s[i:i+5]=="dream":
        i=i+5
      else:
        flag=False
        break
    elif s[i:i+5]=="dream":
        i=i+5
    else:
      flag=False
      break
      
      
  elif s[i]=="e":
    if s[i:i+6]=="eraser":
      i=i+6
    elif s[i:i+5]=="erase":
      i=i+5
    else:
      flag=False
      break
      
      
  else:
    flag=False
    break
if flag==True:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
S = input()

s = ['dream', 'dreamer', 'erase', 'eraser']
R = len(S)
while(R > 0):
    for i in range(4):
        if R >= len(s[i]):
            if S[R-len(s[i]):R] == s[i]:
                R -= len(s[i])
                break
        if i == 3:
            print("NO")
            exit(0)
print("YES")

Submission status: Accepted

Solution code:
def examA():
    S = SI()
    T = SI()
    N = len(S)
    ans = "No"
    for i in range(N):
        cur = S[i:] + S[:i]
        #print(cur)
        if cur==T:
            ans = "Yes"
    print(ans)
    return

def examB():
    H, W = LI()
    S = [SI()for _ in range(H)]
    flag = True
    ans = 0
    print(ans)
    return

def examC():
    L, R = LI()
    ans = inf
    if R-L>=3000:
        R = L+3000

    for l in range(L, R + 1):
        for r in range(l+1, R + 1):
            now = (l*r) %2019
            ans = min(ans,now)
    print(ans)
    return

def examD():
    T = {"dream", "dreamer", "erase", "eraser"}
    S = SI()
    ans = "NO"
    t = ""
    for s in S[::-1]:
        t += s
        if t[::-1] in T:
            t = ""
        if len(t)>10:
            print(ans)
            return
    if t=="":
        ans = "YES"
    print(ans)
    return

def examE():
    N = 50
    K = I()
    base = K//N
    A = [base+i for i in range(N)]
    rest = K%N
    for i in range(rest):
        A[-i-1] += 1
    print(N)
    print(" ".join(map(str,A)))
    return

def examF():
    N = 20
    C = [2**i for i in range(N)]
    L = I()
    cur = 1
    V = [[i+1, i+2, 0]for i in range(N-1)]
    now = 1
    while(now<N):
        if C[now]<=L:
            cur = C[now]
            V.append([now,now+1,C[now-1]])
            now += 1
        else:
            break
    #print(cur)

    for i in range(now)[::-1]:
        if C[i]<=L-cur:
            cost = cur
            V.append([i+1,N,cost])
            cur += C[i]

    print(N,len(V))
    for s,t,c in V:
        print(s,t,c)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

Solution code:
import sys
import resource
sys.setrecursionlimit(10 ** 9)

S = input()
l = []
def dfs(n):
  if n == len(S):
    l.append("YES")
  if n < len(S):
    if S[n:n+5] == "erase":
      dfs(n+5)    
    if S[n:n+5] == "dream":
      dfs(n+5)  
    if S[n:n+6] == "eraser":
      dfs(n+6)              
    if S[n:n+7] == "dreamer":
      dfs(n+7)
dfs(0)
if len(l) == 0:
  l.append("NO")
print(l[0])

Submission status: Accepted

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

a="maerd"
b="remaerd"
c="esare"
d="resare"
s="".join(list(reversed(SI())))
n=len(s)
ind=0
while ind<n:
    #print(ind)
    if s[ind:ind+5]==a or s[ind:ind+5]==c:
        ind+=5
    elif s[ind:ind+6]==d:
        ind+=6
    elif s[ind:ind+7]==b:
        ind+=7
    else:
        print("NO")
        sys.exit()
    #print(ind)
if ind==n:
    print("YES")

Submission status: Accepted

Solution code:
S=input()
S=S[::-1]
L=["dream","dreamer","erase","eraser"]
L=[i[::-1] for i in L]
i=0
while i<len(S):
    flg=0
    for j in range(4):
        if S[i]==L[j][0] and S[i:min(i+len(L[j]),len(S))]==L[j]:
            flg=1
            i+=len(L[j])
            break
    if flg==0:
        break

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

Submission status: Accepted

Solution code:
import re
s = input()
s = re.sub('eraser','0',s)
#print(s)
s = re.sub('erase','0',s)
#print(s)
s = re.sub('dreamer','0',s)
#print(s)
s = re.sub('dream','0',s)
#print(s)


print('YES' if set(s) == set('0') else 'NO')

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()[::-1]
n = len(s)
d = [['maerd',5],['remaerd',7],['esare',5],['resare',6]]
ind = 0
while True:
    if ind == n:
        print('YES')
        break
    ok = False
    for t,a in d:
        if ind + a <= n and s[ind:ind+a] == t:
            # print(s[ind:ind+a],t)
            ind += a
            ok = True
            break
    if not ok:
        print('NO')
        break

Submission status: Accepted

Solution code:
import sys
S = input()
s = S[::-1]
i = 0
n = len(s)-i
while n>0:
  if s[i:i+5] == "maerd" or s[i:i+5] == "esare" :
    i += 5
    n = len(s)-i
  elif s[i:i+6] == "resare":
    i += 6
    n = len(s)-i
  elif s[i:i+7] == "remaerd":
    i += 7
    n = len(s)-i
    pass
  else:
    print("NO")
    sys.exit()
    
print("YES")

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    S = list(input())
    S_Rev = S[::-1]
    n = len(S)

    pos = 0
    while pos < n:
        if S_Rev[pos] == "m":
            if pos + 5 <= n and "".join(S_Rev[pos:pos + 5]) == "maerd":
                pos += 5
            else:
                print("NO")
                break
        elif S_Rev[pos] == "e":
            if pos + 5 <= n and "".join(S_Rev[pos:pos + 5]) == "esare":
                pos += 5
            else:
                print("NO")
                break
        elif S_Rev[pos] == "r":
            if pos + 6 <= n and "".join(S_Rev[pos:pos + 6]) == "resare":
                pos += 6
            elif pos + 7 <= n and "".join(S_Rev[pos:pos + 7]) == "remaerd":
                pos += 7
            else:
                print("NO")
                break
        else:
            print("NO")
            break
    else:
        print("YES")


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
S = str(input())[::-1]
words = ['maerd', 'esare', 'remaerd', 'resare']

leng = len(S)
while leng>=5:
    if S[:5] in words:
        S = S[5:]
        leng -= 5
    elif leng>=7 and S[:7] in words:
        S = S[7:]
        leng -= 7
    elif leng>=6 and S[:6] in words:
        S = S[6:]
        leng -= 6
    else:
        print('NO')
        break

if leng==0:
    print('YES')

Submission status: Accepted

Solution code:
def check():
    S = input()
    dp = [False]*len(S)
    dp[-1]=True
    for i in range(1,len(S)):
        dp[i] = (dp[i-5]&(S[max(0,i-4):i+1]in['dream','erase']))|(dp[i-7]&(S[max(0,i-6):i+1]=='dreamer'))|(dp[i-6]&(S[max(0,i-5):i+1]=='eraser'))

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

Submission status: Accepted

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

Submission status: Accepted

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

cur = 0
while cur < n:
  if s[cur:cur+5:] == "maerd" or s[cur:cur+5:] == "esare":
    cur += 5
    continue
  elif s[cur:cur+6:] == "resare":
    cur += 6
    continue
  elif s[cur:cur+7:] == "remaerd":
    cur += 7
    continue
  print("NO")
  exit()
print("YES")

Submission status: Accepted

Solution code:
s = str(input())

S=s[::-1]
T=""
while len(T)<=len(S):
	if T+"maerd"==S[:len(T)+5]:
		T=T+"maerd"
	elif T+"remaerd"==S[:len(T)+7]:
		T=T+"remaerd"
	elif T+"esare"==S[:len(T)+5]:
		T=T+"esare"
	elif T+"resare"==S[:len(T)+6]:
		T=T+"resare"
	else:
		break


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

S = list(input())
i = len(S) - 1

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

while i > 0:
    if S[i] == 'm':
        for j in range(5):
            if S[i - j] == T[0][4 - j]:
                continue
            else:
                print ('NO')
                exit()
        i -= 5
    elif S[i] == 'r':
        if S[i - 2] == 'm':
            for j in range(7):
                if S[i - j] == T[1][6 - j]:
                    continue
                else:
                    print ('NO')
                    exit()
            i -= 7
        else:
            for j in range(6):
                if S[i - j] == T[3][5 - j]:
                    continue
                else:
                    print ('NO')
                    exit()
            i -= 6
    else:
        for j in range(5):
            if S[i - j] == T[2][4 - j]:
                continue
            else:
                print ('NO')
                exit()
        i -= 5

if i == -1:
    print ('YES')
else:
    print ('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    W="dream dreamer erase eraser".split(" ")
    #print(W)
    S=input()
    t=[S]
    while(t!=[]):
        temp=t.pop()
        for w in W:
            m=len(w)
            if(temp[-m:])==w:
                f=temp[:-m]
                if f=="":
                    print("YES")
                    return
                t.append(f)
    print("NO")
#%%submit!
resolve()

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    s = input()
    w = ["dream", "dreamer", "erase", "eraser"]
    last = len(s)
    for _ in range(len(s)):
        if last < 1:
            break
        for ww in w:
            if s[last - len(ww):] == ww:
                s = s[:last - len(ww)]
                last -= len(ww)
    print("YES" if last < 1 else "NO")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
S = input()

while len(S) >= 5:
    # Sを４つの単語で順に調べて刈っていく
    if len(S) >= 7 and S[-7:] == "dreamer":
        S = S[:-7]
        continue

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

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

    else:
        break

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

Submission status: Accepted

Solution code:
s = input()[::-1] + '0'*7
words = ['maerd', 'remaerd', 'esare', 'resare']
i =0
while True:
    if s[i] == 'm':
        if s[i:i+5] == words[0]:
            i += 5
        else:break
    elif s[i] == 'r':
        if s[i:i+7] == words[1]:
            i += 7
        elif s[i:i+6] == words[3]:
            if s[i+6] == 's':
                i += 5
            else:
                i += 6
        else:break
    elif s[i] == 'e':
        if s[i:i+5] == words[2]:
            if s[i+5] == 's':
                i += 4
            else:
                i += 5
        else:
            break
    else:
        break
#print(s[i:])
if s[i:] == '0'*7:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
s=input()
s=s[::-1]
w=['dream','dreamer','erase','eraser']
lenw=[5,7,5,6]
w=[i[::-1] for i in w]
i=0
n=len(s)
while i<n:
    flg=False
    for j in range(4):
        if s[i:min(i+lenw[j],n)]==w[j]:
            i=i+lenw[j]
            flg=True
    if flg==False:
        break

if i==n and flg:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

DREAM = 'dream'[::-1]
DREAMER = 'dreamer'[::-1]
ERASE = 'erase'[::-1]
ERASER = 'eraser'[::-1]

keywords = (DREAM, DREAMER, ERASE, ERASER)

while len(S) > 0:
    for keyword in keywords:
        if S.startswith(keyword):
            S = S[len(keyword):]
            break
    else:
        break

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

Submission status: Accepted

Solution code:
i = input()[::-1]
T = []
for t in ['dreamer', 'dream', 'eraser', 'erase']:
    T.append(t[::-1])

match = True
while match:
    match = False
    for t in T:
        if i.startswith(t):
            match = True
            i = i.replace(t, '', 1)
            if len(i) < 1:
                print('YES')
                exit()

print('NO')

Submission status: Accepted

Solution code:
s=input()
x,y,l=0,5,len(s)
for _ in range(10**5):
  if x>=l-7:
    if x==l-7 and s[x:l]=='dreamer':
      print('YES')
    elif x==l-6 and s[x:l]=='eraser':
      print('YES')
    elif x==l-5 and (s[x:l]=='dream' or s[x:l]=='erase'):
      print('YES')
    else:
      print('NO')
    exit()
    
  if s[x:y]=='erase':
    x=y+1 if s[y]=='r' else y
    y=x+5
  elif s[x:y]=='dream':
    x=y if s[y:y+3]=='era' else (y+2 if s[y:y+2]=='er' else y) 
    y=x+5
  else:
    print('NO')
    exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

s = input()

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

Submission status: Accepted

Solution code:
s = input()
ws = ['dream', 'dreamer', 'erase', 'eraser']

# 後ろから見ていかないと dream + erase を dreamかdreamerかわかんない
while len(s) > 0:
  # print(s)
  for i in range(4):
    w = ws[i]
    if s.endswith(w):
      s = s[:-len(w)]
      break
  else:
    break

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

Submission status: Accepted

Solution code:
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1

s = readChar()[::-1]

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

jud = ["mae","rem","esa","res"]

while s!="":
	if s[:3] in jud:
		x = jud.index(s[:3])
		if x==0 or x==2:
			if s[:5]==t[x]:
				s = s[5:]
			else:
				print("NO")
				exit()
		elif x==1:
			if s[:7]==t[x]:
				s = s[7:]
			else:
				print("NO")
				exit()
		elif x==3:
			if s[:6]==t[x]:
				s = s[6:]
			else:
				print("NO")
				exit()
		else:
			print(-1)
			exit()
	else:
		print("NO")
		exit()

print("YES")

Submission status: Accepted

Solution code:
patterns = [[5, "dream"], [7, "dreamer"], [5, "erase"], [6, "eraser"]]

s = input()

idx = len(s)
while idx > 0:
    for sub, pat in patterns:
        n_idx = idx - sub
        if pat == s[n_idx:idx]:
            idx = n_idx
            break
        else:
            continue
    if idx != n_idx:
        break

print("YES" if idx == 0 else "NO")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000000)

S = input()[::-1]


while len(S) > 0:
    if S[0] == 'r':
        if S[0:6] == 'resare':
            S = S[6:]
        elif S[0:7] == 'remaerd':
            S = S[7:]
        else:
            print('NO')
            exit()
    elif S[0:5] == 'maerd':
        S = S[5:]
    elif S[0:5] == 'esare':
        S = S[5:]
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 標準入力の取得
S = input()


def main() -> None:
    """Entry point
    """
    # 求解処理
    """
    Tに右から文字を詰めていき、Sと比較
    """
    # 文字の定義
    dream = "dream"
    dreamer = "dreamer"
    erase = "erase"
    eraser = "eraser"

    T = ""
    t = -1
    result = True
    while True:
        s = S[t]
        if s == dream[-1]:
            # 次の文字が"m"のとき、dreamを挿入
            T = dream + T
        elif s == erase[-1]:
            # 次の文字が"e"のとき、eraseを挿入
            T = erase + T
        elif s == dreamer[-1]:
            # 次の文字が"r"のとき、右から3つ目の文字で場合分け
            s = S[t-2]
            if s == dreamer[-3]:
                # 3つ目の文字が"m"のとき、dreamerを挿入
                T = dreamer + T
            elif s == eraser[-3]:
                # 3つ目の文字が"s"のとき、eraserを挿入
                T = eraser + T
            else:
                result = False
                break
        else:
            result = False
            break

        if len(S) <= len(T):
            # 最終チェック
            result = (S == T)
            break
        t = -len(T) - 1  # 次の文字のインデックスを取得

    # 結果出力
    if result:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 標準入力の取得
S = input()

# 求解処理
T = ""
t = -1
result = True
while True:
    s = S[t]
    if s == "m":
        T = "dream" + T
    elif s == "e":
        T = "erase" + T
    elif s == "r":
        s = S[t-2]
        if s == "m":
            T = "dreamer" + T
        elif s == "s":
            T = "eraser" + T
        else:
            result = False
            break

    else:
        result = False
        break

    if len(S) == len(T):
        result = (S == T)
        break
    t = -len(T) - 1

# 結果出力
if result:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s=input()

t1='maerd'
t2='remaerd'
t3='esare'
t4='resare'
t=[t1,t2,t3,t4]

s=s[::-1]

ans=0

while True:
    if s.startswith(t1):
        s=s[5::]
    
    elif s.startswith(t2):
        s=s[7::]
      
    elif s.startswith(t3):
        s=s[5::]
 
    elif s.startswith(t4):
        s=s[6::]
        
    elif len(s)==0:
        break
        
    else:
        print('NO')
        ans=1
        break
        
    
        
if ans==0:
    print('YES')