#C11464. Special Alternating Sort

    ID: 40783 Type: Default 1000ms 256MiB

Special Alternating Sort

Special Alternating Sort

You are given an array of integers. Your task is to sort the array using a special technique: repeatedly remove the smallest element and then the largest element from the remaining array, appending them in that order to form the output list. Formally, if we denote the sorted array as (a_1 \leq a_2 \leq \dots \leq a_n), then the result is constructed as (a_1, a_n, a_2, a_{n-1}, \dots).

The input is read from standard input and the output should be printed to standard output. Numbers in the output must be separated by a single space.

inputFormat

The first line of input contains an integer (n) denoting the number of elements in the array. The second line contains (n) space-separated integers.

outputFormat

Output a single line containing the specially sorted array. The numbers should be printed in order, separated by a single space.## sample

5
1 3 7 2 5
1 7 2 5 3