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()

from collections import deque

q = deque()
if len(S) > 5: #4文字以下ならそもそもバツ→入れない
  q.append((len(S), S))
#ここに、次にチェックする文字列を入れていく
#今回はque(fi-fo)として使うので、popleftを使う

flag = False
while(q):
  nowlen, nows = q.popleft()
  nows5 = nows[0:5]
  nowsfrom5 = nows[5:]
  if nows5 == 'dream':
    if nowlen == 5:
      flag = True
      break
    else:
      if nowlen>=10: q.append((nowlen-5, nowsfrom5))
    if nows[0:7] == 'dreamer':
      if nowlen == 7:
        flag = True
        break
      else:
        if nowlen>=12: q.append((nowlen-7, nows[7:]))
  elif nows5 == 'erase':
    if nowlen == 5:
        flag = True
        break
    else:
      if nowlen>=10: q.append((nowlen-5, nowsfrom5))
    if nows[0:6] == 'eraser':
      if nowlen == 6:
        flag = True
        break
      else: 
        if nowlen>=11: q.append((nowlen-6, nows[6:]))

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

from collections import deque

q = deque()
if len(S) > 5: #4文字以下ならそもそもバツ→入れない
  q.append(S)
#ここに、次にチェックする文字列を入れていく
#今回はque(fi-fo)として使うので、popleftを使う

flag = False
while(q):
  nows = q.popleft()
  nows5 = nows[0:5]
  nowsfrom5 = nows[5:]
  if nows[0:5] == 'dream':
    if nows[5:] == '':
      flag = True
      break
    else:
      if not(len(nowsfrom5)<=4): q.append(nows[5:])
    if nows[0:7] == 'dreamer':
      if nows[7:] == '':
        flag = True
        break
      else:
        if not(len(nows[7:])<=4): q.append(nows[7:])
  elif nows[0:5] == 'erase':
    if nows[5:] == '':
        flag = True
        break
    else:
      if not(len(nowsfrom5)<=4): q.append(nowsfrom5)
    if nows[0:6] == 'eraser':
      if nows[6:] == '':
        flag = True
        break
      else: 
        if not(len(nows[6:])<=4): q.append(nows[6:])

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

from collections import deque

q = deque()
q.append(S)
#ここに、次にチェックする文字列を入れていく
#今回はque(fi-fo)として使うので、popleftを使う

flag = False
while(q):
  nows = q.popleft()
  if len(nows) <= 4: continue
    #残りが4文字以下だと絶対違う
    #またほっとくと添字バグが起きる
  if nows[0:5] == 'dream':
    if nows[5:] == '':
      flag = True
      break
    else: q.append(nows[5:])
    if nows[0:7] == 'dreamer':
      if nows[7:] == '':
        flag = True
        break
      else: q.append(nows[7:])
  elif nows[0:5] == 'erase':
    if nows[5:] == '':
        flag = True
        break
    else: q.append(nows[5:])
    if nows[0:6] == 'eraser':
      if nows[6:] == '':
        flag = True
        break
      else: 
        q.append(nows[6:])

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

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import re

if __name__ == "__main__":
    patterns = ["dream", "dreamer", "erase" ,"eraser"]
    S = input()

    # while True:
    #     flag = False
    #     if S[-5:] == "dream":
    #         S = S[:-5]
    #         flag = True
    #     if S[-7:] == "dreamer":
    #         S = S[:-7]
    #         flag = True
    #     if S[-5:] == "erase":
    #         S = S[:-5]
    #         flag = True
    #     if S[-6:] == "eraser":
    #         S = S[:-6]
    #         flag = True
    #
    #     if flag == False:
    #         print("NO")
    #         break
    #
    #     if S == "":
    #         print("YES")
    #         break

    while True:
        flag = False
        if re.search("dream$",S):
            S = re.sub("dream$","",S)
            flag = True
        if re.search("dreamer$",S):
            S = re.sub("dreamer$","",S)
            flag = True
        if re.search("erase$",S):
            S = re.sub("erase$","",S)
            flag = True
        if re.search("eraser$",S):
            S = re.sub("eraser$","",S)
            flag = True

        if flag == False:
            print("NO")
            break

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

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import re

if __name__ == "__main__":
    patterns = ["dream", "dreamer", "erase" ,"eraser"]
    S = input()

    end = False

    while not(end):
        flag = False
        for pattern in patterns:
            if flag == False:
                if re.search(pattern+"$",S):
                    S = re.sub(pattern+"$","",S)
                    flag = True
            elif flag == True:
                break
        else:
            if flag == False:
                print("NO")
                end = True

        if not(S):
            print("YES")
            end = True

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    i = 0
    while 1:
        temp = []

        for t in T:
            if S[i:len(t) + i] == t:
                i += len(t)

        for t in T:
            temp.append(t in S[i:])
        if any(temp) == False:
            break
    if len(S) != i:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    while 1:
        temp = []
        for t in T:
            if S[:len(t)] == t:
                S = S[len(t):]
        for t in T:
            temp.append(t in S)
        if any(temp) == False:
            break
    if len(S) > 0:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    while 1:
        temp = []
        for t in T:
            if ''.join(S[:len(t)]) == t:
                S = S[len(t):]
        for t in T:
            temp.append(t in S)
        if any(temp) == False:
            break
    if len(S) > 0:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def main():
    S = input()
    S = S[::-1]
    T = 'dreamer', 'dream', 'eraser', 'erase'
    while 1:
        temp = []
        for t in T:
            t = t[::-1]
            temp.append(t in S)
        if any(temp) == False:
            break
        for t in T:
            t = t[::-1]
            if ''.join(S[:len(t)]) == t:
                S = S[len(t):]

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    S = list(S[::-1])
    T = 'dreamer', 'dream', 'eraser', 'erase'
    for s in S:
        for t in T:
            t = t[::-1]
            if ''.join(S[:len(t)]) == t:
                S = S[len(t):]

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(len(s)):
  t = t + s[i]
  for c in li:
    if t == c:
      t = ''

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

Submission status: Time Limit Exceeded

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

n = len(S)
r = 0
while(n > 0):
  for t in T:
    s = n - len(t)
    if(S[s:n].startswith(t)):
      r = 1
      n = s
      break
  if(r == 0):
    break
if r == 0:
  print("NO")
else:
  print("YES")

Submission status: Time Limit Exceeded

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

n = len(S)
r = 0
while(n > 0):
  for t in T:
    s = n - len(t)
    if(t == S[s:n]):
      r = 1
      n = s
      break
  if(r == 0):
    break
if r == 0:
  print("NO")
else:
  print("YES")

Submission status: Time Limit Exceeded

Solution code:
S = input()
T = ''
i = 0

while len(T) < len(S):
    if S[i:i+6] == 'eraser':
        T += 'eraser'
        i += 6
    elif S[i:i+5] == 'erase':
        T += 'erase'
        i += 5
    elif S[i:i+5] == 'dream':
        if S[i+5:i+6] == 'd':
            T += 'dream'
            i += 5
        elif S[i+5:i+8] == 'era':
            T += 'dream'
            i += 5
        elif S[i+5:i+6] == '':
            T += 'dream'
            i += 5
        elif S[i+5:i+8] == 'ere':
            T += 'dreamer'
            i += 7
        elif S[i+5:i+8] == 'erd':
            T += 'dreamer'
            i += 7
        elif S[i+5:i+8] == 'er':
            T += 'dreamer'
            i += 7
    else:
        print('NO')
        exit()

print('YES')

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import re, sys

s = input()

regex = re.compile(r'(dream|dreamer|erase|eraser)$')

while(len(s)):
	if re.search(regex, s):
		s = re.sub(regex, '', s)
	else:
		print('NO')
		sys.exit()

print('YES')

Submission status: Time Limit Exceeded

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

n = len(S)
r = 'NO'
while n != 0:
  for t in T:
    e = n - len(t)
    if(e < 0):
      r = 'NO'
      continue
    if(t == S[e:n]):
      r = 'YES'
      n = e
      break
  if(r == 'NO'):
    print(r)
    quit()

print(r)

Submission status: Time Limit Exceeded

Solution code:
def main(): 
    
    S = input()
    stack = []
    
    strs = S
    cmps = ["dream", "dreamer", "erase", "eraser"]

    while(1):
        if not cmps:
            if stack:
                strs, cmps = stack.pop()
            else:
                print("NO")
                return

        cmp_i = cmps.pop()
        if strs[:len(cmp_i)] == cmp_i:
            if cmps:
                stack.append((strs, cmps))

            strs = strs[len(cmp_i):]
            if strs == "":
                print("YES")
                return
            else:
                cmps = ["dream", "dreamer", "erase", "eraser"]

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

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

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

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

    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

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

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

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

    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

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

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

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

    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)
a=['dream','dreamer','erase','eraser']
def check(c):
    rt=False
    size=len(c)
    if c=='':
        return True
    for i in a:
        if size>=len(i) and c[:len(i)]==i:
            rt=check(c[len(i):]) or rt
    return rt

print('YES' if check(input()) else 'NO')

Submission status: Time Limit Exceeded

Solution code:
T = input()
 
w0 = "dream"
w1 = "dreamer"
w2 = "erase"
w3 = "eraser"
 
dict_sen = {0:w0,1:w1,2:w2,3:w3}
 
dp = ""
FT = len(T)
F = 0
while(F < FT):
  for i in range(4):
    if T[F:F+len(dict_sen[i])] == dict_sen[i]:
      dp = dp + dict_sen[i]
      F = len(dp)
      break
 
if dp != T:
  print("NO")
else :
  print("YES")

Submission status: Time Limit Exceeded

Solution code:
T = input()
 
w0 = "dream"
w1 = "dreamer"
w2 = "erase"
w3 = "eraser"
 
dict_sen = {0:w0,1:w1,2:w2,3:w3}
 
dp = ""
 
while(len(dp) < len(T)):
  for i in range(4):
    if T[:len(dict_sen[i])] == dict_sen[i]:
      T = T[len(dict_sen):]
      dp = dp + dict_sen[i]
      break
if dp == T :
  print("YES")
else :
  print("NO")

Submission status: Time Limit Exceeded

Solution code:
T = input()
 
w0 = "dream"
w1 = "dreamer"
w2 = "erase"
w3 = "eraser"
 
dict_sen = {0:w0,1:w1,2:w2,3:w3}
 
dp = ""
 
while(len(dp) < len(T)):
  for i in range(4):
    if T[len(dp):len(dp)+len(dict_sen[i])] == dict_sen[i]:
      dp = dp + dict_sen[i]
      break
if dp == T :
  print("YES")
else :
  print("NO")

Submission status: Time Limit Exceeded

Solution code:
T = input()

w0 = "dream"
w1 = "dreamer"
w2 = "erase"
w3 = "eraser"

dict_sen = {0:w0,1:w1,2:w2,3:w3}

dp = ""
S = ""

while(len(dp) < len(T)):
  for i in range(4):
    S = dict_sen[i]
    if T[len(dp):len(dp)+len(S)] == S:
      dp = dp + S
      break
if dp == T :
  print("YES")
else :
  print("NO")

Submission status: Time Limit Exceeded

Solution code:
S = input()
S = S[::-1]
divide = list(map(lambda phrase:phrase[::-1], ['dream', 'dreamer', 'erase', 'eraser']))

flag = False
i = 0
while i != len(S):
    for d in divide:
        if S[i:i+len(d)] == d:
            flag = True
            i += len(d)
            break

    if flag == False:
        break

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
S = S[::-1]
divide = list(map(lambda phrase:phrase[::-1], ['dream', 'dreamer', 'erase', 'eraser']))

flag = False
i = 0
while i != len(S):
    for d in divide:
        if S[i:i+len(d)] == d:
            flag = True
            i += len(d)
            break

    if flag == False:
        break

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

Submission status: Time Limit Exceeded

Solution code:
n = input()
t_list = ['dream', 'dreamer', 'erase', 'eraser']
i = 0
while len(n) != 0:
    for t in t_list:
        if n[-len(t):] == t:
            n = n[:-len(t)]
            break
if not n:
    print('YES')
else:
    print('NO')

Submission status: Time Limit Exceeded

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

S = input()
words = ['dream', 'dreamer', 'erase', 'eraser']
result = True

while len(S) != 0 and result == True:
  for i in range(5,8):
    if i == 8:
      result = False
      break
    if S[-i:] == words[0]:
      S = S[:-i]
      break
    elif S[-i:] == words[1]:
      S = S[:-i]
      break
    elif S[-i:] == words[2]:
      S = S[:-i]
      break
    elif S[-i:] == words[3]:
      S = S[:-i]
      break
    else:
      continue

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

Submission status: Time Limit Exceeded

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

S = input()
words = ['dream', 'dreamer', 'erase', 'eraser']
result = True

while len(S) != 0:
  for j in range(5):
    if j == 4:
      result = False
      break
    index = S.rfind(words[j])
    if index >= len(S) - 7:
      length = len(words[j])
      S = S[:-length]
      break
    else:
      continue

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

Submission status: Time Limit Exceeded

Solution code:
inp = input()
inp = inp[::-1]
m = 0
n = 0
li = ['dream','dreamer','erase','eraser']
li =[g[::-1] for g in li]
while True:
    for i in li:
        if inp.startswith(i):
    	    inpp = inp.replace(i,'',1)
    	    if inpp == '':
    		    m = 1
    		    break
    	    for k in li:
    	    	if inpp.startswith(k):
    		        inp = inpp
    		        n = 1
    		        break
    	    else:
                if k == 'eraser':
                	break
                continue
    	    break
    if m == 1:
    	print('YES')
    	break
    if n != 1:
    	print('NO')
    	break

Submission status: Time Limit Exceeded

Solution code:
inp = input()
m = 0
n = 0
li = ['dream','dreamer','erase','eraser']
while True:
    for i in li:
        if inp.startswith(i):
    	    inpp = inp.replace(i,'',1)
    	    if inpp == '':
    		    m = 1
    		    break
    	    for k in li:
    	    	if inpp.startswith(k):
    		        inp = inpp
    		        n = 1
    		        break
    	    else:

    	    	continue
    	    break
    if m == 1:
    	print('YES')
    	break
    if n != 1:
    	print('NO')
    	break

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
A = deque(input())
while len(A) >= 2:
    if len(A) >= 5 and list(A)[-5:] == list("dream"):
        for _ in range(5):
            A.pop()
    elif len(A) >= 5 and list(A)[-5:] == list("erase"):
        for _ in range(5):
            A.pop()
    elif len(A) >= 6 and list(A)[-6:] == list("eraser"):
        for _ in range(6):
            A.pop()
    elif len(A) >= 7 and list(A)[-7:] == list("dreamer"):
        for _ in range(7):
            A.pop()
    else:
        A = deque([0])
if len(A) == 0:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
A = deque(input())
while len(A) >= 2:
    if list(A)[:5] == list("dream"):
        if list(A)[5:7] == list("er") and list(A)[7:8] != list("a"):
            for _ in range(7):
                A.popleft()
        else:
            for _ in range(5):
                A.popleft()
    elif list(A)[:5] == list("erase"):
        if list(A)[5:6] == list("r"):
            for _ in range(6):
                A.popleft()
        else:
            for _ in range(5):
                A.popleft()
    else:
        A = deque([0])
if len(A) == 0:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
A = deque(input())
while len(A) >= 2:
    if list(A)[:7] == list("dreamer") and list(A)[5:8] != list("era"):
        for _ in range(7):
            A.popleft()
    elif list(A)[:5] == list("dream"):
        for _ in range(5):
            A.popleft()
    elif list(A)[:6] == list("eraser"):
        for _ in range(6):
            A.popleft()
    elif list(A)[:5] == list("erase"):
        for _ in range(5):
            A.popleft()
    else:
        A = deque([0])
if len(A) == 0:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
A = deque(input())
while A != deque() and A != deque([0]):
    if list(A)[:7] == list("dreamer") and list(A)[5:10] != list("erase"):
        for _ in range(7):
            A.popleft()
    elif list(A)[:5] == list("dream"):
        for _ in range(5):
            A.popleft()
    elif list(A)[:6] == list("eraser"):
        for _ in range(6):
            A.popleft()
    elif list(A)[:5] == list("erase"):
        for _ in range(5):
            A.popleft()
    else:
        A = deque([0])
if A == deque():
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
A = list(input())
while A != [] and A != [0]:
    if A[:7] == list("dreamer") and A[5:10] != list("erase"):
        A = A[7:]
    elif A[:5] == list("dream"):
        A = A[5:]
    elif A[:6] == list("eraser"):
        A = A[6:]
    elif A[:5] == list("erase"):
        A = A[5:]
    else:
        A = [0]
if A == []:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
A = deque()
A.append(list(input()))
while A[0] != [] and A[0] != [False]:
        if A[0][:7] == list("dreamer"):
            A.appendleft(A[0][7:])
            A[1] = A[1][5:]
        elif A[0][:5] == list("dream"):
            A[0] = A[0][5:]
        elif A[0][:6] == list("eraser"):
            A.appendleft(A[0][6:])
            A[1] = A[1][5:]
        elif A[0][:5] == list("erase"):
            A[0] = A[0][5:]
        else:
            A.popleft()
            if len(A) == 0:
                A.append([False])
if A[0] == []:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
A = deque()
A.append(list(input()))
while A[0] != [] and A[0] != [False]:
        if A[0][:7] == list("dreamer"):
            A.appendleft(A[0][7:])
            A[1] = A[1][5:]
        elif A[0][:5] == list("dream"):
            A[0] = A[0][5:]
        elif A[0][:6] == list("eraser"):
            A.appendleft(A[0][6:])
            A[1] = A[1][5:]
        elif A[0][:5] == list("erase"):
            A[0] = A[0][5:]
        else:
            A.popleft()
            if A == deque():
                A.append([False])
if A[0] == []:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
s=input()
def check(s):
    x=s[-3:]
    if x=='eam':
        if s[-5:]=='dream':
            return 'dream'
    elif x=='mer':
        if s[-7:]=='dreamer':
            return 'dreamer'
    elif x=='ase':
        if s[-5:]=='erase':
            return 'erase'
    elif x=='ser':
        if s[-6:]=='eraser':
            return 'eraser'
    else: return 'False'

count=0
while len(s)>0 and count==0:
    if check(s)=='False':
        count+=1
        print('NO')
    elif check(s)=='dream' or check(s)=='erase':
        if len(s)!=5:s=s[:-5]
        elif len(s)==5:s=''
    elif check(s)=='eraser':
        if len(s)!=6:s=s[:-6]
        elif len(s)==6:s=''
    elif check(s)=='dreamer':
        if len(s)!=7:s=s[:-7]
        elif len(s)==7:s=''

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

Submission status: Time Limit Exceeded

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

words = list(map(lambda s: s[::-1], ['dreamer', 'eraser', 'erase', 'dream']))

while any([w in S for w in words]):
    for w in words:
        if S[:len(w)] == w:
            S = S[len(w):]
            break

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

Submission status: Time Limit Exceeded

Solution code:
import re
import copy

def getDevidedString(S):
    s = copy.deepcopy(S)
    regExDream = "^(.*)dream$"
    if re.match(regExDream, s):
        return s[0:-5]
    regExDreamer = "^(.*)dreamer$"
    if re.match(regExDreamer, s):
        return s[0:-7]
    regExErase = "^(.*)erase$"
    if re.match(regExErase, s):
        return s[0:-5]
    regExEraser = "^(.*)eraser$"
    if re.match(regExEraser, s):
        return s[0:-6]
    return s

S = input()

while len(S) != 0:
    tmp = getDevidedString(S)
    if len(S) != len(tmp):
        S = tmp
    else:
        break

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

Submission status: Time Limit Exceeded

Solution code:
import re
import copy

def getDevidedString(S):
    s = copy.deepcopy(S)
    regExDream = "^(.*)dream$"
    if re.match(regExDream, s):
        return re.sub(regExDream, "\\1", s)
    regExDreamer = "^(.*)dreamer$"
    if re.match(regExDreamer, s):
        return re.sub(regExDreamer, "\\1", s)
    regExErase = "^(.*)erase$"
    if re.match(regExErase, s):
        return re.sub(regExErase, "\\1", s)
    regExEraser = "^(.*)eraser$"
    if re.match(regExEraser, s):
        return re.sub(regExEraser, "\\1", s)
    return s

S = input()

while len(S) != 0:
    tmp = getDevidedString(S)
    if len(S) != len(tmp):
        S = tmp
    else:
        break

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
i = 0
n = len(s)
p = 0
while i < n:
    if i == 0:
        if s[i] == "d":
            if i + 5 <= n:
                if s[i:i+5] == "dream":
                    i = i + 5
                    if i + 5 < n:
                        if s[i] != "e" and s[i] != "d":
                            print("NO")
                            exit()
                else:
                    print("NO")
                    exit()
            else:
                print("NO")
                exit()
        elif s[i] == "e":
            if i + 2 <= n:
                if s[i:i+2] == "er":
                    i = i + 1
                else:
                    print("NO")
                    exit()
            else:
                print("NO")
                exit()
        else:
            print("NO")
            exit()
    else:
        if s[i] == "d":
            if i + 5 <= n:
                if s[i:i+5] == "dream":
                    i = i + 5
                    if i + 5 < n:
                        if s[i] != "e" and s[i] != "d":
                            print("NO")
                            exit()
                else:
                    print("NO")
                    exit()
            else:
                print("NO")
                exit()
        elif s[i] == "e":
            if i + 2 <= n:
                if s[i:i+2] == "er":
                    i = i + 1
                else:
                    print("NO")
                    exit()
            else:
                print("NO")
                exit()
        elif s[i] == "r":
            if s[i - 5: i + 1] == "eraser" and i - 5 >= 0:
                if s[i - 2] != "r":
                    if i + 1 < n:
                        if s[i + 1] == "d":
                            i = i + 1
                        elif s[i + 1] == "e":
                            i = i + 1
                        else:
                            print("NO")
                            exit()
                        #p = 1
                    else:
                        print("YES")
                        exit()
            elif i + 4 <= n:
                if s[i - 2] != "r":
                    if i + 1 < n:
                        if s[i + 1] == "d":
                            i = i + 1
                        elif s[i + 1] == "e":
                            i = i + 1
                        p = 1
                    else:
                        print("YES")
                        exit()
                if s[i:i+4] == "rase":
                    i = i + 4
                    p = 1
                if p == 0:
                    print("NO")
                    exit()
            elif s[i - 2] != "r":
                if i + 1 < n:
                    if s[i + 1] == "d":
                        i = i + 1
                    elif s[i + 1] == "e":
                        i = i + 1
                    else:
                        print("NO")
                        exit()
                else:
                    print("YES")
                    exit()
            else:
                print("NO")
                exit()
        else:
            print("NO")
            exit()
    p = 0
print("YES")