public static void process ( ) throws IOException {
  int a = ni ( ) ;
  int b = ni ( ) ;
  int p = ni ( ) ;
  String s = nln ( ) ;
  char ch [ ] = s . toCharArray ( ) ;
  int n = ch . length ;
  int index = n - 1 ;
  int cost = 0 ;
  for ( int i = n - 2 ;
  i >= 0 ;
  i -- ) {
    if ( i == 0 ) {
      int x = ( ch [ i ] == 'A' ) ? a : b ;
      if ( cost + x <= p ) {
        index = i ;
      }
    }
    else {
      int x = ( ch [ i ] == 'A' ) ? a : b ;
      if ( ch [ i ] == ch [ i - 1 ] ) {
        continue ;
      }
      else {
        if ( cost + x > p ) {
          break ;
        }
        else if ( cost + x <= p ) {
          index = i ;
          cost += x ;
        }
      }
    }
  }
  pn ( index + 1 ) ;
}

public static void process ( ) throws IOException { int a = ni ( ) ; int b = ni ( ) ; int p = ni ( ) ; String s = nln ( ) ; char ch [ ] = s . toCharArray ( ) ; int n = ch . length ; int index = n - 1 ; int cost = 0 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( i == 0 ) { int x = ( ch [ i ] == ' A ' ) ? a : b ; if ( cost + x <= p ) { index = i ; } } else { int x = ( ch [ i ] == ' A ' ) ? a : b ; if ( ch [ i ] == ch [ i - 1 ] ) { continue ; } else { if ( cost + x > p ) { break ; } else if ( cost + x <= p ) { index = i ; cost += x ; } } } } pn ( index + 1 ) ; }
(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 name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (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: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (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: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (ternary_expression condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal))) consequence: (identifier) alternative: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier)))))) alternative: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (ternary_expression condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal))) consequence: (identifier) alternative: (identifier)))) (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 (continue_statement)) alternative: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))) consequence: (block (break_statement)) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier)))))))))))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))))))