private static int mergeAndCount ( int [ ] arr , int l , int m , int r ) {
  int [ ] left = Arrays . copyOfRange ( arr , l , m + 1 ) ;
  int [ ] right = Arrays . copyOfRange ( arr , m + 1 , r + 1 ) ;
  int i = 0 , j = 0 , k = l , swaps = 0 ;
  while ( i < left . length && j < right . length ) {
    if ( left [ i ] <= right [ j ] ) arr [ k ++ ] = left [ i ++ ] ;
    else {
      arr [ k ++ ] = right [ j ++ ] ;
      swaps += ( m + 1 ) - ( l + i ) ;
    }
  }
  while ( i < left . length ) arr [ k ++ ] = left [ i ++ ] ;
  while ( j < right . length ) arr [ k ++ ] = right [ j ++ ] ;
  return swaps ;
}

private static int mergeAndCount ( int [ ] arr , int l , int m , int r ) { int [ ] left = Arrays . copyOfRange ( arr , l , m + 1 ) ; int [ ] right = Arrays . copyOfRange ( arr , m + 1 , r + 1 ) ; int i = 0 , j = 0 , k = l , swaps = 0 ; while ( i < left . length && j < right . length ) { if ( left [ i ] <= right [ j ] ) arr [ k ++ ] = left [ i ++ ] ; else { arr [ k ++ ] = right [ j ++ ] ; swaps += ( m + 1 ) - ( l + i ) ; } } while ( i < left . length ) arr [ k ++ ] = left [ i ++ ] ; while ( j < right . length ) arr [ k ++ ] = right [ j ++ ] ; return swaps ; }
(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)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)) (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (identifier)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier))) right: (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier))))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))) consequence: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (update_expression (identifier))) right: (array_access array: (identifier) index: (update_expression (identifier))))) alternative: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (update_expression (identifier))) right: (array_access array: (identifier) index: (update_expression (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (parenthesized_expression (binary_expression left: (identifier) right: (identifier)))))))))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) body: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (update_expression (identifier))) right: (array_access array: (identifier) index: (update_expression (identifier)))))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) body: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (update_expression (identifier))) right: (array_access array: (identifier) index: (update_expression (identifier)))))) (return_statement (identifier))))