#agc059a. [agc059_a]My Last ABC Problem
[agc059_a]My Last ABC Problem
Problem Statement
Consider a string consisting only of characters A
, B
, and C
. We can do the following operation with it:
- Choose any substring t and any permutation of characters
A
B
C
. Here, t denotes the substring formed by the -th through the -th characters of , where and are of your choice. Then, replace each characterA
,B
, andC
in t by , , and , respectively.
For example, for a string ACBAAC
, we can choose a substring t and C
B
A
. After this operation, the string will become ACBCCA
.
Alina likes strings in which all characters are the same. She defines the beauty of a string as the minimum number of operations required to make all its characters equal.
You are given a string of length consisting only of characters A
, B
, and C
. Answer queries. The -th query is the following:
- Given integers and , find the beauty of the substring t=S.
Constraints
- is a string of length consisting only of characters
A
,B
, andC
. - All numbers in the input are integers.
Input
Input is given from Standard Input in the following format:
Output
Output lines. In the -th line, output the answer to the -th query.
Sample Input 1
Sample Output 1
In the first query, the string is CCC
, in which all letters are already equal. The answer is .
In the second query, the string is BC
. We can change it to BB
in one operation, by choosing a substring t and A
C
B
.
In the third query, the string is ABC
. We can change it to AAB
in one operation, by choosing a substring t and C
A
B
, and then to BBB
in the next operation, by choosing a substring t and B
A
C
.