There are
We will draw
- Each point is an end point of exactly one line segment.
- Each line segment connects a white point and a black point.
Among the
Input Specification
Read the following data from the standard input.
Here B
or W
, and the 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
Constraints
. is a string of length which consists ofB
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

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