atcoder#ABC288G. [ABC288G] 3^N Minesweeper

[ABC288G] 3^N Minesweeper

Score : 600600 points

Problem Statement

There is zero or one bomb at each of positions 0,1,2,,3N10, 1, 2, \ldots, 3^N-1. Let us say that positions xx and yy are neighboring each other if and only if the following condition is satisfied for every i=1,,Ni=1, \ldots, N.

  • Let xx' and yy' be the ii-th lowest digits of xx and yy in ternary representation, respectively. Then, xy1|x' - y'| \leq 1.

It is known that there are exactly AiA_i bombs in total at the positions neighboring position ii. Print a placement of bombs consistent with this information.

Constraints

  • 1N121 \leq N \leq 12
  • There is a placement of bombs consistent with A0,A1,,A3N1A_0, A_1, \ldots, A_{3^N-1}.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

A0A_0 A1A_1 \ldots A3N1A_{3^N-1}

Output

Print B0,B1,,B3N1B_0, B_1, \ldots, B_{3^N-1} with spaces in between, where Bi=0B_i = 0 if position ii has no bomb and Bi=1B_i = 1 if position ii has a bomb.

1
0 1 1
0 0 1

Position 00 is neighboring positions 00 and 11, which have 00 bombs in total. Position 11 is neighboring positions 00, 11, and 22, which have 11 bomb in total. Position 22 is neighboring positions 11 and 22, which have 11 bombs in total. If there is a bomb at only position 22, all conditions above are satisfied, so this placement is correct.

2
2 3 2 4 5 3 3 4 2
0 1 0 1 0 1 1 1 0
2
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0