#K48382. Sort Containers

    ID: 28408 Type: Default 1000ms 256MiB

Sort Containers

Sort Containers

You are given an integer n representing the number of containers, and a sequence of n integers representing the weights of the containers.

Your task is to sort these container weights according to the following criteria:

  • All even weights should be sorted in ascending order.
  • All odd weights should be sorted in descending order.
  • The sorted even weights should come before the sorted odd weights.

This can be mathematically represented as follows:

\[ E = \{ w \in \text{weights} \mid w \bmod 2 = 0 \}, \quad O = \{ w \in \text{weights} \mid w \bmod 2 \neq 0 \} \] \[ \text{Result} = \text{sort}(E, \text{ascending}) \cup \text{sort}(O, \text{descending}) \]

Read the input from standard input and output the sorted list to standard output.

inputFormat

The input consists of two lines:

  1. The first line contains an integer n representing the number of containers.
  2. The second line contains n space-separated integers representing the weights of the containers.

outputFormat

Output a single line containing the sorted container weights separated by a single space. The even weights (sorted in ascending order) should precede the odd weights (sorted in descending order).

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