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
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    S = input()[::-1]

    flag = True
    while S:
        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:
            flag = False
            break

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

if __name__ == '__main__':
    solve()

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:
import re
S = input()

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

Submission status: Accepted

Solution code:
from collections import deque
import sys

def fnw(n,s):
    sm=deque([])
    if n<=len(s):
        for _ in range(n):
            sm.append(s.popleft())
    return ''.join(sm)

def jfws(s):
    fws=fnw(5,s)
    if fws=='dream':
        fws=fnw(2,s)
        if fws=='er':
            if s:
                if s[0]=='a':
                    s.extendleft(deque(reversed(list(fws))))
        else:
            s.extendleft(deque(reversed(list(fws))))
        return False
    elif fws=='erase':
        fws=fnw(1,s)
        if fws!='r' and fws!='':
            s.appendleft(fws)
        return False
    else:
        return True 

def main(s):
    while s:
        if jfws(s):
            return 'NO'
    return 'YES'

s=deque(sys.stdin.readline().strip())
print(main(s))

Submission status: Accepted

Solution code:
from collections import deque
import sys

def fnw(n,s):
    sm=deque([])
    if n<=len(s):
        for _ in range(n):
            sm.append(s.popleft())
    return sm

def jfws(s):
    # print(s)
    sm=fnw(5,s)
    # print(sm)
    if ''.join(sm)=='dream':
        sm=fnw(2,s)
        if ''.join(sm)=='er':
            if bool(s):
                if s[0]=='a':
                    s.extendleft(deque(reversed(list(sm))))
        else:
            s.extendleft(deque(reversed(list(sm))))
        return False
    elif ''.join(sm)=='erase':
        sm=fnw(1,s)
        if ''.join(sm)!='r':
            s.extendleft(sm)
        return False
    else:
        return True 

def main(s):
    while len(s)>0:
        if jfws(s):
            return 'NO'
    return 'YES'

s=deque(sys.stdin.readline().strip())
print(main(s))

Submission status: Accepted

Solution code:
S = input()
n = len(S)
T = ['dreamer', 'eraser', 'dream', 'erase']
idx = n
res = 'YES'
while idx > 0:
    for t in T:
        if S[idx-len(t):idx] == t:
            idx -= len(t)
            break
    else:
        res = 'NO'
        idx = -1
print(res)

Submission status: Accepted

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

cand = {'maerd', 'remaerd', 'esare', 'resare'}

res = 'YES'

while len(S):
    orig = S
    for w in cand:
        if S.startswith(w):
            S = S[len(w):]
    if orig == S:
        res = 'NO'
        break

print(res)

Submission status: Accepted

Solution code:
s=input()
t=""
w=["dreameraser","dreamerase","dreamer","dream","eraser","erase"]
for i in range(10**5):
    for j in range(6):
        temp=t
        temp+=w[j]
        if temp[len(t):len(temp)]==s[len(t):len(temp)]:
                t+=w[j]
                break
    if s==t:
        print("YES")
        exit()
print("NO")
exit()

Submission status: Accepted

Solution code:
S = list(input())
S.reverse()
S = ''.join(S)
idx = 0
len_S = len(S)
flag = True
while idx != len_S:
    if (len_S - idx > 6) and (S[idx:idx+7] == 'remaerd'):
        idx += 7
    elif (len_S - idx > 5) and (S[idx:idx+6] == 'resare'): 
        idx += 6
    elif (len_S - idx > 4) and (S[idx:idx+5] == 'maerd'): 
        idx += 5
    elif (len_S - idx > 4) and (S[idx:idx+5] == 'esare'): 
        idx += 5
    else:
        flag = False
        break

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()

    S = S[::-1]
    idx = 0
    ans = "YES"
    while idx <= len(S) - 1:
        is_ok = False
        if S[idx:idx + 5] in ("maerd", "esare"):
            is_ok = True
            idx += 5
        if S[idx:idx + 6] == "resare":
            is_ok = True
            idx += 6
        if S[idx:idx + 7] == "remaerd":
            is_ok = True
            idx += 7

        if not is_ok:
            ans = "NO"
            break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()

check = ('dream','dreamer','erase','eraser')

index = len(S) + 1
flag = True

while True:
    if len(S) == 0:
        break
    for c in check:
        if S[-len(c):] in check:
            S = S[:-len(c)]
            break
    else:
        flag = False
        break

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

Submission status: Accepted

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

s = input()
s = "".join(s.split("eraser"))
s = "".join(s.split("erase"))
s = "".join(s.split("dreamer"))
s = "".join(s.split("dream"))

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

Submission status: Accepted

Solution code:
s = input()[::-1]
ls = ['dream', 'dreamer', 'erase', 'eraser']
ls = [ls[i][::-1] for i in range(4)]
ans = 'YES'
i = 0
while i < len(s):
    ng = 1
    for j in range(4):
        if s[i:i+len(ls[j])] == ls[j]:
            i += len(ls[j])
            ng = 0
    if ng:
        ans = 'NO'
        break
print(ans)

Submission status: Accepted

Solution code:
import re
s = input()
s = s[::-1]
#print(s)
match = re.match('((remaerd)|(maerd)|(resare)|(esare))*',s)
#print(match)
#print(match.group())
if match.group() == s:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    S = input()
    idx = len(S)
    while idx-5 >= 0:
        if S[idx-5:idx] in ["dream","erase"]:
            idx -= 5
        elif idx-6 >= 0 and S[idx-6:idx] == "eraser":
            idx -= 6
        elif idx-7 >=0 and S[idx-7:idx] == "dreamer":
            idx -= 7
        else:
            print('NO')
            return
    else:
        if idx == 0:
            print('YES')
        else:
            print('NO')

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
s=input()[::-1]
a=["dreamer"[::-1],"eraser"[::-1],"dream"[::-1],"erase"[::-1]]
st=1
en=0
while st>en:
  st=len(s)
  for m in a:
    
    if s.find(m)==0:
      s=s[len(m):]
    
  en=len(s)
  
print("YES" if s=="" else "NO")

Submission status: Accepted

Solution code:
#float型を許すな
#numpyはpythonで
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,factorial
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

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque, Counter
import math
 
# import copy
from bisect import bisect_left, bisect_right
# import heapq
 
# sys.setrecursionlimit(1000000)
 
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
 
def main():
    S = list(getS())
    tgt5 = [list(s) for s in ["dream", "erase"]]
    tgt6 = [list(s) for s in ["eraser"]]
    tgt7 = [list(s) for s in ["dreamer"]]
    dp = [0 for i in range(len(S)+1)]
    dp[0] = 1
    for i, c in enumerate(S):
        if dp[i] == 1:
            for tg in tgt5:
                if S[i: i+5] == tg and i+5 <= len(S):
                    dp[i+5] = 1
            for tg in tgt6:
                if S[i: i+6] == tg and i+6 <= len(S):
                    dp[i+6] = 1
            for tg in tgt7:
                if S[i: i+7] == tg and i+7 <= len(S):
                    dp[i+7] = 1

    # print(dp)
    if dp[-1] == 1:
        print("YES")
    else: 
        print("NO")

    return


 
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = list(input())
tes = ''
tes2 = ''
tes3 = []
res = 1
tr = -1
for i in range(len(s)) :
    tes += s[i]
    if tes == 'dream' or tes == 'erase' or tes == 'dreamer' or tes == 'eraser' :
        for j in range(i+1,len(s)):
            tes2 += s[j]
            if tes2 == 'dream' or tes2 == 'erase' :
                tr = 1
                #print("TRUE")
                #print(tes2)
                tes2 = ''
                break
            elif len(tes2) >= 7 or j == len(s)-1 :
                tr = 0
                #print("FALSE")
                #print(tes2)
                tes2 = ''
                break
        if tr == 1:
            #print(tes)
            tes3.append(tes)
            tes = ''

            

    elif len(tes) > 7:
        res = 0
        break
        
#print(tes2+'2')
#print(tes3)
#print(tes+'1')
if tes == 'dream' or tes == 'erase' or tes == 'dreamer' or tes == 'eraser':
    tes3.append(tes)
    tes = ''

if  len(tes3) > 0 and len(tes) == 0 :
    print('YES')
else :
    print('NO')

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()[::-1]

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

print("YES")

Submission status: Accepted

Solution code:
S = input().strip()
N = len(S)
if N<5:
    print("NO")
else:
    flag = 0
    cur = N
    while cur>0:
        if cur>=7 and S[cur-7:cur]=="dreamer":
            cur -= 7
        elif cur>=6 and S[cur-6:cur]=="eraser":
            cur -= 6
        elif cur>=5 and S[cur-5:cur] in ["dream","erase"]:
            cur -= 5
        else:
            flag = 1
            break
    if flag==0:
        print("YES")
    else:
        print("NO")

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:
S = input()[::-1]
W = ['dream','dreamer','erase','eraser']
i = 0
while i < len(S):
    for w in W:
        if S[i:i+len(w)] == w[::-1]:
            i += len(w)
            break
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
def check():
  S = input()
  n = len(S)
  dp = [False]*(n+10)
  dp[0] = True
  for i in range(n+1):
    if S[i:i+5]=='dream':
      dp[i+5] |= dp[i]
    if S[i:i+7]=='dreamer':
      dp[i+7] |= dp[i]
    if S[i:i+5]=='erase':
      dp[i+5] |= dp[i]
    if S[i:i+6]=='eraser':
      dp[i+6] |= dp[i]
  if dp[n]==True:
    return 'YES'
  return 'NO'
print(check())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re
s=input()
if re.match(r"(dream|dreamer|erase|eraser)+$",s):
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    S = in_s()
    S = S.replace('eraser', '')
    S = S.replace('erase', '')
    S = S.replace('dreamer', '')
    S = S.replace('dream', '')

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input ()
Z = ''.join(list(reversed(S)))
Z = Z.replace('resare', '')
Z = Z.replace('esare', '')
Z = Z.replace('remaerd', '')
Z = Z.replace('maerd', '')
z = len (Z)
if z == 0:
    print ('YES')
else:
    print ('NO')

Submission status: Accepted

Solution code:
s=input()

ans=0
while s!="":
    
    if s[-6:] =="eraser":
        s=s[:-6]
        
    elif s[-5:]=="dream":
        s=s[:-5]
        
    elif s[-7:]=="dreamer":
        s=s[:-7]
        
    elif s[-5:]=="erase":
        s=s[:-5]
        
    else:
        ans=1
        print("NO")
        break

if ans==0:
    print("YES")

Submission status: Accepted

Solution code:
# C 白昼夢

import re

s = input()

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

Submission status: Accepted

Solution code:
# C 白昼夢

s = input()[::-1]

cnt = 0
while cnt < len(s):
  if not s[cnt:cnt+7] == "remaerd":
    if not s[cnt:cnt+6] == "resare":
      if not s[cnt:cnt+5] in ["maerd", "esare"]:
        print("NO")
        exit()
      else:
        cnt += 5
    else:
      cnt += 6
  else:
    cnt += 7
print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

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

while len(S) > 0:
    if S[:5] == a[::-1] or S[:5] == c[::-1]:
        S = S[5:]
    elif S[:6] == d[::-1]:
        S = S[6:]
    elif S[:7] == b[::-1]:
        S = S[7:]
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

Solution code:

S=input()

N=len(S)
dp=[0]*(N+1)
dp[0]=1
L=["dream", "dreamer", "erase", "eraser"]
for i in range(1,N+1):
    for l in L:
        n=len(l)
        if 0<=i-n<N:
            if S[i-n:i]==l and dp[i-n]:
                dp[i]=1

if dp[-1]:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
 
kouho = ["dream", "dreamer", "erase", "eraser"]
 
s = s.replace(kouho[3], "").replace(kouho[2], "").replace(kouho[1], "").replace(kouho[0], "")
 
if s == "":
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
from collections import deque


S=input()

lenS=len(S)
T=deque()
for i in range(lenS):
    T.append(S[i])

#print(T)

A=len(T)

while A>7:
    if T[A-1]== "m" and T[A-2] =="a" and T[A-3] =="e" and T[A-4] =="r" and T[A-5] =="d":
        for i in range(5):
            T.pop()
    elif T[A-1]== "e" and T[A-2] =="s" and T[A-3] =="a" and T[A-4] =="r" and T[A-5] =="e":
        for i in range(5):
            T.pop()
            
    elif T[A-1]== "r" and T[A-2] =="e" and T[A-3] =="s" and T[A-4] =="a" and T[A-5] =="r" and T[A-6] =="e":
        for i in range(6):
            T.pop()
            
    elif T[A-1]== "r" and T[A-2] =="e" and T[A-3] =="m" and T[A-4] =="a" and T[A-5] =="e" and T[A-6] =="r" and T[A-7] =="d":
        for i in range(7):
            T.pop()
    else:
        print("NO")
        exit()
    
    A=len(T)

if A<=4:
    print("NO")
elif A==5 and T[A-1]== "m" and T[A-2] =="a" and T[A-3] =="e" and T[A-4] =="r" and T[A-5] =="d":
    print("YES")
elif A==5 and T[A-1]== "e" and T[A-2] =="s" and T[A-3] =="a" and T[A-4] =="r" and T[A-5] =="e":
    print("YES")
elif A==6 and  T[A-1]== "r" and T[A-2] =="e" and T[A-3] =="s" and T[A-4] =="a" and T[A-5] =="r" and T[A-6] =="e":
    print("YES")
elif A==7 and T[A-1]== "r" and T[A-2] =="e" and T[A-3] =="m" and T[A-4] =="a" and T[A-5] =="e" and T[A-6] =="r" and T[A-7] =="d":
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
'''
dp[i]はSのi文字目（1~Sの長さ)までを表せるかどうか
'''
dp = [0] * (len(S) + 1)
dp[0] = 1
check = "NO"

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

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

print(check)

Submission status: Accepted

Solution code:
s = str(input())


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


solve(s)

Submission status: Accepted

Solution code:
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	s = S().rstrip()
	while len(s) > 0:
		if s[-7:] == 'dreamer':
			s = s[:-7]
		elif s[-5:] == 'dream':
			s = s[:-5]
		elif s[-6:] == 'eraser':
			s = s[:-6]
		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()

S = S[::-1]

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

ind = 0
f = True

while True:
    if ind == len(S):
        f = True
        break
    if S[ind:ind+5] in check:
        ind += 5
    elif S[ind:ind+6] in check:
        ind += 6
    elif S[ind:ind+7] in check:
        ind += 7
    else:
        f = False
        break

if f:
    print('YES')
else:
    print("NO")

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

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

    if temp != 1:
        arr.append([temp, 1])

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

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

s = ''.join(reversed(list(input())))
n = len(s)
ind = 0
flag = True
while ind+4 < n:
    if ind+5 < n and s[ind:ind+6] == 'resare':
        ind+=6
    elif ind+6 < n and s[ind:ind+7] == 'remaerd':
        ind+=7
    elif s[ind:ind+5] == 'maerd' or s[ind:ind+5] == 'esare':
        ind+=5
    else:
        flag=False
        break
if ind == n and flag:
    print('YES')
else:
    print('NO')

Submission status: Accepted

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

cnt = 0
while cnt + 5 <= len(s):
    if s[cnt:cnt + 5] in d:
        cnt = cnt + 5
    elif cnt + 6 <= len(s) and s[cnt:cnt + 6] in d:
        cnt = cnt + 6
    elif cnt + 7 <= len(s) and s[cnt:cnt + 7] in d:
        cnt = cnt + 7
    else:
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

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

cnt = 0
while cnt < len(s):
    if s[cnt:cnt + 5] in d:
        cnt += 5
    elif s[cnt:cnt + 6] in d:
        cnt += 6
    elif s[cnt:cnt + 7] in d:
        cnt += 7
    else:
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

Solution code:
s = input()
s = s.replace("eraser", "")
s = s.replace("erase", "")
s = s.replace("dreamer", "")
s = s.replace("dream", "")

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

Submission status: Accepted

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

while True:
    for s in ss:
        if S.startswith(s):
            S = S[len(s):]
            break
    else:
        if S != '':
            print('NO')
            break

    if S == '':
        print('YES')
        break

Submission status: Accepted

Solution code:
import sys

s = input()
data = {"dream","dreamer","erase","eraser"}

while True:
    for i in data:
        if s.endswith(i):
            s = s[:-len(i)]
            break
    else:break

if s == "":
    print("YES")
    sys.exit()
else:
    print("NO")
    sys.exit()

Submission status: Accepted

Solution code:
S = list(input())
while True:
  if len(S) >= 8:
    if S[:8] == ["d", "r", "e", "a", "m", "e", "r", "a"]:
      del S[:5]
    elif S[:7] == ["d", "r", "e", "a", "m", "e", "r"]:
      del S[:7]
    elif S[:6] == ["e", "r", "a", "s", "e", "r"]:
      del S[:6]
    elif S[:5] == ["d", "r", "e", "a", "m"]:
      del S[:5]
    elif S[:5] == ["e", "r", "a", "s", "e"]:
      del S[:5]
    else:
      print("NO")
      break
  elif len(S) == 7:
    if S[:7] == ["d", "r", "e", "a", "m", "e", "r"]:
      del S[:7]
  elif len(S) == 6:
    if S[:6] == ["e", "r", "a", "s", "e", "r"]:
      del S[:6]
  elif len(S) == 5:
    if S[:5] == ["d", "r", "e", "a", "m"]:
      del S[:5]
    elif S[:5] == ["e", "r", "a", "s", "e"]:
      del S[:5]
  elif len(S) == 0:
    print("YES")
    break
  else:
    print("NO")
    break

Submission status: Accepted

Solution code:
a = ['dream','dreamer','erase','eraser']

a = [x[::-1] for x in a]

s = input()

s = s[::-1]
n = len(s)
i = 0
while i < n:
    if s[i] == 'm':
        if s[i:i+5] == 'maerd':
            i += 5
        else:
            print('NO')
            exit()
    elif s[i] == 'e':
        if s[i:i+5] == 'esare':
            i += 5
        else:
            print('NO')
            exit()
    elif s[i] == 'r':
        if s[i+2] == 'm':
            if s[i:i+7] == 'remaerd':
                i += 7
            else:
                print('NO')
                exit()
        elif s[i+2] == 's':
            if s[i:i+6] == "resare":
                i += 6
            else:
                print('NO')
                exit()
        else:
            print('NO')
            exit()
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    s=input()
    dp=[0]*(len(s)+1)
    dp[0]=1
    for i in range(5,len(s)+1):
        f=0
        if s[i-5:i]=="erase":
            dp[i]=dp[i]|dp[i-5]
        if s[i-5:i]=="dream":
            dp[i]=dp[i]|dp[i-5]
        if i>=6 and s[i-6:i]=="eraser":
            dp[i]=dp[i]|dp[i-6]
        if i>=7 and s[i-7:i]=="dreamer":
            dp[i]=dp[i]|dp[i-7]

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





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#
# Author: Tetsuya Ishikawa <tiskw111@gmail.com>
# Date  : June 30, 2020
##################################################### SOURCE START #####################################################

cs = ["dream", "dreamer", "erase", "eraser"]
S = input().strip()

while True:

    changed = False

    for c in cs:
        if S.endswith(c):
            S = S[:-len(c)]
            changed = True
            break
    
    if len(S) == 0:
        print("YES")
        break

    if not changed:
        print("NO")
        break

##################################################### SOURCE FINISH ####################################################
# vim: expandtab tabstop=4 shiftwidth=4 fdm=marker

Submission status: Accepted

Solution code:
import sys
cin = lambda: sys.stdin.readline().strip()
cout = sys.stdout.write

s = cin()

s = s.replace("eraser",'')
s = s.replace("erase",'')
s = s.replace("dreamer",'')
s = s.replace("dream",'')

if(s == ''):
	cout(f"YES"+'\n')
else:
	cout(f"NO"+'\n')