public static void main ( String [ ] args ) throws Exception {
  String array [ ] = new String [ ] {
    "dreamer" , "dream" , "eraser" , "erase" };
    BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ;
    String str = br . readLine ( ) ;
    int start = 0 ;
    int last = - 1 ;
    while ( start < str . length ( ) && start >= 0 ) {
      boolean flag = false ;
      for ( int j = 0 ;
      j < 4 ;
      j ++ ) {
        if ( match ( array [ j ] , start , str ) ) {
          start += array [ j ] . length ( ) ;
          flag = true ;
          last = j ;
          break ;
        }
      }
      if ( ! flag && last == 0 ) {
        start -= 2 ;
        last = - 1 ;
      }
      else if ( ! flag ) break ;
    }
    if ( start == str . length ( ) ) System . out . println ( "YES" ) ;
    else System . out . println ( "NO" ) ;
  }
  
public static void main ( String [ ] args ) throws Exception { String array [ ] = new String [ ] { " dreamer " , " dream " , " eraser " , " erase " } ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; int start = 0 ; int last = - 1 ; while ( start < str . length ( ) && start >= 0 ) { boolean flag = false ; for ( int j = 0 ; j < 4 ; j ++ ) { if ( match ( array [ j ] , start , str ) ) { start += array [ j ] . length ( ) ; flag = true ; last = j ; break ; } } if ( ! flag && last == 0 ) { start -= 2 ; last = - 1 ; } else if ( ! flag ) break ; } if ( start == str . length ( ) ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) (throws (type_identifier)) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (type_identifier) dimensions: (dimensions) value: (array_initializer (string_literal) (string_literal) (string_literal) (string_literal))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (decimal_integer_literal)))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) body: (block (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (false))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (method_invocation name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (identifier) (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (identifier) right: (true))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (break_statement))))) (if_statement condition: (parenthesized_expression (binary_expression left: (unary_expression operand: (identifier)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal))))) alternative: (if_statement condition: (parenthesized_expression (unary_expression operand: (identifier))) consequence: (break_statement))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) consequence: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) alternative: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))))))