LearnPy Hub
← Arena
AdvancedRating 1700

Trading With a Cooldown

Buy and sell a stock any number of times, but after selling you must wait one day before buying again. Print the maximum profit.

Input

n, then n prices.

Output

A number.

Sample 1

Input
5
1 2 3 0 2
Output
3

Sample 2

Input
1
1
Output
0
solution.py
Output appears here
Trading With a Cooldown · Python Arena problem · LearnPy Hub