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: Time Limit Exceeded

Solution code:
S = input()

flag = 0

words = ("dream","erase","dreamer","eraser")
count = 0

while len(S) >= 5:
    
    for i in words:
        N = len(i)

        if S[-N:] in words:
            n = len(S) - N
            S = S[:n]

            flag = 1
            break
        else:
            continue
 
    if flag == 0:
        break

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

Submission status: Time Limit Exceeded

Solution code:
import sys

S = input()

while len(S) > 0:
    if len(S) < 5:
        print('NO')
        sys.exit(0)
    third = S[-3]
    if third == 'e':
        if len(S) < 5 or S[-5:] != 'dream':
            print('NO')
            sys.exit(0)
        S = S[:-5]
    if third == 'a':
        if len(S) < 5 or S[-5:] != 'erase':
            print('NO')
            sys.exit(0)
        S = S[:-5]
    if third == 'm':
        if len(S) < 7 or S[-7:] != 'dreamer':
            print('NO')
            sys.exit(0)
        S = S[:-7]
    if third == 's':
        if len(S) < 6 or S[-6:] != 'eraser':
            print('NO')
            sys.exit(0)
        S = S[:-6]

print('YES')

Submission status: Time Limit Exceeded

Solution code:
import sys

S = input()

while True:
    if S == '':
        print('YES')
        sys.exit(0)
    if len(S) < 5:
        print('NO')
        sys.exit(0)
    third = S[-3]
    if third == 'e':
        if len(S) < 5 or S[-5:] != 'dream':
            print('NO')
            sys.exit(0)
        S = S[:-5]
    if third == 'a':
        if len(S) < 5 or S[-5:] != 'erase':
            print('NO')
            sys.exit(0)
        S = S[:-5]
    if third == 'm':
        if len(S) < 7 or S[-7:] != 'dreamer':
            print('NO')
            sys.exit(0)
        S = S[:-7]
    if third == 's':
        if len(S) < 6 or S[-6:] != 'eraser':
            print('NO')
            sys.exit(0)
        S = S[:-6]

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import sys
sys.setrecursionlimit(10**6)
def S(): return stdin.readline().rstrip()
a = S()
def f(t,a,l):
    if t == a:
        return True
    else:
        for i in l:
            if t+i in a[:len(t+i)]:
                if f(t+i,a,l):
                    return True
        return False

strl = ['dream','dreamer','erase','eraser']
if f('',a,strl):
    print('YES')
else:
    print('NO')

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import sys
sys.setrecursionlimit(10**6)
def S(): return stdin.readline().rstrip()

a = S()
def f(t,a):
    if t == a:
        return True
    elif len(a)<len(t):
        return False
    else:
        strl = ['dream','dreamer','erase','eraser']
        for i in strl:
            if t+i in a[:len(t+i)]:
                if f(t+i,a):
                    return True
        return False

if f('',a):
    print('YES')
else:
    print('NO')

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import sys
sys.setrecursionlimit(10**6)
def S(): return stdin.readline().rstrip()

a = S()
def f(t,a):
    if t == a:
        return True
    elif len(a)<len(t):
        return False
    else:
        strl = {0:'dream',1:'dreamer',2:'erase',3:'eraser'}
        for i in range(4):
            tmp = strl[i]
            if t+tmp in a[:len(t+tmp)]:
                if f(t+tmp,a):
                    return True
        return False

if f('',a):
    print('YES')
else:
    print('NO')

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())[::-1]
word = ["dream", "dreamer", "erase", "eraser"]
while True:
    if "".join(s[:5][::-1]) in word:
        del s[:5]
        continue
    elif "".join(s[:6][::-1]) == "eraser":
        del s[:6]
        continue
    elif "".join(s[:7][::-1]) == "dreamer":
        del s[:7]
        continue
    break
if len(s) == 0:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:

s = input()

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

while len(s) > 0:
    for word in words:
        s = s[::-1]
        word = word[::-1]
        flg = False

        if s.startswith(word):
            s = s.replace(word, '', 1)
            s = s[::-1]
            flg = True
            break

        s = s[::-1]

    if not flg:
        break

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

Submission status: Time Limit Exceeded

Solution code:
import re

def main():
    s = list(input())
    sr = ''.join(list(reversed(s)))
    t = ['dream', 'dreamer', 'erase', 'eraser']
    tr = list()
    for i in t:
        tr.append(''.join(list(reversed(i))))
    flag = False
    while True:
        for i in tr:
            sr_split = re.split('^' + i, sr ,1)
            if len(sr_split) == 2:
                flag = True
                sr = sr_split[1]
                break
        if not flag:
            print('NO')
            break
        if sr == '':
            print('YES')
            break
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import re

def main():
    s = list(input())
    sr = ''.join(list(reversed(s)))
#    print(sr)
    t = ['dream', 'dreamer', 'erase', 'eraser']
    tr = list()
    for i in t:
        tr.append(''.join(list(reversed(i))))
    flag = False
    while True:
        for i in tr:
            sr_split = re.split('^' + i, sr ,1)
#            print(sr_split)
            if len(sr_split) == 2:
                flag = True
                sr = sr_split[1]
#                print(sr)
        if not flag:
            print('NO')
            break
        if sr == '':
            print('YES')
            break
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

s = sinput()[::-1]
n = len(s)

a = "dream"[::-1]
b = "dreamer"[::-1]
c = "erase"[::-1]
d = "eraser"[::-1]

ss = ""
for i in range(n+1):
    for j in range(i+1,n+1):
        if s[i:j] in [a,b,c,d]: ss += s[i:j]; s = s[:i] + s[j:]

flag = len(ss) == n
ans = "YES" if flag else "NO"
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import re
s = input()

while(True):
    l = len(s)
    s = re.sub('(dream($|er$))|(erase($|r$))','',s)
    if len(s) == l:
        if len(s)==0:
            print('YES')
        else:
            print('NO')
        exit()

Submission status: Time Limit Exceeded

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

while len(s) >= 5:
    if s[:5] == list("maerd"):
        del s[:5]
        continue
    if s[:7] == list("remaerd"):
        del s[:7]
        continue
    if s[:5] == list("esare"):
        del s[:5]
        continue
    if s[:6] == list("resare"):
        del s[:6]
        continue
    break

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

Submission status: Time Limit Exceeded

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

while len(s):
    if s[:5] == list("maerd"):
        del s[:5]
        continue
    if s[:7] == list("remaerd"):
        del s[:7]
        continue
    if s[:5] == list("esare"):
        del s[:5]
        continue
    if s[:6] == list("resare"):
        del s[:6]
        continue
    break

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

Submission status: Time Limit Exceeded

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

while s:
    if s[:5] == list("maerd"):
        del s[:5]
        continue
    if s[:7] == list("remaerd"):
        del s[:7]
        continue
    if s[:5] == list("esare"):
        del s[:5]
        continue
    if s[:6] == list("resare"):
        del s[:6]
        continue
    break

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

Submission status: Time Limit Exceeded

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

while s:
    if s[:5] == list("maerd"):
        del s[:5]
        continue
    elif s[:7] == list("remaerd"):
        del s[:7]
        continue
    elif s[:5] == list("esare"):
        del s[:5]
        continue
    elif s[:6] == list("resare"):
        del s[:6]
        continue
    else:
        break

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
S.reverse()
def check(s):
    if s[:5] == list("maerd"):
        del s[:5]
        return True
    elif s[:7] == list("remaerd"):
        del s[:7]
        return True
    elif s[:5] == list("esare"):
        del s[:5]
        return True
    elif s[:6] == list("resare"):
        del s[:6]
        return True
    else:
        return False

while check(S):
    c = 0

if S == []:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
S.reverse()
def check(s):
    if s[:5] == ["m","a","e","r","d"]:
        del s[:5]
        return True
    elif s[:7] == ["r","e","m","a","e","r","d"]:
        del s[:7]
        return True
    elif s[:5] == ["e","s","a","r","e"]:
        del s[:5]
        return True
    elif s[:6] == ["r","e","s","a","r","e"]:
        del s[:6]
        return True
    else:
        return False

while check(S):
    c = 0

if S == []:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
s = input()

length = len(s)
t = ''
word = ''

for a in range(length-1, -1, -1):
    t += s[a]
    reverse_t = t[::-1]
    if reverse_t == 'dream' or reverse_t == 'dreamer' or reverse_t == 'erase' or reverse_t == 'eraser':
        word = reverse_t + word
        t = ''

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

Submission status: Time Limit Exceeded

Solution code:
target = input()

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

Submission status: Time Limit Exceeded

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

for i in range(len(s)//5):
    s = re.sub("^remaerd", "", s)
    s = re.sub("^maerd", "", s)
    s = re.sub("^resare", "", s)
    s = re.sub("^esare", "", s)

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

Submission status: Time Limit Exceeded

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

for i in range(len(s)):
    s = re.sub("^remaerd", "", s)
    s = re.sub("^maerd", "", s)
    s = re.sub("^resare", "", s)
    s = re.sub("^esare", "", s)

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

Submission status: Time Limit Exceeded

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 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: Time Limit Exceeded

Solution code:
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=input()
n=len(s)
i=0

while i<n-1:
    if n-i>=11:
        if s[i:i+11]=="dreameraser":
            i+=11
    elif n-i>=10:
        if s[i:i+10]=="dreamerase":
            i+=10
    elif n-i>=7:
        if s[i:i+7]=="dreamer":
            i+=7
    elif n-i>=6:
        if s[i:i+6]=="eraser":
            i+=6
    elif n-i>=5:
        if s[i:i+5]=="dream" or s[i:i+5]=="erase":
            i+=5
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()
print("YES")

Submission status: Time Limit Exceeded

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 t=="":
        ans = "YES"
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
while 1:
    for key_word in ["erase", "eraser", "dream", "dreamer"]:
        if S.endswith(key_word):
            S = S[:-len(key_word)]
            break
        else:
            print("NO")
            break
        if not query:
            print("YES")
            break

Submission status: Time Limit Exceeded

Solution code:
words = ['dream', 'dreamer', 'erase', 'eraser']
S = input()
T = []
for a in S[::-1]:
  T += a
  for s in words:
    if ''.join(T)[::-1] == s:
      T = []
print('YES' if T == [] else 'NO')

Submission status: Time Limit Exceeded

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

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

print(yn)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    S=input()
    n=len(S)
    A="dream dreamer erase eraser".split()
    F=A[:]
    for a in A:
        for b in A:
            F.append(a+b)
    
    #print(F)
    #print(A)
    global cond
    cond=[]
    def dfslike_dreameraser(varS):#string->bool,resursion
        #print(varS)
        if len(varS)==0:
            cond.append(1)
            return 
        for word in reversed(F):
            if varS[:len(word)]==word:
                dfslike_dreameraser(varS[len(word):])
        return 
        
    dfslike_dreameraser(S)
    #print(cond)
    print(["NO","YES"][cond!=[]])
#%%submit!
resolve()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    S=input()
    n=len(S)
    A="dream dreamer erase eraser".split()
    F=A[:]
    for a in A:
        for b in A:
            F.append(a+b)
    #print(F)
    #print(A)
    global cond
    cond=[]
    def dfslike_dreameraser(varS):#string->bool,resursion
        #print(varS)
        if len(varS)==0:
            cond.append(1)
            return 
        for word in F:
            if varS[:len(word)]==word:
                dfslike_dreameraser(varS[len(word):])
        return 
        
    dfslike_dreameraser(S)
    #print(cond)
    print(["NO","YES"][cond!=[]])
#%%submit!
resolve()

Submission status: Time Limit Exceeded

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

S = input()
arr = ["dream", "dreamer", "erase", "eraser"]

def func(T):
  if len(T) > len(S): return False
  if T != S[:len(T)]: return False

  res = T == S
  if not res:
    for t in arr: res |= func(T+t)
  return res

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    S = input()
    strings = ["dream", "dreamer", "erase", "eraser"]
    import collections
    deq = collections.deque(["dream", "dreamer", "erase", "eraser"])

    while deq:
        s = deq.pop()
        if s == S:
            print("YES")
            return
        if len(s) < len(S):
            for item in strings:
                deq.append(s+item)
    print("NO")




if '__main__' == __name__:
    resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
S = input()
n=0
flg=0
#print(s[0:K-1]+s[K-1].lower()+s[K:N])
while(not S==""):

#    if  S[n:].startswith("dreameraser"):
#        n=n+11
        #print(S[n:])
        #flg==1
#        continue
    if S.endswith("dreamer"):
        #n=n+6
        S=S[::-1]
        S=S.replace("dreamer","",1)
        S=S[::-1]
        #print(S[n:])
        continue
    elif S.endswith("dream"):
        #n=n+5
        S=S[::-1]
        S=S.replace("dream","",1)
        S=S[::-1]
        #print(S)
        #flg==1
        continue
    elif S.endswith("eraser"):
        #n=n+6
        S=S[::-1]
        S=S.replace("eraser","",1)
        S=S[::-1]
        #print(S[n:])
        continue
    elif S.endswith("erase"):
        #n=n+5
        S=S[::-1]
        S=S.replace("erase","",1)
        S=S[::-1]
        #print(S)
        #flg==1
        continue
    print("NO")
    exit()

print("YES")

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

def main():
    # 入力
    st = input()

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

    d_count = st.count("d")
    era_count = st.count("era")

    d_idx_ls = []
    era_idx_ls = []

    tmp_idx = 0
    for i in range(d_count):
        idx = st.index("d", tmp_idx)
        tmp_idx = idx
        d_idx_ls.append(idx)

    tmp_idx = 0
    for i in range(era_count):
        idx = st.index("era", tmp_idx)
        tmp_idx = idx
        era_idx_ls.append(idx)

    if d_count == 0 and era_count == 0:
        print("NO")
        return
    elif era_count == 0:
        pre_tmp_st_list = [""]
        for i in range(d_count):
            tmp_st_list = []
            for x in pre_tmp_st_list:
                tmp_st_list.append(x + "dream")
                tmp_st_list.append(x + "dreamer")
            pre_tmp_st_list = tmp_st_list

        for x in pre_tmp_st_list:
            if x == st:
                print("YES")
                return
        print("NO")
        return
    elif d_count == 0:
        pre_tmp_st_list = [""]
        for i in range(era_count):
            tmp_st_list = []
            for x in pre_tmp_st_list:
                tmp_st_list.append(x + "erase")
                tmp_st_list.append(x + "eraser")
            pre_tmp_st_list = tmp_st_list

        for x in pre_tmp_st_list:
            if x == st:
                print("YES")
                return
        print("NO")
        return
    else:
        # 2^(d_count + era_count)の候補を作成して確認
        tmp_ls_idx_d = 0
        tmp_ls_idx_era = 0
        pre_tmp_st_list = [""]
        while tmp_ls_idx_d < d_count or tmp_ls_idx_era < era_count:
            tmp_st_list = []
            # 次に追加するのがd
            if tmp_ls_idx_era == era_count:
                for x in pre_tmp_st_list:
                    tmp_st_list.append(x + "dream")
                    tmp_st_list.append(x + "dreamer")
                pre_tmp_st_list = tmp_st_list
                tmp_ls_idx_d += 1
            # 次に追加するのがera
            elif tmp_ls_idx_d == d_count:
                for x in pre_tmp_st_list:
                    tmp_st_list.append(x + "erase")
                    tmp_st_list.append(x + "eraser")
                pre_tmp_st_list = tmp_st_list
                tmp_ls_idx_era += 1
            # 次に追加するのがd
            elif d_idx_ls[tmp_ls_idx_d] < era_idx_ls[tmp_ls_idx_era]:
                for x in pre_tmp_st_list:
                    tmp_st_list.append(x + "dream")
                    tmp_st_list.append(x + "dreamer")
                pre_tmp_st_list = tmp_st_list
                tmp_ls_idx_d += 1
            # 次に追加するのがera
            else:
                for x in pre_tmp_st_list:
                    tmp_st_list.append(x + "erase")
                    tmp_st_list.append(x + "eraser")
                pre_tmp_st_list = tmp_st_list
                tmp_ls_idx_era += 1

        for x in pre_tmp_st_list:
            if x == st:
                print("YES")
                return
        print("NO")


main()

Submission status: Time Limit Exceeded

Solution code:
t=input()
s=''
trigger=1
app=['dream','dreamer','erase','eraser']
while len(s)<len(t) and trigger:
    for i in range(4):
        key=app[i]
        if s+key == t[:len(s)+len(key)]:
            s+=key
            break
        trigger==0
if s==t:
    print('YES')
else:
    print('NO')

Submission status: Time Limit Exceeded

Solution code:
import sys
S = input()
N = len(S)
words = ['dream', 'dreamer', 'erase', 'eraser']
i = 0
while i != N:
    flag = 1
    for word in words:
        if S[::-1][i:i+len(word)] == word[::-1]:
            flag = 0
            i += len(word)
    if flag:
        print('NO')
        sys.exit()
print('YES')

Submission status: Time Limit Exceeded

Solution code:
S = input()
texts = ["dream", "dreamer", "erase", "eraser"]
T = [""]
max_count = len(S) // 5 + 1

match = False
count = 0
while count < max_count:
    if S in T:
        match = True
        break
    for i in range(len(T)):
        t = T.pop(0)
        for j in texts:
            T.append(t+j)
    count += 1

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
texts = ["dream", "dreamer", "erase", "eraser"]
T = [""]
max_count = len(S) // 5 + 1

match = False
count = 0
while count < max_count:
    if S in T:
        match = True
        break
    for i in range(len(T)):
        for j in texts:
            T.append(T[i]+j)
    count += 1

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