#P11973. Maximum Chord Intersections on a Colored Circle

    ID: 14084 Type: Default 1000ms 256MiB

Maximum Chord Intersections on a Colored Circle

Maximum Chord Intersections on a Colored Circle

Given a circle with (2n) labeled points arranged in clockwise order and colored either black or white, with exactly (n) black and (n) white points, draw (n) chords connecting a black point with a white point such that each point is an endpoint of exactly one chord. Two chords are said to intersect if and only if their endpoints (when traversed clockwise) appear in an alternating order. In other words, if a chord connects points (a) and (b) (with (a < b) after a proper rotation) and another chord connects points (c) and (d) (with (c < d)), then these two chords intersect if and only if (a < c < b < d).

Your task is to determine the maximum number of intersecting pairs of chords that can be obtained by choosing an appropriate matching between black and white points.

Note: It is always allowed to draw a chord between any black and white point, even if the chord goes through the interior of the circle. You may assume that (n) is small (for example, (n \le 10)) so that brute‐force search is feasible.

inputFormat

The input consists of two lines. The first line contains a single integer (n) (the number of chords). The second line contains a string of length (2n) consisting only of the characters 'B' and 'W', which represent the colors (black and white respectively) of the points in clockwise order.

outputFormat

Output a single integer — the maximum number of intersecting pairs of chords that can be obtained.

sample

1
BW
0