In this puzzle, you are given a $0$-indexed $N \times N$ square grid consisting of distinct integers from $0$ to $N \times N - 1$, inclusive. Your goal is to reach the ordered state where the number at the intersection of the $i$-th row and the $j$-th column is equal to $i \times N + j$ for each $0 ≤ i, j < N$. You can achieve this goal using two types of moves:
Rearrangement refers to changing the order of the numbers without adding or removing any of them, and it may preserve the original order.
For example, if the current grid is:
| Row/Column | $0$ | $1$ | $2$ |
|---|---|---|---|
| $0$ | $2$ | $4$ | $6$ |
| $1$ | $8$ | $1$ | $5$ |
| $2$ | $7$ | $3$ | $0$ |
By performing the move "D $6$ $2$ $4$", we will obtain the following grid:
| Row/Column | $0$ | $1$ | $2$ |
|---|---|---|---|
| $0$ | $8$ | $1$ | $5$ |
| $1$ | $7$ | $3$ | $0$ |
| $2$ | $6$ | $2$ | $4$ |
However, if we instead execute move "R $2$ $8$ $7$", we would get:
| Row/Column | $0$ | $1$ | $2$ |
|---|---|---|---|
| $0$ | $4$ | $6$ | $2$ |
| $1$ | $1$ | $5$ | $8$ |
| $2$ | $3$ | $0$ | $7$ |
For $N = 3$, the target grid would look like this:
| Row/Column | $0$ | $1$ | $2$ |
|---|---|---|---|
| $0$ | $0$ | $1$ | $2$ |
| $1$ | $3$ | $4$ | $5$ |
| $2$ | $6$ | $7$ | $8$ |
You aim to solve the puzzle with fewer than $3 \times N$ moves. However, partial points may be awarded in case you use more moves or not solve the puzzle. Refer to the scoring section for details.
The first line contains a single integer: $N$.
The following $N$ lines describe the initial grid, with $N$ numbers on each line.
The first line should contain a single integer, $M$, the number of moves. Each of the following $M$ lines should contain a single move.