Problem2364--Step

2364: Step

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MB

Description

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 300300 points

Problem Statement

NN persons are standing in a row. The height of the ii-th person from the front is A_iAi.
We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:
Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.
Find the minimum total height of the stools needed to meet this goal.

Constraints

  • 1 \leq N \leq 2\times 10^51N2×105
  • 1 \leq A_i \leq 10^91Ai109
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:
NNA_1A1\ldotsA_NAN

Output

Print the minimum total height of the stools needed to meet the goal.

Sample Input Copy

5
2 1 5 4 3

Sample Output Copy

4

HINT

If the persons stand on stools of heights 00110011, and 22, respectively, their heights will be 22225555, and 55, satisfying the condition.

We cannot meet the goal with a smaller total height of the stools.

Source/Category