Chessboard
Time limit2sMemory limit1024 MB
Given a black and white n by m grid, find the fewest full diagonal repaints (two diagonal directions) that turn it into a chessboard.
Statement
Vasya likes playing unusual chess. One day he came home from school and found that someone had repainted his favorite chessboard. It was his little brother Kolya, who was still very young. Vasya was not very angry with him, because he loved his younger brother a lot. The only paints at home were black and white, so every cell of the board is painted in one of these two colors.
Vasya decided to fix his brother's mistake by repainting the board so that it becomes a chessboard again, with adjacent cells having different colors. He only wants to paint diagonals, and always the whole diagonal at once. He wants to spend as little time as possible, so he is interested in the method that uses the fewest actions. In one action, Vasya can completely paint one diagonal in either of two colors: black or white. There are two types of diagonals, depending on the direction of the line they lie on. A diagonal that lies on a line going left and down is a diagonal of the first type. A diagonal that lies on a line going right and down is a diagonal of the second type.
You need to help Vasya. You are given the chessboard field spoiled by Kolya. Determine the minimum number of actions with which Vasya can repaint the board so that it becomes a chessboard again.
Input
The first line of the input contains two integers and (), the number of rows and the number of columns of the chessboard, respectively.
The next lines contain the field. Each line contains characters and describes one row of the chessboard. The character W stands for a white cell, and B stands for a black cell.
Output
In the first line of the output, print the number , the minimum number of actions Vasya needs to make his board a chessboard again.
The next lines describe the actions. Each action is described by three parameters: the diagonal type, the coordinates of some cell painted by this action (row and column), and the color. The diagonal type is the number 1 or 2. The color is the character W for white or B for black.