cho.sh
Notes
Loading...

Minecraft

Time limit

1.52s

Memory limit

1024 MB

Problem

Think of the following problem while recalling the game Minecraft, released in 2009.

There is a three-dimensional grid MMM of size n×n×nn \times n \times nn×n×n. Let Mi,j,kM_{i,j,k}Mi,j,k​ be the cell on the iii-th layer, jjj-th row, and kkk-th column. Each cell contains at most one block. If the cell contains a block, Mi,j,k=1M_{i,j,k}=1Mi,j,k​=1; otherwise, Mi,j,k=0M_{i,j,k}=0Mi,j,k​=0.

Project the grid onto the three axis-aligned planes, producing three n×nn \times nn×n two-dimensional grids HHH, RRR, and CCC. They are defined as follows.

  • If Mi,j,k=1M_{i,j,k}=1Mi,j,k​=1 for at least one layer iii, then Hj,k=1H_{j,k}=1Hj,k​=1; otherwise, Hj,k=0H_{j,k}=0Hj,k​=0.
  • If Mi,j,k=1M_{i,j,k}=1Mi,j,k​=1 for at least one row jjj, then Ri,k=1R_{i,k}=1Ri,k​=1; otherwise, Ri,k=0R_{i,k}=0Ri,k​=0.
  • If Mi,j,k=1M_{i,j,k}=1Mi,j,k​=1 for at least one column kkk, then Ci,j=1C_{i,j}=1Ci,j​=1; otherwise, Ci,j=0C_{i,j}=0Ci,j​=0.

Three grids H′H'H′, R′R'R′, and C′C'C′ are given. Determine whether there exists a three-dimensional grid M′M'M′ whose projections satisfy H=H′H=H'H=H′, R=R′R=R'R=R′, and C=C′C=C'C=C′.

Input

The first line contains an integer nnn, the side length of the grid. (1≤n≤1001 \le n \le 1001≤n≤100)

The next nnn lines describe the grid H′H'H′. Each line is a length-nnn string consisting of 0 and 1; the kkk-th character of the jjj-th line is Hj,k′H'_{j,k}Hj,k′​.

The next nnn lines describe the grid R′R'R′. Each line is a length-nnn string consisting of 0 and 1; the kkk-th character of the iii-th line is Ri,k′R'_{i,k}Ri,k′​.

The final nnn lines describe the grid C′C'C′. Each line is a length-nnn string consisting of 0 and 1; the jjj-th character of the iii-th line is Ci,j′C'_{i,j}Ci,j′​.

Output

If a grid M′M'M′ satisfying the conditions exists, print YES on the first line.

Then print all nnn grids of size n×nn \times nn×n. Each grid must be printed using nnn lines, and each line must be a length-nnn string consisting of 0 and 1. In the iii-th printed grid, the kkk-th character of the jjj-th line corresponds to Mi,j,k′M'_{i,j,k}Mi,j,k′​.

If several valid grids exist, print any one of them.

If no grid M′M'M′ satisfies the conditions, print NO on the first line.