#C14197. Separate and Merge Even and Odd Numbers

    ID: 43819 Type: Default 1000ms 256MiB

Separate and Merge Even and Odd Numbers

Separate and Merge Even and Odd Numbers

Given an input string consisting of integers separated by a combination of delimiters such as commas, spaces, or semicolons, your task is to separate the even and odd numbers. Then, sort the even numbers in ascending order and the odd numbers in ascending order. Finally, merge them so that all even numbers appear before all odd numbers.

The process can be mathematically described as follows:

$$ \text{evens} = \{ x \mid x \in \text{numbers},\; x \bmod 2 = 0 \} $$

$$ \text{odds} = \{ x \mid x \in \text{numbers},\; x \bmod 2 \neq 0 \} $$

$$ \text{result} = \text{sort}(\text{evens}) \;\Vert\; \text{sort}(\text{odds}) $$

Output the resulting list as space-separated integers.

inputFormat

The input is provided as a single line containing a sequence of integers. The integers are separated by commas (,), semicolons (;) or spaces.

For example: 34, 7, 23, 32, 1, 15, 8, 4

outputFormat

The output should be the sorted list of integers with even numbers first (sorted in ascending order), followed by odd numbers (sorted in ascending order). The numbers must be printed as space-separated values.

For example: 4 8 32 34 1 7 15 23

## sample
34, 7, 23, 32, 1, 15, 8, 4
4 8 32 34 1 7 15 23