P3392 Painting Stripes
Description
As long as a flag composed of $N \times M$ small squares meets the following rules, it is a valid pattern.
- All cells in the top several rows (at least one row) are white.
- The next several rows (at least one row) are blue.
- The remaining rows (at least one row) are red.
There is a cloth divided into $N$ rows and $M$ columns of cells, where each cell is one of white, blue, or red. Xiao A hopes to turn this cloth into a valid pattern by painting some cells to cover their previous colors.
Xiao A is lazy and wants to repaint the fewest cells so that the cloth becomes a valid pattern.
Input Format
The first line contains two integers $N, M$.
Each of the next $N$ lines is a string of length $M$, where each character is one of `W` (white), `B` (blue), or `R` (red).
Output Format
A single integer, the minimum number of cells that need to be repainted.
Explanation/Hint
### Sample Explanation
Target state is:
```plain
WWWWW
BBBBB
RRRRR
RRRRR
```
In total, $11$ cells need to be changed.
### Constraints
For $100\%$ of the testdata, $N, M \leq 50$.
Translated by ChatGPT 5