Stripe#3845

Stripe

0.5 seconds
256 megabytes
Very easy

Let be some positive integer. We have a paper stripe with n = 2^k cells. Cells are numbered left to right with numbers from to . Here is how the stripe looks like initially (this is a side view, not a top view!) for k = 3, and correspondingly, n = 8:

1 2 3 4 5 6 7 8

We can fold the stripe in the following way: stripe is marked in its center and, keeping one half not touched, fold the other up or down. First, we fold right half up. Then, we fold left half down, and finally, we fold left half up. This is how sample stripe will look like after each move:

As we see, numbers on the stripe from top to bottom stand in the following order: 7, 2, 3, 6, 5, 4, 1, 8.

This is what we need to find. in this task is fixed and equals . So we have a stripe with 2^{21} cells; this stripe is folded times, according to a sequence of folding instructions: LU (we fold left half up), LD (we fold left half down), RU (we fold right half up) or RD (we fold right half down). We need to determine the order of the numbers on the folded stripe. More exactly, we need to know numbers – they should appear on output.

Input

Contains the folding instructions and consists of lines – each line contains two symbols: LU, LD, RU or RD. The -th line contains the description of the -th (1 \leq m \leq 21) fold.

Output

Output consists of exactly lines. The -th line (1 \leq m \leq 1024) contains the -th number from top.

Examples

Sample data are too big to show on paper, but if k = 3 and you have to output the first numbers, the output is the following:

Example 1

Loading
Loading