#d2551. 网格判断

网格判断

Grid Check

Problem Description

You are given an n×nn \times n 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 33 or more consecutive squares of the same color.

Given the grid, determine whether it is correct.

Input Format

The first line contains an integer nn (2≤n≤242 \leq n \leq 24); nn is an even number.

The next nn lines each contain a string of length nn consisting of the characters B and W, representing the colors of the grid squares.

Output Format

If the grid is correct, print the number 11 on a line. Otherwise, print the number 00 on a line.

Sample Input

4
WBBW
WBWB
BWWB
BWBW

Sample Output

1