306891: CF1267B. Balls of Buma
Memory Limit:512 MB
Time Limit:3 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Balls of Buma
题意翻译
### 题目描述 巴尔夫在玩一个游戏。在这个游戏中,他将得到一串彩色的球。他需要选择一个颜色的球并在这串球中选择任意一个位置插入这个球。 当一个球被插入后,以下情况会重复发生:如果连续一串相同颜色的球**由于先前的操作而变长**,并且其长度大于或等于$3$,则这一串相同颜色的球都将被消除。 例如,一串球“AAABBBWWBB”。假如巴尔夫选择了一个颜色为‘W’的球,并将其插入到第$6$个位置(即‘B’和‘W’之间),此时颜色为‘W’的球将被消除,因为该操作使得此段变长且长度为$3$。现在,这串球为“AAABBBBB”。颜色为‘B’的球现在被消除了,因为颜色为‘B’的球段变长了,并且长度为$5$。剩下的球为“AAA”,由于没有任何操作使得颜色为‘A’的球段变长,所以无法再次进行消除。 巴尔夫想知道,如果给你任意一串球,有多少种插入的方式能使得所有的球都能被消除? ### 输入格式 一行字符串,长度不超过300000 ### 输出格式 一个整数,表示能使得所有的球都能被消除的方案总数题目描述
Balph is learning to play a game called Buma. In this game, he is given a row of colored balls. He has to choose the color of one new ball and the place to insert it (between two balls, or to the left of all the balls, or to the right of all the balls). When the ball is inserted the following happens repeatedly: if some segment of balls of the same color became longer as a result of a previous action and its length became at least $ 3 $ , then all the balls of this segment are eliminated. Consider, for example, a row of balls 'AAABBBWWBB'. Suppose Balph chooses a ball of color 'W' and the place to insert it after the sixth ball, i. e. to the left of the two 'W's. After Balph inserts this ball, the balls of color 'W' are eliminated, since this segment was made longer and has length $ 3 $ now, so the row becomes 'AAABBBBB'. The balls of color 'B' are eliminated now, because the segment of balls of color 'B' became longer and has length $ 5 $ now. Thus, the row becomes 'AAA'. However, none of the balls are eliminated now, because there is no elongated segment. Help Balph count the number of possible ways to choose a color of a new ball and a place to insert it that leads to the elimination of all the balls.输入输出格式
输入格式
The only line contains a non-empty string of uppercase English letters of length at most $ 3 \cdot 10^5 $ . Each letter represents a ball with the corresponding color.
输出格式
Output the number of ways to choose a color and a position of a new ball in order to eliminate all the balls.
输入输出样例
输入样例 #1
BBWWBB
输出样例 #1
3
输入样例 #2
BWWB
输出样例 #2
0
输入样例 #3
BBWBB
输出样例 #3
0
输入样例 #4
OOOWWW
输出样例 #4
0
输入样例 #5
WWWOOOOOOWWW
输出样例 #5
7