#C12070. Max Stock Profit

    ID: 41457 Type: Default 1000ms 256MiB

Max Stock Profit

Max Stock Profit

You are given the stock prices for n consecutive days. Your task is to determine the maximum profit that can be achieved by buying on one day and selling on a later day. The profit is calculated using the formula

\(\text{Profit} = P_j - P_i\)

where \(P_i\) is the buying price and \(P_j\) is the selling price, with the condition \(i < j\). If no profit can be made, your answer should be 0.

inputFormat

The input is given via standard input (stdin). The first line contains an integer n representing the number of days. The second line contains n space-separated integers representing the stock prices on each day.

outputFormat

The output is a single integer printed to standard output (stdout) indicating the maximum profit obtainable. Output 0 if no profit is possible.

## sample
6
7 1 5 3 6 4
5