#K65672. Maximum Difference

    ID: 32250 Type: Default 1000ms 256MiB

Maximum Difference

Maximum Difference

You are given an array of integers. Your task is to find the maximum difference between any two elements ai and aj such that j > i. In other words, you need to compute

$$\max_{i<j} \bigl(a_j - a_i\bigr)$$

If no pair exists that satisfies the condition, the answer is 0.

Example:

Input:
6
4 3 10 2 9 1

Output: 7

</p>

inputFormat

The input is read from standard input (stdin). The first line contains a single integer n which represents the number of elements. The second line contains n space-separated integers.

outputFormat

Output a single integer — the maximum difference between any two elements ai and aj (with j > i). Print the result to standard output (stdout).

## sample
6
4 3 10 2 9 1
7