Sort by Parity Count
Given a list of N integers, sort them in non-decreasing order based on the number of odd digits each integer contains. If two numbers have the same count of odd digits, their relative order should be preserved from the original input (stable sort). Print the sorted list.
Input
The first line contains an integer N. The second line contains N space-separated integers.
Output
Print the N space-separated integers sorted according to the rule.
Constraints
1 <= N <= 1000. Each integer will be between -1000 and 1000.
Example 1
5 123 45 6 789 10
6 45 10 123 789
Odd digit counts: 123(2), 45(2), 6(0), 789(3), 10(1). Sorted by count: 6(0), 10(1), 123(2), 45(2), 789(3). 123 and 45 maintain original relative order.
Example 2
3 24 86 135
24 86 135
Odd digit counts: 24(0), 86(0), 135(2). Sorted by count: 24(0), 86(0), 135(2). 24 and 86 maintain original relative order.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
5 123 45 6 789 10
3 24 86 135