#C506. Grouping Evens and Odds
Grouping Evens and Odds
Grouping Evens and Odds
You are given a list of integers. Your task is to group all the even numbers followed by all the odd numbers while preserving the original relative order of the numbers.
An integer x is considered even if \(x \mod 2 = 0\) and odd otherwise.
For example, given the list [1, 2, 3, 4, 5, 6], the output should be [2, 4, 6, 1, 3, 5].
Note: The input will be provided via stdin and the result should be printed to stdout.
inputFormat
The first line contains a single integer (n) representing the number of elements in the list. The second line contains (n) space-separated integers.
outputFormat
Output the rearranged list such that all even numbers come first (in their original order) followed by all odd numbers (in their original order), with the numbers separated by a single space.## sample
6
1 2 3 4 5 6
2 4 6 1 3 5