private static int cost ( int i , int [ ] values , int [ ] cache ) {
  int ans = 0 ;
  if ( cache [ i ] != - 1 ) {
    return cache [ i ] ;
  }
  if ( i == 0 ) {
    ans = 0 ;
  }
  else if ( i == 1 ) {
    ans = Math . abs ( values [ 1 ] - values [ 0 ] ) ;
  }
  else {
    int a = cost ( i - 2 , values , cache ) + Math . abs ( values [ i ] - values [ i - 2 ] ) ;
    int b = cost ( i - 1 , values , cache ) + Math . abs ( values [ i ] - values [ i - 1 ] ) ;
    ans = Math . min ( a , b ) ;
  }
  if ( cache [ i ] == - 1 ) {
    cache [ i ] = ans ;
  }
  return ans ;
}

private static int cost ( int i , int [ ] values , int [ ] cache ) { int ans = 0 ; if ( cache [ i ] != - 1 ) { return cache [ i ] ; } if ( i == 0 ) { ans = 0 ; } else if ( i == 1 ) { ans = Math . abs ( values [ 1 ] - values [ 0 ] ) ; } else { int a = cost ( i - 2 , values , cache ) + Math . abs ( values [ i ] - values [ i - 2 ] ) ; int b = cost ( i - 1 , values , cache ) + Math . abs ( values [ i ] - values [ i - 1 ] ) ; ans = Math . min ( a , b ) ; } if ( cache [ i ] == - 1 ) { cache [ i ] = ans ; } return ans ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (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 (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (unary_expression operand: (decimal_integer_literal)))) consequence: (block (return_statement (array_access array: (identifier) index: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (array_access array: (identifier) index: (decimal_integer_literal)))))))) alternative: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier) (identifier))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (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: (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier) (identifier))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier)))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (unary_expression operand: (decimal_integer_literal)))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))))) (return_statement (identifier))))