Welcome to ZOJ
Select Problem
ZOJ Problem Set - 2958
Correct the digit

Time Limit: 2 Seconds      Memory Limit: 65536 KB

To our acknowledgement, numbers can be displayed on computer screen as below, from 0 to 9:

._. ... ._. ._. ... ._. ._. ._. ._. ._.
|.| ..| ._| ._| |_| |_. |_. ..| |_| |_|
|_| ..| |_. ._| ..| ._| |_| ..| |_| ._|

As you can see, vertical bars and horizontal bars descript digits.

This technology has been used in Cheer bank today. The bank use optical scanner to read the accounts of checks, and display them on computer screen. But there is something wrong with the optical scanner, sometimes it recognizes bars (either vertical or horizontal) as dots. This makes some digit incorrect. To cope with such situation, the bank uses checksum.

The account in a check will always has 9 digit, namely, d1, d2, d3, ..., d9. We consider the account read by the scanner correct if
(9d1 + 8d2 + 7d3 + ... + d9) mod 11 = 0

You are to write a program to detect errors and try to correct them.

Note: Error seldom occurs. So if this does happen, at most 1 digit would be incorrect.


There are multiple test cases for this problem.

There are three lines for each test. Each line contains 27 characters, with no leading and tailing spaces. And you can assume that there is no malformed input, errors will just replace bars with dots.


Output the actual account for each test case if there is no error or the error can be corrected. If you can't find any solution, output "failure". If you can find more than one solution, output "ambiguous".

Sample Input


Sample Output



The solution for the first sample should be 123456789 because the second digit can be 2 or 3, but if it is 3, checksum will not be satisfied. And the fifth digit can be 5 or 6, but if the fifth digit is 6, there will be 2 two incorrect digits, this violates the rule: "at most 1 digit would be incorrect".

Author: GAO, Junxin
Source: ZOJ Monthly, May 2008
Submit    Status