QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#11295. Snake

統計

A snake fills a $3 \times n$ board completely. Successive segments of the snake are numbered from $1$ to $3n$. The segments with successive numbers (i.e., 1 and 2, 2 and 3, 3 and 4...) occupy squares that share an edge. For example, a snake can fill a $3 \times 9$ board as follows:

problem_11295_1.png

The snake's segment numbers in some of the squares have been erased. Can you reconstruct the snake?

Input Format

In the first line of the standard input, there is a single integer $n$ ($1 \le n \le 1\,000$), the length of the board. The three lines that follow describe the board; the $i$-th of them contains $n$ integers $a_{ij}$ ($0 ≤ a_{ij} ≤ 3n$ for $1 ≤ j ≤ n$). If $a_{ij} > 0$, then $a_{ij}$ is the number of the snake's segment occupying the $j$-th square of the $i$-th row of the board. If on the other hand $a_{ij}=0$, then the number of the snake's segment on this square is unknown.

Output Format

Your program is to print three lines to the standard output. The $i$-th lines should hold $n$ positive integers $b_{ij}$ (for $1 ≤ j ≤ n$). All the numbers $b_{ij}$ together should be a permutation of the numbers from $1$ to $3n$. The output numbers should be a valid reconstruction of the snake, i.e., they should be consistent with the (positive) input numbers and satisfy aforementioned constraints.

You may assume that there is at least one valid reconstruction of the snake. If there is more than one, your program can print any valid reconstruction.

Example

Input

9
0 0 5 0 17 0 0 0 21
8 0 0 3 16 0 0 25 0
0 0 0 0 0 0 0 0 23

Output

7 6 5 4 17 18 19 20 21
8 1 2 3 16 15 26 25 22
9 10 11 12 13 14 27 24 23
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.