public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( System . in ) ;
  ban = sc . next ( ) . split ( "" ) ;
  ban2 = new int [ ban . length ] ;
  int sum = 0 ;
  boolean flag = true ;
  int left = 1 ;
  int right = ban . length - 2 ;
  while ( flag ) {
    String colorL = handan ( 0 ) ;
    String colorR = handan ( ban . length - 1 ) ;
    for ( int i = left ;
    left < ban . length ;
    left ++ ) {
      if ( ! colorL . equals ( handan ( left ) ) ) {
        break ;
      }
    }
    for ( int i = right ;
    right >= 0 ;
    right -- ) {
      if ( ! colorR . equals ( handan ( right ) ) ) {
        break ;
      }
    }
    int R = ban . length - 1 - right ;
    int L = left ;
    if ( L > ban . length - 1 ) {
      flag = false ;
      break ;
    }
    else if ( L < R ) {
      sum ++ ;
      for ( int j = 0 ;
      j < left ;
      j ++ ) {
        ban2 [ j ] ++ ;
      }
    }
    else {
      sum ++ ;
      for ( int j = right ;
      j >= 0 ;
      j -- ) {
        ban2 [ j ] ++ ;
      }
    }
  }
  System . out . println ( sum ) ;
}

public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; ban = sc . next ( ) . split ( " " ) ; ban2 = new int [ ban . length ] ; int sum = 0 ; boolean flag = true ; int left = 1 ; int right = ban . length - 2 ; while ( flag ) { String colorL = handan ( 0 ) ; String colorR = handan ( ban . length - 1 ) ; for ( int i = left ; left < ban . length ; left ++ ) { if ( ! colorL . equals ( handan ( left ) ) ) { break ; } } for ( int i = right ; right >= 0 ; right -- ) { if ( ! colorR . equals ( handan ( right ) ) ) { break ; } } int R = ban . length - 1 - right ; int L = left ; if ( L > ban . length - 1 ) { flag = false ; break ; } else if ( L < R ) { sum ++ ; for ( int j = 0 ; j < left ; j ++ ) { ban2 [ j ] ++ ; } } else { sum ++ ; for ( int j = right ; j >= 0 ; j -- ) { ban2 [ j ] ++ ; } } } System . out . println ( sum ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list (string_literal))))) (expression_statement (assignment_expression left: (identifier) right: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (true))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal)))) (while_statement condition: (parenthesized_expression (identifier)) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal)))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier))))))) consequence: (block (break_statement))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier))))))) consequence: (block (break_statement))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal)) right: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (false))) (break_statement)) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (update_expression (identifier))) (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 (expression_statement (update_expression (array_access array: (identifier) index: (identifier))))))) alternative: (block (expression_statement (update_expression (identifier))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (expression_statement (update_expression (array_access array: (identifier) index: (identifier))))))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))