#K7136. Alternate Order

    ID: 33514 Type: Default 1000ms 256MiB

Alternate Order

Alternate Order

You are given an array of integers representing heights. Your task is to rearrange this array into an alternating increasing-decreasing order. More formally, if the given array after sorting is \(A_1 \le A_2 \le \cdots \le A_n\), you need to construct an array \(B\) such that:

\(B_1 = A_1, \; B_2 = A_n, \; B_3 = A_2, \; B_4 = A_{n-1},\) and so on.

For example, if the sorted array is [1, 2, 3, 4, 5], then the output should be [1, 5, 2, 4, 3].

inputFormat

The input is given from standard input (stdin). The first line contains an integer \(n\) representing the number of elements. The second line contains \(n\) space-separated integers.

outputFormat

Output to standard output (stdout) a single line containing the rearranged array in alternate order. Each number should be separated by a single space.

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