#K82817. Zigzag Rearrangement of Colors

    ID: 36060 Type: Default 1000ms 256MiB

Zigzag Rearrangement of Colors

Zigzag Rearrangement of Colors

You are given an integer n representing the number of colors, and a list of n integers which represent the colors. Your task is to rearrange the colors in a zigzag pattern so that the sum of the absolute differences of consecutive colors is maximized. This is achieved by arranging the colors in the following order: the smallest element, the largest element, the second smallest element, the second largest element, and so on.

In mathematical terms, if the sorted array is \(a_1 \leq a_2 \leq \cdots \leq a_n\), you need to form an array \(b\) such that:

[ b_1 = a_1,\quad b_2 = a_n,\quad b_3 = a_2,\quad b_4 = a_{n-1}, \quad \ldots ]

Print the rearranged sequence.

inputFormat

The first line of the input contains an integer n — the number of colors. The second line contains n space-separated integers representing the colors.

outputFormat

Output a single line containing the rearranged sequence in zigzag order, with the numbers separated by a single space.

## sample
4
4 3 2 5
2 5 3 4