#C8387. Sort Even Numbers Only

    ID: 52363 Type: Default 1000ms 256MiB

Sort Even Numbers Only

Sort Even Numbers Only

You are given an integer \(n\) and an array of \(n\) integers. Your task is to sort only the even numbers in the array in ascending order while keeping the odd numbers in their original positions.

In more detail, let \(a_1, a_2, \ldots, a_n\) be the input array. You need to obtain an array \(b_1, b_2, \ldots, b_n\) such that:

  • If \(a_i\) is even, then \(b_i\) is replaced by the next smallest even number from the array when all even numbers are sorted in ascending order.
  • If \(a_i\) is odd, then \(b_i = a_i\) remains unchanged.

For example, if \(n = 5\) and the array is [4, 3, 2, 1, 6], then the even numbers are [4, 2, 6]. When sorted, they become [2, 4, 6]. Replacing the even numbers in the original order yields [2, 3, 4, 1, 6].

Input/Output Method: Your code should read from stdin and write to stdout.

inputFormat

The first line contains a single integer \(n\) denoting the number of elements in the array.

The second line contains \(n\) space-separated integers representing the elements of the array.

outputFormat

Output a single line containing the modified array with only the even numbers sorted in ascending order. The elements should be space-separated.

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