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

Solution (Python):
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"

Solution (Python):
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")

Solution (Python):
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")

Solution (Python):

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

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

Solution (Python):
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')

Solution (Python):
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")

Solution (Python):

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

Solution (Python):
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)

Solution (Python):
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')

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

Solution (Python):
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"

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