#C13134. Maximum Stock Profit

    ID: 42639 Type: Default 1000ms 256MiB

Maximum Stock Profit

Maximum Stock Profit

You are given a list of daily stock prices. Your task is to determine the maximum profit achievable by performing a single buy and a single sell transaction. If no profit is achievable, output 0.

The problem can be formulated as finding
$$\max_{1 \leq i < j \leq n} \left(p_j - p_i\right)$$
where \(p_i\) represents the stock price on day \(i\). If the prices are in descending order or if there is only one day's price, the maximum profit is 0.

inputFormat

The first line contains an integer \(n\) representing the number of days. The second line contains \(n\) space-separated integers representing the stock prices for each day.

outputFormat

Output a single integer representing the maximum profit achievable. If no profit is possible, output 0.

## sample
6
7 1 5 3 6 4
5