#t118. 分糖果
分糖果
Distributing Candies
Problem Description
There are children standing in a queue waiting for the teacher to hand out candies. The -th child wants at least 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 , the number of children.
The second line contains positive integers , 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 children needing candies. To satisfy the requirements, the teacher can distribute as follows:
- Child 1 gets (at least , and no predecessor, so );
- Child 2 needs at least and must exceed child 1's , so give ;
- Child 3 needs at least and must exceed child 2's , so give ;
- Child 4 needs at least and must exceed child 3's , so give .
Total: , which is the minimum.
Constraints
For all test cases, and are guaranteed.