Score : $600$ points
You are going to trade stocks of Company X for the next $N$ days.
As a precognitive, you know that the stock price on the $i$-th day of trading will be $P_i$ yen (the currency in Japan) per unit.
Every day, you can choose to do exactly one of the following.
You initially have $10^{100}$ yen, so you will never be short of money.
Find the maximum possible amount of money you will have gained when the $N$-th day has ended.
Even if you still possess some amount of stocks of Company X when the $N$-th day has ended, it is considered that they are worth $0$ yen.
Input is given from Standard Input in the following format:
$N$ $P_1$ $P_2$ $\dots$ $P_N$
Print the answer as an integer.
8 2 5 4 3 7 1 8 6
16
By acting as follows, your money will increase by $16$ yen, which is the maximum possible.
5 10000 1000 100 10 1
0
15 300 1 4000 1 50000 900000000 20 600000 50000 300 50000 80000000 900000000 7000000 900000000
2787595378