eolymp
bolt
Try our new interface for solving problems
Problems

k-th Meander

k-th Meander

In this problem, you have to find the lexicographically \textbf{k}-th meander of order \textbf{n}. Consider a straight line drawn on a plane. A meander of order \textbf{n} is a closed planar curve which intersects the straight line \textbf{2n} times. One can imagine the meander as a twisting road loop which intersects a straight segment of a river via bridges. The intuitive definition above must however be refined with a few formal conditions: the curve can have no self-intersections or self-touchings, all \textbf{2n} points where the curve intersects the line are different and are indeed intersections, not touchings, and furthermore, the curve and the line have no common points except the above-mentioned ones. \includegraphics{https://static.e-olymp.com/content/4c/4ca24a599b42dc3aa6de07321c09285f4a5a5379.jpg} Let us define a convenient way to draw a meander. Without loss of generality, let the straight line be placed horizontally, and the intersection points put regularly with unit distances between them. Note that the intersection points divide the curve into \textbf{2n} parts. Certain n parts are above the line, and the other \textbf{n} parts below it. We draw each of these parts as semicircles based on the corresponding segments of the line as diameters and located either above or below the line, as needed. One can prove that the picture we got is a meander: in particular, the curve constructed in this way has no self-intersections or self-touchings. The inverse is also true: every meander can be transformed to such picture by a coutinuous (homeomorphic) transformation. Now, let us learn to write a meander down as a string. Consider a meander drawn according to the above procedure. Let us walk along the line from left to right and take a note every time we meet an intersection point. For each such point, there are two parts of the curve connected with it: one above and one below the line. Each of these parts is a semicircle going either to the left or to the right from the current intersection point. We will distinguish between four possible cases and label each case with an English letter: \begin{itemize} \item If both semicircles go to the right, we shall say that the curve opens at this intersection and denote it with the letter \textbf{O} (open). \item If both semicircles go to the left, we shall say that the curve closes at this intersection and denote it with the letter \textbf{C} (close). \item If the lower semicircle goes to the left and the upper one to the right, we shall say that the curve goes up at this intersection and denote it with the letter \textbf{U} (up). \item If the upper semicircle goes to the left and the lower one to the right, we shall say that the curve goes down at this intersection and denote it with the letter \textbf{D} (down). \end{itemize} Moving from left to right, write down the \textbf{2n} letters which we used to label the intersections. It turns out that this information is enough to uniquely restore the drawing of a meander obtained by the procedure above. One can imagine this process as drifting with the current of the river (from left to right) and writing down the configuration of roads in the immediate vicinity of the bridges. Two meanders are considered different if their notations are different. As an example, all eight different meanders of order \textbf{3} are presented below. \includegraphics{https://static.e-olymp.com/content/18/181f493b4a4cf2697e12d3be398c3719c3db9b6c.jpg} For a fixed order \textbf{n}, take all different meanders of this order, and then sort them lexicographically by their notations. Given the order \textbf{n} and the number \textbf{k}, find the notation of the lexicographically \textbf{k}-th meander of order \textbf{n}. \InputFile The first line contains two integers \textbf{n} and \textbf{k}: the order and the number of a meander (\textbf{1} ≤ \textbf{n} ≤ \textbf{25}, \textbf{1} ≤ \textbf{k} ≤ \textbf{10^11}). It is guaranteed that a meander with the given parameters exists. \OutputFile Print a string consisting of \textbf{2n} letters: the notation of the meander which has the number \textbf{k} in a lexicographically sorted list of meanders of order \textbf{n}.
Time limit 4 seconds
Memory limit 64 MiB
Input example #1
3 1
Output example #1
ODOUCC
Source 2014 Petrozavodsk, Ivan Kazmenko Contest, August 22, Problem F