static int countWays ( String str , int m ) {
  HashSet < Character > set = new HashSet < Character > ( ) ;
  for ( int i = 0 ;
  i < str . length ( ) ;
  i ++ ) set . add ( str . charAt ( i ) ) ;
  int result = 0 ;
  for ( int i = 1 ;
  i < str . length ( ) ;
  i ++ ) {
    HashMap < Character , Integer > first_map = new HashMap < Character , Integer > ( ) ;
    HashMap < Character , Integer > second_map = new HashMap < Character , Integer > ( ) ;
    for ( int j = 0 ;
    j < i ;
    j ++ ) {
      if ( first_map . containsKey ( str . charAt ( j ) ) ) first_map . put ( str . charAt ( j ) , ( first_map . get ( str . charAt ( j ) ) + 1 ) ) ;
      else first_map . put ( str . charAt ( j ) , 1 ) ;
    }
    for ( int k = i ;
    k < str . length ( ) ;
    k ++ ) {
      if ( second_map . containsKey ( str . charAt ( k ) ) ) second_map . put ( str . charAt ( k ) , ( second_map . get ( str . charAt ( k ) ) + 1 ) ) ;
      else second_map . put ( str . charAt ( k ) , 1 ) ;
    }
    Iterator itr = set . iterator ( ) ;
    int total_count = 0 ;
    while ( itr . hasNext ( ) ) {
      int first_count = 0 , second_count = 0 ;
      char ch = ( char ) itr . next ( ) ;
      if ( first_map . containsKey ( ch ) ) first_count = first_map . get ( ch ) ;
      if ( second_map . containsKey ( ch ) ) second_count = second_map . get ( ch ) ;
      if ( first_count == second_count && first_count != 0 ) total_count += 1 ;
    }
    if ( total_count >= m ) result += 1 ;
  }
  return result ;
}

static int countWays ( String str , int m ) { HashSet < Character > set = new HashSet < Character > ( ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) set . add ( str . charAt ( i ) ) ; int result = 0 ; for ( int i = 1 ; i < str . length ( ) ; i ++ ) { HashMap < Character , Integer > first_map = new HashMap < Character , Integer > ( ) ; HashMap < Character , Integer > second_map = new HashMap < Character , Integer > ( ) ; for ( int j = 0 ; j < i ; j ++ ) { if ( first_map . containsKey ( str . charAt ( j ) ) ) first_map . put ( str . charAt ( j ) , ( first_map . get ( str . charAt ( j ) ) + 1 ) ) ; else first_map . put ( str . charAt ( j ) , 1 ) ; } for ( int k = i ; k < str . length ( ) ; k ++ ) { if ( second_map . containsKey ( str . charAt ( k ) ) ) second_map . put ( str . charAt ( k ) , ( second_map . get ( str . charAt ( k ) ) + 1 ) ) ; else second_map . put ( str . charAt ( k ) , 1 ) ; } Iterator itr = set . iterator ( ) ; int total_count = 0 ; while ( itr . hasNext ( ) ) { int first_count = 0 , second_count = 0 ; char ch = ( char ) itr . next ( ) ; if ( first_map . containsKey ( ch ) ) first_count = first_map . get ( ch ) ; if ( second_map . containsKey ( ch ) ) second_count = second_map . get ( ch ) ; if ( first_count == second_count && first_count != 0 ) total_count += 1 ; } if ( total_count >= m ) result += 1 ; } return result ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier))) arguments: (argument_list)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) arguments: (argument_list)))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) arguments: (argument_list)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) right: (decimal_integer_literal)))))) alternative: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) (decimal_integer_literal))))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) right: (decimal_integer_literal)))))) alternative: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) (decimal_integer_literal))))))) (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))) (while_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))))) (return_statement (identifier))))