#C13637. Maximum Profit from One Transaction

    ID: 43197 Type: Default 1000ms 256MiB

Maximum Profit from One Transaction

Maximum Profit from One Transaction

You are given a list of daily stock prices. Your task is to compute the maximum profit that can be achieved by performing a single buy and a single sell transaction. Note that the buying must occur before selling. If no profit can be obtained, return 0.

The profit is defined as the difference between the selling price and the buying price.

Example:

Input: 6\n7 1 5 3 6 4
Output: 5

inputFormat

The first line of input contains an integer n which denotes the number of stock prices. The second line contains n space-separated integers representing the stock prices.

If n is 0, then no prices are given and the output should be 0.

outputFormat

Output a single integer denoting the maximum profit that can be achieved. If no profit is possible, output 0.

## sample
6
7 1 5 3 6 4
5