static int countSubString ( String s , char c , int k ) {
  int leftCount = 0 , rightCount = 0 ;
  int left = 0 , right = 0 ;
  int freq = 0 ;
  int result = 0 , len = s . length ( ) ;
  while ( s . charAt ( left ) != c && left < len ) {
    left ++ ;
    leftCount ++ ;
  }
  right = left + 1 ;
  while ( freq != ( k - 1 ) && ( right - 1 ) < len ) {
    if ( s . charAt ( right ) == c ) {
      freq ++ ;
    }
    right ++ ;
  }
  while ( left < len && ( right - 1 ) < len ) {
    while ( s . charAt ( left ) != c && left < len ) {
      left ++ ;
      leftCount ++ ;
    }
    while ( right < len && s . charAt ( right ) != c ) {
      if ( s . charAt ( right ) == c ) {
        freq ++ ;
      }
      right ++ ;
      rightCount ++ ;
    }
    result = result + ( leftCount + 1 ) * ( rightCount + 1 ) ;
    freq = k - 1 ;
    leftCount = 0 ;
    rightCount = 0 ;
    left ++ ;
    right ++ ;
  }
  return result ;
}

static int countSubString ( String s , char c , int k ) { int leftCount = 0 , rightCount = 0 ; int left = 0 , right = 0 ; int freq = 0 ; int result = 0 , len = s . length ( ) ; while ( s . charAt ( left ) != c && left < len ) { left ++ ; leftCount ++ ; } right = left + 1 ; while ( freq != ( k - 1 ) && ( right - 1 ) < len ) { if ( s . charAt ( right ) == c ) { freq ++ ; } right ++ ; } while ( left < len && ( right - 1 ) < len ) { while ( s . charAt ( left ) != c && left < len ) { left ++ ; leftCount ++ ; } while ( right < len && s . charAt ( right ) != c ) { if ( s . charAt ( right ) == c ) { freq ++ ; } right ++ ; rightCount ++ ; } result = result + ( leftCount + 1 ) * ( rightCount + 1 ) ; freq = k - 1 ; leftCount = 0 ; rightCount = 0 ; left ++ ; right ++ ; } 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)) (formal_parameter type: (integral_type) name: (identifier))) 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: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (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)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier)) right: (binary_expression left: (identifier) right: (identifier)))) body: (block (expression_statement (update_expression (identifier))) (expression_statement (update_expression (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (identifier)))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier))) consequence: (block (expression_statement (update_expression (identifier))))) (expression_statement (update_expression (identifier))))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (identifier)))) body: (block (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier)) right: (binary_expression left: (identifier) right: (identifier)))) body: (block (expression_statement (update_expression (identifier))) (expression_statement (update_expression (identifier))))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier)))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier))) consequence: (block (expression_statement (update_expression (identifier))))) (expression_statement (update_expression (identifier))) (expression_statement (update_expression (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (update_expression (identifier))) (expression_statement (update_expression (identifier))))) (return_statement (identifier))))