Score: 500 points
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
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, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Input is given from Standard Input in the following format:
M d_1 c_1 d_2 c_2 : d_M c_M
Print the maximum possible number of rounds in the preliminary stage.
2 2 2 9 1
3
In this case, N = 229 contestants will participate in the first round. One possible progression of the preliminary stage is as follows:
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, 1000000007 will participate in the first round.