public static int minReplace ( int a [ ] , int n ) {
  int i ;
  HashMap < Integer , Integer > te = new HashMap < > ( ) ;
  HashMap < Integer , Integer > to = new HashMap < > ( ) ;
  for ( i = 0 ;
  i < n ;
  i ++ ) {
    if ( i % 2 == 0 ) {
      if ( te . containsKey ( a [ i ] ) ) te . put ( a [ i ] , te . get ( a [ i ] ) + 1 ) ;
      else te . put ( a [ i ] , 1 ) ;
    }
    else {
      if ( to . containsKey ( a [ i ] ) ) to . put ( a [ i ] , to . get ( a [ i ] ) + 1 ) ;
      else to . put ( a [ i ] , 1 ) ;
    }
  }
  int me = - 1 ;
  int mo = - 1 ;
  int ce = - 1 ;
  int co = - 1 ;
  for ( Integer It : te . keySet ( ) ) {
    if ( te . get ( It ) > ce ) {
      ce = te . get ( It ) ;
      me = It ;
    }
  }
  for ( Integer It : to . keySet ( ) ) {
    if ( to . get ( It ) > co ) {
      co = to . get ( It ) ;
      mo = It ;
    }
  }
  int res = 0 ;
  for ( i = 0 ;
  i < n ;
  i ++ ) {
    if ( i % 2 == 0 ) {
      if ( a [ i ] != me ) res ++ ;
    }
    else {
      if ( a [ i ] != mo ) res ++ ;
    }
  }
  return res ;
}

public static int minReplace ( int a [ ] , int n ) { int i ; HashMap < Integer , Integer > te = new HashMap < > ( ) ; HashMap < Integer , Integer > to = new HashMap < > ( ) ; for ( i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { if ( te . containsKey ( a [ i ] ) ) te . put ( a [ i ] , te . get ( a [ i ] ) + 1 ) ; else te . put ( a [ i ] , 1 ) ; } else { if ( to . containsKey ( a [ i ] ) ) to . put ( a [ i ] , to . get ( a [ i ] ) + 1 ) ; else to . put ( a [ i ] , 1 ) ; } } int me = - 1 ; int mo = - 1 ; int ce = - 1 ; int co = - 1 ; for ( Integer It : te . keySet ( ) ) { if ( te . get ( It ) > ce ) { ce = te . get ( It ) ; me = It ; } } for ( Integer It : to . keySet ( ) ) { if ( to . get ( It ) > co ) { co = to . get ( It ) ; mo = It ; } } int res = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { if ( a [ i ] != me ) res ++ ; } else { if ( a [ i ] != mo ) res ++ ; } } return res ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier))) (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)) 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)) arguments: (argument_list)))) (for_statement init: (assignment_expression left: (identifier) right: (decimal_integer_literal)) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))) right: (decimal_integer_literal))))) alternative: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (decimal_integer_literal)))))) alternative: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))) right: (decimal_integer_literal))))) alternative: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (decimal_integer_literal))))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (decimal_integer_literal)))) (enhanced_for_statement type: (type_identifier) name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) 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 (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))))) (enhanced_for_statement type: (type_identifier) name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) 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 (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (assignment_expression left: (identifier) right: (decimal_integer_literal)) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (expression_statement (update_expression (identifier))))) alternative: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (expression_statement (update_expression (identifier)))))))) (return_statement (identifier))))