Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/massiv-juft-va-toq-ajratish

Grouping even and odd numbers

Easy 1000 ms 128 MB 27%
Share

A positive integer $n$ and an array of $n$ integers are given. Print first all array elements with even values, then all elements with odd values, in input order.

Splitting the array elements into even and odd groups

Input

The first line contains a positive integer $n$. The second line contains $n$ integers separated by spaces.

Output

One line with $n$ integers separated by spaces (even ones first, then odd ones).

Note

$1 \le n \le 1000$
$-10^{9} \le a_{i} \le 10^{9}$

Examples

Input #1
6
4 7 2 9 8 5
Output #1
4 2 8 7 9 5
Input #2
4
1 3 2 4
Output #2
2 4 1 3

Sign in to submit a solution

Signing up is free and takes a minute.