static long f ( int n , long x , long [ ] a , long [ ] p ) {
  if ( n == 0 ) {
    return x > 0 ? 1 : 0 ;
  }
  long anp = a [ n - 1 ] ;
  long pnp = p [ n - 1 ] ;
  if ( x <= anp + 1 ) {
    return f ( n - 1 , x - 1 , a , p ) ;
  }
  if ( x == x + anp ) {
    return pnp ;
  }
  if ( x <= 2 * anp + 2 ) {
    return pnp + 1 + f ( n - 1 , x - anp - 2 , a , p ) ;
  }
  return 2 * pnp + 1 ;
}

static long f ( int n , long x , long [ ] a , long [ ] p ) { if ( n == 0 ) { return x > 0 ? 1 : 0 ; } long anp = a [ n - 1 ] ; long pnp = p [ n - 1 ] ; if ( x <= anp + 1 ) { return f ( n - 1 , x - 1 , a , p ) ; } if ( x == x + anp ) { return pnp ; } if ( x <= 2 * anp + 2 ) { return pnp + 1 + f ( n - 1 , x - anp - 2 , a , p ) ; } return 2 * pnp + 1 ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (return_statement (ternary_expression condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) consequence: (decimal_integer_literal) alternative: (decimal_integer_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (return_statement (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier) (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) consequence: (block (return_statement (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (identifier)) right: (decimal_integer_literal)))) consequence: (block (return_statement (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)) (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal)) (identifier) (identifier))))))) (return_statement (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (identifier)) right: (decimal_integer_literal)))))