#K78122. Maximum Profit from Stock Prices

    ID: 35017 Type: Default 1000ms 256MiB

Maximum Profit from Stock Prices

Maximum Profit from Stock Prices

You are given a sequence of n daily prices of an item, represented as integers \(p_1, p_2, \dots, p_n\). Your task is to compute the maximum profit that can be achieved by buying the item on one day and selling it on a later day. Formally, you need to determine \(\max_{1 \leq i < j \leq n} (p_j - p_i)\). If no profitable transaction exists, output 0.

inputFormat

The input consists of two lines. The first line contains a single integer \(n\) representing the number of days. The second line contains \(n\) space-separated integers that indicate the item price on each day.

outputFormat

Output a single integer representing the maximum profit obtainable by buying and then selling the item once. If no profit is possible, output 0.

## sample
6
7 1 5 3 6 4
5

</p>