Under construction

Still being built. Things may change

Chessboard

Time limit2sMemory limit1024 MB

Summary
Given a black and white n by m grid, find the fewest full diagonal repaints (two diagonal directions) that turn it into a chessboard.
Level

Medium5 of 10

Topics
Graph, Matrix
Solved
No attempts yet

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 nn and mm (1≤n,m≤1001 \le n, m \le 100), the number of rows and the number of columns of the chessboard, respectively.

The next nn lines contain the field. Each line contains mm 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 pp, the minimum number of actions Vasya needs to make his board a chessboard again.

The next pp 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.

Examples3

  1. Example 1

    Input
    3 3
    WBB
    BWB
    BBW
    
    Expected output
    1
    1 1 3 W
    
  2. Example 2

    Input
    3 3
    WBW
    WWB
    WWW
    
    Expected output
    1
    2 2 1 B
    
  3. Example 3

    Input
    1 3
    WWW
    
    Expected output
    1
    1 1 2 B