#C1280. Minimize Maximum Height Difference

    ID: 42267 Type: Default 1000ms 256MiB

Minimize Maximum Height Difference

Minimize Maximum Height Difference

You are given the heights of n buildings and an integer K. For each building, you must either add or subtract K to its height exactly once. The goal is to choose the modification for each building such that the difference between the maximum and minimum heights after modification is minimized.

In other words, let the modified heights be represented by an array A where for each building height h, A[i] is either h+K or h-K. You need to find the minimum possible value of (max(A) - min(A)).

If there are no buildings (i.e. the array is empty), the answer is 0.

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. An integer n representing the number of buildings.
  2. If n > 0, a line containing n space-separated integers representing the heights of the buildings.
  3. An integer K on a new line, which is the modification value.

If n is 0, the heights line will be skipped and the only integer after will be K.

outputFormat

Output a single integer to standard output (stdout): the minimum possible value of the maximum difference between the modified building heights.

## sample
4
1 5 8 10
2
5

</p>