#P3392. 涂条纹

涂条纹

Description

As long as a flag composed of N×MN \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 NN rows and MM 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,MN, M.

Each of the next NN lines is a string of length MM, 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.

4 5
WRWRW
BWRWB
WRWRW
RWBWR
11

Hint

Sample Explanation

Target state is:

WWWWW
BBBBB
RRRRR
RRRRR

In total, 1111 cells need to be changed.

Constraints

For 100%100\% of the testdata, N,M50N, M \leq 50.

Translated by ChatGPT 5