Candy Love
There are N children coming to the party and you have decided to distribute candies as return gift to those children. Children are numbered from 1 to N. You are given an array A which defines the maximum number of candies which can be given to any child. There are restrictions on number of candies which can be given to any child :
- Each child should be given at least one candy.
- The maximum candies which can be given to ith child is A[i].
The collective success of party is given by a function S which is calculated as follows :
function S():
Array C denotes the number of candies given to each child sum = o for i = 2 to N: sum = sum a abs(c[i]-[i-1]) return sum Now as the host of party you want to maximize the success of party. So distribute the candies in such a way which maximizes the success of party. Output the maximum value of success which can be obtained.
>##Sample Input## You will be given N denoting the number of children in party and next line will consist of N space separated integers denoting the maximum candies which can be given to any child. >##Sample Output## Print the maximum success value of party which can be obtained. >##Constraints## 2 <= N <= 10^5 1 <= A[i] <= 10^9 >##Sample Input 1## 3 1 2 4 >##Sample Output 1## 3 >##Sample Input 2## 6 3 10 15 10 3 10 >##Sample Output 2## 45 >##Explanation 1## One of the ways to get success value as 3 is giving {1,2,4} candies to children respectively. >##Explanation 2## One of the ways to get success value as 45 is giving {1,10,1,10,1,10} candies to children respectively.