题目描述
Problem Description
It is planned that $ N $ programmers will participate in the qualifying round of DDCC 20XX. However, due to venue constraints, only up to $ 9 $ people can participate in the main competition.
Therefore, the qualifying round will be divided into several rounds and conducted in a knockout format, following these rules:
- All $ N $ participants will participate in the first round.
- When $X\ (X\ \geq\ 10)$ people participate in a round, the number of people advancing to the next round is determined as follows:
- Select any two consecutive digits in the decimal representation of $ X $ and replace them with their sum. The resulting number is the number of people advancing.
For example, if $X\ =\ 2378$, the number of people advancing could be $ 578 $ (if $ 2,3 $ are selected), $ 2108 $ (if $ 3,7 $ are selected), or $ 2315 $ (if $ 7,8 $ are selected).
If $X\ =\ 100$, regardless of which two digits are selected, the number of people advancing will be $ 10 $. - The qualifying round ends when the number of people advancing is $ 9 $ or less.
Ringo, the leader of the DDCC 20XX organizing committee, wants to hold as many qualifying rounds as possible.
Determine the maximum number of qualifying rounds that can be held.
Note that the number of participants $ N $ can be very large, so it is given as two integer sequences $d_1,\ \ldots,\ d_M$ and $c_1,\ \ldots,\ c_M$.
This means that $ N $ is a number with $c_1\ +\ c_2\ +\ \ldots\ +\ c_M$ digits in decimal notation, where the first $ c_1 $ digits are all $ d_1 $, the next $ c_2 $ digits are all $ d_2 $, and so on, with the last $ c_M $ digits all being $ d_M $.
Input Format
The input is given from the standard input in the following format:
$ M $ $ d_1 $ $ c_1 $ $ d_2 $ $ c_2 $ $ : $ $ d_M $ $ c_M $
Output Format
Output the maximum number of qualifying rounds.
Sample Input and Output
Sample Input #1
2
2 2
9 1
Sample Output #1
3
Sample Input #2
3
1 1
0 8
7 1
Sample Output #2
9
Notes/Hints
Constraints
- $1\ \leq\ M\ \leq\ 200000$
- $0\ \leq\ d_i\ \leq\ 9$
- $d_1\ \neq\ 0$
- $d_i\ \neq\ d_{i+1}$
- $c_i\ \geq\ 1$
- $2\ \leq\ c_1\ +\ \ldots\ +\ c_M\ \leq\ 10^{15}$
Sample Explanation 1
In this case, $ N=229 $ people participate in the first round of the qualifying. An example of the progression of the competition could be: - $ 229 $ people participate in round $ 1 $, $ 49 $ people participate in round $ 2 $, $ 13 $ people participate in round $ 3 $, and $ 4 $ people advance to the main competition. In this case, the qualifying is held for $ 3 $ rounds, which is actually optimal.
Sample Explanation 2
In this case, $ 1000000007 $ people participate in the first round.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分