#P1857. LittleElephantwithBall

LittleElephantwithBall

Little Elephant from the Zoo of Lviv likes balls. He has some balls that he wants to arrange into a row on the table. Each of those balls has one of three possible colors: red, green, or blue.

You are given a string S. This string represents all of the balls Little Elephant has, in the order in which he will be placing them onto the table. Red, green, and blue balls are represented by the characters 'R', 'G', and 'B', respectively. Each time Little Elephant places a new ball onto the table, he may add it anywhere into the row of already placed balls.

Additionally, each time Little Elephant adds a ball to the table, he scores some points (possibly zero). The number of points is calculated as follows:

If this is the first ball being placed on the table, there are 0 points for it.
If he adds the current ball to one of the ends of the row, the number of points scored is equal to the number of different colors of the balls on the table, excluding the current ball.
If he adds the current ball between two other balls, the number of points scored is equal to the number of different colors of the balls before the current ball, plus the number of different colors of the balls after the current ball.
For example, suppose that the balls currently on the table form the row "GBBG". Little Elephant now wants to add a new red ball ('R'). One of the options is to add it to the beginning. This scores 2 points and produces the row "RGBBG". Another option is to add it between "GBB" and "G". There are 2 distinct colors in "GBB" and 1 in "G", so this move is worth 2+1 = 3 points. This move produces the row "GBBRG".

Return the maximum total number of points that Little Elephant can earn for placing the balls onto the table.

Input

Test end with EOF
For each case, there is a string being input

Output

Output the maximum totall number of points that Little Elephant can earn for placing the balls onto the table.

Sample Input

RGB
RGGRBBB
RRRGBRR
RRRR
GGRRRGR
G

Sample Output

3
21
16
5
18
0

HINT

Source