cswork / OAOpen practice workspace

DeloitteOA #1

Make Grid Symmetric

Estimated MediumJudge-ready

Topics (AI-labelled)In-place ArraysGreedy

In each operation, you may flip the color of one cell. Find the minimum number of flips so that every row and every column is symmetric about its own center.

This site's standard input/output format and any supplementary ranges follow this problem's description.

Input

The first line contains n m (1≤n,m≤200), followed by n strings of length m containing only B/W. The upper bounds on n and m are site supplements; the original problem gives none.

Output

Output the minimum number of cells to flip.

Example 1

Input:

3 5
BBWWB
WWWBW
BWWWB

Output:

2

Example 2

Input:

3 3
BWB
WBB
WBW

Output:

4

Example 3

Input:

1 1
W

Output:

0

Editorial

Loading solution…