static int rest ( int pvs , int curr_ind , int [ ] arr ) {
  int ans = 0 ;
  if ( curr_ind >= arr . length ) return ans ;
  String key = pvs + "-" + curr_ind ;
  if ( dp . containsKey ( key ) ) return dp . get ( key ) ;
  if ( arr [ curr_ind ] == 0 ) {
    ans = rest ( 0 , curr_ind + 1 , arr ) + 1 ;
  }
  else if ( arr [ curr_ind ] == 3 ) {
    if ( pvs == 1 ) {
      ans = Math . min ( 1 + rest ( 0 , curr_ind + 1 , arr ) , rest ( 2 , curr_ind + 1 , arr ) ) ;
    }
    else if ( pvs == 2 ) ans = Math . min ( rest ( 1 , curr_ind + 1 , arr ) , 1 + rest ( 0 , curr_ind + 1 , arr ) ) ;
    else ans = Math . min ( rest ( 1 , curr_ind + 1 , arr ) , rest ( 2 , curr_ind + 1 , arr ) ) ;
  }
  else {
    if ( pvs == arr [ curr_ind ] ) ans = 1 + rest ( 0 , curr_ind + 1 , arr ) ;
    else ans = rest ( arr [ curr_ind ] , curr_ind + 1 , arr ) ;
  }
  dp . put ( key , ans ) ;
  return ans ;
}

static int rest ( int pvs , int curr_ind , int [ ] arr ) { int ans = 0 ; if ( curr_ind >= arr . length ) return ans ; String key = pvs + " - " + curr_ind ; if ( dp . containsKey ( key ) ) return dp . get ( key ) ; if ( arr [ curr_ind ] == 0 ) { ans = rest ( 0 , curr_ind + 1 , arr ) + 1 ; } else if ( arr [ curr_ind ] == 3 ) { if ( pvs == 1 ) { ans = Math . min ( 1 + rest ( 0 , curr_ind + 1 , arr ) , rest ( 2 , curr_ind + 1 , arr ) ) ; } else if ( pvs == 2 ) ans = Math . min ( rest ( 1 , curr_ind + 1 , arr ) , 1 + rest ( 0 , curr_ind + 1 , arr ) ) ; else ans = Math . min ( rest ( 1 , curr_ind + 1 , arr ) , rest ( 2 , curr_ind + 1 , arr ) ) ; } else { if ( pvs == arr [ curr_ind ] ) ans = 1 + rest ( 0 , curr_ind + 1 , arr ) ; else ans = rest ( arr [ curr_ind ] , curr_ind + 1 , arr ) ; } dp . put ( key , ans ) ; return ans ; }
(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))) 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: (identifier) right: (field_access object: (identifier) field: (identifier)))) consequence: (return_statement (identifier))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (identifier) right: (string_literal)) right: (identifier)))) (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) consequence: (return_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier))) right: (decimal_integer_literal))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (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: (decimal_integer_literal) right: (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier)))) (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier)))))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier))) (binary_expression left: (decimal_integer_literal) right: (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier)))))))) alternative: (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier))) (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier)))))))))) alternative: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (decimal_integer_literal) right: (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier)))))) alternative: (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier))))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier)))) (return_statement (identifier))))