static int solve ( long N ) {
  if ( N < 10 ) return ( int ) N ;
  String s = String . valueOf ( N ) ;
  int len = s . length ( ) ;
  int ans = help ( N ) ;
  for ( int i = 2 ;
  i <= len ;
  i ++ ) {
    long temp = ( long ) Math . pow ( 10 , i - 1 ) ;
    long cur = N / temp - 1 ;
    ans = Math . max ( ans , help ( cur ) + 9 * ( i - 1 ) ) ;
  }
  return ans ;
}

static int solve ( long N ) { if ( N < 10 ) return ( int ) N ; String s = String . valueOf ( N ) ; int len = s . length ( ) ; int ans = help ( N ) ; for ( int i = 2 ; i <= len ; i ++ ) { long temp = ( long ) Math . pow ( 10 , i - 1 ) ; long cur = N / temp - 1 ; ans = Math . max ( ans , help ( cur ) + 9 * ( i - 1 ) ) ; } return ans ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (return_statement (cast_expression type: (integral_type) value: (identifier)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (local_variable_declaration type: (integral_type) 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: (method_invocation name: (identifier) arguments: (argument_list (identifier))))) (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 (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 (decimal_integer_literal) (binary_expression left: (identifier) right: (decimal_integer_literal))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (identifier))) right: (binary_expression left: (decimal_integer_literal) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))))))))))) (return_statement (identifier))))