#P10493. Bloxorz II

Bloxorz II

Problem Description

Because of a great catastrophe, the Academy of Sciences has had no new students for many years (in this world, the Academy of Sciences also serves as a university). Therefore, this year's entrance test has milestone-like significance. As the top information expert of the Academy, this task naturally falls on you. After some thought, you decide to make a problem based on the Bloxorz game.

In the Bloxorz game, as shown in the figure below, there is a 1×11 \times 1 hole as the target on a platform, and a 2×1×12 \times 1 \times 1 rectangular block. The block can roll along its edges on the platform, but it must not lose contact with the platform.

The following figure shows the situation after the block in the above figure rolls to the right.

The next figure shows the situation after it rolls forward.

The task is to get the block into the target hole. Of course, at that time the block should be standing upright.

One roll is called one step. Your problem is: for a given situation, compute the minimum number of steps needed to roll the block into the target hole. Naturally, for freshmen, this is a very hard problem.

The freshmen you defeated feel unconvinced. So they come up with an even harder problem for you to solve:

There is an infinite platform with a coordinate system on it. Now the target hole is at (0,0)(0, 0). The position and state of the block (standing upright, parallel to the xx-axis, or parallel to the yy-axis) are given. Compute the minimum number of steps needed to make the block fall into the hole.

As a top information expert... of course this is not hard for you.

Input Format

The input file contains multiple sets of testdata.

Each test case is on one line in the format C x y, where C is a letter and xx and yy are two integers. This means the block covers the cell (x,y)(x, y) on the platform, and its state is C.

If C is the letter U, it means the block is standing upright.

If C is the letter V, it means the block is parallel to the xx-axis, and the other covered cell is (x+1,y)(x + 1, y).

If C is the letter H, it means the block is parallel to the yy-axis, and the other covered cell is (x,y+1)(x, y + 1).

The input ends at EOF.

Output Format

For each test case, output the answer on a separate line.

U 0 0
H 0 0 
V 1 0
0
4
1

Hint

For 20%20\% of the testdata, x,y100 \mid x \mid , \mid y \mid \le 100.

For 100%100\% of the testdata, x,y109\mid x\mid , \mid y\mid \le 10^9, and there are no more than 100100 test cases in the input.

Translated by ChatGPT 5