QOJ.ac

QOJ

Time Limit: 0.5 s Memory Limit: 32 MB Total points: 100

#12981. Mastermind II

統計

We shall consider sequences that meet the following conditions:

  • the length of the sequence is $c$,
  • the elements of the sequence are digits from the range of 1-9,
  • the elements are not repeated in the sequence.

A single sequence will be called a code.

When two codes are given we estimate their compatibility giving two numbers. The first one (column A in the example) is the sum of those digits that occur in both codes and appear on the same positions in both sequences, whilst the second number (column B) is the sum of those digits that occur in both codes but appear on different positions.

We are given $c$ codes and their compatibility estimations with some unknown code. One should find and present the unknown code. Sample data and a result for $c=3$ are presented below.

A B codes
4 0 4 9 7
0 10 6 7 4
0 5 9 4 1
unknown code 4 1 6

Task

Write a program which:

  • reads a description of codes and estimations of their compatibility,
  • finds a code meeting the conditions of the task,
  • writes the result.

Input

Your program should read the description from the standard input. In the first line there is one integer $c$, $1 \le c \le 9$. In the following $c$ lines there are the descriptions of the given codes of digits and the estimations of their compatibility with some unknown code, one per line. In each of the lines there are $c+2$ non-negative integers separated by single spaces. The first and the second number are the estimation of compatibility of the given code with the unknown one, and the last numbers are different digits from the range of 1-9 forming the given code.

Output

Your program should write to the standard output. There should be $c$ different digits from the range of 1-9 forming the code to be found, separated by single spaces.

You may assume that for the test data there is at least one solution. If for the input data there exist many satisfying codes, your program should write out only one of them (arbitrary).

Example

Input

3
4 0 4 9 7
0 10 6 7 4
0 5 9 4 1

Output

4 1 6
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.