Skip to content
UPEEC

Best Time to Buy and Sell

Easy#arrays#greedy· solved by 0 · time limit 2.0 s

Prices of a component for nn days are given. Buy on one day and sell on a later day to maximise profit. Print the maximum profit (0 if you can't profit).

Input

nn, then nn prices.

Output

The maximum profit.

Constraints

1≤n≤1051 \le n \le 10^5

Sample 1

Input

6
7 1 5 3 6 4

Output

5

Sample 2

Input

5
7 6 4 3 1

Output

0

Sign in or join free to run and submit your solution.