아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Monochrome Points

시간 제한1초메모리 제한512 MB

요약
원 위에 검은 점 N개와 흰 점 N개가 있을 때, 검은 점과 흰 점을 짝지어 선분을 그을 때 교차점 쌍의 최댓값을 구한다.
난이도

보통10점 중 7점

유형
그리디, 동적 계획법, 조합론, 문자열
정답자
아직 제출이 없습니다

문제

There are 2N points on a circle numbered from 1 through 2N, in clockwise order. Each point is either white or black. There are N white points and N black points.

We will draw N 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 N 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 N line segments.

입력

Read the following data from the standard input.

N S

Here S is a string of length 2N representing the colors of the points. Each character of S is either B or W, and the i-th character (1 ≤ i ≤ 2N) is the color of the i-th point. It is B if the point is black, and W if the point is white.

출력

Write one line to the standard output. The output should contain the maximum of the intersection number when we draw N line segments satisfying the conditions.

제한

  • 1 ≤ N ≤ 200 000.
  • S is a string of length 2N which consists of B and W. The character B appears N times in the string S, and the character W appears N times in the string S.

예제4

  1. 예제 1

    입력
    3
    BBWWBW
    
    예상 출력
    2
    
  2. 예제 2

    입력
    5
    BWBWBBWBWW
    
    예상 출력
    8
    
  3. 예제 3

    입력
    10
    WBBBWBBWWBWWBWWBWBWB
    
    예상 출력
    41
    
  4. 예제 4

    입력
    16
    WWWBWBBBBWWBWWBWWBBWWBBBWBBBWWBW
    
    예상 출력
    105