static int countMinimalReplacements ( char [ ] s ) {
  int n = s . length ;
  int cnt = 0 ;
  for ( int i = 1 ;
  i < n ;
  i ++ ) {
    if ( s [ i ] == s [ i - 1 ] ) {
      cnt += 1 ;
      if ( i != ( n - 1 ) ) {
        for ( char it : "012" . toCharArray ( ) ) {
          if ( it != s [ i + 1 ] && it != s [ i - 1 ] ) {
            s [ i ] = it ;
            break ;
          }
        }
      }
      else {
        for ( char it : "012" . toCharArray ( ) ) {
          if ( it != s [ i - 1 ] ) {
            s [ i ] = it ;
            break ;
          }
        }
      }
    }
  }
  return cnt ;
}

static int countMinimalReplacements ( char [ ] s ) { int n = s . length ; int cnt = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( s [ i ] == s [ i - 1 ] ) { cnt += 1 ; if ( i != ( n - 1 ) ) { for ( char it : "012" . toCharArray ( ) ) { if ( it != s [ i + 1 ] && it != s [ i - 1 ] ) { s [ i ] = it ; break ; } } } else { for ( char it : "012" . toCharArray ( ) ) { if ( it != s [ i - 1 ] ) { s [ i ] = it ; break ; } } } } } return cnt ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (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: (field_access object: (identifier) field: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))))) consequence: (block (enhanced_for_statement type: (integral_type) name: (identifier) value: (method_invocation object: (string_literal) name: (identifier) arguments: (argument_list)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) (break_statement)))))) alternative: (block (enhanced_for_statement type: (integral_type) name: (identifier) value: (method_invocation object: (string_literal) name: (identifier) arguments: (argument_list)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) (break_statement))))))))))) (return_statement (identifier))))