eolymp
bolt
Try our new interface for solving problems

Pyramids

It is not too hard to build a pyramid if you have a lot of identical cubes. On a flat foundation you lay, say, \textbf{10}×\textbf{10} cubes in a square. Centered on top of that square you lay a \textbf{9}×\textbf{9} square of cubes. Continuing this way you end up with a single cube, which is the top of the pyramid. The height of such a pyramid equals the length of its base, which in this case is \textbf{10}. We call this a \textit{high} pyramid. If you think that a high pyramid is too steep, you can proceed as follows. On the \textbf{10}×\textbf{10} base square, lay an \textbf{8}×\textbf{8} square, then a \textbf{6}×\textbf{6} square, and so on, ending with a \textbf{2}×\textbf{2} top square (if you start with a base of odd length, you end up with a single cube on top, of course). The height of this pyramid is about half the length of its base. We call this a \textit{low} pyramid. Once upon a time (quite a long time ago, actually) there was a pharaoh who inherited a large number of stone cubes from his father. He ordered his architect to use all of these cubes to build a pyramid, not leaving a single one unused. The architect kindly explained that not every number of cubes can form a pyramid. With \textbf{10} cubes you can build a low pyramid with base \textbf{3}. With \textbf{5} cubes you can build a high pyramid of base \textbf{2}. But no pyramid can be built using exactly \textbf{7} cubes. The pharaoh was not amused, but after some thinking he came up with new restrictions. \begin{enumerate} \item All cubes must be used. \item You may build more than one pyramid, but you must build as few pyramids as possible. \item All pyramids must be different. \item Each pyramid must have a height of at least \textbf{2}. \item Satisfying the above, the largest of the pyramids must be as large as possible (i.e., containing the most cubes). \item Satisfying the above, the next-to-largest pyramid must be as large as possible. \item And so on... \end{enumerate} Drawing figures and pictures in the sand, it took the architect quite some time to come up with the best solution. Write a program that determines how to meet the restrictions of the pharaoh, given the number of cubes. \InputFile The input consists of several test cases, each one on a single line. A test case is an integer \textbf{c} (\textbf{1} ≤ \textbf{c} ≤ \textbf{10^6}), giving the number of cubes available. The last test case is followed by a line containing a single zero. \OutputFile For each test case, display its case number followed by the pyramids to be built. The pyramids should be ordered with the largest first. Pyramids are specified by the length of their base followed by an \textbf{L} for low pyramids or an \textbf{H} for high pyramids. If two differenct pyramids have the same number of cubes, list the high pyramid first. Print "\textbf{impossible}" if it is not possible to meet the requirements of the pharaoh. Follow the format of the sample output.
Zaman məhdudiyyəti 5 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB
Giriş verilənləri #1
29
0
Çıxış verilənləri #1
Case 1: 3H 3L 2H
Mənbə ICPC 2011 World Finals