static int max_length_substring ( String st , int n , int k ) {
  int max_len = 0 ;
  int len = 0 ;
  for ( int i = 0 ;
  i < n ;
  ++ i ) {
    if ( st . charAt ( i ) == '0' ) len ++ ;
    else len = 0 ;
    max_len = Math . max ( max_len , len ) ;
  }
  if ( max_len == n ) return n * k ;
  int pref = 0 , suff = 0 ;
  for ( int i = 0 ;
  st . charAt ( i ) == '0' ;
  ++ i , ++ pref ) ;
  for ( int i = n - 1 ;
  st . charAt ( i ) == '0' ;
  -- i , ++ suff ) ;
  if ( k > 1 ) max_len = Math . max ( max_len , pref + suff ) ;
  return max_len ;
}

static int max_length_substring ( String st , int n , int k ) { int max_len = 0 ; int len = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( st . charAt ( i ) == '0' ) len ++ ; else len = 0 ; max_len = Math . max ( max_len , len ) ; } if ( max_len == n ) return n * k ; int pref = 0 , suff = 0 ; for ( int i = 0 ; st . charAt ( i ) == '0' ; ++ i , ++ pref ) ; for ( int i = n - 1 ; st . charAt ( i ) == '0' ; -- i , ++ suff ) ; if ( k > 1 ) max_len = Math . max ( max_len , pref + suff ) ; return max_len ; }
(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))) (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: (identifier)) 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: (expression_statement (update_expression (identifier))) alternative: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (return_statement (binary_expression left: (identifier) right: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) 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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal)) update: (update_expression (identifier)) update: (update_expression (identifier))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal)) update: (update_expression (identifier)) update: (update_expression (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (identifier))))))) (return_statement (identifier))))