#C11281. Maximum Profit

    ID: 40580 Type: Default 1000ms 256MiB

Maximum Profit

Maximum Profit

You are given a list of stock prices where the i-th element represents the price of the stock on day i. Your task is to compute the maximum profit you can achieve by performing at most one transaction (i.e., buying one and selling one share of the stock).

If no profit can be achieved, return 0.

You can use the following formula to calculate profit for a given day:

\( profit = price - min\_price \)

where \( min\_price \) is the minimum stock price encountered up to that day.

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.

If n is 0, then the list of prices is empty.

outputFormat

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

## sample
6
7 1 5 3 6 4
5