#t118. 分糖果

分糖果

Distributing Candies

Problem Description

There are nn children standing in a queue waiting for the teacher to hand out candies. The ii-th child wants at least aia_i candies, and the number of candies given to him must be strictly greater than the number given to the previous child, otherwise he will be unhappy.

The teacher wants to know the minimum total number of candies needed to keep all children happy. Can you help?

Input Format

The first line contains a positive integer nn, the number of children.

The second line contains nn positive integers a1,a2,…,ana_1, a_2, \ldots, a_n, the minimum number of candies each child needs, in order.

Output Format

Output one line containing one integer: the minimum total number of candies needed.

Sample Input 1

4
1 4 3 3

Sample Input 2

15
314 15926 53589793 238462643 383279502 8 8 4 1 9 7 1 6 9 3

Sample Output 1

16

Sample Output 2

4508143253

Sample Explanation

For the first sample, there are 44 children needing 1,4,3,31, 4, 3, 3 candies. To satisfy the requirements, the teacher can distribute as follows:

  • Child 1 gets 11 (at least 11, and no predecessor, so 11);
  • Child 2 needs at least 44 and must exceed child 1's 11, so give 44;
  • Child 3 needs at least 33 and must exceed child 2's 44, so give 55;
  • Child 4 needs at least 33 and must exceed child 3's 55, so give 66.

Total: 1+4+5+6=161 + 4 + 5 + 6 = 16, which is the minimum.

Constraints

For all test cases, 1≤n≤10001 \le n \le 1000 and 1≤ai≤1091 \le a_i \le 10^9 are guaranteed.