static long calc ( ArrayDeque < Integer > rq , ArrayDeque < Integer > lq ) {
  int rx = rq . pollLast ( ) ;
  int rcount = 1 ;
  long ans = 0 ;
  while ( rq . size ( ) > 0 ) {
    int x = rq . pollLast ( ) ;
    long cnt = rx - x - rcount ;
    ans += cnt ;
    rcount ++ ;
  }
  int lx = lq . pollFirst ( ) ;
  int lcount = 1 ;
  while ( lq . size ( ) > 0 ) {
    int x = lq . pollFirst ( ) ;
    long cnt = x - lx - lcount ;
    ans += cnt ;
    lcount ++ ;
  }
  long max_cnt = Math . max ( rcount , lcount ) ;
  long cnt = max_cnt * ( lx - rx - 1 ) ;
  ans += cnt ;
  return ans ;
}

static long calc ( ArrayDeque < Integer > rq , ArrayDeque < Integer > lq ) { int rx = rq . pollLast ( ) ; int rcount = 1 ; long ans = 0 ; while ( rq . size ( ) > 0 ) { int x = rq . pollLast ( ) ; long cnt = rx - x - rcount ; ans += cnt ; rcount ++ ; } int lx = lq . pollFirst ( ) ; int lcount = 1 ; while ( lq . size ( ) > 0 ) { int x = lq . pollFirst ( ) ; long cnt = x - lx - lcount ; ans += cnt ; lcount ++ ; } long max_cnt = Math . max ( rcount , lcount ) ; long cnt = max_cnt * ( lx - rx - 1 ) ; ans += cnt ; return ans ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (generic_type (type_identifier) (type_arguments (type_identifier))) name: (identifier)) (formal_parameter type: (generic_type (type_identifier) (type_arguments (type_identifier))) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (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))) (while_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (update_expression (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (update_expression (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (return_statement (identifier))))