#K60412. Maximum Profit

    ID: 31081 Type: Default 1000ms 256MiB

Maximum Profit

Maximum Profit

Given an integer \( n \) representing the number of days, and a sequence of \( n \) stock prices, determine the maximum profit achievable from a single buy-sell transaction. You must buy before you sell. If no profit is possible, output 0.

If \( n < 2 \), it is impossible to complete a transaction, so the answer should be 0.

inputFormat

The input is provided via standard input. The first line contains a non-negative integer \( n \) (\( n \geq 0 \)), representing the number of days. The second line contains \( n \) integers separated by spaces, where each integer represents the stock price for that day.

outputFormat

Output a single integer, which is the maximum profit that can be achieved from a single buy and sell transaction. If no profit is possible, output 0.

## sample
6
7 1 5 3 6 4
5

</p>