Faulty Traffic Light

시간 제한2초메모리 제한2048 MB

요약
두 자리의 세그먼트 고장 정보를 받아 주행 신호가 보여 주는 숫자가 1씩 증가하는 최대 연속 구간을 구합니다.
난이도

보통10점 중 5점

유형
완전 탐색, 해시맵, 문자열
정답자
아직 제출이 없습니다

문제

Near Vlad's home, there is a pedestrian traffic light that shows the remaining time to cross the road. The number displayed by the traffic light decreases by 1 every second. However, one day, Vlad approached the crossing and could not believe his eyes: the traffic light switched from 35 to 36!

Vlad was very surprised, but his astonishment faded in the next second: instead of 37 or any other number, the traffic light displayed something that was not a number at all. It turned out that one of the indicators of the traffic light was broken and never lit up. Hence, the number 39 looked like 35, and 38 looked like 36 (see Figures 1-3). After that, Vlad wondered: just how long can this illusion of the traffic light "ticking up by 1" every second last?

Figures 1-3. The behavior of the traffic light from the moment it switched to 39 until the moment it switched to 37: expected is on the top, actual is on the bottom. Lit indicators are colored green (looks gray when printed in black and white), functioning but not currently lit indicators are colored white, and the broken indicator is hatched.

39 looks like 3538 looks like 3637 looks like nonsense

For example, in the above situation, the illusion has lasted for exactly 1 second: from the moment the traffic light "switched from 35 to 36" (actually from 39 to 38) until the moment the traffic light started showing nonsense. Strictly speaking, the traffic light has "ticked up by 1" for kk seconds if it has consecutively displayed xx, x+1x+1, …\ldots, x+kx+k.

You are faced with the following task. The traffic light shows two digits. Both digits are "drawn" in the standard way using seven "stick-like" indicators: four of them are vertical and three are horizontal (see Figure 4).

Figure 4. How the digits look on a functioning traffic light

Each indicator is either functioning (works as it should) or broken (never lights up). The color switching of the traffic light always works correctly and always destroys the illusion of "ticking up". You are given exactly 9999 seconds to cross the road. Hence, a functioning traffic light consecutively shows 9999, 9898, 9797, …\ldots, 22 and 11. It does not show 00, and, instead, immediately switches to another color.

An important note: the traffic light does not show leading zeros, meaning that, on a functioning traffic light, the number 66 is displayed as a single six in the second digit, not as "06". Figures 5-6 show how the numbers 66 and 3737 are displayed on a functioning traffic light.

Figure 5. The number 6 on a functioning traffic lightFigure 6. The number 37 on a functioning traffic light

If such an illusion cannot be created at all (for example, when the traffic light always shows nonsense), then the answer is considered to be 00.

Summing up, the task can be formalized as follows. Find the largest non-negative kk such that there exists at least one yy such that k+1⩽y⩽99k + 1 \leqslant y \leqslant 99 and the numbers yy, y−1y-1, …\ldots, y−ky-k look as the numbers xx, x+1x+1, …\ldots, x+kx+k due to the broken indicators. If such a number kk does not exist, then the answer should be 00.

입력

The first line contains a string of seven characters, with each being either "0" or "1". They describe the states of the indicators in the first digit of the displayed number according to the order in Figure 7: the first character corresponds to the top horizontal indicator, the second to the upper left vertical indicator, the third to the upper right vertical indicator, the fourth to the middle horizontal indicator, the fifth to the lower left vertical indicator, the sixth to the lower right vertical indicator, and the seventh to the bottom horizontal indicator. A "1" means that the corresponding indicator is functioning, and a "0" means that it is broken.

The second line describes the state of the indicators in the second digit of the displayed number in a similar manner.

Figure 7. The order of indicators

출력

Print a single integer: the answer to the problem.

힌트

The first example is the situation discussed in the statement. The statement shows how the illusion can last for one second. It can be shown that it cannot last longer.

In the second example, additionally, the second and fifth (left vertical) indicators in the first digit are broken. The answer of 11 is still achieved in the same way (3939 looks like 3535, and 3838 looks like 3636).

In the third example, the answer is 00. Note that 9090 on such a traffic light looks like 5151, and 8989 looks like 6161, which is greater than 5151. However, these two consecutive displays of the traffic light do not form an illusion of length 11, as the numbers 5151 and 6161 are not consecutive.

In the fourth example, all indicators are broken, and therefore, the traffic light never displays a correctly written number. According to the statement, in this case, the output should be 00.

예제4

  1. 예제 1

    입력
    1111111
    1101111
    
    예상 출력
    1
    
  2. 예제 2

    입력
    1011011
    1101111
    
    예상 출력
    1
    
  3. 예제 3

    입력
    1101111
    0010010
    
    예상 출력
    0
    
  4. 예제 4

    입력
    0000000
    0000000
    
    예상 출력
    0