~/algor $ cat problems/minmax-36-eng-foydali-savdo
Most profitable deal
Medium
1000 ms
128 MB
45%
The prices of a product for $N$ days are given: $A_{1}, A_{2}, \ldots, A_{N}$. The product is bought on day $i$ and sold later, on day $j$ ($i \lt j$); the profit is:
$$A_{j} - A_{i}$$
Find the largest profit. Buying and selling are mandatory, so the profit may also be negative.
Input
The first line contains a positive integer $N$. The next line contains $N$ integers $A_{i}$.
Output
One integer — the largest profit.
Note
$2 \le N \le 10^{5}$
$1 \le A_{i} \le 10^{9}$
Examples
Input #1
6 7 2 5 1 6 3
Output #1
5
Input #2
3 5 4 2
Output #2
-1