When you travel to Egypt, you will probably want to enjoy the famous pyramids and possibly also to take a bus to Luxor to visit the Valley of the Kings. To overcome boredom during such a long trip, imagine you are trying to keep yourself occupied by observing a large clock above the driver’s seat. The clock is a digital one and uses the classical 7-segment display. Since the Egyptian buses are crowded and most local people use to carry strange things with them, your view may be obstructed and some segments possibly hidden.
If you think about such situations, you will quickly notice that it is sometimes possible to read the time reliably even if some of the segments are not visible. For example, in Figure 1, the clock cannot show anything else than 12:04.
In some other cases, there may be several possibilities and you cannot tell for sure what time is displayed. Figure 2 is a good example – the last digit may be 0, 5, 6, 8, or 9. But even if you cannot tell the time immediately, you do not lose hope. After a while, you take another look at the clock and see another “sample” of it. Meanwhile, the people moved a little bit, so you can see a different portion of the display now, as shown in Figure 3. The new picture is even more ambiguous if seen alone. But you are quite sure that no more than four minutes passed between the two samples. With this knowledge, you may not only say what time it is now, but also retroactively determine what time it was before.
Your task is to write a program that automates this process. Given samples of the display (with some segments potentially hidden) and the estimate of the time elapsed between every two consecutive samples, you have to compute what time was displayed at the clock when the samples were taken.