## LCC/Moose '20 Contest 2 J3 - Alan's Snowmen

View as PDF

Points: 3 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Alan has a line of snowmen! Each snowman is made of snowballs. Alan wants every snowman to be at least as tall (having at least as many snowballs) as all the snowmen earlier than it, so he will need to add snowballs to some of the snowmen. Can you help Alan find the minimum number of snowballs he needs to add?

#### Input Specification

The first line will contain . The next line will contain integers .

#### Output Specification

Output the minimum number of snowballs Alan needs to add. Note that 64-bit integers may be required to pass.

No further constraints.

#### Sample Input

6
2 8 4 9 8 7

#### Sample Output

7