CSES-Increasing Array-2-New-Additional-Problems

You are given an array of nn integers. You want to modify the array so that it is increasing, i.e., every element is at least as large as the previous element.

On each move, you can increase or decrease the value of any element by one. What is the minimum number of moves required?

Input

The first input line contains an integer nn: the size of the array.

Then, the second line contains nn integers x1,x2,…,xnx1,x2,…,xn: the contents of the array.

Output

Print the minimum number of moves.

Constraints

  • 1≤n≤2⋅1051≤n≤2⋅105

  • 1≤xi≤1091≤xi≤109

Example

Input:
53 8 5 6 5

Output:
4

Could anyone suggest an approach for this question?
Problem Link: CSES - Increasing Array II

You can check the solution here

Do you have any proof or something as to why is the greedy strategy working here.