#K83917. Aesthetic Stamp Arrangement

    ID: 36304 Type: Default 1000ms 256MiB

Aesthetic Stamp Arrangement

Aesthetic Stamp Arrangement

You are given a collection of n stamps with integer values. You are to arrange these stamps in a sequence to maximize the aesthetic value of the arrangement. The aesthetic value is defined as twice the absolute difference between the maximum and minimum stamp values, i.e.,

\( \text{Aesthetic Value} = 2 \times (\max - \min) \)

Note that an arrangement is only possible if there are at least two stamps. If the number of stamps is less than 2, the input is considered invalid.

Input Format: The first line contains a single integer n representing the number of stamps. The second line contains n space-separated integers representing the stamp values.

Output Format: Output a single integer — the maximum aesthetic value calculated as described above.

Examples:

  • Input: 4
    1 3 2 8
    → Output: 14
  • Input: 5
    5 3 1 8 10
    → Output: 18

inputFormat

The first line of input contains an integer n (n \geq 2) — the number of stamps. The second line contains n space-separated integers representing the values of the stamps.

outputFormat

Output a single integer which is 2 times the difference between the maximum and minimum stamp values.## sample

4
1 3 2 8
14