#C14540. Reorder Even and Odd

    ID: 44201 Type: Default 1000ms 256MiB

Reorder Even and Odd

Reorder Even and Odd

Given a list of integers, your task is to reorder the list so that all even numbers come before all odd numbers. The even numbers must be sorted in ascending order, while the odd numbers must be sorted in descending order. In mathematical notation, let \(E\) denote the set of even numbers and \(O\) denote the set of odd numbers in the list \(A\). The desired output is:

\(\text{result} = \text{sort}(E) \: \Vert \: \text{sort}_{\text{desc}}(O)\)

This means the list is first partitioned into even and odd numbers, then the even part is sorted from smallest to largest, and the odd part is sorted from largest to smallest. Finally, the two parts are concatenated to form the final sequence.

inputFormat

The input is provided via stdin in the following format:

  • The first line contains a single integer \(n\), which is the number of integers.
  • The second line contains \(n\) space-separated integers.

outputFormat

The output should be printed to stdout as a single line containing the reordered integers separated by a space.

## sample
8
4 3 1 2 0 5 9 8
0 2 4 8 9 5 3 1

</p>