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: Wrong Answer

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 'YES'
        sys.exit()
print 'NO'

Submission status: Wrong Answer

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 'NG'
        sys.exit()
print 'OK'

Submission status: Wrong Answer

Solution code:
import sys

s = input()

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

Submission status: Wrong Answer

Solution code:
import sys

s = input()

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

Submission status: Wrong Answer

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
		print "dreamer"
	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: Wrong Answer

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 = 'NO'
        break
        
print sol

Submission status: Wrong Answer

Solution code:
s = raw_input()

def func(st):
    head = st[:8]
    if head[5:8] == 'dre' or head[5:8] == 'era':
        return st[5:]
    elif head[5:8] == 'erd' or head[5:8] == 'ere':
        return st[7:]
    elif head[5:8] == 'rdr' or head[5:8] == 'rer':
        return st[6:]
    else:
        return ''

t = s
while True:
    if len(t) < 8:
        if t == 'dream' or t == 'erase' or t == 'dreamer' or t == 'eraser':
            print 'YES'
        else:
            print 'NO'
        break
    else:
        t = func(t)

Submission status: Wrong Answer

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 + 1 < 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: Wrong Answer

Solution code:
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()



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 < len(s):
				if s[ind] == 'e':
					if ind + 2 == len(s):
						if s[ind+1] == 'r':
							break
						else:
							ans = False
							break
					elif ind + 2 < len(s):
						if s[ind+1] == 'r' 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 + 1 < 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: Wrong Answer

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)>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: Wrong Answer

Solution code:
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()



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 < len(s):
				if s[ind] == 'e':
					if ind + 2 < len(s):
						if s[ind+1] == 'r' 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: Wrong Answer

Solution code:
t=raw_input()
#t=t.replace('eraser','').replace('dreamer','').replace('erase','').replace('dream','')
while len(t):
    if 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: Wrong Answer

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

print(solve(S))

Submission status: Wrong Answer

Solution code:
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()



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 < len(s):
				if s[ind] == 'r':
					ind += 1
		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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=raw_input()

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

Submission status: Wrong Answer

Solution code:
import re

S = raw_input()

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
s = s[::-1]
lis = ['remaerd', 'resare', 'esare', 'maerd']
i = 0
j = 0
#s = s[::-1]
while i < len(s):
    while True:
        tmp = s[i : j]
        #print(s[i : j])
        if len(tmp) == 8:
            print('NO')
            #quit()
        elif tmp in lis:
            i = j
            j = i + 5
            break
        else:
            j += 1
print('YES')

Submission status: Time Limit Exceeded

Solution code:
s = input()
s = s[::-1]
lis = ['remaerd', 'resare', 'esare', 'maerd']
i = 0
j = 0
#s = s[::-1]
while i < len(s):
    while True:
        #print(s[i : j])
        if len(s[i : j]) == 8:
            print('NO')
            #quit()
        elif s[i : j] in lis:
            i = j
            j = i + 5
            break
        else:
            j += 1
print('YES')

Submission status: Time Limit Exceeded

Solution code:
s = input()
s = s[::-1]
lis = ['remaerd', 'resare', 'esare', 'maerd']
i = 0
j = 0
#s = s[::-1]
while i < len(s):
    while True:
        #print(s[i : j])
        if len(s[i : j]) == 8:
            print('NO')
            #quit()
        elif s[i : j] in lis:
            i = j
            break
        else:
            j += 1
print('YES')

Submission status: Time Limit Exceeded

Solution code:
S = input()
lS = len(S)
f = ""
ans = "YES"
i = 0
while(i < lS):
    tmp = S[i:i+5]
    if (tmp == "erase"):
        f = "r"
        i += 5
        continue
    if (tmp == "dream"):
        f = "er"
        i += 5
        continue
    if (f == ""):
        ans = "NO"
        break
    tmp = S[i:i+len(f)]
    if (tmp == f):
        i += len(f)
        f = ""

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
while True:
    if len(S) < 5:
        print('NO')
        break
    s = S[:5]
    if s == 'dream' or s == 'erase':
        if len(S) == 5:
            print('YES')
            break
        if S[5] == 'r':
            S = S[6:]
        else:
            S = S[5:]
        if len(S) == 0:
            print('YES')
            break
    else:
        print('NO')

Submission status: Time Limit Exceeded

Solution code:
import sys
S = input()
num = len(S)
S = S + "zzzzzzzzzzzzzzzzzzzzzz"
cur = 0
while cur < num:
    if S[cur] == 'd':
        if S[cur:cur+11] == 'dreameraser':
            cur += 11
        elif S[cur:cur+10] == 'dreamerase':
            cur += 10
        elif S[cur:cur+7] == 'dreamer':
            cur += 7
        elif S[cur:cur+5] == 'dream':
            cur += 5
        else:
            print('NO')
            sys.exit()
    elif S[cur] == 'e':
        if S[cur:cur+6] == 'eraser':
            cur += 6
        elif S[cur:cur+5] == 'erase':
            cur += 5
        else:
            print('NO')
            sys.exit()
    if cur == num:
        print('YES')
        sys.exit()

Submission status: Time Limit Exceeded

Solution code:
import sys
S = input()
num = len(S)
S = S + "zzzzzzzzzzzzzzzzzzzzzz"
cur = 0
while 1:
    if S[cur] == 'd':
        if S[cur:cur+11] == 'dreameraser':
            cur += 11
        elif S[cur:cur+10] == 'dreamerase':
            cur += 10
        elif S[cur:cur+7] == 'dreamer':
            cur += 7
        elif S[cur:cur+5] == 'dream':
            cur += 5
        else:
            print('NO')
            sys.exit()
    elif S[cur] == 'e':
        if S[cur:cur+6] == 'eraser':
            cur += 6
        elif S[cur:cur+5] == 'erase':
            cur += 5
        else:
            print('NO')
            sys.exit()
    if cur >= num:
        print('YES')
        sys.exit()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

def solve(s):
    stack = deque()
    stack.append(s)
    while len(stack) > 0:
        top = stack.pop()
        if top == '':
            return 'YES'

        if top[:5] == 'dream':
            if top[5:7] == 'er':
                stack.append(top[7:])
            stack.append(top[:5])
        elif top[:5] == 'erase':
            if len(top) > 5 and top[5] == 'r':
                stack.append(top[6:])
            else:
                stack.append(top[5:])
    return 'NO'

print(solve(input()))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

def solve(s):
    que = deque()
    que.append(s)
    while len(que) > 0:
        top = que.pop()
        if top == '':
            return 'YES'

        if top[:5] == 'dream':
            if top[5:7] == 'er':
                que.append(top[:7])
            que.append(top[:5])
        elif top[:5] == 'erase':
            if len(top) > 5 and top[5] == 'r':
                que.append(top[:6])
            else:
                que.append(top[:5])
    return 'NO'

print(solve(input()))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

def solve(s):
    que = deque()
    que.append(s)
    while len(que) > 0:
        top = que.pop()
        if top == '':
            return 'YES'

        if top[:5] == 'dream':
            if top[5:7] == 'er':
                que.append(s[:7])
            que.append(s[:5])
        elif top[:5] == 'erase':
            if len(top) > 5 and top[5] == 'r':
                que.append(top[:6])
            else:
                que.append(top[:5])
    return 'NO'

print(solve(input()))

Submission status: Time Limit Exceeded

Solution code:
S = input()
lst = ["dreamer", "dream", "eraser", "erase"]
lst = [ "".join(list(reversed(k))) for k in lst]
S = "".join(list(reversed(S)))

i  = 0
while i < len(S):
    found = False
    for k in lst:
        try:
            if S[i:].index(k) == 0:
                found = True
                i += len(k)
                break
        except:
            continue

    if not found:
        print("NO")
        exit(0)
print("YES")

Submission status: Time Limit Exceeded

Solution code:
S = input()
lst = ["dreamer", "dream", "eraser", "erase"]
lst = [ "".join(list(reversed(k))) for k in lst]
S = "".join(list(reversed(S)))

i  = 0
while i < len(S):
    found = False
    for k in lst:
        try:
            # print("k: ",k, "i: ", i, "S[i:]: ", S[i:])
            if S[i:].index(k) == 0:
                found = True
                i += len(k)
                # print("FOUND! i  = ", i, ", S[i:] ", S[i:])
                break
        except:
            continue

    if not found:
        print("NO")
        exit(0)
print("YES")

Submission status: Time Limit Exceeded

Solution code:
s = input()
i = 0
while i <= len(s)-5:
  if len(s)-i >= 7:
    if s[i:i+5] == 'dream':
      if s[i+4:i+6] == 'er':
        i += 7
      else:
        i += 5
    elif s[i:i+5] == 'erase':
      if s[i+5] == 'r':
        i += 6
      else:
        i += 5
  elif len(s)-i == 6:
    if s[i:i+5] == 'erase':
      if s[i+5] == 'r':
        i += 6
      else:
        i += 5
  elif len(s)-i == 5:
    if s[i:i+5] == 'erase':
      i = len(s)
    elif s[i:i+5] == 'dream':
      i = len(s)
    else:
      i = len(s)+1
if i == len(s):
  print('YES')
else:
  print('NO')

Submission status: Time Limit Exceeded

Solution code:
s = input()
i = 0
t = ''
while i <= len(s)-5:
  if len(s)-i >= 7:
    if s[i:i+5] == 'dream':
      if s[i+4:i+6] == 'er':
        i += 7
        t += 'dreamer'
      else:
        i += 5
        t += 'dream'
    elif s[i:i+5] == 'erase':
      if s[i+5] == 'r':
        i += 6
        t += 'eraser'
      else:
        i += 5
        t += 'erase'
  elif len(s)-i == 6:
    if s[i:i+5] == 'erase':
      if s[i+5] == 'r':
        i += 6
        t += 'eraser'
      else:
        i += 5
        t += 'erase'
  elif len(s)-i == 5:
    if s[i:i+5] == 'erase':
      i = len(s)
      t += 'erase'
    elif s[i:i+5] == 'dream':
      i = len(s)
      t += 'dream'
    else:
      i = len(s)+1
if i == len(s):
  print('YES')
else:
  print('NO')

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Feb  8 05:12:38 2019

@author: shinjisu
"""


def db(x):
    global debug
    if debug:
        print(x)


# スタックオーバーフロー
def gen(tstr):
    if len(tstr) <= len(S):
        for w in words:
            yield tstr + w
            for w2 in gen(tstr + w):
                yield w2


def solve():
    ans = False
    for genstr in gen(''):
        db(genstr)
        if genstr == S:
            ans = True
            break
    return ans


def solve2():
    stack = list(words)
    while stack != []:
        str = stack.pop()
        db(('pop', str))
        if len(str) < len(S):
            for w in words:
                stack.append(str+w)
        elif len(str) == len(S) and str == S:
            return True
    return False


debug = False
words = ('dream', 'dreamer', 'erase', 'eraser')
S = input()
db(S)
if solve2():
    print('YES')
else:
    print('NO')

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
words = ["dreamer","eraser","dream","erase"]
i = 0
while i<len(s):
    if i<=len(s)-7 and s[i:i+7] == words[0]:
        i += 7
    elif i<=len(s)-6 and s[i:i+6] == words[1]:
        i += 6
    elif i<=len(s)-5 and s[i:i+5] in words:
        i += 5
    elif i>1 and s[i-2:i]=="er":
        if s[i:4]=="aser":
            i += 4
        elif s[i:3]=="ase":
            i += 3
    else:
        break
if i==len(s):
  print("YES")
else:
  print("NO")

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
words = ["dreamer","eraser","dream","erase"]
t = ""
i = 0
while i<len(s):
    if i<=len(s)-7 and s[i:i+7] == words[0]:
        t = t+words[0]
        i += 7
    elif i<=len(s)-6 and s[i:i+6] == words[1]:
        t = t+words[1]
        i += 6
    elif i<=len(s)-5 and s[i:i+5] in words:
        t = t+words[2] if s[i:i+5] == words[2] else t+words[3]
        i += 5
    elif i>1 and s[i-2:i]=="er":
        if s[i:4]=="aser":
            t += "aser"
            i += 4
        elif s[i:3]=="ase":
            t += "ase"
            i += 3
    else:
        break
if s==t:
  print("YES")
else:
  print("NO")

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(100000)
S = raw_input()
T = ""
t = ['dream','dreamer','erase','eraser']
def rec(T,S):
    if len(S) < len(T):
        return False
    if S==T:
        return True
    elif S[len(T)] == "e":
        return rec(T+t[2],S) or rec(T+t[3],S)
    elif S[len(T)] == "d":
        return rec(T+t[0],S) or rec(T+t[1],S)
    else:
        return False
if rec(T,S):
    print "YES"
else:
    print "NO"

Submission status: Time Limit Exceeded

Solution code:
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):]

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

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")

sys.setrecursionlimit(10**5)


def yes():
    print("YES")  # type: str


def no():
    print("NO")  # type: str


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


def dfs(s):
    if len(s) == 0:
        return True
    for t in template:
        if s.startswith(t):
            if dfs(s[len(t):]):
                return True
    return False


def solve(S: str):
    if dfs(S):
        yes()
    else:
        no()

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
ans = "NO"
s = input()


def dfs(s):
    ret = 0
    if len(s) == 0:
        return 1

    if s[:5] == 'dream' or s[:5] == 'erase':
        ret += dfs(s[5:])
    if s[:7] == 'dreamer':
        ret += dfs(s[7:])
    if s[:6] == 'eraser':
        ret += dfs(s[6:])
    return ret


if dfs(s):
    ans = "YES"
print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
words = ['dream', 'dreamer', 'erase', 'eraser']
stack = [0]
ans = "NO"
while stack:
  ind = stack.pop()
  if ind == N:
    ans = 'YES'
    break
  for w in words:
    end = ind+len(w)
    if S[ind:end] == w:
      stack.append(end)
print(ans)

Submission status: Accepted

Solution code:
s=input()
s=s[::-1]
tmp=['dream','dreamer', 'erase', 'eraser']
for i in range(4):
  tmp[i]=tmp[i][::-1]
while 1:
  if len(s)>=5:
    if s[:5]==tmp[0]:
      if len(s)>5:
        s=s[5:]
      else:
        s=[]
      continue
    if s[:5]==tmp[2]:
      if len(s)>5:
        s=s[5:]
      else:
        s=[]
      continue
    if len(s)>=6:
      if s[:6]==tmp[3]:
        if len(s)>6:
          s=s[6:]
        else:
          s=[]
        continue
      if len(s)>=7:
        if s[:7]==tmp[1]:
          if len(s)>7:
            s=s[7:]
          else:
            s=[]
          continue
  break

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
i = 0
while i < N:
    sig = 0
    S5 = S[i:i+5]
    if S5 == 'dream':
        sig = 1
        if S[i+5:i+7] == 'er' and S[i+7:i+8] != 'a':
            i += 2
        i += 5
    elif S5 == 'erase':
        sig = 1
        if S[i+5:i+6] == 'r':
            i += 1
        i += 5
    if sig == 0:
        sig = 2
        Answer = 'NO'
        break
if sig != 2:
    Answer = 'YES'
print(Answer)

Submission status: Accepted

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

while i<n:
  if s[i:i+10]=="dreamerase":
    i+=5
  elif s[i:i+7]=="dreamer":
    i+=7
  elif s[i:i+5]=="dream":
    i+=5
  elif s[i:i+6]=="eraser":
    i+=6
  elif s[i:i+5]=="erase":
    i+=5
  else:
    break
print("YES" if i==n else "NO")

Submission status: Accepted

Solution code:
s=input()
s=s.replace('eraser','#')
s=s.replace('erase','#')
s=s.replace('dreamer','#')
s=s.replace('dream','#')
f=0
for i in s:
    if(i!='#'):
        f=1
        break
if(f==0):
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
s=s.replace('eraser','#')
s=s.replace('erase','#')
s=s.replace('dreamer','#')
s=s.replace('dream','#')
f=1
for it in s:
    if it !='#':
        f=0
        break

if f==1:
    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","*")
f=1
for i in s:
    if i!='*':
        f=0
        break
if f:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    
    S = input().rstrip()

    limit = len(S)//5

    while limit>0 and len(S)>0:
        if S.endswith('dreamer'):
            S = S[:len(S)-7]
        elif S.endswith('eraser'):
            S = S[:len(S)-6]
        elif S.endswith('dream'):
            S = S[:len(S)-5]
        elif S.endswith('erase'):
            S = S[:len(S)-5]
        limit-=1
    
    print('NO' if S else 'YES')

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
s=input(str())
lst=["eraser","erase","dreamer","dream"]
for t in lst:
    s=s.replace(t,"")
if s=="":
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s=(input())[::-1]
T=["dream", "dreamer", "erase","eraser"]
T=[x[::-1] for x in T]
cur=""
for e in s:
    cur+=e
    if(cur in T):
        cur=""
print("YES" if cur=="" else "NO")

Submission status: Accepted

Solution code:
from itertools import product, takewhile


def main():
    words = ["eraser", "erase",  "dreamer", "dream"]
    S = input()[::-1]
    for word in words:
        S = S.replace(word[::-1], '')
    # print(S)
    if len(S) > 0:
        print("NO")
    else:
        print("YES")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    S = input()
    S = S[::-1]
    d = ['maerd', 'remaerd', 'esare', 'resare']

    f = False
    while True:
        for di in d:
            if S.startswith(di):
                f = False
                S = S.replace(di, '', 1)

        if f:
            break
        f = True


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

#n,*a = map(int,readline().split())

"""
a = "dream"[::-1]
b = "dreamer"[::-1]
c = "erase"[::-1]
d = "eraser"[::-1]
"""
s = [*input()]
a = [*"dream"]
b = [*"dreamer"]
c = [*"erase"]
d = [*"eraser"]

while True:
    if not s:
        print("YES")
        break
    elif s[-5:] == a:
        for _ in range(5): s.pop()
    elif s[-5:] == c:
        for _ in range(5): s.pop()
    elif s[-7:] == b:
        for _ in range(7): s.pop()
    elif s[-6:] == d:
        for _ in range(6): s.pop()
    else:
        print("NO")
        break

Submission status: Accepted

Solution code:
s = input()
x = 0
a = s.count("dream")
b = s.count("dreamer")
c = s.count("erase")
d = s.count("eraser")
reigai1 = s.count("dreamerase")
reigai2 = s.count("dreameraser")
reigai1 = reigai1-reigai2
b = b-reigai1-reigai2
a = a-reigai1-reigai2
c = c-reigai1-reigai2
d = d-reigai2
a2 = a-b
c2 = c-d
# print(a,b,c,d)
# print(a2,c2)
# print(reigai1,reigai2)
# print(a2*5+b*7+c2*5+d*6+reigai1*10+reigai2*11)
if a2*5+b*7+c2*5+d*6+reigai1*10+reigai2*11 == len(s):
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = str(input())

S = S.replace('dream', '#')
S = S.replace('erase', '.')
S = S.replace('#er', '')
S = S.replace('.r', '')
S = S.replace('#', '')
S = S.replace('.', '')

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ar = list(input())
l = len(ar)
if l < 5:
    print('NO')
else:
    while True:
        if l == 0:
            print("YES")
            exit()
        if "".join(ar[l-5:l]) == 'dream' or "".join(ar[l-5:l]) == 'erase':
            l -= 5
        elif "".join(ar[l-6:l]) == 'eraser':
            l -= 6
        elif "".join(ar[l-7:l]) == 'dreamer':
            l -= 7
        else:
            print("NO")
            exit()

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]
hoge = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
j = 0
while i < len(s):
    ans = ''
    while j < len(s):
        ans += s[j]
        if len(ans) > 7:
            print('NO')
            quit()
        if ans in hoge:
            break
        else:
            j += 1
    j += 1
    i = j
print('YES')

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]
lis = ['remaerd', 'resare', 'esare', 'maerd']
i = 0
j = 0
#s = s[::-1]
while i < len(s):
    tmp = ''
    while j < len(s):
        tmp += s[j]
        #print(tmp)
        if len(tmp) == 8:
            print('NO')
            quit()
        elif tmp in lis:
            i = j + 1
            j = i
            break
        else:
            j += 1
print('YES')

Submission status: Accepted

Solution code:
s = input()
n = len(s)
idx = 0
while idx < n:
    if idx+5 > n:
        break
    if s[idx:idx+5] == 'dream':
        idx += 5
        if idx+2 <= n and s[idx:idx+2] == 'er' and (idx+2 == n or s[idx+2:idx+3] != 'a'):
            idx += 2
    elif s[idx:idx+5] == 'erase':
        idx += 5
        if idx+1 <= n and s[idx:idx+1] == 'r':
            idx += 1
    else:
        break

if idx == n:
    print('YES')
else:
    print('NO')

Submission status: Accepted

Solution code:
S = input()
T = ""
SS = S[::-1]
d = "maerd"
dd = "remaerd"
e = "esare"
ee = "resare"

cnt1 = 0
cnt2 = 5
for i in range(4, len(S)):
    if(SS[cnt1:cnt2] == dd):
        T += dd
        cnt1 = cnt2
        cnt2 +=1
    elif(SS[cnt1:cnt2] == ee):
        T += ee
        cnt1 = cnt2
        cnt2 += 1
    elif(SS[cnt1:cnt2] == d):
        T += d
        cnt1 = cnt2
        cnt2 += 1
    elif(SS[cnt1:cnt2] == e):
        T += e
        cnt1 = cnt2
        cnt2 += 1
    else:
        cnt2 += 1
    
print("YES" if S == T[::-1] else "NO")

Submission status: Accepted

Solution code:

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

l = ['maerd','remaerd','esare','resare']
i = 0
while i < len(S):
    for w in l:
        if w == S[i:i+len(w)]:
            i += len(w)
            break
    else:
        print('NO')
        exit()
print('YES')

Submission status: Accepted

Solution code:
s=input()

while len(s)>0:
    if s[-5:] in ["dream","erase"]: s=s[:-5]
    elif s[-6:]=="eraser": s=s[:-6]
    elif s[-7:]=="dreamer": s=s[:-7]
    else: break


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

Submission status: Accepted

Solution code:
S=input()
T=""
l=["maerd","remaerd","esare","resare"]
flag=True
for i in range(len(S)):
    T=T+S[len(S)-1-i]
    if T in l:
        T=""
    if len(T)>7:
        flag=False
        break
if flag:
    print("YES")
else:
    print("NO")