eolymp
bolt
Try our new interface for solving problems
Problems

Hourglass

Hourglass

In this problem, you have to solve a puzzle involving a planar board and pieces. The Hourglass Puzzle of size \textbf{n} looks as follows. The board is drawn on a plane which consists of (\textbf{2} ∙ \textbf{n} + \textbf{1}) rows. The rows are horizontal and lie one under the other. Each row consists of positions: the middle row contains one position, and each other row below or above the middle contains one more position than its neighbor towards the middle. The positions in neighboring rows are connected so that each position of the shorter row has exactly two neighboring positions in the longer one. The board for \textbf{n} = \textbf{2} is illustrated below. \includegraphics{https://static.e-olymp.com/content/de/deaf15d6e76084479a5c77b7c6e7942184070b2a.jpg} There are some pieces on the board. Initially, each position of the \textbf{n} top rows contains a red piece (sand), and each position of the \textbf{n} bottom rows contains a blue piece (air). The goal of the puzzle is to swap the pieces, that is, to fill \textbf{n} top rows by air and \textbf{n} bottom rows by sand. Pieces of the same color are considered the same. There can be at most one piece in each position at any given moment. The initial and final positions for \textbf{n} = \textbf{2} are illustrated below. Red pieces are denoted by “\textbf{X}” while blue pieces are denoted by “\textbf{O}”. \includegraphics{https://static.e-olymp.com/content/ac/ac3fa91be4e1c4615882db7e84df53b00cebb1b5.jpg} Moving the pieces complies with the following rules. \begin{itemize} \item Red pieces can only move down, while blue pieces can only move up. \item On each move, exactly one piece changes its position. \item If for some piece, one of the two neighboring positions in the permitted direction (up-left or up-right for blue pieces, down-left or down-right for red ones) exists and is free, that piece can just move there. \item If that position is occupied by a piece of the other color, but the next position in the same direction (up-left, up-right, down-left or down-right) exists and is free, the piece can jump into that free position. \item Note that jumps are allowed only if they follow a straight line, have a length of two positions and go over a piece of the other color. Other kinds of jumps (for example, straight up or straight down by two rows) are not permitted. \end{itemize} The pictures below illustrate the sequence of moves allowing to solve the puzzle for \textbf{n} = \textbf{2}. \includegraphics{https://static.e-olymp.com/content/29/293f2b753481e51c001efc99ca8fa3ea83fe1a88.jpg} The sequence of moves can be written down in the following way. \begin{itemize} \item Moving or jumping up-left is denoted by lowercase English letter <<\textbf{b}>>. \item Moving or jumping up-right is denoted by lowercase English letter <<\textbf{d}>>. \item Moving or jumping down-left is denoted by lowercase English letter <<\textbf{p}>>. \item Moving or jumping down-right is denoted by lowercase English letter <<\textbf{q}>>. \end{itemize} The intuitive meaning of this notation is that the tail of each letter shows the direction of a movement or jump. It turns out that the information provided by such notation is enough to restore all intermediate states of the puzzle. Given \textbf{n}, the size of the puzzle, print out its solution. Note that you don’t have to minimize or maximize the number of moves. \InputFile The size \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{10}) of the puzzle. \OutputFile Print one line containing a solution to the puzzle of the given size. This line must contain only lowercase English letters <<\textbf{b}>>, <<\textbf{d}>>, <<\textbf{p}>> and <<\textbf{q}>> and no other characters, in particular, no spaces. If there are several possible solutions, print any one of them.
Time limit 13 seconds
Memory limit 64 MiB
Input example #1
2
Output example #1
dppdbqbdppqdqbbqdqpdbqb
Source 2014 Petrozavodsk, Ivan Kazmenko Contest, August 22, Problem E