#C14129. Sort Even Numbers While Preserving Odd Positions

    ID: 43744 Type: Default 1000ms 256MiB

Sort Even Numbers While Preserving Odd Positions

Sort Even Numbers While Preserving Odd Positions

You are given an array of integers. Your task is to sort only the even numbers in ascending order while keeping the odd numbers in their original positions. In other words, only the positions of even elements are changed after sorting, and the relative order of odd numbers remains unchanged.

For example, given the array [3, 1, 2, 4, 7, 5, 8, 6], the even numbers [2, 4, 8, 6] when sorted in ascending order become [2, 4, 6, 8], so the resulting array is [3, 1, 2, 4, 7, 5, 6, 8].

The input starts with an integer n representing the number of elements, followed by a line with n space-separated integers. The output should be the modified array printed in one line with space separated values.

inputFormat

The first line of the input contains a single integer n, which denotes the number of elements in the array. The second line contains n space-separated integers representing the array elements.

outputFormat

Output the modified array in a single line where the even numbers have been sorted in ascending order while the odd numbers remain in their original positions. The numbers should be printed space-separated.

## sample
8
3 1 2 4 7 5 8 6
3 1 2 4 7 5 6 8