Tiling the Shower Floor (Large)

Fill a 2^K by 2^K grid with L shaped trominoes leaving one drain cell empty, using the specified recursive placement and numbering scheme.

Medium6Divide and conquerRecursionImplementationSimulationInterviewNo attempts yetTime limit1sMemory limit512 MB

Problem

Mingyu reports to the training center today. After the ceremonies he goes back to the barracks to rest, but the instructor calls him out and asks whether he knows Junseo. Junseo tiled the shower floor and covered the spot where the drain has to go, so Mingyu, who went to the same school, has to lay the floor again.

The shower floor is a square whose side length is a power of two. Junseo filled the whole floor with 2×22 \times 2 tiles, and that leaves no way to keep the drain cell empty. An L shaped tile that covers three cells does work: it can cover every cell except the single drain cell. The L tile is a 2×22 \times 2 square with one cell removed, and you may rotate it in any of the four directions.

Find a placement that covers every cell except the drain cell with L tiles that do not overlap.

Input

The first line contains a natural number KK (1K7)(1 \le K \le 7) that fixes the size of the floor. The side length of the floor is 2K2^K.

The second line contains two natural numbers xx and yy (1x,y2K)(1 \le x, y \le 2^K), separated by a space, giving the position of the drain. The bottom left cell is (1,1)(1, 1) and the top right cell is (2K,2K)(2^K, 2^K).

Output

Print the layout of the floor on 2K2^K lines. The first line is the row with y=2Ky = 2^K and the last line is the row with y=1y = 1. On each line print the cells from x=1x = 1 to x=2Kx = 2^K, separated by single spaces. Print 1-1 for the drain cell and the number of the covering tile for every other cell.

Many placements exist, so the following rule picks one answer. Only a layout that follows this rule exactly is accepted.

Place the tiles by this recursive rule.

  • A square of side length 11 holds only the drain cell, so no tile is placed there.
  • Split a square of side length 2k2^k (k1)(k \ge 1) into four quadrants of side length 2k12^{k-1}. Each quadrant has exactly one cell that touches the center of the square. Cover with a single L tile the three such cells that belong to the three quadrants without the drain. Then treat each of those three cells as the drain of its own quadrant and apply the same rule to all four quadrants.

Number the tiles after the placement is finished. Scan the rows in increasing order of yy, and within a row scan the cells in increasing order of xx. Each time you meet a tile that has no number yet, give it the next number: 11, 22, 33, and so on.

For 1K71 \le K \le 7 such a placement always exists, and no tile number exceeds 1900019000.