QOJ.ac

QOJ

时间限制: 2 s 内存限制: 256 MB 总分: 10

#225. New contract [B]

统计

Your video game production company has achieved stunning success – a series of $N$ games about a quasar slayer traveling through the Galaxy sold excellently, bringing you fame, money, and unexpected trouble. News has broken that a famous science-fiction writer, whose books your games are based on, has decided that he sold the adaptation rights for too low a price and, through his lawyers, is demanding a change to the contract terms.*

The contract stipulated that for licensing game number $i$ (where $i = 1, 2, \dots, N$), the writer would receive a payment $a_i$, which is a positive integer. However, the lawyers argue that since each subsequent game sold better than the previous one, the payment should also be higher. You want to avoid unnecessary publicity (as well as panic among shareholders), so the interference with the contract terms should be as minimal as possible. You have therefore decided to append a certain number of digits to the end of each of the numbers $a_1, \dots, a_N$ such that the resulting new sequence is strictly increasing. For each $a_i$, the appended digits (and their count) can be different, and you may also choose not to change some numbers at all.

Determine the minimum total number of digits you must append to achieve this.

Input

The first line of the input contains a single integer $N$ ($1 \le N \le 200\,000$). The following $N$ lines contain the integers $a_1, \dots, a_N$ ($1 \le a_i \le 10^9$).

Output

Your program should output a single integer – the minimum possible number of appended digits.

Examples

Input 1

3
8
5
13

Output 1

2

Note

Explanation for the example: By appending the digits 7 and 3 to the second and third numbers respectively, we obtain the strictly increasing sequence $(8, 57, 133)$. Other solutions are possible, but it is impossible to achieve the goal by appending only one digit.

*Rumor has it that he will spend the profit on purchasing a mithril fishing vest – however, this information could not be confirmed at the source.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.