static long getAns ( long [ ] a , int n , int prod , long [ ] [ ] dp ) {
  if ( n == 0 ) {
    return prod == 1 ? 0 : Long . MAX_VALUE / 2 ;
  }
  if ( dp [ n ] [ ( prod % 3 + 3 ) % 3 ] != - 1 ) {
    return dp [ n ] [ ( prod % 3 + 3 ) % 3 ] ;
  }
  long ans1 = Math . abs ( a [ n - 1 ] - 1 ) + getAns ( a , n - 1 , prod , dp ) ;
  long ans2 = Math . abs ( a [ n - 1 ] + 1 ) + getAns ( a , n - 1 , prod * - 1 , dp ) ;
  return dp [ n ] [ ( prod % 3 + 3 ) % 3 ] = Math . min ( ans1 , ans2 ) ;
}

static long getAns ( long [ ] a , int n , int prod , long [ ] [ ] dp ) { if ( n == 0 ) { return prod == 1 ? 0 : Long . MAX_VALUE / 2 ; } if ( dp [ n ] [ ( prod % 3 + 3 ) % 3 ] != - 1 ) { return dp [ n ] [ ( prod % 3 + 3 ) % 3 ] ; } long ans1 = Math . abs ( a [ n - 1 ] - 1 ) + getAns ( a , n - 1 , prod , dp ) ; long ans2 = Math . abs ( a [ n - 1 ] + 1 ) + getAns ( a , n - 1 , prod * - 1 , dp ) ; return dp [ n ] [ ( prod % 3 + 3 ) % 3 ] = Math . min ( ans1 , ans2 ) ; }
(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: (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: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) right: (decimal_integer_literal))) right: (unary_expression operand: (decimal_integer_literal)))) consequence: (block (return_statement (array_access array: (array_access array: (identifier) index: (identifier)) index: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) right: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (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) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier) (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (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) (binary_expression left: (identifier) right: (decimal_integer_literal)) (binary_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal))) (identifier)))))) (return_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) right: (decimal_integer_literal))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier)))))))