QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 1024 MB 總分: 10

#8411. Puzzle 3 [C]

统计

Bajtek loves playing mobile games. However, he is often annoyed by advertisements for other games where the player performs very poorly, which is intended to frustrate the viewer and make them want to play. One such advertisement (which you may have had the opportunity to see yourself) has particularly stuck in Bajtek's memory.

Since inspiration can be drawn from anything, Bajtek decided to create a task based on the game above. He chooses a target colored board of dimensions $n \times m$, and starts the game with an $n \times m$ board where no cell has a color. In one move, he can choose a row or a column and repaint all cells in it with a color of his choice (note that this gives him more freedom than in the game shown in the pictures above, where rows and columns had fixed colors). To formalize the task, he denoted all colors with uppercase English letters. Will you help him and write a program that, for any board he specifies, provides a sequence of moves that correctly creates the target color layout? You can assume that you will receive input data for which this goal can be achieved in at most $n + m$ moves.

Input

The first line of standard input contains two integers $n$ and $m$ ($1 \le n, m \le 2\,000$), representing the height and width of the board, respectively.

Each of the next $n$ lines contains $m$ characters, each of which is an uppercase English letter; the $j$-th character in the $i$-th of these lines denotes the target color of the cell located in the $i$-th row and $j$-th column of the board.

It is guaranteed that the given color layout can be achieved with a sequence of at most $n+m$ moves as described in the problem.

Output

The first line of the output should contain a single integer $r$ ($1 \le r \le n+m$), representing the number of moves you want to make. Each of the next $r$ lines should contain a description of a move.

The description of a move should start with the character 'R' or 'K', indicating whether you want to repaint a row or a column (where 'R' stands for row and 'K' for column). Next, after a single space, there should be the number of the row or column you want to repaint. Rows are numbered from top to bottom with numbers from $1$ to $n$, and columns from left to right with numbers from $1$ to $m$. Then, after a single space, there should be a single uppercase English letter representing the color with which you want to repaint the chosen row or column.

Note that you do not need to minimize the number of moves – it is sufficient to perform at most $n + m$ moves.

Examples

Input 1

5 5
AAPAA
APPAA
AAPAA
AAPAA
APPPA

Output 1

10
R 1 Z
K 4 A
K 2 P
R 5 P
R 4 A
R 3 A
R 1 A
K 5 A
K 3 P
K 1 A

Input 2

2 3
AAA
PPP

Output 2

2
R 2 P
R 1 A

Note

Explanation of the example: If in the first example test we assume that the letter 'P' represents the color green, the letter 'A' represents the color yellow, and the letter 'Z' represents the color blue, then the chosen sequence of moves paints the board in the following way:

Figure 1. The target color layout and the sequence of moves.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.