#C2037. Group Even and Odd Numbers
Group Even and Odd Numbers
Group Even and Odd Numbers
Given an array of integers, rearrange the list so that all even numbers appear before all odd numbers while preserving the original relative order within each group. Formally, for a given sequence \(a_1, a_2, \dots, a_n\), output a sequence where every element satisfying \(a_i \mod 2 = 0\) comes before any element satisfying \(a_i \mod 2 = 1\). This problem tests your ability to process arrays and maintain order properties.
inputFormat
The input is given via standard input. The first line contains an integer \(n\) denoting the number of elements. The second line contains \(n\) space-separated integers.
outputFormat
Print the rearranged list to standard output in one line, with each number separated by a single space. If the list is empty, print an empty line.
## sample6
1 2 3 4 5 6
2 4 6 1 3 5