Problem:


Score : 300 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Another string T is initially empty.
Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:

Append one of the following at the end of T: dream, dreamer, erase and eraser.

Constraints

1≦|S|≦10^5

S consists of lowercase English letters.

Input

The input is given from Standard Input in the following format:

S

Output

If it is possible to obtain S = T, print YES. Otherwise, print NO.

Sample Input 1

erasedream

Sample Output 1

YES

Append erase and dream at the end of T in this order, to obtain S = T.

Sample Input 2

dreameraser

Sample Output 2

YES

Append dream and eraser at the end of T in this order, to obtain S = T.

Sample Input 3

dreamerer

Sample Output 3

NO



Sample input:
erasedream


Sample output:
YES

Submission status: Accepted

Solution code:
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    S = input()
    pos = len(S)

    while pos > 0:
        if S[pos - 5:pos] == 'dream' or S[pos - 5:pos] == 'erase':
            pos -= 5
        elif S[pos - 7:pos] == 'dreamer':
            pos -= 7
        elif S[pos - 6:pos] == 'eraser':
            pos -= 6
        else:
            print('NO')
            return None

    print('YES')


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
s = input()

def day_dream(s):
    while not s == "":
        if s[-7:] == "dreamer":
            s = s[:-7]
        elif s[-6:] == "eraser":
            s = s[:-6]
        elif s[-5:] == "dream" or s[-5:] == "erase":
            s = s[:-5]
        else:
            return "NO"
    return "YES"

print(day_dream(s))

Submission status: Accepted

Solution code:
import re

S = input()
x = r"^(dream|dreamer|erase|eraser)*$"

if re.match(x,S):
	print('YES')
else:
	print('NO')

Submission status: Accepted

Solution code:
S = input()

dreamdeleted=False

while len(S) > 0:
    if dreamdeleted == True:
        if S[0:6] == 'eraser':
            S = S[6:len(S)]
            dreamdeleted=False
            continue
        if S[0:5] == 'erase':
            S = S[5:len(S)]
            dreamdeleted=False
            continue
        if S[0:2] == 'er':
            S = S[2:len(S)]
            dreamdeleted=False
            continue
    if S[0:6] == 'eraser':
        S = S[6:len(S)]
        continue
    if S[0:5] == 'dream':
        S = S[5:len(S)]
        dreamdeleted = True
        continue
    if S[0:5] == 'erase':
        S=S[5:len(S)]
        continue
    print('NO')
    break
if len(S) == 0:
    print ('YES')

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
import re
S = input()
a = re.sub(r'eraser', '', S)
b = re.sub(r'erase', '', a)
c = re.sub(r'dreamer', '', b)
d = re.sub(r'dream', '', c)
if len(d) == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = raw_input() + "end!"

def solve():
    pos = 0
    while True:
        plus_one_flag = 0
        if S[pos:pos+5] == "dream":
            pos += 5
        elif S[pos:pos+5] == "erase":
            pos += 4
            plus_one_flag = 1
        elif S[pos:pos+6] == "end!":
            return True
        else:
            return False

        if S[pos:pos+4] == "erer" or S[pos:pos+4] == "erdr" or S[pos:pos+4] == "eren":
            pos += 2
            plus_one_flag = 0
        pos += plus_one_flag

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

Submission status: Accepted

Solution code:
S = input()
T = ''
for i in range(int(len(S)/5)+1):
    if len(S) != len(T):
        if S[len(S)-len(T)-1] == 'm':
            T = 'dream' + T
        elif S[len(S)-len(T)-1] == 'e':
            T = 'erase' + T
        elif S[len(S)-len(T)-3:len(S)-len(T)] == 'mer':
            T = 'dreamer' + T
        elif S[len(S)-len(T)-3:len(S)-len(T)] == 'ser':
            T = 'eraser' + T
        else:
            break

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

Submission status: Accepted

Solution code:
import re

S = input()

x = r"^(dream|dreamer|erase|eraser)*$"

if re.match(x, S):
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
words = ("dream", "erase", "eraser", "dreamer")

s = input()

while len(s) > 0:
    match = False
    for w in words:
        if s.endswith(w):
            s = s[:-len(w)]
            match = True
            break
    if match is False:
        print("NO")
        exit()
print("YES")

Submission status: Accepted

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

while e > 0:
    if e >= 5 and (s[e-5:e] == 'dream' or s[e-5:e] == 'erase'):
        e -= 5
    elif e >= 6 and s[e-6:e] == 'eraser':
        e -= 6
    elif  e >= 7 and s[e-7:e] == 'dreamer':
        e -= 7
    else:
        break

if e == 0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
import re

text = input()
obj = re.match("^(dream|dreamer|erase|eraser)+$", text)
if obj:
    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 = raw_input()[::-1]
while len(s):
    if s.startswith("maerd"):
        s = s[5:]
    elif s.startswith("remaerd"):
        s = s[7:]
    elif s.startswith("esare"):
        s = s[5:]
    elif s.startswith("resare"):
        s = s[6:]
    else:
        print "NO"
        exit()
print "YES"

Submission status: Accepted

Solution code:
s = str(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:
import sys

s = input()

while len(s) != 0:
    if s.endswith('dream') or s.endswith('erase'):
        s = s[:-5]
    elif s.endswith('eraser'):
        s = s[:-6]
    elif s.endswith('dreamer'):
        s = s[:-7]
    else:
        print('NO')
        sys.exit()

print('YES')

Submission status: Accepted

Solution code:
#import library
import re

#prepare
S = ''
T = ''
regex = r'(dream|dreamer|erase|eraser)+$'

#input
S = raw_input()

#output
if re.match(regex,S):
    print 'YES'
else:
    print 'NO'

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class DayDream:

    def is_possible(self, S):

        S = S[::-1]

        candidates = ["dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1]]

        idx = 0
        while idx < len(S):
            
            if S[idx:idx+5] in candidates:
                idx += 5

            elif S[idx:idx+6] in candidates:
                idx += 6

            elif S[idx:idx+7] in candidates:
                idx += 7

            else:
                return "NO"

        return "YES"

if __name__ == "__main__":

    S = raw_input()

    abc = DayDream()
    print abc.is_possible(S)

Submission status: Accepted

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

que = []
que.append(0)
while len(que) > 0:
    i = que.pop()
    if i == len(S):
        print "YES"
        exit()
    for d in D:
        ld = len(d)
        if S[i:i+ld] == d:
            que.append(i+ld)
print "NO"

Submission status: Accepted

Solution code:
str_list = ["dream","dreamer","erase","eraser"]

class stringJudge():
    def __init__(self,string,string_list):
        self.string = string
        self.string_list = string_list
        
    def isNextMatch(self):
        for str_val in self.string_list:
            if self.string.endswith(str_val):
                self.string = self.string.rsplit(str_val,1)[0]
                return True
        return False
               
                    
                    
           
    
instance = stringJudge(input(),str_list)
check = True
while check and len(instance.string) > 0:
    check = instance.isNextMatch()

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

Submission status: Accepted

Solution code:
str_list = ["dream","erase","er","ase","r",]

class stringJudge():
    def __init__(self,string,string_list):
        self.string = string
        self.string_list = string_list
        
    def isNextMatch(self):
        for (i,str_val) in enumerate(str_list):
            if self.string.startswith(str_val):
                self.string = self.string.split(str_val,1)[1]
                if len(self.string) == 0:
                    return True
                if i ==0:
                    if self.string.startswith(self.string_list[0]) or self.string.startswith(self.string_list[2]):
                        return True
                elif i == 1:
                    if self.string.startswith(self.string_list[0]) or self.string.startswith(self.string_list[1]) or self.string.startswith(self.string_list[4]):
                        return True
                elif i == 2:
                    if self.string.startswith(self.string_list[0]) or self.string.startswith(self.string_list[1]) or self.string.startswith(self.string_list[3]):
                        return True
                elif i == 3:
                    if self.string.startswith(self.string_list[0]) or self.string.startswith(self.string_list[1])  or self.string.startswith(self.string_list[4]):
                        return True
                elif i == 4:
                    if self.string.startswith(self.string_list[0]) or self.string.startswith(self.string_list[1]):
                        return True
        return False
                    
                    
           
    
instance = stringJudge(input(),str_list)
check = True
while check and len(instance.string) > 0:
    check = instance.isNextMatch()

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

Submission status: Accepted

Solution code:
S = input()
W = ["dream","dreamer","erase","eraser"]
while len(S) >= 5:
	if len(S) >= 7 and S[-7:] in W:
		S = S[:-7]
	elif len(S) >= 6 and S[-6:] in W:
		S = S[:-6]
	elif S[-5:] in W:
		S = S[:-5]
	else:
		print("NO")
		exit()
if not S:
	print("YES")
else:
	print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def DFS(list,s,t):
    if s==t:
        print("YES")
        sys.exit()
    if not t in s:
        return

    for i in list:
        DFS(list,s,t+i)

list=["maerd","remaerd","esare","resare"]
s=input()
s=s[::-1]
t=""
c_index=0
while True:
    moto=c_index
    for i in list:
        index=0
        temp=c_index
        while index<len(i) and temp<len(s) and i[index]==s[temp]:
            index+=1
            temp+=1
        if index==len(i):
            c_index=temp
            break
    if c_index==len(s):
        print("YES")
        sys.exit()
    if c_index==moto:
        print("NO")
        sys.exit()

Submission status: Accepted

Solution code:
s = raw_input()

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

while len(s) >= 5 and flag:
  for i in range(len(words)):
    if s[-len(words[i]):] == words[i]:
      s = s[:-len(words[i])]
      break
  else:
    flag = False
    print 'NO'
    break

if flag:
  print 'YES'

Submission status: Accepted

Solution code:
s=input()

while True:
    if s[-5::]=="dream":
        s=s[:-5:]
    elif s[-7::]=="dreamer":
        s=s[:-7:]
    elif s[-5::]=="erase":
        s=s[:-5:]
    elif s[-6::]=="eraser":
        s=s[:-6:]
    else:
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = raw_input()
S.replace("a","sine")
if "eraser" in S:
    S=S.replace("eraser", "")
if "erase" in S:
    S=S.replace("erase", "")
if "dreamer" in S:
    S=S.replace("dreamer", "")
if "dream" in S:
    S=S.replace("dream","")
print "YES" if len(S)==0 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', '')
if s == "":
    print("YES")
else:print("NO")

Submission status: Accepted

Solution code:
s = input()
flag = 1
i = 0

while i < len(s):
    if s[i:i+5] == 'dream':
        if s[i+5:i+10] != "erase" and s[i+5:i+7] == "er":
            i += 7
        elif s[i+5:i+11] == "eraser":
            i += 11
        elif s[i+5:i+10] == "erase":
            i += 10
        else:
            i += 5
    elif s[i:i+6] == "eraser":
        i += 6
    elif s[i:i+5] == "erase":
        i += 5
    else:
        flag = 0
        break

if(flag == 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', '')
 
if s == "":
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = input()
head = 0
dreameraser = ["dream","dreamer","erase","eraser"]
for i in range(len(s)):
    for word in dreameraser:
        head = len(s) - len(word)
        cut = s[head:head+len(word)]
#        print(cut)
        if cut in dreameraser:
            s = s[0:head]
if s == "":
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
s = input()

t = ""

a = "dream"
b = "dreamer"
c = "erase"
d = "eraser"

s = s.replace(d,"")
s = s.replace(c,"")
s = s.replace(b,"")
s = s.replace(a,"")

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

Submission status: Accepted

Solution code:
s =raw_input()[::-1]
t = map (lambda x:x[::-1], ["eraser","erase","dreamer","dream"])
for var in t:
    s = s.replace(var,"")
if s == "":
    print "YES"
else :
    print "NO"

Submission status: Accepted

Solution code:
import re
import sys
s = input()
while True:
    if s[-5:] in ['dream', 'erase']:
        s = s[0:-5]
    elif s[-6:] in ['eraser']:
        s = s[0:-6]
    elif s[-7:] in ['dreamer']:
        s = s[0:-7]
    else:
        if s == '':
            print('YES')
            sys.exit()
        else:
            print("NO")
            sys.exit()

Submission status: Accepted

Solution code:
#ABC049C

s=raw_input()
t=s.replace('eraser','')
u=t.replace('erase','')
v=u.replace('dreamer','')
w=v.replace('dream','')
#print w
if len(w)==0:
 print 'YES'
else:
 print 'NO'

Submission status: Accepted

Solution code:
S = input()
w1="dream"
w2="dreamer"
w3="erase"
w4="eraser"
S=S.replace(w4,"").replace(w3,"").replace(w2,"").replace(w1,"")
if len(S)==0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

preS=''
while len(S)!=0 and S!=preS:
    preS = S;
    pre = S[:7]
    if pre[:7][::-1] == 'dreamer':
        S=S[7:]
    elif pre[:6][::-1] == 'eraser':
        S=S[6:]
    elif pre[:5][::-1] == 'dream':
        S=S[5:]
    elif pre[:5][::-1] == 'erase':
        S=S[5:]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
while True:
    temp = s[:5]
    s = s[5:]
    if temp == 'erase':
        if s[0:1] == 'r':
            s = s[1:]
            continue
        else:
            continue
    elif temp == 'dream':
        if s[:5] == 'erase':
            continue
        elif s[:2] == 'er':
            s = s[2:]
            continue
    elif temp == '':
        print('YES')
        break
    else:
        print('NO')
        break

Submission status: Accepted

Solution code:
from Queue import * # Queue, LifoQueue, PriorityQueue
from bisect import * #bisect, insort
from collections import * #deque, Counter,OrderedDict,defaultdict
#set([]) 
import math
import copy
import itertools
import string
import sys
myread = lambda : map(int,raw_input().split())
def solver():
    S = raw_input()
    while S:
        if S[-5:] == "dream":
            S = S[:-5]
        elif S[-7:] == "dreamer":
            S = S[:-7]
        elif S[-5:] == "erase":
            S = S[:-5]
        elif S[-6:] == "eraser":
            S = S[:-6]
        else:
            print "NO"
            return
    print "YES"
if __name__ == "__main__":
    solver()

Submission status: Accepted

Solution code:
a=["eraser","erase","dreamer","dream"]
s=input()
 
for i in range(4):
    s=s.replace(a[i],"")
if s=="":
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
#!/usr/bin/python

import sys

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

def check(s):
    token = s

    while token:
        if token in TOKENS:
            return "YES"

        if len(token) > 5 and token[-5:] in [TOKENS[0], TOKENS[2]]:
            token = token[0:-5]
        elif len(token) > 6 and token[-6:] == TOKENS[3]:
            token = token[0:-6]
        elif len(token) > 7 and token[-7:] == TOKENS[1]:
            token = token[0:-7]
        else:
            return "NO"

def main(argv):
    for line in sys.stdin:
        print check(line.rstrip("\n"))

if __name__ == "__main__":
    main(sys.argv)

Submission status: Accepted

Solution code:
S = input()
L = len(S)
index = L-1
flag = 0
searching = 0

while index> 0:
    if S.rfind('dreamer',0,index+1) == index-6 and S.rfind('dreamer',0,index+1) != -1:
        index = index - 7
        #print('0 index = '+ str(index))
        if index == -1 :
            flag = 1
            break;
        
    elif S.rfind('eraser',0,index+1) == index-5 and S.rfind('eraser',0,index+1) != -1:

        index = index - 6
        #print('1 index = '+ str(index))
        if index == -1 :
            flag = 1
            break;
    else:
        s1 = S.rfind('dream',0,index+1)  
        s2 = S.rfind('erase',0,index+1)
        if (s1 != -1 or s2 != -1 )and(s1==index-4 or s2 ==index-4):
            

            index = index -5
            #print('2 index = '+ str(index))
            if index  == -1 :
                flag = 1
                break;
        else :
            break;


if flag == 1:
    print('YES')
else :
    print('NO')

Submission status: Accepted

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

import sys

def match(s):
    if s[:7] == 'dreamer':
        if len(s) > 7 and s[7] == 'a':
            return 5
        else:
            return 7
    if s[:6] == 'eraser':
        return 6
    if s[:5] == 'dream' or s[:5] == 'erase':
        return 5
    return -1

def main():
    s = raw_input()
    offset = 0
    while offset < len(s):
        n = match(s[offset:])
        if n == -1:
            print 'NO'
            sys.exit()
        offset += n
    print 'YES'

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=raw_input()
l=s.split('eraser')
s=''
for i in l:
    s=s+i
l=s.split('erase')
s=''
for i in l:
    s=s+i
l=s.split('dreamer')
s=''
for i in l:
    s=s+i
l=s.split('dream')
if(l.count('')==len(l)):
    print 'YES'
else:
    print 'NO'

Submission status: Accepted

Solution code:
import re
input_line = input()[::-1]
if len("".join(re.findall('resare|remaerd|esare|maerd|',input_line))) == len(input_line):
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

TS = ['dream','dreamer','erase','eraser']
I = itertools.permutations(TS)
L = list(I)

S = raw_input()
res = []
for i in range(len(L)):
    Sn = S
    for j in range(4):
        Sn = Sn.replace(L[i][j],"")
    res.append(len(Sn))

if min(res) == 0:
    print "YES"
else:
    print "NO"

Submission status: Accepted

Solution code:
s = input()
flag = 1
i = 0

while i < len(s):
    if s[i:i+5] == 'dream':
        if s[i+5:i+10] != "erase" and s[i+5:i+7] == "er":
            i += 7
        elif s[i+5:i+11] == "eraser":
            i += 11
        elif s[i+5:i+10] == "erase":
            i += 10
        else:
            i += 5
    elif s[i:i+6] == "eraser":
        i += 6
    elif s[i:i+5] == "erase":
        i += 5
    else:
        flag = 0
        break

if(flag == 1):
    print("YES")
else:
    print("NO")

Submission status: Accepted

Solution code:
S = input()


while len(S)!=0:
    if S[-7:]=="dreamer":
        S=S[:-7]
    elif S[-6:]=="eraser":
        S=S[:-6]
    elif S[-5:]=="dream" or S[-5:]=="erase":
        S=S[:-5]
    else:
        break


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

Submission status: Accepted

Solution code:
#coding:utf-8
import math
import string
import time
import fractions

s = raw_input()

if len(s) < 5:
	print 'NO'

else:
	while True:
		tmp = len(s)
		if s[-6:] == 'eraser':
			s = s[:-6]
		elif s[-7:] == 'dreamer':
			s = s[:-7]
		elif s[-5:] == 'dream' or s[-5:] == 'erase':
			s = s[:-5]

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

Submission status: Accepted

Solution code:
import re
r=re.compile("^(dream|eraser|dreamer|erase)*$")
if r.match(raw_input()):
    print "YES"
else:
    print "NO"

Submission status: Accepted

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

while 1:
    if len(S) == 0:
        res = 1
        break
    elif S[:5] == 'maerd':
        S = S[5:]
    elif S[:5] == 'esare':
        S = S[5:]
    elif S[0] == 'r':
        if S[:7] == 'remaerd':
            S = S[7:]
        elif S[:6] == 'resare':
            S = S[6:]
        else:
            res = 0
            break
    else:
        res = 0
        break

if res == 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","")
if len(s)==0:
    print("YES")
else:
    print("NO")

Submission status: Accepted

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

s = input()
f = True
while(f):
    if(re.search('dreameraser', s)):
        s = re.sub('dreameraser', '', s)
    elif(re.search('dreamerase', s)):
        s = re.sub('dreamerase', '', s)
    elif(re.search('dreamer', s)):
        s = re.sub('dreamer', '', s)
    elif(re.search('dream', s)):
        s = re.sub('dream', '', s)
    elif(re.search('eraser', s)):
        s = re.sub('eraser', '', s)
    elif(re.search('erase', s)):
        s = re.sub('erase', '', s)
    else:
        f = False
print("NO" if len(s) > 0 else "YES")

Submission status: Accepted

Solution code:
s = input()

ans = 'YES'

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

print(ans)

Submission status: Accepted

Solution code:
s = input()

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

while len(s) > 4:
    if s[-5:] == 'dream':
        s = s[:-5]
        continue
    elif s[-7:] == 'dreamer':
        s = s[:-7]
        continue
    elif s[-5:] == 'erase':
        s = s[:-5]
        continue
    elif s[-6:] == 'eraser':
        s = s[:-6]
        continue
    else:
        break

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

Submission status: Accepted

Solution code:
#!/usr/bin/python

import re
import sys

PATTERN = re.compile("(dream|dreamer|erase|eraser)+$")

def main(argv):
    for line in sys.stdin:
        s = line.rstrip("\n")
        if PATTERN.match(s):
            print "YES"
        else:
            print "NO"

if __name__ == "__main__":
    main(sys.argv)

Submission status: Accepted

Solution code:
a = raw_input()

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

while len(a) > 0:
	if a[:7] == 'dreamer' and a[:8][-1] != 'a':
		a = a[7:]
	elif a[:6] == 'eraser':
		a = a[6:]
	elif a[:5] in ['dream', 'erase']:
		a = a[5:]
	else:
		print "NO"
		break

if len(a) == 0:
	print "YES"

Submission status: Accepted

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

Submission status: Runtime Error

Solution code:
S = list(input())

def hantei(S):
    flag = True
    if S[0:5] == list('dream'):
        del(S[0:5])
        if S[0:2] == list('er') and S[2] != 'a':
            del(S[0:2])
    elif S[0:5] == list('erase'):
        del(S[0:5])
        if S[0:1] == list("r"):
            del(S[0])
    else:
        flag = False
    return S, flag

S, flag = hantei(S)
while flag == True:
    if len(S) == 0:
        print("YES")
        break
    S, flag = hantei(S)
if flag == False:
    print("NO")

Submission status: Runtime Error

Solution code:
S = list(input())

def hantei(S):
    flag = True
    if S[0:5] == list('dream'):
        del(S[0:5])
        if S[0:2] == list('er') and S[2] != 'a':
            del(S[0:2])
    elif S[0:5] == list('erase'):
        del(S[0:5])
        if S[0:1] == list("r"):
            del(S[0])
    else:
        flag = False
    return S, flag

flag = True
while flag == True:
    if len(S) == 0:
        print("YES")
        break
    S, flag = hantei(S)
if flag == False:
    print("NO")

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int,input().split()))
ans = 10**9
for i in range(-100,101):
  tmp = 0
  for a in A:
    tmp += (a-i)**2
  ans = min(ans, tmp)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def solver(T):
    if T == "":
        print("YES")
        quit()
    if len(T) >= 5:
        if T[:5] == "dream" or T[:5] == "erase":
            solver(T[5:])
    if len(T) >= 6:
        if T[:6] == "eraser":
            solver(T[6:])
    if len(T) >= 7:
        if T[:7] == "dreamer":
            solver(T[7:])
    return


def main():
    S = input()
    # 再帰的に解いて解く

    solver(S)
    print("NO")
    return


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    # 再帰的に解いて解く

    def solver(T):
        if T == "":
            print("YES")
            quit()
        if len(T) >= 5:
            if T[:5] == "dream" or T[:5] == "erase":
                solver(T[5:])
        if len(T) >= 6:
            if T[:6] == "eraser":
                solver(T[6:])
        if len(T) >= 7:
            if T[:7] == "dreamer":
                solver(T[7:])
        return

    solver(S)
    print("NO")
    return


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    # 再帰的に解いて解く

    def solver(T):
        if T == "":
            print("YES")
            quit()
        if len(T) >= 5:
            if T[:5] == "dream" or T[:5] == "erase":
                solver(T[5:])
        if len(T) >= 6:
            if T[:6] == "eraser":
                solver(T[6:])
        if len(T) >= 7:
            if T[:7] == "dreamer":
                solver(T[7:])
        return

    solver(S)
    print("NO")
    return


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
S = input()

def is_equal_to(str, start_ind):
    words = ["dream", "dreamer", "erase", "eraser"]
    if start_ind == len(str):
        return True
    for i in range(len(words)):
        if str[start_ind : start_ind+len(words[i])] == words[i]:
            if is_equal_to(str, start_ind+len(words[i])):
                return True
    return False

if is_equal_to(S, 0):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
S = input()

def is_equal_to(str, start_ind):
    words = ["dream", "dreamer", "erase", "eraser"]
    if start_ind == len(str):
        return True
    for i in range(len(words)):
        if str[start_ind : start_ind+len(words[i])] == words[i]:
            if is_equal_to(str, start_ind+len(words[i])):
                return True

if is_equal_to(S, 0):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
S = input()
i = 0
while i <= len(S)-5:
    if S[i:i+5] == "dream":
        i += 5
        if S[i:i+2] == "er" and S[i:i+5] != "erase":
            i += 2
    elif S[i:i+5] == "erase":
        i += 5
        if S[i] == "r":
            i += 1
    else:
        break
if i != len(S):
    print("NO")
else:
    print("YES")