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

static long f ( long [ ] a , long [ ] p , int n , long x ) { if ( x == 1 ) return n > 0 ? 0 : 1 ; if ( x == 3 + 2 * a [ n - 1 ] ) return p [ n - 1 ] * 2 + 1 ; if ( x == a [ n - 1 ] + 2 ) return p [ n - 1 ] + 1 ; if ( 1 < x && x <= a [ n - 1 ] + 1 ) return f ( a , p , n - 1 , x - 1 ) ; return p [ n - 1 ] + 1 + f ( a , p , n - 1 , x - a [ n - 1 ] - 2 ) ; }
(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: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (return_statement (ternary_expression condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) consequence: (decimal_integer_literal) alternative: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (decimal_integer_literal) right: (binary_expression left: (decimal_integer_literal) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))))) consequence: (return_statement (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal)) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal)))) consequence: (return_statement (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (identifier)) right: (binary_expression left: (identifier) right: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal))))) consequence: (return_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)) (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (return_statement (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal)) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)) (binary_expression left: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (decimal_integer_literal))))))))