#C1553. Alternate Removal Game

    ID: 44771 Type: Default 1000ms 256MiB

Alternate Removal Game

Alternate Removal Game

Alice and Bob are playing a simple game with a list of unique positive integers. In each turn, the player whose turn it is removes the largest available number from the list. They take turns alternately, and the game continues until all numbers are removed. The resulting sequence of removed numbers is the output of the game.

Task: Given a list of unique positive integers, simulate the game and output the order in which the numbers are removed. The removal order is achieved by first sorting the list in descending order and then letting the players remove the numbers alternately, which in effect results in the same descending order.

The mathematical representation for a descending order of numbers can be written in LaTeX as follows:

\( sortedNumbers = \{a_1, a_2, \dots, a_n\} \quad \text{where} \quad a_1 \geq a_2 \geq \dots \geq a_n \)

inputFormat

The input is provided via standard input (stdin) and is organized as follows:

  • The first line contains a single integer n, representing the number of numbers.
  • The second line contains n space-separated unique positive integers.

You should read from stdin and process the input accordingly.

outputFormat

Output the sequence of numbers as they are removed, separated by a single space. The output should be sent to standard output (stdout).

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