#P7372. [COCI 2018/2019 #4] Slagalica
[COCI 2018/2019 #4] Slagalica
Description
Jurica created a jigsaw puzzle game. It is a parallelogram with rows and columns, made up of multiple nodes.
In the puzzle, rows are numbered from to from bottom to top, and columns are numbered from to from left to right. Each node is denoted by , where and are the row and column, respectively. Each node has a unique integer weight in .
The puzzle is considered solved when, for the -th row, the weights of the nodes from left to right are .
When , the puzzle looks like the figure below:

There are two types of operations that can be performed on the puzzle:
- Select a unit rhombus that contains nodes , and rotate it clockwise.

- Select a unit equilateral triangle that contains nodes , and rotate it clockwise.

Jurica performed several operations and called them one big operation. Then he repeated this big operation several times and surprisingly solved the puzzle.
Given the puzzle size and the number of repetitions of the big operation, determine whether there exists a big operation such that, starting from the solved puzzle, after repeating this big operation times, it returns to the solved state for the first time. If it is possible, output the operations that make up the big operation.
Input Format
Input integers .
Output Format
If there is no big operation that satisfies the requirement, output -1.
Otherwise, output any valid big operation. This problem uses Special Judge (see the attachment).
If a valid big operation exists, output the number of operations in the big operation in the first line, and then output the following format in the next lines:
- , meaning to apply operation 1;
- , meaning to apply operation 2;
The output are the chosen coordinates for the corresponding operation.
The output must satisfy , , .
2 3 2
5
R 1 1
R 1 1
T 1 1
T 1 1
T 1 1
3 3 12
3
R 1 1
T 2 2
T 2 1
5 4 116
-1
Hint
Constraints
For of the testdata, , .
For of the testdata, , .
Notes
The scoring of this problem follows the original COCI problem, with a full score of .
Translated from COCI2018-2019 CONTEST #4 T4 Slagalica.
Translated by ChatGPT 5
京公网安备 11011102002149号