#K39862. Maximum Stock Profit

    ID: 26515 Type: Default 1000ms 256MiB

Maximum Stock Profit

Maximum Stock Profit

You are given an array of integers where each integer represents the stock price on a given day. Your task is to determine the maximum profit that can be achieved by buying on one day and selling on another day strictly after the buy day. If no profit can be obtained, output 0.

Formally, if the array is denoted as \(prices = [price_1, price_2, \dots, price_n]\), you need to compute \[ \max_{1 \leq i < j \leq n} (price_j - price_i), \] and if this value is negative, return 0.

Input is read from standard input (stdin) and output should be written to standard output (stdout).

inputFormat

The first line of input contains a single integer \(n\) representing the number of days.

The second line contains \(n\) space-separated integers, where each integer represents the stock price on that day.

outputFormat

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

## sample
6
7 1 5 3 6 4
5