#P7372. [COCI 2018/2019 #4] Slagalica

[COCI 2018/2019 #4] Slagalica

Description

Jurica created a jigsaw puzzle game. It is a parallelogram with NN rows and MM columns, made up of multiple nodes.

In the puzzle, rows are numbered from 11 to NN from bottom to top, and columns are numbered from 11 to MM from left to right. Each node is denoted by (x,y)(x,y), where xx and yy are the row and column, respectively. Each node has a unique integer weight in [1,N×M][1, N \times M].

The puzzle is considered solved when, for the ii-th row, the weights of the nodes from left to right are M(i1)+1MiM(i-1)+1 \sim Mi.

When N=3,M=4N=3, M=4, the puzzle looks like the figure below:

There are two types of operations that can be performed on the puzzle:

  1. Select a unit rhombus that contains nodes (x,y),(x+1,y),(x+1,y+1),(x,y+1)(x,y),(x+1,y),(x+1,y+1),(x,y+1), and rotate it clockwise.

  1. Select a unit equilateral triangle that contains nodes (x,y),(x+1,y),(x,y+1)(x,y),(x+1,y),(x,y+1), 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 KK of the big operation, determine whether there exists a big operation such that, starting from the solved puzzle, after repeating this big operation KK 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 N,M,KN, M, K.

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 BB in the big operation in the first line, and then output the following format in the next BB lines:

  • R x y\texttt{R x y}, meaning to apply operation 1;
  • T x y\texttt{T x y}, meaning to apply operation 2;

The output x,yx,y are the chosen coordinates (x,y)(x,y) for the corresponding operation.

The output must satisfy 1B5×1051 \le B \le 5 \times 10^5, 1X<N1 \le X \lt N, 1y<M1 \le y \lt M.

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 40%40\% of the testdata, N,M3N, M \le 3, K20K \le 20.

For 100%100\% of the testdata, 2N,M1002 \le N, M \le 100, 2K10122 \le K \le 10^{12}.

Notes

The scoring of this problem follows the original COCI problem, with a full score of 110110.

Translated from COCI2018-2019 CONTEST #4 T4 Slagalica.

Translated by ChatGPT 5