Masala tavsifi
Karimjon works at the National Library. In the section where Karimjon works, there is a large bookshelf of size , where rows are numbered from to and columns from to .
The cell of the bookshelf contains a book with number . All book numbers on the shelf are distinct.
Karimjon can perform the following two operations:
- Row rearrangement: For every row, rearrange the books in that row in any order. The order can be chosen independently for each row.
- Column rearrangement: For every column, rearrange the books in that column in any order. The order can be chosen independently for each column.
Karimjon wants to sort the bookshelf. In a sorted bookshelf, row contains all books with numbers from to in increasing order, row contains all books with numbers from to in increasing order, and so on. That is, for all and , the condition must hold.
Let be the minimum number of operations needed to sort the bookshelf. You are also given a number , where .
If , you only need to find the minimum number of operations .
If , you need to find and also output the sequence of operations that achieves it.
Input Format
The first line contains three integers , , and .
The next lines each contain integers --- the elements .
Constraints:
Output Format
If , print a single integer --- the minimum number of operations.
If , print the operations in order. For each operation, print a line containing either row or col, indicating whether it is a row rearrangement or a column rearrangement. Then print lines, each containing integers --- the state of the bookshelf after applying this operation. Finally, on the last line, print --- the total number of operations performed.
Each row rearrangement must only permute elements within each row (the multiset of elements in each row must remain the same compared to the state before this operation). Each column rearrangement must only permute elements within each column (the multiset of elements in each column must remain the same compared to the state before this operation).
After all operations, the bookshelf must be sorted, i.e. for all .
The number of operations must equal , the minimum possible.
Scoring
| Subtask | Additional Constraints | Points | Required Subtask |
|---|---|---|---|
| Tests from the example | - | ||
Notes
Example 1:
Here . The minimum number of operations is . We perform one row rearrangement: in row , we rearrange into ; in row , we rearrange into .
Example 2:
Here , so we only need to output .
Example 3:
The minimum is . We perform: row rearrangement, then column rearrangement, then row rearrangement. After all three operations, the bookshelf is sorted.
Misollar
2 2 2 1 0 3 2
row 0 1 2 3 1
2 3 1 0 4 2 5 1 3
2
5 3 2 10 9 11 14 5 12 1 4 7 3 8 13 2 6 0
row 11 9 10 12 14 5 4 7 1 8 3 13 0 2 6 col 0 2 1 4 3 5 8 7 6 11 9 10 12 14 13 row 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 3