#C8222. Even-Odd List Rearrangement
Even-Odd List Rearrangement
Even-Odd List Rearrangement
Given a list of integers, rearrange them such that all even numbers appear before all odd numbers, while maintaining their original relative order. In other words, if the original list is (A = [a_1, a_2, \dots, a_n]), you need to partition it into two sublists: one containing all even numbers and the other containing all odd numbers. The final output is the concatenation of the two sublists, i.e., (\text{Even List} \oplus \text{Odd List}), where (\oplus) denotes concatenation.
inputFormat
The input is read from stdin and consists of two lines. The first line contains an integer (n) representing the number of elements. The second line contains (n) space-separated integers.
outputFormat
Output a single line to stdout containing the rearranged list of integers, with each integer separated by a single space.## sample
7
1 2 3 4 5 6 7
2 4 6 1 3 5 7