public static void main ( String [ ] args ) throws IOException {
  String sr = br . readLine ( ) ;
  long count = 0 ;
  long total = 0 ;
  if ( sr . length ( ) < 10 ) System . out . println ( "0" ) ;
  else {
    for ( int i = sr . length ( ) - 5 ;
    i >= 0 ;
    i -- ) {
      if ( sr . charAt ( i ) == 'm' ) {
        if ( sr . substring ( i , i + 5 ) . equals ( "metal" ) ) count ++ ;
      }
      if ( sr . charAt ( i ) == 'h' ) {
        if ( sr . substring ( i , i + 5 ) . equals ( "heavy" ) ) total += count ;
      }
    }
    System . out . println ( total ) ;
  }
}

public static void main ( String [ ] args ) throws IOException { String sr = br . readLine ( ) ; long count = 0 ; long total = 0 ; if ( sr . length ( ) < 10 ) System . out . println ( "0" ) ; else { for ( int i = sr . length ( ) - 5 ; i >= 0 ; i -- ) { if ( sr . charAt ( i ) == ' m ' ) { if ( sr . substring ( i , i + 5 ) . equals ( " metal " ) ) count ++ ; } if ( sr . charAt ( i ) == ' h ' ) { if ( sr . substring ( i , i + 5 ) . equals ( " heavy " ) ) total += count ; } } System . out . println ( total ) ; } }
(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) 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: (decimal_integer_literal))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) consequence: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) alternative: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) 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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (block (if_statement condition: (parenthesized_expression (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)))) name: (identifier) arguments: (argument_list (string_literal)))) consequence: (expression_statement (update_expression (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (block (if_statement condition: (parenthesized_expression (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)))) name: (identifier) arguments: (argument_list (string_literal)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (identifier)))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))))