#P3681. [CERC2016] 舞动的盘子 Dancing Disks

[CERC2016] 舞动的盘子 Dancing Disks

Description

Luka is very good at solving the Tower of Hanoi problem, and he invented a similar game that uses disks and pegs. The game has nn disks of different sizes and 3636 pegs. The disks are numbered from 11 to nn from smallest to largest. The pegs form a 6×66 \times 6 grid: rows are numbered 11 to 66 from top to bottom, and columns are numbered 11 to 66 from left to right.

At the beginning, all nn disks are stacked on the peg at (1,1)(1,1). In each move, you may choose a peg, take the top several disks, then choose some peg to its right in the same row or some peg below it in the same column, and place all the taken disks on top of that peg (their order is preserved; they are not reversed). The goal is to move all disks to (6,6)(6,6), with strictly decreasing sizes from bottom to top.

Given the initial configuration, find any sequence of moves that completes the game. It is guaranteed that a solution exists.

Input Format

The first line contains a positive integer nn (1n400001 \le n \le 40000), the number of disks.

The second line contains nn positive integers d1,d2,,dnd_1, d_2, \cdots, d_n (1din1 \le d_i \le n), listing from bottom to top the labels of the disks on the peg at (1,1)(1,1).

It is guaranteed that no two disks have the same label.

Output Format

Output mm lines, where mm is the number of moves in your solution.

In the ii-th line, output 44 items ri,ci,pi,nir_i, c_i, p_i, n_i, meaning that in the ii-th move you choose the top nin_i (ni1n_i \ge 1) disks from (ri,ci)(r_i, c_i) and move them in direction pip_i.

If you move to the right, then pip_i is R; if you move downward, then pip_i is D.

If there are multiple valid solutions, output any one.

6
1 6 5 4 3 2
1 1 D 6
2 1 D 6
3 1 D 6
4 1 D 6
5 1 D 6
6 1 R 6
6 2 R 6
6 3 R 6
6 4 R 6
6 5 R 5
6 5 R 1

Hint

Translated by ChatGPT 5