#K36357. Sort Odd and Even Numbers

    ID: 25736 Type: Default 1000ms 256MiB

Sort Odd and Even Numbers

Sort Odd and Even Numbers

Given a list of non-negative integers, sort the list such that all odd numbers appear before all even numbers. Within each group (odd and even), the numbers must be sorted in ascending order.

The input is provided via standard input (stdin) and the output should be sent to standard output (stdout).

Input Format: The first line contains an integer \(n\), representing the total number of elements. The second line contains \(n\) space-separated non-negative integers.

Output Format: Output the rearranged list as a sequence of space-separated integers.

inputFormat

The first line of input contains an integer \(n\) (the number of elements). The second line contains \(n\) space-separated non-negative integers.

outputFormat

Output the sorted list of integers on a single line, where all odd numbers come first (sorted in ascending order) followed by all even numbers (sorted in ascending order), separated by spaces.

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