#C3737. Maximum Stock Profit

    ID: 47197 Type: Default 1000ms 256MiB

Maximum Stock Profit

Maximum Stock Profit

You are given a sequence of stock prices for n consecutive days. The price on the i-th day is denoted by \(p_i\). Your task is to compute the maximum profit you can achieve by making a single transaction (i.e. buying one share and later selling it). If no profit is possible, output 0.

Note: You are only allowed to buy once and sell once. Formally, you need to find a pair of indices \(i\) and \(j\) such that \(1 \le i < j \le n\) and \(p_j - p_i\) is maximized. If no such positive difference exists, output 0.

inputFormat

The first line of input contains an integer \(n\) denoting the number of days. The second line contains \(n\) space-separated integers \(p_1, p_2, \dots, p_n\) representing the price of the stock on each day.

outputFormat

Output a single integer representing the maximum profit that can be obtained from a single buy-sell transaction. If no profit can be made, output 0.

## sample
6
7 1 5 3 6 4
5