#C1154. Maximum Stock Profit

    ID: 40867 Type: Default 1000ms 256MiB

Maximum Stock Profit

Maximum Stock Profit

You are given the stock prices for n consecutive days. The price on each day is represented as an integer. Your task is to determine the maximum profit that can be achieved by performing a single buy-sell transaction. In other words, find the maximum difference between two prices such that the lower price appears before the higher price in the sequence.

If no profit is possible, output 0.

Input/Output: The program should read from stdin and write the answer to stdout.

Input Format: The first line contains an integer n indicating the number of days. The second line contains n space-separated integers representing the stock prices.

Output Format: A single integer representing the maximum profit. If no profit is possible, output 0.

inputFormat

The first line contains an integer n, the number of days. The second line contains n space-separated integers where each integer is the stock price for that day.

outputFormat

Output a single integer which is the maximum profit that can be obtained from one transaction. If the best profit is not positive, output 0.

## sample
6
7 1 5 3 6 4
5

</p>