#import <Foundation/Foundation.h>
#import <stdarg.h>

@interface StdIO : NSObject
+(NSMutableString*)stringFromStdIn; // 標準入力から NSString を得る
+(void)printf:(NSString*)format, ...; // 標準出力へ出力
@end

@implementation StdIO
+(NSMutableString*)stringFromStdIn
{
    NSFileHandle *handle = [NSFileHandle fileHandleWithStandardInput];
    NSMutableString *result = [NSMutableString string];
    NSData *data = [handle availableData];
    while ([data length] > 0) {
        [result appendString:[[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]];
        data = [handle availableData];
    }
    NSUInteger length = [result length];
    if (length >= 1 && [result characterAtIndex:length-1] == '\n') { // 入力末尾に改行文字があれば削除
        [result deleteCharactersInRange:NSMakeRange(length-1,1)];
    }
    return result;
}
+(void)printf:(NSString*)format, ...
{
    va_list arguments;
    va_start(arguments, format);
    NSString *string = [[[NSString alloc] initWithFormat:format arguments:arguments] autorelease];
    NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
    [fileHandle writeData:[string dataUsingEncoding:NSUTF8StringEncoding]];
    va_end(arguments);
}
@end

int main() {
    @autoreleasepool {
        NSString *S = [StdIO stringFromStdIn];
        NSUInteger length = [S length];
        NSArray *words = @[@"dream", @"erase", @"eraser", @"dreamer"];
        NSMutableArray *candidates = [NSMutableArray arrayWithObject:@0]; // 切断に成功している位置の候補を格納するキュー
        NSNumber *candidate;
        while ((candidate = [candidates shift])) {
            NSUInteger currentIndex = [candidate unsignedIntegerValue]; // 先頭候補を取り出し
            for (NSString *word in words) {
                NSUInteger size = [word length];
                if (currentIndex + size <= length) {
                    NSString *prefix = [S substringWithRange:NSMakeRange(currentIndex, size)];
                    if ([prefix isEqualToString: word]) {
                        if (currentIndex + size == length) { // ちょうど末尾にたどり着いたら終了
                            [StdIO printf:@"YES"];
                            return 0;
                        } else {
                            [candidates addObject:@(currentIndex + size)];
                        }
                    }
                }
            }
        }
        [StdIO printf:@"NO"];
    }
    return 0;
}
