static int getPairs ( int a [ ] , int n ) {
  HashSet < Integer > visited1 = new HashSet < Integer > ( ) ;
  int un [ ] = new int [ n ] ;
  un [ n - 1 ] = 0 ;
  int count = 0 ;
  for ( int i = n - 1 ;
  i > 0 ;
  i -- ) {
    if ( visited1 . contains ( a [ i ] ) ) un [ i - 1 ] = count ;
    else un [ i - 1 ] = ++ count ;
    visited1 . add ( a [ i ] ) ;
  }
  HashSet < Integer > visited2 = new HashSet < Integer > ( ) ;
  int answer = 0 ;
  for ( int i = 0 ;
  i < n - 1 ;
  i ++ ) {
    if ( visited2 . contains ( a [ i ] ) ) continue ;
    answer += un [ i ] ;
    visited2 . add ( a [ i ] ) ;
  }
  return answer ;
}

static int getPairs ( int a [ ] , int n ) { HashSet < Integer > visited1 = new HashSet < Integer > ( ) ; int un [ ] = new int [ n ] ; un [ n - 1 ] = 0 ; int count = 0 ; for ( int i = n - 1 ; i > 0 ; i -- ) { if ( visited1 . contains ( a [ i ] ) ) un [ i - 1 ] = count ; else un [ i - 1 ] = ++ count ; visited1 . add ( a [ i ] ) ; } HashSet < Integer > visited2 = new HashSet < Integer > ( ) ; int answer = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( visited2 . contains ( a [ i ] ) ) continue ; answer += un [ i ] ; visited2 . add ( a [ i ] ) ; } return answer ; }
(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: (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: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (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: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))) consequence: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (identifier))) alternative: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (update_expression (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))))) (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: (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: (binary_expression left: (identifier) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))) consequence: (continue_statement)) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))))) (return_statement (identifier))))