public static void main ( String [ ] args ) {
  Scanner scanner = new Scanner ( System . in ) ;
  final int N = scanner . nextInt ( ) ;
  final String S = scanner . next ( ) ;
  Deque < Color > deque = new ArrayDeque < > ( ) ;
  String [ ] strings = S . split ( "" ) ;
  for ( int i = 0 ;
  i < N ;
  i ++ ) {
    Color ball = Color . toEnum ( strings [ i ] ) ;
    if ( deque . size ( ) == 0 ) {
      deque . addLast ( ball ) ;
      continue ;
    }
    if ( deque . size ( ) == 1 ) {
      Color ball1 = deque . getFirst ( ) ;
      if ( ball1 == ball ) {
        deque . removeFirst ( ) ;
      }
      else {
        deque . addLast ( ball ) ;
      }
      continue ;
    }
    Color ball1 = deque . getFirst ( ) ;
    Color ball2 = deque . getLast ( ) ;
    if ( ball == ball1 ) {
      deque . removeFirst ( ) ;
      continue ;
    }
    if ( ball == ball2 ) {
      deque . removeLast ( ) ;
      continue ;
    }
    if ( i == N - 1 ) {
      deque . addLast ( ball ) ;
      continue ;
    }
    Color nextBall = Color . toEnum ( strings [ i + 1 ] ) ;
    if ( ball == nextBall ) {
      deque . addLast ( ball ) ;
      continue ;
    }
    if ( ball1 == nextBall ) {
      deque . addLast ( ball ) ;
    }
    else if ( ball2 == nextBall ) {
      deque . addFirst ( ball ) ;
    }
  }
  System . out . println ( deque . size ( ) ) ;
}

public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; final int N = scanner . nextInt ( ) ; final String S = scanner . next ( ) ; Deque < Color > deque = new ArrayDeque < > ( ) ; String [ ] strings = S . split ( " " ) ; for ( int i = 0 ; i < N ; i ++ ) { Color ball = Color . toEnum ( strings [ i ] ) ; if ( deque . size ( ) == 0 ) { deque . addLast ( ball ) ; continue ; } if ( deque . size ( ) == 1 ) { Color ball1 = deque . getFirst ( ) ; if ( ball1 == ball ) { deque . removeFirst ( ) ; } else { deque . addLast ( ball ) ; } continue ; } Color ball1 = deque . getFirst ( ) ; Color ball2 = deque . getLast ( ) ; if ( ball == ball1 ) { deque . removeFirst ( ) ; continue ; } if ( ball == ball2 ) { deque . removeLast ( ) ; continue ; } if ( i == N - 1 ) { deque . addLast ( ball ) ; continue ; } Color nextBall = Color . toEnum ( strings [ i + 1 ] ) ; if ( ball == nextBall ) { deque . addLast ( ball ) ; continue ; } if ( ball1 == nextBall ) { deque . addLast ( ball ) ; } else if ( ball2 == nextBall ) { deque . addFirst ( ball ) ; } } System . out . println ( deque . size ( ) ) ; }
(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)))))) (local_variable_declaration (modifiers) type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration (modifiers) type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (local_variable_declaration type: (array_type element: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_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 (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (continue_statement))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) consequence: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) alternative: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (continue_statement))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (continue_statement))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (continue_statement))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (continue_statement))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (continue_statement))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))