public static void process ( ) throws IOException {
  int a = sc . nextInt ( ) , b = sc . nextInt ( ) , curr = sc . nextInt ( ) ;
  String str = sc . next ( ) ;
  int i = str . length ( ) - 2 ;
  Deque < Integer > q = new LinkedList < Integer > ( ) ;
  while ( i >= 0 ) {
    if ( q . isEmpty ( ) ) {
      int cc = str . charAt ( i ) - 'A' ;
      if ( cc == 0 ) {
        if ( curr >= a ) {
          q . add ( cc ) ;
          i -- ;
          curr -= a ;
        }
        else {
          break ;
        }
      }
      else {
        if ( curr >= b ) {
          q . add ( cc ) ;
          curr -= b ;
          i -- ;
        }
        else break ;
      }
      continue ;
    }
    int prev = q . peekLast ( ) ;
    int cc = str . charAt ( i ) - 'A' ;
    if ( prev == cc ) {
      i -- ;
      continue ;
    }
    if ( cc == 0 ) {
      if ( curr >= a ) {
        q . add ( cc ) ;
        i -- ;
        curr -= a ;
      }
      else {
        break ;
      }
    }
    else {
      if ( curr >= b ) {
        q . add ( cc ) ;
        curr -= b ;
        i -- ;
      }
      else break ;
    }
  }
  if ( i == - 1 ) System . out . println ( 1 ) ;
  else {
    System . out . println ( i + 2 ) ;
  }
}

public static void process ( ) throws IOException { int a = sc . nextInt ( ) , b = sc . nextInt ( ) , curr = sc . nextInt ( ) ; String str = sc . next ( ) ; int i = str . length ( ) - 2 ; Deque < Integer > q = new LinkedList < Integer > ( ) ; while ( i >= 0 ) { if ( q . isEmpty ( ) ) { int cc = str . charAt ( i ) - ' A ' ; if ( cc == 0 ) { if ( curr >= a ) { q . add ( cc ) ; i -- ; curr -= a ; } else { break ; } } else { if ( curr >= b ) { q . add ( cc ) ; curr -= b ; i -- ; } else break ; } continue ; } int prev = q . peekLast ( ) ; int cc = str . charAt ( i ) - ' A ' ; if ( prev == cc ) { i -- ; continue ; } if ( cc == 0 ) { if ( curr >= a ) { q . add ( cc ) ; i -- ; curr -= a ; } else { break ; } } else { if ( curr >= b ) { q . add ( cc ) ; curr -= b ; i -- ; } else break ; } } if ( i == - 1 ) System . out . println ( 1 ) ; else { System . out . println ( i + 2 ) ; } }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters) (throws (type_identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) 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)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))) (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 (type_identifier))) arguments: (argument_list)))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) consequence: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (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 (update_expression (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier)))) alternative: (block (break_statement)))) alternative: (block (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 (assignment_expression left: (identifier) right: (identifier))) (expression_statement (update_expression (identifier)))) alternative: (break_statement)))) (continue_statement))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (update_expression (identifier))) (continue_statement))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (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 (update_expression (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier)))) alternative: (block (break_statement)))) alternative: (block (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 (assignment_expression left: (identifier) right: (identifier))) (expression_statement (update_expression (identifier)))) alternative: (break_statement)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal)))) consequence: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (decimal_integer_literal)))) alternative: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))))))))