|Codeforces Round #766 (Div. 2)|
You have an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. You are allowed to perform the following operation on it:
Note that the array changes after each operation, and the subsequent operations are performed on the new array.
What is the maximum number of times you can perform the operation on the array?
The first line consists of a single integer $$$n$$$ ($$$2 \le n \le 10^6$$$).
The second line consists of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^6$$$). All $$$a_i$$$ are distinct.
Output a single line containing one integer — the maximum number of times the operation can be performed on the given array.
5 4 20 1 25 30
3 6 10 15
In the first example, one of the ways to perform maximum number of operations on the array is:
It can be proved that there is no way to perform more than $$$3$$$ operations on the original array.
In the second example one can add $$$3$$$, then $$$1$$$, then $$$5$$$, and $$$2$$$.