There are points on a circle numbered from through , in clockwise order. Each point is either white or black. There are white points and black points.
We will draw line segments connecting these points so that the following conditions are satisfied.
- Each point is an end point of exactly one line segment.
- Each line segment connects a white point and a black point.
Among the line segments, the number of pairs of line segments intersecting each other is called the intersection number. Write a program which, given the information of the colors of the points, calculates the maximum of the intersection number when we draw line segments.
Input Specification
Read the following data from the standard input.
Here is a string of length representing the colors of the points. Each character of is either B
or W
, and the -th character is the color of the -th point. It is B
if the point is black, and W
if the point is white.
Output Specification
Write one line to the standard output. The output should contain the maximum of the intersection number when we draw line segments satisfying the conditions.
Constraints
- .
- is a string of length which consists of
B
andW
. The characterB
appears times in the string , and the characterW
appears times in the string .
Subtasks
- (4 points) .
- (21 points) .
- (10 points) .
- (65 points) No additional constraints.
Sample Input 1
3
BBWWBW
Sample Output 1
2
Explanation for Sample 1
If we draw line segments as in the figure on the left, then the intersection number is . On the other hand, if we draw line segments as in the figure on the right, then the intersection number is , but the conditions in the task statement are not satisfied.
Sample Input 2
5
BWBWBBWBWW
Sample Output 2
8
Sample Input 3
10
WBBBWBBWWBWWBWWBWBWB
Sample Output 3
41
Sample Input 4
16
WWWBWBBBBWWBWWBWWBBWWBBBWBBBWWBW
Sample Output 4
105
Comments