#P35. [KBC002C] Sequence 3
[KBC002C] Sequence 3
Source
This problem is moved from Long Long OJ (Copyright by Google Inc.). All rights reserved.
Adapted from: https://luogu.com.cn/problem/P13026
Attention
is the hard version of this problem.
Problem Description
Given a sequence of integers, you need to add digits at the end of the integers in order to make the sequence strictly increasing.
Adding digit at the end of a number can be represented as .
Find the minimum number of digits to be added.
Input Format
The first line consists of an integer .
The following lines consists of integers .
Output Format
Output the minimum number of digits to be added.
Samples
4
20
1
45
132
4
Sample Explanation
After adding digits, the sequence becomes .
Note that this is not the only possible solution.
Data Range
For of the test cases:
- .
- .
For the remaining of the test cases:
- .
- All the numbers in are equal.
- .