P1203 [USACO1.1] Broken Necklace
Description
You have a necklace made of $n$ beads that are red, white, or blue, arranged arbitrarily. Here are two examples for $n=29$:

The first and second beads are marked in the picture.
The necklace in Figure A can be represented by the string: `brbrrrbbbrrrrrbrrbbrbbbbrrrrb`.
Suppose you break the necklace at some point, lay it out in a line, then from one end start collecting beads of a single color until you encounter a bead of a different color, and do the same from the other end (the color you collect on the two sides may differ). Determine where to break the necklace to collect the maximum number of beads.
For example, for the necklace in Figure A, breaking between bead $9$ and bead $10$, or between bead $24$ and bead $25$, allows you to collect $8$ beads.
A string representing a necklace that may include white beads will use exactly the three symbols `r`, `b`, `w`.
Write a program to determine the maximum number of beads that can be collected from the given necklace.
::::info[白色珠子是什么?]
In some necklaces, there are also white beads (as in Figure B).
When collecting beads, any white bead you encounter may be treated as red or as blue.
::::
Input Format
The first line contains a positive integer $n$, the number of beads.
The second line contains a string of length $n$, where each character is `r`, `b`, or `w`.
Output Format
Output a single integer on one line: the maximum number of beads that can be collected from the given necklace.
Explanation/Hint
Constraints
For $100\%$ of the testdata, $3\le n \le 350$.
Translated from NOCOW.
USACO Training Section 1.1.
Translated by ChatGPT 5