#K54062. Maximum Stock Trading Profit

    ID: 29670 Type: Default 1000ms 256MiB

Maximum Stock Trading Profit

Maximum Stock Trading Profit

You are given a list of daily stock prices. Your task is to determine the maximum profit that can be achieved by buying one share of the stock on one day and selling it on a later day.

If no profit is possible, output 0. In mathematical terms, you need to maximize \(profit = price_j - price_i\) where \(i < j\). If the list is empty or contains only one price, then the profit is 0.

inputFormat

The input begins with an integer \(n\) representing the number of days. The next line contains \(n\) integers, each representing the stock price on a day, separated by spaces. If \(n = 0\), there are no stock prices.

outputFormat

Output a single integer which is the maximum profit obtainable. If no profit is found, output 0.

## sample
6
7 1 5 3 6 4
5