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:
ar = list(input())
while True:
    a = len(ar)
    if a == 0:
        print("YES")
        break
    if "".join(ar[a-5:a]) == "dream" or "".join(ar[a-5:a]) == "erase":
        del ar[a-5:a]
    elif "".join(ar[a-6:a]) == "eraser":
        del ar[a-6:a]
    elif "".join(ar[a-7:a]) == "dreamer":
        del ar[a-7:a]
    else:
        print("NO")
        break

Submission status: Accepted

Solution code:
S = input()
rS = S[::-1]
keys = ['dream', 'dreamer', 'erase', 'eraser']
reversed_keys = [keys[i][::-1] for i in range(len(keys))]
i = 0

while i < len(rS):
    if rS[i:i+5] in reversed_keys:
        i += 5
    elif rS[i:i+6] in reversed_keys:
        i += 6
    elif rS[i:i+7] in reversed_keys:
        i += 7
    else:
        break
if i == len(rS):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
daydream = ['dream', 'dreamer', 'erase', 'eraser']
s = input()
import sys
while s:
    for i in daydream:
        if s.endswith(i):
            s = s[:-len(i)]
            break
    else:
        break
else:
    print('YES')
    sys.exit()
print('NO')

Submission status: Accepted

Solution code:
S=input()
i=3
while i<=len(S):
    if i==3:
        if S[-3:]=="eam":
            i+=2
            if S[-i:-i+2]=="dr":
                i+=3
            else:
                print("NO")
                break
        elif S[-3:]=="mer":
            i+=4
            if S[-i:-i+4]=="drea":
                i+=3
            else:
                print("NO")
                break
        elif S[-3:]=="ase":
            i+=2
            if S[-i:-i+2]=="er":
                i+=3
            else:
                print("NO")
                break
        elif S[-3:]=="ser":
            i+=3
            if S[-i:-i+3]=="era":
                i+=3
            else:
                print("NO")
                break
        else:
            print("NO")
            break
    else:
        if S[-i:-i+3]=="eam":
            i+=2
            if S[-i:-i+2]=="dr":
                i+=3
            else:
                print("NO")
                break
        elif S[-i:-i+3]=="mer":
            i+=4
            if S[-i:-i+4]=="drea":
                i+=3
            else:
                print("NO")
                break
        elif S[-i:-i+3]=="ase":
            i+=2
            if S[-i:-i+2]=="er":
                i+=3
            else:
                print("NO")
                break
        elif S[-i:-i+3]=="ser":
            i+=3
            if S[-i:-i+3]=="era":
                i+=3
        
        else:
            print("NO")
            break
else:
    print("YES")

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]
l = "dream dreamer erase eraser".split()
l = [i[::-1] for i in l]


while len(s) > 0:
    flag = False
    for i in l:
        n = len(i)
        if s[:min(n, len(s))] in i:
            s = s[min(n, len(s)):]
            flag = True
            break
    if not flag:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input().strip()
def solve(S):
    while len(S)>0:
        if S[-6:]=='eraser':
            S=S[:-6]
        elif S[-7:]=='dreamer':
            S=S[:-7]
        elif S[-5:]=='erase':
            S=S[:-5]
        elif S[-5:]=='dream':
            S=S[:-5]
        else:
            return False
    return True

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

Submission status: Accepted

Solution code:
def check(s):
    if s == '':
        return True
    while(s != ''):
        if s.startswith('eraser'):
            s = s[6:]
        elif s.startswith('erase'):
            s = s[5:]
        elif s.startswith('dreamera'):
            #dream,erase(r)
            s = s[5:]
        elif s.startswith('dreamer'):
            s = s[7:]
        elif s.startswith('dream'):
            s = s[5:]
        else:
            return False
    return True

s=input()
if check(s):
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
import sys
import collections
import itertools
import math
from collections import Counter
from collections import deque
MOD = 10 ** 9 + 7

S = input()

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

s = S
while len(s) > 0:
    deleted = False
    for k in keys:
        idx = s.rfind(k)
        if idx+len(k) == len(s):
            s = s[0:idx]
            deleted = True
            break
    if deleted == False:
        break

if deleted == False or len(s) != 0:
    print("NO")
else:
    print("YES")


sys.exit(0)

Submission status: Accepted

Solution code:
Ss = input()

lenS = len(Ss)
i = 0
while i < lenS:
    if Ss[i:].startswith('dream'):
        if Ss[i + 5:i + 7] == 'er' and Ss[i + 7:i + 8] != 'a': # dreamer
            i += 7
        else: # dream
            i += 5
    elif Ss[i:].startswith('erase'):
        if Ss[i + 5:i + 6] == 'r': # eraser
            i += 6
        else: # erase
            i += 5
    else:
        print('NO')
        break
else:
    print('YES')

Submission status: Accepted

Solution code:
S=input()

S=S[::-1]

count=0
while(count<len(S)):
  if (len(S)-count)<5:
    print('NO')
    exit()
    
  elif S[count]=='e' and S[count+1]=='s' and S[count+2]=='a' and S[count+3]=='r' and S[count+4]=='e':
    count+=5
  elif S[count]=='m' and S[count+1]=='a' and S[count+2]=='e' and S[count+3]=='r' and S[count+4]=='d':
    count+=5
  
  elif (len(S)-count)==5:
    print('NO')
    exit()
  elif S[count]=='r' and S[count+1]=='e' and S[count+2]=='s' and S[count+3]=='a' and S[count+4]=='r' and S[count+5]=='e':
    count+=6
  elif (len(S)-count)==6:
    print('NO')
    exit()
  elif S[count]=='r' and S[count+1]=='e' and S[count+2]=='m' and S[count+3]=='a' and S[count+4]=='e'and S[count+5]=='r' and S[count+6]=='d':
    count+=7
  else:
    print('NO')
    exit()

print('YES')

Submission status: Accepted

Solution code:
s = input()

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


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


"""
1 => 1,2
"""

Submission status: Accepted

Solution code:
match = ['eraser', 'erase', 'dreamer', 'dream']
len_m = [len(m) for m in match]
S = input()
n = len(S)
dp = [False] * (n + 1)
dp[0] = True
for i in range(1, n + 1):
    for w, word in zip(len_m, match):
        if S[i - w:i] == word and dp[i - w]:
            dp[i] = True
            break
print('YES' if dp[n] else 'NO')

Submission status: Accepted

Solution code:
match = ['eraser', 'erase', 'dreamer', 'dream']
len_m = [len(m) for m in match]
S = input()
n = len(S)
dp = [False] * (n + 1)
dp[0] = True
for i in range(1, n + 1):
    for lm, m in zip(len_m, match):
        if S[:i].endswith(m) and dp[i - lm]:
            dp[i] = True
            break
print('YES' if dp[n] else 'NO')

Submission status: Accepted

Solution code:
match = ['eraser', 'erase', 'dreamer', 'dream']
len_m = [len(m) for m in match]
S = input()
n = len(S)
dp = [False] * (n + 1)
dp[0] = True
for i in range(1, n + 1):
    for lm, m in zip(len_m, match):
        if S[:i].endswith(m):
            dp[i] |= dp[i - lm]
print('YES' if dp[n] else 'NO')

Submission status: Accepted

Solution code:
s = input()
w = ['dream','dreamer','erase','eraser']
flag = True
while flag:
    flag = False
    if len(s)<5:
        break
    for i in w:
        if s[-len(i):] == i:
            s = s[:-len(i)]
            flag = True
if s:
    print('NO')
else:
    print('YES')

Submission status: Accepted

Solution code:
import sys
S=input()
L=['dream','dreamer','erase','eraser']
T=[i[::-1] for i in L]
S=S[::-1]
while True:
    #print(S)
    if len(S)==0:
        print('YES')
        sys.exit()
    if S[:5]==T[0]:
        S=S[5:]
        continue
    if S[:5]==T[2]:
        S=S[5:]
        continue
    if S[:7]==T[1]:
        S=S[7:]
        continue
    if S[:6]==T[3]:
        S=S[6:]
        continue
    print('NO')
    sys.exit()

Submission status: Accepted

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

s = input()[::-1]
w = [
    "dream"[::-1]
    ,"dreamer"[::-1]
    ,"erase"[::-1]
    ,"eraser"[::-1]
]

while len(s)>0:
    if s.startswith(w[0]):
        s = s[len(w[0]):]
    elif s.startswith(w[1]):
        s = s[len(w[1]):]
    elif s.startswith(w[2]):
        s = s[len(w[2]):]
    elif s.startswith(w[3]):
        s = s[len(w[3]):]
    else:
        break

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

Submission status: Accepted

Solution code:
s = input()

def solve(s):
    i = 0
    n = len(s)

    while i < n:
        if s[i:i+5] == 'dream':
            if s[i+5:i+7] != 'er':
                i += 5
            elif i+7 < n and s[i+7] == 'a':
                i += 5
            else:
                i += 7
        elif s[i:i+5] == 'erase':
            if i+5 < n and s[i+5] == 'r':
                i += 6
            else:
                i += 5
        else:
            return False
    return True

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
S=S[::-1]
cnt=["dream","dreamer","erase","eraser"]

for i in range(4):
  s=cnt[i]
  s=s[::-1]
  cnt[i]=s

while len(S):
  if S[:5]==cnt[0]:
    S=S[5:]
  elif S[:7]==cnt[1]:
    S=S[7:]
  elif S[:5]==cnt[2]:
    S=S[5:]
  elif S[:6]==cnt[3]:
    S=S[6:]
  else:
    break

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S=input().strip()
ws=['dream','dreamer','erase','eraser']
while True:
  change = False
  for w in ws:
    if len(w) <= len(S) and S[-len(w):] == w:
      S = S[:-len(w)]
      change = True
  if not change:
    break
print("YES" if len(S) == 0 else "NO")

Submission status: Accepted

Solution code:
S = input()

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

for key in keys:
    S = S.replace(key, '')

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

Submission status: Accepted

Solution code:
S = input()

keys = ('dreameraser', 'eraser', 'erase', 'dreamer', 'dream')

for key in keys:
    S = S.replace(key, '')

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
d=['dream','dreamer','erase','eraser']
while s:
    for m in d:
        if s.endswith(m):
            s=s[:-len(m)]
            break
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
s=input()

while 1:

    if s[-5:] in ["dream","erase"]:
        s=s[:-5]
    elif s[-6:] == "eraser":
        s=s[:-6]
    elif s[-7:] == "dreamer":
        s=s[:-7]
    elif s == "":
        print("YES")
        exit()
    else:
        print("NO")
        exit()

Submission status: Accepted

Solution code:
s=input()[::-1]
d=['maerd','remaerd','esare','resare']
while s:
    for i in range(4):
        if s.startswith(d[i]):
            s=s[len(d[i]):]
            break
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
import re

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S = input()
L = len(S)
S += "________"
i = 0
res = "YES"
while i < L:
    if S[i:i+5] == "dream":
        if S[i+5:i+7] == "er":
            if S[i+7] == "a":
                i += 5 # dream
            else:
                i += 7 # dreamer
        else:
            i += 5 # dream
    elif S[i:i+5] == "erase":
        if S[i+5] == "r":
            i += 6 # eraser
        else:
            i += 5 # erase
    else:
        res = "NO"
        break

print(res)

Submission status: Accepted

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

s = input()
s = re.sub('eraser?', '1', s)
s = re.sub('dream(er)?', '1', s)
print('YES' if len(s) == s.count('1') else 'NO')

Submission status: Accepted

Solution code:
DAYDREAM = ["dream", "dreamer", "erase", "eraser" ]
S = input()

ind = len(S)
res = True
while ind > 0:
	ok = False
	for i in DAYDREAM:
		if S[ind - len(i):ind] == i:
			ind -= len(i)
			ok = True
			break;
	if ok == False:
		res = False
		break

print("YES" if res == True else "NO")

Submission status: Accepted

Solution code:
import sys
DAYDREAM = ["dream", "dreamer", "erase", "eraser" ]
S = input()

ind = len(S)
res = True

while ind > 0:
	ok = False
	for i in DAYDREAM:
#		print("ind:", ind, "subS: ", S[ind - len(i):ind], file=sys.stderr)
		if S[ind - len(i):ind] == i:
			ind -= len(i)
			ok = True
			break;
	if ok == False:
		res = False
		break

print("YES" if res == True else "NO")

Submission status: Accepted

Solution code:
S = raw_input().split()[0]
t = ['dreameraser','dreamerase','dreamer','dream','eraser','erase']
while len(S) > 0:
    for i in t:
        if S[-len(i):]==i:
            S = S[:-len(i)]
            break
        elif i == t[-1]:
            print "NO"
            exit()
print "YES"

Submission status: Accepted

Solution code:
s = input()

five = ["dream", "erase"]
six = ["eraser"]
seven = ["dreamer"]

i = len(s) - 1

ans = False
while True:
  if i < 4:
    break
  elif i == 4:
    ans = s[:5] in five
    break
  elif i == 5:
    ans = s[:6] in six
    break
  elif i == 6:
    ans = s[:7] in seven
    break
  else:
    if s[i+1-5:i+1] in five:
      i -= 5
    elif s[i+1-6:i+1] in six:
      i -= 6
    elif s[i+1-7:i+1] in seven:
      i -= 7
    else:
      break

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

Submission status: Accepted

Solution code:
import sys
pattern = ["dream", "dreamer", "erase", "eraser"]
split_pattern = ["dream", "er", "ase", "r"]
grammer = {
        "ase": ["er"],
        "r": ["ase", "er"],
        "er": ["dream"],
        "dream": [],
        }
s = input()

splited = []
while s:
    for spl in split_pattern:
        if s.startswith(spl):
            splited.insert(0, spl)
            s = s[len(spl):]
            break
    else:
        print("NO")
        sys.exit()

pred = []
for word in splited:
    if not pred:
        pred = grammer[word][:]
    else:
        if word != pred[0]:
            print("NO")
            break
        else:
            del pred[0]
else:
    print("YES")

Submission status: Accepted

Solution code:
import sys

def solve(s):
    tmp_s = s
    while(len(tmp_s) > 0):
        if tmp_s.startswith("maerd"):
            tmp_s = tmp_s[5:]
        elif tmp_s.startswith("remaerd"):
            tmp_s = tmp_s[7:]
        elif tmp_s.startswith("esare"):
            tmp_s = tmp_s[5:]
        elif tmp_s.startswith("resare"):
            tmp_s = tmp_s[6:]
        else:
            return False

    return True

def main():
    line = sys.stdin.readline().rstrip()
    line_rev = line[::-1]

    if solve(line_rev):
        print("YES")
    else:
        print("NO")

    return 0

if __name__ == '__main__':
    sys.exit(main())

Submission status: Accepted

Solution code:
W = ["dream", "dreamer", "erase", "eraser"]
S = raw_input()

while S:
    for w in W:
	if S.endswith(w):
             S = S[:-len(w)]
             break
    else:
        print "NO"
        break
else:
    print "YES"

Submission status: Accepted

Solution code:
import sys

S = raw_input()
S = S[::-1]
T = ''
words = ['dreamer', 'dream', 'eraser', 'erase']
for i in range(len(words)):
    words[i] = words[i][::-1]
while len(S):
    N = len(S)
    for word in words:
        if S[:len(word)] == word:
            S = S[len(word):]
            break
    if N == len(S):
        sys.stdout.write('NO')
        break
    if len(S) == 0:
        sys.stdout.write('YES')

Submission status: Accepted

Solution code:
S = raw_input()
while len(S) > 0:
	if S.startswith("dream"):
		S = S[len("dream"):]
		if S.startswith("er"):
			if S.startswith("erase"):
				continue
			else:
				S = S[len("er"):]
		continue
	elif S.startswith("eraser"):
		S = S[len("eraser"):]
		continue
	elif S.startswith("erase"):
		S = S[len("erase"):]
		continue
	break
if len(S) > 0:
	print("NO")
else:
	print("YES")

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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


def main():
    p = 'dream dreamer erase eraser'.split()
    pp = [[_, len(_)] for _ in p]
    s = input()
    while len(s) > 0:
        f = False
        for ps, pl in pp:
            if ps == s[-pl:]:
                s = s[:-pl]
                f = True
                break
        if not f:
            return 'NO'

    return 'YES'


print(main())

Submission status: Accepted

Solution code:
S = input()

i = 0

a = ["dreameraser", "dreamerase", "dreamer", "eraser", "dream", "erase"]
while i < len(S):
    f = False
    for j in a:
        l = len(j)
        if S[i:i + l] == j:
            f = True
            i += l
            break

    if not f:
        print("NO")
        exit(0)

print("YES")

Submission status: Accepted

Solution code:
dream, erase = "dream erase".split()

s = input().strip()
while 1:
  if s.startswith(dream):
     s = s[5:]
     if s.startswith("er") and not s.startswith("era"):
       s = s[2:]
  elif s.startswith(erase):
    s = s[5:]
    if s.startswith('r'):
      s = s[1:]
  else:
    break
print("NO" if s else "YES")

Submission status: Accepted

Solution code:
import sys

line = sys.stdin.readline().rstrip()

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

Submission status: Accepted

Solution code:
import sys

s = input()

i = 0
N = len(s)
while i < N:
    if s[i:i+5] == 'dream':
        i += 5
    elif s[i:i+6] == 'eraser':
        i += 6
    elif s[i:i+5] == 'erase':
        i += 5
    elif s[i:i+2] == 'er' and s[i-5:i] == 'dream':
        i += 2
    else:
        print("NO")
        sys.exit()
print("YES")

Submission status: Accepted

Solution code:
import sys
 
S = list(raw_input())
pos = 0
while (pos < len(S)):
	if (''.join([S[x] for x in range(pos, min(pos+11, len(S)), 1)]) == "dreameraser"):
		pos += 11
	elif (''.join([S[x] for x in range(pos, min(pos+10, len(S)), 1)]) == "dreamerase"):
		pos += 10
	elif (''.join([S[x] for x in range(pos, min(pos+7, len(S)), 1)]) == "dreamer"):
		pos += 7
	elif (''.join([S[x] for x in range(pos, min(pos+6, len(S)), 1)]) == "eraser"):
		pos += 6
	elif (''.join([S[x] for x in range(pos, min(pos+5, len(S)), 1)]) == "erase"):
		pos += 5
	elif (''.join([S[x] for x in range(pos, min(pos+5, len(S)), 1)]) == "dream"):
		pos += 5
	else:
		print "NO"
		sys.exit()
print "YES"

Submission status: Accepted

Solution code:
S = input()
for i in ['eraser', 'erase', 'dreamer', 'dream']:
    S=S.replace(i, 'R')
s = set(S)
print(['NO', 'YES'][len(s) == 1 and 'R' in s])

Submission status: Accepted

Solution code:
import re

if re.match("^(dream(er)?|eraser?)*$", input()):
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = raw_input()

def pick_greedy(S):
    if S[0:5] == 'dream':
        if S[5:7] == 'er':
            if S[7] == 'a':
                ret = 'dream'
            else:
                ret = 'dreamer'
        else:
            ret = 'dream'
    elif S[0:5] == 'erase':
        if S[5] == 'r':
            ret = 'eraser'
        else:
            ret = 'erase'
    else:
        ret = 'no'
    return ret

sol = 'YES'

while len(S) > 0:
    try:
        r = pick_greedy(S)
        if r == 'no':
            sol = 'NO'
            break
        else:
            if len(S) < len(r):
                sol = 'NO'
                break
            else:
                S = S[len(r):]
    except:
        sol = 'YES'
        break
        
print sol

Submission status: Accepted

Solution code:
import sys

s = raw_input()
l = ['dreameraser', 'dreamerase', 'eraser', 'dreamer', 'dream', 'erase']

flag = True
while flag:
    if len(s) == 0:
        print 'YES'
        sys.exit()
    for w in l:
        if s.find(w) == 0:
            s = s[len(w):len(s)]
            break
    else:
        flag = False
print 'NO'

Submission status: Accepted

Solution code:
import sys
s=raw_input()
while True:
    flag=True
    n=len(s)
    if n==0:print 'YES';sys.exit()
    if n>4:
        if s[n-5:]=='dream' or s[n-5:]=='erase':
            s=s[:n-5]
            flag=False
    n=len(s)
    if n>5:
        if s[n-6:]=='eraser':
            s=s[:n-6]
            flag=False
    n=len(s)
    if n>6:
        if s[n-7:]=='dreamer':
            s=s[:n-7]
            flag=False
    if flag: print 'NO';sys.exit()

Submission status: Accepted

Solution code:
T = ["maerd", "remaerd", "esare", "resare"]

s = raw_input()
s = s[::-1]

ans = True
while True:
	if s == "":
		ans = True
		break
	elif s[0] == "m" and len(s) >= len(T[0]) and s[:len(T[0])] == T[0]:
		s = s[len(T[0]):]
	elif s[0] == "r" and len(s) > 2:
		if s[2] == "m" and len(s) >= len(T[1]) and s[:len(T[1])] == T[1]:
			s = s[len(T[1]):]
		elif s[2] == "s" and len(s) >= len(T[3]) and s[:len(T[3])] == T[3]:
			s = s[len(T[3]):]
		else:
			ans = False
			break
	elif s[0] == "e" and len(s) >= len(T[2]) and s[:len(T[2])] == T[2]:
		s = s[len(T[2]):]
	else:
		ans = False
		break

if ans:
	print "YES"
else:
	print "NO"

Submission status: Accepted

Solution code:
s = input()

dream = "dream"
erase = "erase"

ans = True
ind = 0
while ind < len(s):
	if s[ind] == 'd':
		tmp = s[ind:ind+5]
		if tmp == dream:
			ind += 5
			if ind + 2 == len(s):
				if s[ind:ind+2] == 'er':
					break
			elif ind + 2 < len(s):
				if s[ind:ind+2] == 'er' and s[ind+2] != 'a':
					ind += 2
		else:
			ans = False
			break
	elif s[ind] == 'e':
		tmp = s[ind:ind+5]
		if tmp == erase:
			ind += 5
			if ind < len(s):
				if s[ind] == 'r':
					ind += 1
		else:
			ans = False
			break
	else:
		ans = False
		break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
i = 0
while i < N:
    if i + 5 <= N:
        if S[i:i+5] == "dream":
            if i + 7 <= N:
                if S[i:i+7] == "dreamer":
                    if S[i+5:i+10] == "erase":
                        i = i + 5
                    else:
                        i = i + 7
                else:
                    i = i + 5
            else:
                i = i + 5
        elif S[i:i+5] == "erase":
            if i + 6 <= N:
                if S[i:i+6] == "eraser":
                    i = i + 6
                else:
                    i = i + 5
            else:
                i = i + 5
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

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

def dfs(s,idx):
    if idx==len(s):
        print("YES")
        exit()
    if idx>len(s):
        return
    if idx+5<=len(s) and s[idx:idx+5]=="dream":
        dfs(s,idx+5)
    if idx+7<=len(s) and s[idx:idx+7]=="dreamer":
        dfs(s,idx+7)
    if idx+5<=len(s) and s[idx:idx+5]=="erase":
        dfs(s,idx+5)
    if idx+6<=len(s) and s[idx:idx+6]=="eraser":
        dfs(s,idx+6)
    return
s=raw_input()
dfs(s,0)
print("NO")

Submission status: Accepted

Solution code:
S=str(input())
S=S[::-1]
while True:
    if S[:5]=='maerd':
        S=S[5:]

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

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:
t=raw_input()
#t=t.replace('eraser','').replace('dreamer','').replace('erase','').replace('dream','')
while len(t):
    if len(t)>10 and t[:11]=='dreameraser':
        t=t[11:]
    elif len(t)>9 and t[:10]=='dreamerase':
        t=t[10:]
    elif len(t)>6 and t[:7]=='dreamer':
        t=t[7:]
    elif len(t)>4 and t[:5]=='dream':
        t=t[5:]
    elif len(t)>5 and t[:6]=='eraser':
        t=t[6:]
    elif len(t)>4 and t[:5]=='erase':
        t=t[5:]
    else:
        break
print 'YES' if t=='' else 'NO'

Submission status: Accepted

Solution code:
S=input()
# S=list(S)
def solve(S):
	while(S!=""):
		if len(S)>=7 and S[-7:]=="dreamer":
			S=S[:-7]
		elif len(S)>=6 and S[-6:]=="eraser":
			S=S[:-6]
		elif len(S)>=5 and S[-5:]=="dream" :
			S=S[:-5]
		elif len(S)>=5 and S[-5:]=="erase":
			S=S[:-5]
		else:
			return("NO")
	return("YES")

print(solve(S))

Submission status: Accepted

Solution code:
s = input()

dp = [True] * (len(s)+1)

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

for i in range(1,len(s)+1):
	found = False
	for word in check:
		j = i - len(word)
		if j >= 0 and s[j:i] == word and dp[j]:
			found = True
			break
	dp[i] = found

if dp[len(s)]:
	print('YES')
else:
	print('NO')

Submission status: Accepted

Solution code:

s = input()[::-1]

t = [x[::-1] for x in ['dream', 'dreamer', 'erase', 'eraser']]

i = 0
while i < len(s):
    if s[i] == 'm':
        if s[i: i + 5] == t[0]:
            i += 5
            continue
    elif s[i] == 'e':
        if s[i: i + 5] == t[2]:
            i += 5
            continue
    elif s[i] == 'r':
        if s[i: i + 6] == t[3]:
            i += 6
            continue
        elif s[i: i + 7] == t[1]:
            i += 7
            continue
    break

print('YES' if i == len(s) else 'NO')

Submission status: Accepted

Solution code:
#import string,itertools,fractions,heapq,re,array,bisect
#from math import *
#from collections import Counter
def rl(s): return xrange(len(s))

INF = 2147483647


import sys
stdin = sys.stdin

S =        ( stdin.readline().strip() )

N = len(S)
ok_ends = [False] * (N+1)
ok_ends[0] = True
for i in range(1, N+1):
    for word in ['dream', 'dreamer', 'erase', 'eraser']:
        if S[max(0, i-len(word)): i] == word:
            if ok_ends[max(0, i-len(word))]:
                ok_ends[i] = True

if ok_ends[-1]:
    print "YES"
else:
    print "NO"

Submission status: Accepted

Solution code:
def read():
    return int(input())
 
def reads(sep=None):
    return list(map(int, input().split()))
 
def main():
	a = ['dream', 'dreamer', 'erase', 'eraser']
	s = input()
	flag = True
	while flag:
		flag = False
		for i in range(len(a)):
			if a[i] == s[-len(a[i]):]:
				s = s[:-len(a[i])]
				flag = True
	if 0 < len(s):
		print('NO')
	else:
		print('YES')
	
main()

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]
a = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
    a[i] = a[i][::-1]

while len(s) > 0:
    #print(s)
    if s[:3] == 'rem' and s[:len(a[1])] == a[1]:
        s = s[len(a[1]):]
    elif s[:3] == 'res' and s[:len(a[3])] == a[3]:
        s = s[len(a[3]):]
    elif s[0] == 'e' and s[:len(a[2])] == a[2]:
        s = s[len(a[2]):]
    elif s[0] == 'm' and s[:len(a[0])] == a[0]:
        s = s[len(a[0]):]
    else:
        print("NO")
        raise SystemExit

print("YES")

Submission status: Accepted

Solution code:
s = raw_input()
s = s[::-1]
i = 0
dream = False
while i < len(s):
	p = s[i:i+7]
	
	if p == "remaerd":
		i += 7
	elif p[:6] == "resare":
		i += 6
	elif p[:5] == "maerd" or p[:5] == "esare":
		i += 5
	else:
		break
	
if i >= len(s):
	print "YES"
else:
	print "NO"

Submission status: Accepted

Solution code:
import re

s = input()
s = re.sub('eraser?', '1', s)
s = re.sub('dream(er)?', '1', s)
print('YES' if len(s) == s.count('1') else 'NO')

Submission status: Accepted

Solution code:
from sys import exit

def no():
  print("NO"); exit()

S = input()

n = len(S)

while n >= 5:
  # print(n)
  pf = S[n-3:n]
  if pf == "eam":
    if S[n-5:n] == "dream":
      n -= 5
    else:
      no()
  elif pf == "mer":
    if n >= 7 and S[n-7:n] == "dreamer":
      n -= 7
    else:
      no()
  elif pf == "ase":
    if S[n-5:n] == "erase":
      n -= 5
    else:
      no()
  elif pf == "ser":
    if n >= 6 and S[n-6:n] == "eraser":
      n -= 6
    else:
      no()
  else:
    no()

if n > 0:
  no()
else:
  print("YES"); exit()

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from collections import *
S = input()

seen = set()
dq = deque()

ok = False
seen.add(0)
while len(seen) > 0:
    pos = sorted(list(seen))[0]
    seen.remove(pos)
    if pos == len(S):
        ok = True
        break

    part = S[pos:]
    if part.startswith('dream'):
        seen.add(pos + 5)
    if part.startswith('dreamer'):
        seen.add(pos + 7)
    if part.startswith('erase'):
        seen.add(pos + 5)
    if part.startswith('eraser'):
        seen.add(pos + 6)
if ok:
    print('YES')
else:
    print('NO')