A factory's final assembly line re-sorts components before packaging. Every component arrives bearing a serial number. A dispatch rule recodes each component to a lane marker: components with an even serial number are recoded to lane marker 0, and components with an odd serial number are recoded to lane marker 1. After recoding, the line rearranges all of the components' lane markers into non-decreasing order (so every marker 0 precedes every marker 1) before they proceed to packaging.
Given the serial numbers of all the components currently on the line, output their lane markers after recoding and reordering.
n — the number of components on the line.n integers, the serial numbers of the components, in the order they currently sit on the line.Print n integers separated by single spaces on one line — the lane markers (each 0 or 1) after recoding every component by the parity of its serial number and rearranging them into non-decreasing order.
Example 1
Input
5 7 4 2 9 3
Expected
0 0 1 1 1
Explanation
The five serial numbers 7, 4, 2, 9, 3 recode to lane markers 1, 0, 0, 1, 1 (odd numbers become 1, even numbers become 0). Arranging these markers in non-decreasing order puts both 0s first, followed by all three 1s, giving 0 0 1 1 1.
Example 2
Input
1 0
Expected
0
Explanation
The single component has serial number 0, which is even, so it recodes to lane marker 0. With only one component, the output is simply 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →