#C1567. Maximum Absolute Difference Arrangement

    ID: 44786 Type: Default 1000ms 256MiB

Maximum Absolute Difference Arrangement

Maximum Absolute Difference Arrangement

Given an array of n integers, rearrange the elements such that the sum of absolute differences between adjacent pairs is maximized. In other words, if the rearranged array is \(a_1, a_2, \dots, a_n\), you need to maximize:

\(\sum_{i=1}^{n-1} |a_i - a_{i+1}|\)

You are required to read the input from standard input (stdin) and write the output to standard output (stdout). The rearrangement should be output as a sequence of integers separated by spaces.

inputFormat

The input consists of two lines:

  • The first line contains a single integer \(n\) representing the number of elements in the array.
  • The second line contains \(n\) space-separated integers.

outputFormat

Output the rearranged array as a single line of \(n\) space-separated integers such that the sum of absolute differences between consecutive elements is maximized.

## sample
3
1 3 2
3 1 2