static int get_unordered_pairs ( int [ ] a , int n ) {
  ArrayList < Integer > vs = new ArrayList < Integer > ( ) ;
  int [ ] m = new int [ maximum ( a ) + 1 ] ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    m [ ( int ) a [ i ] ] ++ ;
    if ( m [ a [ i ] ] == 1 ) vs . add ( a [ i ] ) ;
  }
  int number_of_pairs = 0 ;
  for ( int i = 0 ;
  i < vs . size ( ) ;
  i ++ ) {
    if ( m [ ( int ) vs . get ( i ) ] < ( int ) vs . get ( i ) ) continue ;
    else if ( m [ ( int ) vs . get ( i ) ] == ( int ) vs . get ( i ) ) number_of_pairs += 1 ;
    else {
      number_of_pairs += 1 ;
      for ( int j = ( int ) vs . get ( i ) + 1 ;
      j <= m [ ( int ) vs . get ( i ) ] ;
      j ++ ) {
        if ( m [ j ] >= ( int ) vs . get ( i ) ) number_of_pairs += 1 ;
      }
    }
  }
  return number_of_pairs ;
}

static int get_unordered_pairs ( int [ ] a , int n ) { ArrayList < Integer > vs = new ArrayList < Integer > ( ) ; int [ ] m = new int [ maximum ( a ) + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { m [ ( int ) a [ i ] ] ++ ; if ( m [ a [ i ] ] == 1 ) vs . add ( a [ i ] ) ; } int number_of_pairs = 0 ; for ( int i = 0 ; i < vs . size ( ) ; i ++ ) { if ( m [ ( int ) vs . get ( i ) ] < ( int ) vs . get ( i ) ) continue ; else if ( m [ ( int ) vs . get ( i ) ] == ( int ) vs . get ( i ) ) number_of_pairs += 1 ; else { number_of_pairs += 1 ; for ( int j = ( int ) vs . get ( i ) + 1 ; j <= m [ ( int ) vs . get ( i ) ] ; j ++ ) { if ( m [ j ] >= ( int ) vs . get ( i ) ) number_of_pairs += 1 ; } } } return number_of_pairs ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier))) arguments: (argument_list)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (identifier))) right: (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 (expression_statement (update_expression (array_access array: (identifier) index: (cast_expression type: (integral_type) value: (array_access array: (identifier) index: (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier))) right: (decimal_integer_literal))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))))) (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) right: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) consequence: (continue_statement) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) right: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))))))))) (return_statement (identifier))))