Even numbers first
Rearrange the array so all even numbers come before all odd numbers. Keep the original order inside each group.
Reported in: Wipro Elite NTH (memory-based)
Input
First line: N. Second line: N integers.
Output
The rearranged array, space-separated.
Constraints
1 ≤ N ≤ 10^5.
Example 1
Input:
7
3 8 5 2 9 4 1
Output:
8 2 4 3 5 9 1Example 2
Input:
4
1 3 5 7
Output:
1 3 5 7Hint: Two passes: print the evens in order, then the odds in order.