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
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

S=input()
N=len(S)
ans=True
i=N
while ans:
    if i==0:
        break
    elif i>=5 and S[i-5:i]=='dream':
        i-=5
    elif i>=7 and S[i-7:i]=='dreamer':
        i-=7
    elif i>=5 and S[i-5:i]=='erase':
        i-=5
    elif i>=6 and S[i-6:i]=='eraser':
        i-=6
    else:
        ans=False
judge(ans,['YES','NO'])

Submission status: Accepted

Solution code:
S=input()
N=len(S)
strings = ["maerd", "remaerd", "esare", "resare"]
tmp = ""
for i in range(N-1, -1, -1):
    if tmp not in strings:
        tmp += S[i]
        if tmp in strings:
            tmp = ""
if tmp:
    print("NO")
else:
    print("YES")

Submission status: Accepted

Solution code:

url = "https://atcoder.jp//contests/abc049/tasks/arc065_a"

def main():
    words = ['dream','dreamer', 'erase', 'eraser']
    s = input()
    rs = s[::-1]
    while rs != '':
        tmp = len(rs)
        for word in words:
            if len(word) > len(rs):
                continue
            rs = rs[0:len(word)].replace(word[::-1], '') + rs[len(word):]
        if tmp == len(rs):
            print('NO')
            exit()
    print('YES')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
n = len(s)

i = n
while i > 0:
    if i >= 7 and s[i-7:i] == 'dreamer':
        i -= 7
    elif i >= 5 and s[i-5:i] == 'dream':
        i -= 5
    elif i >= 6 and s[i-6:i] == 'eraser':
        i -= 6
    elif i >= 5 and s[i-5:i] == 'erase':
        i -= 5
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

S = S.replace("eraser", "")
S = S.replace("erase", "")
S = S.replace("dreamer", "")
S = S.replace("dream", "")

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

Submission status: Accepted

Solution code:
s = 'HAKUTYUMU' + input()
 
 
while s != 'HAKUTYUMU':
    next_s = s
 
    if s[-5:] == 'dream':
        next_s = s[:-5]
    if s[-7:] == 'dreamer':
        next_s = s[:-7]
    if s[-5:] == 'erase':
        next_s = s[:-5]
    if s[-6:] == 'eraser':
        next_s = s[:-6]
 
    if s == next_s:
        print('NO')
        exit()
 
    s = next_s
 
print('YES')

Submission status: Accepted

Solution code:
s = 'HAKUTYUMU' + input()


while s != 'HAKUTYUMU':
    next_s = s

    if s[-5:] == 'dream':
        next_s = s[:-5]
    if s[-7:] == 'dreamer':
        next_s = s[:-7]
    if s[-5:] == 'erase':
        next_s = s[:-5]
    if s[-6:] == 'eraser':
        next_s = s[:-6]

    if s == next_s:
        print('NO')
        exit()

    s = next_s

print('YES')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000)

s = 'HAKUTYUMU' + input()


while s != 'HAKUTYUMU':
    next_s = s

    if s[-5:] == 'dream':
        next_s = s[:-5]
    if s[-7:] == 'dreamer':
        next_s = s[:-7]
    if s[-5:] == 'erase':
        next_s = s[:-5]
    if s[-6:] == 'eraser':
        next_s = s[:-6]

    if s == next_s:
        print('NO')
        exit()

    s = next_s

print('YES')

Submission status: Accepted

Solution code:
s = input()
l = len(s)

idx = 0
ans = "NO"
dream = False
erase = False
while idx<l:
    if s[idx]=="d":
        if s[idx:(idx+5)] == "dream":
            idx += 5
            dream = True
            erase = False
        else:
            break
    elif s[idx] == "e":
        if s[idx+1] != "r":
            break
        else:
            if s[idx:(idx+5)] == "erase":
                idx += 5
                erase = True
                dream = False
            elif dream:
                idx += 2
                erase = False
                dream = False
            else:
                break
    elif s[idx]== "r":
        if erase:
            idx += 1
            erase = False
            dream = False
        else:
            break
    else:
        break

if idx == l:
    ans = "YES"

print(ans)

Submission status: Accepted

Solution code:
s=input()
t=""
i=len(s)
five=["dream","erase"]
flag=0
while s!=t:
  if i>=7 and s[i-7:i]=="dreamer":
    t=s[i-7:i]+t
    i-=7
  elif  i>=6 and s[i-6:i]=="eraser":
    t=s[i-6:i]+t
    i-=6
  elif i>=5 and (s[i-5:i] in five):
    t=s[i-5:i]+t
    i-=5
  else:
    flag=1
    break
if flag==0:
  print("YES")
else:
  print("NO")

Submission status: Accepted

Solution code:
def solve():
    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:
            return 'NO'
    return 'YES'

    
if __name__ == '__main__':
    ans = solve()
    print(ans)

Submission status: Accepted

Solution code:
#!/user/bin/env pypy3
import sys
from typing import List


def fast_input():
    return sys.stdin.readline()[:-1]


def print_format(b: bool) -> str:
    return "YES" if b else "NO"


def solve(s: str, tokens: List[str], dp_max: int) -> bool:
    dp = [False] * dp_max
    dp[0] = True

    for s_ind in range(len(s)):
        if not dp[s_ind]:
            continue
        for token in tokens:
            if s[s_ind:s_ind + len(token)] == token:
                dp[s_ind + len(token)] = True
    return dp[len(s)]


def main():
    tokens = ["dream", "erase", "eraser", "dreamer"]
    s = fast_input()
    result = solve(s=s, tokens=tokens, dp_max=len(s) + 6)
    print(print_format(result))


main()

Submission status: Accepted

Solution code:
#!/user/bin/env pypy3
import sys
from typing import List


def fast_input():
    return sys.stdin.readline()[:-1]


def print_format(b: bool) -> str:
    return "YES" if b else "NO"


def solve(s: str, tokens: List[str], s_max: int) -> bool:
    dp = [False] * s_max
    dp[0] = True

    for s_ind in range(len(s)):
        if not dp[s_ind]:
            continue
        for token in tokens:
            if s[s_ind:s_ind + len(token)] == token:
                dp[s_ind + len(token)] = True
    return dp[len(s)]


def main():
    tokens = ["dream", "erase", "eraser", "dreamer"]
    s = fast_input()
    result = solve(s=s, tokens=tokens, s_max=len(s) + 6)
    print(print_format(result))


main()

Submission status: Accepted

Solution code:
#!/user/bin/env pypy3
import itertools
import sys


def fast_input():
    return sys.stdin.readline()[:-1]


def print_format(b: bool) -> str:
    return "YES" if b else "NO"


def solve(s: str) -> bool:
    for p in itertools.permutations(["dreamer", "eraser", "dream", "erase"]):
        work = s
        for token in p:
            work = work.replace(token, '')
        if work == "":
            return True
    return False


def main():
    result = solve(fast_input())
    print(print_format(result))


main()

Submission status: Accepted

Solution code:
S = input()
dp = [False] * (len(S) + 1)
dp[0] = True
for i in range(len(S)+1):
    if i >= 5 and dp[i-5] and S[i-5:i] == 'erase':
        dp[i] = True
    if i >= 6 and dp[i-6] and S[i-6:i] == 'eraser':
        dp[i] = True
    if i >= 5 and dp[i-5] and S[i-5:i] == 'dream':
        dp[i] = True
    if i >= 7 and dp[i-7] and S[i-7:i] == 'dreamer':
        dp[i] = True
print('YES' if dp[len(S)] else 'NO')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input_str = input()
process_flag = 'process'
ans_flag = 'NO'
d_e = ''
ans_list = []

def pre_str_process(now_str):
  ans_list.append(now_str[:5])
  now_str = now_str[5:]
  return now_str

def dream(now_str):
  now_str = pre_str_process(now_str)
  if (now_str == '') or (now_str == 'er'):
    return now_str, 'OK'
  if now_str[:5] == 'dream':
    return now_str, 'dream'
  if now_str[:2] == 'er':
    if now_str[:5] == 'erase':
      return now_str, 'erase'
    if now_str[:7] == 'ererase':
      now_str = now_str[2:]
      return now_str, 'erase'
    if now_str[:7] == 'erdream':
      now_str = now_str[2:]
      return now_str, 'dream'
    else:
      return now_str, 'NG'

  else:
    return now_str, 'NG'

def erase(now_str):
  now_str = pre_str_process(now_str)
  if (now_str == '') or (now_str == 'r'):
    return now_str, 'OK'
  if now_str[0] == 'r':
    now_str = now_str[1:]
    if now_str[:5] == 'dream':
      return now_str, 'dream'
    if now_str[:5] == 'erase':
      return now_str, 'erase'
    else:
      return now_str, 'NG'
  if now_str[:5] == 'erase':
    return now_str, 'erase'
  if now_str[:5] == 'dream':
    return now_str, 'dream'
  else:
    return now_str, 'NG'

first_str = input_str[:5]
process_num = 0
while process_flag == 'process':
  process_num += 1
  if process_num == 1:
    if first_str == 'dream':
      now_str = input_str
      d_e = 'dream'
    elif first_str == 'erase':
      now_str = input_str
      d_e = 'erase'
    else:
      break
  elif d_e == 'dream':
    now_str, d_e = dream(now_str)
  elif d_e == 'erase':
    now_str, d_e = erase(now_str)
  elif d_e == 'OK':
    ans_flag = 'YES'
    break
  elif d_e == 'NG':
    break
print(ans_flag)

Submission status: Accepted

Solution code:
s = input()
i = 0
while True:
    if s == "":
        print("YES")
        exit(0)
    if i == 0:
        if s[:5] == "dream":
            s = s[5:]
            i = 1
        elif s[:5] == "erase":
            s = s[5:]
            i = 2
        else:
            break
    elif i == 1:
        if s[:5] == "dream":
            s = s[5:]
            i = 1
        elif s[:2] == "er":
            s = s[2:]
            i = 3
        else:
            break
    elif i == 2:
        if s[:5] == "dream":
            s = s[5:]
            i = 1
        elif s[:5] == "erase":
            s = s[5:]
            i = 2
        elif s[:1] == "r":
            s = s[1:]
            i = 0
        else:
            break
    elif i == 3:
        if s[:5] == "dream":
            s = s[5:]
            i = 1
        elif s[:3] == "ase":
            s = s[3:]
            i = 2
        elif s[:5] == "erase":
            s = s[5:]
            i = 2
        else:
            break
print("NO")

Submission status: Accepted

Solution code:
s = input()
S = ''.join(list(reversed(s)))
N = len(S)

i = 0
while True:
    l = N - i
    if l>=5 and (S[i:i+5]=='maerd' or S[i:i+5]=='esare'):
        i += 5
    elif l>=6 and S[i:i+6]=='resare':
        i += 6
    elif l>=7 and S[i:i+7]=='remaerd':
        i += 7
    else:
        print("NO")
        exit()
    if i == N:
        print('YES')
        exit()

Submission status: Accepted

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

judge()

Submission status: Accepted

Solution code:
S = input()
T = ['dream','dreamer','erase','eraser']
while len(S) != 0:
    for t in T:
        if S.endswith(t):
            S = S[:len(S)-len(t)]
            break
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
# vim: fileencoding=utf-8


def main():
    s = input()
    c = ["dreamer", "dream", "erase", "eraser"]
    n = [7, 5, 5, 6]
    while True:
        f = True
        for i in range(4):
            if s[-n[i] :] == c[i]:
                f = False
                s = s[: -n[i]]
                break
        if f:
            if len(s) == 0:
                print("YES")
            else:
                print("NO")
            return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# vim: fileencoding=utf-8


def main():
    s = list(input())
    c = ["dreamer", "dream", "erase", "eraser"]
    n = [7, 5, 5, 6]
    while True:
        f = True
        for i in range(4):
            if "".join(s[-n[i] :]) == c[i]:
                f = False
                s = s[: -n[i]]
                break
        if f:
            if len(s) == 0:
                print("YES")
            else:
                print("NO")
            return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
while True:
    l = len(S)
    if l == 0:
        print('YES'); break
    if l-5 >= 0 and S[l-5:] == 'dream':
        S = S[:l-5]; continue
    if l-7 >= 0 and S[l-7:] == 'dreamer':
        S = S[:l-7]; continue
    if l-5 >= 0 and S[l-5:] == 'erase':
        S = S[:l-5]; continue
    if l-6 >= 0 and S[l-6:] == 'eraser':
        S = S[:l-6]; continue
    print('NO')
    break

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

words = ['dream', 'dreamer', 'erase', 'eraser']
ans = 'YES'

pointer = len(s)
while pointer > 0:
    if s[pointer-5: pointer] == list(words[0]):
        pointer -= 5
    elif s[pointer-5: pointer] == list(words[2]):
        pointer -= 5
    elif s[pointer-7: pointer] == list(words[1]):
        pointer -= 7
    elif s[pointer-6: pointer] == list(words[3]):
        pointer -= 6
    else:
        ans = 'NO'
        break

print(ans)

Submission status: Accepted

Solution code:
S = input()

while 1:
    for target in ["dream", "dreamer", "erase", "eraser"]:
        if S.endswith(target):
            S = S[:-len(target)]
            break
    else:
        print("NO")
        break
    if len(S) == 0:
        print("YES")
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re;print(re.match('(dream|dreamer|erase|eraser)*$',input())and'YES'or'NO')

Submission status: Accepted

Solution code:
S=input()
L=len(S)
X=('dream','dreamer','erase','eraser')
while L>0:
    f=1
    for x in X:
        if S[:L].endswith(x):
            L-=len(x)
            f=0
    if f:
        break
print(['NO','YES'][L==0])

Submission status: Accepted

Solution code:
S = input()

T = ""

while True:
    T_len = len(T)
    for word in ["dream", "dreamer", "erase", "eraser"]:
        if word + T == S[-1 * len(word + T):]:
            T = word + T
            if T == S:
                print("YES")
                exit()
    if T_len == len(T):
        print("NO")
        exit()

Submission status: Accepted

Solution code:
a,b,c,d=[i[::-1] for i in ['dream','dreamer','erase','eraser']]
s,j=input()[::-1],True
while j:
  j=False
  for i in [a,b,c,d]:
    if s.startswith(i): s=s[len(i):];j=True
print('YNEOS'[len(s)>0::2])

Submission status: Accepted

Solution code:
s = str(input())
z = 'YES'
while len(s) != 0:
    if s[:11] == 'dreameraser':
        s = s[11:]
    elif s[:10] == 'dreamerase':
        s = s[10:]
    elif s[:13] == 'dreamereraser':
        s = s[13:]
    elif s[:12] == 'dreamererase':
        s = s[12:]
    elif 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:
        z = 'NO'
        break
print(z)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def main():
    s = input()
    l = len(s)
    while s:
        if 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:
            print("NO")
            return
    print("YES")



if __name__ == "__main__":
    main()

Submission status: Accepted

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

def f(x):
    print(x)
    exit()

if N < 5:
    f("NO")
elif S[0] == "d":
    w = 1
elif S[0] == "e":
    w = -1
else:
    f("NO")

i = 0
while True:
    if w > 0:
        if S[i]+S[i+1]+S[i+2]+S[i+3]+S[i+4] == "dream":
            i += 5
            if i == N:
                f("YES")
            elif S[i] == "d":
                pass
            elif S[i] == "e":
                if i+1 <= N-1:
                    if S[i+1] == "r":
                        if i+1 == N-1:
                            f("YES")
                        elif S[i+2] == "a":
                            w *= -1
                        elif S[i+2] == "e":
                            i += 2
                            w *= -1
                        elif S[i+2] == "d":
                            i += 2
                        else:
                            f("NO")
                    else:
                        f("NO")
                else:
                    f("NO")
            else:
                f("NO")
        else:
            f("NO")
    elif w < 0:
        if S[i]+S[i+1]+S[i+2]+S[i+3]+S[i+4] == "erase":
            i += 5
            if i == N:
                f("YES")
            if S[i] == "r":
                i += 1
                if i == N:
                    f("YES")
            if S[i] == "d":
                w *= -1
            elif S[i] == "e":
                pass
            else:
                f("NO")
        else:
            f("NO")
    if i+4 > N-1:
        f("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
s = input()
i = 0
while i < len(s):
    if s[i] == 'd':
        S = s[i:i + 5]
        if i + 6 < len(s):
            if S + s[i + 5] + s[i + 6] == "dreamer":
                i += 7
                if i + 3 < len(s):
                    if s[i:i + 4] == "aser":
                        i += 4
                        continue
                if i + 2 < len(s):
                    if s[i:i + 3] == "ase":
                        i += 3
                        continue
                continue
        if S == "dream":
            i += 5
            continue
        break
    elif s[i] == 'e':
        S = s[i:i + 5]
        if i + 5 < len(s):
            if S + s[i + 5] == "eraser":
                i += 6
                continue
        if S == "erase":
            i += 5
            continue
        break
    else:
        break
    if i + 4 >= len(s):
        break
else:
    print("YES")
    exit()
print("NO")

Submission status: Accepted

Solution code:
txtd = ["dreameraser",
        "dreamerase",
        "dreamer",
        "dream"]
txtd_n = [len(a) for a in txtd]
txtd_l = len(txtd)
txte = ["eraser",
        "erase"]
txte_n = [len(a) for a in txte]
txte_l = len(txte)
        
S = input()
len_idx = len(S)
i = 0
able = True
while i < len_idx:
  old_i = i
  remain = len_idx - i
  
  if S[i] == "d":
    for j in range(txtd_l):
      if remain >= txtd_n[j]:
        if S[i:i+txtd_n[j]] == txtd[j]:
          i += txtd_n[j]
          break
  elif S[i] == "e":
    for j in range(txte_l):
      if remain >= txte_n[j]:
        if S[i:i+txte_n[j]] == txte[j]:
          i += txte_n[j]
          break

  if old_i == i:
    able = False
    break

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

Submission status: Accepted

Solution code:
S = input()

dm, dr, ee, er = 'dream', 'dreamer', 'erase', 'eraser'

word = [dm[::-1], dr[::-1], ee[::-1], er[::-1], ]

s = S[::-1]

while s:
    for i in range(4):
        if s.startswith(word[i]):
            s = s[len(word[i]):]
            break
    else:
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

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

for i in range(100000):
    if s[:5] == 'maerd':
        s = s[5:]
    if s[:5] == 'esare':
        s = s[5:]
    if s[:6] == 'resare':
        s = s[6:]
    if s[:7] == 'remaerd':
        s = s[7:]

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

Submission status: Accepted

Solution code:
s=input()
s_re = s[::-1]
list =  ["dream","dreamer","erase", "eraser"]
list_re = [ i[::-1] for i in list]

count=True
while count:
    value=0
    for i in list_re:
        if s_re[:len(i)] == i:
            s_re = s_re[len(i):]
            value=0
        else:
            value+=1
    if value>3:
        count=False

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

Submission status: Accepted

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

while S:
    for candidate in candidates:
        if S.endswith(candidate):
            S = S[:-len(candidate)]
            break
    else:
        break

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

Submission status: Accepted

Solution code:
S=input()
while len(S)>=5:
    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()

ans = True
while s != "":
    words = ["eraser", "dream", "erase", "dreamer"]

    found = False
    for word in words:
        if s[-len(word):] == word:
            s = s[:-len(word)]
            found = True
            break

    if not found:
        ans = False
        break

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

Submission status: Accepted

Solution code:
S = input()

# 後ろから削除したいので、反転して前から削除する
S = S[::-1] 
words = {'maerd', 'remaerd', 'esare', 'resare'}

while len(S) > 0:
  orig = S
  for w in words:
    if S.startswith(w):
      S = S[len(w):]
      break
  if orig == S:
    break

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

Submission status: Accepted

Solution code:
S = input()
 
# 前から順に消すと詰む
# 後ろから順に消すと一意に定まる
while True:
  if S[-5:] == 'erase': S = S[:-5]
  else:
    if S[-6:] == 'eraser': S = S[:-6]
    else:
      if S[-5:] == 'dream': S = S[:-5]
      else:
        if S[-7:] == 'dreamer': S = S[:-7]
        else: break

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
s = input()

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

def check():
    tmp = s
    while(True):
      current_len = len(tmp)
      for w in words:
        if tmp.endswith(w):
          tmp = tmp[:-len(w)]
      if len(tmp) == 0:
          return "YES"

      if current_len == len(tmp):
          return "NO"

print(check())

Submission status: Accepted

Solution code:
s = input()

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from re import *
if match("^(dream|dreamer|erase|eraser)+$", input()):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
A = input()
A = A[::-1]
divide = [i[::-1] for i  in ["dream", "dreamer", "erase", "eraser"]]

flag = 1
while flag and A:
  flag = 0
  for word in divide:
    if A.startswith(word):
      A = A[len(word):]
      flag = 1

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

Submission status: Accepted

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

while len(S) > 0:
  for t in text:
    if S.find(t) == 0:
      S = S[len(t):]
      break
  else:
    print('NO')
    break
else:
  print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
r = ''.join(list(reversed(s)))
flag = [0,0,0,0]
t = ['maerd', 'remaerd', 'esare', 'resare']
while len(r) >= 0:
    if r[0:5] == t[0]:
        r = r[5:]
        flag[0] +=1
    elif r[0:7] == t[1]:
        r = r[7:]
        flag[1] +=1
    elif r[0:5] == t[2]:
        r = r[5:]
        flag[2] +=1
    elif r[0:6] == t[3]:
        r = r[6:]
        flag[3] +=1
    elif len(r) == 0:
        print('YES')
        break
    else:
        print('NO')
        break
# print(flag)

Submission status: Accepted

Solution code:
S = list(input())
S.reverse()
S = ''.join(S)
st = ['maerd','remaerd','esare','resare']
ans = 'YES'
while S != '':
    if S[0:5] in st:
        S = S[5:]
    elif S[0:6] in st:
        S = S[6:]
    elif S[0:7] in st:
        S = S[7:]
    else:
        ans = 'NO'
        break
print(ans)

Submission status: Accepted

Solution code:
s = list(input())

a = list("dream")
b = list("dreamer")
c = list("erase")
d = list("eraser")
flag = 0

while(flag == 0):
    if s[-7:] == b:
        del s[-7:]
    elif s[-6:] == d:
        del s[-6:]
    elif s[-5:] == a or s[-5:] == c:
        del s[-5:]
    elif s == []:
        print("YES")
        flag = 1
    else:
        print("NO")
        flag = 1

Submission status: Accepted

Solution code:
s=input()
p=True
t=""
l=s
while p==True:
    p=False
    f=l[0:8]
    if f=="dreamera":
        t +="dream"
        l=l[5:]
        p=True
    f=l[0:7]
    if p==False and f=="dreamer":
        t += "dreamer"
        l=l[7:]
        p=True
    f=l[0:6]
    if p==False and f=="eraser":
        t+="eraser"
        l=l[6:]
        p=True
    f=l[0:5]
    if p==False and f=="erase":
        t+="erase"
        l=l[5:]
        p=True
    if p==False and f=="dream":
        t+="dream"
        l=l[5:]
        p=True
if s==t:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# dfs
import sys
sys.setrecursionlimit(10**6)

C = ['dream', 'dreamer', 'erase', 'eraser']
S = input()
L = len(S)

def dfs(l):
    if l == L:
        return True
    elif l > L:
        return False

    for c in C:
        if S.find(c, l, l+7) == l:
            if dfs(l+len(c)):
                return True
    return False

print('YES' if dfs(0) else 'NO')

Submission status: Accepted

Solution code:
# dfs
import sys
sys.setrecursionlimit(10**6)

C = ['dream', 'dreamer', 'erase', 'eraser']
S = input()
L = len(S)


def dfs(x, l):
    if l == L:
        return True
    elif l > L:
        return False

    match = S[l:l+7]
    for c in C:
        if match.find(c) == 0:
            if dfs(c, l+len(c)):
                return True
    return False


print('YES' if dfs('', 0) else 'NO')

Submission status: Accepted

Solution code:
words = ['dream','dreamer', 'erase', 'eraser']
s = raw_input()
dp = [False for _ in range(len(s))]

for j in range(len(s)):
	for w in words:
		b = dp[j - len(w)] if j - len(w) -1 >= 0 else True
		b &= j-len(w) +1 >= 0 and s[j- len(w)+1:j+1] == w
		if b:
			dp[j] = True
			break
print 'YES' if dp[-1] else 'NO'

Submission status: Accepted

Solution code:
import re
                                      
S = input()
S = re.sub("eraser", "", S)
S = re.sub("erase", "", S)
S = re.sub("dreamer", "", S)
S = re.sub("dream", "", S)
print("YES" if len(S) == 0 else "NO")