Problem B
This Ain't Your Grandpa's Checkerboard

You are given an
-
Every row has the same number of black squares as it has white squares.
-
Every column has the same number of black squares as it has white squares.
-
No row or column has
or more consecutive squares of the same color.
Given a grid, determine whether it is correct.
Input
The first line contains an integer
Output
If the grid is correct, print the number
Sample Input 1 | Sample Output 1 |
---|---|
4 WBBW WBWB BWWB BWBW |
1 |
Sample Input 2 | Sample Output 2 |
---|---|
4 BWWB BWBB WBBW WBWW |
0 |
Sample Input 3 | Sample Output 3 |
---|---|
6 BWBWWB WBWBWB WBBWBW BBWBWW BWWBBW WWBWBB |
0 |
Sample Input 4 | Sample Output 4 |
---|---|
6 WWBBWB BBWWBW WBWBWB BWBWBW BWBBWW WBWWBB |
1 |