QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#17529. Making Pizza for Hungry Muto

统计

While exploring Chu Chu Island to defeat the Black Mage, Kinesis encountered Hungry Muto. Simia, who feeds Muto every day, asked Kinesis for help in making a giant pizza for the grumpy Muto. Since the large Muto is blocking the path to the Black Mage, Kinesis has no choice but to accept Simia's request.

The giant pizza Muto wants is an $N \times N$ grid. The top-left cell is at row $1$, column $1$, and the bottom-right cell is at row $N$, column $N$. Simia's recipe shows the arrangement of meatballs that must be placed on the pizza, and Kinesis must top the pizza exactly as shown in the recipe. Initially, there is one meatball placed at row $R$, column $C$ by Simia. The shape of a meatball matches a grid cell exactly, and no more than one meatball can occupy a single cell.

The state of the pizza when $N=5, R=3, C=2$, and the positions outside the pizza where psychokinesis can be used

Since stepping on the pizza makes it inedible, Kinesis must complete the pizza by using psychokinesis from outside the pizza. The process of using psychokinesis once is as follows:

  1. Choose a position to use psychokinesis. The possible positions are one of the top, bottom, left, or right sides of the pizza. Psychokinesis starts from where Kinesis is positioned: if from the top, it acts in the direction of increasing row indices; if from the bottom, decreasing row indices; if from the left, increasing column indices; and if from the right, decreasing column indices.
  2. Choose the row or column number to apply the psychokinesis. Psychokinesis must be applied parallel to the rows or columns and cannot span more than one row or column.
  3. Use the psychokinesis. There are two types of psychokinesis:
    • push: Pushes a meatball into the grid and places it in the cell immediately in front of the first meatball it hits. If there is a meatball in the first cell in the direction of the psychokinesis before pushing, or if there are no meatballs in that direction such that the pushed meatball cannot be placed within the pizza, the pushed meatball disappears.
    • pull: Removes the first meatball hit by the psychokinesis from the pizza. If there are no meatballs in the direction of the psychokinesis, nothing happens.
Using the `push` and `pull` psychokinesis

If the pizza is topped according to Simia's recipe, Muto will eat the pizza happily and open the path to the next region. However, since Kinesis does not know when the Black Mage will destroy the world, he cannot afford to waste time making the pizza.

Output a method to complete the pizza using at most $2N^2$ uses of psychokinesis.

Input

The first line contains the size of the pizza $N$ ($3 \leq N \leq 50$).

The second line contains two space-separated integers $R$ and $C$, representing the row and column of the meatball initially placed by Simia ($1 \leq R, C \leq N$).

The next $N$ lines contain the arrangement of meatballs according to Simia's recipe. Each line contains a string of length $N$. The $j$-th character of the $i$-th line indicates whether there is a meatball at row $i$, column $j$, where . represents an empty cell and # represents a cell with a meatball.

Output

If the pizza can be completed using at most $2N^2$ uses of psychokinesis, output the number of times $M$ Kinesis used psychokinesis on the first line. Note that $M$ does not need to be the minimum ($0 \leq M \leq 2N^2$).

If $M \geq 1$, output the actions performed by Kinesis on the following $M$ lines, one per line. Each line should contain the position where psychokinesis was used (top: U, bottom: D, left: L, right: R), the row or column number $X$ ($1 \leq X \leq N$), and the type of psychokinesis (push or pull), separated by spaces.

If the pizza cannot be completed using $2N^2$ or fewer uses of psychokinesis, output only -1 on the first line.

Examples

Input 1

3
2 2
.#.
##.
...

Output 1

2
U 2 push
L 2 push

Input 2

3
1 2
...
#.#
.#.

Output 2

6
D 2 push
D 2 push
L 2 push
R 2 push
U 2 pull
U 2 pull

Input 3

4
1 1
....
....
....
....

Output 3

1
L 1 pull

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.