atcoder#DDCC2020QUALD. Digit Sum Replace
Digit Sum Replace
Score: points
Problem Statement
programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
- All the contestants will participate in the first round.
- When contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:- The organizer will choose two consecutive digits in the decimal notation of , and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round. For example, when , the number of contestants advancing to the next round will be (if and are chosen), (if and are chosen), or (if and are chosen). When , the number of contestants advancing to the next round will be , no matter which two digits are chosen.
- The organizer will choose two consecutive digits in the decimal notation of , and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round. For example, when , the number of contestants advancing to the next round will be (if and are chosen), (if and are chosen), or (if and are chosen). When , the number of contestants advancing to the next round will be , no matter which two digits are chosen.
- The preliminary stage ends when or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, , can be enormous, it is given to you as two integer sequences and , which means the following: the decimal notation of consists of digits, whose first digits are all , the following digits are all , , and the last digits are all .
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible number of rounds in the preliminary stage.
2
2 2
9 1
3
In this case, contestants will participate in the first round. One possible progression of the preliminary stage is as follows:
- contestants participate in Round , contestants participate in Round , contestants participate in Round , and contestants advance to the finals.
Here, three rounds take place in the preliminary stage, which is the maximum possible number.
3
1 1
0 8
7 1
9
In this case, will participate in the first round.