Mõttemeister

No attempts yetTime limit1sMemory limit1024 MB

Statement

Mõttemeister is a board game for two players. The first player thinks of a secret 4-digit number, and the second player tries to guess it.

On each turn the guesser proposes a 4-digit number. The first player answers with two values $A$ and $B$, where $A$ is how many of the digits in the proposed number are correct, and $B$ is how many of those are also in the correct position.

The guesser then makes a new proposal, and the game continues until the guesser finds the secret number or the number of turns exceeds a given limit.

For example, suppose the secret number is $5247$. For the proposal $1234$ the answer would be $2$ (the digits $2$ and $4$ are correct) and $1$ (the digit $2$ is in the correct position).

If a proposal contains repeated digits, each digit is counted as correct only as many times as it occurs in the secret number.

Write a program that, from the given proposals and answers, finds all possible values of the secret number.

Input

The first line contains an integer $N$ ($1 \le N \le 10,000$). Each of the next $N$ lines describes one turn: the proposed 4-digit number, its count of correct digits $A$ ($0 \le A \le 4$), and the count of those digits that are also in the correct position $B$ ($0 \le B \le A$).

Output

On the first line print the number $M$ of possible values of the secret number. On the next $M$ lines print the possible secret numbers in increasing order, one per line. Every number is printed with exactly four digits, padded with leading $0$s if necessary.