CodeLab Academy 📞 9936 6696
← List Python · Level 10: Algorithms Code · 100 points ← #943 #945 →

#944. Stocks: many trades

You get the price of a stock for each day. You may buy and sell as many times as you want (one share at a time). Find the largest profit. ### Input The first line has n, the second line has n integers separated by spaces. ### Output A number.

Examples

Input
3
52 2 18
Output
16
Input
12
20 66 63 49 44 36 89 33 69 42 58 39
Output
151

💡 You can solve it with Python, JavaScript or blocks. Read the input line by line with input(). Don't print a question (like input("Number: ")). Print exactly what the output asks for, nothing more.

🔒 You can solve the first 3 problems without an account. Sign up for free to solve this one!