LearnPy Hub
← Arena
IntermediateRating 1100

Trade Every Day

You may buy and sell a stock many times (holding at most one share). Print the maximum profit.

Input

n, then n prices.

Output

A number.

Sample 1

Input
6
7 1 5 3 6 4
Output
7

Sample 2

Input
5
1 2 3 4 5
Output
4
solution.py
Output appears here
Trade Every Day · Python Arena problem · LearnPy Hub