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: Runtime Error

Solution code:
import sys

S = input()

while S:
    prefix = S[0:5]
    if prefix == 'dream':
        if S[5:7] == 'er':
            if len(S) > 8 and S[7] == 'a':
                S = S[5:]
            else:
                S = S[7:]
        else:
            S = S[5:]
    elif prefix == 'erase':
        if S[5] == 'r':
            S = S[6:]
        else:
            S = S[5:]
    else:
        print('NO')
        sys.exit(0)
    # print(S)
print('YES')

Submission status: Runtime Error

Solution code:
import sys

S = input()

while S:
    prefix = S[0:5]
    if prefix == 'dream':
        if S[5:7] == 'er':
            if S[7] == 'a':
                S = S[5:]
            else:
                S = S[7:]
        else:
            S = S[5:]
    elif prefix == 'erase':
        if S[5] == 'r':
            S = S[6:]
        else:
            S = S[5:]
    else:
        print('NO')
        sys.exit(0)
    # print(S)
print('YES')

Submission status: Runtime Error

Solution code:
import java.lang.*;
import java.io.*;
import java.util.*;


public class Main {
	
	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {
	
	public void solve(InputReader in, PrintWriter out) {
		final String dream = "dream";
		final String dreamer = "dreamer";
		final String erase = "erase";
		final String eraser = "eraser";
		final int dreamLen = dream.length();
		final int dreamerLen = dreamer.length();
		final int eraseLen = erase.length();
		final int eraserLen = eraser.length();
		
		final String s = in.next();
		final int slen = s.length();
		int i = 0, j;
		char ch;
		
		while (i < slen) {
			ch = s.charAt(i);
			if (ch!='d' && ch!='e') {
				out.println("NO");
				return;
			}
			
			boolean flag = false;
			
			if (ch == 'e') {
				if (i+eraserLen <= slen) {
					if (eraser.equals(s.substring(i, i+eraserLen))) {
						flag = true;
						i += eraserLen;
					}
				}
				if (!flag && i+eraseLen <= slen) {
					if (erase.equals(s.substring(i, i+eraseLen))) {
						flag = true;
						i += eraseLen;
					}
				}
			} else {
				if (i+dreamerLen<=slen && dreamer.equals(s.substring(i, i+dreamerLen))) {
					flag = true;
					if (i+dreamLen+eraseLen<=slen && erase.equals(s.substring(i+dreamLen, i+dreamLen+eraseLen))) {
						i += dreamLen;
					} else {
						i += dreamerLen;
					}
				} else if (i+dreamLen<=slen && dream.equals(s.substring(i, i+dreamLen))) {
					flag = true;
					i += dreamLen;
				}
			}
			
			if (!flag) {
				out.println("NO");
				return ;
			}
		}
		
		if (i == slen)
			out.println("YES");
		else
			out.println("NO");
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;
	
	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}
	
	public String next() {
		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
	
	public long nextLong() {
		return Long.parseLong(next());
	}
}

Submission status: Runtime Error

Solution code:
s = input()

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

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

# print(s,t)

tmp = s

while tmp != '':
    d = tmp[:5] == 'maerd'
    dr = tmp[:7] == 'remaerd'
    e = tmp[:5] == 'esare'
    er = tmp[:6] == 'resare'
    # print(tmp[:5])
    # print(d,dr,e,er)

    if d:
        tmp = tmp[5:]
    elif e:
        tmp = tmp[5:]
    elif dr:
        tmp = tmp[7:]
    elif er:
        tmp = tmp[6:]
    else:
        print('NO')
        break

if tmp == '':
    print('YES')

Submission status: Runtime Error

Solution code:
input = input()
# 前から一意に分解することができないので, 後ろから分解していくことになる
reversed_str = input[::-1]
dream = 'dream'
dreamer = 'dreamer'
erase = 'erase'
eraser = 'eraser'

dream = dream[::-1]
dreamer = dreamer[::-1]
erase = erase[::-1]
eraser = eraser[::-1]

def check(str):
    if str == '':
        return True

    if len(str) < 5:
        return False

    if str[0:5] == dream or str[0:5] == erase:
        check(str[5:])
        return True
    elif str[0:6] == eraser:
        check(str[6:])
        return True
    elif str[0:7] == dreamer:
        check(str[7:])
        return True

    return False

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

Submission status: Runtime Error

Solution code:
input = input()
"""
def check(str):
    # 終了条件が分からない

    str0 = str + 'dream'
    str1 = str + 'dreamer'
    str2 = str + 'erase'
    str3 = str + 'eraser'

    print(str)
    if str0 == input or str1 == input or str2 == input or str3 == input:
        return True

    check(str0)
    check(str1)
    check(str2)
    check(str3)

    return False



if check(''):
    print('YES')
else:
    print('NO')
# 再帰が深いとダメになる
"""
# 前から一意に分解することができないので, 後ろから分解していくことになる
reversed_str = input[::-1]
dream = 'dream'
dreamer = 'dreamer'
erase = 'erase'
eraser = 'eraser'

dream = dream[::-1]
dreamer = dreamer[::-1]
erase = erase[::-1]
eraser = eraser[::-1]

def check(str):
    if str == '':
        return True

    if len(str) < 5:
        return False

    if str[0:5] == dream or str[0:5] == erase:
        if check(str[5:]):
            return True
    elif str[0:6] == eraser:
        if check(str[6:]):
            return True
    elif str[0:7] == dreamer:
        if check(str[7:]):
            return True

    return False

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

Submission status: Runtime Error

Solution code:
S = raw_input()
S = S.strip("dream", "")
S = S.strip("dreamer", "")
S = S.strip("erase", "")
S = S.strip("eraser", "")

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

Submission status: Runtime Error

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

while len(S) > 0:
	flag = False
	for d in l:
		if S.endswith(d):
			S = S[:-len(d)]
			flag = True
			break
	if flag = False:
		print('NO')
		exit()
		
print('YES')

Submission status: Runtime Error

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

s = input()

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

Submission status: Runtime Error

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=""
DFS(list,s,t)
print("NO")

Submission status: Runtime Error

Solution code:
s = raw_input(); i = 0; d = 1
# dreamerase eraser
while i < len(s):
	if s.startswith(i,i+len('dreamerase')):
		i += len('dreamerase')
	elif s.startswith(i,i+len('dreameraser')):
		i += len('dreameraser')
	elif s.startswith(i,i+len('dream')):
		i += len('dream')
	elif s.startswith(i,i+len('dreamer')):
		i += len('dreamer')
	elif s.startswith(i,i+len('erase')):
		i += len('erase')
	elif s.startswith(i,i+len('eraser')):
		i += len('eraser')
	else:
		d = 0
if d == 1:
	print 'YES'
else:
	print 'NO'

Submission status: Runtime Error

Solution code:
#cording : utf-8

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

def check(str):
    if str is "":
        return True

    for s in strset:
        if str.startswith(s):
            if check(str.split(s,1)[1]):
                return True
    return False

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

Submission status: Runtime Error

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

DREAM = "dream"
DREAMER = "dreamer"
ERASE = "erase"
ERASER = "eraser"

text = input()

while(len(text) > 0):
    if text[-5:] == DREAM:
        text = text[:-5]
    elif text[-6:] == DREAMER:
        text = text[:-6]
    elif text[-5:] == ERASE:
        text = text[:-5]
    else:
        text = text[-6]
    if len(text) == 0:
        print("YES")
        break

Submission status: Runtime Error

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

DREAM = "dream"
DREAMER = "dreamer"
ERASE = "erase"
ERASER = "eraser"

text = input()

while(len(text):
    if text[-5:] == DREAM:
        text = text[:-5]
    elif text[-6:] == DREAMER:
        text = text[:-6]
    elif text[-5:] == ERASE:
        text = text[:-5]
    else:
        text = text[-6]
    if len(text) == 0:
        print("YES")

Submission status: Runtime Error

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: Runtime Error

Solution code:
#!/usr/bin/python

import re
import sys

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

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

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

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