시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.5 초 64 MB52125.000%

문제

Little P is very fond of the chips produced by Company X because they are crisp, very tasty and with each package he now increases his chances of winning the big prize at the end-of-year lottery. To take part in this lottery, all he has to do is collect the pieces of puzzle found in the packages. Whenever he finds four pieces that can be assembled to form a square (the square representing the assembled puzzle), he is to stick them to a sheet of paper, label them “Chips forever” and send them to Company X.

The puzzle pieces are made from cardboard, both sides having the same colour, and can be used in 8 distinct ways (in their current position or rotated by 90o, 180o, 270o on both sides).

The initial pieces were n by n squares. From each piece we chose 2 adjacent sides and we cut out some small squares (1 by 1). We cut at least one small square from each chosen side, but also leave at least one small square on each chosen side.

When assembled together they form a 2n–1 by 2n–1 square.

Each piece is given a number from 1 to 4. All the elements for a given piece have the same number, except for the cut out squares that are 0.

This is the last puzzle Little P was able to assemble:

He put these pieces together to form a 7 by 7 square as illustrated in the figure below.

Little P needs a program to help him assemble the puzzle.

You are given the four n by n puzzle pieces in order. They can be rotated and mirrored.

Your task is to assemble these four pieces to form a 2n-1 by 2n-1 square so that the pieces fit perfectly without overlapping and without any spaces between the pieces.

입력

The input contains the integer n on the first line, representing the size of the puzzle pieces. The next lines describe the 4 puzzle pieces in order.

A puzzle piece is represented by n lines. Each line contains n digits separated by one space.

A blank line separates the puzzle pieces.

출력

The output will contain 2n-1 lines with 2n-1 digits separated by one space that will represent an assembled puzzle.

제한

  • 3 ≤ n ≤ 20
  • In all the test cases the puzzle can be solved.
  • Any correct solution will be accepted.

예제 입력 1

3
0 1 1
1 1 0
1 1 1

0 0 2
2 2 2
0 2 2

3 3 3
0 3 3
0 3 0

4 4 0
4 4 4
4 0 0

예제 출력 1

4 4 3 3 3
4 4 4 3 3
4 1 1 3 2
1 1 2 2 2
1 1 1 2 2

The puzzle assembled in output contains all the pieces without any rotations or mirroring.

예제 입력 2

4
1 1 1 1
1 1 1 0
1 1 1 1
1 1 0 1

2 2 2 2
2 2 2 0
2 2 2 0
0 2 2 0

0 3 0 0
3 3 3 0
3 3 3 0
3 3 3 3

4 4 4 0
4 4 4 4
4 4 4 4
0 0 4 0

예제 출력 2

1 1 1 1 3 3 3
1 1 1 3 3 3 3
1 1 1 1 3 3 3
1 1 4 1 2 2 3
4 4 4 4 2 2 2
4 4 4 4 2 2 2
4 4 4 2 2 2 2

The puzzle assembled in puzzle.out, given in left, contains

  • piece 1 – used without rotation or mirroring;
  • piece 2 – rotated by 180o;
  • piece 3 – mirrored and rotated;
  • piece 4 – mirrored.

Another correct solution is:

3 3 3 1 1 1 1
3 3 3 3 1 1 1
3 3 3 1 1 1 1
3 2 2 1 4 1 1
2 2 2 4 4 4 4
2 2 2 4 4 4 4
2 2 2 2 4 4 4