public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( System . in ) ;
  String inputText = sc . next ( ) ;
  char [ ] p1 = {
    'm' , 'a' , 'e' , 'r' , 'd' };
    char [ ] p2 = {
      'r' , 'e' , 'm' , 'a' , 'e' , 'r' , 'd' };
      char [ ] p3 = {
        'e' , 's' , 'a' , 'r' , 'e' };
        char [ ] p4 = {
          'r' , 'e' , 's' , 'a' , 'r' , 'e' };
          char [ ] inputArray = inputText . toCharArray ( ) ;
          int wordIndex = 0 ;
          char [ ] targetArray = null ;
          for ( int i = inputArray . length - 1 ;
          i >= 0 ;
          i -- ) {
            if ( wordIndex == 0 ) {
              if ( inputArray [ i ] == 'm' ) {
                targetArray = p1 ;
              }
              else if ( inputArray [ i ] == 'e' ) {
                targetArray = p3 ;
              }
              else if ( inputArray [ i ] == 'r' ) {
                if ( i - 2 > 0 ) {
                  if ( inputArray [ i - 2 ] == 'm' ) {
                    targetArray = p2 ;
                  }
                  else if ( inputArray [ i - 2 ] == 's' ) {
                    targetArray = p4 ;
                  }
                  else {
                    System . out . println ( "NO" ) ;
                    return ;
                  }
                }
                else {
                  System . out . println ( "NO" ) ;
                  return ;
                }
              }
              else {
                System . out . println ( "NO" ) ;
                return ;
              }
            }
            else {
              if ( targetArray [ wordIndex ] != inputArray [ i ] ) {
                System . out . println ( "NO" ) ;
                return ;
              }
            }
            if ( wordIndex < targetArray . length - 1 ) {
              wordIndex ++ ;
            }
            else {
              wordIndex = 0 ;
              targetArray = null ;
            }
          }
          System . out . println ( "YES" ) ;
        }
        
public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String inputText = sc . next ( ) ; char [ ] p1 = { ' m ' , ' a ' , ' e ' , ' r ' , ' d ' } ; char [ ] p2 = { ' r ' , ' e ' , ' m ' , ' a ' , ' e ' , ' r ' , ' d ' } ; char [ ] p3 = { ' e ' , ' s ' , ' a ' , ' r ' , ' e ' } ; char [ ] p4 = { ' r ' , ' e ' , ' s ' , ' a ' , ' r ' , ' e ' } ; char [ ] inputArray = inputText . toCharArray ( ) ; int wordIndex = 0 ; char [ ] targetArray = null ; for ( int i = inputArray . length - 1 ; i >= 0 ; i -- ) { if ( wordIndex == 0 ) { if ( inputArray [ i ] == ' m ' ) { targetArray = p1 ; } else if ( inputArray [ i ] == ' e ' ) { targetArray = p3 ; } else if ( inputArray [ i ] == ' r ' ) { if ( i - 2 > 0 ) { if ( inputArray [ i - 2 ] == ' m ' ) { targetArray = p2 ; } else if ( inputArray [ i - 2 ] == ' s ' ) { targetArray = p4 ; } else { System . out . println ( " NO " ) ; return ; } } else { System . out . println ( " NO " ) ; return ; } } else { System . out . println ( " NO " ) ; return ; } } else { if ( targetArray [ wordIndex ] != inputArray [ i ] ) { System . out . println ( " NO " ) ; return ; } } if ( wordIndex < targetArray . length - 1 ) { wordIndex ++ ; } else { wordIndex = 0 ; targetArray = null ; } } System . out . println ( " YES " ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (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: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_initializer (character_literal) (character_literal) (character_literal) (character_literal) (character_literal)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_initializer (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_initializer (character_literal) (character_literal) (character_literal) (character_literal) (character_literal)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_initializer (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) 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: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (null_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (character_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (character_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier)))) alternative: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) (return_statement))))) alternative: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) (return_statement)))) alternative: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) (return_statement)))))) alternative: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) (return_statement))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal)))) consequence: (block (expression_statement (update_expression (identifier)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (null_literal))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal))))))