#K59297. Sort Odds Before Evens
Sort Odds Before Evens
Sort Odds Before Evens
Given a list of integers, your task is to rearrange the list so that all odd numbers come before all even numbers. Within the odd numbers group, the numbers should be sorted in ascending order, and similarly, the even numbers group should also be sorted in ascending order.
In other words, if the input list is \(L = [a_1, a_2, \dots, a_n]\), you need to output a list \(L'\) such that:
- All odd numbers in \(L'\) appear before any even number.
- The odd numbers are sorted in ascending order.
- The even numbers are sorted in ascending order.
You will read the input from standard input and write your output to standard output.
inputFormat
The input consists of two lines:
- The first line contains a single integer \(n\) (\(0 \leq n \leq 10^5\)), representing the number of elements in the list.
- The second line contains \(n\) space-separated integers.
If \(n = 0\), the second line will be empty.
outputFormat
Output a single line containing the sorted list, with the numbers separated by a single space. If the list is empty, output nothing.
## sample7
10 21 3 14 5 8 7
3 5 7 21 8 10 14