Score : $400$ points
There is a perfect binary tree with $2^{10^{100}}-1$ vertices, numbered $1,2,...,2^{10^{100}}-1$.
Vertex $1$ is the root. For each $1\leq i < 2^{10^{100}-1}$, Vertex $i$ has two children: Vertex $2i$ to the left and Vertex $2i+1$ to the right.
Takahashi starts at Vertex $X$ and performs $N$ moves, represented by a string $S$. The $i$-th move is as follows.
U
, go to the parent of the vertex he is on now.L
, go to the left child of the vertex he is on now.R
, go to the right child of the vertex he is on now.Find the index of the vertex Takahashi will be on after $N$ moves. In the given cases, it is guaranteed that the answer is at most $10^{18}$.
U
, L
, and R
.Input is given from Standard Input in the following format:
$N$ $X$ $S$
Print the answer.
3 2 URL
6
The perfect binary tree has the following structure.
In the three moves, Takahashi goes $2 \to 1 \to 3 \to 6$.
4 500000000000000000 RRUU
500000000000000000
During the process, Takahashi may be at a vertex whose index exceeds $10^{18}$.
30 123456789 LRULURLURLULULRURRLRULRRRUURRU
126419752371