Chessboard
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Zenyk and Marichka drank some juice and decided that they want to learn how to play chess well.
To do this, they first need a chessboard — a board of 8 rows and 8 columns, consisting of black and white cells. The cell in the first row of the first column must be white, and any two cells adjacent by a side must have different colors.
Zenyk found some board in the basement, which turned out to be of the correct size, but in it, the cell at the intersection of the \(i\)-th row and \(j\)-th column is colored with color \(a_{ij}\). He decided to transform this board into a correct one using a sequence of actions. Each action can be of one of two types:
Zenyk swaps the colors of two cells of the board that are adjacent by a side. He spends exactly 1 minute on this.
Zenyk asks Marichka to swap the colors of two cells of the board that are adjacent diagonally. Since Marichka is well-organized, she does this instantly, i.e., spends 0 minutes.
Zenyk is wondering if he can form a correct chessboard, and if so, in what minimum number of minutes?
Input
8 rows are given with 8 characters in each, denoting the color \(a_{ij}\) of the cell at the intersection of
the \(i\)-th row and \(j\)-th column of the initial board. The
character W denotes a white cell, and the character
B — a black one.
Output
In the first line, output TAK if Zenyk and Marichka can
obtain a correct chessboard using the actions described in the
statement. Otherwise, output NI.
In the case of a positive answer, in the second line output the minimum number of minutes in which they can achieve their goal.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| WWWWWWWW BBBBBBBB WBWBWBWB BWBWBWBW WBWBWBWB BWBWBWBB WBWBWBWB BWBWBWWW | TAK 5 |
| Input (stdin) | Output (stdout) |
|---|---|
| WWWWWWWW WWWWWWWW WWWWWWWW WWWWWWWW WWWWWWWW WWWWWWWW WWWWWWWW WWWWWWWW | NI |
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|