Stock Maximize#11480

Stock Maximize

1 second
128 megabytes
Easy

Your algorithms have become so good at predicting the market that now you know what the share price of Wooden Orange Toothpicks Inc. (WOT) will be for the next number of days.

Each day, you can either buy one share of WOT, sell any number of shares of WOT that you own, or not make any transaction at all. What is the maximum profit you can obtain with the optimum trading strategy?

Input

The first line contains the number of predicted prices n\:(1 \le n \le 50000) for WOT. The next line contains integers p_i\:(1 \le p_i \le 10^5), each is a predicted stock price on the -th day.

Output

Print the maximum profit that can be obtained in the market.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading