#K62007. Maximum Difference After Removal

    ID: 31435 Type: Default 1000ms 256MiB

Maximum Difference After Removal

Maximum Difference After Removal

You are given a list of n integers. Your task is to remove exactly one element from the list such that the difference between the maximum and minimum numbers of the remaining list is maximized. If n is less than or equal to 2, output 0 since removal does not lead to a meaningful difference.

The problem can be formally stated as:

Given an integer \( n \) and an array \( arr \) of \( n \) integers, remove exactly one element from \( arr \) and compute \[ \text{answer} = \max \left( (\max(arr \setminus \{x\}) - \min(arr \setminus \{x\})) \right) \quad \text{for each } x \in arr. \]

Find the maximum possible value of \( answer \) after the removal.

inputFormat

The first line contains an integer \( n \) representing the number of elements in the array.

The second line contains \( n \) space-separated integers representing the elements of the array.

outputFormat

Output a single integer, the maximum difference between any two elements of the list after removing exactly one element.

## sample
4
1 2 3 4
3

</p>