Under construction

Still being built. Things may change

Minecraft

Time limit1.52sMemory limit1024 MB

Summary
Given three 2D projections of a 3D 0/1 grid, construct any consistent 3D grid or report impossibility.
Level

Medium6 of 10

Topics
Matrix, Greedy, Implementation
Solved
No attempts yet

Problem

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

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

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

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

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

Input

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

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

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

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

Output

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

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

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

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

Examples2

  1. Example 1

    Input
    5
    11111
    10000
    10000
    10000
    11111
    11111
    10000
    10000
    10000
    11111
    11111
    10000
    10000
    10000
    11111
    
    Expected output
    YES
    11111
    10000
    10000
    10000
    11111
    10000
    00000
    00000
    00000
    00000
    10000
    00000
    00000
    00000
    00000
    10000
    00000
    00000
    00000
    00000
    11111
    10000
    10000
    10000
    11111
    
  2. Example 2

    Input
    4
    0111
    0001
    1100
    1101
    1010
    0111
    0010
    0101
    1101
    1111
    0111
    1101
    
    Expected output
    NO