시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 512 MB 14 4 4 28.571%

문제

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 is correct, print the number 1 on a single line. Otherwise, print the number 0 on a single line.

예제 입력 1

4
WBBW
WBWB
BWWB
BWBW

예제 출력 1

1

예제 입력 2

4
BWWB
BWBB
WBBW
WBWW

예제 출력 2

0

예제 입력 3

6
BWBWWB
WBWBWB
WBBWBW
BBWBWW
BWWBBW
WWBWBB

예제 출력 3

0

예제 입력 4

6
WWBBWB
BBWWBW
WBWBWB
BWBWBW
BWBBWW
WBWWBB

예제 출력 4

1