using System;
using System.Collections;
public class Program {
public static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
var input = Console.ReadLine().Split(" ");
Stack evenStack = new Stack();
for(int i = 0; i < n; i++) {
var num = Convert.ToInt32(input[i]);
if(num % 2 == 0)
evenStack.Push(num);
else {
while(evenStack.Count > 0) {
Console.Write(evenStack.Pop() + " ");
}
Console.Write(num + " ");
}
}
while(evenStack.Count > 0) {
Console.Write(evenStack.Pop() + " ");
}
}
}