static int givesum ( int A [ ] , int n ) {
  int max = Arrays . stream ( A ) . max ( ) . getAsInt ( ) ;
  int maxBit = ( int ) Math . ceil ( Math . log ( max ) + 1 ) ;
  int totalSubarrays = n * ( n + 1 ) / 2 ;
  int s = 0 ;
  for ( int i = 0 ;
  i < maxBit ;
  i ++ ) {
    int c1 = 0 ;
    Vector < Integer > vec = new Vector < > ( ) ;
    int sum = 0 ;
    for ( int j = 0 ;
    j < n ;
    j ++ ) {
      int a = A [ j ] >> i ;
      if ( ! ( a % 2 == 1 ) ) {
        vec . add ( j ) ;
      }
    }
    int cntSubarrNotSet = 0 ;
    int cnt = 1 ;
    for ( int j = 1 ;
    j < vec . size ( ) ;
    j ++ ) {
      if ( vec . get ( j ) - vec . get ( j - 1 ) == 1 ) {
        cnt ++ ;
      }
      else {
        cntSubarrNotSet += cnt * ( cnt + 1 ) / 2 ;
        cnt = 1 ;
      }
    }
    cntSubarrNotSet += cnt * ( cnt + 1 ) / 2 ;
    if ( vec . size ( ) == 0 ) cntSubarrNotSet = 0 ;
    int cntSubarrIthSet = totalSubarrays - cntSubarrNotSet ;
    s += cntSubarrIthSet * Math . pow ( 2 , i ) ;
  }
  return s ;
}

static int givesum ( int A [ ] , int n ) { int max = Arrays . stream ( A ) . max ( ) . getAsInt ( ) ; int maxBit = ( int ) Math . ceil ( Math . log ( max ) + 1 ) ; int totalSubarrays = n * ( n + 1 ) / 2 ; int s = 0 ; for ( int i = 0 ; i < maxBit ; i ++ ) { int c1 = 0 ; Vector < Integer > vec = new Vector < > ( ) ; int sum = 0 ; for ( int j = 0 ; j < n ; j ++ ) { int a = A [ j ] >> i ; if ( ! ( a % 2 == 1 ) ) { vec . add ( j ) ; } } int cntSubarrNotSet = 0 ; int cnt = 1 ; for ( int j = 1 ; j < vec . size ( ) ; j ++ ) { if ( vec . get ( j ) - vec . get ( j - 1 ) == 1 ) { cnt ++ ; } else { cntSubarrNotSet += cnt * ( cnt + 1 ) / 2 ; cnt = 1 ; } } cntSubarrNotSet += cnt * ( cnt + 1 ) / 2 ; if ( vec . size ( ) == 0 ) cntSubarrNotSet = 0 ; int cntSubarrIthSet = totalSubarrays - cntSubarrNotSet ; s += cntSubarrIthSet * Math . pow ( 2 , i ) ; } return s ; }
(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) value: (method_invocation object: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list)))) (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 (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (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: (parenthesized_expression (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: (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: (decimal_integer_literal))) (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)) 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: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))) (if_statement condition: (parenthesized_expression (unary_expression operand: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (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: (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: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal))))) right: (decimal_integer_literal))) consequence: (block (expression_statement (update_expression (identifier)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier)))))))) (return_statement (identifier))))