Time limit
1.52s
Memory limit
1024 MB
Think of the following problem while recalling the game Minecraft, released in 2009.
There is a three-dimensional grid M of size n×n×n. Let Mi,j,k be the cell on the i-th layer, j-th row, and k-th column. Each cell contains at most one block. If the cell contains a block, Mi,j,k=1; otherwise, Mi,j,k=0.
Project the grid onto the three axis-aligned planes, producing three n×n two-dimensional grids H, R, and C. They are defined as follows.
Three grids H′, R′, and C′ are given. Determine whether there exists a three-dimensional grid M′ whose projections satisfy H=H′, R=R′, and C=C′.
The first line contains an integer n, the side length of the grid. (1≤n≤100)
The next n lines describe the grid H′. Each line is a length-n string consisting of 0 and 1; the k-th character of the j-th line is Hj,k′.
The next n lines describe the grid R′. Each line is a length-n string consisting of 0 and 1; the k-th character of the i-th line is Ri,k′.
The final n lines describe the grid C′. Each line is a length-n string consisting of 0 and 1; the j-th character of the i-th line is Ci,j′.
If a grid M′ satisfying the conditions exists, print YES on the first line.
Then print all n grids of size n×n. Each grid must be printed using n lines, and each line must be a length-n string consisting of 0 and 1. In the i-th printed grid, the k-th character of the j-th line corresponds to Mi,j,k′.
If several valid grids exist, print any one of them.
If no grid M′ satisfies the conditions, print NO on the first line.