#d2551. 网格判断
网格判断
Grid Check
Problem Description
You are given an grid in which each square is colored either black or white. The grid is correct if all of the following conditions hold:
- Each row contains the same number of black squares as white squares.
- Each column contains the same number of black squares as white squares.
- No row or column has or more consecutive squares of the same color.
Given the grid, determine whether it is correct.
Input Format
The first line contains an integer (); is an even number.
The next lines each contain a string of length consisting of the characters B and W, representing the colors of the grid squares.
Output Format
If the grid is correct, print the number on a line. Otherwise, print the number on a line.
Sample Input
4
WBBW
WBWB
BWWB
BWBW
Sample Output
1