#C5401. Sort Even Numbers in a List
Sort Even Numbers in a List
Sort Even Numbers in a List
You are given a list of integers. Your task is to sort the even numbers in ascending order while keeping the odd numbers in their original positions. More formally, if the input list is \( a_1, a_2, \dots, a_n \), then extract all even elements, sort them, and then replace each even element in the original list with the corresponding element from the sorted list.
Example:
Input: 6 5 3 2 8 1 4</p>Even numbers extracted: [2, 8, 4] Sorted even numbers: [2, 4, 8] Output: 5 3 2 4 1 8
The problem requires you to read the input from standard input (stdin) and output the result to standard output (stdout).
inputFormat
The first line of the input contains a single integer \( n \) representing the number of elements in the list. The second line contains \( n \) space-separated integers.
outputFormat
Output the modified list of integers in one line, where the even numbers have been sorted in ascending order while the odd numbers remain in their original positions. The numbers should be separated by a single space.
## sample6
5 3 2 8 1 4
5 3 2 4 1 8