ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

1802. Cube Puzzle

Time limit: 1.0 second
Memory limit: 64 MB
Problem illustration
Petka's birthday present for Anka was an interesting wooden puzzle, which he had made himself. The puzzle consists of six flat n × n squares. Each square is lacquered on one side and has the other side divided into n2 square cells. There are columns with 1 × 1 sections on some cells; the height of each column is at most n.
Help Anka use these parts to assemble a lacquered n × n × n cube or determine that this is impossible. The parts of the puzzle can be rotated arbitrarily.

Input

The first line contains the integer n (2 ≤ n ≤ 20). Then the six parts of the puzzle are described. Each part is described by n lines consisting of n integers each. These integers are the heights of the columns on this part. The integers in each line are separated with a space. All heights are in the range from 0 to n. The sum of the heights of columns on all parts of the puzzle is n3.

Output

If it is impossible to assemble a lacquered cube from the described six parts, output the only line “No”. Otherwise, output “Yes” in the first line and then describe the scheme of assembling the cube. This description should contain n blocks, each block containing n lines with n integers in each line. The first block describes the lower layer of the cube, the second block describes the layer lying immediately on the lower layer, and so on. The last block describes the upper layer. The first line in the description of a layer corresponds to the back small cubes, the second line corresponds to the small cubes located immediately in front of the back small cubes, and so on. The last line describes the front small cubes. The small cubes in each line are described from left to right. Each integer is in the range from 1 to 6 and specifies the number of the part which the corresponding small cube belongs to (the parts are numbered from 1 to 6 as they are given in the input). If several schemes of assembling the cube are possible, output any of them.

Samples

inputoutput
3
0 0 0
1 0 1
1 2 0
1 0 0
1 1 1
0 0 0
0 2 1
1 0 0
0 0 0
0 1 0
0 0 0
0 2 1
1 0 0
0 0 1
0 2 1
0 0 1
0 2 1
1 0 0
Yes
3 4 4
1 4 1
1 1 5
3 3 2
5 6 2
5 1 2
6 4 2
3 6 6
5 5 6
3
0 0 0
0 3 0
0 0 0
2 0 0
0 0 0
0 0 0
0 0 2
0 0 0
0 0 0
2 0 0
0 0 0
0 0 0
0 0 2
0 0 0
0 0 0
2 1 2
2 1 2
2 2 2
No
Problem Author: Stanislav Vasilyev
Problem Source: NEERC 2010, Eastern subregional contest