static String solve ( int format , String time ) {
  int minHour ;
  int maxHour ;
  if ( format == 12 ) {
    minHour = 1 ;
    maxHour = 12 ;
  }
  else {
    minHour = 0 ;
    maxHour = 23 ;
  }
  int minDiffNum = Integer . MAX_VALUE ;
  String result = null ;
  for ( int hour = minHour ;
  hour <= maxHour ;
  hour ++ ) {
    for ( int minute = 0 ;
    minute <= 59 ;
    minute ++ ) {
      String t = String . format ( "%02d:%02d" , hour , minute ) ;
      int diffNum = ( int ) IntStream . range ( 0 , time . length ( ) ) . filter ( i -> time . charAt ( i ) != t . charAt ( i ) ) . count ( ) ;
      if ( diffNum < minDiffNum ) {
        minDiffNum = diffNum ;
        result = t ;
      }
    }
  }
  return result ;
}

static String solve ( int format , String time ) { int minHour ; int maxHour ; if ( format == 12 ) { minHour = 1 ; maxHour = 12 ; } else { minHour = 0 ; maxHour = 23 ; } int minDiffNum = Integer . MAX_VALUE ; String result = null ; for ( int hour = minHour ; hour <= maxHour ; hour ++ ) { for ( int minute = 0 ; minute <= 59 ; minute ++ ) { String t = String . format ( " % 02d : %02d " , hour , minute ) ; int diffNum = ( int ) IntStream . range ( 0 , time . length ( ) ) . filter ( i -> time . charAt ( i ) != t . charAt ( i ) ) . count ( ) ; if ( diffNum < minDiffNum ) { minDiffNum = diffNum ; result = t ; } } } return result ; }
(method_declaration (modifiers) type: (type_identifier) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (type_identifier) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (null_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal) (identifier) (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (cast_expression type: (integral_type) value: (method_invocation object: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) name: (identifier) arguments: (argument_list (lambda_expression parameters: (identifier) body: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))) name: (identifier) arguments: (argument_list))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))))))) (return_statement (identifier))))