This Ain't Your Grandpa's Checkerboard
题号:NC218995
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

You are given an n−by−n grid where each square is colored either black or white. A grid is correct if all of the following conditions are satisfied:

  • 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 3 or more consecutive squares of the same color.

Given a grid, determine whether it is correct.

输入描述:

The first line contains an integer n(2≤n≤24; n is even ) . Each of the next n lines contains a string of length n consisting solely of the characters ‘B’ and ‘W’, representing the colors of the grid squares.

输出描述:

If the grid iscorrect, print the number 1 on a single line. Otherwise, print the number 0 on a single line.
示例1

输入

复制
4
WBBW
WBWB
BWWB
BWBW

输出

复制
1
示例2

输入

复制
4
BWWB
BWBB
WBBW
WBWW

输出

复制
0
示例3

输入

复制
6
BWBWWB
WBWBWB
WBBWBW
BBWBWW
BWWBBW
WWBWBB

输出

复制
0
示例4

输入

复制
6
WWBBWB
BBWWBW
WBWBWB
BWBWBW
BWBBWW
WBWWBB

输出

复制
1