2019 South Central USA Regional Contest

#### Start

2019-11-09 09:00 AKST

## 2019 South Central USA Regional Contest

#### End

2019-11-09 14:00 AKST
The end is near!
Contest is over.
Not yet started.
Contest is starting in -928 days 8:56:42

5:00:00

0:00:00

# Problem JThis Ain't Your Grandpa's Checkerboard

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.

## Input

The first line contains an integer $n$ ($2\le n\le 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.

## Output

If the grid is correct, print the number $1$ on a single line. Otherwise, print the number $0$ on a single line.

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