시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB0000.000%

문제

Bulls and Cows is a game played between two players, one called the codemaker and the other the codebreaker. The codemaker forms a secret “code”, a decimal integer of K digits, all of them different. The codebreaker then attempts to guess the code by naming numbers of K digits. For each guess, the codemaker responds with the number of digits of correct value in the correct position (“Bulls”) and the number of correct digits in an incorrect position (“Cows”).

For example, if the secret code were 1230 and the codebreaker guessed 1205, the response would be “2 Bulls and 1 Cow”.

Write a program to read a series of guesses and responses for a game and to print the number of possible solutions and, from among all possible solutions, the numerically smallest one.

입력

Input consists of one or more game descriptions.

Each game description begins with a line with a single integer K in the range 1 . . . 7. A nonpositive value for K signals the end of input.

Each positive K is followed by some number of lines, each line containing one guess and response. Each line will contain K+2 single-digit numbers, separated by one or more blanks. The first K digits represent the guess. The next number represents the number of Bulls. The final digit is the number of Cows.

The end of the sequence of guess-and-response lines is signaled by a line of K integers, the first of which is -1.

출력

For each game description in the input, print a line of the form

N is one of M possible solutions.

where the N is a sequence of K digits, printed with no intervening spaces, and representing the numerically smallest possible solution, and where M is an integer denoting the number of possible solutions.

예제 입력 1

6
0 1 2 8 4 5 5 0
0 1 2 9 5 4 3 2
-1 1 2 3 4 5 0 0
0

예제 출력 1

012345 is one of 5 possible solutions.